Commit Graph
238 Commits
Author SHA1 Message Date
Hubert Maier 76210767fa JANITORIAL: AGS: Fix typos 2024-12-25 17:08:44 +02:00
Thierry Crozat 83eefd4214 AGS: Engine: create ccInstances wrapped in std::unique_ptr
This also fixed a potential memory leak in ccInstance::CreateEx().

From upstream 30167df0690e0a771a8eb4f14a4d6a72da526b49

Also remove unreachable code (same condition checked twice in a
function) as that caused a compilation error with the changes above
otherwise. This change is part of upstream commit
881d31966cf7600c9b5628fff4c194d628196f4a
2024-11-27 21:23:33 +00:00
Le Philousophe 7cc927d73e AGS: Make NumberPtr a class instead of a union
It's illegal to reference an inactive member of a union and the types
are not layout compatible (and even not of the same size).
Instead, store every value in a integer of pointer size and cast
pointers to and from it.
This should really fix bug #13557.
2024-11-16 22:42:53 +01:00
Le Philousophe c5bc568d41 AGS: Fix call_function signature
call_function returns from PluginMethod::operator() which returns a
NumberPtr.
Its two calls also expect a NumberPtr but the function returned an int.
This should fix bug #13557.
2024-11-15 22:39:15 +01:00
D G Turner b78318dbf1 AGS: Fix Usage Of Undefined Preprocessor Define GCC Compiler Warning
This is emitted if -Wundef is passed to GCC.
2024-11-03 17:28:44 +00:00
Walter Agazzi 543dff99a6 AGS: Expand info in cc_instance error logging macros 2024-10-30 18:07:42 +02:00
Walter Agazzi 08a2d9cc9e AGS: Add casts in cc_instance 2024-10-30 18:07:42 +02:00
Walter Agazzi 5ce015027f AGS: Add const_casts, comment out unneeded bindings 2024-10-30 18:07:42 +02:00
Walter Agazzi 77c508662f AGS: Fixed "Engine: hotfix potential exception if cc_error is called during quit()"
From upstream a7416bfb473a68ad34958bcba028454565bb5756
2024-10-30 18:07:42 +02:00
Walter Agazzi 6c209a2a98 AGS: Engine: use uintptr_t in couple of places in ccInstance::Run()
...although this does not change much, because code offsets are int32-based everywhere else.

From upstream dd10f63d993278eb6c063bac24e25815a7146f99
2024-10-30 18:07:42 +02:00
Walter Agazzi de40de36fb AGS: Engine: change return type of GetDirectPtr() to void*
It makes little sense as intptr_t.
From upstream 23335a6b7c00267bb0419790f3f92d8ae4aedc3e
2024-10-30 18:07:42 +02:00
Walter Agazzi 38ea062044 AGS: Engine: just amended comments to IScriptObject
From upstream 0f8ef52a60b54fc8db0ea89cf15569ba8b876611
2024-10-30 18:07:42 +02:00
Walter Agazzi 822842d038 AGS: Engine, Common: refactor guard using set_our_eip
Remove naked our_eip usages
From upstream 9f4371ab8c2fbc9ccf41b49f7b975ebe8bc5d1b8
2024-10-30 18:07:42 +02:00
Walter Agazzi 4cdfd7ebba AGS: Engine: in cc_instance, use static_cast where possible
From upstream 13835765706f16affd1e2a43015a967a73fe04f3
2024-10-30 18:07:42 +02:00
Walter Agazzi 5549e5c0c3 AGS: Engine: cc_instance adjust for loop
From upstream e60a7411a0909b3c1b5edbdde3c8f7bf746700b6
2024-10-30 18:07:42 +02:00
Walter Agazzi 032d4e9919 AGS: Engine: in script cc_instance used const when possible
From upstream a27fae178c350451eaaa2cb1d9c46d6aa1dda67f
2024-10-30 18:07:42 +02:00
Walter Agazzi e710697044 AGS: Engine: tidy script runner remove unused variables
From upstream 0dc1562b075cea3d2bd1c1ad1a4feafe471b2db5
2024-10-30 18:07:42 +02:00
Walter Agazzi 4e41e60781 AGS: Engine: store ScriptString in memory similarly to dynamic array
This potentially allows to access any metadata while passing string pointer around the script functions.

As a consequence: never wrap external buffer, always allocate your own.
From upstream 043758b1bb5116f038c5c597d17fe9524b92b3c2
2024-10-30 18:07:42 +02:00
Walter Agazzi 455b9609d0 AGS: Script API: implemented Type.GetByName() for all applicable types
From upstream 29602688ec766cdc0b8fb7aa761f73292365651b
2024-10-30 18:07:42 +02:00
Walter Agazzi 57464f3dce AGS: Engine: Complete "object interaction events take obj pointer and mode as params" commit
This completes cb6cce267d75ccdbca452873693a1ccadf0f688b
2024-10-30 18:07:42 +02:00
Walter Agazzi 815041ec6a AGS: Engine: store game's ccInstances as unique_ptrs instead
The script handling part of the engine appeared to be too fragile and dependent on
 a precise timing of **deleting** a ccInstance.
For example, restoring a saved game may execute in the midst of the call to
RunScriptFunction(), at the "post script cleanup" stage, while there are still references
to ccInstance on the engine's call stack (and few other places). If anything prevents
 ccInstance's disposal at this moment, that would in turn lead to logical errors due to
  the game scripts "instances" counting. The most outstanding consequence is that the
   script exports are kept pointing into the deleted memory and not re-registered after the save is restored.

Overall, the script handling part of the engine would benefit from a major refactor,
 with a goal to make it safe and consistent, but this is not something I might do at the moment.

From upstream 1f6abf4b678f77825c710d4ae18b57ff8f882c93
2024-10-30 18:07:42 +02:00
Walter Agazzi 09ffee9ed7 AGS: Engine: store ccInstances in shared_ptr, tidy freeing of instances (take two)
After the updates to cc_instance this should now work

From upstream b1e4f75141ce88b3146f55ecd9d7a95378428072
and 49e8aa0b566dea4ce025f9530a9f2392dbe67a33
2024-10-30 18:07:42 +02:00
Walter Agazzi c00522563a AGS: Engine: store ScriptUserObject in memory similar to DynamicArrays
I realized this recently that SUOs were not registered in the script exports
properly. In AGS standards the object having a memory buffer should
register that buffer's address directly, so that it could be read and written
to directly. That is how strings, arrays, and any other structs are exported.
This also how the engine plugins can access the data if they use script API
to retrieve it.

There have not been any script API working with custom structs earlier,
but there is since 3.5.0 (few functions returning managed Point struct).
Plugins won't be able to use them correctly without this fix.

From upstream 9658c71528676acb386e2c638e782cc4e7d2afe5
2024-10-30 18:07:42 +02:00
Walter Agazzi f13f7cfac2 AGS: Engine: rem the distinction between static/dynamic objects in script VM
From upstream 04450b2a41f0e0f107a4ea85dab375f439b4ffae
2024-10-30 18:07:42 +02:00
Walter Agazzi ac0422354a AGS: Engine: renamed ICCDynamicObject to IScriptObject
because this interface is now used for both Dynamic and
Static object managers.
From upstream 1bb14f7a2bae43534edf950c040bcd4a1be5f7df
2024-10-30 18:07:42 +02:00
Walter Agazzi 54b8b1d873 AGS: Engine: changed script object data pointers from char* to void*
This seems to be far more appropriate.
From upstream a495538a5e0106a655e4e04cf547be8ec9284d7c
2024-10-30 18:07:42 +02:00
Walter Agazzi 70dd8cb1f8 AGS: Engine: in RuntimeScriptValue store generic ptr as void*
From upstream 9d11b497907419ce9bf0ea47eb585bd748a3e027
2024-10-30 18:07:42 +02:00
Walter Agazzi 795dacac07 AGS: Engine: inherit StaticObject managers from ICCDynamicObject
This removes an excessive separation between "static managers" and "dynamic managers",
and let use the single ICCDynamicObject interface when working with both kinds.
Simplifies RuntimeScriptValue and StaticArray classes.

Picked out most common implementation into CCBasicObject, which is inherited by
AGSCCDynamicObject and AGSCCStaticObject.

From upstream 781632881dd64af2b57b789617da15107bca9451
2024-10-30 18:07:42 +02:00
Walter Agazzi 27ce106dac AGS: Engine: added a template ScFnRegister ctor for easier direct function
From upstream 78dcba2b8e874c3c313493e04dc0b83fdfb564cb
2024-10-30 18:07:42 +02:00
Walter Agazzi 813801779c AGS: Engine: Added new functions for API scripts registration
These can be used to gradually move to the new style introduced
in upstream 9221ea54c1a81b9f37829d7fafc90ac2806d4eb1
2024-10-30 18:07:42 +02:00
Walter Agazzi f62f270423 AGS: Engine: use enum for Text script callback types
From upstream 047f6fb020564bca9c6d99d1f6c1474386e3da97
2024-10-30 18:07:42 +02:00
Walter Agazzi 720b7a53ec AGS: Engine: object interaction events take obj pointer and mode as params
Partially from upstream 1897504aa30fda5f7d5cc9d9538cb49944c70151
2024-10-30 18:07:42 +02:00
Walter Agazzi 51cf1f1568 AGS: Engine: tidied code in RunObjectInteraction functions
From upstream c20764239b3a8a234c473feb4f7009afdc3c4c6d
2024-10-30 18:07:42 +02:00
Walter Agazzi dd8c13c1f0 AGS: Engine: replaced global evblock* vars with a local ObjectEvent argument
From upstream 279d3d78ff04423fce137a4907fd42d44ee12969
2024-10-30 18:07:42 +02:00
Walter Agazzi 8153a59121 Revert "AGS: Engine: store ccInstances in shared_ptr, tidy freeing of instances"
This reverts commit 016323f1f9797827a36a77ae3a5859b56d3b0998.
2024-10-30 18:07:42 +02:00
Walter Agazzi 253187f4e2 Revert "AGS: Engine: store game's ccInstances as unique_ptrs instead"
This reverts commit 547cd40186876f17914f6a96261aaf5c4dfc21b4.
2024-10-30 18:07:42 +02:00
Walter Agazzi b1e7617964 AGS: Engine: store game's ccInstances as unique_ptrs instead
From upstream 1f6abf4b678f77825c710d4ae18b57ff8f882c93
2024-10-30 18:07:42 +02:00
Walter Agazzi 4019f9305b AGS: Engine: store ccInstances in shared_ptr, tidy freeing of instances
From upstream b1e4f75141ce88b3146f55ecd9d7a95378428072
and 49e8aa0b566dea4ce025f9530a9f2392dbe67a33
2024-10-30 18:07:42 +02:00
Walter Agazzi 08bd16b555 AGS: Engine: replaced more if/else with switches in RuntimeScriptValue
From upstream e51283a73c346d7738f809afd2955c0f95eaf72a
2024-10-30 18:07:42 +02:00
Walter Agazzi a90e5b7dd7 AGS: Engine: added missing exclusive variadic api impls for plugins
from upstream a61392135e734898b93d73db42942dc881250ef2
2024-10-30 18:07:42 +02:00
Walter Agazzi ad168dbee8 AGS: Engine: added explicit functions for Speech api and GetAudioClipCount()
from upstream 45dcb946a818a65768dfa7f08f27b27a2dccffc2
2024-10-30 18:07:42 +02:00
Walter Agazzi 09039ca805 AGS: Engine: brought multivariant script api functions to naming consistency
The idea is that the old variants have internal names with number
(signifying number of args), while the latest variant has a name without number.

Make sure there's a distinct function for each variant, and older vars are calling later ones in a sequence.
These calls likely to be inlined.
From upstream ca48926a37e848a1bcc162f77cc81e63ec7a1ca0
2024-10-30 18:07:42 +02:00
Walter Agazzi 1467791290 AGS: Engine: tidy code a bit in script_runtime.cpp 2024-10-30 18:07:42 +02:00
Walter Agazzi 96257b87cb AGS: Engine: ensure that all AnimateObject variants lead to the same impl 2024-10-30 18:07:42 +02:00
Walter Agazzi c4f25a16ed AGS: Engine: ensure that all AnimateCharacter variants lead to the same impl
from upstream eb623b4557c91e353fe6fa1bbcfc109e614ceac2
2024-10-30 18:07:42 +02:00
Walter Agazzi 0f44b1946c AGS: Engine: refactored CCDynamicArray for clarity and easier extension 2024-10-30 18:07:42 +02:00
Walter Agazzi 11f50581a3 AGS: Don't use uintptr_t 2024-10-30 18:07:42 +02:00
Walter Agazzi 3a5ccd4cba AGS: Engine: moved dynamic object management functions to a separate unit
From upstream 1a9df937e3ac9eba0c2f5b663507a52569d635e0
2024-10-30 18:07:42 +02:00
Walter Agazzi 4895a10b82 AGS: Engine: ccInstance: fixed MEMWRITEPTR may leave undefined value
This might happen when assigning a local pointer variable, which was not cleaned either with ZEROMEMORY or MEMINITPTR.
from upstream a989f3ed0150fc0218c47b3d7ac3c655d072e78a
2024-10-30 18:07:42 +02:00
Walter Agazzi 9b56d15ef7 AGS: Engine: fixed stack unwind assert was hiding other errors
This complements 2697c95
from upstream ec693e5b74b437745d98bf3bcba26f891f857525
2024-10-30 18:07:42 +02:00