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

Real-time engine tweaking via 👼Script - with example. #3177

Merged
merged 12 commits into from
Jan 26, 2025

Conversation

ohlidalp
Copy link
Member

@ohlidalp ohlidalp commented Sep 8, 2024

Added input events EV_TRUCK_MANUAL_CLUTCH_MODIFIER_25/50 To go with existing accel/brake modifiers. Suggested by Gibbzy on Discord: https://discord.com/channels/136544456244461568/189904947649708032/1280998672246771753

UPDATE: Turns out this needs more research - the modifiers work but they don't have the desired effect, see Discussion: https://discord.com/channels/136544456244461568/189904947649708032/1282776986107773010. To research further, I've dusted off my Engine-AngelScript bindings (made a year ago and never merged) and created an engine diagnostic script 📜 'example_actor_engineDiag.as'.

UPDATE2: To help modders figure out what the engine needs, I've extended the above script with real-time engine tweaking capabilities. This is possible thanks to the ACTORSIMATTR_ system introduced recently in #3210. 'engturbo' isn't in the tool yet but the ACTORSIMATTR_ constants exist.
Either way it's just an example script, if anybody finds it almost useful let me know.
image

@ohlidalp

This comment was marked as outdated.

@ohlidalp ohlidalp marked this pull request as draft September 14, 2024 04:20
"Engine" is quite ambiguous (a render engine, a physics engine...) but "EngineSim" became synonymous with The Engine Simulator by AngeTheGreat https://www.engine-sim.parts/, so I'm reverting this old change of mine.
The gear-vector prep code was moved from ActorSpawner.cpp to Engine.cpp

Engine.h codechanges:
- added doxy comments about 'engine' keyword args
- added `getDiffRatio()` getter so `m_diff_ratio` is no longer a dead attr - will be bound to AngelScript later
This touches many files but it's just find&replace of the renamed functions in Engine.h
This is a preparation for AngelScript bindings which must all be `camelCase()`.
Deleted `Engine::shiftmodes`, using global `SimGearboxMode` (see Application.h) for everything. The enums are the same except for syntax.
tidy up of conf funcs, added diag funcs
Engine class upgraded to RefCountingObject - that means all codebase uses EnginePtr now.
Ambiguous func `Engine::getEngineTorque()` renamed to `getCurEngineTorque()`
Func `Engine::getShiftingToGear()` renamed to `getShifTargetGear()`
Engine.h - some more doxygen doc shuffling.
@ohlidalp ohlidalp force-pushed the Gibzy_clutch_modif_keys branch from f20db9e to 51656ae Compare January 24, 2025 19:39
How to read 'engine/engoption' attributes:

        Each value is displayed twice (for debugging) from different sources:
        1. the 'get***' value is what EngineClass object reports via `get***()` functions.
        2. the UPPERCASE value is what ActorClass object reports via `getSimAttribute()` function.
        There are exceptions, a few values have multiple EngineClass getters or lack Attribute handle.
@ohlidalp ohlidalp force-pushed the Gibzy_clutch_modif_keys branch from 51656ae to 790cb00 Compare January 25, 2025 00:49
@ohlidalp ohlidalp changed the title Added EV_TRUCK_MANUAL_CLUTCH_MODIFIER_25/50 Real-time engine tweaking via 👼Script - with example. Jan 25, 2025
@ohlidalp ohlidalp marked this pull request as ready for review January 25, 2025 00:58
Copy link
Member

@CuriousMike56 CuriousMike56 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome script. One issue though:

Spawn the Pontiac Firebird and switch to neutral gear, results in a divide by zero error:

The script ended with exception; details below:
	context.ExceptionLineNumber: 38
	context.ExceptionString: Divide by zero
	context.ExceptionFunction.Declaration: void updateEnginePlotBuffers(EngineClass@)
	context.ExceptionFunction.ModuleName: example_actor_engineDiag.as(category:CUSTOM,unique ID:11)
	context.ExceptionFunction.ScriptSectionName: example_actor_engineDiag.as
	context.ExceptionFunction.ObjectName: 

@ohlidalp
Copy link
Member Author

I've renamed confusing EngineClass attr getters:

  • getMaxRPM() --> getShiftDownRPM() -- equivalent of ACTORSIMATTR_ENGINE_SHIFT_DOWN_RPM
  • getMinRPM() --> getShiftUpRPM() -- equivalent of ACTORSIMATTR_ENGINE_SHIFT_UP_RPM

The 'example_actor_engineDiag.as' was updated:

  • updated 'engine' tab to show new names
  • completely removed the 'clutch' tab as it didn't make sense anymore - I got confused by the min/max RPM when writing it. @CuriousMike56 This also fixes the division-by-zero script crash with 1970 Pontiac Firebird.
  • fixed plot min/max values in the 'state' tab.

Changes:
* `getMaxRPM()` --> `getShiftDownRPM()` -- equivalent of `ACTORSIMATTR_ENGINE_SHIFT_DOWN_RPM`
* `getMinRPM()` --> `getShiftUpRPM()` -- equivalent of `ACTORSIMATTR_ENGINE_SHIFT_UP_RPM`

The 'example_actor_engineDiag.as' was updated:
* updated 'engine' tab to show new names
* completely removed the 'clutch' tab as it didn't make sense anymore - I got confused by the min/max RPM when writing it. This also fixes a division-by-zero script crash reported by Mike.
* fixed plot min/max values in the 'state' tab.
// Attributes can be edited realtime (on every keystroke) or using the [Focus] button.
// Focused editing means all other inputs are disabled and [Apply/Reset] buttons must be used.
^ This hint was added to the help box.
@ohlidalp ohlidalp force-pushed the Gibzy_clutch_modif_keys branch from 93f6c37 to 720b275 Compare January 25, 2025 15:18
@ohlidalp ohlidalp merged commit 9bdcd82 into RigsOfRods:master Jan 26, 2025
2 checks passed
@ohlidalp ohlidalp deleted the Gibzy_clutch_modif_keys branch January 26, 2025 14:55
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