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