Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script updates and fixes #3197

Merged
merged 36 commits into from
Dec 8, 2024
Merged

Script updates and fixes #3197

merged 36 commits into from
Dec 8, 2024

Conversation

ohlidalp
Copy link
Member

@ohlidalp ohlidalp commented Nov 11, 2024

Fixes #3195 - apparently I forgot to fix some scripts after I fixed the [X] button in 41060b8

I'm in the process of going through the scripts, making sure they work and they use all capabilities offered by the game. For example I added tabs to the road editor since those arrived in the meantime.

changes made:
* added `*_utils`  namespaces (new convention for includes)
* unified style of scripts: using global variables and functions instead of classes.
* scripts auto-formatted by script_editor.as
This reverts a line from caf88e5 - I wanted to be purist and force users to do `engity.getSubEntities(0).setMaterial()` but since OGRE has this convenience method and the skeletal posing example already uses it, let's just roll with it.
Returns `array<Ogre::MovableObjects@>` in no particular order; works using bounding boxes so large/generated meshes like roads get matched all the time.

comes with example script.
drawSelectableFileList() now Creates a child window with dynamic height (but clamped to hardcoded max value).
		const int MAX_CHILD_HEIGHT = 300;
		const int CHILD_WIDTH = 600;
Also fixed typos in `get/setCameraOrientation()` function bindings - parameter was declared as `vector3`, should have been `quaternion`.
Also fixed weird binding of global `game` object, preventing use of AngelScript delegates. Fixed to bind as non-counting reference because that's the sensible choice.
@ohlidalp ohlidalp marked this pull request as ready for review November 25, 2024 08:36
When loaded with a terrain containing races, it detects them and generates race-def files for each of them, also modifying the .terrn2 file.
These files can't be processed yet, but they contain all info normally present in the race definition scripts.
Example from Auriga:
```
; ~~ New 'race-def' format (file extension: .race). ~~
; Each race file specifies a single race
; In .terrn2 file, list the race files under new section [Races]
; Filenames must include extension and end with = (like scripts do)
; Race system supports alternating paths!
; Checkpoint format: checkpointNum(1+), altpathNum(1+), x, y, z, rotX, rotY, rotZ, objName(override, optional)
; By convention, the checkpoint meshes are oriented sideways (facing X axis)

race_name 1 kilometer drag
race_laps 0.000000
race_checkpoint_object 31-checkpoint
race_start_object 31-checkpoint
race_finish_object 31-checkpoint

begin_checkpoints
1.000000,1.000000,1010.000000,9.000000,505.000000,0.000000,90.000000,0.000000
2.000000,1.000000,10.000000,9.000000,505.000000,0.000000,90.000000,0.000000
end_checkpoints
```
Since adding INT/FLOAT and removing NUMBER token types from GenericDocument, all copypasted viewers/editors in scripts are broken.
This is 1st step to creating an unified viewer/editor as include, but not yet there.
Implements `GenericDocEditor` which doesn't edit yet but has highlight+selection and can be shared by scripts.
Currently only 'example_terrn2_raceConverter.as' was updated to use it.
terrnBatcher coding style matched others.
rigEditorAlpha updated to use 'genericdoc_utils'
3 scripts renamed - category changed for clarity.
also removed one Float->Int compiler warning
Tooltips were polished: brighter title, no more "Title:" and "Brief:" prefixes, separator moved under title+brief
FIXME: this example was created for Tritonas00's sky shader which was later reverted.
Crashes on me under Win10, DirectX9 although used to work OK... I added a lot of checks and buttons to test slow, at one point it worked but then stopped again... crashes somewhere in OGRE overlay system, I can't easily debug at the moemnt, so I'm just posting the updated script.
@CuriousMike56
Copy link
Collaborator

Tested all scripts in scripts/ directory except those used by the base game (base.as, default.as, AI.as, races.as)

The following scripts fail or throw warnings:

example_ogre_overlays.as

Guaranteed game crash almost every time. Log warnings:

example_ogre_overlays.as (30, 1): Info = Compiling void frameStep(float)
example_ogre_overlays.as (66, 73): Warning = The operand is implicitly converted to handle in order to compare them

example_terrn_raceConverter.as

Fails if no races are present on terrain, otherwise OK

addfunc (1, 42): Error = No matching symbol 'races'
An error occurred while trying to add a function ('void eventCallback(int key, int value) { races.eventCallback(key, value); }') to script module 'default.as(category:TERRAIN,unique ID:0)'.
Error in `getVariable()` - 'races' not found

example_autotest_scenario.as

Loads with warnings:

example_autotest_scenario.as (78, 1): Info = Compiling void frameStep(float)
example_autotest_scenario.as (145, 38): Warning = Signed/Unsigned mismatch
example_autotest_scenario.as (153, 31): Warning = Signed/Unsigned mismatch
Executing main() in example_autotest_scenario.as(category:CUSTOM,unique ID:1)
Automated test is running...
The script finished successfully.
Automated test step 0: Waiting for the game to fully load...

Doesn't advance past step 0, even with a vehicle spawned. Removing vehicle gives 'out of bounds' error:

Autotest: vehicle deleted, ID: 1
The script ended with exception; details below:
context.ExceptionLineNumber: 73
context.ExceptionString: Index out of bounds
context.ExceptionFunction.Declaration: void eventCallbackEx(scriptEvents, int, int, int, int, string, string, string, string)
context.ExceptionFunction.ModuleName: example_autotest_scenario.as(category:CUSTOM,unique ID:1)
context.ExceptionFunction.ScriptSectionName: example_autotest_scenario.as
context.ExceptionFunction.ObjectName: 

example_game_keyCodes.as

OK with warning:

example_game_keyCodes.as (24, 1): Info = Compiling void showKeyState(keyCodes, string)
example_game_keyCodes.as (34, 31): Warning = Signed/Unsigned mismatch

example_ogre_textureBlitting.as

example_ogre_textureBlitting.as (11, 1): Error = Identifier 'GridViewer' is not a data type in global namespace
example_ogre_textureBlitting.as (12, 1): Error = Identifier 'GridViewer' is not a data type in global namespace
example_ogre_textureBlitting.as (61, 24): Error = Identifier 'GridViewer' is not a data type in global namespace

example_ImGui_nodeHighlight.as

Spammed log with 'out of bounds' error first time, have yet to reproduce again (with or without vehicle spawned)

The script ended with exception; details below:
context.ExceptionLineNumber: 197
context.ExceptionString: Index out of bounds
context.ExceptionFunction.Declaration: void drawNodeHighlights(BeamClass@)
context.ExceptionFunction.ModuleName: example_ImGui_nodeHighlight.as(category:CUSTOM,unique ID:1)
context.ExceptionFunction.ScriptSectionName: example_ImGui_nodeHighlight.as
context.ExceptionFunction.ObjectName: 

All other scripts appear to load OK 👍

road_editor.as
demo_script.as
script_editor.as
overlay_editor.as
genericdoc_utils.as
gridviewer_utils.as
imgui_utils.as
scriptinfo_utils.as
example_terrn_railBuilder.as
example_actor_RigEditorAlpha.as
example_actor_shockTuning.as
example_angelscript_exceptionEvent.as
example_angelscript_getScriptDetails.as
example_angelscript_linecallback.as
example_game_camera.as
example_game_fetchUrlAsStringAsync.as
example_game_findResourceFileInfo.as
example_game_getManagedMaterials.as
example_game_getMousePointedMovableObjects.as
example_game_gridSpawn.as
example_game_setEventSimulatedValue.as
example_GenericDocument_uniEditor.as
example_html_parsing.as
example_ImGui_devDocLinksOffline.as
example_ImGui_hotkeyHighlight.as
example_ImGui_ImHyperlink.as
example_ImGui_tabs.as
example_ogre_characterPosing(skelAnims).as
example_ogre_inspector.as
example_ogre_ManualObject.as
example_ogre_meshedConcrete.as
example_ogre_shaderParams.as
example_ogre_terrnBatcher.as
example_ogre_vertexData.as
example_terrn_odefBrowser.as

@ohlidalp ohlidalp force-pushed the 3195_scripts branch 2 times, most recently from d764e5e to 60db491 Compare December 5, 2024 02:33
Changes:
* added + registered `enum ScriptRetCode` - used by all script manipulation funcs (add/get/delete | funcs/variables)
* added func `scriptVariableExists()` to go with `scriptFunctionExists()`
* added internal helper `validateScriptModule`- used by all script manipulation funcs (add/get/delete | funcs/variables)

Following is analysis of former state (most but not all funcs returned 0 on success)
~ executeString() [script: not exported] - used to return 0 on success, 1 on internal error and negative number otherwise.
~ addFunction() [script: `game.addScriptFunction()`] - used to return 0 on success, 1 on internal error and negative number otherwise.
~ functionExists() [script: `game.scriptFunctionExists()`] - used to return function ID (always >0) on success, negative number on error.
~ deleteFunction() [script: `game.deleteScriptFunction()`] - used to return function ID (always >0) on success, negative number on error.
~ addVariable() [script: `game.addScriptVariable()` ] - used to return 0 on success, 1 on internal error and negative number otherwise.
~ variableExists() [script: `game.scriptVariableExists()`] - newly added, returns 0 on success  and negative number otherwise.
~ deleteVariable() [script: `game.deleteScriptVariable()` ] - used to return 0 on success, 1 on internal error and negative number otherwise.
~ getVariable() [script: `game.getScriptVariable()` ] - recently added, returns 0 on success  and negative number otherwise.
@ohlidalp
Copy link
Member Author

ohlidalp commented Dec 5, 2024

@CuriousMike56 Thanks for such an elaborate test. Everything should be fixed now.

Please also test if races/AI work normally because I've done changes across the entire scripting subsystem - I had to unify return codes of functions because it was an undocumented mess:

~ executeString() [script: not exported] - used to return 0 on success, 1 on internal error and negative number otherwise.
~ addFunction() [script: `game.addScriptFunction()`] - used to return 0 on success, 1 on internal error and negative number otherwise.
~ functionExists() [script: `game.scriptFunctionExists()`] - used to return function ID (always >0) on success, negative number on error.
~ deleteFunction() [script: `game.deleteScriptFunction()`] - used to return function ID (always >0) on success, negative number on error.
~ addVariable() [script: `game.addScriptVariable()` ] - used to return 0 on success, 1 on internal error and negative number otherwise.
~ variableExists() [script: `game.scriptVariableExists()`] - newly added, returns 0 on success  and negative number otherwise.
~ deleteVariable() [script: `game.deleteScriptVariable()` ] - used to return 0 on success, 1 on internal error and negative number otherwise.
~ getVariable() [script: `game.getScriptVariable()` ] - recently added, returns 0 on success  and negative number otherwise.

@ohlidalp ohlidalp closed this Dec 5, 2024
@ohlidalp ohlidalp reopened this Dec 5, 2024
@CuriousMike56
Copy link
Collaborator

Well loading all scripts at once works now lol (previously crashed) 👍
screenshot_2024-12-08_02-57-19_1
Races and AI seem to be functioning as expected too ✅

@ohlidalp ohlidalp merged commit 02d049b into RigsOfRods:master Dec 8, 2024
4 checks passed
@ohlidalp ohlidalp deleted the 3195_scripts branch December 9, 2024 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants