mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-11 19:54:03 +00:00
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
This commit is contained in:
parent
439bc8364d
commit
3d012651fd
@ -97,8 +97,8 @@ int32 Logic::animate(int32 *params, bool reverse) {
|
||||
|
||||
// read the main parameters
|
||||
|
||||
ob_logic = (Object_logic *) params[0];
|
||||
ob_graphic = (Object_graphic *) params[1];
|
||||
ob_logic = (Object_logic *) memory->intToPtr(params[0]);
|
||||
ob_graphic = (Object_graphic *) memory->intToPtr(params[1]);
|
||||
|
||||
if (ob_logic->looping == 0) {
|
||||
// This is the start of the anim - set up the first frame
|
||||
@ -227,11 +227,11 @@ int32 Logic::megaTableAnimate(int32 *params, bool reverse) {
|
||||
// if this is the start of the anim, read the anim table to get the
|
||||
// appropriate anim resource
|
||||
|
||||
ob_logic = (Object_logic *) params[0];
|
||||
ob_logic = (Object_logic *) memory->intToPtr(params[0]);
|
||||
|
||||
if (ob_logic->looping == 0) {
|
||||
ob_mega = (Object_mega *) params[2];
|
||||
anim_table = (uint32 *) params[3];
|
||||
ob_mega = (Object_mega *) memory->intToPtr(params[2]);
|
||||
anim_table = (uint32 *) memory->intToPtr(params[3]);
|
||||
|
||||
// appropriate anim resource is in 'table[direction]'
|
||||
pars[2] = anim_table[ob_mega->current_dir];
|
||||
@ -291,7 +291,7 @@ int32 Logic::fnSetFrame(int32 *params) {
|
||||
|
||||
// set up anim resource in graphic object
|
||||
|
||||
ob_graphic = (Object_graphic *) params[0];
|
||||
ob_graphic = (Object_graphic *) memory->intToPtr(params[0]);
|
||||
ob_graphic->anim_resource = res;
|
||||
|
||||
if (params[2])
|
||||
@ -308,7 +308,7 @@ int32 Logic::fnSetFrame(int32 *params) {
|
||||
int32 Logic::fnNoSprite(int32 *params) {
|
||||
// params: 0 pointer to object's graphic structure
|
||||
|
||||
Object_graphic *ob_graphic = (Object_graphic *) params[0];
|
||||
Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]);
|
||||
|
||||
// remove previous status (but don't affect the shading upper-word)
|
||||
ob_graphic->type &= 0xffff0000;
|
||||
@ -321,7 +321,7 @@ int32 Logic::fnNoSprite(int32 *params) {
|
||||
int32 Logic::fnBackPar0Sprite(int32 *params) {
|
||||
// params: 0 pointer to object's graphic structure
|
||||
|
||||
Object_graphic *ob_graphic = (Object_graphic *) params[0];
|
||||
Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]);
|
||||
|
||||
// remove previous status (but don't affect the shading upper-word)
|
||||
ob_graphic->type &= 0xffff0000;
|
||||
@ -334,7 +334,7 @@ int32 Logic::fnBackPar0Sprite(int32 *params) {
|
||||
int32 Logic::fnBackPar1Sprite(int32 *params) {
|
||||
// params: 0 pointer to object's graphic structure
|
||||
|
||||
Object_graphic *ob_graphic = (Object_graphic *) params[0];
|
||||
Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]);
|
||||
|
||||
// remove previous status (but don't affect the shading upper-word)
|
||||
ob_graphic->type &= 0xffff0000;
|
||||
@ -347,7 +347,7 @@ int32 Logic::fnBackPar1Sprite(int32 *params) {
|
||||
int32 Logic::fnBackSprite(int32 *params) {
|
||||
// params: 0 pointer to object's graphic structure
|
||||
|
||||
Object_graphic *ob_graphic = (Object_graphic *) params[0];
|
||||
Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]);
|
||||
|
||||
// remove previous status (but don't affect the shading upper-word)
|
||||
ob_graphic->type &= 0xffff0000;
|
||||
@ -360,7 +360,7 @@ int32 Logic::fnBackSprite(int32 *params) {
|
||||
int32 Logic::fnSortSprite(int32 *params) {
|
||||
// params: 0 pointer to object's graphic structure
|
||||
|
||||
Object_graphic *ob_graphic = (Object_graphic *) params[0];
|
||||
Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]);
|
||||
|
||||
// remove previous status (but don't affect the shading upper-word)
|
||||
ob_graphic->type &= 0xffff0000;
|
||||
@ -373,7 +373,7 @@ int32 Logic::fnSortSprite(int32 *params) {
|
||||
int32 Logic::fnForeSprite(int32 *params) {
|
||||
// params: 0 pointer to object's graphic structure
|
||||
|
||||
Object_graphic *ob_graphic = (Object_graphic *) params[0];
|
||||
Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]);
|
||||
|
||||
// remove previous status (but don't affect the shading upper-word)
|
||||
ob_graphic->type &= 0xffff0000;
|
||||
@ -386,7 +386,7 @@ int32 Logic::fnForeSprite(int32 *params) {
|
||||
int32 Logic::fnForePar0Sprite(int32 *params) {
|
||||
// params: 0 pointer to object's graphic structure
|
||||
|
||||
Object_graphic *ob_graphic = (Object_graphic *) params[0];
|
||||
Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]);
|
||||
|
||||
// remove previous status (but don't affect the shading upper-word)
|
||||
ob_graphic->type &= 0xffff0000;
|
||||
@ -399,7 +399,7 @@ int32 Logic::fnForePar0Sprite(int32 *params) {
|
||||
int32 Logic::fnForePar1Sprite(int32 *params) {
|
||||
// params: 0 pointer to object's graphic structure
|
||||
|
||||
Object_graphic *ob_graphic = (Object_graphic *) params[0];
|
||||
Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]);
|
||||
|
||||
// remove previous status (but don't affect the shading upper-word)
|
||||
ob_graphic->type &= 0xffff0000;
|
||||
@ -412,7 +412,7 @@ int32 Logic::fnForePar1Sprite(int32 *params) {
|
||||
int32 Logic::fnShadedSprite(int32 *params) {
|
||||
// params: 0 pointer to object's graphic structure
|
||||
|
||||
Object_graphic *ob_graphic = (Object_graphic *) params[0];
|
||||
Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]);
|
||||
|
||||
// remove previous status (but don't affect the shading upper-word)
|
||||
ob_graphic->type &= 0x0000ffff;
|
||||
@ -428,7 +428,7 @@ int32 Logic::fnShadedSprite(int32 *params) {
|
||||
int32 Logic::fnUnshadedSprite(int32 *params) {
|
||||
// params: 0 pointer to object's graphic structure
|
||||
|
||||
Object_graphic *ob_graphic = (Object_graphic *) params[0];
|
||||
Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[0]);
|
||||
|
||||
// remove previous status (but don't affect the shading upper-word)
|
||||
ob_graphic->type &= 0x0000ffff;
|
||||
@ -680,17 +680,17 @@ int32 Logic::fnPlaySequence(int32 *params) {
|
||||
// of computer games" - but at the very least we want to show the
|
||||
// cutscene subtitles, so I removed them.
|
||||
|
||||
debug(5, "fnPlaySequence(\"%s\");", params[0]);
|
||||
debug(5, "fnPlaySequence(\"%s\");", (const char *) memory->intToPtr(params[0]));
|
||||
|
||||
#ifdef _SWORD2_DEBUG
|
||||
// check that the name paseed from script is 8 chars or less
|
||||
if (strlen((char *) params[0]) > 8)
|
||||
if (strlen((const char *) memory->intToPtr(params[0])) > 8)
|
||||
error("Sequence filename too long");
|
||||
#endif
|
||||
|
||||
// add the appropriate file extension & play it
|
||||
|
||||
sprintf(filename, "%s.smk", (char *) params[0]);
|
||||
sprintf(filename, "%s.smk", (const char *) memory->intToPtr(params[0]));
|
||||
|
||||
// Write to walkthrough file (zebug0.txt)
|
||||
debug(5, "PLAYING SEQUENCE \"%s\"", filename);
|
||||
|
@ -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;
|
||||
|
@ -185,7 +185,7 @@ int32 Logic::fnPauseForEvent(int32 *params) {
|
||||
// params: 0 pointer to object's logic structure
|
||||
// 1 number of game-cycles to pause
|
||||
|
||||
Object_logic *ob_logic = (Object_logic *) params[0];
|
||||
Object_logic *ob_logic = (Object_logic *) memory->intToPtr(params[0]);
|
||||
|
||||
// first, check for an event
|
||||
|
||||
|
@ -148,7 +148,7 @@ int32 Logic::fnPause(int32 *params) {
|
||||
// NB. Pause-value of 0 causes script to continue, 1 causes a 1-cycle
|
||||
// quit, 2 gives 2 cycles, etc.
|
||||
|
||||
Object_logic *ob_logic = (Object_logic *) params[0];
|
||||
Object_logic *ob_logic = (Object_logic *) memory->intToPtr(params[0]);
|
||||
|
||||
if (ob_logic->looping == 0) {
|
||||
// start the pause
|
||||
@ -177,7 +177,7 @@ int32 Logic::fnRandomPause(int32 *params) {
|
||||
// 1 minimum number of game-cycles to pause
|
||||
// 2 maximum number of game-cycles to pause
|
||||
|
||||
Object_logic *ob_logic = (Object_logic *) params[0];
|
||||
Object_logic *ob_logic = (Object_logic *) memory->intToPtr(params[0]);
|
||||
int32 pars[2];
|
||||
|
||||
if (ob_logic->looping == 0) {
|
||||
@ -202,7 +202,7 @@ int32 Logic::fnPassGraph(int32 *params) {
|
||||
|
||||
// params: 0 pointer to a graphic structure (might not need this?)
|
||||
|
||||
memcpy(&_vm->_engineGraph, (uint8 *) params[0], sizeof(Object_graphic));
|
||||
memcpy(&_vm->_engineGraph, memory->intToPtr(params[0]), sizeof(Object_graphic));
|
||||
|
||||
// makes no odds
|
||||
return IR_CONT;
|
||||
@ -218,7 +218,7 @@ int32 Logic::fnPassMega(int32 *params) {
|
||||
|
||||
// params: 0 pointer to a mega structure
|
||||
|
||||
memcpy(&_vm->_engineMega, (uint8 *) params[0], sizeof(Object_mega));
|
||||
memcpy(&_vm->_engineMega, memory->intToPtr(params[0]), sizeof(Object_mega));
|
||||
|
||||
// makes no odds
|
||||
return IR_CONT;
|
||||
@ -233,7 +233,7 @@ int32 Logic::fnSetValue(int32 *params) {
|
||||
// params: 0 pointer to object's mega structure
|
||||
// 1 value to set it to
|
||||
|
||||
Object_mega *ob_mega = (Object_mega *) params[0];
|
||||
Object_mega *ob_mega = (Object_mega *) memory->intToPtr(params[0]);
|
||||
|
||||
ob_mega->megaset_res = params[1];
|
||||
|
||||
|
@ -34,7 +34,7 @@ int32 Logic::fnAddMenuObject(int32 *params) {
|
||||
assert(_vm->_totalTemp < TOTAL_engine_pockets);
|
||||
|
||||
// copy the structure to our in-the-engine list
|
||||
memcpy(&_vm->_tempList[_vm->_totalTemp], (uint8 *) params[0], sizeof(menu_object));
|
||||
memcpy(&_vm->_tempList[_vm->_totalTemp], memory->intToPtr(params[0]), sizeof(menu_object));
|
||||
_vm->_totalTemp++;
|
||||
|
||||
// script continue
|
||||
|
@ -198,16 +198,7 @@ int32 Logic::executeOpcode(int i, int32 *params) {
|
||||
return (this->*op) (params);
|
||||
}
|
||||
|
||||
// FIXME: The script engine assumes it can freely cast from pointer to in32
|
||||
// and back again with no ill effects. As far as I know, there is absolutely
|
||||
// no guarantee that this will work.
|
||||
//
|
||||
// Maybe we can represent them as offsets into the memory manager's memory?
|
||||
// Assuming, of course, that all the pointers we try to pass around this way
|
||||
// point to somewhere in that block.
|
||||
//
|
||||
// I also have a feeling the handling of a script's local variables may be
|
||||
// alignment-unsafe.
|
||||
// FIXME: Is the handling of script local variables really alignment-safe?
|
||||
|
||||
#define CHECKSTACKPOINTER2 assert(stackPointer2 >= 0 && stackPointer2 < STACK_SIZE);
|
||||
#define PUSHONSTACK(x) { stack2[stackPointer2] = (x); stackPointer2++; CHECKSTACKPOINTER2 }
|
||||
@ -362,8 +353,8 @@ int Logic::runScript(char *scriptData, char *objectData, uint32 *offset) {
|
||||
case CP_PUSH_LOCAL_ADDR:
|
||||
// push the address of a local variable
|
||||
Read16ip(parameter);
|
||||
debug(5, "Push address of local variable %d (%x)", parameter, (int32) (variables + parameter));
|
||||
PUSHONSTACK((int32) (variables + parameter));
|
||||
debug(5, "Push address of local variable %d (%x)", parameter, memory->ptrToInt((const uint8 *) (variables + parameter)));
|
||||
PUSHONSTACK(memory->ptrToInt((uint8 *) (variables + parameter)));
|
||||
break;
|
||||
case CP_PUSH_INT32:
|
||||
// Push a long word value on to the stack
|
||||
@ -598,14 +589,14 @@ int Logic::runScript(char *scriptData, char *objectData, uint32 *offset) {
|
||||
Read8ip(parameter);
|
||||
|
||||
// ip points to the string
|
||||
PUSHONSTACK((int32) (code + ip));
|
||||
PUSHONSTACK(memory->ptrToInt((const uint8 *) (code + ip)));
|
||||
ip += (parameter + 1);
|
||||
break;
|
||||
case CP_PUSH_DEREFERENCED_STRUCTURE:
|
||||
// Push the address of a dereferenced structure
|
||||
Read32ip(parameter);
|
||||
debug(5, "Push address of far variable (%x)", (int32) (objectData + sizeof(int32) + sizeof(_standardHeader) + sizeof(_object_hub) + parameter));
|
||||
PUSHONSTACK((int32) (objectData + sizeof(int32) + sizeof(_standardHeader) + sizeof(_object_hub) + parameter));
|
||||
debug(5, "Push address of far variable (%x)", memory->ptrToInt((const uint8 *) (objectData + sizeof(int32) + sizeof(_standardHeader) + sizeof(_object_hub) + parameter)));
|
||||
PUSHONSTACK(memory->ptrToInt((const uint8 *) (objectData + sizeof(int32) + sizeof(_standardHeader) + sizeof(_object_hub) + parameter)));
|
||||
break;
|
||||
case OP_GTTHANE:
|
||||
// '>='
|
||||
|
@ -88,6 +88,38 @@ MemoryManager::~MemoryManager(void) {
|
||||
free(_freeMemman);
|
||||
}
|
||||
|
||||
// I don't know about C++, but here's what "C: A Reference Manual" (Harbison &
|
||||
// Steele) has to say:
|
||||
//
|
||||
// "There is no requirement in C that any of the integral types be large enough
|
||||
// to represent a pointer, although C programmers often assume that type long
|
||||
// is large enough, which it is on most computers. In C99, header inttypes.h
|
||||
// may define integer types intptr_t and uintptr_t, which are guaranteed large
|
||||
// enough to hold a pointer as an integer."
|
||||
//
|
||||
// The script engine frequently needs to pass around pointers to various
|
||||
// structures etc. and, and used to do so by casting them to int32 and back
|
||||
// again. Since those pointers always point to memory that belongs to the
|
||||
// memory manager, we can easily represent them as offsets instead.
|
||||
|
||||
int32 MemoryManager::ptrToInt(const uint8 *p) {
|
||||
debug(9, "ptrToInt: %p -> %d", p, p - _freeMemman);
|
||||
|
||||
if (p < _freeMemman || p >= &_freeMemman[MEMORY_POOL])
|
||||
warning("ptrToInt: Converting bad pointer: %p", p);
|
||||
|
||||
return p - _freeMemman;
|
||||
}
|
||||
|
||||
uint8 *MemoryManager::intToPtr(int32 n) {
|
||||
debug(9, "intToPtr: %d -> %p", n, &_freeMemman[n]);
|
||||
|
||||
if (n < 0 || n >= MEMORY_POOL)
|
||||
warning("intToPtr: Converting bad integer: %d", n);
|
||||
|
||||
return &_freeMemman[n];
|
||||
}
|
||||
|
||||
mem *MemoryManager::lowLevelAlloc(uint32 size, uint32 type, uint32 unique_id) {
|
||||
// allocate a block of memory - locked or float
|
||||
|
||||
|
@ -95,6 +95,9 @@ public:
|
||||
MemoryManager(void);
|
||||
~MemoryManager(void);
|
||||
|
||||
int32 ptrToInt(const uint8 *p);
|
||||
uint8 *intToPtr(int32 n);
|
||||
|
||||
mem *allocMemory(uint32 size, uint32 type, uint32 unique_id);
|
||||
void freeMemory(mem *block);
|
||||
void floatMemory(mem *block);
|
||||
|
@ -1156,7 +1156,7 @@ int32 Logic::fnRegisterMouse(int32 *params) {
|
||||
// params: 0 pointer to Object_mouse or 0 for no write to mouse
|
||||
// list
|
||||
|
||||
_vm->registerMouse((Object_mouse *) params[0]);
|
||||
_vm->registerMouse((Object_mouse *) memory->intToPtr(params[0]));
|
||||
return IR_CONT;
|
||||
}
|
||||
|
||||
@ -1181,7 +1181,7 @@ int32 Logic::fnRegisterPointerText(int32 *params) {
|
||||
int32 Logic::fnInitFloorMouse(int32 *params) {
|
||||
// params: 0 pointer to object's mouse structure
|
||||
|
||||
Object_mouse *ob_mouse = (Object_mouse *) params[0];
|
||||
Object_mouse *ob_mouse = (Object_mouse *) memory->intToPtr(params[0]);
|
||||
|
||||
// floor is always lowest priority
|
||||
|
||||
@ -1200,7 +1200,7 @@ int32 Logic::fnInitFloorMouse(int32 *params) {
|
||||
int32 Logic::fnSetScrollLeftMouse(int32 *params) {
|
||||
// params: 0 pointer to object's mouse structure
|
||||
|
||||
Object_mouse *ob_mouse = (Object_mouse *) params[0];
|
||||
Object_mouse *ob_mouse = (Object_mouse *) memory->intToPtr(params[0]);
|
||||
|
||||
// Highest priority
|
||||
|
||||
@ -1224,7 +1224,7 @@ int32 Logic::fnSetScrollLeftMouse(int32 *params) {
|
||||
int32 Logic::fnSetScrollRightMouse(int32 *params) {
|
||||
// params: 0 pointer to object's mouse structure
|
||||
|
||||
Object_mouse *ob_mouse = (Object_mouse *) params[0];
|
||||
Object_mouse *ob_mouse = (Object_mouse *) memory->intToPtr(params[0]);
|
||||
|
||||
// Highest priority
|
||||
|
||||
|
@ -557,9 +557,9 @@ int32 Logic::fnPassPlayerSaveData(int32 *params) {
|
||||
|
||||
// copy from player object to savegame header
|
||||
|
||||
memcpy(&_vm->g_header.logic, (uint8 *) params[0], sizeof(Object_logic));
|
||||
memcpy(&_vm->g_header.graphic, (uint8 *) params[1], sizeof(Object_graphic));
|
||||
memcpy(&_vm->g_header.mega, (uint8 *) params[2], sizeof(Object_mega));
|
||||
memcpy(&_vm->g_header.logic, memory->intToPtr(params[0]), sizeof(Object_logic));
|
||||
memcpy(&_vm->g_header.graphic, memory->intToPtr(params[1]), sizeof(Object_graphic));
|
||||
memcpy(&_vm->g_header.mega, memory->intToPtr(params[2]), sizeof(Object_mega));
|
||||
|
||||
// makes no odds
|
||||
return IR_CONT;
|
||||
@ -573,9 +573,9 @@ int32 Logic::fnGetPlayerSaveData(int32 *params) {
|
||||
// 1 pointer to object's graphic structure
|
||||
// 2 pointer to object's mega structure
|
||||
|
||||
Object_logic *ob_logic = (Object_logic *) params[0];
|
||||
Object_graphic *ob_graphic = (Object_graphic *) params[1];
|
||||
Object_mega *ob_mega = (Object_mega *) params[2];
|
||||
Object_logic *ob_logic = (Object_logic *) memory->intToPtr(params[0]);
|
||||
Object_graphic *ob_graphic = (Object_graphic *) memory->intToPtr(params[1]);
|
||||
Object_mega *ob_mega = (Object_mega *) memory->intToPtr(params[2]);
|
||||
|
||||
int32 pars[3];
|
||||
|
||||
|
@ -387,7 +387,7 @@ int32 Logic::fnTheyDoWeWait(int32 *params) {
|
||||
|
||||
res_man->closeResource(target);
|
||||
|
||||
ob_logic = (Object_logic *) params[0];
|
||||
ob_logic = (Object_logic *) memory->intToPtr(params[0]);
|
||||
|
||||
if (!INS_COMMAND && RESULT == 1 && ob_logic->looping == 0) {
|
||||
// first time so set up targets command if target is waiting
|
||||
@ -498,7 +498,7 @@ int32 Logic::fnTimedWait(int32 *params) {
|
||||
_standardHeader *head;
|
||||
int32 target = params[1];
|
||||
|
||||
ob_logic = (Object_logic *) params[0];
|
||||
ob_logic = (Object_logic *) memory->intToPtr(params[0]);
|
||||
|
||||
if (!ob_logic->looping)
|
||||
ob_logic->looping = params[2]; // first time in
|
||||
@ -580,7 +580,7 @@ int32 Logic::fnSpeechProcess(int32 *params) {
|
||||
int32 pars[9];
|
||||
int32 ret;
|
||||
|
||||
ob_speech = (Object_speech *) params[1];
|
||||
ob_speech = (Object_speech *) memory->intToPtr(params[1]);
|
||||
|
||||
debug(5, " SP");
|
||||
|
||||
@ -896,8 +896,8 @@ int32 Logic::fnISpeak(int32 *params) {
|
||||
|
||||
// set up the pointers which we know we'll always need
|
||||
|
||||
ob_logic = (Object_logic *) params[S_OB_LOGIC];
|
||||
ob_graphic = (Object_graphic *) params[S_OB_GRAPHIC];
|
||||
ob_logic = (Object_logic *) memory->intToPtr(params[S_OB_LOGIC]);
|
||||
ob_graphic = (Object_graphic *) memory->intToPtr(params[S_OB_GRAPHIC]);
|
||||
|
||||
// FIRST TIME ONLY: create the text, load the wav, set up the anim,
|
||||
// etc.
|
||||
@ -1039,10 +1039,10 @@ int32 Logic::fnISpeak(int32 *params) {
|
||||
// use this direction table to derive the anim
|
||||
// NB. ASSUMES WE HAVE A MEGA OBJECT!!
|
||||
|
||||
ob_mega = (Object_mega*) params[S_OB_MEGA];
|
||||
ob_mega = (Object_mega *) memory->intToPtr(params[S_OB_MEGA]);
|
||||
|
||||
// pointer to anim table
|
||||
anim_table = (int32 *) params[S_DIR_TABLE];
|
||||
anim_table = (int32 *) memory->intToPtr(params[S_DIR_TABLE]);
|
||||
|
||||
// appropriate anim resource is in 'table[direction]'
|
||||
_animId = anim_table[ob_mega->current_dir];
|
||||
@ -1373,7 +1373,7 @@ void Logic::locateTalker(int32 *params) {
|
||||
|
||||
if (cdt_entry->frameType & FRAME_OFFSET) {
|
||||
// this may be NULL
|
||||
ob_mega = (Object_mega*) params[S_OB_MEGA];
|
||||
ob_mega = (Object_mega *) memory->intToPtr(params[S_OB_MEGA]);
|
||||
|
||||
// calc scale at which to print the sprite, based on
|
||||
// feet y-coord & scaling constants (NB. 'scale' is
|
||||
@ -1446,7 +1446,7 @@ void Logic::formText(int32 *params) {
|
||||
// text
|
||||
|
||||
if (params[S_TEXT]) {
|
||||
ob_speech = (Object_speech *) params[S_OB_SPEECH];
|
||||
ob_speech = (Object_speech *) memory->intToPtr(params[S_OB_SPEECH]);
|
||||
|
||||
// establish the max width allowed for this text sprite
|
||||
|
||||
|
@ -141,7 +141,7 @@ int32 Logic::fnRegisterStartPoint(int32 *params) {
|
||||
error("ERROR: _startList full");
|
||||
|
||||
// +1 to allow for NULL terminator
|
||||
if (strlen((char*) params[1]) + 1 > MAX_description)
|
||||
if (strlen((const char *) memory->intToPtr(params[1])) + 1 > MAX_description)
|
||||
error("ERROR: startup description too long");
|
||||
#endif
|
||||
|
||||
@ -152,7 +152,7 @@ int32 Logic::fnRegisterStartPoint(int32 *params) {
|
||||
// the correct start
|
||||
_startList[_totalStartups].key = params[0];
|
||||
|
||||
strcpy(_startList[_totalStartups].description, (char*) params[1]);
|
||||
strcpy(_startList[_totalStartups].description, (const char *) memory->intToPtr(params[1]));
|
||||
|
||||
// point to next
|
||||
_totalStartups++;
|
||||
|
@ -60,9 +60,9 @@ int32 Logic::fnWalk(int32 *params) {
|
||||
|
||||
// get the parameters
|
||||
|
||||
ob_logic = (Object_logic *) params[0];
|
||||
ob_graph = (Object_graphic *) params[1];
|
||||
ob_mega = (Object_mega *) params[2];
|
||||
ob_logic = (Object_logic *) memory->intToPtr(params[0]);
|
||||
ob_graph = (Object_graphic *) memory->intToPtr(params[1]);
|
||||
ob_mega = (Object_mega *) memory->intToPtr(params[2]);
|
||||
|
||||
target_x = (int16) params[4];
|
||||
target_y = (int16) params[5];
|
||||
@ -88,7 +88,7 @@ int32 Logic::fnWalk(int32 *params) {
|
||||
if (params[6] < 0 || params[6] > 8)
|
||||
error("Invalid direction (%d) in fnWalk", params[6]);
|
||||
|
||||
ob_walkdata = (Object_walkdata *) params[3];
|
||||
ob_walkdata = (Object_walkdata *) memory->intToPtr(params[3]);
|
||||
|
||||
ob_mega->walk_pc = 0; // always
|
||||
|
||||
@ -170,7 +170,7 @@ int32 Logic::fnWalk(int32 *params) {
|
||||
if (checkEventWaiting()) {
|
||||
if (walkAnim[walk_pc].step == 0 && walkAnim[walk_pc + 1].step == 1) {
|
||||
// at the beginning of a step
|
||||
ob_walkdata = (Object_walkdata *) params[3];
|
||||
ob_walkdata = (Object_walkdata *) memory->intToPtr(params[3]);
|
||||
_router->earlySlowOut(ob_mega, ob_walkdata);
|
||||
}
|
||||
}
|
||||
@ -255,7 +255,7 @@ int32 Logic::fnWalkToAnim(int32 *params) {
|
||||
|
||||
// if this is the start of the walk, read anim file to get start coords
|
||||
|
||||
ob_logic = (Object_logic *) params[0];
|
||||
ob_logic = (Object_logic *) memory->intToPtr(params[0]);
|
||||
|
||||
if (ob_logic->looping == 0) {
|
||||
// open anim file
|
||||
@ -320,13 +320,13 @@ int32 Logic::fnTurn(int32 *params) {
|
||||
// if this is the start of the turn, get the mega's current feet
|
||||
// coords + the required direction
|
||||
|
||||
ob_logic = (Object_logic *) params[0];
|
||||
ob_logic = (Object_logic *) memory->intToPtr(params[0]);
|
||||
|
||||
if (ob_logic->looping == 0) {
|
||||
if (params[4] < 0 || params[4] > 7)
|
||||
error("Invalid direction (%d) in fnTurn", params[4]);
|
||||
|
||||
ob_mega = (Object_mega *) params[2];
|
||||
ob_mega = (Object_mega *) memory->intToPtr(params[2]);
|
||||
|
||||
pars[4] = ob_mega->feet_x;
|
||||
pars[5] = ob_mega->feet_y;
|
||||
@ -367,8 +367,8 @@ int32 Logic::fnStandAt(int32 *params) {
|
||||
|
||||
// set up pointers to the graphic & mega structure
|
||||
|
||||
ob_graph = (Object_graphic *) params[0];
|
||||
ob_mega = (Object_mega *) params[1];
|
||||
ob_graph = (Object_graphic *) memory->intToPtr(params[0]);
|
||||
ob_mega = (Object_mega *) memory->intToPtr(params[1]);
|
||||
|
||||
// set up the stand frame & set the mega's new direction
|
||||
|
||||
@ -394,7 +394,7 @@ int32 Logic::fnStand(int32 *params) {
|
||||
// 1 pointer to object's mega structure
|
||||
// 2 target direction
|
||||
|
||||
Object_mega *ob_mega = (Object_mega *) params[1];
|
||||
Object_mega *ob_mega = (Object_mega *) memory->intToPtr(params[1]);
|
||||
int32 pars[5];
|
||||
|
||||
pars[0] = params[0];
|
||||
@ -556,10 +556,10 @@ int32 Logic::fnFaceXY(int32 *params) {
|
||||
// if this is the start of the turn, get the mega's current feet
|
||||
// coords + the required direction
|
||||
|
||||
ob_logic = (Object_logic *) params[0];
|
||||
ob_logic = (Object_logic *) memory->intToPtr(params[0]);
|
||||
|
||||
if (ob_logic->looping == 0) {
|
||||
ob_mega = (Object_mega *) params[2];
|
||||
ob_mega = (Object_mega *) memory->intToPtr(params[2]);
|
||||
|
||||
pars[4] = ob_mega->feet_x;
|
||||
pars[5] = ob_mega->feet_y;
|
||||
@ -591,8 +591,8 @@ int32 Logic::fnFaceMega(int32 *params) {
|
||||
Object_mega *ob_mega;
|
||||
_standardHeader *head;
|
||||
|
||||
ob_mega = (Object_mega *) params[2];
|
||||
ob_logic = (Object_logic *) params[0];
|
||||
ob_mega = (Object_mega *) memory->intToPtr(params[2]);
|
||||
ob_logic = (Object_logic *) memory->intToPtr(params[0]);
|
||||
|
||||
if (ob_logic->looping == 0) {
|
||||
// get targets info
|
||||
@ -647,8 +647,8 @@ int32 Logic::fnWalkToTalkToMega(int32 *params) {
|
||||
int mega_separation = params[5];
|
||||
_standardHeader *head;
|
||||
|
||||
ob_logic = (Object_logic*) params[0];
|
||||
ob_mega = (Object_mega*) params[2];
|
||||
ob_logic = (Object_logic *) memory->intToPtr(params[0]);
|
||||
ob_mega = (Object_mega *) memory->intToPtr(params[2]);
|
||||
|
||||
pars[0] = params[0]; // standard stuff
|
||||
pars[1] = params[1];
|
||||
@ -771,7 +771,7 @@ int32 Logic::fnSetScaling(int32 *params) {
|
||||
// where s is system scale, which itself is (256 * actual_scale) ie.
|
||||
// s == 128 is half size
|
||||
|
||||
Object_mega *ob_mega = (Object_mega *) params[0];
|
||||
Object_mega *ob_mega = (Object_mega *) memory->intToPtr(params[0]);
|
||||
|
||||
ob_mega->scale_a = params[1];
|
||||
ob_mega->scale_b = params[2];
|
||||
|
Loading…
Reference in New Issue
Block a user