vice city online: the bare online core
This commit is contained in:
commit
2f98475c19
256 changed files with 144219 additions and 0 deletions
3
.gitattributes
vendored
Normal file
3
.gitattributes
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
sdk/* linguist-vendored
|
||||||
|
vendor/* linguist-vendored
|
||||||
|
*.sh text eol=lf
|
||||||
382
.gitignore
vendored
Normal file
382
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,382 @@
|
||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
##
|
||||||
|
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.rsuser
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
|
*.userprefs
|
||||||
|
|
||||||
|
# Mono auto generated files
|
||||||
|
mono_crash.*
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
[Aa][Rr][Mm]/
|
||||||
|
[Aa][Rr][Mm]64/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
[Ll]og/
|
||||||
|
[Bb]uild/
|
||||||
|
|
||||||
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
|
.vs/
|
||||||
|
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||||
|
#wwwroot/
|
||||||
|
|
||||||
|
# Visual Studio 2017 auto generated files
|
||||||
|
Generated\ Files/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
# NUnit
|
||||||
|
*.VisualState.xml
|
||||||
|
TestResult.xml
|
||||||
|
nunit-*.xml
|
||||||
|
|
||||||
|
# Build Results of an ATL Project
|
||||||
|
[Dd]ebugPS/
|
||||||
|
[Rr]eleasePS/
|
||||||
|
dlldata.c
|
||||||
|
|
||||||
|
# Benchmark Results
|
||||||
|
BenchmarkDotNet.Artifacts/
|
||||||
|
|
||||||
|
# .NET Core
|
||||||
|
project.lock.json
|
||||||
|
project.fragment.lock.json
|
||||||
|
artifacts/
|
||||||
|
|
||||||
|
# StyleCop
|
||||||
|
StyleCopReport.xml
|
||||||
|
|
||||||
|
# Files built by Visual Studio
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*_h.h
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.iobj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.ipdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*_wpftmp.csproj
|
||||||
|
*.log
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.svclog
|
||||||
|
*.scc
|
||||||
|
|
||||||
|
# Chutzpah Test files
|
||||||
|
_Chutzpah*
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opendb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
*.VC.db
|
||||||
|
*.VC.VC.opendb
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
*.sap
|
||||||
|
|
||||||
|
# Visual Studio Trace Files
|
||||||
|
*.e2e
|
||||||
|
|
||||||
|
# TFS 2012 Local Workspace
|
||||||
|
$tf/
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# JustCode is a .NET coding add-in
|
||||||
|
.JustCode
|
||||||
|
|
||||||
|
# TeamCity is a build add-in
|
||||||
|
_TeamCity*
|
||||||
|
|
||||||
|
# DotCover is a Code Coverage Tool
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
# AxoCover is a Code Coverage Tool
|
||||||
|
.axoCover/*
|
||||||
|
!.axoCover/settings.json
|
||||||
|
|
||||||
|
# Visual Studio code coverage results
|
||||||
|
*.coverage
|
||||||
|
*.coveragexml
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
_NCrunch_*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
nCrunchTemp_*
|
||||||
|
|
||||||
|
# MightyMoose
|
||||||
|
*.mm.*
|
||||||
|
AutoTest.Net/
|
||||||
|
|
||||||
|
# Web workbench (sass)
|
||||||
|
.sass-cache/
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress/
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
*.azurePubxml
|
||||||
|
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||||
|
# but database connection strings (with potential passwords) will be unencrypted
|
||||||
|
*.pubxml
|
||||||
|
*.publishproj
|
||||||
|
|
||||||
|
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||||
|
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||||
|
# in these scripts will be unencrypted
|
||||||
|
PublishScripts/
|
||||||
|
|
||||||
|
# NuGet Packages
|
||||||
|
*.nupkg
|
||||||
|
# NuGet Symbol Packages
|
||||||
|
*.snupkg
|
||||||
|
# The packages folder can be ignored because of Package Restore
|
||||||
|
**/[Pp]ackages/*
|
||||||
|
# except build/, which is used as an MSBuild target.
|
||||||
|
!**/[Pp]ackages/build/
|
||||||
|
# Uncomment if necessary however generally it will be regenerated when needed
|
||||||
|
#!**/[Pp]ackages/repositories.config
|
||||||
|
# NuGet v3's project.json files produces more ignorable files
|
||||||
|
*.nuget.props
|
||||||
|
*.nuget.targets
|
||||||
|
|
||||||
|
# Microsoft Azure Build Output
|
||||||
|
csx/
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Microsoft Azure Emulator
|
||||||
|
ecf/
|
||||||
|
rcf/
|
||||||
|
|
||||||
|
# Windows Store app package directories and files
|
||||||
|
AppPackages/
|
||||||
|
BundleArtifacts/
|
||||||
|
Package.StoreAssociation.xml
|
||||||
|
_pkginfo.txt
|
||||||
|
*.appx
|
||||||
|
*.appxbundle
|
||||||
|
*.appxupload
|
||||||
|
|
||||||
|
# Visual Studio cache files
|
||||||
|
# files ending in .cache can be ignored
|
||||||
|
*.[Cc]ache
|
||||||
|
# but keep track of directories ending in .cache
|
||||||
|
!?*.[Cc]ache/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
ClientBin/
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.dbproj.schemaview
|
||||||
|
*.jfm
|
||||||
|
*.pfx
|
||||||
|
*.publishsettings
|
||||||
|
orleans.codegen.cs
|
||||||
|
|
||||||
|
# Including strong name files can present a security risk
|
||||||
|
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||||
|
#*.snk
|
||||||
|
|
||||||
|
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||||
|
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||||
|
#bower_components/
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file
|
||||||
|
# to a newer Visual Studio version. Backup files are not needed,
|
||||||
|
# because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
ServiceFabricBackup/
|
||||||
|
*.rptproj.bak
|
||||||
|
|
||||||
|
# SQL Server files
|
||||||
|
*.mdf
|
||||||
|
*.ldf
|
||||||
|
*.ndf
|
||||||
|
|
||||||
|
# Business Intelligence projects
|
||||||
|
*.rdl.data
|
||||||
|
*.bim.layout
|
||||||
|
*.bim_*.settings
|
||||||
|
*.rptproj.rsuser
|
||||||
|
*- [Bb]ackup.rdl
|
||||||
|
*- [Bb]ackup ([0-9]).rdl
|
||||||
|
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||||
|
|
||||||
|
# Microsoft Fakes
|
||||||
|
FakesAssemblies/
|
||||||
|
|
||||||
|
# GhostDoc plugin setting file
|
||||||
|
*.GhostDoc.xml
|
||||||
|
|
||||||
|
# Node.js Tools for Visual Studio
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Visual Studio 6 build log
|
||||||
|
*.plg
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace options file
|
||||||
|
*.opt
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||||
|
*.vbw
|
||||||
|
|
||||||
|
# Visual Studio LightSwitch build output
|
||||||
|
**/*.HTMLClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/ModelManifest.xml
|
||||||
|
**/*.Server/GeneratedArtifacts
|
||||||
|
**/*.Server/ModelManifest.xml
|
||||||
|
_Pvt_Extensions
|
||||||
|
|
||||||
|
# Paket dependency manager
|
||||||
|
.paket/paket.exe
|
||||||
|
paket-files/
|
||||||
|
|
||||||
|
# FAKE - F# Make
|
||||||
|
.fake/
|
||||||
|
|
||||||
|
# CodeRush personal settings
|
||||||
|
.cr/personal
|
||||||
|
|
||||||
|
# Python Tools for Visual Studio (PTVS)
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Cake - Uncomment if you are using it
|
||||||
|
# tools/**
|
||||||
|
# !tools/packages.config
|
||||||
|
|
||||||
|
# Tabs Studio
|
||||||
|
*.tss
|
||||||
|
|
||||||
|
# Telerik's JustMock configuration file
|
||||||
|
*.jmconfig
|
||||||
|
|
||||||
|
# BizTalk build output
|
||||||
|
*.btp.cs
|
||||||
|
*.btm.cs
|
||||||
|
*.odx.cs
|
||||||
|
*.xsd.cs
|
||||||
|
|
||||||
|
# OpenCover UI analysis results
|
||||||
|
OpenCover/
|
||||||
|
|
||||||
|
# Azure Stream Analytics local run output
|
||||||
|
ASALocalRun/
|
||||||
|
|
||||||
|
# MSBuild Binary and Structured Log
|
||||||
|
*.binlog
|
||||||
|
|
||||||
|
# NVidia Nsight GPU debugger configuration file
|
||||||
|
*.nvuser
|
||||||
|
|
||||||
|
# MFractors (Xamarin productivity tool) working folder
|
||||||
|
.mfractor/
|
||||||
|
|
||||||
|
# Local History for Visual Studio
|
||||||
|
.localhistory/
|
||||||
|
|
||||||
|
# BeatPulse healthcheck temp database
|
||||||
|
healthchecksdb
|
||||||
|
|
||||||
|
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||||
|
MigrationBackup/
|
||||||
|
|
||||||
|
vendor/glew-2.1.0/
|
||||||
|
vendor/glfw-3.3.2.bin.WIN32/
|
||||||
|
vendor/glfw-3.3.2.bin.WIN64/
|
||||||
|
|
||||||
|
sdk/
|
||||||
|
|
||||||
|
codewarrior/reVC.mcp
|
||||||
|
codewarrior/reVC_Data/
|
||||||
|
codewarrior/Release/
|
||||||
|
codewarrior/Debug/
|
||||||
|
|
||||||
|
src/extras/GitSHA1.cpp
|
||||||
|
# vc-sandbox: original game data never enters this repo
|
||||||
|
/anim/
|
||||||
|
/Audio/
|
||||||
|
/audio/
|
||||||
|
/movies/
|
||||||
|
/mp3/
|
||||||
|
/mss/
|
||||||
|
/skins/
|
||||||
|
/txd/
|
||||||
|
*.img
|
||||||
|
*.dir
|
||||||
|
*.gxt
|
||||||
|
*.adf
|
||||||
|
gta-vc.exe
|
||||||
|
build.log
|
||||||
|
build.err
|
||||||
|
build/web/
|
||||||
|
web/dist/
|
||||||
|
server/cars.json
|
||||||
86
LICENSE
Normal file
86
LICENSE
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
CRT Noncommercial Share-Alike License, version 1.1
|
||||||
|
|
||||||
|
Copyright (c) 2026 CRTkafa (CRT)
|
||||||
|
Project home: https://git.crt.fyi/CRT/vc-online
|
||||||
|
|
||||||
|
1. What this license covers
|
||||||
|
|
||||||
|
This license covers everything CRTkafa wrote for this project ("the Work"): the online part of the engine
|
||||||
|
(src/online and every change marked ONLINE in the rest of src), the game server (server/), the web page and
|
||||||
|
shell (web/), the desktop app (desktop/), the tools (tools/), the online game data (gamefiles/online/), the
|
||||||
|
documentation and the pictures in docs/.
|
||||||
|
|
||||||
|
It does not cover the code this project is built on: re3 / reVC, librw and the other libraries in src/ and
|
||||||
|
vendor/ keep their own terms (see docs/UPSTREAM.md). It does not cover the original game's files, which are not in
|
||||||
|
this repository and must come from your own copy of the game.
|
||||||
|
|
||||||
|
2. What you may do
|
||||||
|
|
||||||
|
You may use, copy, study, change, run and share the Work, and build your own projects on it, as long as you keep
|
||||||
|
every condition below. Anything this license does not allow is not allowed.
|
||||||
|
|
||||||
|
3. Never commercial
|
||||||
|
|
||||||
|
You may not use the Work or anything built on it to earn money or anything else of value, in any form and at any
|
||||||
|
scale. That includes, and is not limited to: selling it or access to it; paid accounts, items, skins, ranks,
|
||||||
|
priority or any other paid feature; advertising; sponsorships and paid promotion; affiliate links; asking for
|
||||||
|
donations, tips or subscriptions for it or for running it; tokens, NFTs or other crypto schemes. This holds just
|
||||||
|
the same when the Work runs as a service that people reach over a network.
|
||||||
|
|
||||||
|
4. Credit CRTkafa and link here
|
||||||
|
|
||||||
|
Every copy, every changed version, every project built on the Work and every public deployment of any of them
|
||||||
|
must credit CRTkafa as the original author and link to https://git.crt.fyi/CRT/vc-online.
|
||||||
|
|
||||||
|
- In source code: keep this LICENSE file and keep the credit and the link in your README.
|
||||||
|
- In anything people play or use (a website, a server, an app): show the credit and the link where players can
|
||||||
|
find them, at least in an about or credits screen reachable from the game's menu or its start page.
|
||||||
|
|
||||||
|
You may give your project any name; it does not have to be called CRT City. You may not remove, hide or shorten
|
||||||
|
the credit, and you may not suggest that CRTkafa made, approved or supports your version.
|
||||||
|
|
||||||
|
5. Keep it open source
|
||||||
|
|
||||||
|
If you share a changed version of the Work, or let other people use one over a network (for example by hosting
|
||||||
|
a page or a game server people play on), you must publish the complete source code of your version (client,
|
||||||
|
server, tools, and the data and scripts you wrote to build and run it) publicly and free of charge, under this
|
||||||
|
same license, at the same time it becomes available. Link to that source from the same about or credits screen.
|
||||||
|
|
||||||
|
6. Your own parts are yours
|
||||||
|
|
||||||
|
What you write yourself in your version (new code, data, art, sound, text) belongs to you. You may put those parts
|
||||||
|
under any license you choose as well, for example MIT, GPL or a Creative Commons license, as long as that license
|
||||||
|
lets them be published together with your version as section 5 asks and does not take away any condition of this
|
||||||
|
license. The parts that come from the Work stay under this license, and your version as a whole, the Work together
|
||||||
|
with your parts, is still shared non-commercially, with the credit and the full source, as sections 3 to 5 say.
|
||||||
|
|
||||||
|
7. The original game and its owners
|
||||||
|
|
||||||
|
This project is a fan-made, non-commercial project. It is not made, approved, endorsed or supported by Rockstar
|
||||||
|
Games or Take-Two Interactive, and it has no connection to them. Grand Theft Auto, Vice City and every related name,
|
||||||
|
logo, character, model, map, sound and piece of music are trademarks or copyrighted works of their owners. Nothing
|
||||||
|
in this license gives anyone any right to them.
|
||||||
|
|
||||||
|
- No game files: this repository holds none of the original game's files, and no copy or version of the Work may
|
||||||
|
hold, ship, upload or link to them. Every player and every host needs their own legally bought copy of the game.
|
||||||
|
- No piracy: the Work must not be used to share, sell or give access to the game itself, to unlock it without a
|
||||||
|
copy, or to get around its protection.
|
||||||
|
- Rights holders: if you own rights in something here and want it changed or removed, write to hi@crt.fyi. It will
|
||||||
|
be looked at and, where the request is valid, changed or taken down promptly. Anyone who runs a version of the
|
||||||
|
Work must answer such requests the same way.
|
||||||
|
|
||||||
|
8. Keep the notices
|
||||||
|
|
||||||
|
Do not remove or change the copyright line, this license, or the credits to the upstream authors in
|
||||||
|
docs/UPSTREAM.md.
|
||||||
|
|
||||||
|
9. When the license ends
|
||||||
|
|
||||||
|
If you break any condition, your rights under this license end at once, without notice. If it is the first
|
||||||
|
time and you fix every breach within 30 days of being told about it, your rights come back.
|
||||||
|
|
||||||
|
10. No warranty
|
||||||
|
|
||||||
|
The Work is given as it is, without any warranty of any kind. In no case is the author liable for any claim,
|
||||||
|
damage or other liability arising from the Work or its use. You alone are responsible for how you use the Work,
|
||||||
|
for the copy of the game you use it with, and for anything you host or share.
|
||||||
111
README.md
Normal file
111
README.md
Normal file
|
|
@ -0,0 +1,111 @@
|
||||||
|
# vice city online
|
||||||
|
|
||||||
|
gta vice city. multiplayer. in a browser tab. no install.
|
||||||
|
|
||||||
|
**[gta.crt.fyi](https://gta.crt.fyi/)**: free roam, up to 32 players, phone and desktop.
|
||||||
|
|
||||||
|
this repo is the bare online core, the way it stood in its first week: connect, player and car sync, chat, vehicles. the live game has grown a lot on top of it since. that part stays closed.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
i took [reVC](docs/UPSTREAM.md), the reversed source of the game, compiled it to WebAssembly, and wrote the online part on top: netcode, server, streaming, touch controls, ui. the game was never meant to do any of this :)
|
||||||
|
|
||||||
|
## what's in it
|
||||||
|
|
||||||
|
**multiplayer**
|
||||||
|
- own WebSocket server, players and cars synced by snapshots
|
||||||
|
- passengers: get in a car someone else is driving
|
||||||
|
- pvp with real gunfire, kill feed, spawn protection, passive mode
|
||||||
|
- name tags over every player, so you can tell them from the crowd. change yours from the pause menu
|
||||||
|
- chat with bubbles over heads, player list, ping and fps on screen
|
||||||
|
- reconnects by itself when the line drops
|
||||||
|
|
||||||
|
**free roam, not story mode**
|
||||||
|
- spawn straight into the world: no missions, no cutscenes, no wanted level
|
||||||
|
- 81 vehicles by category, called from a menu with real pictures from the game
|
||||||
|
- weapon wheel, unlimited sprint, money from the start
|
||||||
|
- radio strip with the game's own station logos. on the phone, tap one and you're tuned. your station follows you to the next car
|
||||||
|
- stuck in a wall? `/stuck` in chat
|
||||||
|
- swimming instead of drowning
|
||||||
|
- bikes grip more, sand is drivable, streets are busier. the old bug that kept every car on skid grip after its first slide is gone
|
||||||
|
- short death screen, then back in the game
|
||||||
|
|
||||||
|
**built for a browser**
|
||||||
|
- the game starts on a small pack of what the spawn point reads (22 MB, 11 MB gzipped)
|
||||||
|
- the 312 MB world comes down behind the running game, 8 MB at a time. every piece works the moment it lands, and what the game asks for jumps the queue
|
||||||
|
- sound, music and the rest stream by range request
|
||||||
|
- browsers that switch stacks themselves (JSPI) get an engine without Asyncify, 30% smaller. the rest get the old one
|
||||||
|
- phone: stick, held buttons that also steer the camera, the mobile game's own pictures
|
||||||
|
- english, french, german, italian, turkish. follows the browser until you change it
|
||||||
|
|
||||||
|
| | |
|
||||||
|
|---|---|
|
||||||
|
|  |  |
|
||||||
|
|  | |
|
||||||
|
|
||||||
|
## controls
|
||||||
|
|
||||||
|
| key | |
|
||||||
|
|---|---|
|
||||||
|
| WASD | move |
|
||||||
|
| Space / Shift | jump / run |
|
||||||
|
| Left / Right mouse | fire / aim |
|
||||||
|
| F | enter car |
|
||||||
|
| R / wheel | radio, in a car |
|
||||||
|
| Hold Q | weapon wheel |
|
||||||
|
| B | vehicles |
|
||||||
|
| T | chat |
|
||||||
|
| Tab | players |
|
||||||
|
| P | passive mode |
|
||||||
|
|
||||||
|
## how it's put together
|
||||||
|
|
||||||
|
```
|
||||||
|
src/online/ netcode inside the game
|
||||||
|
src/core/CdStreamWeb.cpp world streaming over http
|
||||||
|
server/ game server (bun, websocket)
|
||||||
|
web/shell/ the page: loading, menus, tags, chat, touch
|
||||||
|
gamefiles/online/ all tuning and strings, json with schemas
|
||||||
|
tools/ build, manifest, start pack, pictures
|
||||||
|
```
|
||||||
|
|
||||||
|
## run it
|
||||||
|
|
||||||
|
game files are not in this repo, and neither is reVC. you bring both:
|
||||||
|
|
||||||
|
- your own copy of the game (pc version, the folder with `gta-vc.exe`)
|
||||||
|
- your own copy of reVC, the reversed source this runs on (a folder or a git address). the patch fits reVC commit `f8b78769` (`patches/REVC_BASE`), the last one of the miami branch
|
||||||
|
|
||||||
|
you need [bun](https://bun.sh), git and [emscripten](https://emscripten.org/docs/getting_started/downloads.html) (emsdk 6.0.13 or newer).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
EMSDK=/opt/emsdk ./build.sh /path/to/your/reVC
|
||||||
|
cp -r gamefiles/. <game dir>/ # the online data next to your game files
|
||||||
|
bun tools/map-icons.ts <game dir> # map icons, read from your own data/main.scm
|
||||||
|
bun tools/make-manifest.ts <game dir>
|
||||||
|
bun tools/serve.ts web/dist <game dir> 8790
|
||||||
|
bun server/main.ts
|
||||||
|
```
|
||||||
|
|
||||||
|
`build.sh` puts reVC, our patch and our code together in `build/revc` and lands the engine in `web/dist`. new pictures: `tools/thumbs.ts`, `tools/readme-shots.ts`.
|
||||||
|
|
||||||
|
## license
|
||||||
|
|
||||||
|
the online part, the server, the page, the tools and the docs are mine, under the [CRT Noncommercial Share-Alike License](LICENSE). short version:
|
||||||
|
|
||||||
|
- **never commercial.** no selling, no paid stuff, no ads, no sponsors, no donations for it
|
||||||
|
- **credit CRTkafa and link [git.crt.fyi/CRT/vc-online](https://git.crt.fyi/CRT/vc-online)**, in your readme and in your game (an about or credits screen is enough)
|
||||||
|
- **keep it open source.** host or share your own version and you publish its full source, under the same license
|
||||||
|
- name it whatever you like. it doesn't have to be crt city
|
||||||
|
- **what you write yourself is yours.** put your own parts under any license you like (MIT, GPL, ...), the parts from here stay under this one
|
||||||
|
- **no game files, no piracy.** never ship, upload or link the game's files. everyone needs their own copy
|
||||||
|
|
||||||
|
the code underneath (re3 / reVC, librw) keeps its own terms, see [docs/UPSTREAM.md](docs/UPSTREAM.md). the game's own files are not here and never will be.
|
||||||
|
|
||||||
|
## greetz
|
||||||
|
|
||||||
|
aap, Fire_Head, shfil, erorcun, Nick007J, Serge and everyone behind re3 / reVC and librw. none of this exists without them. their readme, history and license notes: [docs/UPSTREAM.md](docs/UPSTREAM.md).
|
||||||
|
|
||||||
|
their terms apply here too: educational, documentation and modding use. no commercial use, no piracy.
|
||||||
|
|
||||||
|
CRT · [x.com/CRTkafa](https://x.com/CRTkafa)
|
||||||
53
build.sh
Executable file
53
build.sh
Executable file
|
|
@ -0,0 +1,53 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Builds the game engine from YOUR copy of reVC plus this repo.
|
||||||
|
#
|
||||||
|
# This repo does not contain reVC and does not say where to get it. Bring your own copy:
|
||||||
|
# ./build.sh /path/to/reVC a folder (a git checkout or plain files)
|
||||||
|
# ./build.sh https://host/reVC.git a git address you have the right to use
|
||||||
|
#
|
||||||
|
# Needs: bash, git, and Emscripten (emsdk) 6.0.13 or newer: EMSDK=/path/to/emsdk (default /opt/emsdk).
|
||||||
|
# Result: web/dist/revc.js, revc.wasm (+ the -jspi pair). Game data comes from your own copy of the game.
|
||||||
|
set -euo pipefail
|
||||||
|
ROOT=$(cd "$(dirname "$0")" && pwd)
|
||||||
|
BASE=$(cat "$ROOT/patches/REVC_BASE")
|
||||||
|
SRC=${1:-}
|
||||||
|
JOBS=${JOBS:-$(nproc 2>/dev/null || echo 8)}
|
||||||
|
[ -n "$SRC" ] || { sed -n '2,9p' "$0" | sed 's/^# \{0,1\}//'; exit 2; }
|
||||||
|
|
||||||
|
WORK="$ROOT/build/revc"
|
||||||
|
rm -rf "$WORK"; mkdir -p "$ROOT/build"
|
||||||
|
echo "== reVC from $SRC"
|
||||||
|
if [ -d "$SRC" ]; then
|
||||||
|
if [ -d "$SRC/.git" ]; then git clone -q "$SRC" "$WORK"; else cp -a "$SRC" "$WORK"; fi
|
||||||
|
else
|
||||||
|
git clone -q "$SRC" "$WORK"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "$WORK"
|
||||||
|
if [ -d .git ] && git cat-file -e "$BASE^{commit}" 2>/dev/null; then
|
||||||
|
git -c advice.detachedHead=false checkout -q "$BASE"
|
||||||
|
APPLY=(git apply --3way --whitespace=nowarn)
|
||||||
|
echo "== at reVC $BASE"
|
||||||
|
else
|
||||||
|
echo "!! this copy is not a git checkout holding reVC $BASE: trying anyway, the patch may not fit"
|
||||||
|
[ -d .git ] || git init -q
|
||||||
|
APPLY=(git apply --whitespace=nowarn)
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "== our changes to reVC"
|
||||||
|
"${APPLY[@]}" "$ROOT/patches/revc.patch"
|
||||||
|
while IFS= read -r f; do [ -n "$f" ] && rm -rf -- "$f"; done < "$ROOT/patches/revc-removed.txt"
|
||||||
|
|
||||||
|
echo "== our own code"
|
||||||
|
for d in src vendor web tools gamefiles; do [ -d "$ROOT/$d" ] && cp -a "$ROOT/$d/." "$WORK/$d/"; done
|
||||||
|
|
||||||
|
echo "== engine ($JOBS jobs)"
|
||||||
|
# Both engines: the page gives browsers that switch stacks themselves (Chrome) revc-jspi, the others revc. The
|
||||||
|
# second build only links again.
|
||||||
|
bash tools/build-web.sh "$JOBS"
|
||||||
|
WEB_ASYNC=jspi bash tools/build-web.sh "$JOBS"
|
||||||
|
mkdir -p "$ROOT/web/dist"
|
||||||
|
# Everything the build put there: the engine, and the page when the build copies it in.
|
||||||
|
cp -a web/dist/. "$ROOT/web/dist/"
|
||||||
|
echo "== done: $ROOT/web/dist"
|
||||||
|
ls -la "$ROOT/web/dist" | grep revc
|
||||||
15
bun.lock
Normal file
15
bun.lock
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"lockfileVersion": 2,
|
||||||
|
"configVersion": 1,
|
||||||
|
"workspaces": {
|
||||||
|
"": {
|
||||||
|
"name": "vc-online",
|
||||||
|
"devDependencies": {
|
||||||
|
"playwright-core": "^1.64.1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"packages": {
|
||||||
|
"playwright-core": ["playwright-core@1.64.1", "", { "bin": { "playwright-core": "cli.js" } }, "sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ=="],
|
||||||
|
}
|
||||||
|
}
|
||||||
196
docs/UPSTREAM.md
Normal file
196
docs/UPSTREAM.md
Normal file
|
|
@ -0,0 +1,196 @@
|
||||||
|
<img src="https://github.com/GTAmodding/re3/blob/miami/res/images/logo_1024.png?raw=true" alt="reVC logo" width="200">
|
||||||
|
|
||||||
|
[](https://actions-badge.atrox.dev/GTAmodding/re3/goto?ref=miami)
|
||||||
|
<a href="https://discord.gg/RFNbjsUMGg"><img src="https://img.shields.io/badge/discord-join-7289DA.svg?logo=discord&longCache=true&style=flat" /></a>
|
||||||
|
|
||||||
|
## Intro
|
||||||
|
|
||||||
|
In this repository you'll find the fully reversed source code for GTA III ([master](https://github.com/GTAmodding/re3/tree/master/) branch) and GTA VC ([miami](https://github.com/GTAmodding/re3/tree/miami/) branch).
|
||||||
|
|
||||||
|
It has been tested and works on Windows, Linux, MacOS and FreeBSD, on x86, amd64, arm and arm64.\
|
||||||
|
Rendering is handled either by original RenderWare (D3D8)
|
||||||
|
or the reimplementation [librw](https://github.com/aap/librw) (D3D9, OpenGL 2.1 or above, OpenGL ES 2.0 or above).\
|
||||||
|
Audio is done with MSS (using dlls from original GTA) or OpenAL.
|
||||||
|
|
||||||
|
We cannot build for PS2 or Xbox yet. If you're interested in doing so, get in touch with us.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
- reVC requires game assets to work, so you **must** own [a copy of GTA Vice City](https://store.steampowered.com/app/12110/Grand_Theft_Auto_Vice_City/).
|
||||||
|
- Build reVC or download the latest build:
|
||||||
|
- [Windows D3D9 MSS 32bit](https://nightly.link/GTAmodding/re3/workflows/reVC_msvc_x86/miami/reVC_Release_win-x86-librw_d3d9-mss.zip)
|
||||||
|
- [Windows D3D9 64bit](https://nightly.link/GTAmodding/re3/workflows/reVC_msvc_amd64/miami/reVC_Release_win-amd64-librw_d3d9-oal.zip)
|
||||||
|
- [Windows OpenGL 64bit](https://nightly.link/GTAmodding/re3/workflows/reVC_msvc_amd64/miami/reVC_Release_win-amd64-librw_gl3_glfw-oal.zip)
|
||||||
|
- [Linux 64bit](https://nightly.link/GTAmodding/re3/workflows/build-cmake-conan/miami/ubuntu-18.04-gl3.zip)
|
||||||
|
- [MacOS 64bit x86-64](https://nightly.link/GTAmodding/re3/workflows/build-cmake-conan/miami/macos-latest-gl3.zip)
|
||||||
|
- Extract the downloaded zip over your GTA VC directory and run reVC. The zip includes the binary, updated and additional gamefiles and in case of OpenAL the required dlls.
|
||||||
|
|
||||||
|
## Screenshots
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
## Improvements
|
||||||
|
|
||||||
|
We have implemented a number of changes and improvements to the original game.
|
||||||
|
They can be configured in `core/config.h`.
|
||||||
|
Some of them can be toggled at runtime, some cannot.
|
||||||
|
|
||||||
|
* Fixed a lot of smaller and bigger bugs
|
||||||
|
* User files (saves and settings) stored in GTA root directory
|
||||||
|
* Settings stored in reVC.ini file instead of gta_vc.set
|
||||||
|
* Debug menu to do and change various things (Ctrl-M to open)
|
||||||
|
* Debug camera (Ctrl-B to toggle)
|
||||||
|
* Rotatable camera
|
||||||
|
* XInput controller support (Windows)
|
||||||
|
* No loading screens between islands ("map memory usage" in menu)
|
||||||
|
* Rendering
|
||||||
|
* Widescreen support (properly scaled HUD, Menu and FOV)
|
||||||
|
* PS2 MatFX (vehicle reflections)
|
||||||
|
* PS2 alpha test (better rendering of transparency)
|
||||||
|
* Xbox vehicle rendering
|
||||||
|
* Xbox world lightmap rendering (needs Xbox map)
|
||||||
|
* Xbox ped rim light
|
||||||
|
* Xbox screen rain droplets
|
||||||
|
* More customizable colourfilter
|
||||||
|
* Menu
|
||||||
|
* More options
|
||||||
|
* Controller configuration menu
|
||||||
|
* ...
|
||||||
|
* Can load DFFs and TXDs from other platforms, possibly with a performance penalty
|
||||||
|
* ...
|
||||||
|
|
||||||
|
## To-Do
|
||||||
|
|
||||||
|
The following things would be nice to have/do:
|
||||||
|
|
||||||
|
* Fix physics for high FPS
|
||||||
|
* Improve performance on lower end devices, especially the OpenGL layer on the Raspberry Pi (if you have experience with this, please get in touch)
|
||||||
|
* [PS2 port](https://github.com/GTAmodding/re3/wiki/PS2-port)
|
||||||
|
* Xbox port (not quite as important)
|
||||||
|
* reverse remaining unused/debug functions
|
||||||
|
* compare CodeWarrior build with original binary for more accurate code (very tedious)
|
||||||
|
|
||||||
|
## Modding
|
||||||
|
|
||||||
|
Asset modifications (models, texture, handling, script, ...) should work the same way as with original GTA for the most part.
|
||||||
|
|
||||||
|
Mods that make changes to the code (dll/asi, CLEO, limit adjusters) will *not* work.
|
||||||
|
Some things these mods do are already implemented in re3 (much of SkyGFX, GInput, SilentPatch, Widescreen fix),
|
||||||
|
others can easily be achieved (increasing limis, see `config.h`),
|
||||||
|
others will simply have to be rewritten and integrated into the code directly.
|
||||||
|
Sorry for the inconvenience.
|
||||||
|
|
||||||
|
## Building from Source
|
||||||
|
|
||||||
|
When using premake, you may want to point GTA_VC_RE_DIR environment variable to GTA Vice City root folder if you want the executable to be moved there via post-build script.
|
||||||
|
|
||||||
|
Clone the repository with `git clone --recursive -b miami https://github.com/GTAmodding/re3.git reVC`. Then `cd reVC` into the cloned repository.
|
||||||
|
|
||||||
|
<details><summary>Linux Premake</summary>
|
||||||
|
|
||||||
|
For Linux using premake, proceed: [Building on Linux](https://github.com/GTAmodding/re3/wiki/Building-on-Linux)
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details><summary>Linux Conan</summary>
|
||||||
|
|
||||||
|
Install python and conan, and then run build.
|
||||||
|
```
|
||||||
|
conan export vendor/librw librw/master@
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
conan install .. reVC/master@ -if build -o reVC:audio=openal -o librw:platform=gl3 -o librw:gl3_gfxlib=glfw --build missing -s reVC:build_type=RelWithDebInfo -s librw:build_type=RelWithDebInfo
|
||||||
|
conan build .. -if build -bf build -pf package
|
||||||
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details><summary>MacOS Premake</summary>
|
||||||
|
|
||||||
|
For MacOS using premake, proceed: [Building on MacOS](https://github.com/GTAmodding/re3/wiki/Building-on-MacOS)
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details><summary>FreeBSD</summary>
|
||||||
|
|
||||||
|
For FreeBSD using premake, proceed: [Building on FreeBSD](https://github.com/GTAmodding/re3/wiki/Building-on-FreeBSD)
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details><summary>Windows</summary>
|
||||||
|
|
||||||
|
Assuming you have Visual Studio 2015/2017/2019:
|
||||||
|
- Run one of the `premake-vsXXXX.cmd` variants on root folder.
|
||||||
|
- Open build/reVC.sln with Visual Studio and compile the solution.
|
||||||
|
|
||||||
|
Microsoft recently discontinued its downloads of the DX9 SDK. You can download an archived version here: https://archive.org/details/dxsdk_jun10
|
||||||
|
|
||||||
|
**If you choose OpenAL on Windows** You must read [Running OpenAL build on Windows](https://github.com/GTAmodding/re3/wiki/Running-OpenAL-build-on-Windows).
|
||||||
|
</details>
|
||||||
|
|
||||||
|
> :information_source: premake has an `--with-lto` option if you want the project to be compiled with Link Time Optimization.
|
||||||
|
|
||||||
|
> :information_source: There are various settings in [config.h](https://github.com/GTAmodding/re3/tree/miami/src/core/config.h), you may want to take a look there.
|
||||||
|
|
||||||
|
> :information_source: reVC uses completely homebrew RenderWare-replacement rendering engine; [librw](https://github.com/aap/librw/). librw comes as submodule of re3, but you also can use LIBRW enviorenment variable to specify path to your own librw.
|
||||||
|
|
||||||
|
If you feel the need, you can also use CodeWarrior 7 to compile reVC using the supplied codewarrior/reVC.mcp project - this requires the original RW34 libraries, and the DX8 SDK. The build is unstable compared to the MSVC builds though, and is mostly meant to serve as a reference.
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
As long as it's not linux/cross-platform skeleton/compatibility layer, all of the code on the repo that's not behind a preprocessor condition(like FIX_BUGS) are **completely** reversed code from original binaries.
|
||||||
|
|
||||||
|
We **don't** accept custom codes, as long as it's not wrapped via preprocessor conditions, or it's linux/cross-platform skeleton/compatibility layer.
|
||||||
|
|
||||||
|
We accept only these kinds of PRs;
|
||||||
|
|
||||||
|
- A new feature that exists in at least one of the GTAs (if it wasn't in III/VC then it doesn't have to be decompilation)
|
||||||
|
- Game, UI or UX bug fixes (if it's a fix to original code, it should be behind FIX_BUGS)
|
||||||
|
- Platform-specific and/or unused code that's not been reversed yet
|
||||||
|
- Makes reversed code more understandable/accurate, as in "which code would produce this assembly".
|
||||||
|
- A new cross-platform skeleton/compatibility layer, or improvements to them
|
||||||
|
- Translation fixes, for languages original game supported
|
||||||
|
- Code that increase maintainability
|
||||||
|
|
||||||
|
We have a [Coding Style](https://github.com/GTAmodding/re3/blob/master/CODING_STYLE.md) document that isn't followed or enforced very well.
|
||||||
|
|
||||||
|
Do not use features from C++11 or later.
|
||||||
|
|
||||||
|
|
||||||
|
## History
|
||||||
|
|
||||||
|
re3 was started sometime in the spring of 2018,
|
||||||
|
initially as a way to test reversed collision and physics code
|
||||||
|
inside the game.
|
||||||
|
This was done by replacing single functions of the game
|
||||||
|
with their reversed counterparts using a dll.
|
||||||
|
|
||||||
|
After a bit of work the project lay dormant for about a year
|
||||||
|
and was picked up again and pushed to github in May 2019.
|
||||||
|
At the time I (aap) had reversed around 10k lines of code and estimated
|
||||||
|
the final game to have around 200-250k.
|
||||||
|
Others quickly joined the effort (Fire_Head, shfil, erorcun and Nick007J
|
||||||
|
in time order, and Serge a bit later) and we made very quick progress
|
||||||
|
throughout the summer of 2019
|
||||||
|
after which the pace slowed down a bit.
|
||||||
|
|
||||||
|
Due to everyone staying home during the start of the Corona pandemic
|
||||||
|
everybody had a lot of time to work on re3 again and
|
||||||
|
we finally got a standalone exe in April 2020 (around 180k lines by then).
|
||||||
|
|
||||||
|
After the initial excitement and fixing and polishing the code further,
|
||||||
|
reVC was started in early May 2020 by starting from re3 code,
|
||||||
|
not by starting from scratch replacing functions with a dll.
|
||||||
|
After a few months of mostly steady progress we considered reVC
|
||||||
|
finished in December.
|
||||||
|
|
||||||
|
Since then we have started reLCS, which is currently work in progress.
|
||||||
|
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
We don't feel like we're in a position to give this code a license.\
|
||||||
|
The code should only be used for educational, documentation and modding purposes.\
|
||||||
|
We do not encourage piracy or commercial use.\
|
||||||
|
Please keep derivate work open source and give proper credit.
|
||||||
BIN
docs/launch/shot-two-players.png
Normal file
BIN
docs/launch/shot-two-players.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 758 KiB |
BIN
docs/shots/cars.jpg
Normal file
BIN
docs/shots/cars.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 107 KiB |
BIN
docs/shots/vehicles.jpg
Normal file
BIN
docs/shots/vehicles.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 93 KiB |
BIN
docs/shots/wheel.jpg
Normal file
BIN
docs/shots/wheel.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 96 KiB |
921
gamefiles/online/menu.json
Normal file
921
gamefiles/online/menu.json
Normal file
|
|
@ -0,0 +1,921 @@
|
||||||
|
{
|
||||||
|
"$schema": "./menu.schema.json",
|
||||||
|
"comment": "Online menus. weapons: type = eWeaponType number from WeaponType.h. cars: model = model name from default.ide (cars and bikes); thumbs/<model>.jpg is its picture. featured = the six shown first. startWeapons = weapon types given when joining. help = the permanent command list on screen.",
|
||||||
|
"keys": {
|
||||||
|
"weapons": "q",
|
||||||
|
"cars": "b",
|
||||||
|
"passive": "p",
|
||||||
|
"name": "n"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"promptSeconds": 45,
|
||||||
|
"fightLockSeconds": 10,
|
||||||
|
"title": "CHOOSE A NAME",
|
||||||
|
"placeholder": "your name",
|
||||||
|
"ok": "OK",
|
||||||
|
"locked": "you fired in the last few seconds: wait",
|
||||||
|
"away": "paused: nobody can hit you",
|
||||||
|
"back": "back in the game"
|
||||||
|
},
|
||||||
|
"startArmour": 100,
|
||||||
|
"startMoney": 1000000,
|
||||||
|
"death": {
|
||||||
|
"title": "WASTED",
|
||||||
|
"killedBy": "by",
|
||||||
|
"feedSeconds": 6
|
||||||
|
},
|
||||||
|
"tags": {
|
||||||
|
"fullScaleDistance": 25,
|
||||||
|
"minScale": 0.7
|
||||||
|
},
|
||||||
|
"lookSettleMs": 250,
|
||||||
|
"helpSeconds": 25,
|
||||||
|
"desktopRenderWidth": 1920,
|
||||||
|
"startWeapons": [
|
||||||
|
1,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
6,
|
||||||
|
9,
|
||||||
|
10,
|
||||||
|
12,
|
||||||
|
15,
|
||||||
|
17,
|
||||||
|
18,
|
||||||
|
19,
|
||||||
|
20,
|
||||||
|
21,
|
||||||
|
22,
|
||||||
|
23,
|
||||||
|
24,
|
||||||
|
25,
|
||||||
|
26,
|
||||||
|
27,
|
||||||
|
28,
|
||||||
|
30,
|
||||||
|
31,
|
||||||
|
32,
|
||||||
|
33
|
||||||
|
],
|
||||||
|
"weapons": [
|
||||||
|
{
|
||||||
|
"name": "Brass Knuckles",
|
||||||
|
"type": 1,
|
||||||
|
"ammo": 1,
|
||||||
|
"icon": "Brass-Knuckles"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Golf Club",
|
||||||
|
"type": 3,
|
||||||
|
"ammo": 1,
|
||||||
|
"icon": "golf"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Nightstick",
|
||||||
|
"type": 4,
|
||||||
|
"ammo": 1,
|
||||||
|
"icon": "baton"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Knife",
|
||||||
|
"type": 5,
|
||||||
|
"ammo": 1,
|
||||||
|
"icon": "knife"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Baseball Bat",
|
||||||
|
"type": 6,
|
||||||
|
"ammo": 1,
|
||||||
|
"icon": "bat"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Machete",
|
||||||
|
"type": 9,
|
||||||
|
"ammo": 1,
|
||||||
|
"icon": "machette"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Katana",
|
||||||
|
"type": 10,
|
||||||
|
"ammo": 1,
|
||||||
|
"icon": "katana"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Chainsaw",
|
||||||
|
"type": 11,
|
||||||
|
"ammo": 1,
|
||||||
|
"icon": "chainsaw"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Grenades",
|
||||||
|
"type": 12,
|
||||||
|
"ammo": 99,
|
||||||
|
"icon": "grenade"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Tear Gas",
|
||||||
|
"type": 14,
|
||||||
|
"ammo": 99,
|
||||||
|
"icon": "teargas"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Molotov",
|
||||||
|
"type": 15,
|
||||||
|
"ammo": 99,
|
||||||
|
"icon": "molotov"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Colt .45",
|
||||||
|
"type": 17,
|
||||||
|
"ammo": 999,
|
||||||
|
"icon": "pistol"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Python",
|
||||||
|
"type": 18,
|
||||||
|
"ammo": 999,
|
||||||
|
"icon": "python"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Shotgun",
|
||||||
|
"type": 19,
|
||||||
|
"ammo": 999,
|
||||||
|
"icon": "shotgun"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "SPAS-12",
|
||||||
|
"type": 20,
|
||||||
|
"ammo": 999,
|
||||||
|
"icon": "spaz"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Stubby Shotgun",
|
||||||
|
"type": 21,
|
||||||
|
"ammo": 999,
|
||||||
|
"icon": "stubbs"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Tec-9",
|
||||||
|
"type": 22,
|
||||||
|
"ammo": 999,
|
||||||
|
"icon": "tec9"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Uzi",
|
||||||
|
"type": 23,
|
||||||
|
"ammo": 999,
|
||||||
|
"icon": "uzi"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Ingram",
|
||||||
|
"type": 24,
|
||||||
|
"ammo": 999,
|
||||||
|
"icon": "uzi2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "MP5",
|
||||||
|
"type": 25,
|
||||||
|
"ammo": 999,
|
||||||
|
"icon": "mp5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "M4",
|
||||||
|
"type": 26,
|
||||||
|
"ammo": 999,
|
||||||
|
"icon": "m4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Ruger",
|
||||||
|
"type": 27,
|
||||||
|
"ammo": 999,
|
||||||
|
"icon": "rugger"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Sniper Rifle",
|
||||||
|
"type": 28,
|
||||||
|
"ammo": 99,
|
||||||
|
"icon": "sniper"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Rocket Launcher",
|
||||||
|
"type": 30,
|
||||||
|
"ammo": 99,
|
||||||
|
"icon": "rocket"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Flamethrower",
|
||||||
|
"type": 31,
|
||||||
|
"ammo": 999,
|
||||||
|
"icon": "flame"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "M60",
|
||||||
|
"type": 32,
|
||||||
|
"ammo": 999,
|
||||||
|
"icon": "m60"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Minigun",
|
||||||
|
"type": 33,
|
||||||
|
"ammo": 999,
|
||||||
|
"icon": "minigun"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cars": [
|
||||||
|
{
|
||||||
|
"name": "Infernus",
|
||||||
|
"model": "infernus",
|
||||||
|
"group": "Sports"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Cheetah",
|
||||||
|
"model": "cheetah",
|
||||||
|
"group": "Sports"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Banshee",
|
||||||
|
"model": "banshee",
|
||||||
|
"group": "Sports"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Comet",
|
||||||
|
"model": "comet",
|
||||||
|
"group": "Sports"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Stinger",
|
||||||
|
"model": "stinger",
|
||||||
|
"group": "Sports"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Deluxo",
|
||||||
|
"model": "deluxo",
|
||||||
|
"group": "Sports"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Hotring",
|
||||||
|
"model": "hotring",
|
||||||
|
"group": "Sports"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Hotring A",
|
||||||
|
"model": "hotrina",
|
||||||
|
"group": "Sports"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Hotring B",
|
||||||
|
"model": "hotrinb",
|
||||||
|
"group": "Sports"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Bloodring",
|
||||||
|
"model": "bloodra",
|
||||||
|
"group": "Sports"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Bloodring B",
|
||||||
|
"model": "bloodrb",
|
||||||
|
"group": "Sports"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Sabre",
|
||||||
|
"model": "sabre",
|
||||||
|
"group": "Muscle"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Sabre Turbo",
|
||||||
|
"model": "sabretur",
|
||||||
|
"group": "Muscle"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Stallion",
|
||||||
|
"model": "stallion",
|
||||||
|
"group": "Muscle"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Voodoo",
|
||||||
|
"model": "voodoo",
|
||||||
|
"group": "Muscle"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Virgo",
|
||||||
|
"model": "virgo",
|
||||||
|
"group": "Muscle"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Manana",
|
||||||
|
"model": "manana",
|
||||||
|
"group": "Muscle"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Esperanto",
|
||||||
|
"model": "esperant",
|
||||||
|
"group": "Muscle"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Idaho",
|
||||||
|
"model": "idaho",
|
||||||
|
"group": "Muscle"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Blista Compact",
|
||||||
|
"model": "blistac",
|
||||||
|
"group": "Muscle"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Admiral",
|
||||||
|
"model": "admiral",
|
||||||
|
"group": "Sedans"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Sentinel",
|
||||||
|
"model": "sentinel",
|
||||||
|
"group": "Sedans"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Sentinel XS",
|
||||||
|
"model": "sentxs",
|
||||||
|
"group": "Sedans"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Washington",
|
||||||
|
"model": "washing",
|
||||||
|
"group": "Sedans"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Glendale",
|
||||||
|
"model": "glendale",
|
||||||
|
"group": "Sedans"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Greenwood",
|
||||||
|
"model": "greenwoo",
|
||||||
|
"group": "Sedans"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Oceanic",
|
||||||
|
"model": "oceanic",
|
||||||
|
"group": "Sedans"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Hermes",
|
||||||
|
"model": "hermes",
|
||||||
|
"group": "Sedans"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Regina",
|
||||||
|
"model": "regina",
|
||||||
|
"group": "Sedans"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Perennial",
|
||||||
|
"model": "peren",
|
||||||
|
"group": "Sedans"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Stretch",
|
||||||
|
"model": "stretch",
|
||||||
|
"group": "Sedans"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Love Fist",
|
||||||
|
"model": "lovefist",
|
||||||
|
"group": "Sedans"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Landstalker",
|
||||||
|
"model": "landstal",
|
||||||
|
"group": "Off-road"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Rancher",
|
||||||
|
"model": "rancher",
|
||||||
|
"group": "Off-road"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Sandking",
|
||||||
|
"model": "sandking",
|
||||||
|
"group": "Off-road"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Patriot",
|
||||||
|
"model": "patriot",
|
||||||
|
"group": "Off-road"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "BF Injection",
|
||||||
|
"model": "bfinject",
|
||||||
|
"group": "Off-road"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Mesa",
|
||||||
|
"model": "mesa",
|
||||||
|
"group": "Off-road"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Walton",
|
||||||
|
"model": "walton",
|
||||||
|
"group": "Off-road"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Bobcat",
|
||||||
|
"model": "bobcat",
|
||||||
|
"group": "Off-road"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Vice Cheetah",
|
||||||
|
"model": "vicechee",
|
||||||
|
"group": "Off-road"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "PCJ-600",
|
||||||
|
"model": "pcj600",
|
||||||
|
"group": "Bikes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Sanchez",
|
||||||
|
"model": "sanchez",
|
||||||
|
"group": "Bikes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Angel",
|
||||||
|
"model": "angel",
|
||||||
|
"group": "Bikes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Freeway",
|
||||||
|
"model": "freeway",
|
||||||
|
"group": "Bikes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Faggio",
|
||||||
|
"model": "faggio",
|
||||||
|
"group": "Bikes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Pizza Boy",
|
||||||
|
"model": "pizzaboy",
|
||||||
|
"group": "Bikes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Taxi",
|
||||||
|
"model": "taxi",
|
||||||
|
"group": "Service"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Cabbie",
|
||||||
|
"model": "cabbie",
|
||||||
|
"group": "Service"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Kaufman Cab",
|
||||||
|
"model": "kaufman",
|
||||||
|
"group": "Service"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Zebra Cab",
|
||||||
|
"model": "zebra",
|
||||||
|
"group": "Service"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Police",
|
||||||
|
"model": "police",
|
||||||
|
"group": "Service"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "FBI Rancher",
|
||||||
|
"model": "fbiranch",
|
||||||
|
"group": "Service"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "FBI Washington",
|
||||||
|
"model": "fbicar",
|
||||||
|
"group": "Service"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Enforcer",
|
||||||
|
"model": "enforcer",
|
||||||
|
"group": "Service"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Ambulance",
|
||||||
|
"model": "ambulan",
|
||||||
|
"group": "Service"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Fire Truck",
|
||||||
|
"model": "firetruk",
|
||||||
|
"group": "Service"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Barracks",
|
||||||
|
"model": "barracks",
|
||||||
|
"group": "Service"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Securicar",
|
||||||
|
"model": "securica",
|
||||||
|
"group": "Service"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Caddy",
|
||||||
|
"model": "caddy",
|
||||||
|
"group": "Service"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Bus",
|
||||||
|
"model": "bus",
|
||||||
|
"group": "Work"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Coach",
|
||||||
|
"model": "coach",
|
||||||
|
"group": "Work"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Rumpo",
|
||||||
|
"model": "rumpo",
|
||||||
|
"group": "Work"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Pony",
|
||||||
|
"model": "pony",
|
||||||
|
"group": "Work"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Mule",
|
||||||
|
"model": "mule",
|
||||||
|
"group": "Work"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Benson",
|
||||||
|
"model": "benson",
|
||||||
|
"group": "Work"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Yankee",
|
||||||
|
"model": "yankee",
|
||||||
|
"group": "Work"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Moonbeam",
|
||||||
|
"model": "moonbeam",
|
||||||
|
"group": "Work"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Boxville",
|
||||||
|
"model": "boxville",
|
||||||
|
"group": "Work"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Burrito",
|
||||||
|
"model": "burrito",
|
||||||
|
"group": "Work"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Flatbed",
|
||||||
|
"model": "flatbed",
|
||||||
|
"group": "Work"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Linerunner",
|
||||||
|
"model": "linerun",
|
||||||
|
"group": "Work"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Packer",
|
||||||
|
"model": "packer",
|
||||||
|
"group": "Work"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Trashmaster",
|
||||||
|
"model": "trash",
|
||||||
|
"group": "Work"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Mr. Whoopee",
|
||||||
|
"model": "mrwhoop",
|
||||||
|
"group": "Work"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Spand Express",
|
||||||
|
"model": "spand",
|
||||||
|
"group": "Work"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Top Fun",
|
||||||
|
"model": "topfun",
|
||||||
|
"group": "Work"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Phoenix",
|
||||||
|
"model": "pheonix",
|
||||||
|
"group": "Muscle"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Cuban Hermes",
|
||||||
|
"model": "cuban",
|
||||||
|
"group": "Sedans"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Romero",
|
||||||
|
"model": "romero",
|
||||||
|
"group": "Sedans"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Gang Burrito",
|
||||||
|
"model": "gangbur",
|
||||||
|
"group": "Work"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"help": [
|
||||||
|
"WASD move Space jump Shift run",
|
||||||
|
"Left fire Right aim F enter car",
|
||||||
|
"T chat Tab players P passive N name",
|
||||||
|
"Hold Q weapon wheel B vehicles Esc menu",
|
||||||
|
"x.com/CRTkafa"
|
||||||
|
],
|
||||||
|
"featured": [
|
||||||
|
"infernus",
|
||||||
|
"cheetah",
|
||||||
|
"banshee",
|
||||||
|
"hotring",
|
||||||
|
"pcj600",
|
||||||
|
"sanchez"
|
||||||
|
],
|
||||||
|
"wheel": [
|
||||||
|
{
|
||||||
|
"name": "Melee",
|
||||||
|
"types": [
|
||||||
|
1,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
6,
|
||||||
|
9,
|
||||||
|
10,
|
||||||
|
11
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Thrown",
|
||||||
|
"types": [
|
||||||
|
12,
|
||||||
|
14,
|
||||||
|
15
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Pistols",
|
||||||
|
"types": [
|
||||||
|
17,
|
||||||
|
18
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Shotguns",
|
||||||
|
"types": [
|
||||||
|
19,
|
||||||
|
20,
|
||||||
|
21
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "SMG",
|
||||||
|
"types": [
|
||||||
|
22,
|
||||||
|
23,
|
||||||
|
24,
|
||||||
|
25
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Rifles",
|
||||||
|
"types": [
|
||||||
|
26,
|
||||||
|
27
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Sniper",
|
||||||
|
"types": [
|
||||||
|
28
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Heavy",
|
||||||
|
"types": [
|
||||||
|
30,
|
||||||
|
31,
|
||||||
|
32,
|
||||||
|
33
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"touch": {
|
||||||
|
"renderWidth": 1280,
|
||||||
|
"lookSpeed": 1.6,
|
||||||
|
"stickRadius": 60,
|
||||||
|
"stickDeadZone": 0.3,
|
||||||
|
"rotate": "Turn your phone sideways",
|
||||||
|
"stick": {
|
||||||
|
"up": {
|
||||||
|
"key": "w",
|
||||||
|
"code": "KeyW",
|
||||||
|
"keyCode": 87
|
||||||
|
},
|
||||||
|
"down": {
|
||||||
|
"key": "s",
|
||||||
|
"code": "KeyS",
|
||||||
|
"keyCode": 83
|
||||||
|
},
|
||||||
|
"left": {
|
||||||
|
"key": "a",
|
||||||
|
"code": "KeyA",
|
||||||
|
"keyCode": 65
|
||||||
|
},
|
||||||
|
"right": {
|
||||||
|
"key": "d",
|
||||||
|
"code": "KeyD",
|
||||||
|
"keyCode": 68
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"buttons": [
|
||||||
|
{
|
||||||
|
"label": "FIRE",
|
||||||
|
"icon": "shoot",
|
||||||
|
"mouse": 0,
|
||||||
|
"right": 4,
|
||||||
|
"bottom": 8,
|
||||||
|
"size": 22
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "AIM",
|
||||||
|
"icon": "lockon",
|
||||||
|
"mouse": 2,
|
||||||
|
"right": 28,
|
||||||
|
"bottom": 6,
|
||||||
|
"size": 15
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "JUMP",
|
||||||
|
"icon": "jump",
|
||||||
|
"key": " ",
|
||||||
|
"code": "Space",
|
||||||
|
"keyCode": 32,
|
||||||
|
"right": 6,
|
||||||
|
"bottom": 32,
|
||||||
|
"size": 15
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "RUN",
|
||||||
|
"icon": "run",
|
||||||
|
"key": "Shift",
|
||||||
|
"code": "ShiftLeft",
|
||||||
|
"keyCode": 16,
|
||||||
|
"toggle": true,
|
||||||
|
"right": 22,
|
||||||
|
"bottom": 24,
|
||||||
|
"size": 15
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "CAR",
|
||||||
|
"icon": "enterandexit",
|
||||||
|
"key": "f",
|
||||||
|
"code": "KeyF",
|
||||||
|
"keyCode": 70,
|
||||||
|
"right": 6,
|
||||||
|
"bottom": 50,
|
||||||
|
"size": 15
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "WEAPONS",
|
||||||
|
"icon": "swapgun",
|
||||||
|
"wheel": true,
|
||||||
|
"top": 3,
|
||||||
|
"right": 51,
|
||||||
|
"bar": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "VEHICLES",
|
||||||
|
"icon": "car",
|
||||||
|
"key": "b",
|
||||||
|
"code": "KeyB",
|
||||||
|
"keyCode": 66,
|
||||||
|
"top": 3,
|
||||||
|
"right": 40,
|
||||||
|
"bar": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "CHAT",
|
||||||
|
"icon": "cellphone",
|
||||||
|
"key": "t",
|
||||||
|
"code": "KeyT",
|
||||||
|
"keyCode": 84,
|
||||||
|
"top": 3,
|
||||||
|
"right": 32,
|
||||||
|
"bar": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "PLAYERS",
|
||||||
|
"key": "Tab",
|
||||||
|
"code": "Tab",
|
||||||
|
"keyCode": 9,
|
||||||
|
"top": 3,
|
||||||
|
"right": 62,
|
||||||
|
"bar": true,
|
||||||
|
"icon": "players",
|
||||||
|
"parts": [
|
||||||
|
"circle",
|
||||||
|
"StarIcon"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "PASSIVE",
|
||||||
|
"key": "p",
|
||||||
|
"code": "KeyP",
|
||||||
|
"keyCode": 80,
|
||||||
|
"top": 3,
|
||||||
|
"right": 72,
|
||||||
|
"bar": true,
|
||||||
|
"icon": "passive",
|
||||||
|
"parts": [
|
||||||
|
"circle",
|
||||||
|
"ShieldIcon"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "MENU",
|
||||||
|
"icon": "pause",
|
||||||
|
"key": "Escape",
|
||||||
|
"code": "Escape",
|
||||||
|
"keyCode": 27,
|
||||||
|
"top": 3,
|
||||||
|
"right": 25,
|
||||||
|
"bar": true,
|
||||||
|
"always": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"carGroups": [
|
||||||
|
"Sports",
|
||||||
|
"Muscle",
|
||||||
|
"Sedans",
|
||||||
|
"Off-road",
|
||||||
|
"Bikes",
|
||||||
|
"Service",
|
||||||
|
"Work"
|
||||||
|
],
|
||||||
|
"radio": [
|
||||||
|
{
|
||||||
|
"station": 0,
|
||||||
|
"icon": "wildstyle",
|
||||||
|
"name": "Wildstyle"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"station": 1,
|
||||||
|
"icon": "flash",
|
||||||
|
"name": "Flash FM"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"station": 2,
|
||||||
|
"icon": "kchat",
|
||||||
|
"name": "K-Chat"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"station": 3,
|
||||||
|
"icon": "fever",
|
||||||
|
"name": "Fever 105"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"station": 4,
|
||||||
|
"icon": "vrock",
|
||||||
|
"name": "V-Rock"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"station": 5,
|
||||||
|
"icon": "vcpr",
|
||||||
|
"name": "VCPR"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"station": 6,
|
||||||
|
"icon": "espantoso",
|
||||||
|
"name": "Radio Espantoso"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"station": 7,
|
||||||
|
"icon": "emotion",
|
||||||
|
"name": "Emotion 98.3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"station": 8,
|
||||||
|
"icon": "wave103",
|
||||||
|
"name": "Wave 103"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"station": 10,
|
||||||
|
"name": "Radio Off"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
48
gamefiles/online/menu.schema.json
Normal file
48
gamefiles/online/menu.schema.json
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||||
|
"title": "Online menus",
|
||||||
|
"type": "object",
|
||||||
|
"required": ["keys", "startWeapons", "weapons", "cars", "featured", "help"],
|
||||||
|
"properties": {
|
||||||
|
"$schema": { "type": "string" },
|
||||||
|
"comment": { "type": "string" },
|
||||||
|
"keys": {
|
||||||
|
"type": "object",
|
||||||
|
"required": ["weapons", "cars", "passive", "name"],
|
||||||
|
"properties": { "name": { "type": "string", "minLength": 1, "maxLength": 1 }, "weapons": { "type": "string", "minLength": 1, "maxLength": 1 }, "cars": { "type": "string", "minLength": 1, "maxLength": 1 }, "passive": { "type": "string", "minLength": 1, "maxLength": 1 } },
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"name": { "type": "object" },
|
||||||
|
"startArmour": { "type": "number", "minimum": 0, "maximum": 100 },
|
||||||
|
"startMoney": { "type": "integer", "minimum": 0 },
|
||||||
|
"carGroups": { "type": "array", "items": { "type": "string" } },
|
||||||
|
"death": { "type": "object" },
|
||||||
|
"tags": { "type": "object" },
|
||||||
|
"lookSettleMs": { "type": "number", "minimum": 0 },
|
||||||
|
"helpSeconds": { "type": "number", "minimum": 0 },
|
||||||
|
"desktopRenderWidth": { "type": "integer", "minimum": 640 },
|
||||||
|
"startWeapons": { "type": "array", "items": { "type": "integer", "minimum": 1, "maximum": 36 } },
|
||||||
|
"weapons": {
|
||||||
|
"type": "array", "minItems": 1,
|
||||||
|
"items": {
|
||||||
|
"type": "object", "required": ["name", "type", "ammo"],
|
||||||
|
"properties": { "name": { "type": "string" }, "type": { "type": "integer", "minimum": 1, "maximum": 36 }, "ammo": { "type": "integer", "minimum": 1 }, "icon": { "type": "string" } },
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cars": {
|
||||||
|
"type": "array", "minItems": 1,
|
||||||
|
"items": {
|
||||||
|
"type": "object", "required": ["name", "model"],
|
||||||
|
"properties": { "name": { "type": "string" }, "model": { "type": "string" }, "bike": { "type": "boolean" } },
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"featured": { "type": "array", "minItems": 6, "maxItems": 6, "items": { "type": "string" } },
|
||||||
|
"wheel": { "type": "array", "items": { "type": "object", "required": ["name", "types"], "properties": { "name": { "type": "string" }, "types": { "type": "array", "items": { "type": "integer" } } }, "additionalProperties": false } },
|
||||||
|
"radio": { "type": "array", "items": { "type": "object", "required": ["station", "name"], "properties": { "station": { "type": "integer", "minimum": 0, "maximum": 10 }, "icon": { "type": "string" }, "name": { "type": "string" } }, "additionalProperties": false } },
|
||||||
|
"touch": { "type": "object", "required": ["renderWidth", "lookSpeed", "stickRadius", "stickDeadZone", "rotate", "stick", "buttons"] },
|
||||||
|
"help": { "type": "array", "items": { "type": "string" } }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
46
gamefiles/online/net.json
Normal file
46
gamefiles/online/net.json
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
{
|
||||||
|
"$schema": "./net.schema.json",
|
||||||
|
"comment": "Multiplayer tuning. skins = ped models other players are shown with (one per player id, repeating). Distances in world units, times in seconds.",
|
||||||
|
"bubbleSeconds": 6,
|
||||||
|
"bubbleDistance": 60,
|
||||||
|
"infiniteSprint": true,
|
||||||
|
"carStreamDistance": 200,
|
||||||
|
"sendHz": 30,
|
||||||
|
"aimFov": 42,
|
||||||
|
"aimDistance": 0.55,
|
||||||
|
"radarScale": 1.4,
|
||||||
|
"skins": [
|
||||||
|
"HMYBE",
|
||||||
|
"WMYST",
|
||||||
|
"BMYRI",
|
||||||
|
"HMYRI",
|
||||||
|
"WMYRI",
|
||||||
|
"BMYST",
|
||||||
|
"HMYST",
|
||||||
|
"WMYBE"
|
||||||
|
],
|
||||||
|
"snapDistance": 8.0,
|
||||||
|
"smoothing": 12.0,
|
||||||
|
"maxExtrapolation": 0.3,
|
||||||
|
"runSpeed": 3.5,
|
||||||
|
"sprintSpeed": 6.5,
|
||||||
|
"walkSpeed": 0.4,
|
||||||
|
"pedDensity": 5.0,
|
||||||
|
"carDensity": 5.0,
|
||||||
|
"maxPeds": 50,
|
||||||
|
"maxCars": 40,
|
||||||
|
"sandGripScale": 2.0,
|
||||||
|
"sandDragScale": 0.35,
|
||||||
|
"bikeGripScale": 1.5,
|
||||||
|
"spawnProbeHeight": 2.0,
|
||||||
|
"spawnClearance": 0.1,
|
||||||
|
"reconnectMinSeconds": 1,
|
||||||
|
"reconnectMaxSeconds": 10,
|
||||||
|
"deathFadeMs": 500,
|
||||||
|
"deathRespawnMs": 1200,
|
||||||
|
"deathFadeSeconds": 0.4,
|
||||||
|
"tagHeight": 1.2,
|
||||||
|
"swimEnterDepth": 0.3,
|
||||||
|
"swimDepth": 0.45,
|
||||||
|
"swimLift": 0.12
|
||||||
|
}
|
||||||
161
gamefiles/online/net.schema.json
Normal file
161
gamefiles/online/net.schema.json
Normal file
|
|
@ -0,0 +1,161 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||||
|
"title": "Online networking tuning",
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"bubbleSeconds",
|
||||||
|
"bubbleDistance",
|
||||||
|
"radarScale",
|
||||||
|
"sendHz",
|
||||||
|
"skins",
|
||||||
|
"snapDistance",
|
||||||
|
"smoothing",
|
||||||
|
"maxExtrapolation",
|
||||||
|
"runSpeed",
|
||||||
|
"sprintSpeed",
|
||||||
|
"walkSpeed"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"$schema": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"comment": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"aimFov": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 20,
|
||||||
|
"maximum": 70
|
||||||
|
},
|
||||||
|
"aimDistance": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0.2,
|
||||||
|
"maximum": 1
|
||||||
|
},
|
||||||
|
"sendHz": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 1,
|
||||||
|
"maximum": 60
|
||||||
|
},
|
||||||
|
"skins": {
|
||||||
|
"type": "array",
|
||||||
|
"minItems": 1,
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"snapDistance": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"smoothing": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"bubbleSeconds": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 1
|
||||||
|
},
|
||||||
|
"bubbleDistance": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 5
|
||||||
|
},
|
||||||
|
"infiniteSprint": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"carStreamDistance": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 50
|
||||||
|
},
|
||||||
|
"radarScale": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0.5,
|
||||||
|
"maximum": 3
|
||||||
|
},
|
||||||
|
"maxExtrapolation": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"runSpeed": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"sprintSpeed": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"walkSpeed": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"pedDensity": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"carDensity": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"maxPeds": {
|
||||||
|
"type": "integer",
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 100
|
||||||
|
},
|
||||||
|
"maxCars": {
|
||||||
|
"type": "integer",
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 80
|
||||||
|
},
|
||||||
|
"sandGripScale": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"sandDragScale": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"bikeGripScale": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"spawnProbeHeight": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"reconnectMinSeconds": { "type": "number", "exclusiveMinimum": 0 },
|
||||||
|
"reconnectMaxSeconds": { "type": "number", "exclusiveMinimum": 0 },
|
||||||
|
"spawnClearance": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"deathFadeMs": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"deathRespawnMs": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"deathFadeSeconds": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"tagHeight": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"swimEnterDepth": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"swimDepth": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
|
"swimLift": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
12
gamefiles/online/spawn.json
Normal file
12
gamefiles/online/spawn.json
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"$schema": "./spawn.schema.json",
|
||||||
|
"comment": "Where players appear on joining and after death or arrest. x/y in world units, heading in degrees, spreadRadius = random offset so players do not stack.",
|
||||||
|
"points": [
|
||||||
|
{
|
||||||
|
"x": 402.9,
|
||||||
|
"y": -1558.9,
|
||||||
|
"heading": 26.0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"spreadRadius": 5.0
|
||||||
|
}
|
||||||
26
gamefiles/online/spawn.schema.json
Normal file
26
gamefiles/online/spawn.schema.json
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||||
|
"title": "Online spawn points",
|
||||||
|
"type": "object",
|
||||||
|
"required": ["points", "spreadRadius"],
|
||||||
|
"properties": {
|
||||||
|
"$schema": { "type": "string" },
|
||||||
|
"comment": { "type": "string" },
|
||||||
|
"points": {
|
||||||
|
"type": "array",
|
||||||
|
"minItems": 1,
|
||||||
|
"items": {
|
||||||
|
"type": "object",
|
||||||
|
"required": ["x", "y", "heading"],
|
||||||
|
"properties": {
|
||||||
|
"x": { "type": "number" },
|
||||||
|
"y": { "type": "number" },
|
||||||
|
"heading": { "type": "number", "minimum": 0, "maximum": 360 }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"spreadRadius": { "type": "number", "minimum": 0 }
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
8
package.json
Normal file
8
package.json
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"name": "vc-online",
|
||||||
|
"private": true,
|
||||||
|
"type": "module",
|
||||||
|
"devDependencies": {
|
||||||
|
"playwright-core": "^1.64.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
1
patches/REVC_BASE
Normal file
1
patches/REVC_BASE
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
f8b787694079b6f0487eec42c44035ee5a7a0c8d
|
||||||
1
patches/revc-removed.txt
Normal file
1
patches/revc-removed.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
vendor/librw
|
||||||
3010
patches/revc.patch
Normal file
3010
patches/revc.patch
Normal file
File diff suppressed because it is too large
Load diff
22
server/bots.ts
Normal file
22
server/bots.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
// Test helper: connects N bots that walk in circles and prints what they see.
|
||||||
|
// Usage: VC_KEY=... bun server/bots.ts [url] [count]
|
||||||
|
const url = process.argv[2] ?? "ws://127.0.0.1:8791/ws";
|
||||||
|
const count = Number(process.argv[3] ?? 2);
|
||||||
|
const key = process.env.VC_KEY!;
|
||||||
|
const seen: Record<number, number> = {};
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
const ws = new WebSocket(`${url}?key=${key}`);
|
||||||
|
let id = 0, t = 0;
|
||||||
|
ws.onmessage = (e) => {
|
||||||
|
const m = JSON.parse(String(e.data));
|
||||||
|
if (m.t === "welcome") {
|
||||||
|
id = m.id;
|
||||||
|
ws.send(JSON.stringify({ t: "hello", name: `bot${i}` }));
|
||||||
|
setInterval(() => {
|
||||||
|
t += 0.05;
|
||||||
|
ws.send(JSON.stringify({ t: "s", pos: [600 + Math.cos(t) * 5, -1257 + Math.sin(t) * 5, 7], vel: [0, 0, 0], heading: t, model: 0, anim: 1, hp: 100 }));
|
||||||
|
}, 50);
|
||||||
|
} else if (m.t === "snap") seen[id] = m.p.length;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
setTimeout(() => { console.log("each bot sees others:", seen); process.exit(Object.values(seen).every((n) => n === count - 1) ? 0 : 1); }, 2500);
|
||||||
71
server/config.json
Normal file
71
server/config.json
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
{
|
||||||
|
"comment": "Game server settings. The access key is not stored here: it comes from the VC_KEY environment variable.",
|
||||||
|
"host": "127.0.0.1",
|
||||||
|
"port": 8791,
|
||||||
|
"tickHz": 30,
|
||||||
|
"maxPlayers": 32,
|
||||||
|
"spawnProtectionSeconds": 15,
|
||||||
|
"passiveCooldownSeconds": 10,
|
||||||
|
"fightLockSeconds": 10,
|
||||||
|
"maxHitDamage": 200,
|
||||||
|
"maxHitDistance": 300,
|
||||||
|
"killCreditSeconds": 10,
|
||||||
|
"carsPerOwner": 3,
|
||||||
|
"carColours": 94,
|
||||||
|
"carsFile": "cars.json",
|
||||||
|
"maxNameLength": 20,
|
||||||
|
"maxMessageBytes": 2048,
|
||||||
|
"idleTimeoutSeconds": 30,
|
||||||
|
"maxMessagesPerSecond": 60,
|
||||||
|
"maxWorldCars": 96,
|
||||||
|
"dock": {
|
||||||
|
"models": [
|
||||||
|
"squalo",
|
||||||
|
"jetmax"
|
||||||
|
],
|
||||||
|
"boatsPerPlayer": 3,
|
||||||
|
"refillSeconds": 10,
|
||||||
|
"slots": [
|
||||||
|
{
|
||||||
|
"pos": [
|
||||||
|
511.0,
|
||||||
|
-1580.0,
|
||||||
|
7.0
|
||||||
|
],
|
||||||
|
"heading": -1.571
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pos": [
|
||||||
|
511.0,
|
||||||
|
-1570.0,
|
||||||
|
7.0
|
||||||
|
],
|
||||||
|
"heading": -1.571
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pos": [
|
||||||
|
511.0,
|
||||||
|
-1560.0,
|
||||||
|
7.0
|
||||||
|
],
|
||||||
|
"heading": -1.571
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pos": [
|
||||||
|
511.0,
|
||||||
|
-1550.0,
|
||||||
|
7.0
|
||||||
|
],
|
||||||
|
"heading": -1.571
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pos": [
|
||||||
|
511.0,
|
||||||
|
-1540.0,
|
||||||
|
7.0
|
||||||
|
],
|
||||||
|
"heading": -1.571
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
241
server/main.ts
Normal file
241
server/main.ts
Normal file
|
|
@ -0,0 +1,241 @@
|
||||||
|
// Free-roam game server: relays each player's state to everybody else.
|
||||||
|
// Run: VC_KEY=<access key> bun server/main.ts
|
||||||
|
import config from "./config.json";
|
||||||
|
import { parseState, type PlayerState } from "./protocol";
|
||||||
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
||||||
|
import { join } from "node:path";
|
||||||
|
|
||||||
|
// With VC_KEY set, connecting needs the key; without it the server is open (the address is the secret).
|
||||||
|
const key = process.env.VC_KEY || "";
|
||||||
|
|
||||||
|
interface Client {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
state: PlayerState | null;
|
||||||
|
lastSeen: number;
|
||||||
|
windowStart: number;
|
||||||
|
windowCount: number;
|
||||||
|
owner: string; // private token from the player's browser: says whose cars are whose
|
||||||
|
protectedUntil: number; // nobody can hurt this player until then
|
||||||
|
passive: boolean; // cannot hurt anybody and cannot be hurt
|
||||||
|
passiveChanged: number;
|
||||||
|
away: boolean; // name box or pause menu open: like passive
|
||||||
|
lastShotAt: number; // last hit this player landed: no hiding in a menu right after
|
||||||
|
lastHitBy: number; // for the kill message
|
||||||
|
lastHitAt: number;
|
||||||
|
kills: number;
|
||||||
|
deaths: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cars players spawned: they stay in the world, also over restarts.
|
||||||
|
interface WorldCar {
|
||||||
|
id: number;
|
||||||
|
owner: string;
|
||||||
|
ownerName: string;
|
||||||
|
model: string;
|
||||||
|
pos: [number, number, number];
|
||||||
|
heading: number;
|
||||||
|
c1: number;
|
||||||
|
c2: number;
|
||||||
|
driven: boolean;
|
||||||
|
free?: boolean; // a boat at the dock: anybody can take it
|
||||||
|
session?: boolean; // a boat somebody took: gone when that player leaves, never saved
|
||||||
|
slot?: number;
|
||||||
|
}
|
||||||
|
const carsPath = join(import.meta.dir, config.carsFile);
|
||||||
|
const cars = new Map<number, WorldCar>();
|
||||||
|
let nextCarId = 1;
|
||||||
|
if (existsSync(carsPath)) {
|
||||||
|
try {
|
||||||
|
for (const c of JSON.parse(readFileSync(carsPath, "utf8"))) { c.driven = false; cars.set(c.id, c); nextCarId = Math.max(nextCarId, c.id + 1); }
|
||||||
|
} catch (e) { console.error("cars file unreadable, starting empty", e); }
|
||||||
|
}
|
||||||
|
// Old owners may be over the limit: only the newest ones stay.
|
||||||
|
{
|
||||||
|
const seen = new Map<string, number>();
|
||||||
|
for (const c of [...cars.values()].sort((a, b) => b.id - a.id)) {
|
||||||
|
const n = (seen.get(c.owner) || 0) + 1;
|
||||||
|
seen.set(c.owner, n);
|
||||||
|
if (n > config.carsPerOwner) cars.delete(c.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let saveTimer: any = null;
|
||||||
|
const saveCars = () => {
|
||||||
|
if (saveTimer) return;
|
||||||
|
saveTimer = setTimeout(() => { saveTimer = null; writeFileSync(carsPath, JSON.stringify([...cars.values()].filter((x) => !x.free && !x.session))); }, 2000);
|
||||||
|
};
|
||||||
|
const carFor = (car: WorldCar, c: Client) => {
|
||||||
|
const { owner, ...pub } = car;
|
||||||
|
return { ...pub, mine: !car.free && owner === c.owner };
|
||||||
|
};
|
||||||
|
const sendCar = (car: WorldCar, t: string) => {
|
||||||
|
for (const [id, ws] of sockets) { const o = clients.get(id); if (o) send(ws, { t, car: carFor(car, o) }); }
|
||||||
|
};
|
||||||
|
// The dock: every slot always holds a boat; a taken one is replaced after a moment.
|
||||||
|
const dockBoat = (slot: number) => {
|
||||||
|
const s = config.dock.slots[slot];
|
||||||
|
const car: WorldCar = { id: nextCarId++, owner: "", ownerName: "", model: config.dock.models[slot % config.dock.models.length], pos: s.pos as [number, number, number],
|
||||||
|
heading: s.heading, c1: Math.floor(Math.random() * config.carColours), c2: Math.floor(Math.random() * config.carColours), driven: false, free: true, slot };
|
||||||
|
cars.set(car.id, car);
|
||||||
|
return car;
|
||||||
|
};
|
||||||
|
const removeCar = (car: WorldCar) => { cars.delete(car.id); broadcast({ t: "carRemove", id: car.id }); };
|
||||||
|
const num3 = (v: any) => Array.isArray(v) && v.length === 3 && v.every(Number.isFinite);
|
||||||
|
const validModel = (m: unknown) => typeof m === "string" && /^[a-z0-9_]{1,16}$/.test(m);
|
||||||
|
|
||||||
|
const clients = new Map<number, Client>();
|
||||||
|
const sockets = new Map<number, any>();
|
||||||
|
let nextId = 1;
|
||||||
|
|
||||||
|
const send = (ws: any, msg: object) => ws.send(JSON.stringify(msg));
|
||||||
|
const broadcast = (msg: object, except?: number) => {
|
||||||
|
const text = JSON.stringify(msg);
|
||||||
|
for (const [id, ws] of sockets) if (id !== except) ws.send(text);
|
||||||
|
};
|
||||||
|
const cleanName = (n: unknown) =>
|
||||||
|
(typeof n === "string" ? n : "").replace(/[^\x20-\x7e]/g, "").trim().slice(0, config.maxNameLength) || "Player";
|
||||||
|
|
||||||
|
const server = Bun.serve({
|
||||||
|
port: config.port,
|
||||||
|
hostname: config.host,
|
||||||
|
fetch(req, srv) {
|
||||||
|
const url = new URL(req.url);
|
||||||
|
if (url.pathname === "/health") return new Response(JSON.stringify({ ok: true, players: clients.size }));
|
||||||
|
// The key comes from the entry link (?key=) or from the cookie the web server sets after it.
|
||||||
|
const cookieKey = /(?:^|;\s*)vcgate=([^;]+)/.exec(req.headers.get("cookie") ?? "")?.[1];
|
||||||
|
const given = url.searchParams.get("key") ?? cookieKey;
|
||||||
|
if (url.pathname !== "/ws" || (key && given !== key)) return new Response("not found", { status: 404 });
|
||||||
|
if (clients.size >= config.maxPlayers) return new Response("full", { status: 503 });
|
||||||
|
return srv.upgrade(req, { data: {} }) ? undefined : new Response("upgrade failed", { status: 400 });
|
||||||
|
},
|
||||||
|
websocket: {
|
||||||
|
maxPayloadLength: config.maxMessageBytes,
|
||||||
|
open(ws) {
|
||||||
|
const id = nextId++;
|
||||||
|
(ws.data as any).id = id;
|
||||||
|
clients.set(id, { id, name: "Player", state: null, lastSeen: Date.now(), windowStart: Date.now(), windowCount: 0,
|
||||||
|
owner: "", protectedUntil: Date.now() + config.spawnProtectionSeconds * 1000, passive: false, passiveChanged: 0, away: false, lastShotAt: 0, lastHitBy: 0, lastHitAt: 0, kills: 0, deaths: 0 });
|
||||||
|
sockets.set(id, ws);
|
||||||
|
send(ws, { t: "welcome", id, tickHz: config.tickHz, max: config.maxPlayers });
|
||||||
|
},
|
||||||
|
message(ws, raw) {
|
||||||
|
const c = clients.get((ws.data as any).id);
|
||||||
|
if (!c || typeof raw !== "string") return;
|
||||||
|
const now = Date.now();
|
||||||
|
if (now - c.windowStart > 1000) { c.windowStart = now; c.windowCount = 0; }
|
||||||
|
if (++c.windowCount > config.maxMessagesPerSecond) return;
|
||||||
|
c.lastSeen = now;
|
||||||
|
let m: any;
|
||||||
|
try { m = JSON.parse(raw); } catch { return; }
|
||||||
|
if (m.t === "hello") {
|
||||||
|
const first = c.name === "Player" && !c.state;
|
||||||
|
c.name = cleanName(m.name);
|
||||||
|
if (typeof m.owner === "string" && /^[a-f0-9]{16,64}$/.test(m.owner)) c.owner = m.owner;
|
||||||
|
for (const car of cars.values()) if (car.owner === c.owner && c.owner) car.ownerName = c.name;
|
||||||
|
send(ws, { t: "cars", cars: [...cars.values()].map((car) => carFor(car, c)) });
|
||||||
|
if (first) broadcast({ t: "join", id: c.id, name: c.name }, c.id);
|
||||||
|
} else if (m.t === "away") {
|
||||||
|
if (m.on && now - c.lastShotAt < config.fightLockSeconds * 1000) { c.away = false; send(ws, { t: "away", on: false, wait: true }); return; }
|
||||||
|
c.away = !!m.on;
|
||||||
|
send(ws, { t: "away", on: c.away });
|
||||||
|
} else if (m.t === "marker" && Number.isFinite(m.x) && Number.isFinite(m.y)) {
|
||||||
|
console.log(`marker ${c.name} x=${m.x} y=${m.y}` + (Number.isFinite(m.z) ? ` z=${m.z} heading=${m.heading}` : ""));
|
||||||
|
} else if (m.t === "ping" && typeof m.n === "number") {
|
||||||
|
send(ws, { t: "pong", n: m.n });
|
||||||
|
} else if (m.t === "s") {
|
||||||
|
const s = parseState(m);
|
||||||
|
if (s) c.state = s;
|
||||||
|
} else if (m.t === "hit" && Number.isFinite(m.target) && Number.isFinite(m.damage) && Number.isFinite(m.weapon)) {
|
||||||
|
const v = clients.get(m.target), vs = sockets.get(m.target);
|
||||||
|
if (!v || !vs || v === c || c.passive || v.passive || c.away || v.away || now < v.protectedUntil) return;
|
||||||
|
c.lastShotAt = now;
|
||||||
|
if (c.state && v.state) {
|
||||||
|
const a: any = c.state, b: any = v.state;
|
||||||
|
if (Array.isArray(a.pos) && Array.isArray(b.pos) && Math.hypot(a.pos[0] - b.pos[0], a.pos[1] - b.pos[1]) > config.maxHitDistance) return;
|
||||||
|
}
|
||||||
|
v.lastHitBy = c.id; v.lastHitAt = now;
|
||||||
|
send(vs, { t: "dmg", amount: Math.min(Math.max(m.damage, 0), config.maxHitDamage), weapon: m.weapon, from: c.id });
|
||||||
|
} else if (m.t === "died") {
|
||||||
|
c.deaths++;
|
||||||
|
const k = now - c.lastHitAt < config.killCreditSeconds * 1000 ? clients.get(c.lastHitBy) : undefined;
|
||||||
|
if (k) k.kills++;
|
||||||
|
broadcast({ t: "kill", victim: c.name, killer: k?.name ?? "", kills: k?.kills ?? 0, killerId: k?.id ?? 0 });
|
||||||
|
} else if (m.t === "spawned") {
|
||||||
|
c.protectedUntil = now + config.spawnProtectionSeconds * 1000;
|
||||||
|
send(ws, { t: "protected", seconds: config.spawnProtectionSeconds });
|
||||||
|
} else if (m.t === "passive") {
|
||||||
|
if (now - c.passiveChanged < config.passiveCooldownSeconds * 1000) { send(ws, { t: "passive", on: c.passive, wait: true }); return; }
|
||||||
|
c.passive = !c.passive; c.passiveChanged = now;
|
||||||
|
send(ws, { t: "passive", on: c.passive });
|
||||||
|
} else if (m.t === "spawncar" && validModel(m.model) && num3(m.pos) && Number.isFinite(m.heading) && c.owner) {
|
||||||
|
const mine = [...cars.values()].filter((x) => x.owner === c.owner && !x.session);
|
||||||
|
while (mine.length >= config.carsPerOwner) {
|
||||||
|
const old = mine.shift()!;
|
||||||
|
if (old.driven) continue;
|
||||||
|
cars.delete(old.id);
|
||||||
|
broadcast({ t: "carRemove", id: old.id });
|
||||||
|
}
|
||||||
|
// The world holds a limited number of cars: the oldest parked one goes first.
|
||||||
|
for (const old of [...cars.values()]) {
|
||||||
|
if (cars.size < config.maxWorldCars) break;
|
||||||
|
if (old.driven || old.free || old.session) continue;
|
||||||
|
cars.delete(old.id);
|
||||||
|
broadcast({ t: "carRemove", id: old.id });
|
||||||
|
}
|
||||||
|
const car: WorldCar = { id: nextCarId++, owner: c.owner, ownerName: c.name, model: m.model, pos: m.pos, heading: m.heading,
|
||||||
|
c1: Math.floor(Math.random() * config.carColours), c2: Math.floor(Math.random() * config.carColours), driven: false };
|
||||||
|
cars.set(car.id, car);
|
||||||
|
sendCar(car, "carAdd");
|
||||||
|
saveCars();
|
||||||
|
} else if (m.t === "park" && Number.isFinite(m.id) && num3(m.pos) && Number.isFinite(m.heading)) {
|
||||||
|
const car = cars.get(m.id);
|
||||||
|
if (!car || car.owner !== c.owner) return;
|
||||||
|
car.pos = m.pos; car.heading = m.heading; car.driven = !!m.driven;
|
||||||
|
sendCar(car, "carAdd");
|
||||||
|
saveCars();
|
||||||
|
} else if (m.t === "take" && Number.isFinite(m.id) && c.owner) {
|
||||||
|
const car = cars.get(m.id);
|
||||||
|
if (!car || !car.free) return;
|
||||||
|
const slot = car.slot!;
|
||||||
|
const held = [...cars.values()].filter((x) => x.session && x.owner === c.owner);
|
||||||
|
while (held.length >= config.dock.boatsPerPlayer) { const old = held.shift()!; if (!old.driven) removeCar(old); }
|
||||||
|
car.free = false; car.session = true; car.owner = c.owner; car.ownerName = c.name; delete car.slot;
|
||||||
|
sendCar(car, "carAdd");
|
||||||
|
setTimeout(() => sendCar(dockBoat(slot), "carAdd"), config.dock.refillSeconds * 1000);
|
||||||
|
} else if (m.t === "chat" && typeof m.text === "string") {
|
||||||
|
const text = m.text.replace(/[^\x20-\x7e]/g, "").trim().slice(0, 120);
|
||||||
|
if (text) broadcast({ t: "chat", id: c.id, name: c.name, text });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
close(ws) {
|
||||||
|
const id = (ws.data as any).id;
|
||||||
|
const gone = clients.get(id);
|
||||||
|
clients.delete(id);
|
||||||
|
sockets.delete(id);
|
||||||
|
// A car its owner was driving when the connection ended stays where it was last parked.
|
||||||
|
if (gone && gone.owner) for (const car of [...cars.values()]) {
|
||||||
|
if (car.owner !== gone.owner) continue;
|
||||||
|
if (car.session) removeCar(car);
|
||||||
|
else if (car.driven) { car.driven = false; sendCar(car, "carAdd"); }
|
||||||
|
}
|
||||||
|
broadcast({ t: "leave", id });
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// One snapshot per tick: for every player, everybody else's last known state.
|
||||||
|
setInterval(() => {
|
||||||
|
const now = Date.now();
|
||||||
|
for (const [id, c] of clients) {
|
||||||
|
if (now - c.lastSeen > config.idleTimeoutSeconds * 1000) sockets.get(id)?.close();
|
||||||
|
}
|
||||||
|
for (const [id, ws] of sockets) {
|
||||||
|
const p = [];
|
||||||
|
for (const [oid, o] of clients) if (oid !== id && o.state) p.push({ id: oid, name: o.name, ...o.state });
|
||||||
|
send(ws, { t: "snap", p });
|
||||||
|
}
|
||||||
|
}, 1000 / config.tickHz);
|
||||||
|
|
||||||
|
config.dock.slots.forEach((_, i) => dockBoat(i));
|
||||||
|
|
||||||
|
console.log(`vc-online server on :${server.port}`);
|
||||||
62
server/protocol.ts
Normal file
62
server/protocol.ts
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
// Wire format between the browser game and the server. Messages are JSON text frames.
|
||||||
|
//
|
||||||
|
// client -> server
|
||||||
|
// {"t":"hit","target":id,"damage":n,"weapon":n} the local player hit another player; the server decides
|
||||||
|
// {"t":"died"} {"t":"spawned"} {"t":"passive"} own life state, passive mode toggle
|
||||||
|
// {"t":"spawncar","model":"...","pos":[x,y,z],"heading":n}, {"t":"park","id":n,"pos":[...],"heading":n,"driven":bool}
|
||||||
|
// {"t":"hello","name":"..."} first message after connecting
|
||||||
|
// {"t":"s", ...PlayerState} own state, sent every tick
|
||||||
|
// {"t":"chat","text":"..."}
|
||||||
|
// server -> client
|
||||||
|
// {"t":"welcome","id":1,"tickHz":20}
|
||||||
|
// {"t":"snap","p":[{"id":2,"name":"..", ...PlayerState}, ...]} every other player
|
||||||
|
// {"t":"join","id":2,"name":".."} {"t":"leave","id":2}
|
||||||
|
// {"t":"chat","id":2,"name":"..","text":".."}
|
||||||
|
|
||||||
|
export type Vec3 = [number, number, number];
|
||||||
|
|
||||||
|
// What one player says about itself. Positions are world units, heading in radians.
|
||||||
|
export interface PlayerState {
|
||||||
|
pos: Vec3;
|
||||||
|
vel: Vec3;
|
||||||
|
heading: number;
|
||||||
|
model: number; // ped model id
|
||||||
|
anim: number; // walk/run/idle state id, rendered by the client
|
||||||
|
hp: number;
|
||||||
|
wep?: number; // weapon type in hand
|
||||||
|
fire?: number; // 1 while shooting, drives the flash and sound on other screens
|
||||||
|
// Present while the player drives a car: the car's own state.
|
||||||
|
car?: CarState;
|
||||||
|
// Present while the player rides in somebody else's car.
|
||||||
|
ride?: { driver: number; seat: number };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CarState {
|
||||||
|
key: number; // id of the car, unique per owner
|
||||||
|
model: string; // model name, e.g. "cheetah"
|
||||||
|
pos: Vec3;
|
||||||
|
vel: Vec3;
|
||||||
|
fwd: Vec3; // orientation: forward and up vectors
|
||||||
|
up: Vec3;
|
||||||
|
colours: [number, number];
|
||||||
|
}
|
||||||
|
|
||||||
|
const finite = (n: unknown): n is number => typeof n === "number" && Number.isFinite(n) && Math.abs(n) < 1e6;
|
||||||
|
const vec3 = (v: unknown): v is Vec3 => Array.isArray(v) && v.length === 3 && v.every(finite);
|
||||||
|
|
||||||
|
export function parseState(m: any): PlayerState | null {
|
||||||
|
if (!vec3(m.pos) || !vec3(m.vel) || !finite(m.heading) || !finite(m.model) || !finite(m.anim) || !finite(m.hp)) return null;
|
||||||
|
const s: PlayerState = { pos: m.pos, vel: m.vel, heading: m.heading, model: m.model | 0, anim: m.anim | 0, hp: m.hp };
|
||||||
|
if (finite(m.wep)) s.wep = m.wep | 0;
|
||||||
|
if (finite(m.fire)) s.fire = m.fire ? 1 : 0;
|
||||||
|
if (m.car) {
|
||||||
|
const c = m.car;
|
||||||
|
if (!finite(c.key) || typeof c.model !== "string" || c.model.length > 24 || !vec3(c.pos) || !vec3(c.vel) || !vec3(c.fwd) || !vec3(c.up)) return null;
|
||||||
|
if (!Array.isArray(c.colours) || c.colours.length !== 2 || !c.colours.every(finite)) return null;
|
||||||
|
s.car = { key: c.key | 0, model: c.model, pos: c.pos, vel: c.vel, fwd: c.fwd, up: c.up, colours: [c.colours[0] | 0, c.colours[1] | 0] };
|
||||||
|
} else if (m.ride) {
|
||||||
|
if (!finite(m.ride.driver) || !finite(m.ride.seat)) return null;
|
||||||
|
s.ride = { driver: m.ride.driver | 0, seat: m.ride.seat | 0 };
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
393
src/core/CdStreamWeb.cpp
Normal file
393
src/core/CdStreamWeb.cpp
Normal file
|
|
@ -0,0 +1,393 @@
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
// Streaming for the browser build: image files (models/gta3.img) are not in the
|
||||||
|
// in-memory file system, every read is an HTTP range request to the data host.
|
||||||
|
// Reads stay asynchronous like on the PC; CdStreamSync yields to the browser
|
||||||
|
// (ASYNCIFY) until the request is done.
|
||||||
|
#include "common.h"
|
||||||
|
#include "CdStream.h"
|
||||||
|
|
||||||
|
#include <emscripten.h>
|
||||||
|
#include <emscripten/fetch.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#define CDTRACE(f, ...) printf("%s: " f "\n", "cdvd_stream", ## __VA_ARGS__)
|
||||||
|
|
||||||
|
static const int MAX_RETRIES = 3;
|
||||||
|
|
||||||
|
struct CdReadInfo
|
||||||
|
{
|
||||||
|
uint32 nSectorOffset;
|
||||||
|
uint32 nSectorsToRead;
|
||||||
|
void *pBuffer;
|
||||||
|
int32 nImage;
|
||||||
|
int32 nStatus;
|
||||||
|
int32 nRetries;
|
||||||
|
bool bReading;
|
||||||
|
bool bBlockFetch;
|
||||||
|
};
|
||||||
|
|
||||||
|
static char gCdImageNames[MAX_CDIMAGES+1][64];
|
||||||
|
static std::string gImgUrls[MAX_CDIMAGES];
|
||||||
|
static std::string gImgKeys[MAX_CDIMAGES]; // lower-case path, the key of Module.vcImages
|
||||||
|
static uint32 gImgSizes[MAX_CDIMAGES];
|
||||||
|
static int32 gNumImages;
|
||||||
|
static int32 gNumChannels;
|
||||||
|
static CdReadInfo *gpReadInfo;
|
||||||
|
static int32 lastPosnRead;
|
||||||
|
|
||||||
|
#ifdef FLUSHABLE_STREAMING
|
||||||
|
// A request in flight cannot be cancelled, so a flush just waits for it in CdStreamSync.
|
||||||
|
bool flushStream[MAX_CDCHANNELS];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// "MODELS\\GTA3.IMG" -> "<data url>/models/gta3.img"
|
||||||
|
static std::string
|
||||||
|
ImageUrl(const char *path)
|
||||||
|
{
|
||||||
|
char *base = (char*)EM_ASM_PTR({ return stringToNewUTF8(Module.vcDataUrl || "data"); });
|
||||||
|
std::string url = base;
|
||||||
|
free(base);
|
||||||
|
url += '/';
|
||||||
|
for(const char *p = path; *p; p++)
|
||||||
|
url += *p == '\\' ? '/' : (char)tolower(*p);
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reads are small and scattered, and every request costs a round trip to the data host.
|
||||||
|
// The image is therefore fetched in aligned blocks, and the latest blocks are kept: models
|
||||||
|
// that sit next to each other in the image (the same area) come out of memory.
|
||||||
|
static const uint32 BLOCK_SIZE = 2 * 1024 * 1024;
|
||||||
|
static const int NUM_BLOCKS = 48;
|
||||||
|
struct Block
|
||||||
|
{
|
||||||
|
int32 image;
|
||||||
|
uint32 index;
|
||||||
|
uint32 lastUse;
|
||||||
|
std::vector<uint8> data;
|
||||||
|
};
|
||||||
|
static Block gBlocks[NUM_BLOCKS];
|
||||||
|
static uint32 gBlockClock;
|
||||||
|
|
||||||
|
static Block *
|
||||||
|
FindBlock(int32 image, uint32 index)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < NUM_BLOCKS; i++)
|
||||||
|
if(gBlocks[i].image == image && gBlocks[i].index == index && !gBlocks[i].data.empty())
|
||||||
|
return &gBlocks[i];
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Block *
|
||||||
|
ClaimBlock(int32 image, uint32 index)
|
||||||
|
{
|
||||||
|
Block *victim = &gBlocks[0];
|
||||||
|
for(int i = 0; i < NUM_BLOCKS; i++){
|
||||||
|
if(gBlocks[i].data.empty()){ victim = &gBlocks[i]; break; }
|
||||||
|
if(gBlocks[i].lastUse < victim->lastUse) victim = &gBlocks[i];
|
||||||
|
}
|
||||||
|
victim->image = image;
|
||||||
|
victim->index = index;
|
||||||
|
victim->lastUse = ++gBlockClock;
|
||||||
|
victim->data.clear();
|
||||||
|
return victim;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copies [from, from+size) out of a block, if the whole range lies inside it.
|
||||||
|
static bool
|
||||||
|
CopyFromBlock(int32 image, uint64 from, uint32 size, void *dst)
|
||||||
|
{
|
||||||
|
uint32 index = (uint32)(from / BLOCK_SIZE);
|
||||||
|
Block *b = FindBlock(image, index);
|
||||||
|
uint64 start = from - (uint64)index * BLOCK_SIZE;
|
||||||
|
if(!b || start + size > b->data.size()) return false;
|
||||||
|
memcpy(dst, &b->data[start], size);
|
||||||
|
b->lastUse = ++gBlockClock;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void StartFetch(int32 channel);
|
||||||
|
|
||||||
|
static void
|
||||||
|
OnFetchDone(emscripten_fetch_t *fetch)
|
||||||
|
{
|
||||||
|
int32 channel = (int32)(intptr_t)fetch->userData;
|
||||||
|
CdReadInfo *ch = &gpReadInfo[channel];
|
||||||
|
uint32 want = ch->nSectorsToRead * CDSTREAM_SECTOR_SIZE;
|
||||||
|
bool ok = fetch->status == 206 || fetch->status == 200;
|
||||||
|
if(ok){
|
||||||
|
uint64 from = (uint64)ch->nSectorOffset * CDSTREAM_SECTOR_SIZE;
|
||||||
|
uint64 blockStart = from / BLOCK_SIZE * BLOCK_SIZE;
|
||||||
|
bool blockFetch = ch->bBlockFetch;
|
||||||
|
if(blockFetch){
|
||||||
|
Block *b = ClaimBlock(ch->nImage, (uint32)(from / BLOCK_SIZE));
|
||||||
|
b->data.assign((const uint8*)fetch->data, (const uint8*)fetch->data + fetch->numBytes);
|
||||||
|
uint64 start = from - blockStart;
|
||||||
|
uint64 n = start >= b->data.size() ? 0 : Min((uint64)want, b->data.size() - start);
|
||||||
|
if(n) memcpy(ch->pBuffer, &b->data[start], n);
|
||||||
|
if(n < want) memset((uint8*)ch->pBuffer + n, 0, want - n);
|
||||||
|
}else{
|
||||||
|
uint64 n = fetch->numBytes < want ? fetch->numBytes : want;
|
||||||
|
memcpy(ch->pBuffer, fetch->data, n);
|
||||||
|
if(n < want)
|
||||||
|
memset((uint8*)ch->pBuffer + n, 0, want - n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
emscripten_fetch_close(fetch);
|
||||||
|
EM_ASM({ if(Module.vcBusy) Module.vcBusy($0); }, -1);
|
||||||
|
if(!ok && ch->nRetries++ < MAX_RETRIES){
|
||||||
|
CDTRACE("read failed (HTTP %d), retrying", fetch->status);
|
||||||
|
StartFetch(channel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ch->nStatus = ok ? STREAM_NONE : STREAM_ERROR;
|
||||||
|
ch->nSectorsToRead = 0;
|
||||||
|
ch->bReading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
StartFetch(int32 channel)
|
||||||
|
{
|
||||||
|
CdReadInfo *ch = &gpReadInfo[channel];
|
||||||
|
uint64 from = (uint64)ch->nSectorOffset * CDSTREAM_SECTOR_SIZE;
|
||||||
|
uint64 to = from + (uint64)ch->nSectorsToRead * CDSTREAM_SECTOR_SIZE - 1;
|
||||||
|
static char range[64];
|
||||||
|
// Ask for the whole aligned block when the request lies inside one; a request that
|
||||||
|
// crosses a block border is fetched as it is.
|
||||||
|
ch->bBlockFetch = from / BLOCK_SIZE == to / BLOCK_SIZE;
|
||||||
|
if(ch->bBlockFetch){
|
||||||
|
uint64 blockStart = from / BLOCK_SIZE * BLOCK_SIZE;
|
||||||
|
uint64 blockEnd = Min(blockStart + BLOCK_SIZE, (uint64)gImgSizes[ch->nImage]) - 1;
|
||||||
|
snprintf(range, sizeof(range), "bytes=%llu-%llu", (unsigned long long)blockStart, (unsigned long long)blockEnd);
|
||||||
|
}else
|
||||||
|
snprintf(range, sizeof(range), "bytes=%llu-%llu", (unsigned long long)from, (unsigned long long)to);
|
||||||
|
const char *headers[] = { "Range", range, nil };
|
||||||
|
|
||||||
|
// An image the page already holds in memory (Module.vcImages) is copied, no request needed.
|
||||||
|
if(EM_ASM_INT({
|
||||||
|
const key = UTF8ToString($0);
|
||||||
|
if(Module.vcReadLog) Module.vcReadLog.push($1 + ":" + $2);
|
||||||
|
const img = Module.vcImages && Module.vcImages[key];
|
||||||
|
if(!img){
|
||||||
|
// Pieces of the image that have already arrived are used at once. A piece the game
|
||||||
|
// asks for and does not have yet moves to the front of the download.
|
||||||
|
const part = Module.vcPart;
|
||||||
|
if(part && part.key === key){
|
||||||
|
const first = Math.floor($1 / part.size);
|
||||||
|
const last = Math.floor(($1 + $2 - 1) / part.size);
|
||||||
|
let all = true;
|
||||||
|
for(let i = last; i >= first; i--){
|
||||||
|
if(!part.done[i]){
|
||||||
|
all = false;
|
||||||
|
part.want.push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(all){
|
||||||
|
const n = Math.max(0, Math.min($2, part.buf.length - $1));
|
||||||
|
HEAPU8.set(part.buf.subarray($1, $1 + n), $3);
|
||||||
|
HEAPU8.fill(0, $3 + n, $3 + $2);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The start pack: what the game reads at the spawn point, ahead of the whole image.
|
||||||
|
const pack = Module.vcStart;
|
||||||
|
if(!pack || pack.key !== key) return 0;
|
||||||
|
let lo = 0;
|
||||||
|
let hi = pack.ranges.length - 1;
|
||||||
|
while(lo <= hi){
|
||||||
|
const mid = (lo + hi) >> 1;
|
||||||
|
const r = pack.ranges[mid];
|
||||||
|
if($1 < r.at) hi = mid - 1;
|
||||||
|
else if($1 >= r.at + r.size) lo = mid + 1;
|
||||||
|
else{
|
||||||
|
if($1 + $2 > r.at + r.size) return 0;
|
||||||
|
const from = r.pos + $1 - r.at;
|
||||||
|
HEAPU8.set(pack.data.subarray(from, from + $2), $3);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
const n = Math.max(0, Math.min($2, img.length - $1));
|
||||||
|
HEAPU8.set(img.subarray($1, $1 + n), $3);
|
||||||
|
HEAPU8.fill(0, $3 + n, $3 + $2);
|
||||||
|
return 1;
|
||||||
|
}, gImgKeys[ch->nImage].c_str(), (double)from, (double)(to - from + 1), ch->pBuffer)){
|
||||||
|
ch->nStatus = STREAM_NONE;
|
||||||
|
ch->nSectorsToRead = 0;
|
||||||
|
ch->bReading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(CopyFromBlock(ch->nImage, from, (uint32)(to - from + 1), ch->pBuffer)){
|
||||||
|
ch->nStatus = STREAM_NONE;
|
||||||
|
ch->nSectorsToRead = 0;
|
||||||
|
ch->bReading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emscripten_fetch_attr_t attr;
|
||||||
|
emscripten_fetch_attr_init(&attr);
|
||||||
|
strcpy(attr.requestMethod, "GET");
|
||||||
|
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
|
||||||
|
attr.requestHeaders = headers;
|
||||||
|
attr.userData = (void*)(intptr_t)channel;
|
||||||
|
attr.onsuccess = OnFetchDone;
|
||||||
|
attr.onerror = OnFetchDone;
|
||||||
|
ch->bReading = true;
|
||||||
|
EM_ASM({ if(Module.vcBusy) Module.vcBusy($0); }, 1);
|
||||||
|
emscripten_fetch(&attr, gImgUrls[ch->nImage].c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CdStreamInitThread(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CdStreamInit(int32 numChannels)
|
||||||
|
{
|
||||||
|
gNumImages = 0;
|
||||||
|
gNumChannels = numChannels;
|
||||||
|
gpReadInfo = (CdReadInfo*)calloc(numChannels, sizeof(CdReadInfo));
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32
|
||||||
|
GetGTA3ImgSize(void)
|
||||||
|
{
|
||||||
|
return gImgSizes[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CdStreamShutdown(void)
|
||||||
|
{
|
||||||
|
free(gpReadInfo);
|
||||||
|
gpReadInfo = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32
|
||||||
|
CdStreamRead(int32 channel, void *buffer, uint32 offset, uint32 size)
|
||||||
|
{
|
||||||
|
ASSERT(channel < gNumChannels);
|
||||||
|
lastPosnRead = size + offset;
|
||||||
|
int32 image = _GET_INDEX(offset);
|
||||||
|
if(image >= gNumImages)
|
||||||
|
return STREAM_NONE;
|
||||||
|
|
||||||
|
CdReadInfo *ch = &gpReadInfo[channel];
|
||||||
|
if(ch->nSectorsToRead != 0 || ch->bReading){
|
||||||
|
if(ch->nImage == image && ch->nSectorOffset == _GET_OFFSET(offset) && ch->nSectorsToRead >= size)
|
||||||
|
return STREAM_SUCCESS;
|
||||||
|
return STREAM_NONE;
|
||||||
|
}
|
||||||
|
ch->nImage = image;
|
||||||
|
ch->nStatus = STREAM_NONE;
|
||||||
|
ch->nSectorOffset = _GET_OFFSET(offset);
|
||||||
|
ch->nSectorsToRead = size;
|
||||||
|
ch->pBuffer = buffer;
|
||||||
|
ch->nRetries = 0;
|
||||||
|
StartFetch(channel);
|
||||||
|
return STREAM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32
|
||||||
|
CdStreamGetStatus(int32 channel)
|
||||||
|
{
|
||||||
|
CdReadInfo *ch = &gpReadInfo[channel];
|
||||||
|
if(ch->bReading)
|
||||||
|
return STREAM_READING;
|
||||||
|
if(ch->nSectorsToRead != 0)
|
||||||
|
return STREAM_WAITING;
|
||||||
|
int32 status = ch->nStatus;
|
||||||
|
ch->nStatus = STREAM_NONE;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32
|
||||||
|
CdStreamGetLastPosn(void)
|
||||||
|
{
|
||||||
|
return lastPosnRead;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32
|
||||||
|
CdStreamSync(int32 channel)
|
||||||
|
{
|
||||||
|
CdReadInfo *ch = &gpReadInfo[channel];
|
||||||
|
while(ch->bReading)
|
||||||
|
emscripten_sleep(1);
|
||||||
|
#ifdef FLUSHABLE_STREAMING
|
||||||
|
if(flushStream[channel]){
|
||||||
|
flushStream[channel] = false;
|
||||||
|
ch->nStatus = STREAM_NONE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return ch->nStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
AddToQueue(Queue *queue, int32 item)
|
||||||
|
{
|
||||||
|
queue->items[queue->tail] = item;
|
||||||
|
queue->tail = (queue->tail + 1) % queue->size;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32
|
||||||
|
GetFirstInQueue(Queue *queue)
|
||||||
|
{
|
||||||
|
return queue->head == queue->tail ? -1 : queue->items[queue->head];
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
RemoveFirstInQueue(Queue *queue)
|
||||||
|
{
|
||||||
|
if(queue->head != queue->tail)
|
||||||
|
queue->head = (queue->head + 1) % queue->size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Image sizes come from the data host's manifest.json ("ranged" list), which the
|
||||||
|
// page loads before start-up.
|
||||||
|
bool
|
||||||
|
CdStreamAddImage(char const *path)
|
||||||
|
{
|
||||||
|
ASSERT(gNumImages < MAX_CDIMAGES);
|
||||||
|
std::string url = ImageUrl(path);
|
||||||
|
double size = EM_ASM_DOUBLE({
|
||||||
|
const rel = UTF8ToString($0);
|
||||||
|
const hit = (Module.vcRanged || []).find(f => rel.endsWith("/" + f.path));
|
||||||
|
return hit ? hit.size : -1;
|
||||||
|
}, url.c_str());
|
||||||
|
if(size < 0){
|
||||||
|
CDTRACE("%s is not in the manifest", url.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
gImgUrls[gNumImages] = url;
|
||||||
|
std::string key;
|
||||||
|
for(const char *p = path; *p; p++)
|
||||||
|
key += *p == '\\' ? '/' : (char)tolower(*p);
|
||||||
|
gImgKeys[gNumImages] = key;
|
||||||
|
gImgSizes[gNumImages] = (uint32)size;
|
||||||
|
strncpy(gCdImageNames[gNumImages], path, 63);
|
||||||
|
gNumImages++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
CdStreamGetImageName(int32 cd)
|
||||||
|
{
|
||||||
|
return cd < gNumImages ? gCdImageNames[cd] : nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CdStreamRemoveImages(void)
|
||||||
|
{
|
||||||
|
for(int32 i = 0; i < gNumChannels; i++)
|
||||||
|
CdStreamSync(i);
|
||||||
|
gNumImages = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32
|
||||||
|
CdStreamGetNumImages(void)
|
||||||
|
{
|
||||||
|
return gNumImages;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
455
src/core/WebFile.cpp
Normal file
455
src/core/WebFile.cpp
Normal file
|
|
@ -0,0 +1,455 @@
|
||||||
|
#include "common.h"
|
||||||
|
#include "crossplatform.h"
|
||||||
|
#include "WebFile.h"
|
||||||
|
|
||||||
|
#ifndef __EMSCRIPTEN__
|
||||||
|
|
||||||
|
FILE *
|
||||||
|
WebFileOpen(const char *path, const char *mode)
|
||||||
|
{
|
||||||
|
return fcaseopen(path, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
WebStreamsReady(void)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
WebFilePrefetch(const char *path, double fraction)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <emscripten.h>
|
||||||
|
#include <emscripten/fetch.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#define WEBFILE_TRACE(f, ...) printf("webfile: " f "\n", ## __VA_ARGS__)
|
||||||
|
|
||||||
|
static const int64 CHUNK_SIZE = 256 * 1024; // one HTTP request
|
||||||
|
static const int MAX_CHUNKS = 24; // cached per file (6 MB)
|
||||||
|
static const int MAX_RETRIES = 3;
|
||||||
|
|
||||||
|
struct WebChunk
|
||||||
|
{
|
||||||
|
int64 index;
|
||||||
|
std::vector<uint8> data;
|
||||||
|
uint32 lastUse;
|
||||||
|
bool loading;
|
||||||
|
bool failed;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct WebFileState
|
||||||
|
{
|
||||||
|
std::string url;
|
||||||
|
std::string rel;
|
||||||
|
bool closing; // closed by the game, deleted when its last fetch lands
|
||||||
|
int64 size;
|
||||||
|
int64 pos;
|
||||||
|
WebChunk chunks[MAX_CHUNKS];
|
||||||
|
uint32 useCounter;
|
||||||
|
bool samples; // sfx.raw: a missing part may play as silence
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::vector<WebFileState*> openFiles;
|
||||||
|
|
||||||
|
// Chunks fetched ahead of a radio switch.
|
||||||
|
struct PrefetchChunk
|
||||||
|
{
|
||||||
|
std::string rel;
|
||||||
|
int64 index;
|
||||||
|
std::vector<uint8> data;
|
||||||
|
uint32 lastUse;
|
||||||
|
bool loading;
|
||||||
|
bool failed;
|
||||||
|
};
|
||||||
|
static const size_t MAX_PREFETCH = 16;
|
||||||
|
static std::vector<PrefetchChunk*> prefetched;
|
||||||
|
static uint32 prefetchCounter;
|
||||||
|
|
||||||
|
static PrefetchChunk *
|
||||||
|
FindPrefetched(const std::string &rel, int64 index)
|
||||||
|
{
|
||||||
|
for(PrefetchChunk *p : prefetched)
|
||||||
|
if(p->index == index && p->rel == rel)
|
||||||
|
return p;
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
GamePlaying(void)
|
||||||
|
{
|
||||||
|
return EM_ASM_INT({ return window.vcPlaying ? 1 : 0; }) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct FetchJob
|
||||||
|
{
|
||||||
|
WebFileState *file;
|
||||||
|
WebChunk *chunk;
|
||||||
|
int retries;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void StartChunkFetch(FetchJob *job);
|
||||||
|
|
||||||
|
static void
|
||||||
|
OnChunkDone(emscripten_fetch_t *fetch)
|
||||||
|
{
|
||||||
|
FetchJob *job = (FetchJob*)fetch->userData;
|
||||||
|
bool ok = fetch->status == 206 || fetch->status == 200;
|
||||||
|
if(ok)
|
||||||
|
job->chunk->data.assign((const uint8*)fetch->data, (const uint8*)fetch->data + fetch->numBytes);
|
||||||
|
int status = fetch->status;
|
||||||
|
emscripten_fetch_close(fetch);
|
||||||
|
if(!ok && job->retries++ < MAX_RETRIES){
|
||||||
|
WEBFILE_TRACE("%s: HTTP %d, retrying", job->file->url.c_str(), status);
|
||||||
|
StartChunkFetch(job);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
job->chunk->failed = !ok;
|
||||||
|
job->chunk->loading = false;
|
||||||
|
WebFileState *file = job->file;
|
||||||
|
delete job;
|
||||||
|
if(file->closing){
|
||||||
|
for(int i = 0; i < MAX_CHUNKS; i++)
|
||||||
|
if(file->chunks[i].loading)
|
||||||
|
return;
|
||||||
|
delete file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
StartChunkFetch(FetchJob *job)
|
||||||
|
{
|
||||||
|
int64 from = job->chunk->index * CHUNK_SIZE;
|
||||||
|
int64 to = Min(from + CHUNK_SIZE, job->file->size) - 1;
|
||||||
|
char range[64];
|
||||||
|
snprintf(range, sizeof(range), "bytes=%lld-%lld", (long long)from, (long long)to);
|
||||||
|
const char *headers[] = { "Range", range, nil };
|
||||||
|
|
||||||
|
emscripten_fetch_attr_t attr;
|
||||||
|
emscripten_fetch_attr_init(&attr);
|
||||||
|
strcpy(attr.requestMethod, "GET");
|
||||||
|
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
|
||||||
|
attr.requestHeaders = headers; // copied by emscripten_fetch
|
||||||
|
attr.userData = job;
|
||||||
|
attr.onsuccess = OnChunkDone;
|
||||||
|
attr.onerror = OnChunkDone;
|
||||||
|
emscripten_fetch(&attr, job->file->url.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the slot holding chunk `index`, starting a fetch if it is not there yet.
|
||||||
|
static WebChunk *
|
||||||
|
RequestChunk(WebFileState *f, int64 index)
|
||||||
|
{
|
||||||
|
if(index < 0 || index * CHUNK_SIZE >= f->size)
|
||||||
|
return nil;
|
||||||
|
WebChunk *victim = nil;
|
||||||
|
for(int i = 0; i < MAX_CHUNKS; i++){
|
||||||
|
WebChunk *c = &f->chunks[i];
|
||||||
|
if(c->index == index && !c->failed){
|
||||||
|
c->lastUse = ++f->useCounter;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
if(c->loading)
|
||||||
|
continue;
|
||||||
|
if(victim == nil || c->lastUse < victim->lastUse)
|
||||||
|
victim = c;
|
||||||
|
}
|
||||||
|
if(victim == nil)
|
||||||
|
return nil; // every slot is loading; the caller waits and asks again
|
||||||
|
victim->index = index;
|
||||||
|
victim->data.clear();
|
||||||
|
PrefetchChunk *ready = FindPrefetched(f->rel, index);
|
||||||
|
if(ready && !ready->loading && !ready->failed){
|
||||||
|
victim->data = ready->data;
|
||||||
|
victim->loading = false;
|
||||||
|
victim->failed = false;
|
||||||
|
victim->lastUse = ++f->useCounter;
|
||||||
|
return victim;
|
||||||
|
}
|
||||||
|
victim->loading = true;
|
||||||
|
victim->failed = false;
|
||||||
|
victim->lastUse = ++f->useCounter;
|
||||||
|
StartChunkFetch(new FetchJob{ f, victim, 0 });
|
||||||
|
return victim;
|
||||||
|
}
|
||||||
|
|
||||||
|
// One request for a big read (a whole sample bank), straight into the caller's buffer.
|
||||||
|
static ssize_t
|
||||||
|
DirectRead(WebFileState *f, char *buf, size_t size)
|
||||||
|
{
|
||||||
|
struct Job { char *buf; size_t size; ssize_t result; bool done; } job = { buf, size, -1, false };
|
||||||
|
char range[64];
|
||||||
|
snprintf(range, sizeof(range), "bytes=%lld-%lld", (long long)f->pos, (long long)(f->pos + size - 1));
|
||||||
|
const char *headers[] = { "Range", range, nil };
|
||||||
|
// The first sound bank, which the game waits for, is also a file of its own: the CDN caches that name,
|
||||||
|
// while ranges of the big file crawl through it. If it is missing or differs, the range read takes over.
|
||||||
|
bool useHead = f->samples && f->pos == 0;
|
||||||
|
std::string headUrl = f->url + ".head.bin";
|
||||||
|
for(int attempt = 0; attempt <= MAX_RETRIES && job.result < 0; attempt++){
|
||||||
|
bool head = useHead && attempt == 0;
|
||||||
|
emscripten_fetch_attr_t attr;
|
||||||
|
emscripten_fetch_attr_init(&attr);
|
||||||
|
strcpy(attr.requestMethod, "GET");
|
||||||
|
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
|
||||||
|
attr.requestHeaders = head ? nil : headers;
|
||||||
|
attr.userData = &job;
|
||||||
|
attr.onsuccess = [](emscripten_fetch_t *fetch){
|
||||||
|
Job *j = (Job*)fetch->userData;
|
||||||
|
size_t n = Min(j->size, (size_t)fetch->numBytes);
|
||||||
|
memcpy(j->buf, fetch->data, n);
|
||||||
|
j->result = n;
|
||||||
|
j->done = true;
|
||||||
|
emscripten_fetch_close(fetch);
|
||||||
|
};
|
||||||
|
attr.onerror = [](emscripten_fetch_t *fetch){
|
||||||
|
((Job*)fetch->userData)->done = true;
|
||||||
|
emscripten_fetch_close(fetch);
|
||||||
|
};
|
||||||
|
job.done = false;
|
||||||
|
double waitStart = emscripten_get_now();
|
||||||
|
emscripten_fetch(&attr, head ? headUrl.c_str() : f->url.c_str());
|
||||||
|
while(!job.done)
|
||||||
|
emscripten_sleep(1);
|
||||||
|
if(head && job.result != (ssize_t)size) job.result = -1;
|
||||||
|
printf("[web] game waited %.0f ms for a direct read of %s (%zu bytes)\n", emscripten_get_now() - waitStart, f->url.c_str(), size);
|
||||||
|
}
|
||||||
|
if(job.result > 0)
|
||||||
|
f->pos += job.result;
|
||||||
|
return job.result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssize_t
|
||||||
|
CookieRead(void *cookie, char *buf, size_t size)
|
||||||
|
{
|
||||||
|
WebFileState *f = (WebFileState*)cookie;
|
||||||
|
if(f->pos >= f->size)
|
||||||
|
return 0;
|
||||||
|
size = (size_t)Min((int64)size, f->size - f->pos);
|
||||||
|
if((int64)size >= 4 * CHUNK_SIZE)
|
||||||
|
return DirectRead(f, buf, size);
|
||||||
|
size_t done = 0;
|
||||||
|
bool silenceOk = f->samples && GamePlaying();
|
||||||
|
while(done < size && f->pos < f->size){
|
||||||
|
int64 index = f->pos / CHUNK_SIZE;
|
||||||
|
WebChunk *c;
|
||||||
|
if(silenceOk){
|
||||||
|
c = RequestChunk(f, index);
|
||||||
|
if(c == nil || c->loading || c->failed){
|
||||||
|
size_t gap = (size_t)Min((int64)(size - done), (index + 1) * CHUNK_SIZE - f->pos);
|
||||||
|
memset(buf + done, 0, gap);
|
||||||
|
done += gap;
|
||||||
|
f->pos += gap;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
double waitStart = emscripten_get_now();
|
||||||
|
while((c = RequestChunk(f, index)) == nil || c->loading)
|
||||||
|
emscripten_sleep(1);
|
||||||
|
double waited = emscripten_get_now() - waitStart;
|
||||||
|
if(waited > 100.0)
|
||||||
|
printf("[web] game waited %.0f ms for %s (chunk %lld)\n", waited, f->url.c_str(), (long long)index);
|
||||||
|
if(c->failed)
|
||||||
|
return done > 0 ? (ssize_t)done : -1;
|
||||||
|
// Streams read forward: have the next chunk on its way before it is needed.
|
||||||
|
RequestChunk(f, index + 1);
|
||||||
|
int64 offset = f->pos - index * CHUNK_SIZE;
|
||||||
|
size_t n = (size_t)Min((int64)(size - done), (int64)c->data.size() - offset);
|
||||||
|
if(n == 0)
|
||||||
|
break;
|
||||||
|
memcpy(buf + done, c->data.data() + offset, n);
|
||||||
|
done += n;
|
||||||
|
f->pos += n;
|
||||||
|
}
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
CookieSeek(void *cookie, off_t *offset, int whence)
|
||||||
|
{
|
||||||
|
WebFileState *f = (WebFileState*)cookie;
|
||||||
|
int64 base = whence == SEEK_SET ? 0 : whence == SEEK_CUR ? f->pos : f->size;
|
||||||
|
int64 pos = base + *offset;
|
||||||
|
if(pos < 0)
|
||||||
|
return -1;
|
||||||
|
f->pos = pos;
|
||||||
|
*offset = pos;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
CookieClose(void *cookie)
|
||||||
|
{
|
||||||
|
WebFileState *f = (WebFileState*)cookie;
|
||||||
|
for(size_t i = 0; i < openFiles.size(); i++)
|
||||||
|
if(openFiles[i] == f){
|
||||||
|
openFiles.erase(openFiles.begin() + i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// A fetch still in flight writes into the chunk, so the state lives until it lands.
|
||||||
|
for(int i = 0; i < MAX_CHUNKS; i++)
|
||||||
|
if(f->chunks[i].loading){
|
||||||
|
f->closing = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
delete f;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string
|
||||||
|
RelativePath(const char *path)
|
||||||
|
{
|
||||||
|
std::string rel;
|
||||||
|
for(const char *p = path; *p; p++)
|
||||||
|
rel += *p == '\\' ? '/' : (char)tolower(*p);
|
||||||
|
while(rel.compare(0, 2, "./") == 0)
|
||||||
|
rel.erase(0, 2);
|
||||||
|
return rel;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double
|
||||||
|
RangedSize(const std::string &rel)
|
||||||
|
{
|
||||||
|
return EM_ASM_DOUBLE({
|
||||||
|
const map = Module.vcRangedMap;
|
||||||
|
const size = map && map.get(UTF8ToString($0));
|
||||||
|
return size === undefined ? -1 : size;
|
||||||
|
}, rel.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string
|
||||||
|
DataUrl(const std::string &rel)
|
||||||
|
{
|
||||||
|
char *base = (char*)EM_ASM_PTR({ return stringToNewUTF8(Module.vcDataUrl || "data"); });
|
||||||
|
std::string url = std::string(base) + "/" + rel;
|
||||||
|
free(base);
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
OnPrefetchDone(emscripten_fetch_t *fetch)
|
||||||
|
{
|
||||||
|
PrefetchChunk *p = (PrefetchChunk*)fetch->userData;
|
||||||
|
p->failed = !(fetch->status == 206 || fetch->status == 200);
|
||||||
|
if(!p->failed)
|
||||||
|
p->data.assign((const uint8*)fetch->data, (const uint8*)fetch->data + fetch->numBytes);
|
||||||
|
p->loading = false;
|
||||||
|
emscripten_fetch_close(fetch);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
PrefetchChunkReady(const std::string &rel, int64 size, int64 index)
|
||||||
|
{
|
||||||
|
if(index < 0 || index * CHUNK_SIZE >= size)
|
||||||
|
return true;
|
||||||
|
PrefetchChunk *p = FindPrefetched(rel, index);
|
||||||
|
if(p && p->failed && !p->loading){
|
||||||
|
// Leave it to the ordinary read, which retries and waits.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(p){
|
||||||
|
p->lastUse = ++prefetchCounter;
|
||||||
|
return !p->loading;
|
||||||
|
}
|
||||||
|
if(prefetched.size() >= MAX_PREFETCH){
|
||||||
|
PrefetchChunk *victim = nil;
|
||||||
|
for(PrefetchChunk *c : prefetched)
|
||||||
|
if(!c->loading && (victim == nil || c->lastUse < victim->lastUse))
|
||||||
|
victim = c;
|
||||||
|
if(victim == nil)
|
||||||
|
return false;
|
||||||
|
p = victim;
|
||||||
|
}else{
|
||||||
|
p = new PrefetchChunk();
|
||||||
|
prefetched.push_back(p);
|
||||||
|
}
|
||||||
|
p->rel = rel;
|
||||||
|
p->index = index;
|
||||||
|
p->data.clear();
|
||||||
|
p->lastUse = ++prefetchCounter;
|
||||||
|
p->loading = true;
|
||||||
|
p->failed = false;
|
||||||
|
|
||||||
|
int64 from = index * CHUNK_SIZE;
|
||||||
|
char range[64];
|
||||||
|
snprintf(range, sizeof(range), "bytes=%lld-%lld", (long long)from, (long long)(Min(from + CHUNK_SIZE, size) - 1));
|
||||||
|
const char *headers[] = { "Range", range, nil };
|
||||||
|
emscripten_fetch_attr_t attr;
|
||||||
|
emscripten_fetch_attr_init(&attr);
|
||||||
|
strcpy(attr.requestMethod, "GET");
|
||||||
|
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
|
||||||
|
attr.requestHeaders = headers;
|
||||||
|
attr.userData = p;
|
||||||
|
attr.onsuccess = OnPrefetchDone;
|
||||||
|
attr.onerror = OnPrefetchDone;
|
||||||
|
emscripten_fetch(&attr, DataUrl(rel).c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
WebFilePrefetch(const char *path, double fraction)
|
||||||
|
{
|
||||||
|
if(!GamePlaying())
|
||||||
|
return true;
|
||||||
|
std::string rel = RelativePath(path);
|
||||||
|
double size = RangedSize(rel);
|
||||||
|
if(size < 0)
|
||||||
|
return true;
|
||||||
|
int64 target = (int64)(Clamp(fraction, 0.0, 1.0) * size) / CHUNK_SIZE;
|
||||||
|
bool ready = PrefetchChunkReady(rel, (int64)size, 0);
|
||||||
|
// The decoder looks for a tag at the very end of the file when it opens it.
|
||||||
|
ready = PrefetchChunkReady(rel, (int64)size, ((int64)size - 1) / CHUNK_SIZE) && ready;
|
||||||
|
ready = PrefetchChunkReady(rel, (int64)size, target) && ready;
|
||||||
|
ready = PrefetchChunkReady(rel, (int64)size, target + 1) && ready;
|
||||||
|
return ready;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *
|
||||||
|
WebFileOpen(const char *path, const char *mode)
|
||||||
|
{
|
||||||
|
std::string rel = RelativePath(path);
|
||||||
|
double size = RangedSize(rel);
|
||||||
|
if(size < 0 || mode[0] != 'r')
|
||||||
|
return fcaseopen(path, mode);
|
||||||
|
|
||||||
|
WebFileState *f = new WebFileState();
|
||||||
|
f->url = DataUrl(rel);
|
||||||
|
f->rel = rel;
|
||||||
|
f->size = (int64)size;
|
||||||
|
for(int i = 0; i < MAX_CHUNKS; i++)
|
||||||
|
f->chunks[i].index = -1;
|
||||||
|
f->samples = rel.size() >= 4 && rel.compare(rel.size() - 4, 4, ".raw") == 0;
|
||||||
|
if(!f->samples)
|
||||||
|
openFiles.push_back(f);
|
||||||
|
|
||||||
|
cookie_io_functions_t io = { CookieRead, nil, CookieSeek, CookieClose };
|
||||||
|
return fopencookie(f, mode, io);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
WebStreamsReady(void)
|
||||||
|
{
|
||||||
|
if(openFiles.empty() || !GamePlaying())
|
||||||
|
return true;
|
||||||
|
bool ready = true;
|
||||||
|
for(WebFileState *f : openFiles){
|
||||||
|
if(f->pos >= f->size)
|
||||||
|
continue;
|
||||||
|
int64 index = f->pos / CHUNK_SIZE;
|
||||||
|
for(int64 i = index; i <= index + 1; i++){
|
||||||
|
if(i * CHUNK_SIZE >= f->size)
|
||||||
|
break;
|
||||||
|
WebChunk *c = RequestChunk(f, i);
|
||||||
|
if(c == nil || c->loading || c->failed)
|
||||||
|
ready = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ready;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
14
src/core/WebFile.h
Normal file
14
src/core/WebFile.h
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Opens a game file for reading. In the browser build, files the data manifest lists
|
||||||
|
// as "ranged" (big audio files) are not in memory: they are read over HTTP range
|
||||||
|
// requests in chunks, behind an ordinary FILE*. Everywhere else this is fcaseopen.
|
||||||
|
FILE *WebFileOpen(const char *path, const char *mode);
|
||||||
|
|
||||||
|
// False while a music or ambience file still waits for the data its decoder reads next. The game
|
||||||
|
// must not wait for the network: the stream skips its update and the sound catches up by itself.
|
||||||
|
bool WebStreamsReady(void);
|
||||||
|
|
||||||
|
// Radio switch: fetches the start of the file and the part around `fraction` (0..1) in the background.
|
||||||
|
// True once they are here, or when there is nothing to wait for. Opening the file afterwards does not wait.
|
||||||
|
bool WebFilePrefetch(const char *path, double fraction);
|
||||||
34
src/online/Online.cpp
Normal file
34
src/online/Online.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
#include "common.h"
|
||||||
|
#include "Online.h"
|
||||||
|
#include "OnlineSpawn.h"
|
||||||
|
#include "OnlineNet.h"
|
||||||
|
#include "World.h"
|
||||||
|
|
||||||
|
static bool spawned;
|
||||||
|
|
||||||
|
void
|
||||||
|
COnline::Init(void)
|
||||||
|
{
|
||||||
|
COnlineSpawn::Load();
|
||||||
|
COnlineNet::Load();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
COnline::Reset(void)
|
||||||
|
{
|
||||||
|
spawned = false;
|
||||||
|
COnlineNet::Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Runs after the scripts each frame. The free roam script creates the player on its
|
||||||
|
// first frame; the player is then moved to the beach once.
|
||||||
|
void
|
||||||
|
COnline::Process(void)
|
||||||
|
{
|
||||||
|
if(!spawned && FindPlayerPed()){
|
||||||
|
COnlineSpawn::SpawnPlayer();
|
||||||
|
COnlineNet::GiveStartWeapons();
|
||||||
|
spawned = true;
|
||||||
|
}
|
||||||
|
COnlineNet::Process();
|
||||||
|
}
|
||||||
10
src/online/Online.h
Normal file
10
src/online/Online.h
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Free roam online: entry points the game calls (see #ifdef ONLINE in core/).
|
||||||
|
class COnline
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void Init(void);
|
||||||
|
static void Reset(void);
|
||||||
|
static void Process(void);
|
||||||
|
};
|
||||||
30
src/online/OnlineData.cpp
Normal file
30
src/online/OnlineData.cpp
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
#include "common.h"
|
||||||
|
#include "OnlineData.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void
|
||||||
|
OnlineDataError(const char *path, const char *what)
|
||||||
|
{
|
||||||
|
std::string text = std::string("Online data error:\n") + path + ": " + what;
|
||||||
|
#ifdef _WIN32
|
||||||
|
MessageBoxA(nil, text.c_str(), "vc-online", MB_OK | MB_ICONERROR);
|
||||||
|
#endif
|
||||||
|
printf("%s\n", text.c_str());
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json
|
||||||
|
OnlineLoadJson(const char *path)
|
||||||
|
{
|
||||||
|
std::ifstream in(path);
|
||||||
|
nlohmann::json j = in ? nlohmann::json::parse(in, nil, false) : nlohmann::json();
|
||||||
|
if(j.is_discarded() || !j.is_object())
|
||||||
|
OnlineDataError(path, "cannot read the file");
|
||||||
|
return j;
|
||||||
|
}
|
||||||
6
src/online/OnlineData.h
Normal file
6
src/online/OnlineData.h
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#pragma once
|
||||||
|
#include "../../vendor/nlohmann/json.hpp"
|
||||||
|
|
||||||
|
// Reads a data file of the online mode; a missing or broken file stops the game with a message.
|
||||||
|
nlohmann::json OnlineLoadJson(const char *path);
|
||||||
|
[[noreturn]] void OnlineDataError(const char *path, const char *what);
|
||||||
1253
src/online/OnlineNet.cpp
Normal file
1253
src/online/OnlineNet.cpp
Normal file
File diff suppressed because it is too large
Load diff
19
src/online/OnlineNet.h
Normal file
19
src/online/OnlineNet.h
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Connection to the game server: sends the local player's state and shows the other players.
|
||||||
|
class COnlineNet
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void Load(void); // reads online/net.json
|
||||||
|
static void Process(void); // every frame while playing
|
||||||
|
static void GiveStartWeapons(void); // the weapons every player starts with
|
||||||
|
// True when ped is another player; a hit from the local player goes to the server.
|
||||||
|
static bool RemoteHit(class CPed *ped, class CEntity *by, int weapon, float damage);
|
||||||
|
static bool IsRemotePlayer(class CEntity *e);
|
||||||
|
static float AimAmount(void); // 0 walking around, 1 right button fully aimed
|
||||||
|
static float AimFov(float normal);
|
||||||
|
static float AimDistance(void);
|
||||||
|
static void DrawBubbles(void); // what players said, above their heads
|
||||||
|
static void PumpOutbox(void); // page messages to the server, every frame even in menus
|
||||||
|
static void Reset(void); // the world is being restarted: drop the remote players
|
||||||
|
};
|
||||||
78
src/online/OnlineSpawn.cpp
Normal file
78
src/online/OnlineSpawn.cpp
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
#include "common.h"
|
||||||
|
#include "OnlineSpawn.h"
|
||||||
|
#include "General.h"
|
||||||
|
#include "World.h"
|
||||||
|
#include "Streaming.h"
|
||||||
|
#include "PlayerPed.h"
|
||||||
|
#include "Camera.h"
|
||||||
|
|
||||||
|
#include "OnlineData.h"
|
||||||
|
#include <vector>
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
#include <emscripten.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct SpawnPoint
|
||||||
|
{
|
||||||
|
CVector pos;
|
||||||
|
float heading;
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::vector<SpawnPoint> points;
|
||||||
|
static float spreadRadius;
|
||||||
|
|
||||||
|
void
|
||||||
|
COnlineSpawn::Load(void)
|
||||||
|
{
|
||||||
|
nlohmann::json j = OnlineLoadJson("online/spawn.json");
|
||||||
|
if(!j.contains("points") || !j["points"].is_array() || j["points"].empty())
|
||||||
|
OnlineDataError("online/spawn.json", "\"points\" must list at least one spawn point");
|
||||||
|
if(!j.contains("spreadRadius") || !j["spreadRadius"].is_number())
|
||||||
|
OnlineDataError("online/spawn.json", "\"spreadRadius\" is missing");
|
||||||
|
points.clear();
|
||||||
|
for(auto &p : j["points"]){
|
||||||
|
if(!p.contains("x") || !p.contains("y") || !p.contains("heading"))
|
||||||
|
OnlineDataError("online/spawn.json", "every point needs x, y and heading");
|
||||||
|
points.push_back({ CVector(p["x"].get<float>(), p["y"].get<float>(), 0.0f), p["heading"].get<float>() });
|
||||||
|
}
|
||||||
|
spreadRadius = j["spreadRadius"].get<float>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// A random point, moved a little so players joining together do not stack up.
|
||||||
|
// The ground height is looked up once the area's collision is loaded. Heading in degrees, as CRestart uses.
|
||||||
|
void
|
||||||
|
COnlineSpawn::Pick(CVector *pos, float *heading)
|
||||||
|
{
|
||||||
|
const SpawnPoint &p = points[CGeneral::GetRandomNumberInRange(0, (int32)points.size())];
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
// The game's own generator starts from the same seed in every browser: everybody would draw the same spot.
|
||||||
|
float angle = (float)EM_ASM_DOUBLE({ return Math.random(); }) * TWOPI;
|
||||||
|
float dist = (float)EM_ASM_DOUBLE({ return Math.sqrt(Math.random()); }) * spreadRadius;
|
||||||
|
#else
|
||||||
|
float angle = CGeneral::GetRandomNumberInRange(0.0f, TWOPI);
|
||||||
|
float dist = CGeneral::GetRandomNumberInRange(0.0f, spreadRadius);
|
||||||
|
#endif
|
||||||
|
*pos = p.pos + CVector(Cos(angle) * dist, Sin(angle) * dist, 0.0f);
|
||||||
|
CStreaming::LoadSceneCollision(*pos);
|
||||||
|
bool found;
|
||||||
|
float z = CWorld::FindGroundZFor3DCoord(pos->x, pos->y, 1000.0f, &found);
|
||||||
|
pos->z = (found ? z : 10.0f) + 1.0f;
|
||||||
|
*heading = p.heading;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
COnlineSpawn::SpawnPlayer(void)
|
||||||
|
{
|
||||||
|
CPlayerPed *player = FindPlayerPed();
|
||||||
|
if(player == nil)
|
||||||
|
return;
|
||||||
|
CVector pos;
|
||||||
|
float heading;
|
||||||
|
Pick(&pos, &heading);
|
||||||
|
CStreaming::LoadScene(pos);
|
||||||
|
player->Teleport(pos);
|
||||||
|
heading = DEGTORAD(heading);
|
||||||
|
player->m_fRotationCur = player->m_fRotationDest = heading;
|
||||||
|
player->SetHeading(heading);
|
||||||
|
TheCamera.SetCameraDirectlyBehindForFollowPed_CamOnAString();
|
||||||
|
}
|
||||||
11
src/online/OnlineSpawn.h
Normal file
11
src/online/OnlineSpawn.h
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Where players appear: on joining and after every death or arrest.
|
||||||
|
// The points come from online/spawn.json next to the game data.
|
||||||
|
class COnlineSpawn
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void Load(void);
|
||||||
|
static void Pick(CVector *pos, float *heading);
|
||||||
|
static void SpawnPlayer(void);
|
||||||
|
};
|
||||||
57
tools/build-web.sh
Normal file
57
tools/build-web.sh
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Browser build: reVC + librw (GL3 over WebGL2) compiled with Emscripten into web/dist.
|
||||||
|
# Usage: EMSDK=/opt/emsdk tools/build-web.sh [jobs]
|
||||||
|
set -euo pipefail
|
||||||
|
JOBS=${1:-16}
|
||||||
|
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
||||||
|
cd "$ROOT"
|
||||||
|
set +u; source "${EMSDK:-/opt/emsdk}/emsdk_env.sh" >/dev/null 2>&1; set -u
|
||||||
|
emcc --version | head -1
|
||||||
|
OBJ=build/web/obj
|
||||||
|
OUT=web/dist
|
||||||
|
mkdir -p "$OBJ" "$OUT"
|
||||||
|
|
||||||
|
OPT=(-O3 -g0)
|
||||||
|
COMMON=("${OPT[@]}" -DNDEBUG -DRW_GL3 --use-port=contrib.glfw3 -Wno-everything)
|
||||||
|
RW_FLAGS=("${COMMON[@]}" -DLODEPNG_NO_COMPILE_CPP -Ivendor/librw)
|
||||||
|
GAME_FLAGS=("${COMMON[@]}" -std=c++17 -DLIBRW -DAUDIO_OAL -DCMAKE_BUILD -DUSE_OUR_VERSIONING
|
||||||
|
-sUSE_MPG123=1 -Ivendor/librw -Iweb/include)
|
||||||
|
for d in $(find src -type d); do GAME_FLAGS+=(-I"$d"); done
|
||||||
|
|
||||||
|
echo "#define GIT_SHA1 \"$(git rev-parse --short HEAD)\"
|
||||||
|
const char* g_GIT_SHA1 = GIT_SHA1;" > build/web/GitSHA1.cpp
|
||||||
|
|
||||||
|
# One compile per source; only sources newer than their object are rebuilt.
|
||||||
|
compile() { # src obj flags...
|
||||||
|
local src=$1 obj=$2; shift 2
|
||||||
|
if [ ! -f "$obj" ] || [ "$src" -nt "$obj" ]; then
|
||||||
|
mkdir -p "$(dirname "$obj")"
|
||||||
|
case $src in *.c) cc=emcc;; *) cc=em++;; esac
|
||||||
|
$cc "$@" -c "$src" -o "$obj" 2>"$obj.log" || { echo "FAIL $src"; cat "$obj.log" | grep -E "error" | head -20; return 1; }
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
export -f compile
|
||||||
|
|
||||||
|
RW_SRCS=$(find vendor/librw/src -name '*.cpp' -o -name '*.c')
|
||||||
|
GAME_SRCS=$(find src -name '*.cpp' | grep -v -e src/skel/win/ ; echo build/web/GitSHA1.cpp)
|
||||||
|
|
||||||
|
status=0
|
||||||
|
printf '%s\n' $RW_SRCS | xargs -P "$JOBS" -I{} bash -c 'compile "$1" "'"$OBJ"'/$1.o" "${@:2}"' _ {} "${RW_FLAGS[@]}" || status=1
|
||||||
|
printf '%s\n' $GAME_SRCS | xargs -P "$JOBS" -I{} bash -c 'compile "$1" "'"$OBJ"'/$1.o" "${@:2}"' _ {} "${GAME_FLAGS[@]}" || status=1
|
||||||
|
[ $status -eq 0 ] || { echo "compile failed"; exit 1; }
|
||||||
|
|
||||||
|
LINK_DEBUG=()
|
||||||
|
[ "${WEB_DEBUG:-0}" = 1 ] && LINK_DEBUG=(--profiling-funcs -sASSERTIONS=1)
|
||||||
|
[ "${WEB_DEBUG:-0}" = names ] && LINK_DEBUG=(--profiling-funcs)
|
||||||
|
OBJS=$(for s in $RW_SRCS $GAME_SRCS; do echo "$OBJ/$s.o"; done)
|
||||||
|
# WEB_ASYNC=jspi: the browser switches stacks itself and the game code stays uninstrumented.
|
||||||
|
if [ "${WEB_ASYNC:-asyncify}" = jspi ]; then ASYNC_FLAGS=(-sJSPI); ENGINE=revc-jspi; else ASYNC_FLAGS=(-sASYNCIFY -sASYNCIFY_STACK_SIZE=262144); ENGINE=revc; fi
|
||||||
|
em++ "${OPT[@]}" "${LINK_DEBUG[@]}" $OBJS -o "$OUT/$ENGINE.js" \
|
||||||
|
--use-port=contrib.glfw3 -sUSE_MPG123=1 -lopenal -lwebsocket.js \
|
||||||
|
-sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -sGL_ENABLE_GET_PROC_ADDRESS -sGL_TRACK_ERRORS=0 \
|
||||||
|
"${ASYNC_FLAGS[@]}" -sSTACK_SIZE=4MB \
|
||||||
|
-sALLOW_MEMORY_GROWTH -sINITIAL_MEMORY=512MB -sMAXIMUM_MEMORY=4GB \
|
||||||
|
-sFETCH -sFORCE_FILESYSTEM -lidbfs.js \
|
||||||
|
-sEXPORTED_RUNTIME_METHODS=FS,callMain -sINVOKE_RUN=0 -sEXIT_RUNTIME=0
|
||||||
|
cp web/shell/* "$OUT"/ 2>/dev/null || true
|
||||||
|
ls -la "$OUT"
|
||||||
19
tools/build-win.ps1
Normal file
19
tools/build-win.ps1
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Local Windows build (MSVC, below-normal priority) and install into a game folder.
|
||||||
|
# Usage: powershell -File tools/build-win.ps1 [-GameDir C:\Games\GTAVC] [-Jobs 4]
|
||||||
|
param([string]$GameDir = "C:\Games\GTAVC", [int]$Jobs = 4)
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
$root = Split-Path $PSScriptRoot -Parent
|
||||||
|
Set-Location $root
|
||||||
|
& .\premake5.exe vs2019 --with-librw --no-full-paths | Out-Null
|
||||||
|
$vs = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
|
||||||
|
$toolset = if (Test-Path "$vs\VC\Tools\MSVC\14.5*") { "v145" } else { "v143" }
|
||||||
|
$args = @("build\reVC.sln", "/m:$Jobs", "/nologo", "/v:minimal", "/p:Configuration=Release",
|
||||||
|
"/p:Platform=win-amd64-librw_d3d9-oal", "/p:PlatformToolset=$toolset", "/p:WindowsTargetPlatformVersion=10.0")
|
||||||
|
$p = Start-Process -FilePath "$vs\MSBuild\Current\Bin\MSBuild.exe" -ArgumentList $args -NoNewWindow -PassThru `
|
||||||
|
-RedirectStandardOutput build.log -RedirectStandardError build.err
|
||||||
|
$p.PriorityClass = "BelowNormal"; $p.WaitForExit()
|
||||||
|
$errors = Select-String -Path build.log -Pattern ": (fatal )?error " | ForEach-Object { $_.Line -replace '^.*\\src\\', 'src\' -replace ' \[.*$', '' } | Sort-Object -Unique
|
||||||
|
if ($errors) { $errors; exit 1 }
|
||||||
|
$bin = "bin\win-amd64-librw_d3d9-oal\Release"
|
||||||
|
Copy-Item "$bin\reVC.exe" $GameDir -Force
|
||||||
|
"built and installed to $GameDir"
|
||||||
50
tools/font-turkish.py
Normal file
50
tools/font-turkish.py
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# Adds the Turkish letters the menu font lacks, built from its own letters and accents.
|
||||||
|
# Usage: python tools/font-turkish.py web/shell/BowlbyOne.ttf
|
||||||
|
import sys
|
||||||
|
from fontTools.ttLib import TTFont
|
||||||
|
from fontTools.pens.ttGlyphPen import TTGlyphPen
|
||||||
|
from fontTools.pens.boundsPen import BoundsPen
|
||||||
|
|
||||||
|
path = sys.argv[1]
|
||||||
|
font = TTFont(path)
|
||||||
|
glyphs = font.getGlyphSet()
|
||||||
|
table = font['glyf']
|
||||||
|
cmap = font.getBestCmap()
|
||||||
|
cap_height = font['OS/2'].sCapHeight or 1400
|
||||||
|
x_height = font['OS/2'].sxHeight or 1000
|
||||||
|
|
||||||
|
|
||||||
|
def bounds(name):
|
||||||
|
pen = BoundsPen(glyphs)
|
||||||
|
glyphs[name].draw(pen)
|
||||||
|
return pen.bounds
|
||||||
|
|
||||||
|
|
||||||
|
def add(code, name, base, accent, above):
|
||||||
|
if code in cmap:
|
||||||
|
return
|
||||||
|
b, a = bounds(base), bounds(accent)
|
||||||
|
dx = (b[0] + b[2]) / 2 - (a[0] + a[2]) / 2
|
||||||
|
gap = (b[3] - b[1]) * 0.06
|
||||||
|
dy = b[3] + gap - a[1] if above else b[1] + gap - a[3]
|
||||||
|
pen = TTGlyphPen(glyphs)
|
||||||
|
pen.addComponent(base, (1, 0, 0, 1, 0, 0))
|
||||||
|
pen.addComponent(accent, (1, 0, 0, 1, round(dx), round(dy)))
|
||||||
|
glyph = pen.glyph()
|
||||||
|
table[name] = glyph
|
||||||
|
font['hmtx'][name] = font['hmtx'][base]
|
||||||
|
font.setGlyphOrder(font.getGlyphOrder() if name in font.getGlyphOrder() else font.getGlyphOrder() + [name])
|
||||||
|
for t in font['cmap'].tables:
|
||||||
|
if t.isUnicode():
|
||||||
|
t.cmap[code] = name
|
||||||
|
|
||||||
|
|
||||||
|
add(0x11E, 'Gbreve', 'G', 'breve', True)
|
||||||
|
add(0x11F, 'gbreve', 'g', 'breve', True)
|
||||||
|
add(0x15E, 'Scedilla', 'S', 'cedilla', False)
|
||||||
|
add(0x15F, 'scedilla', 's', 'cedilla', False)
|
||||||
|
add(0x130, 'Idotaccent', 'I', 'dotaccent', True)
|
||||||
|
font['maxp'].numGlyphs = len(font.getGlyphOrder())
|
||||||
|
font.save(path)
|
||||||
|
print('ok', len(font.getGlyphOrder()))
|
||||||
46
tools/make-manifest.ts
Normal file
46
tools/make-manifest.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
// Writes manifest.json into a game folder: the eager files (path + size) the browser
|
||||||
|
// loads before start-up and the ranged image files it streams, chosen by web/data-pack.json. The data host serves
|
||||||
|
// every file under its lower-case path, so the manifest uses lower case too.
|
||||||
|
// Usage: bun tools/make-manifest.ts <game dir>
|
||||||
|
import { Glob } from "bun";
|
||||||
|
import { createHash } from "node:crypto";
|
||||||
|
import { join, relative } from "node:path";
|
||||||
|
import { existsSync, statSync, writeFileSync, readFileSync } from "node:fs";
|
||||||
|
|
||||||
|
const gameDir = process.argv[2];
|
||||||
|
if (!gameDir) throw new Error("usage: bun tools/make-manifest.ts <game dir>");
|
||||||
|
const pack = JSON.parse(readFileSync(join(import.meta.dir, "../web/data-pack.json"), "utf8"));
|
||||||
|
const lower = (p: string) => p.replaceAll("\\", "/").toLowerCase();
|
||||||
|
const matches = (patterns: string[], path: string) => patterns.some((g) => new Glob(lower(g)).match(path));
|
||||||
|
|
||||||
|
const files: { path: string; size: number }[] = [];
|
||||||
|
const diskPath = new Map<string, string>(); // lower-case path -> real path on disk
|
||||||
|
const ranged: { path: string; size: number; memory?: boolean }[] = [];
|
||||||
|
for (const path of new Glob("**/*").scanSync({ cwd: gameDir, onlyFiles: true })) {
|
||||||
|
const rel = lower(path);
|
||||||
|
const size = statSync(join(gameDir, path)).size;
|
||||||
|
diskPath.set(rel, path);
|
||||||
|
if (matches(pack.skip, rel)) continue;
|
||||||
|
// A file named exactly in "eager" beats a "ranged" folder pattern.
|
||||||
|
const named = pack.eager.some((g: string) => !g.includes("*") && lower(g) === rel);
|
||||||
|
if (!named && matches(pack.ranged, rel)) ranged.push(matches(pack.memory ?? [], rel) ? { path: rel, size, memory: true } : { path: rel, size });
|
||||||
|
else if (matches(pack.eager, rel)) files.push({ path: rel, size });
|
||||||
|
}
|
||||||
|
files.sort((a, b) => a.path.localeCompare(b.path));
|
||||||
|
const total = files.reduce((n, f) => n + f.size, 0);
|
||||||
|
// All eager files in one blob, in manifest order: the browser fetches one file, not hundreds.
|
||||||
|
const bundle = Buffer.concat(files.map((f) => readFileSync(join(gameDir, diskPath.get(f.path)!))));
|
||||||
|
writeFileSync(join(gameDir, "eager.bin"), bundle);
|
||||||
|
// The start pack: the pieces of the world image the game reads at the spawn point (web/start-ranges.json).
|
||||||
|
let start: any;
|
||||||
|
const rangesFile = join(import.meta.dir, "../web/start-ranges.json");
|
||||||
|
if (existsSync(rangesFile)) {
|
||||||
|
const { key, ranges } = JSON.parse(readFileSync(rangesFile, "utf8"));
|
||||||
|
const image = readFileSync(join(gameDir, diskPath.get(key)!));
|
||||||
|
const pack = Buffer.concat(ranges.map(([at, size]: number[]) => image.subarray(at, at + size)));
|
||||||
|
writeFileSync(join(gameDir, "start.bin"), pack);
|
||||||
|
start = { path: "start.bin", key, ranges, hash: createHash("sha256").update(pack).digest("hex").slice(0, 16) };
|
||||||
|
console.log(`start pack ${(pack.length / 1048576).toFixed(1)} MB in ${ranges.length} ranges`);
|
||||||
|
}
|
||||||
|
writeFileSync(join(gameDir, "manifest.json"), JSON.stringify({ start, files, ranged, bundle: { path: "eager.bin", size: bundle.length, hash: createHash("sha256").update(bundle).digest("hex").slice(0, 16) } }, null, 0));
|
||||||
|
console.log(`${files.length} files, ${(total / 1048576).toFixed(1)} MB eager; ${ranged.length} ranged`);
|
||||||
60
tools/make-turkish-gxt.py
Normal file
60
tools/make-turkish-gxt.py
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
# Builds text/turkish.gxt: the Turkish text of the Gta Turk City mod (by Serdar "radreSword" Kilic),
|
||||||
|
# with the keys it lacks (settings this engine added) taken from the game's own american.gxt.
|
||||||
|
# Usage: python tools/make-turkish-gxt.py <mod american.gxt> <game american.gxt> <output>
|
||||||
|
import struct, sys
|
||||||
|
|
||||||
|
def read(path):
|
||||||
|
d = open(path, 'rb').read()
|
||||||
|
assert d[:4] == b'TABL', path
|
||||||
|
n = struct.unpack('<I', d[4:8])[0] // 12
|
||||||
|
out = {}
|
||||||
|
for i in range(n):
|
||||||
|
name = d[8 + i * 12:16 + i * 12]
|
||||||
|
off = struct.unpack('<I', d[16 + i * 12:20 + i * 12])[0]
|
||||||
|
p = off + (8 if i else 0)
|
||||||
|
assert d[p:p + 4] == b'TKEY', name
|
||||||
|
size = struct.unpack('<I', d[p + 4:p + 8])[0]
|
||||||
|
keys = p + 8
|
||||||
|
data = keys + size + 8
|
||||||
|
entries = {}
|
||||||
|
for k in range(size // 12):
|
||||||
|
o = struct.unpack('<I', d[keys + k * 12:keys + k * 12 + 4])[0]
|
||||||
|
key = d[keys + k * 12 + 4:keys + k * 12 + 12]
|
||||||
|
q = e = data + o
|
||||||
|
while d[e:e + 2] != b'\0\0':
|
||||||
|
e += 2
|
||||||
|
entries[key] = d[q:e]
|
||||||
|
out[name] = entries
|
||||||
|
return out
|
||||||
|
|
||||||
|
def write(path, tables):
|
||||||
|
names = [n for n in tables if n.rstrip(b'\0') == b'MAIN'] + sorted(n for n in tables if n.rstrip(b'\0') != b'MAIN')
|
||||||
|
body = bytearray()
|
||||||
|
start = 8 + 12 * len(names)
|
||||||
|
index = bytearray()
|
||||||
|
for i, name in enumerate(names):
|
||||||
|
offset = start + len(body)
|
||||||
|
index += name + struct.pack('<I', offset)
|
||||||
|
if i:
|
||||||
|
body += name
|
||||||
|
keys, text = bytearray(), bytearray()
|
||||||
|
for key in sorted(tables[name]):
|
||||||
|
keys += struct.pack('<I', len(text)) + key
|
||||||
|
text += tables[name][key] + b'\0\0'
|
||||||
|
body += b'TKEY' + struct.pack('<I', len(keys)) + keys + b'TDAT' + struct.pack('<I', len(text)) + text
|
||||||
|
if len(body) % 4:
|
||||||
|
body += b'\0' * (4 - len(body) % 4)
|
||||||
|
open(path, 'wb').write(b'TABL' + struct.pack('<I', len(index)) + index + body)
|
||||||
|
|
||||||
|
mod, game = read(sys.argv[1]), read(sys.argv[2])
|
||||||
|
added = 0
|
||||||
|
for name, entries in game.items():
|
||||||
|
target = mod.setdefault(name, {})
|
||||||
|
for key, value in entries.items():
|
||||||
|
if key not in target:
|
||||||
|
target[key] = value
|
||||||
|
added += 1
|
||||||
|
write(sys.argv[3], mod)
|
||||||
|
check = read(sys.argv[3])
|
||||||
|
assert check.keys() == mod.keys() and all(check[n] == mod[n] for n in mod)
|
||||||
|
print(f'{sum(len(t) for t in mod.values())} keys, {added} taken from the game')
|
||||||
23
tools/map-icons.ts
Normal file
23
tools/map-icons.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
// Reads every map icon the game's own script can place (data/main.scm) and writes online/mapicons.json,
|
||||||
|
// so the online map shows all locations although missions do not run. Usage: bun tools/map-icons.ts <game dir>
|
||||||
|
import { readFileSync, writeFileSync } from "node:fs";
|
||||||
|
const dir = process.argv[2];
|
||||||
|
if (!dir) throw new Error("usage: bun tools/map-icons.ts <game dir>");
|
||||||
|
const d = readFileSync(`${dir}/data/main.scm`);
|
||||||
|
const OPS = new Set([0x02a7, 0x02a8, 0x04ce, 0x0570]);
|
||||||
|
const seen = new Map<string, { sprite: number; x: number; y: number; z: number }>();
|
||||||
|
for (let i = 0; i + 24 < d.length; i++) {
|
||||||
|
if (!OPS.has(d.readUInt16LE(i))) continue;
|
||||||
|
if (d[i + 2] !== 6 || d[i + 7] !== 6 || d[i + 12] !== 6) continue;
|
||||||
|
const t = d[i + 17];
|
||||||
|
const sprite = t === 4 ? d.readInt8(i + 18) : t === 5 ? d.readInt16LE(i + 18) : t === 1 ? d.readInt32LE(i + 18) : -1;
|
||||||
|
if (sprite <= 0 || sprite > 60) continue;
|
||||||
|
const [x, y, z] = [d.readFloatLE(i + 3), d.readFloatLE(i + 8), d.readFloatLE(i + 13)];
|
||||||
|
if (Math.abs(x) > 3000 || Math.abs(y) > 3000) continue;
|
||||||
|
seen.set(`${sprite}:${Math.round(x)}:${Math.round(y)}`, { sprite, x: +x.toFixed(1), y: +y.toFixed(1), z: +z.toFixed(1) });
|
||||||
|
}
|
||||||
|
const icons = [...seen.values()].sort((a, b) => a.sprite - b.sprite);
|
||||||
|
writeFileSync(`${dir}/online/mapicons.json`, JSON.stringify({ icons }));
|
||||||
|
const count: Record<number, number> = {};
|
||||||
|
for (const c of icons) count[c.sprite] = (count[c.sprite] || 0) + 1;
|
||||||
|
console.log(icons.length, JSON.stringify(count));
|
||||||
80
tools/mobile-icons.py
Normal file
80
tools/mobile-icons.py
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# Turns the mobile version's HUD texture database (texdb/hud.dxt.*) into PNG files.
|
||||||
|
# Usage: python tools/mobile-icons.py <dir with hud.txt, hud.dxt.toc, hud.dxt.dat> <output dir>
|
||||||
|
import os, re, struct, sys
|
||||||
|
import numpy as np
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
src, out = sys.argv[1], sys.argv[2]
|
||||||
|
os.makedirs(out, exist_ok=True)
|
||||||
|
names = re.findall(r'^"([^"]+)"', open(f'{src}/hud.txt', encoding='latin1').read(), re.M)
|
||||||
|
toc = struct.unpack(f'<{os.path.getsize(src + "/hud.dxt.toc") // 4}I', open(f'{src}/hud.dxt.toc', 'rb').read())[1:]
|
||||||
|
dat = open(f'{src}/hud.dxt.dat', 'rb').read()
|
||||||
|
print(len(names), 'names', len(toc), 'offsets')
|
||||||
|
|
||||||
|
|
||||||
|
def c565(c):
|
||||||
|
return np.array([((c >> 11) & 31) * 255 // 31, ((c >> 5) & 63) * 255 // 63, (c & 31) * 255 // 31], dtype=np.int32)
|
||||||
|
|
||||||
|
|
||||||
|
def colour_block(b, opaque_only):
|
||||||
|
c0, c1, bits = struct.unpack('<HHI', b)
|
||||||
|
p = [c565(c0), c565(c1)]
|
||||||
|
alpha = [255, 255, 255, 255]
|
||||||
|
if c0 > c1 or opaque_only:
|
||||||
|
p += [(2 * p[0] + p[1]) // 3, (p[0] + 2 * p[1]) // 3]
|
||||||
|
else:
|
||||||
|
p += [(p[0] + p[1]) // 2, np.zeros(3, dtype=np.int32)]
|
||||||
|
alpha[3] = 0
|
||||||
|
px = np.zeros((4, 4, 4), dtype=np.uint8)
|
||||||
|
for i in range(16):
|
||||||
|
k = (bits >> (2 * i)) & 3
|
||||||
|
px[i // 4, i % 4, :3] = p[k]
|
||||||
|
px[i // 4, i % 4, 3] = alpha[k]
|
||||||
|
return px
|
||||||
|
|
||||||
|
|
||||||
|
def alpha5(b):
|
||||||
|
a0, a1 = b[0], b[1]
|
||||||
|
bits = int.from_bytes(b[2:8], 'little')
|
||||||
|
t = [a0, a1]
|
||||||
|
if a0 > a1:
|
||||||
|
t += [((7 - i) * a0 + i * a1) // 7 for i in range(1, 7)]
|
||||||
|
else:
|
||||||
|
t += [((5 - i) * a0 + i * a1) // 5 for i in range(1, 5)] + [0, 255]
|
||||||
|
return np.array([t[(bits >> (3 * i)) & 7] for i in range(16)], dtype=np.uint8).reshape(4, 4)
|
||||||
|
|
||||||
|
|
||||||
|
def decode(kind, w, h, d):
|
||||||
|
img = np.zeros((h, w, 4), dtype=np.uint8)
|
||||||
|
size = 8 if kind in (0x83f0, 0x83f1) else 16
|
||||||
|
at = 0
|
||||||
|
for y in range(0, h, 4):
|
||||||
|
for x in range(0, w, 4):
|
||||||
|
if kind in (0x83f0, 0x83f1):
|
||||||
|
px = colour_block(d[at:at + 8], False)
|
||||||
|
elif kind == 0x83f2:
|
||||||
|
px = colour_block(d[at + 8:at + 16], True)
|
||||||
|
bits = int.from_bytes(d[at:at + 8], 'little')
|
||||||
|
px[:, :, 3] = np.array([((bits >> (4 * i)) & 15) * 17 for i in range(16)], dtype=np.uint8).reshape(4, 4)
|
||||||
|
else:
|
||||||
|
px = colour_block(d[at + 8:at + 16], True)
|
||||||
|
px[:, :, 3] = alpha5(d[at:at + 8])
|
||||||
|
at += size
|
||||||
|
img[y:y + 4, x:x + 4] = px[:min(4, h - y), :min(4, w - x)]
|
||||||
|
return img
|
||||||
|
|
||||||
|
|
||||||
|
done = 0
|
||||||
|
kinds = {}
|
||||||
|
for name, off in zip(names, toc):
|
||||||
|
if off == 0xffffffff:
|
||||||
|
continue
|
||||||
|
_, kind, w, h = struct.unpack('<HHHH', dat[off:off + 8])
|
||||||
|
h &= 0x7fff
|
||||||
|
kinds[hex(kind)] = kinds.get(hex(kind), 0) + 1
|
||||||
|
if kind not in (0x83f0, 0x83f1, 0x83f2, 0x83f3) or not w or not h or w & 3 or h & 3:
|
||||||
|
continue
|
||||||
|
Image.fromarray(decode(kind, w, h, dat[off + 8:]), 'RGBA').save(f'{out}/{name}.png')
|
||||||
|
done += 1
|
||||||
|
print('saved', done, 'formats', kinds)
|
||||||
58
tools/online-icons.py
Normal file
58
tools/online-icons.py
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# Puts the mobile game's pictures the page uses into <game dir>/online/icons, from the output of mobile-icons.py.
|
||||||
|
# Button pictures keep their name, weapons become w<type>.png, and the two buttons the game has no picture for
|
||||||
|
# are made from its own parts. Usage: python tools/online-icons.py <mobile icons dir> <game dir>
|
||||||
|
import json, os, re, struct, sys
|
||||||
|
import numpy as np
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
src, game = sys.argv[1], sys.argv[2]
|
||||||
|
out = f'{game}/online/icons'
|
||||||
|
os.makedirs(out, exist_ok=True)
|
||||||
|
menu = json.load(open(os.path.join(os.path.dirname(__file__), '../gamefiles/online/menu.json'), encoding='utf-8'))
|
||||||
|
|
||||||
|
hud = lambda name: Image.open(f'{src}/hud_{name}.png').convert('RGBA')
|
||||||
|
names = {b['icon'] for b in menu['touch']['buttons'] if 'icon' in b and 'parts' not in b} | {'circle', 'analognub'}
|
||||||
|
for name in names:
|
||||||
|
hud(name).save(f'{out}/{name}.png')
|
||||||
|
for w in menu['weapons']:
|
||||||
|
hud(w['icon']).save(f'{out}/w{w["type"]}.png')
|
||||||
|
for b in menu['touch']['buttons']:
|
||||||
|
if 'parts' not in b:
|
||||||
|
continue
|
||||||
|
base = hud(b['parts'][0])
|
||||||
|
mark = hud(b['parts'][1])
|
||||||
|
mark.thumbnail((base.width * 11 // 20, base.height * 11 // 20))
|
||||||
|
base.alpha_composite(mark, ((base.width - mark.width) // 2, (base.height - mark.height) // 2))
|
||||||
|
base.save(f'{out}/{b["icon"]}.png')
|
||||||
|
|
||||||
|
|
||||||
|
# The station logos are in the PC game's menu textures: DXT3, 128 x 128.
|
||||||
|
def c565(c):
|
||||||
|
return np.array([((c >> 11) & 31) * 255 // 31, ((c >> 5) & 63) * 255 // 63, (c & 31) * 255 // 31])
|
||||||
|
|
||||||
|
|
||||||
|
def dxt3(d, w, h):
|
||||||
|
img = np.zeros((h, w, 4), np.uint8)
|
||||||
|
at = 0
|
||||||
|
for y in range(0, h, 4):
|
||||||
|
for x in range(0, w, 4):
|
||||||
|
alpha = int.from_bytes(d[at:at + 8], 'little')
|
||||||
|
c0, c1, bits = struct.unpack('<HHI', d[at + 8:at + 16])
|
||||||
|
p = [c565(c0), c565(c1)]
|
||||||
|
p += [(2 * p[0] + p[1]) // 3, (p[0] + 2 * p[1]) // 3]
|
||||||
|
for i in range(16):
|
||||||
|
img[y + i // 4, x + i % 4, :3] = p[(bits >> (2 * i)) & 3]
|
||||||
|
img[y + i // 4, x + i % 4, 3] = ((alpha >> (4 * i)) & 15) * 17
|
||||||
|
at += 16
|
||||||
|
return Image.fromarray(img, 'RGBA')
|
||||||
|
|
||||||
|
|
||||||
|
txd = open(f'{game}/models/fronten2.txd', 'rb').read()
|
||||||
|
stations = {r['icon']: r['station'] for r in menu['radio'] if 'icon' in r}
|
||||||
|
for m in re.finditer(rb'\x15\x00\x00\x00', txd):
|
||||||
|
s = m.start() + 24
|
||||||
|
name = txd[s + 8:s + 40].split(b'\0')[0].decode('latin1')
|
||||||
|
if name in stations:
|
||||||
|
dxt3(txd[s + 92:s + 92 + 128 * 128], 128, 128).save(f'{out}/r{stations[name]}.png')
|
||||||
|
print(len(os.listdir(out)), 'pictures')
|
||||||
38
tools/readme-shots.ts
Normal file
38
tools/readme-shots.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
// Takes the README pictures from a real two-player session: headless, muted, local game server only.
|
||||||
|
// Needs: bun tools/serve.ts web/dist <game dir> 8790 and bun server/main.ts on 8791.
|
||||||
|
import { chromium } from "playwright-core";
|
||||||
|
import { mkdirSync } from "node:fs";
|
||||||
|
const out = "docs/shots";
|
||||||
|
mkdirSync(out, { recursive: true });
|
||||||
|
const url = "http://127.0.0.1:8790/?mute=1&server=ws://127.0.0.1:8791/ws";
|
||||||
|
const b = await chromium.launch({ channel: "chrome", headless: true, args: ["--mute-audio"] });
|
||||||
|
async function player(name: string) {
|
||||||
|
const c = await b.newContext({ viewport: { width: 1280, height: 720 } });
|
||||||
|
await c.addInitScript((n) => { try { localStorage.setItem("vcNamed", "1"); localStorage.setItem("vcName", n); } catch (e) {} }, name);
|
||||||
|
const p = await c.newPage();
|
||||||
|
await p.goto(url);
|
||||||
|
await p.waitForFunction(() => (window as any).vcPlaying, null, { timeout: 240000, polling: 500 });
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
const wait = (s: number) => new Promise((r) => setTimeout(r, s * 1000));
|
||||||
|
const shot = (p: any, name: string) => p.screenshot({ path: `${out}/${name}.jpg`, type: "jpeg", quality: 82, timeout: 90000 });
|
||||||
|
const cmd = (p: any, c: string) => p.evaluate((x: string) => { const M = (window as any).Module; (M.vcCmds || (M.vcCmds = [])).push(x); }, c);
|
||||||
|
const a = await player("crt"), other = await player("tommy");
|
||||||
|
await wait(15);
|
||||||
|
await shot(a, "players");
|
||||||
|
await a.keyboard.press("b");
|
||||||
|
await wait(2);
|
||||||
|
await shot(a, "vehicles");
|
||||||
|
await a.keyboard.press("Escape");
|
||||||
|
await wait(1);
|
||||||
|
await a.keyboard.down("q");
|
||||||
|
await wait(2);
|
||||||
|
await shot(a, "wheel");
|
||||||
|
await a.keyboard.up("q");
|
||||||
|
await wait(1);
|
||||||
|
await cmd(other, "car infernus");
|
||||||
|
await cmd(a, "car cheetah");
|
||||||
|
await wait(8);
|
||||||
|
await shot(a, "cars");
|
||||||
|
await Promise.race([b.close(), wait(5)]);
|
||||||
|
process.exit(0);
|
||||||
42
tools/serve.ts
Normal file
42
tools/serve.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
// Local dev server: the web build at / and a game folder at /data/, with HTTP range
|
||||||
|
// requests and case-insensitive paths (the browser asks for lower-case names).
|
||||||
|
// Usage: bun tools/serve.ts <dist dir> <game dir> [port]
|
||||||
|
import { join } from "node:path";
|
||||||
|
import { readdirSync, existsSync, statSync } from "node:fs";
|
||||||
|
|
||||||
|
const [dist, gameDir, port = "8790"] = process.argv.slice(2);
|
||||||
|
if (!dist || !gameDir) throw new Error("usage: bun tools/serve.ts <dist dir> <game dir> [port]");
|
||||||
|
|
||||||
|
// Finds "models/gta3.img" as "MODELS/GTA3.IMG" or any other casing on disk.
|
||||||
|
function resolveCase(root: string, rel: string): string | null {
|
||||||
|
let dir = root;
|
||||||
|
for (const part of rel.split("/").filter(Boolean)) {
|
||||||
|
if (part === "..") return null;
|
||||||
|
const hit = readdirSync(dir).find((n) => n.toLowerCase() === part.toLowerCase());
|
||||||
|
if (!hit) return null;
|
||||||
|
dir = join(dir, hit);
|
||||||
|
}
|
||||||
|
return existsSync(dir) && statSync(dir).isFile() ? dir : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bun.serve({
|
||||||
|
port: Number(port),
|
||||||
|
hostname: "127.0.0.1",
|
||||||
|
fetch(req) {
|
||||||
|
const path = decodeURIComponent(new URL(req.url).pathname);
|
||||||
|
const file = path.startsWith("/data/")
|
||||||
|
? resolveCase(gameDir, path.slice(6))
|
||||||
|
: resolveCase(dist, path === "/" ? "index.html" : path.slice(1));
|
||||||
|
if (!file) return new Response("not found", { status: 404 });
|
||||||
|
const body = Bun.file(file);
|
||||||
|
const range = req.headers.get("range")?.match(/bytes=(\d+)-(\d*)/);
|
||||||
|
if (!range) return new Response(body, { headers: { "Accept-Ranges": "bytes" } });
|
||||||
|
const start = Number(range[1]);
|
||||||
|
const end = range[2] ? Math.min(Number(range[2]), body.size - 1) : body.size - 1;
|
||||||
|
return new Response(body.slice(start, end + 1), {
|
||||||
|
status: 206,
|
||||||
|
headers: { "Content-Range": `bytes ${start}-${end}/${body.size}`, "Accept-Ranges": "bytes" },
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log(`serving on http://127.0.0.1:${port}`);
|
||||||
40
tools/stage-site.ts
Normal file
40
tools/stage-site.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
// Builds build/site: the web build at / and exactly the game files the manifest lists at /data/,
|
||||||
|
// under lower-case names (the browser asks for lower-case paths, a Linux server is case-sensitive).
|
||||||
|
// Usage: bun tools/stage-site.ts <dist dir> <game dir> [out dir]
|
||||||
|
import { join, dirname } from "node:path";
|
||||||
|
import { readdirSync, mkdirSync, copyFileSync, existsSync, statSync, rmSync, cpSync } from "node:fs";
|
||||||
|
|
||||||
|
const [dist, gameDir, out = "build/site"] = process.argv.slice(2);
|
||||||
|
if (!dist || !gameDir) throw new Error("usage: bun tools/stage-site.ts <dist dir> <game dir> [out dir]");
|
||||||
|
|
||||||
|
function resolveCase(root: string, rel: string): string | null {
|
||||||
|
let dir = root;
|
||||||
|
for (const part of rel.split("/").filter(Boolean)) {
|
||||||
|
const hit = readdirSync(dir).find((n) => n.toLowerCase() === part.toLowerCase());
|
||||||
|
if (!hit) return null;
|
||||||
|
dir = join(dir, hit);
|
||||||
|
}
|
||||||
|
return existsSync(dir) && statSync(dir).isFile() ? dir : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
rmSync(out, { recursive: true, force: true });
|
||||||
|
cpSync(dist, out, { recursive: true });
|
||||||
|
|
||||||
|
const manifestPath = join(gameDir, "manifest.json");
|
||||||
|
const manifest = await Bun.file(manifestPath).json();
|
||||||
|
mkdirSync(join(out, "data"), { recursive: true });
|
||||||
|
copyFileSync(manifestPath, join(out, "data", "manifest.json"));
|
||||||
|
copyFileSync(join(gameDir, "eager.bin"), join(out, "data", "eager.bin"));
|
||||||
|
|
||||||
|
let bytes = 0, count = 0, missing: string[] = [];
|
||||||
|
for (const f of [...manifest.files, ...manifest.ranged] as { path: string }[]) {
|
||||||
|
const src = resolveCase(gameDir, f.path);
|
||||||
|
if (!src) { missing.push(f.path); continue; }
|
||||||
|
const dst = join(out, "data", f.path.toLowerCase());
|
||||||
|
mkdirSync(dirname(dst), { recursive: true });
|
||||||
|
copyFileSync(src, dst);
|
||||||
|
bytes += statSync(dst).size;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
console.log(`${count} files, ${(bytes / 1048576).toFixed(0)} MB staged in ${out}`);
|
||||||
|
if (missing.length) { console.error("missing:", missing.slice(0, 10)); process.exit(1); }
|
||||||
8
tools/stamp-index.sh
Normal file
8
tools/stamp-index.sh
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Writes build/index.stamped.html: the page with the version of the engine in web/dist.
|
||||||
|
set -e
|
||||||
|
V=$(cat web/dist/revc.js web/dist/revc.wasm web/dist/revc-jspi.js web/dist/revc-jspi.wasm | sha256sum | cut -c1-12)
|
||||||
|
# Apache prefers these over the originals, so they must always match: upload them with the engine.
|
||||||
|
for f in revc.js revc.wasm revc-jspi.js revc-jspi.wasm; do brotli -f -q 11 -k "web/dist/$f" -o "web/dist/$f.br"; done
|
||||||
|
sed "s/__ENGINE_V__/$V/g" web/shell/index.html > build/index.stamped.html
|
||||||
|
echo "$V"
|
||||||
39
tools/thumbs.ts
Normal file
39
tools/thumbs.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
// Takes the vehicle pictures for the menu from the running game (photo mode), for every vehicle in menu.json.
|
||||||
|
// Needs: bun tools/serve.ts web/dist <game dir> 8790 and bun server/main.ts on 8791.
|
||||||
|
// Usage: bun tools/thumbs.ts <game dir>
|
||||||
|
import { chromium } from "playwright-core";
|
||||||
|
import { mkdirSync, readFileSync } from "node:fs";
|
||||||
|
const dir = process.argv[2];
|
||||||
|
if (!dir) throw new Error("usage: bun tools/thumbs.ts <game dir>");
|
||||||
|
const { cars, weapons } = JSON.parse(readFileSync(`${dir}/online/menu.json`, "utf8"));
|
||||||
|
const out = `${dir}/online/thumbs`;
|
||||||
|
mkdirSync(out, { recursive: true });
|
||||||
|
const w = 1600, h = 900, k = w / 1280;
|
||||||
|
const b = await chromium.launch({ channel: "chrome", headless: true, args: ["--mute-audio"] });
|
||||||
|
const p = await (await b.newContext({ viewport: { width: w, height: h } })).newPage();
|
||||||
|
p.on("console", (m) => { if (/error|abort|cannot|failed/i.test(m.text())) console.log("console:", m.text().slice(0, 200)); });
|
||||||
|
p.on("pageerror", (e) => console.log("pageerror", String(e).slice(0, 300)));
|
||||||
|
await p.addInitScript(() => { try { localStorage.setItem("vcNamed", "1"); } catch (e) {} });
|
||||||
|
await p.goto("http://127.0.0.1:8790/?mute=1&server=ws://127.0.0.1:8791/ws");
|
||||||
|
// Photo mode wears the engine out after a few dozen vehicles: a fresh page for each batch.
|
||||||
|
async function ready() {
|
||||||
|
await p.waitForFunction(() => (window as any).vcPlaying, null, { timeout: 180000, polling: 500 });
|
||||||
|
await p.addStyleTag({ content: ".ui { display: none !important; }" });
|
||||||
|
await new Promise((r) => setTimeout(r, 6000));
|
||||||
|
}
|
||||||
|
await ready();
|
||||||
|
let shot = 0;
|
||||||
|
for (const g of weapons) {
|
||||||
|
await p.evaluate((t) => { const M = (window as any).Module; (M.vcCmds || (M.vcCmds = [])).push("weapon " + t); }, g.type);
|
||||||
|
await new Promise((r) => setTimeout(r, 1200));
|
||||||
|
await p.screenshot({ path: `${out}/w${g.type}.jpg`, type: "jpeg", quality: 85, timeout: 90000, clip: { x: 1132 * k, y: 38 * k, width: 96 * k, height: 96 * k } });
|
||||||
|
}
|
||||||
|
for (const c of cars) {
|
||||||
|
if (shot++ % 12 === 0) { await p.reload(); await ready(); }
|
||||||
|
await p.evaluate((m) => { const M = (window as any).Module; (M.vcCmds || (M.vcCmds = [])).push("photo " + m); }, c.model);
|
||||||
|
await new Promise((r) => setTimeout(r, 2500));
|
||||||
|
await p.screenshot({ path: `${out}/${c.model}.jpg`, type: "jpeg", quality: 80, timeout: 90000, clip: c.bike ? { x: 531 * k, y: 280 * k, width: 220 * k, height: 124 * k } : { x: 451 * k, y: 268 * k, width: 330 * k, height: 186 * k } });
|
||||||
|
console.log(c.model);
|
||||||
|
}
|
||||||
|
await Promise.race([b.close(), new Promise((r) => setTimeout(r, 4000))]);
|
||||||
|
process.exit(0);
|
||||||
24
tools/trace-start.ts
Normal file
24
tools/trace-start.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
// Records what the game reads from the world image at the spawn point and writes web/start-ranges.json.
|
||||||
|
// Headless, muted, and not connected to the game server. Usage: bun tools/trace-start.ts <page url>
|
||||||
|
import { chromium } from "playwright-core";
|
||||||
|
import { join } from "node:path";
|
||||||
|
const url = process.argv[2];
|
||||||
|
const br = await chromium.launch({ channel: "chrome", headless: true, args: ["--mute-audio"] });
|
||||||
|
const p = await (await br.newContext({ viewport: { width: 1280, height: 720 } })).newPage();
|
||||||
|
await p.addInitScript(() => { try { localStorage.setItem("vcNamed", "1"); } catch (e) {} });
|
||||||
|
await p.goto(`${url}?mute=1&imgdelay=900&readlog=1&server=ws://127.0.0.1:9/ws`);
|
||||||
|
await p.waitForFunction(() => (window as any).vcPlaying, null, { timeout: 240000, polling: 500 });
|
||||||
|
await p.waitForTimeout(30000); // the first seconds of play load what stands around the player
|
||||||
|
const log: string[] = await p.evaluate(() => (window as any).Module.vcReadLog);
|
||||||
|
await Promise.race([br.close(), new Promise((r) => setTimeout(r, 4000))]);
|
||||||
|
const reads = log.map((l) => l.split(":").map(Number)).sort((a, b) => a[0] - b[0]);
|
||||||
|
const ranges: number[][] = [];
|
||||||
|
for (const [at, size] of reads) {
|
||||||
|
const last = ranges[ranges.length - 1];
|
||||||
|
if (last && at <= last[0] + last[1]) last[1] = Math.max(last[1], at + size - last[0]);
|
||||||
|
else ranges.push([at, size]);
|
||||||
|
}
|
||||||
|
const total = ranges.reduce((n, r) => n + r[1], 0);
|
||||||
|
await Bun.write(join(import.meta.dir, "../web/start-ranges.json"), JSON.stringify({ key: "models/gta3.img", ranges }));
|
||||||
|
console.log(`${log.length} reads, ${ranges.length} ranges, ${(total / 1048576).toFixed(1)} MB`);
|
||||||
|
process.exit(0);
|
||||||
86
tools/webcheck.ts
Normal file
86
tools/webcheck.ts
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
// Plays the web build in a hidden, muted Chrome the way a player would (real key
|
||||||
|
// events) and reports what happened: game states, frame stalls, audio level, errors.
|
||||||
|
// Usage: bun tools/webcheck.ts [url] [--radio] [--shot out.png] [--log <regex>]
|
||||||
|
import { chromium, type Page } from "playwright-core";
|
||||||
|
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
const url = args.find((a) => a.startsWith("http")) ?? "http://127.0.0.1:8790/?mute=1";
|
||||||
|
const shot = args.includes("--shot") ? args[args.indexOf("--shot") + 1] : null;
|
||||||
|
const radio = args.includes("--radio");
|
||||||
|
const dpr = args.includes("--dpr") ? Number(args[args.indexOf("--dpr") + 1]) : 1;
|
||||||
|
const [vw, vh] = (args.includes("--size") ? args[args.indexOf("--size") + 1] : "1280x720").split("x").map(Number);
|
||||||
|
const logFilter = args.includes("--log") ? new RegExp(args[args.indexOf("--log") + 1], "i") : null;
|
||||||
|
|
||||||
|
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
||||||
|
const report: Record<string, unknown> = {};
|
||||||
|
const errors: string[] = [];
|
||||||
|
|
||||||
|
async function waitLog(page: Page, re: RegExp, timeoutMs: number) {
|
||||||
|
const start = Date.now();
|
||||||
|
while (Date.now() - start < timeoutMs) {
|
||||||
|
const hit = await page.evaluate((src) => (window as any).vcLog?.some((l: any) => new RegExp(src).test(l.text)) || (src.includes("GS_PLAYING_GAME") && (window as any).vcPlaying), re.source);
|
||||||
|
if (hit) return Date.now() - start;
|
||||||
|
await sleep(250);
|
||||||
|
}
|
||||||
|
const tail = await page.evaluate(() => (window as any).vcLog?.slice(-15).map((l: any) => l.text));
|
||||||
|
throw new Error(`timed out waiting for ${re}\n${(tail ?? []).join("\n")}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function press(page: Page, key: string, holdMs = 150) {
|
||||||
|
await page.keyboard.down(key);
|
||||||
|
await sleep(holdMs);
|
||||||
|
await page.keyboard.up(key);
|
||||||
|
await sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Longest gap between frames (ms) while `action` runs.
|
||||||
|
async function measureStall(page: Page, action: () => Promise<void>) {
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const gl = (document.getElementById("canvas") as HTMLCanvasElement).getContext("webgl2")!;
|
||||||
|
const w = window as any;
|
||||||
|
w.vcFrames = [];
|
||||||
|
if (!w.vcClearHooked) {
|
||||||
|
const clear = gl.clear.bind(gl);
|
||||||
|
gl.clear = (m: number) => { w.vcFrames.push(performance.now()); clear(m); };
|
||||||
|
w.vcClearHooked = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await action();
|
||||||
|
return page.evaluate(() => {
|
||||||
|
const f: number[] = (window as any).vcFrames;
|
||||||
|
let worst = 0;
|
||||||
|
for (let i = 1; i < f.length; i++) worst = Math.max(worst, f[i] - f[i - 1]);
|
||||||
|
return { frames: f.length, worstGapMs: Math.round(worst) };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const browser = await chromium.launch({ channel: "chrome", headless: true, args: ["--mute-audio", "--autoplay-policy=no-user-gesture-required"] });
|
||||||
|
try {
|
||||||
|
const page = await browser.newPage({ viewport: { width: vw, height: vh }, deviceScaleFactor: dpr });
|
||||||
|
|
||||||
|
page.on("pageerror", (e) => errors.push(String(e.stack ?? e).slice(0, 1500)));
|
||||||
|
await page.goto(url);
|
||||||
|
report.loadMs = await waitLog(page, /GS_PLAYING_GAME/, 90000);
|
||||||
|
await sleep(Number(process.env.VC_WAIT ?? 4000));
|
||||||
|
if (radio) {
|
||||||
|
await press(page, "f", 300);
|
||||||
|
await sleep(4000);
|
||||||
|
const switches = [];
|
||||||
|
for (let i = 0; i < 4; i++) switches.push(await measureStall(page, async () => { await press(page, "Insert"); await sleep(2500); }));
|
||||||
|
report.radioSwitches = switches;
|
||||||
|
}
|
||||||
|
if (args.includes("--pause")) { await press(page, "Escape", 300); await sleep(1500); }
|
||||||
|
report.idle = await measureStall(page, () => sleep(3000));
|
||||||
|
report.audioLevel = await page.evaluate(() => (window as any).vcAudioLevel?.() ?? null);
|
||||||
|
report.audioFiles = await page.evaluate(() => [...new Set(performance.getEntriesByType("resource")
|
||||||
|
.map((e) => e.name).filter((n) => /\/audio\//i.test(n)).map((n) => n.split("/").pop()))]);
|
||||||
|
if (shot) await page.screenshot({ path: shot });
|
||||||
|
if (logFilter) report.log = await page.evaluate((src) => (window as any).vcLog.filter((l: any) => new RegExp(src, "i").test(l.text)).slice(-30).map((l: any) => l.text), logFilter.source);
|
||||||
|
report.errors = errors;
|
||||||
|
} catch (e) {
|
||||||
|
report.failure = String(e).slice(0, 3000);
|
||||||
|
report.errors = errors;
|
||||||
|
} finally {
|
||||||
|
await browser.close();
|
||||||
|
}
|
||||||
|
console.log(JSON.stringify(report, null, 1));
|
||||||
32
vendor/librw/.appveyor.yml
vendored
Normal file
32
vendor/librw/.appveyor.yml
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
image: Visual Studio 2017
|
||||||
|
configuration: Release
|
||||||
|
environment:
|
||||||
|
GLFW_BASE: glfw-3.3.4.bin.WIN64
|
||||||
|
GLFW_URL: https://github.com/glfw/glfw/releases/download/3.3.4/%GLFW_BASE%.zip
|
||||||
|
SDL2_BASE: SDL2-devel-2.0.14-VC
|
||||||
|
SDL2_URL: https://www.libsdl.org/release/%SDL2_BASE%.zip
|
||||||
|
SDL2_DIRAME: SDL2-2.0.14
|
||||||
|
PREMAKE5_URL: https://github.com/premake/premake-core/releases/download/v5.0.0-alpha16/premake-5.0.0-alpha16-windows.zip
|
||||||
|
matrix:
|
||||||
|
- PLATFORM: win-amd64-null
|
||||||
|
- PLATFORM: win-amd64-gl3
|
||||||
|
PREMAKE5_EXTRA_ARGS: --gfxlib=glfw
|
||||||
|
- PLATFORM: win-amd64-gl3
|
||||||
|
PREMAKE5_EXTRA_ARGS: --gfxlib=sdl2
|
||||||
|
- PLATFORM: win-amd64-d3d9
|
||||||
|
|
||||||
|
install:
|
||||||
|
- appveyor DownloadFile %GLFW_URL% -FileName "%APPVEYOR_BUILD_FOLDER%/%GLFW_BASE%.zip"
|
||||||
|
- 7z x "%APPVEYOR_BUILD_FOLDER%/%GLFW_BASE%.zip"
|
||||||
|
- appveyor DownloadFile %SDL2_URL% -FileName "%APPVEYOR_BUILD_FOLDER%/%SDL2_BASE%.zip"
|
||||||
|
- 7z x "%APPVEYOR_BUILD_FOLDER%/%SDL2_BASE%.zip"
|
||||||
|
- appveyor DownloadFile %PREMAKE5_URL% -FileName "%APPVEYOR_BUILD_FOLDER%/premake5.zip"
|
||||||
|
- mkdir "%APPVEYOR_BUILD_FOLDER%/bin" && cd "%APPVEYOR_BUILD_FOLDER%/bin" && 7z x "%APPVEYOR_BUILD_FOLDER%/premake5.zip"
|
||||||
|
- set PATH=%APPVEYOR_BUILD_FOLDER%/bin;%PATH%
|
||||||
|
before_build:
|
||||||
|
- mkdir "%APPVEYOR_BUILD_FOLDER%/build"
|
||||||
|
- cd "%APPVEYOR_BUILD_FOLDER%"
|
||||||
|
- premake5 vs2017 --glfwdir64=%APPVEYOR_BUILD_FOLDER%/%GLFW_BASE% --sdl2dir=%APPVEYOR_BUILD_FOLDER%/%SDL2_DIRAME% %PREMAKE5_EXTRA_ARGS%
|
||||||
|
build:
|
||||||
|
project: c:\projects\librw\build\librw.sln
|
||||||
|
verbosity: minimal
|
||||||
60
vendor/librw/.github/workflows/build-cmake-conan.yml
vendored
Normal file
60
vendor/librw/.github/workflows/build-cmake-conan.yml
vendored
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
name: Conan
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
release:
|
||||||
|
types: published
|
||||||
|
jobs:
|
||||||
|
build-cmake:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [windows-latest, ubuntu-latest, macos-latest]
|
||||||
|
platform: ['null', 'gl3', 'd3d9']
|
||||||
|
gl3_gfxlib: ['glfw', 'sdl2']
|
||||||
|
exclude:
|
||||||
|
- os: ubuntu-latest
|
||||||
|
platform: d3d9
|
||||||
|
- os: macos-latest
|
||||||
|
platform: d3d9
|
||||||
|
- platform: 'null'
|
||||||
|
gl3_gfxlib: sdl2
|
||||||
|
- platform: d3d9
|
||||||
|
gl3_gfxlib: sdl2
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
- name: "Setup conan"
|
||||||
|
run: |
|
||||||
|
python -m pip install conan
|
||||||
|
conan config init
|
||||||
|
conan config set log.print_run_commands=True
|
||||||
|
conan config set general.revisions_enabled=1
|
||||||
|
conan remote add bincrafters https://bincrafters.jfrog.io/artifactory/api/conan/public-conan
|
||||||
|
- name: "Create host profile"
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
cp ~/.conan/profiles/default host_profile
|
||||||
|
- name: "Download/build dependencies (conan install)"
|
||||||
|
run: |
|
||||||
|
conan install ${{ github.workspace }} librw/master@ -if build -o librw:platform=${{ matrix.platform }} -o librw:gl3_gfxlib=${{ matrix.gl3_gfxlib }} --build missing -pr:h ./host_profile -pr:b default
|
||||||
|
env:
|
||||||
|
CONAN_SYSREQUIRES_MODE: enabled
|
||||||
|
- name: "Build librw (conan build)"
|
||||||
|
run: |
|
||||||
|
conan build ${{ github.workspace }} -if build -bf build -pf package
|
||||||
|
- name: "Package librw (conan package)"
|
||||||
|
run: |
|
||||||
|
conan package ${{ github.workspace }} -if build -bf build -pf package
|
||||||
|
- name: "Create binary package (cpack)"
|
||||||
|
working-directory: ./build
|
||||||
|
run: |
|
||||||
|
cpack
|
||||||
|
- name: "Archive binary package (github artifacts)"
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: "${{ matrix.os }}-${{ matrix.platform }}"
|
||||||
|
path: build/*.tar.xz
|
||||||
|
if-no-files-found: error
|
||||||
29
vendor/librw/.github/workflows/build-ps2.yml
vendored
Normal file
29
vendor/librw/.github/workflows/build-ps2.yml
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
name: Playstation 2 (by ps2dev)
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
release:
|
||||||
|
types: published
|
||||||
|
jobs:
|
||||||
|
build-playstation-2:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: ps2dev/ps2dev
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: "Install dependencies"
|
||||||
|
run: |
|
||||||
|
apk add build-base cmake
|
||||||
|
- name: "Build files"
|
||||||
|
run: |
|
||||||
|
cmake -S. -Bbuild -DLIBRW_INSTALL=ON -DLIBRW_PLATFORM=PS2 -DCMAKE_TOOLCHAIN_FILE=cmake/ps2/cmaketoolchain/toolchain_ps2_ee.cmake
|
||||||
|
cmake --build build --parallel
|
||||||
|
- name: "Create binary package (cpack)"
|
||||||
|
working-directory: ./build
|
||||||
|
run: |
|
||||||
|
cpack
|
||||||
|
- name: "Archive binary package (github artifacts)"
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: "ps2"
|
||||||
|
path: build/*.tar.xz
|
||||||
|
if-no-files-found: error
|
||||||
26
vendor/librw/.github/workflows/build-switch.yml
vendored
Normal file
26
vendor/librw/.github/workflows/build-switch.yml
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
name: Nintendo Switch (by devkitPro)
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
release:
|
||||||
|
types: published
|
||||||
|
jobs:
|
||||||
|
build-nintendo-switch:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: devkitpro/devkita64:latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: "Build files"
|
||||||
|
run: |
|
||||||
|
/opt/devkitpro/portlibs/switch/bin/aarch64-none-elf-cmake -S. -Bbuild -DLIBRW_PLATFORM=GL3 -DLIBRW_GL3_GFXLIB=GLFW -DLIBRW_INSTALL=True
|
||||||
|
cmake --build build --parallel
|
||||||
|
- name: "Create binary package (cpack)"
|
||||||
|
working-directory: ./build
|
||||||
|
run: |
|
||||||
|
cpack
|
||||||
|
- name: "Archive binary package (github artifacts)"
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: "switch-gl3"
|
||||||
|
path: build/*.tar.xz
|
||||||
|
if-no-files-found: error
|
||||||
10
vendor/librw/.gitignore
vendored
Normal file
10
vendor/librw/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
/bin
|
||||||
|
/build
|
||||||
|
/obj
|
||||||
|
/lib
|
||||||
|
/output
|
||||||
|
/.vs
|
||||||
|
librw.vcxproj.user
|
||||||
|
librw.VC.db
|
||||||
|
librw.VC.VC.opendb
|
||||||
|
imgui.ini
|
||||||
46
vendor/librw/.travis.yml
vendored
Normal file
46
vendor/librw/.travis.yml
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
language: cpp
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- os: linux
|
||||||
|
env: TARGET=release_linux-amd64-null
|
||||||
|
script:
|
||||||
|
- mkdir -p "$TRAVIS_BUILD_DIR/build"
|
||||||
|
#- docker build -t librw "$TRAVIS_BUILD_DIR"
|
||||||
|
#- docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" --name librw_instance -d librw sleep infinity
|
||||||
|
- docker pull librw/librw
|
||||||
|
- docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" -v "$TRAVIS_BUILD_DIR/build:/build:rw,z" --name librw_instance -d librw/librw sleep infinity
|
||||||
|
- docker exec -u builder librw_instance /bin/bash -c "cd /librw && premake5 gmake && cd /librw/build && make config=$TARGET verbose=1"
|
||||||
|
- os: linux
|
||||||
|
env: TARGET=release_linux-amd64-gl3 GFXLIB=glfw
|
||||||
|
services: docker
|
||||||
|
script:
|
||||||
|
- mkdir -p "$TRAVIS_BUILD_DIR/build"
|
||||||
|
#- docker build -t librw "$TRAVIS_BUILD_DIR"
|
||||||
|
#- docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" --name librw_instance -d librw sleep infinity
|
||||||
|
- docker pull librw/librw
|
||||||
|
- docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" -v "$TRAVIS_BUILD_DIR/build:/build:rw,z" --name librw_instance -d librw/librw sleep infinity
|
||||||
|
- docker exec -u builder librw_instance /bin/bash -c "cd /librw && premake5 --gfxlib=$GFXLIB gmake && cd /librw/build && make config=$TARGET verbose=1"
|
||||||
|
- os: linux
|
||||||
|
env: TARGET=release_linux-amd64-gl3 GFXLIB=sdl2
|
||||||
|
services: docker
|
||||||
|
script:
|
||||||
|
- mkdir -p "$TRAVIS_BUILD_DIR/build"
|
||||||
|
#- docker build -t librw "$TRAVIS_BUILD_DIR"
|
||||||
|
#- docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" --name librw_instance -d librw sleep infinity
|
||||||
|
- docker pull librw/librw
|
||||||
|
- docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" -v "$TRAVIS_BUILD_DIR/build:/build:rw,z" --name librw_instance -d librw/librw sleep infinity
|
||||||
|
- docker exec -u builder librw_instance /bin/bash -c "cd /librw && premake5 --gfxlib=$GFXLIB gmake && cd /librw/build && make config=$TARGET verbose=1"
|
||||||
|
- name: "ps2"
|
||||||
|
os: linux
|
||||||
|
env: TARGET=release_ps2
|
||||||
|
services: docker
|
||||||
|
script:
|
||||||
|
- mkdir -p "$TRAVIS_BUILD_DIR/build"
|
||||||
|
#- docker build -t librw "$TRAVIS_BUILD_DIR"
|
||||||
|
#- docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" --name librw_instance -d librw sleep infinity
|
||||||
|
- docker pull librw/librw
|
||||||
|
- docker run -v "$TRAVIS_BUILD_DIR:/librw:rw,z" -v "$TRAVIS_BUILD_DIR/build:/build:rw,z" --name librw_instance -d librw/librw sleep infinity
|
||||||
|
- docker exec -u builder librw_instance /bin/bash -c "cd /librw && premake5 gmake && cd /librw/build && make config=$TARGET verbose=1"
|
||||||
|
allow_failures:
|
||||||
|
- name: "ps2"
|
||||||
174
vendor/librw/ARCHITECTURE.MD
vendored
Normal file
174
vendor/librw/ARCHITECTURE.MD
vendored
Normal file
|
|
@ -0,0 +1,174 @@
|
||||||
|
This document gives an overview of the architecture of librw.
|
||||||
|
|
||||||
|
Disclaimer: Some of these design decision were taken over from original RW,
|
||||||
|
some are my own. I only take partial responsibility.
|
||||||
|
|
||||||
|
Differently from original RW, librw has no neat separation into modules.
|
||||||
|
Some things could be made optional, but in particular RW's RpWorld
|
||||||
|
plugin is integrated with everything else.
|
||||||
|
|
||||||
|
# Plugins
|
||||||
|
|
||||||
|
To extend structs with custom data,
|
||||||
|
RW (and librw) provides a plugin mechanism
|
||||||
|
for certain structs.
|
||||||
|
This can be used to tack more data onto a struct
|
||||||
|
and register custom streaming functions.
|
||||||
|
Plugins must be registered before any instance
|
||||||
|
of that struct is allocated.
|
||||||
|
|
||||||
|
# Pipelines
|
||||||
|
|
||||||
|
RW's pipeline architecture was designed for very flexible data flow.
|
||||||
|
Unfortunately for RW most of the rendering pipeline moved into the GPU
|
||||||
|
causing RW's pipeline architecture to be severely overengineered.
|
||||||
|
|
||||||
|
librw's pipeline architecture is therefore much simplified
|
||||||
|
and only implements what is actually needed,
|
||||||
|
but the name *pipeline* is retained.
|
||||||
|
|
||||||
|
Three pipelines are implemented in librw itself:
|
||||||
|
Default, Skin, MatFX (only env map so far).
|
||||||
|
Others can be implemented by applications using librw.
|
||||||
|
|
||||||
|
# RW Objects
|
||||||
|
|
||||||
|
## Frame
|
||||||
|
|
||||||
|
A Frame is an orientation in space, arranged in a hierarchy.
|
||||||
|
Camera, Lights and Atomics can be attached to it.
|
||||||
|
It has two matrices: a (so called) model matrix,
|
||||||
|
which is relative to its parent,
|
||||||
|
and a local transformation matrix (LTM) which is relative to the world.
|
||||||
|
The LTM is updated automatically as needed whenever the hierarchy gets dirty.
|
||||||
|
|
||||||
|
## Camera
|
||||||
|
|
||||||
|
A Camera is attached to a Frame to position it in space
|
||||||
|
and has a framebuffer and a z-buffer attached to render to.
|
||||||
|
Rendering is started by `beginUpdate` and ended by `endUpdate`.
|
||||||
|
This sets up things like framebuffers and matrices
|
||||||
|
so that the Camera's raster can be rendered to.
|
||||||
|
|
||||||
|
## Light
|
||||||
|
|
||||||
|
Lights are attached to a Frame to position it in space.
|
||||||
|
They are used to light Atomics for rendering.
|
||||||
|
Different types of light are possible.
|
||||||
|
|
||||||
|
## Geometry
|
||||||
|
|
||||||
|
A Geometry contains the raw geometry data that can be rendered.
|
||||||
|
It has a list of materials that are applied to its triangles.
|
||||||
|
The latter are sorted by materials into meshes for easier instancing.
|
||||||
|
|
||||||
|
## Atomic
|
||||||
|
|
||||||
|
An Atomic is attached to a Frame to position it in space
|
||||||
|
and references a Geometry.
|
||||||
|
Atomics are the objects that are rendered by pipelines.
|
||||||
|
|
||||||
|
## Clump
|
||||||
|
|
||||||
|
A Clump is a container of Atomics, Lights and Cameras.
|
||||||
|
Clumps can be read from and written to DFF files.
|
||||||
|
Rendering a Clump will be render all of its Atomics.
|
||||||
|
|
||||||
|
# Engine
|
||||||
|
|
||||||
|
Due to the versatility of librw,
|
||||||
|
there are three levels of code:
|
||||||
|
Platform indpendent code,
|
||||||
|
platform specific code,
|
||||||
|
and render device specific code.
|
||||||
|
|
||||||
|
The second category does not exist in original RW,
|
||||||
|
but because librw is supposed to be able to
|
||||||
|
convert between all sorts of platform specific files,
|
||||||
|
the code for that has to be available no matter
|
||||||
|
the render platform used.
|
||||||
|
The common interface for all device-independent
|
||||||
|
platform code is the `Driver` struct.
|
||||||
|
The `Engine` struct has an array with one for each platform.
|
||||||
|
|
||||||
|
The render device specific code
|
||||||
|
is used for actually rendering something to the screen.
|
||||||
|
The common interface for the device-dependent
|
||||||
|
code is the `Device` struct and the `Engine`
|
||||||
|
struct only has a single one, as there can only be one render device
|
||||||
|
(i.e. you cannot select D3D or OpenGL at runtime).
|
||||||
|
|
||||||
|
Thus when implementing a new backend
|
||||||
|
you have to implement the `Driver` and `Device` interfaces.
|
||||||
|
But do note that the `Driver` can be extended with plugins!
|
||||||
|
|
||||||
|
# Driver
|
||||||
|
|
||||||
|
The driver is mostly concerned with conversion
|
||||||
|
between platform independent data to platform dependent one, and vice versa.
|
||||||
|
This concerns the following two cases.
|
||||||
|
|
||||||
|
## Raster, Images
|
||||||
|
|
||||||
|
Images contain platform independent uncompressed pixel data.
|
||||||
|
Rasters contain platform dependent (and possibly compressed) pixel data.
|
||||||
|
A driver has to be able to convert an image to a raster for the purposes of loading textures
|
||||||
|
from files or having them converted from foreign rasters.
|
||||||
|
Converting from rasters to images is not absolutely necessary but it's needed e.g. for taking screenshots.
|
||||||
|
librw has a set of default raster formats that the platform is
|
||||||
|
expected to implement for the most part, however not all have to be supported necessarily.
|
||||||
|
A driver is also free to implement its own formats;
|
||||||
|
this is done for texture compression.
|
||||||
|
|
||||||
|
Rasters have different types,
|
||||||
|
`TEXTURE` and `CAMERATEXTURE` rasters can be used as textures,
|
||||||
|
`CAMERA` and `CAMERATEXTURE` can be used as render targets,
|
||||||
|
`ZBUFFER` is used as a depth-buffer.
|
||||||
|
|
||||||
|
## Pipelines
|
||||||
|
|
||||||
|
A librw ObjPipeline implements essentially
|
||||||
|
an instance stage which converts platform independent geometry
|
||||||
|
to a format that can efficiently be rendered,
|
||||||
|
and a render stage that actually renders it.
|
||||||
|
(There is also an uninstance function,
|
||||||
|
but this is only used to convert platform specific geometry back to the generic format
|
||||||
|
and hence is not necessary.)
|
||||||
|
|
||||||
|
# Device
|
||||||
|
|
||||||
|
The device implements everything that is actually needed for rendering.
|
||||||
|
|
||||||
|
This includes starting, handling and closing the rendering device,
|
||||||
|
setting render states,
|
||||||
|
allocating and destroying buffers and textures,
|
||||||
|
im2d and im3d rendering,
|
||||||
|
and the render functions of the pipelines.
|
||||||
|
|
||||||
|
## System
|
||||||
|
|
||||||
|
The `system` function implements certain device requests
|
||||||
|
from the engine (why these aren't separate functions I don't know, RW design).
|
||||||
|
|
||||||
|
The `Engine` is started in different stages, at various points of which
|
||||||
|
the render device gets different requests.
|
||||||
|
At the end the device is initialized and ready for rendering.
|
||||||
|
A similar but reverse sequence happens on shutdown.
|
||||||
|
|
||||||
|
Subsystems (screens) and video modes are queried through
|
||||||
|
the `system` by the application before the device is started.
|
||||||
|
|
||||||
|
## Immediate mode
|
||||||
|
|
||||||
|
Im2d and im3d are immediate-mode style rendering interface.
|
||||||
|
|
||||||
|
## Pipelines
|
||||||
|
|
||||||
|
For instancing the typical job is to allocate and fill
|
||||||
|
a struct to hold some data about an atomic,
|
||||||
|
an array of structs for all the meshes,
|
||||||
|
and vertex and index buffers to hold geometry for rendering.
|
||||||
|
|
||||||
|
The render function will render the previously instanced
|
||||||
|
data by doing a per-object setup and then iterating over
|
||||||
|
and rendering all the meshes.
|
||||||
160
vendor/librw/CMakeLists.txt
vendored
Normal file
160
vendor/librw/CMakeLists.txt
vendored
Normal file
|
|
@ -0,0 +1,160 @@
|
||||||
|
set(librw_MAINPROJECT ON)
|
||||||
|
if(DEFINED PROJECT_NAME)
|
||||||
|
set(librw_MAINPROJECT OFF)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.8)
|
||||||
|
project(librw
|
||||||
|
VERSION 0.0.1
|
||||||
|
LANGUAGES C CXX
|
||||||
|
)
|
||||||
|
set(librw_AUTHOR aap)
|
||||||
|
|
||||||
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
set(LIBRW_PLATFORMS "NULL" "GL3" "D3D9")
|
||||||
|
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL ON)
|
||||||
|
elseif(NINTENDO_SWITCH)
|
||||||
|
set(LIBRW_PLATFORMS "NULL" "GL3")
|
||||||
|
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL OFF)
|
||||||
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/nx")
|
||||||
|
include(NXFunctions)
|
||||||
|
elseif(PS2)
|
||||||
|
set(LIBRW_PLATFORMS "PS2")
|
||||||
|
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL OFF)
|
||||||
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/ps2")
|
||||||
|
include(PS2Functions)
|
||||||
|
else()
|
||||||
|
set(LIBRW_PLATFORMS "NULL" "GL3")
|
||||||
|
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL ON)
|
||||||
|
endif()
|
||||||
|
list(GET LIBRW_PLATFORMS 0 LIBRW_PLATFORM_DEFAULT)
|
||||||
|
set(LIBRW_PLATFORM "${LIBRW_PLATFORM_DEFAULT}" CACHE STRING "Platform")
|
||||||
|
set_property(CACHE LIBRW_PLATFORM PROPERTY STRINGS ${LIBRW_PLATFORMS})
|
||||||
|
message(STATUS "LIBRW_PLATFORM = ${LIBRW_PLATFORM} (choices=${LIBRW_PLATFORMS})")
|
||||||
|
set("LIBRW_PLATFORM_${LIBRW_PLATFORM}" ON)
|
||||||
|
if(NOT LIBRW_PLATFORM IN_LIST LIBRW_PLATFORMS)
|
||||||
|
message(FATAL_ERROR "Illegal LIBRW_PLATFORM=${LIBRW_PLATFORM}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(LIBRW_GL3_GFXLIBS "GLFW" "SDL2")
|
||||||
|
set(LIBRW_GL3_GFXLIB "GLFW" CACHE STRING "gfxlib for gl3")
|
||||||
|
set_property(CACHE LIBRW_GL3_GFXLIB PROPERTY STRINGS ${LIBRW_GL3_GFXLIBS})
|
||||||
|
if(LIBRW_PLATFORM_GL3)
|
||||||
|
message(STATUS "LIBRW_GL3_GFXLIB = ${LIBRW_GL3_GFXLIB} (choices=${LIBRW_GL3_GFXLIBS})")
|
||||||
|
endif()
|
||||||
|
if(NOT LIBRW_GL3_GFXLIB IN_LIST LIBRW_GL3_GFXLIBS)
|
||||||
|
message(FATAL_ERROR "Illegal LIBRW_GL3_GFXLIB=${LIBRW_GL3_GFXLIB}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(LIBRW_PLATFORM_PS2)
|
||||||
|
enable_language(DSM)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT COMMAND librw_platform_target)
|
||||||
|
function(librw_platform_target)
|
||||||
|
endfunction()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(CMakeDependentOption)
|
||||||
|
|
||||||
|
option(LIBRW_TOOLS "Build librw tools" ${librw_MAINPROJECT})
|
||||||
|
option(LIBRW_INSTALL "Install librw files" ${librw_MAINPROJECT})
|
||||||
|
cmake_dependent_option(LIBRW_EXAMPLES "Build librw examples" ON "LIBRW_TOOLS;NOT LIBRW_PLATFORM_NULL" OFF)
|
||||||
|
|
||||||
|
if(LIBRW_INSTALL)
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
set(LIBRW_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/librw")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_subdirectory(src)
|
||||||
|
|
||||||
|
if(LIBRW_TOOLS AND NOT LIBRW_PLATFORM_PS2 AND NOT LIBRW_PLATFORM_NULL)
|
||||||
|
add_subdirectory(skeleton)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_subdirectory(tools)
|
||||||
|
|
||||||
|
if(LIBRW_INSTALL)
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
configure_package_config_file(cmake/librw-config.cmake.in librw-config.cmake
|
||||||
|
INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}"
|
||||||
|
)
|
||||||
|
install(
|
||||||
|
FILES "${CMAKE_CURRENT_BINARY_DIR}/librw-config.cmake"
|
||||||
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
|
||||||
|
)
|
||||||
|
install(
|
||||||
|
EXPORT librw-targets NAMESPACE librw::
|
||||||
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if(LIBRW_GL3_GFXLIB STREQUAL "SDL2")
|
||||||
|
install(
|
||||||
|
FILES "${CMAKE_CURRENT_LIST_DIR}/cmake/FindSDL2.cmake"
|
||||||
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
string(REPLACE "." ";" cmake_c_compiler_version_list "${CMAKE_C_COMPILER_VERSION}")
|
||||||
|
list(GET cmake_c_compiler_version_list 0 cmake_c_compiler_version_major)
|
||||||
|
|
||||||
|
string(TOLOWER "${LIBRW_PLATFORM}" librw_platform)
|
||||||
|
set(compiler)
|
||||||
|
set(os)
|
||||||
|
if(NOT LIBRW_PLATFORM STREQUAL "PS2")
|
||||||
|
if(MSVC)
|
||||||
|
set(compiler "-msvc${MSVC_VERSION}")
|
||||||
|
elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||||
|
set(compiler "-gcc${cmake_c_compiler_version_major}")
|
||||||
|
elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||||
|
set(compiler "-clang${cmake_c_compiler_version_major}")
|
||||||
|
elseif(CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
|
||||||
|
set(compiler "-appleclang${cmake_c_compiler_version_major}")
|
||||||
|
else()
|
||||||
|
set(compiler "-UNK")
|
||||||
|
message(WARNING "Unknown compiler. Created cpack package will be wrong. (override using cpack -P)")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
if(LIBRW_PLATFORM_NULL)
|
||||||
|
set(platform "-null")
|
||||||
|
elseif(LIBRW_PLATFORM_PS2)
|
||||||
|
set(platform "-ps2")
|
||||||
|
elseif(LIBRW_PLATFORM_GL3)
|
||||||
|
if(LIBRW_GL3_GFXLIB STREQUAL "GLFW")
|
||||||
|
set(platform "-gl3-glfw")
|
||||||
|
else()
|
||||||
|
set(platform "-gl3-sdl2")
|
||||||
|
endif()
|
||||||
|
elseif(LIBRW_PLATFORM_D3D9)
|
||||||
|
set(platform "-d3d9")
|
||||||
|
endif()
|
||||||
|
if(NOT LIBRW_PLATFORM_PS2)
|
||||||
|
if(WIN32)
|
||||||
|
set(os "-win")
|
||||||
|
elseif(NINTENDO_SWITCH)
|
||||||
|
set(os "-switch")
|
||||||
|
elseif(PS2)
|
||||||
|
set(os "-ps2")
|
||||||
|
elseif(APPLE)
|
||||||
|
set(os "-apple")
|
||||||
|
elseif(UNIX)
|
||||||
|
set(os "-linux")
|
||||||
|
else()
|
||||||
|
set(compiler "-UNK")
|
||||||
|
message(WARNING "Unknown os. Created cpack package will be wrong. (override using cpack -P)")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}${platform}${os}${compiler}")
|
||||||
|
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A (partial) re-implementation of RenderWare Graphics")
|
||||||
|
set(CPACK_PACKAGE_VENDOR "aap")
|
||||||
|
set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/LICENSE")
|
||||||
|
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
|
||||||
|
set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}")
|
||||||
|
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}")
|
||||||
|
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}")
|
||||||
|
set(CPACK_GENERATOR "TXZ")
|
||||||
|
include(CPack)
|
||||||
|
endif()
|
||||||
60
vendor/librw/Dockerfile
vendored
Normal file
60
vendor/librw/Dockerfile
vendored
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
FROM ubuntu:rolling
|
||||||
|
|
||||||
|
ENV PS2DEV /ps2dev
|
||||||
|
ENV PS2SDK $PS2DEV/ps2sdk
|
||||||
|
ENV PATH $PATH:$PS2DEV/bin:$PS2DEV/ee/bin:$PS2DEV/iop/bin:$PS2DEV/dvp/bin:$PS2SDK/bin
|
||||||
|
|
||||||
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
|
||||||
|
ENV TOOLCHAIN_GIT_URL git://github.com/ps2dev/ps2toolchain.git
|
||||||
|
ENV TOOLCHAIN_GIT_BRANCH master
|
||||||
|
|
||||||
|
ENV PREMAKE5_URL=https://github.com/premake/premake-core/releases/download/v5.0.0-alpha12/premake-5.0.0-alpha12-linux.tar.gz
|
||||||
|
|
||||||
|
RUN mkdir -p "$PS2DEV" "$PS2SDK" \
|
||||||
|
&& apt-get update \
|
||||||
|
&& apt-get upgrade -y \
|
||||||
|
&& apt-get install -y \
|
||||||
|
build-essential \
|
||||||
|
cmake \
|
||||||
|
autoconf \
|
||||||
|
bzip2 \
|
||||||
|
gcc \
|
||||||
|
git \
|
||||||
|
libucl-dev \
|
||||||
|
make \
|
||||||
|
patch \
|
||||||
|
vim \
|
||||||
|
wget \
|
||||||
|
zip \
|
||||||
|
zlib1g-dev \
|
||||||
|
libglfw3-dev \
|
||||||
|
libsdl2-dev \
|
||||||
|
&& git clone -b $TOOLCHAIN_GIT_BRANCH $TOOLCHAIN_GIT_URL /toolchain \
|
||||||
|
&& cd /toolchain \
|
||||||
|
&& ./toolchain.sh \
|
||||||
|
&& git clone git://github.com/ps2dev/ps2eth.git /ps2dev/ps2eth \
|
||||||
|
&& make -C /ps2dev/ps2eth \
|
||||||
|
&& git clone git://github.com/ps2dev/ps2-packer.git /ps2-packer \
|
||||||
|
&& make install -C /ps2-packer \
|
||||||
|
&& rm -rf \
|
||||||
|
/ps2-packer \
|
||||||
|
/ps2dev/ps2eth/.git \
|
||||||
|
/ps2dev/ps2sdk/test.tmp \
|
||||||
|
/ps2dev/test.tmp \
|
||||||
|
/toolchain \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
|
&& wget "$PREMAKE5_URL" -O /tmp/premake5.tar.gz \
|
||||||
|
&& tar xf /tmp/premake5.tar.gz -C /usr/bin/ \
|
||||||
|
&& rm /tmp/premake5.tar.gz \
|
||||||
|
&& groupadd 1000 -g 1000 \
|
||||||
|
&& groupadd 1001 -g 1001 \
|
||||||
|
&& groupadd 2000 -g 2000 \
|
||||||
|
&& groupadd 999 -g 999 \
|
||||||
|
&& useradd -ms /bin/bash builder -g 1001 -G 1000,2000,999 \
|
||||||
|
&& printf "builder:builder" | chpasswd \
|
||||||
|
&& adduser builder sudo \
|
||||||
|
&& printf "builder ALL= NOPASSWD: ALL\\n" >> /etc/sudoers
|
||||||
|
|
||||||
|
USER builder
|
||||||
|
WORKDIR /home/builder
|
||||||
22
vendor/librw/LICENSE
vendored
Normal file
22
vendor/librw/LICENSE
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 aap
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
9
vendor/librw/README.cmake
vendored
Normal file
9
vendor/librw/README.cmake
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
Build with cmake
|
||||||
|
================
|
||||||
|
|
||||||
|
Linux
|
||||||
|
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake .. -DLIBRW_PLATFORM=GL3 -DLIBRW_GL3_GFXLIB=SDL2
|
||||||
|
make
|
||||||
26
vendor/librw/README.md
vendored
Normal file
26
vendor/librw/README.md
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
librw
|
||||||
|
=====
|
||||||
|
|
||||||
|
This library is supposed to be a re-implementation of RenderWare graphics,
|
||||||
|
or a good part of it anyway.
|
||||||
|
|
||||||
|
It is intended to be cross-platform in two senses:
|
||||||
|
support rendering on different platforms similar to RW;
|
||||||
|
supporting all file formats for all platforms at all times and provide
|
||||||
|
way to convert to all other platforms.
|
||||||
|
|
||||||
|
Supported file formats are DFF and TXD for PS2, D3D8, D3D9 and Xbox.
|
||||||
|
Not all pre-instanced PS2 DFFs are supported.
|
||||||
|
BSP is not supported at all.
|
||||||
|
|
||||||
|
For rendering we have D3D9 and OpenGL (>=2.1, ES >= 2.0) backends.
|
||||||
|
Rendering some things on the PS2 is working as a test only.
|
||||||
|
|
||||||
|
# Uses
|
||||||
|
|
||||||
|
librw can be used for rendering [GTA](https://github.com/gtamodding/re3).
|
||||||
|
|
||||||
|
# Building
|
||||||
|
|
||||||
|
Get premake5. Generate a config, e.g. with ``premake5 gmake``,
|
||||||
|
and look in the build directory.
|
||||||
24
vendor/librw/TODO
vendored
Normal file
24
vendor/librw/TODO
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
TODO:
|
||||||
|
- tristrips
|
||||||
|
- examples
|
||||||
|
skeleton + interface
|
||||||
|
camtex
|
||||||
|
matfx1 (more new shaders)
|
||||||
|
hanim1
|
||||||
|
fog
|
||||||
|
imlight?
|
||||||
|
patch?
|
||||||
|
- morphing
|
||||||
|
- Pipelines (PDS, Xbox, PC)
|
||||||
|
- bsp
|
||||||
|
|
||||||
|
driver
|
||||||
|
- metrics
|
||||||
|
|
||||||
|
ps2
|
||||||
|
- rendering!
|
||||||
|
- ADC conversion
|
||||||
|
|
||||||
|
|
||||||
|
BUGS:
|
||||||
|
- fseek with negative offset on ps2 over ps2link messes up the current position
|
||||||
24
vendor/librw/args.h
vendored
Normal file
24
vendor/librw/args.h
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
extern char *argv0;
|
||||||
|
#define USED(x) ((void)x)
|
||||||
|
#define SET(x) ((x)=0)
|
||||||
|
|
||||||
|
#define ARGBEGIN for((argv0||(argv0=*argv)),argv++,argc--;\
|
||||||
|
argv[0] && argv[0][0]=='-' && argv[0][1];\
|
||||||
|
argc--, argv++) {\
|
||||||
|
char *_args, *_argt;\
|
||||||
|
char _argc;\
|
||||||
|
_args = &argv[0][1];\
|
||||||
|
if(_args[0]=='-' && _args[1]==0){\
|
||||||
|
argc--; argv++; break;\
|
||||||
|
}\
|
||||||
|
_argc = 0;\
|
||||||
|
while(*_args && (_argc = *_args++))\
|
||||||
|
switch(_argc)
|
||||||
|
#define ARGEND SET(_argt);USED(_argt);USED(_argc);USED(_args);}USED(argv);USED(argc);
|
||||||
|
#define ARGF() (_argt=_args, _args=(char*)"",\
|
||||||
|
(*_argt? _argt: argv[1]? (argc--, *++argv): 0))
|
||||||
|
#define EARGF(x) (_argt=_args, _args=(char*)"",\
|
||||||
|
(*_argt? _argt: argv[1]? (argc--, *++argv): ((x), abort(), (char*)0)))
|
||||||
|
|
||||||
|
#define ARGC() _argc
|
||||||
|
|
||||||
38
vendor/librw/cmake/FindSDL2.cmake
vendored
Normal file
38
vendor/librw/cmake/FindSDL2.cmake
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
find_package(PkgConfig QUIET)
|
||||||
|
if(PKG_CONFIG_FOUND)
|
||||||
|
pkg_check_modules(SDL2 IMPORTED_TARGET "sdl2")
|
||||||
|
if(TARGET PkgConfig::SDL2 AND NOT TARGET SDL2::SDL2)
|
||||||
|
add_library(SDL2::SDL2 INTERFACE IMPORTED)
|
||||||
|
set_property(TARGET SDL2::SDL2 PROPERTY INTERFACE_LINK_LIBRARIES PkgConfig::SDL2)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_library(SDL2main_LIBRARY SDL2main)
|
||||||
|
|
||||||
|
if(NOT SDL2_FOUND)
|
||||||
|
find_path(SDL2_INCLUDE_DIR sdl2.h)
|
||||||
|
find_library(SDL2_LIBRARY SDL2 SDL2d)
|
||||||
|
|
||||||
|
find_library(SDL2main_LIBRARY SDL2main)
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
find_package_handle_standard_args(libuv
|
||||||
|
REQUIRED_VARS SDL2_INCLUDE_DIR SDL2_LIBRARY
|
||||||
|
)
|
||||||
|
|
||||||
|
if(NOT TARGET SDL2::SDL2)
|
||||||
|
add_library(SDL2::SDL2 UNKNOWN IMPORTED)
|
||||||
|
set_target_properties(SDL2::SDL2 PROPERTIES
|
||||||
|
IMPORTED_LOCATION "${SDL2_LIBRARY}"
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(SDL2main_LIBRARY AND NOT TARGET SDL2::SDL2main)
|
||||||
|
add_library(SDL2::SDL2main UNKNOWN IMPORTED)
|
||||||
|
set_target_properties(SDL2::SDL2main PROPERTIES
|
||||||
|
IMPORTED_LOCATION "${SDL2main_LIBRARY}"
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
22
vendor/librw/cmake/librw-config.cmake.in
vendored
Normal file
22
vendor/librw/cmake/librw-config.cmake.in
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/librw-targets.cmake")
|
||||||
|
|
||||||
|
set(LIBRW_PLATFORM "@LIBRW_PLATFORM@")
|
||||||
|
set(LIBRW_PLATFORMS "@LIBRW_PLATFORMS@")
|
||||||
|
set(LIBRW_PLATFORM_@LIBRW_PLATFORM@ ON)
|
||||||
|
|
||||||
|
if(LIBRW_PLATFORM_GL3)
|
||||||
|
set(LIBRW_GL3_GFXLIB "@LIBRW_GL3_GFXLIB@")
|
||||||
|
set(LIBRW_GL3_GFXLIBS "@LIBRW_GL3_GFXLIBS@")
|
||||||
|
|
||||||
|
set(OpenGL_GL_PREFERENCE GLVND)
|
||||||
|
find_package(OpenGL)
|
||||||
|
if(NOT TARGET OpenGL::OpenGL AND NOT TARGET OpenGL::EGL AND NOT TARGET OpenGL::GL)
|
||||||
|
message(FATAL_ERROR "find_package(OpenGL) failed: no target was created")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(LIBRW_GL3_GFXLIB STREQUAL "GLFW")
|
||||||
|
find_package(glfw3 REQUIRED)
|
||||||
|
elseif(LIBRW_GL3_GFXLIB STREQUAL "SDL2")
|
||||||
|
find_package(SDL2 REQUIRED)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
37
vendor/librw/cmake/nx/NXFunctions.cmake
vendored
Normal file
37
vendor/librw/cmake/nx/NXFunctions.cmake
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
if(NOT COMMAND nx_generate_nacp)
|
||||||
|
message(FATAL_ERROR "The `nx_generate_nacp` cmake command is not available. Please use an appropriate Nintendo Switch toolchain.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT COMMAND nx_create_nro)
|
||||||
|
message(FATAL_ERROR "The `nx_create_nro` cmake command is not available. Please use an appropriate Nintendo Switch toolchain.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
|
||||||
|
|
||||||
|
function(librw_platform_target TARGET)
|
||||||
|
cmake_parse_arguments(LPT "INSTALL" "" "" ${ARGN})
|
||||||
|
|
||||||
|
get_target_property(TARGET_TYPE "${TARGET}" TYPE)
|
||||||
|
if(TARGET_TYPE STREQUAL "EXECUTABLE")
|
||||||
|
nx_generate_nacp(${TARGET}.nacp
|
||||||
|
NAME "${TARGET}"
|
||||||
|
AUTHOR "${librw_AUTHOR}"
|
||||||
|
VERSION "${librw_VERSION}"
|
||||||
|
)
|
||||||
|
|
||||||
|
nx_create_nro(${TARGET}
|
||||||
|
NACP ${TARGET}.nacp
|
||||||
|
)
|
||||||
|
|
||||||
|
if(LIBRW_INSTALL AND LPT_INSTALL)
|
||||||
|
get_target_property(TARGET_OUTPUT_NAME ${TARGET} OUTPUT_NAME)
|
||||||
|
if(NOT TARGET_OUTPUT_NAME)
|
||||||
|
set(TARGET_OUTPUT_NAME "${TARGET}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${TARGET_OUTPUT_NAME}.nro"
|
||||||
|
DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
18
vendor/librw/cmake/ps2/PS2Functions.cmake
vendored
Normal file
18
vendor/librw/cmake/ps2/PS2Functions.cmake
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
if(NOT COMMAND add_erl_executable)
|
||||||
|
message(FATAL_ERROR "The `add_erl_executable` cmake command is not available. Please use an appropriate Playstation 2 toolchain.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
function(librw_platform_target TARGET)
|
||||||
|
cmake_parse_arguments(LPT "INSTALL" "" "" ${ARGN})
|
||||||
|
|
||||||
|
get_target_property(TARGET_TYPE "${TARGET}" TYPE)
|
||||||
|
if(TARGET_TYPE STREQUAL "EXECUTABLE")
|
||||||
|
add_erl_executable(${TARGET} OUTPUT_VAR ERL_FILE)
|
||||||
|
|
||||||
|
if(LIBRW_INSTALL AND LPT_INSTALL)
|
||||||
|
install(FILES "${ERL_FILE}"
|
||||||
|
DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
16
vendor/librw/cmake/ps2/cmaketoolchain/CMakeDSMCompiler.cmake.in
vendored
Normal file
16
vendor/librw/cmake/ps2/cmaketoolchain/CMakeDSMCompiler.cmake.in
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
set(CMAKE_DSM_COMPILER "@_CMAKE_DSM_COMPILER@")
|
||||||
|
set(CMAKE_DSM_COMPILER_ARG1 "@_CMAKE_DSM_COMPILER_ARG1@")
|
||||||
|
set(CMAKE_DSM_COMPILER_AR "@_CMAKE_DSM_COMPILER_AR@")
|
||||||
|
set(CMAKE_RANLIB "@CMAKE_RANLIB@")
|
||||||
|
set(CMAKE_DSM_COMPILER_RANLIB "@_CMAKE_DSM_COMPILER_RANLIB@")
|
||||||
|
set(CMAKE_LINKER "@CMAKE_LINKER@")
|
||||||
|
set(CMAKE_DSM_COMPILER_LOADED 1)
|
||||||
|
set(CMAKE_DSM_COMPILER_ID "@_CMAKE_DSM_COMPILER_ID@")
|
||||||
|
set(CMAKE_DSM_COMPILER_VERSION "@_CMAKE_DSM_COMPILER_VERSION@")
|
||||||
|
set(CMAKE_DSM_COMPILER_ENV_VAR "@_CMAKE_DSM_COMPILER_ENV_VAR@")
|
||||||
|
@_SET_CMAKE_DSM_COMPILER_ARCHITECTURE_ID@
|
||||||
|
|
||||||
|
set(CMAKE_DSM_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC)
|
||||||
|
set(CMAKE_DSM_LINKER_PREFERENCE 0)
|
||||||
|
|
||||||
|
@CMAKE_DSM_COMPILER_CUSTOM_CODE@
|
||||||
79
vendor/librw/cmake/ps2/cmaketoolchain/CMakeDSMInformation.cmake
vendored
Normal file
79
vendor/librw/cmake/ps2/cmaketoolchain/CMakeDSMInformation.cmake
vendored
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
if(UNIX)
|
||||||
|
set(CMAKE_DSM_OUTPUT_EXTENSION .o)
|
||||||
|
else()
|
||||||
|
set(CMAKE_DSM_OUTPUT_EXTENSION .obj)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_INCLUDE_FLAG_DSM "-I")
|
||||||
|
|
||||||
|
set(CMAKE_DSM_FLAGS_INIT "$ENV{DSMFLAGS} ${CMAKE_DSM_FLAGS_INIT}")
|
||||||
|
|
||||||
|
# replace for CMake >= 3.11
|
||||||
|
foreach(c "" _DEBUG _RELEASE _MINSIZEREL _RELWITHDEBINFO)
|
||||||
|
string(STRIP "${CMAKE_DSM_FLAGS${c}_INIT}" CMAKE_DSM_FLAGS${c}_INIT)
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
set (CMAKE_DSM_FLAGS "${CMAKE_DSM_FLAGS_INIT}" CACHE STRING
|
||||||
|
"Flags used by the assembler during all build types.")
|
||||||
|
|
||||||
|
if(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
|
||||||
|
get_property(_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
||||||
|
# default build type is none
|
||||||
|
if(NOT _GENERATOR_IS_MULTI_CONFIG AND NOT CMAKE_NO_BUILD_TYPE)
|
||||||
|
set (CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE_INIT} CACHE STRING
|
||||||
|
"Choose the type of build, options are: None, Debug Release RelWithDebInfo MinSizeRel.")
|
||||||
|
endif()
|
||||||
|
unset(_GENERATOR_IS_MULTI_CONFIG)
|
||||||
|
set (CMAKE_DSM_FLAGS_DEBUG "${CMAKE_DSM_FLAGS_DEBUG_INIT}" CACHE STRING
|
||||||
|
"Flags used by the assembler during debug builds.")
|
||||||
|
set (CMAKE_DSM_FLAGS_MINSIZEREL "${CMAKE_DSM_FLAGS_MINSIZEREL_INIT}" CACHE STRING
|
||||||
|
"Flags used by the assembler during release minsize builds.")
|
||||||
|
set (CMAKE_DSM_FLAGS_RELEASE "${CMAKE_DSM_FLAGS_RELEASE_INIT}" CACHE STRING
|
||||||
|
"Flags used by the assembler during release builds.")
|
||||||
|
set (CMAKE_DSM_FLAGS_RELWITHDEBINFO "${CMAKE_DSM_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
|
||||||
|
"Flags used by the assembler during Release with Debug Info builds.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
mark_as_advanced(CMAKE_DSM_FLAGS
|
||||||
|
CMAKE_DSM_FLAGS_DEBUG
|
||||||
|
CMAKE_DSM_FLAGS_MINSIZEREL
|
||||||
|
CMAKE_DSM_FLAGS_RELEASE
|
||||||
|
CMAKE_DSM_FLAGS_RELWITHDEBINFO
|
||||||
|
)
|
||||||
|
# WITH: cmake_initialize_per_config_variable(CMAKE_DSM_FLAGS "Flags used by the DSM compiler")
|
||||||
|
|
||||||
|
if(NOT CMAKE_DSM_COMPILE_OBJECT)
|
||||||
|
set(CMAKE_DSM_COMPILE_OBJECT "<CMAKE_DSM_COMPILER> <INCLUDES> <FLAGS> -o <OBJECT> <SOURCE>")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_DSM_CREATE_STATIC_LIBRARY)
|
||||||
|
set(CMAKE_DSM_CREATE_STATIC_LIBRARY
|
||||||
|
"<CMAKE_DSM_COMPILER_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS> "
|
||||||
|
"<CMAKE_DSM_COMPILER_RANLIB> <TARGET>")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_DSM_LINK_EXECUTABLE)
|
||||||
|
set(CMAKE_DSM_LINK_EXECUTABLE
|
||||||
|
"<CMAKE_DSM_COMPILER> <FLAGS> <CMAKE_DSM_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_EXECUTABLE_RUNTIME_DSM_FLAG)
|
||||||
|
set(CMAKE_EXECUTABLE_RUNTIME_DSM_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_DSM_FLAG})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_EXECUTABLE_RUNTIME_DSM_FLAG_SEP)
|
||||||
|
set(CMAKE_EXECUTABLE_RUNTIME_DSM_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_DSM_FLAG_SEP})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_EXECUTABLE_RPATH_LINK_DSM_FLAG)
|
||||||
|
set(CMAKE_EXECUTABLE_RPATH_LINK_DSM_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_DSM_FLAG})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# to be done
|
||||||
|
if(NOT CMAKE_DSM_CREATE_SHARED_LIBRARY)
|
||||||
|
set(CMAKE_DSM_CREATE_SHARED_LIBRARY)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CMAKE_DSM_CREATE_SHARED_MODULE)
|
||||||
|
set(CMAKE_DSM_CREATE_SHARED_MODULE)
|
||||||
|
endif()
|
||||||
87
vendor/librw/cmake/ps2/cmaketoolchain/CMakeDetermineDSMCompiler.cmake
vendored
Normal file
87
vendor/librw/cmake/ps2/cmaketoolchain/CMakeDetermineDSMCompiler.cmake
vendored
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
|
||||||
|
|
||||||
|
if (NOT CMAKE_DSM_COMPILER)
|
||||||
|
message(FATAL_ERROR "Need CMAKE_DSM_COMPILER set")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
_cmake_find_compiler_path(DSM)
|
||||||
|
mark_as_advanced(CMAKE_DSM_COMPILER)
|
||||||
|
|
||||||
|
if (NOT CMAKE_DSM_COMPILER_ID)
|
||||||
|
# Table of per-vendor compiler id flags with expected output.
|
||||||
|
list(APPEND CMAKE_DSM_COMPILER_ID_VENDORS GNU )
|
||||||
|
set(CMAKE_DSM_COMPILER_ID_VENDOR_FLAGS_GNU "--version")
|
||||||
|
set(CMAKE_DSM_COMPILER_ID_VENDOR_REGEX_GNU "(GNU assembler)|(GCC)|(Free Software Foundation)")
|
||||||
|
|
||||||
|
include(CMakeDetermineCompilerId)
|
||||||
|
cmake_determine_compiler_id_vendor(DSM "")
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT _CMAKE_TOOLCHAIN_LOCATION)
|
||||||
|
get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_DSM_COMPILER}" PATH)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (CMAKE_DSM_COMPILER_ID)
|
||||||
|
if (CMAKE_DSM_COMPILER_VERSION)
|
||||||
|
set(_version " ${CMAKE_DSM_COMPILER_VERSION}")
|
||||||
|
else()
|
||||||
|
set(_version "")
|
||||||
|
endif()
|
||||||
|
message(STATUS "The DSM compiler identification is ${CMAKE_DSM_COMPILER_ID}${_version}")
|
||||||
|
unset(_version)
|
||||||
|
else()
|
||||||
|
message(STATUS "The DSM compiler identification is unknown")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT _CMAKE_TOOLCHAIN_PREFIX)
|
||||||
|
get_filename_component(COMPILER_BASENAME "${CMAKE_DSM_COMPILER}" NAME)
|
||||||
|
if (COMPILER_BASENAME MATCHES "^(.+1)g?as(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
|
||||||
|
set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(_CMAKE_PROCESSING_LANGUAGE "DSM")
|
||||||
|
find_program(CMAKE_DSM_COMPILER_AR NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ar HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
|
||||||
|
find_program(CMAKE_DSM_COMPILER_RANLIB NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ranlib HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
|
||||||
|
find_program(CMAKE_DSM_COMPILER_STRIP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}strip HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
|
||||||
|
find_program(CMAKE_DSM_COMPILER_NM NAMES ${_CMAKE_TOOLCHAIN_PREFIX}nm HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
|
||||||
|
find_program(CMAKE_DSM_COMPILER_OBJDUMP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objdump HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
|
||||||
|
find_program(CMAKE_DSM_COMPILER_OBJCOPY NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objcopy HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
|
||||||
|
|
||||||
|
unset(_CMAKE_PROCESSING_LANGUAGE)
|
||||||
|
|
||||||
|
set(CMAKE_DSM_COMPILER_ENV_VAR "DSM")
|
||||||
|
|
||||||
|
if (CMAKE_DSM_COMPILER)
|
||||||
|
message(STATUS "Found DSM assembler: ${CMAKE_DSM_COMPILER}")
|
||||||
|
else()
|
||||||
|
message(STATUS "Didn't find assembler")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
foreach(_var
|
||||||
|
COMPILER
|
||||||
|
COMPILER_ID
|
||||||
|
COMPILER_ARG1
|
||||||
|
COMPILER_ENV_VAR
|
||||||
|
COMPILER_AR
|
||||||
|
COMPILER_RANLIB
|
||||||
|
COMPILER_VERSION
|
||||||
|
)
|
||||||
|
set(_CMAKE_DSM_${_var} "${CMAKE_DSM_${_var}}")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
configure_file("${CMAKE_CURRENT_LIST_DIR}/CMakeDSMCompiler.cmake.in"
|
||||||
|
"${CMAKE_PLATFORM_INFO_DIR}/CMakeDSMCompiler.cmake" @ONLY)
|
||||||
|
|
||||||
|
foreach(_var
|
||||||
|
COMPILER
|
||||||
|
COMPILER_ID
|
||||||
|
COMPILER_ARG1
|
||||||
|
COMPILER_ENV_VAR
|
||||||
|
COMPILER_AR
|
||||||
|
COMPILER_VERSION
|
||||||
|
)
|
||||||
|
unset(_CMAKE_DSM_${_var})
|
||||||
|
endforeach()
|
||||||
7
vendor/librw/cmake/ps2/cmaketoolchain/CMakeTestDSMCompiler.cmake
vendored
Normal file
7
vendor/librw/cmake/ps2/cmaketoolchain/CMakeTestDSMCompiler.cmake
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
set(_ASM_COMPILER_WORKS 0)
|
||||||
|
|
||||||
|
if(CMAKE_DSM_COMPILER)
|
||||||
|
set(_DSM_COMPILER_WORKS)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_DSM_COMPILER_WORKS ${_DSM_COMPILER_WORKS} CACHE INTERNAL "")
|
||||||
1
vendor/librw/cmake/ps2/cmaketoolchain/Platform/PlayStation2.cmake
vendored
Normal file
1
vendor/librw/cmake/ps2/cmaketoolchain/Platform/PlayStation2.cmake
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
|
||||||
24
vendor/librw/cmake/ps2/cmaketoolchain/conanfile.py
vendored
Normal file
24
vendor/librw/cmake/ps2/cmaketoolchain/conanfile.py
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
from conans import ConanFile
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
|
class Ps2devCMakeToolchainConan(ConanFile):
|
||||||
|
name = "ps2dev-cmaketoolchain"
|
||||||
|
description = "CMake toolchain script for ps2dev"
|
||||||
|
topics = "ps2", "sdk", "library", "sony", "playstation", "ps2"
|
||||||
|
|
||||||
|
def export_sources(self):
|
||||||
|
self.copy("*.cmake*", dst="cmake")
|
||||||
|
self.copy("Platform", dst="cmake")
|
||||||
|
|
||||||
|
def package(self):
|
||||||
|
shutil.copytree(os.path.join(self.source_folder, "cmake"),
|
||||||
|
os.path.join(self.package_folder, "cmake"))
|
||||||
|
|
||||||
|
def package_info(self):
|
||||||
|
self.user_info.cmake_dir = os.path.join(self.package_folder, "cmake").replace("\\", "/")
|
||||||
|
|
||||||
|
cmake_toolchain_file = os.path.join(self.package_folder, "cmake", "toolchain_ps2_ee.cmake").replace("\\", "/")
|
||||||
|
self.user_info.cmake_toolchain_file = cmake_toolchain_file
|
||||||
|
self.cpp_info.CONAN_CMAKE_TOOLCHAIN_FILE = cmake_toolchain_file
|
||||||
92
vendor/librw/cmake/ps2/cmaketoolchain/toolchain_ps2_ee.cmake
vendored
Normal file
92
vendor/librw/cmake/ps2/cmaketoolchain/toolchain_ps2_ee.cmake
vendored
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
cmake_minimum_required(VERSION 3.7)
|
||||||
|
|
||||||
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
|
||||||
|
|
||||||
|
set(CMAKE_SYSTEM_NAME "PlayStation2")
|
||||||
|
set(CMAKE_SYSTEM_PROCESSOR "mips64r5900el")
|
||||||
|
set(CMAKE_SYSTEM_VERSION 1)
|
||||||
|
|
||||||
|
set(CMAKE_NO_SYSTEM_FROM_IMPORTED ON)
|
||||||
|
|
||||||
|
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||||
|
|
||||||
|
if(NOT DEFINED ENV{PS2DEV})
|
||||||
|
message(FATAL_ERROR "Need environment variable PS2DEV set")
|
||||||
|
endif()
|
||||||
|
if(NOT DEFINED ENV{PS2SDK})
|
||||||
|
message(FATAL_ERROR "Need environment variable PS2SDK set")
|
||||||
|
endif()
|
||||||
|
if(NOT DEFINED ENV{GSKIT})
|
||||||
|
message(FATAL_ERROR "Need environment variable PS2SDK set")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(PS2DEV "$ENV{PS2DEV}")
|
||||||
|
set(PS2SDK "$ENV{PS2SDK}")
|
||||||
|
set(GSKIT "$ENV{GSKIT}")
|
||||||
|
|
||||||
|
if(NOT IS_DIRECTORY "${PS2DEV}")
|
||||||
|
message(FATAL_ERROR "PS2DEV must be a folder path (${PS2DEV})")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT IS_DIRECTORY "${PS2SDK}")
|
||||||
|
message(FATAL_ERROR "PS2SDK must be a folder path (${PS2SDK})")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT IS_DIRECTORY "${GSKIT}")
|
||||||
|
message(FATAL_ERROR "GSKIT must be a folder path (${GSKIT})")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_DSM_SOURCE_FILE_EXTENSIONS "dsm")
|
||||||
|
|
||||||
|
set(CMAKE_C_COMPILER "${PS2DEV}/ee/bin/mips64r5900el-ps2-elf-gcc" CACHE FILEPATH "C compiler")
|
||||||
|
set(CMAKE_CXX_COMPILER "${PS2DEV}/ee/bin/mips64r5900el-ps2-elf-g++" CACHE FILEPATH "CXX compiler")
|
||||||
|
set(CMAKE_ASM_COMPILER "${PS2DEV}/ee/bin/mips64r5900el-ps2-elf-g++" CACHE FILEPATH "ASM assembler")
|
||||||
|
set(CMAKE_DSM_COMPILER "${PS2DEV}/dvp/bin/dvp-as" CACHE FILEPATH "DSM assembler")
|
||||||
|
set(CMAKE_AR "${PS2DEV}/ee/bin/mips64r5900el-ps2-elf-ar" CACHE FILEPATH "archiver")
|
||||||
|
set(CMAKE_LINKER "${PS2DEV}/ee/bin/mips64r5900el-ps2-elf-ld" CACHE FILEPATH "Linker")
|
||||||
|
set(CMAKE_RANLIB "${PS2DEV}/ee/bin/mips64r5900el-ps2-elf-ranlib" CACHE FILEPATH "ranlib")
|
||||||
|
set(CMAKE_STRIP "${PS2DEV}/ee/bin/mips64r5900el-ps2-elf-strip" CACHE FILEPATH "strip")
|
||||||
|
|
||||||
|
set(CMAKE_ASM_FLAGS_INIT "-G0 -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}/common/include\" -D_EE")
|
||||||
|
set(CMAKE_C_FLAGS_INIT "-G0 -fno-common -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}/common/include\" -D_EE")
|
||||||
|
set(CMAKE_CXX_FLAGS_INIT "-G0 -fno-common -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}/common/include\" -D_EE")
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS_INIT "-G0 -L\"${PS2SDK}/ee/lib\" -Wl,-r -Wl,-d")
|
||||||
|
|
||||||
|
set(CMAKE_FIND_ROOT_PATH "${PS2DEV}/ee" "${PS2SDK}/ee" "${GSKIT}")
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||||
|
|
||||||
|
set(PS2 1)
|
||||||
|
set(EE 1)
|
||||||
|
|
||||||
|
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
|
||||||
|
|
||||||
|
function(add_erl_executable TARGET)
|
||||||
|
cmake_parse_arguments("AEE" "" "OUTPUT_VAR" "" ${ARGN})
|
||||||
|
|
||||||
|
get_target_property(output_dir "${TARGET}" RUNTIME_OUTPUT_DIRECTORY)
|
||||||
|
if(NOT output_dir)
|
||||||
|
set(output_dir ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
get_target_property(output_name ${TARGET} OUTPUT_NAME)
|
||||||
|
if(NOT output_name)
|
||||||
|
set(output_name ${TARGET})
|
||||||
|
endif()
|
||||||
|
set(outfile "${output_dir}/${output_name}.erl")
|
||||||
|
|
||||||
|
add_custom_command(OUTPUT "${outfile}"
|
||||||
|
COMMAND "${CMAKE_COMMAND}" -E copy "$<TARGET_FILE:${TARGET}>" "${outfile}"
|
||||||
|
COMMAND "${CMAKE_STRIP}" --strip-unneeded -R .mdebug.eabi64 -R .reginfo -R .comment "${outfile}"
|
||||||
|
DEPENDS ${TARGET}
|
||||||
|
)
|
||||||
|
add_custom_target("${TARGET}_erl" ALL
|
||||||
|
DEPENDS "${outfile}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if(AEE_OUTPUT_VAR)
|
||||||
|
set("${AEE_OUTPUT_VAR}" "${outfile}" PARENT_SCOPE)
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
12
vendor/librw/conan/playstation2
vendored
Normal file
12
vendor/librw/conan/playstation2
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
[settings]
|
||||||
|
os=Playstation2
|
||||||
|
arch=mips
|
||||||
|
compiler=gcc
|
||||||
|
compiler.version=3.2
|
||||||
|
compiler.libcxx=libstdc++
|
||||||
|
build_type=Release
|
||||||
|
[options]
|
||||||
|
librw:platform=ps2
|
||||||
|
[build_requires]
|
||||||
|
ps2dev-ps2toolchain/unknown@madebr/testing
|
||||||
|
[env]
|
||||||
136
vendor/librw/conanfile.py
vendored
Normal file
136
vendor/librw/conanfile.py
vendored
Normal file
|
|
@ -0,0 +1,136 @@
|
||||||
|
from conans import ConanFile, CMake, tools
|
||||||
|
from conans.errors import ConanException, ConanInvalidConfiguration
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import textwrap
|
||||||
|
|
||||||
|
|
||||||
|
class LibrwConan(ConanFile):
|
||||||
|
name = "librw"
|
||||||
|
version = "master"
|
||||||
|
license = "MIT"
|
||||||
|
settings = "os", "arch", "compiler", "build_type"
|
||||||
|
generators = "cmake", "cmake_find_package"
|
||||||
|
options = {
|
||||||
|
"platform": ["null", "gl3", "d3d9", "ps2"],
|
||||||
|
"gl3_gfxlib": ["glfw", "sdl2"],
|
||||||
|
}
|
||||||
|
default_options = {
|
||||||
|
"platform": "gl3",
|
||||||
|
"gl3_gfxlib": "glfw",
|
||||||
|
"openal:with_external_libs": False,
|
||||||
|
"sdl2:vulkan": False,
|
||||||
|
"sdl2:opengl": True,
|
||||||
|
"sdl2:sdl2main": True,
|
||||||
|
}
|
||||||
|
no_copy_source = True
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _os_is_playstation2(self):
|
||||||
|
try:
|
||||||
|
return self.settings.os == "Playstation2"
|
||||||
|
except ConanException:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def config_options(self):
|
||||||
|
if self._os_is_playstation2:
|
||||||
|
self.options.platform = "ps2"
|
||||||
|
if self.settings.os == "Windows":
|
||||||
|
self.options.platform = "d3d9"
|
||||||
|
self.options["sdl2"].directx = False
|
||||||
|
|
||||||
|
def configure(self):
|
||||||
|
if self.options.platform != "gl3":
|
||||||
|
del self.options.gl3_gfxlib
|
||||||
|
|
||||||
|
def validate(self):
|
||||||
|
if self.options.platform == "d3d9" and self.settings.os != "Windows":
|
||||||
|
raise ConanInvalidConfiguration("platform=d3d9 can only be built for os=Windows")
|
||||||
|
if self._os_is_playstation2:
|
||||||
|
if self.options.platform not in ("null", "ps2"):
|
||||||
|
raise ConanInvalidConfiguration("os=Playstation2 only supports platform=(null,ps2)")
|
||||||
|
|
||||||
|
def requirements(self):
|
||||||
|
if self.options.platform == "gl3":
|
||||||
|
if self.options.gl3_gfxlib == "glfw":
|
||||||
|
self.requires("glfw/3.3.2")
|
||||||
|
elif self.options.gl3_gfxlib == "sdl2":
|
||||||
|
self.requires("sdl2/2.0.12@bincrafters/stable")
|
||||||
|
elif self.options.platform == "ps2":
|
||||||
|
self.requires("ps2dev-ps2sdk/unknown@madebr/testing")
|
||||||
|
if self._os_is_playstation2:
|
||||||
|
self.requires("ps2dev-cmaketoolchain/{}".format(self.version))
|
||||||
|
|
||||||
|
def export_sources(self):
|
||||||
|
for d in ("cmake", "skeleton", "src", "tools"):
|
||||||
|
shutil.copytree(src=d, dst=os.path.join(self.export_sources_folder, d))
|
||||||
|
self.copy("args.h")
|
||||||
|
self.copy("rw.h")
|
||||||
|
self.copy("CMakeLists.txt")
|
||||||
|
self.copy("LICENSE")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _librw_platform(self):
|
||||||
|
return {
|
||||||
|
"null": "NULL",
|
||||||
|
"gl3": "GL3",
|
||||||
|
"d3d9": "D3D9",
|
||||||
|
"ps2": "PS2",
|
||||||
|
}[str(self.options.platform)]
|
||||||
|
|
||||||
|
def build(self):
|
||||||
|
if self.source_folder == self.build_folder:
|
||||||
|
raise Exception("cannot build with source_folder == build_folder")
|
||||||
|
if self.options.platform == "gl3" and self.options.gl3_gfxlib == "glfw":
|
||||||
|
tools.save("Findglfw3.cmake",
|
||||||
|
textwrap.dedent(
|
||||||
|
"""
|
||||||
|
if(NOT TARGET glfw)
|
||||||
|
message(STATUS "Creating glfw TARGET")
|
||||||
|
add_library(glfw INTERFACE IMPORTED)
|
||||||
|
set_target_properties(glfw PROPERTIES
|
||||||
|
INTERFACE_LINK_LIBRARIES CONAN_PKG::glfw)
|
||||||
|
endif()
|
||||||
|
"""), append=True)
|
||||||
|
tools.save("CMakeLists.txt",
|
||||||
|
textwrap.dedent(
|
||||||
|
"""
|
||||||
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
project(cmake_wrapper)
|
||||||
|
|
||||||
|
include("{}/conanbuildinfo.cmake")
|
||||||
|
conan_basic_setup(TARGETS)
|
||||||
|
|
||||||
|
add_subdirectory("{}" librw)
|
||||||
|
""").format(self.install_folder.replace("\\", "/"),
|
||||||
|
self.source_folder.replace("\\", "/")))
|
||||||
|
cmake = CMake(self)
|
||||||
|
env = {}
|
||||||
|
cmake.definitions["LIBRW_PLATFORM"] = self._librw_platform
|
||||||
|
cmake.definitions["LIBRW_INSTALL"] = True
|
||||||
|
cmake.definitions["LIBRW_TOOLS"] = True
|
||||||
|
if self.options.platform == "gl3":
|
||||||
|
cmake.definitions["LIBRW_GL3_GFXLIB"] = str(self.options.gl3_gfxlib).upper()
|
||||||
|
if self._os_is_playstation2:
|
||||||
|
env["PS2SDK"] = self.deps_cpp_info["ps2dev-ps2sdk"].rootpath
|
||||||
|
with tools.environment_append(env):
|
||||||
|
cmake.configure(source_folder=self.build_folder)
|
||||||
|
cmake.build()
|
||||||
|
|
||||||
|
def package(self):
|
||||||
|
cmake = CMake(self)
|
||||||
|
cmake.install()
|
||||||
|
|
||||||
|
def package_info(self):
|
||||||
|
self.cpp_info.includedirs.append(os.path.join("include", "librw"))
|
||||||
|
self.cpp_info.libs = ["librw" if self.settings.compiler == "Visual Studio" else "rw"]
|
||||||
|
if self.options.platform == "null":
|
||||||
|
self.cpp_info.defines.append("RW_NULL")
|
||||||
|
elif self.options.platform == "gl3":
|
||||||
|
self.cpp_info.defines.append("RW_GL3")
|
||||||
|
if self.options.gl3_gfxlib == "sdl2":
|
||||||
|
self.cpp_info.defines.append("LIBRW_SDL2")
|
||||||
|
elif self.options.platform == "d3d9":
|
||||||
|
self.cpp_info.defines.append("RW_D3D9")
|
||||||
|
elif self.options.platform == "ps2":
|
||||||
|
self.cpp_info.defines.append("RW_PS2")
|
||||||
22
vendor/librw/docker_rebuild_ps2.sh
vendored
Normal file
22
vendor/librw/docker_rebuild_ps2.sh
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
TARGET=release_ps2
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
LIBRWDIR=$(dirname "$(readlink -f "$0")")
|
||||||
|
echo "LIBRWDIR is $LIBRWDIR"
|
||||||
|
|
||||||
|
cd "$LIBRWDIR"
|
||||||
|
|
||||||
|
premake5 gmake
|
||||||
|
|
||||||
|
docker rm librw_instance -f >/dev/null 2>&1 || true
|
||||||
|
docker stop librw_instance -t 0 >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
docker pull librw/librw
|
||||||
|
docker run -v "$LIBRWDIR:/librw:rw,z" --name librw_instance -d librw/librw sleep infinity
|
||||||
|
docker exec -u builder librw_instance /bin/bash -c "cd /librw/build && make clean config=$TARGET && make config=$TARGET verbose=1"
|
||||||
|
|
||||||
|
docker rm librw_instance -f >/dev/null 2>&1 || true
|
||||||
|
docker stop librw_instance -t 0 >/dev/null 2>&1 || true
|
||||||
1
vendor/librw/premake-vs2019.cmd
vendored
Normal file
1
vendor/librw/premake-vs2019.cmd
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
premake5 vs2019
|
||||||
277
vendor/librw/premake5.lua
vendored
Normal file
277
vendor/librw/premake5.lua
vendored
Normal file
|
|
@ -0,0 +1,277 @@
|
||||||
|
newoption {
|
||||||
|
trigger = "gfxlib",
|
||||||
|
value = "LIBRARY",
|
||||||
|
description = "Choose a particular development library",
|
||||||
|
default = "glfw",
|
||||||
|
allowed = {
|
||||||
|
{ "glfw", "GLFW" },
|
||||||
|
{ "sdl2", "SDL2" },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
newoption {
|
||||||
|
trigger = "glfwdir64",
|
||||||
|
value = "PATH",
|
||||||
|
description = "Directory of glfw",
|
||||||
|
default = "../glfw-3.3.4.bin.WIN64",
|
||||||
|
}
|
||||||
|
|
||||||
|
newoption {
|
||||||
|
trigger = "glfwdir32",
|
||||||
|
value = "PATH",
|
||||||
|
description = "Directory of glfw",
|
||||||
|
default = "../glfw-3.3.4.bin.WIN32",
|
||||||
|
}
|
||||||
|
|
||||||
|
newoption {
|
||||||
|
trigger = "sdl2dir",
|
||||||
|
value = "PATH",
|
||||||
|
description = "Directory of sdl2",
|
||||||
|
default = "../SDL2-2.0.14",
|
||||||
|
}
|
||||||
|
|
||||||
|
workspace "librw"
|
||||||
|
location "build"
|
||||||
|
language "C++"
|
||||||
|
|
||||||
|
configurations { "Release", "Debug" }
|
||||||
|
filter { "system:windows" }
|
||||||
|
configurations { "ReleaseStatic" }
|
||||||
|
platforms { "win-x86-null", "win-x86-gl3", "win-x86-d3d9",
|
||||||
|
"win-amd64-null", "win-amd64-gl3", "win-amd64-d3d9" }
|
||||||
|
filter { "system:linux" }
|
||||||
|
platforms { "linux-x86-null", "linux-x86-gl3",
|
||||||
|
"linux-amd64-null", "linux-amd64-gl3",
|
||||||
|
"linux-arm-null", "linux-arm-gl3",
|
||||||
|
"ps2" }
|
||||||
|
if _OPTIONS["gfxlib"] == "sdl2" then
|
||||||
|
includedirs { "/usr/include/SDL2" }
|
||||||
|
end
|
||||||
|
filter {}
|
||||||
|
|
||||||
|
filter "configurations:Debug"
|
||||||
|
defines { "DEBUG" }
|
||||||
|
symbols "On"
|
||||||
|
filter "configurations:Release*"
|
||||||
|
defines { "NDEBUG" }
|
||||||
|
optimize "On"
|
||||||
|
filter "configurations:ReleaseStatic"
|
||||||
|
staticruntime("On")
|
||||||
|
|
||||||
|
filter { "platforms:*null" }
|
||||||
|
defines { "RW_NULL" }
|
||||||
|
filter { "platforms:*gl3" }
|
||||||
|
defines { "RW_GL3" }
|
||||||
|
if _OPTIONS["gfxlib"] == "sdl2" then
|
||||||
|
defines { "LIBRW_SDL2" }
|
||||||
|
end
|
||||||
|
filter { "platforms:*d3d9" }
|
||||||
|
defines { "RW_D3D9" }
|
||||||
|
filter { "platforms:ps2" }
|
||||||
|
defines { "RW_PS2" }
|
||||||
|
toolset "gcc"
|
||||||
|
gccprefix 'ee-'
|
||||||
|
buildoptions { "-nostdlib", "-fno-common" }
|
||||||
|
includedirs { "$(PS2SDK)/ee/include", "$(PS2SDK)/common/include" }
|
||||||
|
optimize "Off"
|
||||||
|
|
||||||
|
filter { "platforms:*amd64*" }
|
||||||
|
architecture "x86_64"
|
||||||
|
filter { "platforms:*x86*" }
|
||||||
|
architecture "x86"
|
||||||
|
filter { "platforms:*arm*" }
|
||||||
|
architecture "ARM"
|
||||||
|
|
||||||
|
filter { "platforms:win*" }
|
||||||
|
system "windows"
|
||||||
|
filter { "platforms:linux*" }
|
||||||
|
system "linux"
|
||||||
|
|
||||||
|
filter { "platforms:win*gl3" }
|
||||||
|
includedirs { path.join(_OPTIONS["sdl2dir"], "include") }
|
||||||
|
filter { "platforms:win-x86-gl3" }
|
||||||
|
includedirs { path.join(_OPTIONS["glfwdir32"], "include") }
|
||||||
|
filter { "platforms:win-amd64-gl3" }
|
||||||
|
includedirs { path.join(_OPTIONS["glfwdir64"], "include") }
|
||||||
|
|
||||||
|
filter "action:vs*"
|
||||||
|
buildoptions { "/wd4996", "/wd4244" }
|
||||||
|
|
||||||
|
filter { "platforms:win*gl3", "action:not vs*" }
|
||||||
|
if _OPTIONS["gfxlib"] == "sdl2" then
|
||||||
|
includedirs { "/mingw/include/SDL2" } -- TODO: Detect this properly
|
||||||
|
end
|
||||||
|
|
||||||
|
filter {}
|
||||||
|
|
||||||
|
Libdir = "lib/%{cfg.platform}/%{cfg.buildcfg}"
|
||||||
|
Bindir = "bin/%{cfg.platform}/%{cfg.buildcfg}"
|
||||||
|
|
||||||
|
project "librw"
|
||||||
|
kind "StaticLib"
|
||||||
|
targetname "rw"
|
||||||
|
targetdir (Libdir)
|
||||||
|
defines { "LODEPNG_NO_COMPILE_CPP" }
|
||||||
|
files { "src/*.*" }
|
||||||
|
files { "src/*/*.*" }
|
||||||
|
filter { "platforms:*gl3" }
|
||||||
|
files { "src/gl/glad/*.*" }
|
||||||
|
|
||||||
|
project "dumprwtree"
|
||||||
|
kind "ConsoleApp"
|
||||||
|
targetdir (Bindir)
|
||||||
|
removeplatforms { "*gl3", "*d3d9", "ps2" }
|
||||||
|
files { "tools/dumprwtree/*" }
|
||||||
|
includedirs { "." }
|
||||||
|
libdirs { Libdir }
|
||||||
|
links { "librw" }
|
||||||
|
|
||||||
|
function findlibs()
|
||||||
|
filter { "platforms:linux*gl3" }
|
||||||
|
links { "GL" }
|
||||||
|
if _OPTIONS["gfxlib"] == "glfw" then
|
||||||
|
links { "glfw" }
|
||||||
|
else
|
||||||
|
links { "SDL2" }
|
||||||
|
end
|
||||||
|
filter { "platforms:win-amd64-gl3" }
|
||||||
|
libdirs { path.join(_OPTIONS["glfwdir64"], "lib-vc2015") }
|
||||||
|
libdirs { path.join(_OPTIONS["sdl2dir"], "lib/x64") }
|
||||||
|
filter { "platforms:win-x86-gl3" }
|
||||||
|
libdirs { path.join(_OPTIONS["glfwdir32"], "lib-vc2015") }
|
||||||
|
libdirs { path.join(_OPTIONS["sdl2dir"], "lib/x86") }
|
||||||
|
filter { "platforms:win*gl3" }
|
||||||
|
links { "opengl32" }
|
||||||
|
if _OPTIONS["gfxlib"] == "glfw" then
|
||||||
|
links { "glfw3" }
|
||||||
|
else
|
||||||
|
links { "SDL2" }
|
||||||
|
end
|
||||||
|
filter { "platforms:*d3d9" }
|
||||||
|
links { "gdi32", "d3d9" }
|
||||||
|
filter { "platforms:*d3d9", "action:vs*" }
|
||||||
|
links { "Xinput9_1_0" }
|
||||||
|
filter {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function skeleton()
|
||||||
|
files { "skeleton/*.cpp", "skeleton/*.h" }
|
||||||
|
files { "skeleton/imgui/*.cpp", "skeleton/imgui/*.h" }
|
||||||
|
includedirs { "skeleton" }
|
||||||
|
end
|
||||||
|
|
||||||
|
function skeltool(dir)
|
||||||
|
targetdir (Bindir)
|
||||||
|
files { path.join("tools", dir, "*.cpp"),
|
||||||
|
path.join("tools", dir, "*.h") }
|
||||||
|
vpaths {
|
||||||
|
{["src"] = { path.join("tools", dir, "*") }},
|
||||||
|
{["skeleton"] = { "skeleton/*" }},
|
||||||
|
}
|
||||||
|
skeleton()
|
||||||
|
debugdir ( path.join("tools", dir) )
|
||||||
|
includedirs { "." }
|
||||||
|
libdirs { Libdir }
|
||||||
|
links { "librw" }
|
||||||
|
findlibs()
|
||||||
|
end
|
||||||
|
|
||||||
|
function vucode()
|
||||||
|
filter "files:**.dsm"
|
||||||
|
buildcommands {
|
||||||
|
'cpp "%{file.relpath}" | dvp-as -o "%{cfg.objdir}/%{file.basename}.o"'
|
||||||
|
}
|
||||||
|
buildoutputs { '%{cfg.objdir}/%{file.basename}.o' }
|
||||||
|
filter {}
|
||||||
|
end
|
||||||
|
|
||||||
|
project "playground"
|
||||||
|
kind "WindowedApp"
|
||||||
|
characterset ("MBCS")
|
||||||
|
skeltool("playground")
|
||||||
|
entrypoint("WinMainCRTStartup")
|
||||||
|
removeplatforms { "*null" }
|
||||||
|
removeplatforms { "ps2" } -- for now
|
||||||
|
|
||||||
|
project "imguitest"
|
||||||
|
kind "WindowedApp"
|
||||||
|
characterset ("MBCS")
|
||||||
|
skeltool("imguitest")
|
||||||
|
entrypoint("WinMainCRTStartup")
|
||||||
|
removeplatforms { "*null" }
|
||||||
|
removeplatforms { "ps2" }
|
||||||
|
|
||||||
|
project "lights"
|
||||||
|
kind "WindowedApp"
|
||||||
|
characterset ("MBCS")
|
||||||
|
skeltool("lights")
|
||||||
|
entrypoint("WinMainCRTStartup")
|
||||||
|
removeplatforms { "*null" }
|
||||||
|
removeplatforms { "ps2" }
|
||||||
|
|
||||||
|
project "subrast"
|
||||||
|
kind "WindowedApp"
|
||||||
|
characterset ("MBCS")
|
||||||
|
skeltool("subrast")
|
||||||
|
entrypoint("WinMainCRTStartup")
|
||||||
|
removeplatforms { "*null" }
|
||||||
|
removeplatforms { "ps2" }
|
||||||
|
|
||||||
|
project "camera"
|
||||||
|
kind "WindowedApp"
|
||||||
|
characterset ("MBCS")
|
||||||
|
skeltool("camera")
|
||||||
|
entrypoint("WinMainCRTStartup")
|
||||||
|
removeplatforms { "*null" }
|
||||||
|
removeplatforms { "ps2" }
|
||||||
|
|
||||||
|
project "im2d"
|
||||||
|
kind "WindowedApp"
|
||||||
|
characterset ("MBCS")
|
||||||
|
skeltool("im2d")
|
||||||
|
entrypoint("WinMainCRTStartup")
|
||||||
|
removeplatforms { "*null" }
|
||||||
|
removeplatforms { "ps2" }
|
||||||
|
|
||||||
|
project "im3d"
|
||||||
|
kind "WindowedApp"
|
||||||
|
characterset ("MBCS")
|
||||||
|
skeltool("im3d")
|
||||||
|
entrypoint("WinMainCRTStartup")
|
||||||
|
removeplatforms { "*null" }
|
||||||
|
removeplatforms { "ps2" }
|
||||||
|
|
||||||
|
project "ska2anm"
|
||||||
|
kind "ConsoleApp"
|
||||||
|
characterset ("MBCS")
|
||||||
|
targetdir (Bindir)
|
||||||
|
files { path.join("tools/ska2anm", "*.cpp"),
|
||||||
|
path.join("tools/ska2anm", "*.h") }
|
||||||
|
debugdir ( path.join("tools/ska2nm") )
|
||||||
|
includedirs { "." }
|
||||||
|
libdirs { Libdir }
|
||||||
|
links { "librw" }
|
||||||
|
findlibs()
|
||||||
|
removeplatforms { "*gl3", "*d3d9", "*ps2" }
|
||||||
|
|
||||||
|
project "ps2test"
|
||||||
|
kind "ConsoleApp"
|
||||||
|
targetdir (Bindir)
|
||||||
|
vucode()
|
||||||
|
removeplatforms { "*gl3", "*d3d9", "*null" }
|
||||||
|
targetextension '.elf'
|
||||||
|
includedirs { "." }
|
||||||
|
files { "tools/ps2test/*.cpp",
|
||||||
|
"tools/ps2test/vu/*.dsm",
|
||||||
|
"tools/ps2test/*.h" }
|
||||||
|
libdirs { "$(PS2SDK)/ee/lib" }
|
||||||
|
links { "librw" }
|
||||||
|
|
||||||
|
--project "ps2rastertest"
|
||||||
|
-- kind "ConsoleApp"
|
||||||
|
-- targetdir (Bindir)
|
||||||
|
-- removeplatforms { "*gl3", "*d3d9" }
|
||||||
|
-- files { "tools/ps2rastertest/*.cpp" }
|
||||||
|
-- includedirs { "." }
|
||||||
|
-- libdirs { Libdir }
|
||||||
|
-- links { "librw" }
|
||||||
25
vendor/librw/rw.h
vendored
Normal file
25
vendor/librw/rw.h
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "src/rwbase.h"
|
||||||
|
#include "src/rwerror.h"
|
||||||
|
#include "src/rwplg.h"
|
||||||
|
#include "src/rwrender.h"
|
||||||
|
#include "src/rwengine.h"
|
||||||
|
#include "src/rwpipeline.h"
|
||||||
|
#include "src/rwobjects.h"
|
||||||
|
#include "src/rwanim.h"
|
||||||
|
#include "src/rwplugins.h"
|
||||||
|
#include "src/rwuserdata.h"
|
||||||
|
#include "src/rwcharset.h"
|
||||||
|
#include "src/ps2/rwps2.h"
|
||||||
|
#include "src/ps2/rwps2plg.h"
|
||||||
|
#include "src/d3d/rwxbox.h"
|
||||||
|
#include "src/d3d/rwd3d.h"
|
||||||
|
#include "src/d3d/rwd3d8.h"
|
||||||
|
#include "src/d3d/rwd3d9.h"
|
||||||
|
#include "src/gl/rwwdgl.h"
|
||||||
|
#include "src/gl/rwgl3.h"
|
||||||
|
#include "src/gl/rwgl3shader.h"
|
||||||
|
#include "src/gl/rwgl3plg.h"
|
||||||
80
vendor/librw/skeleton/CMakeLists.txt
vendored
Normal file
80
vendor/librw/skeleton/CMakeLists.txt
vendored
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
add_library(librw_skeleton
|
||||||
|
glfw.cpp
|
||||||
|
sdl2.cpp
|
||||||
|
skeleton.cpp
|
||||||
|
skeleton.h
|
||||||
|
win.cpp
|
||||||
|
|
||||||
|
imgui/imgui_impl_rw.cpp
|
||||||
|
imgui/imgui_impl_rw.h
|
||||||
|
|
||||||
|
imgui/imconfig.h
|
||||||
|
imgui/imgui.cpp
|
||||||
|
imgui/imgui.h
|
||||||
|
imgui/imgui_demo.cpp
|
||||||
|
imgui/imgui_draw.cpp
|
||||||
|
imgui/imgui_internal.h
|
||||||
|
imgui/imgui_tables.cpp
|
||||||
|
imgui/imgui_widgets.cpp
|
||||||
|
imgui/imstb_rectpack.h
|
||||||
|
imgui/imstb_textedit.h
|
||||||
|
imgui/imstb_truetype.h
|
||||||
|
|
||||||
|
imgui/ImGuizmo.cpp
|
||||||
|
imgui/ImGuizmo.h
|
||||||
|
)
|
||||||
|
add_library(librw::skeleton ALIAS librw_skeleton)
|
||||||
|
|
||||||
|
set_target_properties(librw_skeleton
|
||||||
|
PROPERTIES
|
||||||
|
PREFIX ""
|
||||||
|
EXPORT_NAME skeleton
|
||||||
|
CXX_STANDARD 11
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(librw_skeleton
|
||||||
|
PRIVATE
|
||||||
|
librw
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(librw_skeleton
|
||||||
|
PUBLIC
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||||
|
$<INSTALL_INTERFACE:${LIBRW_INSTALL_INCLUDEDIR}/skeleton>
|
||||||
|
)
|
||||||
|
|
||||||
|
if(LIBRW_INSTALL)
|
||||||
|
install(
|
||||||
|
FILES
|
||||||
|
skeleton.h
|
||||||
|
DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/skeleton"
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
FILES
|
||||||
|
imgui/imconfig.h
|
||||||
|
imgui/imgui.h
|
||||||
|
imgui/imgui_impl_rw.h
|
||||||
|
imgui/imgui_internal.h
|
||||||
|
imgui/ImGuizmo.h
|
||||||
|
imgui/imstb_rectpack.h
|
||||||
|
imgui/imstb_textedit.h
|
||||||
|
imgui/imstb_truetype.h
|
||||||
|
DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/skeleton/imgui"
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
FILES
|
||||||
|
imgui/LICENSE_imgui.txt
|
||||||
|
imgui/LICENSE_imguizmo.txt
|
||||||
|
DESTINATION "${CMAKE_INSTALL_DOCDIR}"
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
TARGETS librw_skeleton
|
||||||
|
EXPORT librw-targets
|
||||||
|
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||||
|
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||||
|
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
262
vendor/librw/skeleton/glfw.cpp
vendored
Normal file
262
vendor/librw/skeleton/glfw.cpp
vendored
Normal file
|
|
@ -0,0 +1,262 @@
|
||||||
|
#ifndef LIBRW_SDL2
|
||||||
|
|
||||||
|
#include <rw.h>
|
||||||
|
#include "skeleton.h"
|
||||||
|
|
||||||
|
using namespace sk;
|
||||||
|
using namespace rw;
|
||||||
|
|
||||||
|
#ifdef RW_OPENGL
|
||||||
|
|
||||||
|
GLFWwindow *window;
|
||||||
|
int keymap[GLFW_KEY_LAST+1];
|
||||||
|
|
||||||
|
static void
|
||||||
|
initkeymap(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < GLFW_KEY_LAST+1; i++)
|
||||||
|
keymap[i] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_SPACE] = ' ';
|
||||||
|
keymap[GLFW_KEY_APOSTROPHE] = '\'';
|
||||||
|
keymap[GLFW_KEY_COMMA] = ',';
|
||||||
|
keymap[GLFW_KEY_MINUS] = '-';
|
||||||
|
keymap[GLFW_KEY_PERIOD] = '.';
|
||||||
|
keymap[GLFW_KEY_SLASH] = '/';
|
||||||
|
keymap[GLFW_KEY_0] = '0';
|
||||||
|
keymap[GLFW_KEY_1] = '1';
|
||||||
|
keymap[GLFW_KEY_2] = '2';
|
||||||
|
keymap[GLFW_KEY_3] = '3';
|
||||||
|
keymap[GLFW_KEY_4] = '4';
|
||||||
|
keymap[GLFW_KEY_5] = '5';
|
||||||
|
keymap[GLFW_KEY_6] = '6';
|
||||||
|
keymap[GLFW_KEY_7] = '7';
|
||||||
|
keymap[GLFW_KEY_8] = '8';
|
||||||
|
keymap[GLFW_KEY_9] = '9';
|
||||||
|
keymap[GLFW_KEY_SEMICOLON] = ';';
|
||||||
|
keymap[GLFW_KEY_EQUAL] = '=';
|
||||||
|
keymap[GLFW_KEY_A] = 'A';
|
||||||
|
keymap[GLFW_KEY_B] = 'B';
|
||||||
|
keymap[GLFW_KEY_C] = 'C';
|
||||||
|
keymap[GLFW_KEY_D] = 'D';
|
||||||
|
keymap[GLFW_KEY_E] = 'E';
|
||||||
|
keymap[GLFW_KEY_F] = 'F';
|
||||||
|
keymap[GLFW_KEY_G] = 'G';
|
||||||
|
keymap[GLFW_KEY_H] = 'H';
|
||||||
|
keymap[GLFW_KEY_I] = 'I';
|
||||||
|
keymap[GLFW_KEY_J] = 'J';
|
||||||
|
keymap[GLFW_KEY_K] = 'K';
|
||||||
|
keymap[GLFW_KEY_L] = 'L';
|
||||||
|
keymap[GLFW_KEY_M] = 'M';
|
||||||
|
keymap[GLFW_KEY_N] = 'N';
|
||||||
|
keymap[GLFW_KEY_O] = 'O';
|
||||||
|
keymap[GLFW_KEY_P] = 'P';
|
||||||
|
keymap[GLFW_KEY_Q] = 'Q';
|
||||||
|
keymap[GLFW_KEY_R] = 'R';
|
||||||
|
keymap[GLFW_KEY_S] = 'S';
|
||||||
|
keymap[GLFW_KEY_T] = 'T';
|
||||||
|
keymap[GLFW_KEY_U] = 'U';
|
||||||
|
keymap[GLFW_KEY_V] = 'V';
|
||||||
|
keymap[GLFW_KEY_W] = 'W';
|
||||||
|
keymap[GLFW_KEY_X] = 'X';
|
||||||
|
keymap[GLFW_KEY_Y] = 'Y';
|
||||||
|
keymap[GLFW_KEY_Z] = 'Z';
|
||||||
|
keymap[GLFW_KEY_LEFT_BRACKET] = '[';
|
||||||
|
keymap[GLFW_KEY_BACKSLASH] = '\\';
|
||||||
|
keymap[GLFW_KEY_RIGHT_BRACKET] = ']';
|
||||||
|
keymap[GLFW_KEY_GRAVE_ACCENT] = '`';
|
||||||
|
keymap[GLFW_KEY_ESCAPE] = KEY_ESC;
|
||||||
|
keymap[GLFW_KEY_ENTER] = KEY_ENTER;
|
||||||
|
keymap[GLFW_KEY_TAB] = KEY_TAB;
|
||||||
|
keymap[GLFW_KEY_BACKSPACE] = KEY_BACKSP;
|
||||||
|
keymap[GLFW_KEY_INSERT] = KEY_INS;
|
||||||
|
keymap[GLFW_KEY_DELETE] = KEY_DEL;
|
||||||
|
keymap[GLFW_KEY_RIGHT] = KEY_RIGHT;
|
||||||
|
keymap[GLFW_KEY_LEFT] = KEY_LEFT;
|
||||||
|
keymap[GLFW_KEY_DOWN] = KEY_DOWN;
|
||||||
|
keymap[GLFW_KEY_UP] = KEY_UP;
|
||||||
|
keymap[GLFW_KEY_PAGE_UP] = KEY_PGUP;
|
||||||
|
keymap[GLFW_KEY_PAGE_DOWN] = KEY_PGDN;
|
||||||
|
keymap[GLFW_KEY_HOME] = KEY_HOME;
|
||||||
|
keymap[GLFW_KEY_END] = KEY_END;
|
||||||
|
keymap[GLFW_KEY_CAPS_LOCK] = KEY_CAPSLK;
|
||||||
|
keymap[GLFW_KEY_SCROLL_LOCK] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_NUM_LOCK] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_PRINT_SCREEN] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_PAUSE] = KEY_NULL;
|
||||||
|
|
||||||
|
keymap[GLFW_KEY_F1] = KEY_F1;
|
||||||
|
keymap[GLFW_KEY_F2] = KEY_F2;
|
||||||
|
keymap[GLFW_KEY_F3] = KEY_F3;
|
||||||
|
keymap[GLFW_KEY_F4] = KEY_F4;
|
||||||
|
keymap[GLFW_KEY_F5] = KEY_F5;
|
||||||
|
keymap[GLFW_KEY_F6] = KEY_F6;
|
||||||
|
keymap[GLFW_KEY_F7] = KEY_F7;
|
||||||
|
keymap[GLFW_KEY_F8] = KEY_F8;
|
||||||
|
keymap[GLFW_KEY_F9] = KEY_F9;
|
||||||
|
keymap[GLFW_KEY_F10] = KEY_F10;
|
||||||
|
keymap[GLFW_KEY_F11] = KEY_F11;
|
||||||
|
keymap[GLFW_KEY_F12] = KEY_F12;
|
||||||
|
keymap[GLFW_KEY_F13] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_F14] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_F15] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_F16] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_F17] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_F18] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_F19] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_F20] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_F21] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_F22] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_F23] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_F24] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_F25] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_KP_0] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_KP_1] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_KP_2] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_KP_3] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_KP_4] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_KP_5] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_KP_6] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_KP_7] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_KP_8] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_KP_9] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_KP_DECIMAL] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_KP_DIVIDE] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_KP_MULTIPLY] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_KP_SUBTRACT] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_KP_ADD] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_KP_ENTER] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_KP_EQUAL] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_LEFT_SHIFT] = KEY_LSHIFT;
|
||||||
|
keymap[GLFW_KEY_LEFT_CONTROL] = KEY_LCTRL;
|
||||||
|
keymap[GLFW_KEY_LEFT_ALT] = KEY_LALT;
|
||||||
|
keymap[GLFW_KEY_LEFT_SUPER] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_RIGHT_SHIFT] = KEY_RSHIFT;
|
||||||
|
keymap[GLFW_KEY_RIGHT_CONTROL] = KEY_RCTRL;
|
||||||
|
keymap[GLFW_KEY_RIGHT_ALT] = KEY_RALT;
|
||||||
|
keymap[GLFW_KEY_RIGHT_SUPER] = KEY_NULL;
|
||||||
|
keymap[GLFW_KEY_MENU] = KEY_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void KeyUp(int key) { EventHandler(KEYUP, &key); }
|
||||||
|
static void KeyDown(int key) { EventHandler(KEYDOWN, &key); }
|
||||||
|
|
||||||
|
static void
|
||||||
|
keypress(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||||
|
{
|
||||||
|
if(key >= 0 && key <= GLFW_KEY_LAST){
|
||||||
|
if(action == GLFW_RELEASE) KeyUp(keymap[key]);
|
||||||
|
else if(action == GLFW_PRESS) KeyDown(keymap[key]);
|
||||||
|
else if(action == GLFW_REPEAT) KeyDown(keymap[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
charinput(GLFWwindow *window, unsigned int c)
|
||||||
|
{
|
||||||
|
EventHandler(CHARINPUT, (void*)(uintptr)c);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
resize(GLFWwindow *window, int w, int h)
|
||||||
|
{
|
||||||
|
rw::Rect r;
|
||||||
|
r.x = 0;
|
||||||
|
r.y = 0;
|
||||||
|
r.w = w;
|
||||||
|
r.h = h;
|
||||||
|
EventHandler(RESIZE, &r);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mousemove(GLFWwindow *window, double x, double y)
|
||||||
|
{
|
||||||
|
sk::MouseState ms;
|
||||||
|
ms.posx = x;
|
||||||
|
ms.posy = y;
|
||||||
|
EventHandler(MOUSEMOVE, &ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mousebtn(GLFWwindow *window, int button, int action, int mods)
|
||||||
|
{
|
||||||
|
static int buttons = 0;
|
||||||
|
sk::MouseState ms;
|
||||||
|
|
||||||
|
switch(button){
|
||||||
|
case GLFW_MOUSE_BUTTON_LEFT:
|
||||||
|
if(action == GLFW_PRESS)
|
||||||
|
buttons |= 1;
|
||||||
|
else
|
||||||
|
buttons &= ~1;
|
||||||
|
break;
|
||||||
|
case GLFW_MOUSE_BUTTON_MIDDLE:
|
||||||
|
if(action == GLFW_PRESS)
|
||||||
|
buttons |= 2;
|
||||||
|
else
|
||||||
|
buttons &= ~2;
|
||||||
|
break;
|
||||||
|
case GLFW_MOUSE_BUTTON_RIGHT:
|
||||||
|
if(action == GLFW_PRESS)
|
||||||
|
buttons |= 4;
|
||||||
|
else
|
||||||
|
buttons &= ~4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ms.buttons = buttons;
|
||||||
|
EventHandler(MOUSEBTN, &ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
args.argc = argc;
|
||||||
|
args.argv = argv;
|
||||||
|
|
||||||
|
if(EventHandler(INITIALIZE, nil) == EVENTERROR)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
engineOpenParams.width = sk::globals.width;
|
||||||
|
engineOpenParams.height = sk::globals.height;
|
||||||
|
engineOpenParams.windowtitle = sk::globals.windowtitle;
|
||||||
|
engineOpenParams.window = &window;
|
||||||
|
|
||||||
|
if(EventHandler(RWINITIALIZE, nil) == EVENTERROR)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
initkeymap();
|
||||||
|
glfwSetKeyCallback(window, keypress);
|
||||||
|
glfwSetCharCallback(window, charinput);
|
||||||
|
glfwSetWindowSizeCallback(window, resize);
|
||||||
|
glfwSetCursorPosCallback(window, mousemove);
|
||||||
|
glfwSetMouseButtonCallback(window, mousebtn);
|
||||||
|
|
||||||
|
float lastTime = glfwGetTime()*1000;
|
||||||
|
while(!sk::globals.quit && !glfwWindowShouldClose(window)){
|
||||||
|
float currTime = glfwGetTime()*1000;
|
||||||
|
float timeDelta = (currTime - lastTime)*0.001f;
|
||||||
|
glfwPollEvents();
|
||||||
|
|
||||||
|
EventHandler(IDLE, &timeDelta);
|
||||||
|
|
||||||
|
lastTime = currTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
EventHandler(RWTERMINATE, nil);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace sk {
|
||||||
|
|
||||||
|
void
|
||||||
|
SetMousePosition(int x, int y)
|
||||||
|
{
|
||||||
|
glfwSetCursorPos(*engineOpenParams.window, (double)x, (double)y);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
2724
vendor/librw/skeleton/imgui/ImGuizmo.cpp
vendored
Normal file
2724
vendor/librw/skeleton/imgui/ImGuizmo.cpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
213
vendor/librw/skeleton/imgui/ImGuizmo.h
vendored
Normal file
213
vendor/librw/skeleton/imgui/ImGuizmo.h
vendored
Normal file
|
|
@ -0,0 +1,213 @@
|
||||||
|
// https://github.com/CedricGuillemet/ImGuizmo
|
||||||
|
// v 1.61 WIP
|
||||||
|
//
|
||||||
|
// The MIT License(MIT)
|
||||||
|
//
|
||||||
|
// Copyright(c) 2021 Cedric Guillemet
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files(the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions :
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
//
|
||||||
|
// -------------------------------------------------------------------------------------------
|
||||||
|
// History :
|
||||||
|
// 2019/11/03 View gizmo
|
||||||
|
// 2016/09/11 Behind camera culling. Scaling Delta matrix not multiplied by source matrix scales. local/world rotation and translation fixed. Display message is incorrect (X: ... Y:...) in local mode.
|
||||||
|
// 2016/09/09 Hatched negative axis. Snapping. Documentation update.
|
||||||
|
// 2016/09/04 Axis switch and translation plan autohiding. Scale transform stability improved
|
||||||
|
// 2016/09/01 Mogwai changed to Manipulate. Draw debug cube. Fixed inverted scale. Mixing scale and translation/rotation gives bad results.
|
||||||
|
// 2016/08/31 First version
|
||||||
|
//
|
||||||
|
// -------------------------------------------------------------------------------------------
|
||||||
|
// Future (no order):
|
||||||
|
//
|
||||||
|
// - Multi view
|
||||||
|
// - display rotation/translation/scale infos in local/world space and not only local
|
||||||
|
// - finish local/world matrix application
|
||||||
|
// - OPERATION as bitmask
|
||||||
|
//
|
||||||
|
// -------------------------------------------------------------------------------------------
|
||||||
|
// Example
|
||||||
|
#if 0
|
||||||
|
void EditTransform(const Camera& camera, matrix_t& matrix)
|
||||||
|
{
|
||||||
|
static ImGuizmo::OPERATION mCurrentGizmoOperation(ImGuizmo::ROTATE);
|
||||||
|
static ImGuizmo::MODE mCurrentGizmoMode(ImGuizmo::WORLD);
|
||||||
|
if (ImGui::IsKeyPressed(90))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
|
||||||
|
if (ImGui::IsKeyPressed(69))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::ROTATE;
|
||||||
|
if (ImGui::IsKeyPressed(82)) // r Key
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::SCALE;
|
||||||
|
if (ImGui::RadioButton("Translate", mCurrentGizmoOperation == ImGuizmo::TRANSLATE))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::RadioButton("Rotate", mCurrentGizmoOperation == ImGuizmo::ROTATE))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::ROTATE;
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::RadioButton("Scale", mCurrentGizmoOperation == ImGuizmo::SCALE))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::SCALE;
|
||||||
|
float matrixTranslation[3], matrixRotation[3], matrixScale[3];
|
||||||
|
ImGuizmo::DecomposeMatrixToComponents(matrix.m16, matrixTranslation, matrixRotation, matrixScale);
|
||||||
|
ImGui::InputFloat3("Tr", matrixTranslation, 3);
|
||||||
|
ImGui::InputFloat3("Rt", matrixRotation, 3);
|
||||||
|
ImGui::InputFloat3("Sc", matrixScale, 3);
|
||||||
|
ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, matrix.m16);
|
||||||
|
|
||||||
|
if (mCurrentGizmoOperation != ImGuizmo::SCALE)
|
||||||
|
{
|
||||||
|
if (ImGui::RadioButton("Local", mCurrentGizmoMode == ImGuizmo::LOCAL))
|
||||||
|
mCurrentGizmoMode = ImGuizmo::LOCAL;
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::RadioButton("World", mCurrentGizmoMode == ImGuizmo::WORLD))
|
||||||
|
mCurrentGizmoMode = ImGuizmo::WORLD;
|
||||||
|
}
|
||||||
|
static bool useSnap(false);
|
||||||
|
if (ImGui::IsKeyPressed(83))
|
||||||
|
useSnap = !useSnap;
|
||||||
|
ImGui::Checkbox("", &useSnap);
|
||||||
|
ImGui::SameLine();
|
||||||
|
vec_t snap;
|
||||||
|
switch (mCurrentGizmoOperation)
|
||||||
|
{
|
||||||
|
case ImGuizmo::TRANSLATE:
|
||||||
|
snap = config.mSnapTranslation;
|
||||||
|
ImGui::InputFloat3("Snap", &snap.x);
|
||||||
|
break;
|
||||||
|
case ImGuizmo::ROTATE:
|
||||||
|
snap = config.mSnapRotation;
|
||||||
|
ImGui::InputFloat("Angle Snap", &snap.x);
|
||||||
|
break;
|
||||||
|
case ImGuizmo::SCALE:
|
||||||
|
snap = config.mSnapScale;
|
||||||
|
ImGui::InputFloat("Scale Snap", &snap.x);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y);
|
||||||
|
ImGuizmo::Manipulate(camera.mView.m16, camera.mProjection.m16, mCurrentGizmoOperation, mCurrentGizmoMode, matrix.m16, NULL, useSnap ? &snap.x : NULL);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef USE_IMGUI_API
|
||||||
|
#include "imconfig.h"
|
||||||
|
#endif
|
||||||
|
#ifndef IMGUI_API
|
||||||
|
#define IMGUI_API
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace ImGuizmo
|
||||||
|
{
|
||||||
|
// call inside your own window and before Manipulate() in order to draw gizmo to that window.
|
||||||
|
// Or pass a specific ImDrawList to draw to (e.g. ImGui::GetForegroundDrawList()).
|
||||||
|
IMGUI_API void SetDrawlist(ImDrawList* drawlist = nullptr);
|
||||||
|
|
||||||
|
// call BeginFrame right after ImGui_XXXX_NewFrame();
|
||||||
|
IMGUI_API void BeginFrame();
|
||||||
|
|
||||||
|
// this is necessary because when imguizmo is compiled into a dll, and imgui into another
|
||||||
|
// globals are not shared between them.
|
||||||
|
// More details at https://stackoverflow.com/questions/19373061/what-happens-to-global-and-static-variables-in-a-shared-library-when-it-is-dynam
|
||||||
|
// expose method to set imgui context
|
||||||
|
IMGUI_API void SetImGuiContext(ImGuiContext* ctx);
|
||||||
|
|
||||||
|
// return true if mouse cursor is over any gizmo control (axis, plan or screen component)
|
||||||
|
IMGUI_API bool IsOver();
|
||||||
|
|
||||||
|
// return true if mouse IsOver or if the gizmo is in moving state
|
||||||
|
IMGUI_API bool IsUsing();
|
||||||
|
|
||||||
|
// enable/disable the gizmo. Stay in the state until next call to Enable.
|
||||||
|
// gizmo is rendered with gray half transparent color when disabled
|
||||||
|
IMGUI_API void Enable(bool enable);
|
||||||
|
|
||||||
|
// helper functions for manualy editing translation/rotation/scale with an input float
|
||||||
|
// translation, rotation and scale float points to 3 floats each
|
||||||
|
// Angles are in degrees (more suitable for human editing)
|
||||||
|
// example:
|
||||||
|
// float matrixTranslation[3], matrixRotation[3], matrixScale[3];
|
||||||
|
// ImGuizmo::DecomposeMatrixToComponents(gizmoMatrix.m16, matrixTranslation, matrixRotation, matrixScale);
|
||||||
|
// ImGui::InputFloat3("Tr", matrixTranslation, 3);
|
||||||
|
// ImGui::InputFloat3("Rt", matrixRotation, 3);
|
||||||
|
// ImGui::InputFloat3("Sc", matrixScale, 3);
|
||||||
|
// ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, gizmoMatrix.m16);
|
||||||
|
//
|
||||||
|
// These functions have some numerical stability issues for now. Use with caution.
|
||||||
|
IMGUI_API void DecomposeMatrixToComponents(const float* matrix, float* translation, float* rotation, float* scale);
|
||||||
|
IMGUI_API void RecomposeMatrixFromComponents(const float* translation, const float* rotation, const float* scale, float* matrix);
|
||||||
|
|
||||||
|
IMGUI_API void SetRect(float x, float y, float width, float height);
|
||||||
|
// default is false
|
||||||
|
IMGUI_API void SetOrthographic(bool isOrthographic);
|
||||||
|
|
||||||
|
// Render a cube with face color corresponding to face normal. Usefull for debug/tests
|
||||||
|
IMGUI_API void DrawCubes(const float* view, const float* projection, const float* matrices, int matrixCount);
|
||||||
|
IMGUI_API void DrawGrid(const float* view, const float* projection, const float* matrix, const float gridSize);
|
||||||
|
|
||||||
|
// call it when you want a gizmo
|
||||||
|
// Needs view and projection matrices.
|
||||||
|
// matrix parameter is the source matrix (where will be gizmo be drawn) and might be transformed by the function. Return deltaMatrix is optional
|
||||||
|
// translation is applied in world space
|
||||||
|
enum OPERATION
|
||||||
|
{
|
||||||
|
TRANSLATE_X = (1u << 0),
|
||||||
|
TRANSLATE_Y = (1u << 1),
|
||||||
|
TRANSLATE_Z = (1u << 2),
|
||||||
|
ROTATE_X = (1u << 3),
|
||||||
|
ROTATE_Y = (1u << 4),
|
||||||
|
ROTATE_Z = (1u << 5),
|
||||||
|
ROTATE_SCREEN = (1u << 6),
|
||||||
|
SCALE_X = (1u << 7),
|
||||||
|
SCALE_Y = (1u << 8),
|
||||||
|
SCALE_Z = (1u << 9),
|
||||||
|
BOUNDS = (1u << 10),
|
||||||
|
TRANSLATE = TRANSLATE_X | TRANSLATE_Y | TRANSLATE_Z,
|
||||||
|
ROTATE = ROTATE_X | ROTATE_Y | ROTATE_Z | ROTATE_SCREEN,
|
||||||
|
SCALE = SCALE_X | SCALE_Y | SCALE_Z
|
||||||
|
};
|
||||||
|
|
||||||
|
inline OPERATION operator|(OPERATION lhs, OPERATION rhs)
|
||||||
|
{
|
||||||
|
return static_cast<OPERATION>(static_cast<int>(lhs) | static_cast<int>(rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
enum MODE
|
||||||
|
{
|
||||||
|
LOCAL,
|
||||||
|
WORLD
|
||||||
|
};
|
||||||
|
|
||||||
|
IMGUI_API bool Manipulate(const float* view, const float* projection, OPERATION operation, MODE mode, float* matrix, float* deltaMatrix = NULL, const float* snap = NULL, const float* localBounds = NULL, const float* boundsSnap = NULL);
|
||||||
|
//
|
||||||
|
// Please note that this cubeview is patented by Autodesk : https://patents.google.com/patent/US7782319B2/en
|
||||||
|
// It seems to be a defensive patent in the US. I don't think it will bring troubles using it as
|
||||||
|
// other software are using the same mechanics. But just in case, you are now warned!
|
||||||
|
//
|
||||||
|
IMGUI_API void ViewManipulate(float* view, float length, ImVec2 position, ImVec2 size, ImU32 backgroundColor);
|
||||||
|
|
||||||
|
IMGUI_API void SetID(int id);
|
||||||
|
|
||||||
|
// return true if the cursor is over the operation's gizmo
|
||||||
|
IMGUI_API bool IsOver(OPERATION op);
|
||||||
|
IMGUI_API void SetGizmoSizeClipSpace(float value);
|
||||||
|
|
||||||
|
// Allow axis to flip
|
||||||
|
// When true (default), the guizmo axis flip for better visibility
|
||||||
|
// When false, they always stay along the positive world/local axis
|
||||||
|
IMGUI_API void AllowAxisFlip(bool value);
|
||||||
|
}
|
||||||
21
vendor/librw/skeleton/imgui/LICENSE_imgui.txt
vendored
Normal file
21
vendor/librw/skeleton/imgui/LICENSE_imgui.txt
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014-2021 Omar Cornut
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
21
vendor/librw/skeleton/imgui/LICENSE_imguizmo.txt
vendored
Normal file
21
vendor/librw/skeleton/imgui/LICENSE_imguizmo.txt
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2016 Cedric Guillemet
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
121
vendor/librw/skeleton/imgui/imconfig.h
vendored
Normal file
121
vendor/librw/skeleton/imgui/imconfig.h
vendored
Normal file
|
|
@ -0,0 +1,121 @@
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// COMPILE-TIME OPTIONS FOR DEAR IMGUI
|
||||||
|
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
|
||||||
|
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it)
|
||||||
|
// B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp
|
||||||
|
// files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
|
||||||
|
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
|
||||||
|
// Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
//---- Define assertion handler. Defaults to calling assert().
|
||||||
|
// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
|
||||||
|
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
|
||||||
|
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
|
||||||
|
|
||||||
|
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
|
||||||
|
// Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
|
||||||
|
// DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
|
||||||
|
// for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details.
|
||||||
|
//#define IMGUI_API __declspec( dllexport )
|
||||||
|
//#define IMGUI_API __declspec( dllimport )
|
||||||
|
|
||||||
|
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
|
||||||
|
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
|
|
||||||
|
//---- Disable all of Dear ImGui or don't implement standard windows.
|
||||||
|
// It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp.
|
||||||
|
//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
|
||||||
|
//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. Not recommended.
|
||||||
|
//#define IMGUI_DISABLE_METRICS_WINDOW // Disable metrics/debugger window: ShowMetricsWindow() will be empty.
|
||||||
|
|
||||||
|
//---- Don't implement some functions to reduce linkage requirements.
|
||||||
|
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a)
|
||||||
|
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow. (imm32.lib/.a)
|
||||||
|
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime).
|
||||||
|
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
|
||||||
|
//#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies)
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
|
||||||
|
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
|
||||||
|
|
||||||
|
//---- Include imgui_user.h at the end of imgui.h as a convenience
|
||||||
|
//#define IMGUI_INCLUDE_IMGUI_USER_H
|
||||||
|
|
||||||
|
//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
|
||||||
|
//#define IMGUI_USE_BGRA_PACKED_COLOR
|
||||||
|
|
||||||
|
//---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...)
|
||||||
|
//#define IMGUI_USE_WCHAR32
|
||||||
|
|
||||||
|
//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
|
||||||
|
// By default the embedded implementations are declared static and not available outside of Dear ImGui sources files.
|
||||||
|
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
|
||||||
|
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
|
||||||
|
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
|
||||||
|
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
|
||||||
|
|
||||||
|
//---- Use stb_printf's faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined)
|
||||||
|
// Requires 'stb_sprintf.h' to be available in the include path. Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by STB sprintf.
|
||||||
|
// #define IMGUI_USE_STB_SPRINTF
|
||||||
|
|
||||||
|
//---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui)
|
||||||
|
// Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided).
|
||||||
|
// On Windows you may use vcpkg with 'vcpkg install freetype' + 'vcpkg integrate install'.
|
||||||
|
//#define IMGUI_ENABLE_FREETYPE
|
||||||
|
|
||||||
|
//---- Use stb_truetype to build and rasterize the font atlas (default)
|
||||||
|
// The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend.
|
||||||
|
//#define IMGUI_ENABLE_STB_TRUETYPE
|
||||||
|
|
||||||
|
//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
|
||||||
|
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
|
||||||
|
/*
|
||||||
|
#define IM_VEC2_CLASS_EXTRA \
|
||||||
|
ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
|
||||||
|
operator MyVec2() const { return MyVec2(x,y); }
|
||||||
|
|
||||||
|
#define IM_VEC4_CLASS_EXTRA \
|
||||||
|
ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
|
||||||
|
operator MyVec4() const { return MyVec4(x,y,z,w); }
|
||||||
|
*/
|
||||||
|
|
||||||
|
//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
|
||||||
|
// Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).
|
||||||
|
// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer.
|
||||||
|
// Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
|
||||||
|
//#define ImDrawIdx unsigned int
|
||||||
|
|
||||||
|
//---- Override ImDrawCallback signature (will need to modify renderer backends accordingly)
|
||||||
|
//struct ImDrawList;
|
||||||
|
//struct ImDrawCmd;
|
||||||
|
//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
|
||||||
|
//#define ImDrawCallback MyImDrawCallback
|
||||||
|
|
||||||
|
//---- Debug Tools: Macro to break in Debugger
|
||||||
|
// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.)
|
||||||
|
//#define IM_DEBUG_BREAK IM_ASSERT(0)
|
||||||
|
//#define IM_DEBUG_BREAK __debugbreak()
|
||||||
|
|
||||||
|
//---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(),
|
||||||
|
// (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.)
|
||||||
|
// This adds a small runtime cost which is why it is not enabled by default.
|
||||||
|
//#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX
|
||||||
|
|
||||||
|
//---- Debug Tools: Enable slower asserts
|
||||||
|
//#define IMGUI_DEBUG_PARANOID
|
||||||
|
|
||||||
|
//---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
|
||||||
|
/*
|
||||||
|
namespace ImGui
|
||||||
|
{
|
||||||
|
void MyFunction(const char* name, const MyMatrix44& v);
|
||||||
|
}
|
||||||
|
*/
|
||||||
11589
vendor/librw/skeleton/imgui/imgui.cpp
vendored
Normal file
11589
vendor/librw/skeleton/imgui/imgui.cpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
2852
vendor/librw/skeleton/imgui/imgui.h
vendored
Normal file
2852
vendor/librw/skeleton/imgui/imgui.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
7725
vendor/librw/skeleton/imgui/imgui_demo.cpp
vendored
Normal file
7725
vendor/librw/skeleton/imgui/imgui_demo.cpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
4152
vendor/librw/skeleton/imgui/imgui_draw.cpp
vendored
Normal file
4152
vendor/librw/skeleton/imgui/imgui_draw.cpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
240
vendor/librw/skeleton/imgui/imgui_impl_rw.cpp
vendored
Normal file
240
vendor/librw/skeleton/imgui/imgui_impl_rw.cpp
vendored
Normal file
|
|
@ -0,0 +1,240 @@
|
||||||
|
#include <rw.h>
|
||||||
|
#include <skeleton.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "imgui/imgui.h"
|
||||||
|
#include "imgui_impl_rw.h"
|
||||||
|
|
||||||
|
using namespace rw::RWDEVICE;
|
||||||
|
|
||||||
|
static rw::Texture *g_FontTexture;
|
||||||
|
static Im2DVertex *g_vertbuf;
|
||||||
|
static int g_vertbufSize;
|
||||||
|
|
||||||
|
void
|
||||||
|
ImGui_ImplRW_RenderDrawLists(ImDrawData* draw_data)
|
||||||
|
{
|
||||||
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
|
|
||||||
|
// minimized
|
||||||
|
if (io.DisplaySize.x <= 0.0f || io.DisplaySize.y <= 0.0f)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(g_vertbuf == nil || g_vertbufSize < draw_data->TotalVtxCount){
|
||||||
|
if(g_vertbuf){
|
||||||
|
rwFree(g_vertbuf);
|
||||||
|
g_vertbuf = nil;
|
||||||
|
}
|
||||||
|
g_vertbufSize = draw_data->TotalVtxCount + 5000;
|
||||||
|
g_vertbuf = rwNewT(Im2DVertex, g_vertbufSize, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
float xoff = 0.0f;
|
||||||
|
float yoff = 0.0f;
|
||||||
|
#ifdef RWHALFPIXEL
|
||||||
|
xoff = -0.5;
|
||||||
|
yoff = 0.5;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
rw::Camera *cam = (rw::Camera*)rw::engine->currentCamera;
|
||||||
|
Im2DVertex *vtx_dst = g_vertbuf;
|
||||||
|
float recipZ = 1.0f/cam->nearPlane;
|
||||||
|
for(int n = 0; n < draw_data->CmdListsCount; n++){
|
||||||
|
const ImDrawList *cmd_list = draw_data->CmdLists[n];
|
||||||
|
const ImDrawVert *vtx_src = cmd_list->VtxBuffer.Data;
|
||||||
|
for(int i = 0; i < cmd_list->VtxBuffer.Size; i++){
|
||||||
|
vtx_dst[i].setScreenX(vtx_src[i].pos.x + xoff);
|
||||||
|
vtx_dst[i].setScreenY(vtx_src[i].pos.y + yoff);
|
||||||
|
vtx_dst[i].setScreenZ(rw::im2d::GetNearZ());
|
||||||
|
vtx_dst[i].setCameraZ(cam->nearPlane);
|
||||||
|
vtx_dst[i].setRecipCameraZ(recipZ);
|
||||||
|
vtx_dst[i].setColor(vtx_src[i].col&0xFF, vtx_src[i].col>>8 & 0xFF, vtx_src[i].col>>16 & 0xFF, vtx_src[i].col>>24 & 0xFF);
|
||||||
|
vtx_dst[i].setU(vtx_src[i].uv.x, recipZ);
|
||||||
|
vtx_dst[i].setV(vtx_src[i].uv.y, recipZ);
|
||||||
|
}
|
||||||
|
vtx_dst += cmd_list->VtxBuffer.Size;
|
||||||
|
}
|
||||||
|
|
||||||
|
int vertexAlpha = rw::GetRenderState(rw::VERTEXALPHA);
|
||||||
|
int srcBlend = rw::GetRenderState(rw::SRCBLEND);
|
||||||
|
int dstBlend = rw::GetRenderState(rw::DESTBLEND);
|
||||||
|
int ztest = rw::GetRenderState(rw::ZTESTENABLE);
|
||||||
|
void *tex = rw::GetRenderStatePtr(rw::TEXTURERASTER);
|
||||||
|
int addrU = rw::GetRenderState(rw::TEXTUREADDRESSU);
|
||||||
|
int addrV = rw::GetRenderState(rw::TEXTUREADDRESSV);
|
||||||
|
int filter = rw::GetRenderState(rw::TEXTUREFILTER);
|
||||||
|
int cullmode = rw::GetRenderState(rw::CULLMODE);
|
||||||
|
|
||||||
|
rw::SetRenderState(rw::VERTEXALPHA, 1);
|
||||||
|
rw::SetRenderState(rw::SRCBLEND, rw::BLENDSRCALPHA);
|
||||||
|
rw::SetRenderState(rw::DESTBLEND, rw::BLENDINVSRCALPHA);
|
||||||
|
rw::SetRenderState(rw::ZTESTENABLE, 0);
|
||||||
|
rw::SetRenderState(rw::CULLMODE, rw::CULLNONE);
|
||||||
|
|
||||||
|
int vtx_offset = 0;
|
||||||
|
for(int n = 0; n < draw_data->CmdListsCount; n++){
|
||||||
|
const ImDrawList *cmd_list = draw_data->CmdLists[n];
|
||||||
|
int idx_offset = 0;
|
||||||
|
for(int i = 0; i < cmd_list->CmdBuffer.Size; i++){
|
||||||
|
const ImDrawCmd *pcmd = &cmd_list->CmdBuffer[i];
|
||||||
|
if(pcmd->UserCallback)
|
||||||
|
pcmd->UserCallback(cmd_list, pcmd);
|
||||||
|
else{
|
||||||
|
rw::Texture *tex = (rw::Texture*)pcmd->TextureId;
|
||||||
|
if(tex && tex->raster){
|
||||||
|
rw::SetRenderStatePtr(rw::TEXTURERASTER, tex->raster);
|
||||||
|
rw::SetRenderState(rw::TEXTUREADDRESSU, tex->getAddressU());
|
||||||
|
rw::SetRenderState(rw::TEXTUREADDRESSV, tex->getAddressV());
|
||||||
|
rw::SetRenderState(rw::TEXTUREFILTER, tex->getFilter());
|
||||||
|
}else
|
||||||
|
rw::SetRenderStatePtr(rw::TEXTURERASTER, nil);
|
||||||
|
rw::im2d::RenderIndexedPrimitive(rw::PRIMTYPETRILIST,
|
||||||
|
g_vertbuf+vtx_offset, cmd_list->VtxBuffer.Size,
|
||||||
|
cmd_list->IdxBuffer.Data+idx_offset, pcmd->ElemCount);
|
||||||
|
}
|
||||||
|
idx_offset += pcmd->ElemCount;
|
||||||
|
}
|
||||||
|
vtx_offset += cmd_list->VtxBuffer.Size;
|
||||||
|
}
|
||||||
|
|
||||||
|
rw::SetRenderState(rw::VERTEXALPHA,vertexAlpha);
|
||||||
|
rw::SetRenderState(rw::SRCBLEND, srcBlend);
|
||||||
|
rw::SetRenderState(rw::DESTBLEND, dstBlend);
|
||||||
|
rw::SetRenderState(rw::ZTESTENABLE, ztest);
|
||||||
|
rw::SetRenderStatePtr(rw::TEXTURERASTER, tex);
|
||||||
|
rw::SetRenderState(rw::TEXTUREADDRESSU, addrU);
|
||||||
|
rw::SetRenderState(rw::TEXTUREADDRESSV, addrV);
|
||||||
|
rw::SetRenderState(rw::TEXTUREFILTER, filter);
|
||||||
|
rw::SetRenderState(rw::CULLMODE, cullmode);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ImGui_ImplRW_Init(void)
|
||||||
|
{
|
||||||
|
using namespace sk;
|
||||||
|
|
||||||
|
ImGui::CreateContext();
|
||||||
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
|
|
||||||
|
io.KeyMap[ImGuiKey_Tab] = KEY_TAB;
|
||||||
|
io.KeyMap[ImGuiKey_LeftArrow] = KEY_LEFT;
|
||||||
|
io.KeyMap[ImGuiKey_RightArrow] = KEY_RIGHT;
|
||||||
|
io.KeyMap[ImGuiKey_UpArrow] = KEY_UP;
|
||||||
|
io.KeyMap[ImGuiKey_DownArrow] = KEY_DOWN;
|
||||||
|
io.KeyMap[ImGuiKey_PageUp] = KEY_PGUP;
|
||||||
|
io.KeyMap[ImGuiKey_PageDown] = KEY_PGDN;
|
||||||
|
io.KeyMap[ImGuiKey_Home] = KEY_HOME;
|
||||||
|
io.KeyMap[ImGuiKey_End] = KEY_END;
|
||||||
|
io.KeyMap[ImGuiKey_Delete] = KEY_DEL;
|
||||||
|
io.KeyMap[ImGuiKey_Backspace] = KEY_BACKSP;
|
||||||
|
io.KeyMap[ImGuiKey_Enter] = KEY_ENTER;
|
||||||
|
io.KeyMap[ImGuiKey_Escape] = KEY_ESC;
|
||||||
|
io.KeyMap[ImGuiKey_A] = 'A';
|
||||||
|
io.KeyMap[ImGuiKey_C] = 'C';
|
||||||
|
io.KeyMap[ImGuiKey_V] = 'V';
|
||||||
|
io.KeyMap[ImGuiKey_X] = 'X';
|
||||||
|
io.KeyMap[ImGuiKey_Y] = 'Y';
|
||||||
|
io.KeyMap[ImGuiKey_Z] = 'Z';
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ImGui_ImplRW_Shutdown(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
ImGui_ImplRW_CreateFontsTexture()
|
||||||
|
{
|
||||||
|
// Build texture atlas
|
||||||
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
|
unsigned char *pixels;
|
||||||
|
int width, height;
|
||||||
|
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height, nil);
|
||||||
|
|
||||||
|
rw::Image *image;
|
||||||
|
image = rw::Image::create(width, height, 32);
|
||||||
|
image->allocate();
|
||||||
|
for(int y = 0; y < height; y++)
|
||||||
|
memcpy(image->pixels + image->stride*y, pixels + width*4* y, width*4);
|
||||||
|
g_FontTexture = rw::Texture::create(rw::Raster::createFromImage(image));
|
||||||
|
g_FontTexture->setFilter(rw::Texture::LINEAR);
|
||||||
|
image->destroy();
|
||||||
|
|
||||||
|
// Store our identifier
|
||||||
|
io.Fonts->TexID = (void*)g_FontTexture;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ImGui_ImplRW_CreateDeviceObjects()
|
||||||
|
{
|
||||||
|
// if(!g_pd3dDevice)
|
||||||
|
// return false;
|
||||||
|
if(!ImGui_ImplRW_CreateFontsTexture())
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ImGui_ImplRW_NewFrame(float timeDelta)
|
||||||
|
{
|
||||||
|
if(!g_FontTexture)
|
||||||
|
ImGui_ImplRW_CreateDeviceObjects();
|
||||||
|
|
||||||
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
|
|
||||||
|
io.DisplaySize = ImVec2(sk::globals.width, sk::globals.height);
|
||||||
|
io.DeltaTime = timeDelta;
|
||||||
|
|
||||||
|
io.KeyCtrl = io.KeysDown[sk::KEY_LCTRL] || io.KeysDown[sk::KEY_RCTRL];
|
||||||
|
io.KeyShift = io.KeysDown[sk::KEY_LSHIFT] || io.KeysDown[sk::KEY_RSHIFT];
|
||||||
|
io.KeyAlt = io.KeysDown[sk::KEY_LALT] || io.KeysDown[sk::KEY_RALT];
|
||||||
|
io.KeySuper = false;
|
||||||
|
|
||||||
|
if(io.WantSetMousePos)
|
||||||
|
sk::SetMousePosition(io.MousePos.x, io.MousePos.y);
|
||||||
|
|
||||||
|
ImGui::NewFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
sk::EventStatus
|
||||||
|
ImGuiEventHandler(sk::Event e, void *param)
|
||||||
|
{
|
||||||
|
using namespace sk;
|
||||||
|
|
||||||
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
|
MouseState *ms;
|
||||||
|
uint c;
|
||||||
|
|
||||||
|
switch(e){
|
||||||
|
case KEYDOWN:
|
||||||
|
c = *(int*)param;
|
||||||
|
if(c < 256)
|
||||||
|
io.KeysDown[c] = 1;
|
||||||
|
return EVENTPROCESSED;
|
||||||
|
case KEYUP:
|
||||||
|
c = *(int*)param;
|
||||||
|
if(c < 256)
|
||||||
|
io.KeysDown[c] = 0;
|
||||||
|
return EVENTPROCESSED;
|
||||||
|
case CHARINPUT:
|
||||||
|
c = (uint)(uintptr)param;
|
||||||
|
io.AddInputCharacter((unsigned short)c);
|
||||||
|
return EVENTPROCESSED;
|
||||||
|
case MOUSEMOVE:
|
||||||
|
ms = (MouseState*)param;
|
||||||
|
io.MousePos.x = ms->posx;
|
||||||
|
io.MousePos.y = ms->posy;
|
||||||
|
return EVENTPROCESSED;
|
||||||
|
case MOUSEBTN:
|
||||||
|
ms = (MouseState*)param;
|
||||||
|
io.MouseDown[0] = !!(ms->buttons & 1);
|
||||||
|
io.MouseDown[2] = !!(ms->buttons & 2);
|
||||||
|
io.MouseDown[1] = !!(ms->buttons & 4);
|
||||||
|
return EVENTPROCESSED;
|
||||||
|
}
|
||||||
|
return EVENTPROCESSED;
|
||||||
|
}
|
||||||
5
vendor/librw/skeleton/imgui/imgui_impl_rw.h
vendored
Normal file
5
vendor/librw/skeleton/imgui/imgui_impl_rw.h
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
IMGUI_API bool ImGui_ImplRW_Init(void);
|
||||||
|
IMGUI_API void ImGui_ImplRW_Shutdown(void);
|
||||||
|
IMGUI_API void ImGui_ImplRW_NewFrame(float timeDelta);
|
||||||
|
sk::EventStatus ImGuiEventHandler(sk::Event e, void *param);
|
||||||
|
void ImGui_ImplRW_RenderDrawLists(ImDrawData* draw_data);
|
||||||
2688
vendor/librw/skeleton/imgui/imgui_internal.h
vendored
Normal file
2688
vendor/librw/skeleton/imgui/imgui_internal.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
4028
vendor/librw/skeleton/imgui/imgui_tables.cpp
vendored
Normal file
4028
vendor/librw/skeleton/imgui/imgui_tables.cpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
8056
vendor/librw/skeleton/imgui/imgui_widgets.cpp
vendored
Normal file
8056
vendor/librw/skeleton/imgui/imgui_widgets.cpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
639
vendor/librw/skeleton/imgui/imstb_rectpack.h
vendored
Normal file
639
vendor/librw/skeleton/imgui/imstb_rectpack.h
vendored
Normal file
|
|
@ -0,0 +1,639 @@
|
||||||
|
// [DEAR IMGUI]
|
||||||
|
// This is a slightly modified version of stb_rect_pack.h 1.00.
|
||||||
|
// Those changes would need to be pushed into nothings/stb:
|
||||||
|
// - Added STBRP__CDECL
|
||||||
|
// Grep for [DEAR IMGUI] to find the changes.
|
||||||
|
|
||||||
|
// stb_rect_pack.h - v1.00 - public domain - rectangle packing
|
||||||
|
// Sean Barrett 2014
|
||||||
|
//
|
||||||
|
// Useful for e.g. packing rectangular textures into an atlas.
|
||||||
|
// Does not do rotation.
|
||||||
|
//
|
||||||
|
// Not necessarily the awesomest packing method, but better than
|
||||||
|
// the totally naive one in stb_truetype (which is primarily what
|
||||||
|
// this is meant to replace).
|
||||||
|
//
|
||||||
|
// Has only had a few tests run, may have issues.
|
||||||
|
//
|
||||||
|
// More docs to come.
|
||||||
|
//
|
||||||
|
// No memory allocations; uses qsort() and assert() from stdlib.
|
||||||
|
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
|
||||||
|
//
|
||||||
|
// This library currently uses the Skyline Bottom-Left algorithm.
|
||||||
|
//
|
||||||
|
// Please note: better rectangle packers are welcome! Please
|
||||||
|
// implement them to the same API, but with a different init
|
||||||
|
// function.
|
||||||
|
//
|
||||||
|
// Credits
|
||||||
|
//
|
||||||
|
// Library
|
||||||
|
// Sean Barrett
|
||||||
|
// Minor features
|
||||||
|
// Martins Mozeiko
|
||||||
|
// github:IntellectualKitty
|
||||||
|
//
|
||||||
|
// Bugfixes / warning fixes
|
||||||
|
// Jeremy Jaussaud
|
||||||
|
// Fabian Giesen
|
||||||
|
//
|
||||||
|
// Version history:
|
||||||
|
//
|
||||||
|
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
|
||||||
|
// 0.99 (2019-02-07) warning fixes
|
||||||
|
// 0.11 (2017-03-03) return packing success/fail result
|
||||||
|
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
|
||||||
|
// 0.09 (2016-08-27) fix compiler warnings
|
||||||
|
// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
|
||||||
|
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
|
||||||
|
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
|
||||||
|
// 0.05: added STBRP_ASSERT to allow replacing assert
|
||||||
|
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
|
||||||
|
// 0.01: initial release
|
||||||
|
//
|
||||||
|
// LICENSE
|
||||||
|
//
|
||||||
|
// See end of file for license information.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// INCLUDE SECTION
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef STB_INCLUDE_STB_RECT_PACK_H
|
||||||
|
#define STB_INCLUDE_STB_RECT_PACK_H
|
||||||
|
|
||||||
|
#define STB_RECT_PACK_VERSION 1
|
||||||
|
|
||||||
|
#ifdef STBRP_STATIC
|
||||||
|
#define STBRP_DEF static
|
||||||
|
#else
|
||||||
|
#define STBRP_DEF extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct stbrp_context stbrp_context;
|
||||||
|
typedef struct stbrp_node stbrp_node;
|
||||||
|
typedef struct stbrp_rect stbrp_rect;
|
||||||
|
|
||||||
|
#ifdef STBRP_LARGE_RECTS
|
||||||
|
typedef int stbrp_coord;
|
||||||
|
#else
|
||||||
|
typedef unsigned short stbrp_coord;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
|
||||||
|
// Assign packed locations to rectangles. The rectangles are of type
|
||||||
|
// 'stbrp_rect' defined below, stored in the array 'rects', and there
|
||||||
|
// are 'num_rects' many of them.
|
||||||
|
//
|
||||||
|
// Rectangles which are successfully packed have the 'was_packed' flag
|
||||||
|
// set to a non-zero value and 'x' and 'y' store the minimum location
|
||||||
|
// on each axis (i.e. bottom-left in cartesian coordinates, top-left
|
||||||
|
// if you imagine y increasing downwards). Rectangles which do not fit
|
||||||
|
// have the 'was_packed' flag set to 0.
|
||||||
|
//
|
||||||
|
// You should not try to access the 'rects' array from another thread
|
||||||
|
// while this function is running, as the function temporarily reorders
|
||||||
|
// the array while it executes.
|
||||||
|
//
|
||||||
|
// To pack into another rectangle, you need to call stbrp_init_target
|
||||||
|
// again. To continue packing into the same rectangle, you can call
|
||||||
|
// this function again. Calling this multiple times with multiple rect
|
||||||
|
// arrays will probably produce worse packing results than calling it
|
||||||
|
// a single time with the full rectangle array, but the option is
|
||||||
|
// available.
|
||||||
|
//
|
||||||
|
// The function returns 1 if all of the rectangles were successfully
|
||||||
|
// packed and 0 otherwise.
|
||||||
|
|
||||||
|
struct stbrp_rect
|
||||||
|
{
|
||||||
|
// reserved for your use:
|
||||||
|
int id;
|
||||||
|
|
||||||
|
// input:
|
||||||
|
stbrp_coord w, h;
|
||||||
|
|
||||||
|
// output:
|
||||||
|
stbrp_coord x, y;
|
||||||
|
int was_packed; // non-zero if valid packing
|
||||||
|
|
||||||
|
}; // 16 bytes, nominally
|
||||||
|
|
||||||
|
|
||||||
|
STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
|
||||||
|
// Initialize a rectangle packer to:
|
||||||
|
// pack a rectangle that is 'width' by 'height' in dimensions
|
||||||
|
// using temporary storage provided by the array 'nodes', which is 'num_nodes' long
|
||||||
|
//
|
||||||
|
// You must call this function every time you start packing into a new target.
|
||||||
|
//
|
||||||
|
// There is no "shutdown" function. The 'nodes' memory must stay valid for
|
||||||
|
// the following stbrp_pack_rects() call (or calls), but can be freed after
|
||||||
|
// the call (or calls) finish.
|
||||||
|
//
|
||||||
|
// Note: to guarantee best results, either:
|
||||||
|
// 1. make sure 'num_nodes' >= 'width'
|
||||||
|
// or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
|
||||||
|
//
|
||||||
|
// If you don't do either of the above things, widths will be quantized to multiples
|
||||||
|
// of small integers to guarantee the algorithm doesn't run out of temporary storage.
|
||||||
|
//
|
||||||
|
// If you do #2, then the non-quantized algorithm will be used, but the algorithm
|
||||||
|
// may run out of temporary storage and be unable to pack some rectangles.
|
||||||
|
|
||||||
|
STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
|
||||||
|
// Optionally call this function after init but before doing any packing to
|
||||||
|
// change the handling of the out-of-temp-memory scenario, described above.
|
||||||
|
// If you call init again, this will be reset to the default (false).
|
||||||
|
|
||||||
|
|
||||||
|
STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
|
||||||
|
// Optionally select which packing heuristic the library should use. Different
|
||||||
|
// heuristics will produce better/worse results for different data sets.
|
||||||
|
// If you call init again, this will be reset to the default.
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
STBRP_HEURISTIC_Skyline_default=0,
|
||||||
|
STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
|
||||||
|
STBRP_HEURISTIC_Skyline_BF_sortHeight
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// the details of the following structures don't matter to you, but they must
|
||||||
|
// be visible so you can handle the memory allocations for them
|
||||||
|
|
||||||
|
struct stbrp_node
|
||||||
|
{
|
||||||
|
stbrp_coord x,y;
|
||||||
|
stbrp_node *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct stbrp_context
|
||||||
|
{
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
int align;
|
||||||
|
int init_mode;
|
||||||
|
int heuristic;
|
||||||
|
int num_nodes;
|
||||||
|
stbrp_node *active_head;
|
||||||
|
stbrp_node *free_head;
|
||||||
|
stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// IMPLEMENTATION SECTION
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifdef STB_RECT_PACK_IMPLEMENTATION
|
||||||
|
#ifndef STBRP_SORT
|
||||||
|
#include <stdlib.h>
|
||||||
|
#define STBRP_SORT qsort
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef STBRP_ASSERT
|
||||||
|
#include <assert.h>
|
||||||
|
#define STBRP_ASSERT assert
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// [DEAR IMGUI] Added STBRP__CDECL
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define STBRP__NOTUSED(v) (void)(v)
|
||||||
|
#define STBRP__CDECL __cdecl
|
||||||
|
#else
|
||||||
|
#define STBRP__NOTUSED(v) (void)sizeof(v)
|
||||||
|
#define STBRP__CDECL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
STBRP__INIT_skyline = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
|
||||||
|
{
|
||||||
|
switch (context->init_mode) {
|
||||||
|
case STBRP__INIT_skyline:
|
||||||
|
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
|
||||||
|
context->heuristic = heuristic;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
STBRP_ASSERT(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
|
||||||
|
{
|
||||||
|
if (allow_out_of_mem)
|
||||||
|
// if it's ok to run out of memory, then don't bother aligning them;
|
||||||
|
// this gives better packing, but may fail due to OOM (even though
|
||||||
|
// the rectangles easily fit). @TODO a smarter approach would be to only
|
||||||
|
// quantize once we've hit OOM, then we could get rid of this parameter.
|
||||||
|
context->align = 1;
|
||||||
|
else {
|
||||||
|
// if it's not ok to run out of memory, then quantize the widths
|
||||||
|
// so that num_nodes is always enough nodes.
|
||||||
|
//
|
||||||
|
// I.e. num_nodes * align >= width
|
||||||
|
// align >= width / num_nodes
|
||||||
|
// align = ceil(width/num_nodes)
|
||||||
|
|
||||||
|
context->align = (context->width + context->num_nodes-1) / context->num_nodes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
#ifndef STBRP_LARGE_RECTS
|
||||||
|
STBRP_ASSERT(width <= 0xffff && height <= 0xffff);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (i=0; i < num_nodes-1; ++i)
|
||||||
|
nodes[i].next = &nodes[i+1];
|
||||||
|
nodes[i].next = NULL;
|
||||||
|
context->init_mode = STBRP__INIT_skyline;
|
||||||
|
context->heuristic = STBRP_HEURISTIC_Skyline_default;
|
||||||
|
context->free_head = &nodes[0];
|
||||||
|
context->active_head = &context->extra[0];
|
||||||
|
context->width = width;
|
||||||
|
context->height = height;
|
||||||
|
context->num_nodes = num_nodes;
|
||||||
|
stbrp_setup_allow_out_of_mem(context, 0);
|
||||||
|
|
||||||
|
// node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
|
||||||
|
context->extra[0].x = 0;
|
||||||
|
context->extra[0].y = 0;
|
||||||
|
context->extra[0].next = &context->extra[1];
|
||||||
|
context->extra[1].x = (stbrp_coord) width;
|
||||||
|
#ifdef STBRP_LARGE_RECTS
|
||||||
|
context->extra[1].y = (1<<30);
|
||||||
|
#else
|
||||||
|
context->extra[1].y = 65535;
|
||||||
|
#endif
|
||||||
|
context->extra[1].next = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// find minimum y position if it starts at x1
|
||||||
|
static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
|
||||||
|
{
|
||||||
|
stbrp_node *node = first;
|
||||||
|
int x1 = x0 + width;
|
||||||
|
int min_y, visited_width, waste_area;
|
||||||
|
|
||||||
|
STBRP__NOTUSED(c);
|
||||||
|
|
||||||
|
STBRP_ASSERT(first->x <= x0);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// skip in case we're past the node
|
||||||
|
while (node->next->x <= x0)
|
||||||
|
++node;
|
||||||
|
#else
|
||||||
|
STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
|
||||||
|
#endif
|
||||||
|
|
||||||
|
STBRP_ASSERT(node->x <= x0);
|
||||||
|
|
||||||
|
min_y = 0;
|
||||||
|
waste_area = 0;
|
||||||
|
visited_width = 0;
|
||||||
|
while (node->x < x1) {
|
||||||
|
if (node->y > min_y) {
|
||||||
|
// raise min_y higher.
|
||||||
|
// we've accounted for all waste up to min_y,
|
||||||
|
// but we'll now add more waste for everything we've visted
|
||||||
|
waste_area += visited_width * (node->y - min_y);
|
||||||
|
min_y = node->y;
|
||||||
|
// the first time through, visited_width might be reduced
|
||||||
|
if (node->x < x0)
|
||||||
|
visited_width += node->next->x - x0;
|
||||||
|
else
|
||||||
|
visited_width += node->next->x - node->x;
|
||||||
|
} else {
|
||||||
|
// add waste area
|
||||||
|
int under_width = node->next->x - node->x;
|
||||||
|
if (under_width + visited_width > width)
|
||||||
|
under_width = width - visited_width;
|
||||||
|
waste_area += under_width * (min_y - node->y);
|
||||||
|
visited_width += under_width;
|
||||||
|
}
|
||||||
|
node = node->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
*pwaste = waste_area;
|
||||||
|
return min_y;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int x,y;
|
||||||
|
stbrp_node **prev_link;
|
||||||
|
} stbrp__findresult;
|
||||||
|
|
||||||
|
static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
|
||||||
|
{
|
||||||
|
int best_waste = (1<<30), best_x, best_y = (1 << 30);
|
||||||
|
stbrp__findresult fr;
|
||||||
|
stbrp_node **prev, *node, *tail, **best = NULL;
|
||||||
|
|
||||||
|
// align to multiple of c->align
|
||||||
|
width = (width + c->align - 1);
|
||||||
|
width -= width % c->align;
|
||||||
|
STBRP_ASSERT(width % c->align == 0);
|
||||||
|
|
||||||
|
// if it can't possibly fit, bail immediately
|
||||||
|
if (width > c->width || height > c->height) {
|
||||||
|
fr.prev_link = NULL;
|
||||||
|
fr.x = fr.y = 0;
|
||||||
|
return fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
node = c->active_head;
|
||||||
|
prev = &c->active_head;
|
||||||
|
while (node->x + width <= c->width) {
|
||||||
|
int y,waste;
|
||||||
|
y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
|
||||||
|
if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
|
||||||
|
// bottom left
|
||||||
|
if (y < best_y) {
|
||||||
|
best_y = y;
|
||||||
|
best = prev;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// best-fit
|
||||||
|
if (y + height <= c->height) {
|
||||||
|
// can only use it if it first vertically
|
||||||
|
if (y < best_y || (y == best_y && waste < best_waste)) {
|
||||||
|
best_y = y;
|
||||||
|
best_waste = waste;
|
||||||
|
best = prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prev = &node->next;
|
||||||
|
node = node->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
best_x = (best == NULL) ? 0 : (*best)->x;
|
||||||
|
|
||||||
|
// if doing best-fit (BF), we also have to try aligning right edge to each node position
|
||||||
|
//
|
||||||
|
// e.g, if fitting
|
||||||
|
//
|
||||||
|
// ____________________
|
||||||
|
// |____________________|
|
||||||
|
//
|
||||||
|
// into
|
||||||
|
//
|
||||||
|
// | |
|
||||||
|
// | ____________|
|
||||||
|
// |____________|
|
||||||
|
//
|
||||||
|
// then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
|
||||||
|
//
|
||||||
|
// This makes BF take about 2x the time
|
||||||
|
|
||||||
|
if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
|
||||||
|
tail = c->active_head;
|
||||||
|
node = c->active_head;
|
||||||
|
prev = &c->active_head;
|
||||||
|
// find first node that's admissible
|
||||||
|
while (tail->x < width)
|
||||||
|
tail = tail->next;
|
||||||
|
while (tail) {
|
||||||
|
int xpos = tail->x - width;
|
||||||
|
int y,waste;
|
||||||
|
STBRP_ASSERT(xpos >= 0);
|
||||||
|
// find the left position that matches this
|
||||||
|
while (node->next->x <= xpos) {
|
||||||
|
prev = &node->next;
|
||||||
|
node = node->next;
|
||||||
|
}
|
||||||
|
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
|
||||||
|
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
|
||||||
|
if (y + height <= c->height) {
|
||||||
|
if (y <= best_y) {
|
||||||
|
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
|
||||||
|
best_x = xpos;
|
||||||
|
STBRP_ASSERT(y <= best_y);
|
||||||
|
best_y = y;
|
||||||
|
best_waste = waste;
|
||||||
|
best = prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tail = tail->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fr.prev_link = best;
|
||||||
|
fr.x = best_x;
|
||||||
|
fr.y = best_y;
|
||||||
|
return fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
|
||||||
|
{
|
||||||
|
// find best position according to heuristic
|
||||||
|
stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
|
||||||
|
stbrp_node *node, *cur;
|
||||||
|
|
||||||
|
// bail if:
|
||||||
|
// 1. it failed
|
||||||
|
// 2. the best node doesn't fit (we don't always check this)
|
||||||
|
// 3. we're out of memory
|
||||||
|
if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
|
||||||
|
res.prev_link = NULL;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
// on success, create new node
|
||||||
|
node = context->free_head;
|
||||||
|
node->x = (stbrp_coord) res.x;
|
||||||
|
node->y = (stbrp_coord) (res.y + height);
|
||||||
|
|
||||||
|
context->free_head = node->next;
|
||||||
|
|
||||||
|
// insert the new node into the right starting point, and
|
||||||
|
// let 'cur' point to the remaining nodes needing to be
|
||||||
|
// stiched back in
|
||||||
|
|
||||||
|
cur = *res.prev_link;
|
||||||
|
if (cur->x < res.x) {
|
||||||
|
// preserve the existing one, so start testing with the next one
|
||||||
|
stbrp_node *next = cur->next;
|
||||||
|
cur->next = node;
|
||||||
|
cur = next;
|
||||||
|
} else {
|
||||||
|
*res.prev_link = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
// from here, traverse cur and free the nodes, until we get to one
|
||||||
|
// that shouldn't be freed
|
||||||
|
while (cur->next && cur->next->x <= res.x + width) {
|
||||||
|
stbrp_node *next = cur->next;
|
||||||
|
// move the current node to the free list
|
||||||
|
cur->next = context->free_head;
|
||||||
|
context->free_head = cur;
|
||||||
|
cur = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
// stitch the list back in
|
||||||
|
node->next = cur;
|
||||||
|
|
||||||
|
if (cur->x < res.x + width)
|
||||||
|
cur->x = (stbrp_coord) (res.x + width);
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
cur = context->active_head;
|
||||||
|
while (cur->x < context->width) {
|
||||||
|
STBRP_ASSERT(cur->x < cur->next->x);
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
|
STBRP_ASSERT(cur->next == NULL);
|
||||||
|
|
||||||
|
{
|
||||||
|
int count=0;
|
||||||
|
cur = context->active_head;
|
||||||
|
while (cur) {
|
||||||
|
cur = cur->next;
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
cur = context->free_head;
|
||||||
|
while (cur) {
|
||||||
|
cur = cur->next;
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
STBRP_ASSERT(count == context->num_nodes+2);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
// [DEAR IMGUI] Added STBRP__CDECL
|
||||||
|
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
|
||||||
|
{
|
||||||
|
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||||
|
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||||
|
if (p->h > q->h)
|
||||||
|
return -1;
|
||||||
|
if (p->h < q->h)
|
||||||
|
return 1;
|
||||||
|
return (p->w > q->w) ? -1 : (p->w < q->w);
|
||||||
|
}
|
||||||
|
|
||||||
|
// [DEAR IMGUI] Added STBRP__CDECL
|
||||||
|
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
|
||||||
|
{
|
||||||
|
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||||
|
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||||
|
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef STBRP_LARGE_RECTS
|
||||||
|
#define STBRP__MAXVAL 0xffffffff
|
||||||
|
#else
|
||||||
|
#define STBRP__MAXVAL 0xffff
|
||||||
|
#endif
|
||||||
|
|
||||||
|
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
|
||||||
|
{
|
||||||
|
int i, all_rects_packed = 1;
|
||||||
|
|
||||||
|
// we use the 'was_packed' field internally to allow sorting/unsorting
|
||||||
|
for (i=0; i < num_rects; ++i) {
|
||||||
|
rects[i].was_packed = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// sort according to heuristic
|
||||||
|
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
|
||||||
|
|
||||||
|
for (i=0; i < num_rects; ++i) {
|
||||||
|
if (rects[i].w == 0 || rects[i].h == 0) {
|
||||||
|
rects[i].x = rects[i].y = 0; // empty rect needs no space
|
||||||
|
} else {
|
||||||
|
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
|
||||||
|
if (fr.prev_link) {
|
||||||
|
rects[i].x = (stbrp_coord) fr.x;
|
||||||
|
rects[i].y = (stbrp_coord) fr.y;
|
||||||
|
} else {
|
||||||
|
rects[i].x = rects[i].y = STBRP__MAXVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// unsort
|
||||||
|
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
|
||||||
|
|
||||||
|
// set was_packed flags and all_rects_packed status
|
||||||
|
for (i=0; i < num_rects; ++i) {
|
||||||
|
rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
|
||||||
|
if (!rects[i].was_packed)
|
||||||
|
all_rects_packed = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return the all_rects_packed status
|
||||||
|
return all_rects_packed;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
This software is available under 2 licenses -- choose whichever you prefer.
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
ALTERNATIVE A - MIT License
|
||||||
|
Copyright (c) 2017 Sean Barrett
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
||||||
|
This is free and unencumbered software released into the public domain.
|
||||||
|
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||||
|
software, either in source code form or as a compiled binary, for any purpose,
|
||||||
|
commercial or non-commercial, and by any means.
|
||||||
|
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||||
|
software dedicate any and all copyright interest in the software to the public
|
||||||
|
domain. We make this dedication for the benefit of the public at large and to
|
||||||
|
the detriment of our heirs and successors. We intend this dedication to be an
|
||||||
|
overt act of relinquishment in perpetuity of all present and future rights to
|
||||||
|
this software under copyright law.
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
1447
vendor/librw/skeleton/imgui/imstb_textedit.h
vendored
Normal file
1447
vendor/librw/skeleton/imgui/imstb_textedit.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue