mirror of
https://github.com/dhewm/dhewm3-sdk.git
synced 2025-05-31 09:01:09 +00:00
Fix script interpreter stack for x86_64
Alot of stack and event variables are pointers. Align the size of all script and event variable types to sizeof(intptr_t) so that the CPU needs only one fetch insn on 64bit archs. Tested on x86 and x86_64 and found no different script behaviours compared to the binary from id. Savegames on x86_64 do work, but are not compatible to x86 and vice versa (among other issues, the stack is written to file as-is). x86 builds can still load savegames from the official binary and vice versa.
This commit is contained in:
parent
dc86a8a02c
commit
f8efcf5e90
12 changed files with 240 additions and 110 deletions
|
@ -30,7 +30,7 @@ If you have questions concerning this license or the applicable additional terms
|
|||
#define __SCRIPT_INTERPRETER_H__
|
||||
|
||||
#define MAX_STACK_DEPTH 64
|
||||
#define LOCALSTACK_SIZE 6144
|
||||
#define LOCALSTACK_SIZE (6144 * 2)
|
||||
|
||||
typedef struct prstack_s {
|
||||
int s;
|
||||
|
@ -60,7 +60,8 @@ private:
|
|||
|
||||
void PopParms( int numParms );
|
||||
void PushString( const char *string );
|
||||
void Push( int value );
|
||||
void PushVector( const idVec3 &vector );
|
||||
void Push( intptr_t value );
|
||||
const char *FloatToString( float value );
|
||||
void AppendString( idVarDef *def, const char *from );
|
||||
void SetString( idVarDef *def, const char *from );
|
||||
|
@ -135,12 +136,25 @@ ID_INLINE void idInterpreter::PopParms( int numParms ) {
|
|||
idInterpreter::Push
|
||||
====================
|
||||
*/
|
||||
ID_INLINE void idInterpreter::Push( int value ) {
|
||||
if ( localstackUsed + sizeof( int ) > LOCALSTACK_SIZE ) {
|
||||
ID_INLINE void idInterpreter::Push( intptr_t value ) {
|
||||
if ( localstackUsed + sizeof( intptr_t ) > LOCALSTACK_SIZE ) {
|
||||
Error( "Push: locals stack overflow\n" );
|
||||
}
|
||||
*( int * )&localstack[ localstackUsed ] = value;
|
||||
localstackUsed += sizeof( int );
|
||||
*( intptr_t * )&localstack[ localstackUsed ] = value;
|
||||
localstackUsed += sizeof( intptr_t );
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
idInterpreter::PushVector
|
||||
====================
|
||||
*/
|
||||
ID_INLINE void idInterpreter::PushVector( const idVec3 &vector ) {
|
||||
if ( localstackUsed + E_EVENT_SIZEOF_VEC > LOCALSTACK_SIZE ) {
|
||||
Error( "Push: locals stack overflow\n" );
|
||||
}
|
||||
*( idVec3 * )&localstack[ localstackUsed ] = vector;
|
||||
localstackUsed += E_EVENT_SIZEOF_VEC;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue