-
Notifications
You must be signed in to change notification settings - Fork 179
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
AngelScript: fixed ref counting, added ProceduralRoad API #2930
Conversation
b9eb90d
to
b5b4c2c
Compare
Sneak preview of what's coming. This script tests the new procedural road APIs and will become an useful tool later. The window only appears in terrain editing mode (hotkey |
ae54ab2
to
06563bc
Compare
It's all drawn by the script! |
59cec94
to
3b44e37
Compare
getting some gcc warnings:
Hm, can't load any script:
|
I didn't expect a problem with calling conventions... But apparently linux x64 is more complicated: https://www.gamedev.net/forums/topic/712220-native-calling-on-linux-x86-64-not-working-for-a-type/ |
801c8e9
to
2bb223b
Compare
loadscript
command, fixed ref counting
loadscript
command, fixed ref counting2bb223b
to
e3835d9
Compare
5ef1f0b
to
fb602a8
Compare
This introduces `RefCountingObject` to the codebase. Using it makes it possible to pass object between C++ and AngelScript without worry. See https://github.com/only-a-ptr/RefCountingObject-AngelScript In the case of Actor, the refcounting was dummy and the game would certainly crash if a script kept pointer to an Actor which got removed. Signifficant code changes: - utils/memory/RefCountingObject* - new files. - ForwardDeclarations.h - added ActorPtr - Application.h - updated comments regarding message queue arguments. Instead of sending weak Actor* pointers, a strong ActorPtr* is sent. - main.cpp - updated message handling to cope with new pointers. - SimData.h - new entry in `enum class ActorState`: `DISPOSED` - means the actor was removed from simulation and it's component objects were deleted, but it still lives as an empty shell to satisfy existing pointers. - ActorManager.cpp - DeleteActorInternal() - changed to only dispose, but not delete the actor - the deleting will be done by RefCountingObjectPtr. - ScriptEngine.h/cpp - added function `setEventsEnabled()` which stops the TRIGGER_EVENT() macros from working, as a hack for fast dirty shutdown.
Signifficant codechanges: - global variable `App::g_sim_terrain` removed, replaced by new variable `GameContext::m_terrain`. - global function `App::GetSimTerrain()` removed, using `GameContext::GetTerrain()` - static factory func `Terrain* Terrain::LoadAndPrepareTerrain()` changed to nonstatic `void Terrain::initialize()`, loading now done by GameContext. - Terrain.h: added function `dispose()` and flag `bool m_disposed` - after the terrain is unloaded, the scripts may still hold pointers to it. Therefore it must remain in memory, even though all the component objects were deleted.
Lesson learned for the `RefCountingObject<>` mechanic - implicit conversion of `Foo*` to `FooPtr` is a no-no; the constructor was made private and static function `Bind()` was added to make it obvious creating the shared pointer is an once-per-object operation.
CODECHANGES: * new file ProceduralRoadAngelscript.cpp - binds ProceduralPointClass, ProceduralRoadClass, ProceduralObjectClass, ProceduralManagerClass * ProceduralRoad.h/cpp - added strong enums RoadType and TextureFit - extracted from class ProceduralRoad * TerrainAngelscript.cpp - added getter for procedural manager. * TObjFileFormat: accomodated new pointer type.
The 'engine' param in `Register*()` funcs was moved to the front, for style: - this way it better resembles the AngelScript reg funcs - context objects generally get passed first in APIs.
1753b68
to
8f3f282
Compare
The work is almost done. The
I updated the terrain editor script. To test, just put it to "Documents/My Games/Rigs of Rods/scripts" and in the game console, say 'loadscript terrain_editor.as'. |
Crashed as soon as i spawned a desperado in f1 testtrack:
Also still got massive spam about:
|
Purpose: To do AngelScript right - currently the object refcounting is dummy and prone to crash. Estimate: 8 man days. This is hard work but it's an once-and-for-all fix which needs to be done at some point. Work to be done:
|
I'm closing this because it got stale and it was too invasive to begin with. I'll start a new PR with less code and more added value. |
Status (last update 2022-10-14)
Many feats originally developed here got merged in #2931.
The object ref-counting system, originally created here, got perfected in it's own repo: https://github.com/only-a-ptr/RefCountingObject-AngelScript
New script features:
TerrainClass, ProceduralRoadClass, ProceduralObjectClass, ProceduralManagerClass, ProceduralPointClass
RoadType, TextureFit
Reference counting fix
Previously, if a script kept a pointer (a 'handle' in AngelScript terminology) to
BeamClass
orVehicleAIClass
after the vehicle was removed, it would crash. I studied how the reference counting system works and added aRefCountingObject
base class which lets us keep track of the object both inside and outside of the script. It will help registering more objects to the script engine.