Open ohlidalp opened 5 years ago
To implement this, tough, we need to create a new scripting interface from scratch, the existing won't cut it:
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 are pre-defined moment in game session where scripts can be invoked.
Note: Multiplayer state can be accessed/controlled at any time using GVars.
AddHook(HOOK_TYPE,MyHookFunction)
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.
Something to tackle after v0.4.8 release and OGRE 1.11+ port:
AngelScript is great, but RoR's programming interface needs improvement.
TRIGGER_EVENT()
macros work by synchronously invoking the handler script function - not good for parallelism and maintenance.TRIGGER_EVENT()
macro writing tostd::vector<>
makes much more sense.cameras
or node 0? I don't even know!.ImGui::Begin("window name");
can as well be AngelScript code. It would only be accessible in per-frame invocation of script (not in per-physics-tick) - see https://www.angelcode.com/angelscript/sdk/docs/manual/doc_adv_dynamic_config.htmlRoR 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?