Lift restriction on 2000 globals in scripts in total by rewriting some code to use std::list. Patch reviewed by Cyp.

master
Per Inge Mathisen 2011-01-18 22:05:26 +01:00
parent 36fddc036e
commit 8607441e64
1 changed files with 13 additions and 51 deletions

View File

@ -25,6 +25,7 @@
*/ */
#include <string.h> #include <string.h>
#include <list>
#include "lib/framework/frame.h" #include "lib/framework/frame.h"
#include "lib/script/script.h" #include "lib/script/script.h"
@ -48,16 +49,13 @@ typedef struct _scrv_store
// The list of script contexts // The list of script contexts
static SCRV_STORE *psContextStore=NULL; static SCRV_STORE *psContextStore=NULL;
// keep a note of all base object pointers // Copy of all references to game objects, so that we can NULL them on death...
#define MAX_BASEPOINTER 2000 //200 - local variables require more of these ("run" error) static std::list<INTERP_VAL *>basePointers;
static INTERP_VAL *asBasePointers[MAX_BASEPOINTER];
// Initialise the script value module // Initialise the script value module
BOOL scrvInitialise(void) BOOL scrvInitialise(void)
{ {
psContextStore = NULL; psContextStore = NULL;
memset(asBasePointers, 0, sizeof(asBasePointers));
return true; return true;
} }
@ -75,7 +73,6 @@ void scrvShutDown(void)
} }
} }
// reset the script value module // reset the script value module
void scrvReset(void) void scrvReset(void)
{ {
@ -90,10 +87,9 @@ void scrvReset(void)
} }
psContextStore = NULL; psContextStore = NULL;
memset(asBasePointers, 0, sizeof(asBasePointers)); basePointers.clear();
} }
// Add a new context to the list // Add a new context to the list
BOOL scrvAddContext(char *pID, SCRIPT_CONTEXT *psContext, SCRV_TYPE type) BOOL scrvAddContext(char *pID, SCRIPT_CONTEXT *psContext, SCRV_TYPE type)
{ {
@ -123,63 +119,31 @@ BOOL scrvAddContext(char *pID, SCRIPT_CONTEXT *psContext, SCRV_TYPE type)
return true; return true;
} }
// Add a new base pointer variable // Add a new base pointer variable
BOOL scrvAddBasePointer(INTERP_VAL *psVal) BOOL scrvAddBasePointer(INTERP_VAL *psVal)
{ {
SDWORD i; basePointers.push_back(psVal);
for(i=0; i<MAX_BASEPOINTER; i++)
{
if (asBasePointers[i] == NULL)
{
asBasePointers[i] = psVal;
return true; return true;
}
}
ASSERT(false, "scrvAddBasePointer: not enough base pointers left (total :%d)", MAX_BASEPOINTER);
return false;
} }
// remove a base pointer from the list // remove a base pointer from the list
void scrvReleaseBasePointer(INTERP_VAL *psVal) void scrvReleaseBasePointer(INTERP_VAL *psVal)
{ {
SDWORD i; basePointers.remove(psVal);
for(i=0; i<MAX_BASEPOINTER; i++)
{
if (asBasePointers[i] == psVal)
{
asBasePointers[i] = NULL;
return;
}
}
} }
static bool baseObjDead(const INTERP_VAL *val)
{
BASE_OBJECT *psObj = (BASE_OBJECT *)val->v.oval;
return (psObj && isDead(psObj));
}
// Check all the base pointers to see if they have died // Check all the base pointers to see if they have died
void scrvUpdateBasePointers(void) void scrvUpdateBasePointers(void)
{ {
unsigned int i; basePointers.remove_if(baseObjDead);
for(i = 0; i < MAX_BASEPOINTER; i++)
{
if (asBasePointers[i] != NULL)
{
INTERP_VAL *psVal = asBasePointers[i];
BASE_OBJECT *psObj = (BASE_OBJECT *)psVal->v.oval;
if (psObj && isDead(psObj))
{
psVal->v.oval = NULL;
}
}
}
} }
// create a group structure for a ST_GROUP variable // create a group structure for a ST_GROUP variable
BOOL scrvNewGroup(INTERP_VAL *psVal) BOOL scrvNewGroup(INTERP_VAL *psVal)
{ {
@ -198,7 +162,6 @@ BOOL scrvNewGroup(INTERP_VAL *psVal)
return true; return true;
} }
// release a ST_GROUP variable // release a ST_GROUP variable
void scrvReleaseGroup(INTERP_VAL *psVal) void scrvReleaseGroup(INTERP_VAL *psVal)
{ {
@ -214,7 +177,6 @@ void scrvReleaseGroup(INTERP_VAL *psVal)
grpLeave(psGroup, NULL); grpLeave(psGroup, NULL);
} }
// Get a context from the list // Get a context from the list
BOOL scrvGetContext(char *pID, SCRIPT_CONTEXT **ppsContext) BOOL scrvGetContext(char *pID, SCRIPT_CONTEXT **ppsContext)
{ {