aboutsummaryrefslogtreecommitdiff
path: root/sword2/build_display.cpp
diff options
context:
space:
mode:
authorTorbjörn Andersson2003-11-10 07:52:15 +0000
committerTorbjörn Andersson2003-11-10 07:52:15 +0000
commit3d012651fd43d83ed67617ac0c5c0e32e6dd2ad4 (patch)
treec09b3c0e43525ea8d355fa6d364a20cee9be6252 /sword2/build_display.cpp
parent439bc8364d248293c1ba7b1d92d2b00b4a6fa609 (diff)
downloadscummvm-rg350-3d012651fd43d83ed67617ac0c5c0e32e6dd2ad4.tar.gz
scummvm-rg350-3d012651fd43d83ed67617ac0c5c0e32e6dd2ad4.tar.bz2
scummvm-rg350-3d012651fd43d83ed67617ac0c5c0e32e6dd2ad4.zip
The script engine frequently needs to pass pointers to various structures
etc. to the different opcodes. Until now it has done so by casting the pointer to an int32 (opcode parameters are represented as arrays of int32) and then the opcode function casts it back to whatever pointer it needs. At least in C there is no guarantee that a pointer can be represented as an integer type (though apparently C99 may define such a type), so this has struck me as unsafe ever since I first noticed it. However, since all such pointers appear to point to the memory block owned by the memory manager, we can easily convert them to integers by treating them as offsets into the memory block. So that's what I have done. I hope I caught all the occurences in the opcode functions, or we're going to have some pretty interesting regressions on our hands... svn-id: r11241
Diffstat (limited to 'sword2/build_display.cpp')
-rw-r--r--sword2/build_display.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/sword2/build_display.cpp b/sword2/build_display.cpp
index 82f098719a..5c51ed5b32 100644
--- a/sword2/build_display.cpp
+++ b/sword2/build_display.cpp
@@ -576,7 +576,7 @@ void Sword2Engine::registerFrame(int32 *params, buildit *build_unit) {
// open animation file & set up the necessary pointers
- ob_graph = (Object_graphic *) params[1];
+ ob_graph = (Object_graphic *) memory->intToPtr(params[1]);
assert(ob_graph->anim_resource);
@@ -614,7 +614,7 @@ void Sword2Engine::registerFrame(int32 *params, buildit *build_unit) {
if (cdt_entry->frameType & FRAME_OFFSET) {
// param 2 is pointer to mega structure
- ob_mega = (Object_mega *) params[2];
+ ob_mega = (Object_mega *) memory->intToPtr(params[2]);
// calc scale at which to print the sprite, based on feet
// y-coord & scaling constants (NB. 'scale' is actually
@@ -655,7 +655,7 @@ void Sword2Engine::registerFrame(int32 *params, buildit *build_unit) {
if (params[0]) {
// passed a mouse structure, so add to the _mouseList
- ob_mouse = (Object_mouse *) params[0];
+ ob_mouse = (Object_mouse *) memory->intToPtr(params[0]);
// only if 'pointer' isn't NULL
if (ob_mouse->pointer) {
@@ -706,7 +706,7 @@ int32 Logic::fnRegisterFrame(int32 *params) {
}
int32 Sword2Engine::registerFrame(int32 *params) {
- Object_graphic *ob_graph = (Object_graphic *) params[1];
+ Object_graphic *ob_graph = (Object_graphic *) memory->intToPtr(params[1]);
// check low word for sprite type
switch (ob_graph->type & 0x0000ffff) {
@@ -788,7 +788,7 @@ int32 Logic::fnUpdatePlayerStats(int32 *params) {
// params: 0 pointer to mega structure
- Object_mega *ob_mega = (Object_mega *) params[0];
+ Object_mega *ob_mega = (Object_mega *) memory->intToPtr(params[0]);
_vm->_thisScreen.player_feet_x = ob_mega->feet_x;
_vm->_thisScreen.player_feet_y = ob_mega->feet_y;