RigsOfRods / rigs-of-rods

Main development repository for Rigs of Rods soft-body physics simulator
https://www.rigsofrods.org
GNU General Public License v3.0
991 stars 175 forks source link

AngelScript subsystem future #1558

Open ohlidalp opened 5 years ago

ohlidalp commented 5 years ago

Something to tackle after v0.4.8 release and OGRE 1.11+ port:

AngelScript is great, but RoR's programming interface needs improvement.

RoR has traditionally had everything data driven - Truckfiles, soundscripts, eventboxes in .odef files - and that's a good thing. The problem is, implementing all the logic is then up to the developers who are not the best fit - I'm not at all into motorsports, so how am I supposed to code a powertrain with all the mods and specifics that exist in real world? And where do I find the time? Moving the complexity out would give us a chance of getting more devs interested specifically in this stuff - with proper in-game GUI, scripts aren't scary like application programming.

I'm not suggesting all modders should write code instead of config files. I'm suggesting that the config files they write won't be parsed and executed by RoR's code directly, but by community-driven suite of scripts which will then control RoR. Sounds fair?

ohlidalp commented 5 years ago

To implement this, tough, we need to create a new scripting interface from scratch, the existing won't cut it:

Draft

Just an initial idea - some things may not be possible or need updates. @AnotherFoxGuy @ulteq @tritonas00 @Speciesx I'd really like your early feedback just to be sure I'm not writing nonsense. Sorry for doodling future concepts instead of finishing v0.4.8, but lately I've never had time at home - now I'm at work, I can't code and I'm bored.

Hooks

Hooks are pre-defined moment in game session where scripts can be invoked.

Note: Multiplayer state can be accessed/controlled at any time using GVars.

Hooking methods

Script sources

APIs and their availability

Running script files and sharing data

Script files are only executed in hooks APP_BOOT, TERRAIN_LOAD, ACTOR_SPAWN - only here you can define global variables and functions. Other hooks can only invoke registered functions and thus can only read/write existing global variables, but not add new ones.

Because starting with v0.4.8 graphics (updating 3D scene + rendering) will run in parallel with simulation, you can't access global variables from hook SIMULATION_FRAME - you must send/receive data to/from it manually. To do it, use RoR::SetFrameInput(objectWithSimData) and RoR::GetFrameOutput(objectWithGuiData) in a SIMULATION_STEP* hook and RoR::GetFrameInput(objectWithSimData) and RoR::SetFrameOutput(objectWithGuiData). This will be most useful for drawing custom gui with DearIMGUI - in SIMULATION_FRAME hook, you receive simulation data to visualize, draw GUI and send resulting user input back.