From 8607441e64d02aa5d6d4089b3bb58a9600d4583d Mon Sep 17 00:00:00 2001 From: Per Inge Mathisen Date: Tue, 18 Jan 2011 22:05:26 +0100 Subject: [PATCH] Lift restriction on 2000 globals in scripts in total by rewriting some code to use std::list. Patch reviewed by Cyp. --- src/scriptvals.cpp | 64 ++++++++++------------------------------------ 1 file changed, 13 insertions(+), 51 deletions(-) diff --git a/src/scriptvals.cpp b/src/scriptvals.cpp index 3cedc73dc..fab3eba8f 100644 --- a/src/scriptvals.cpp +++ b/src/scriptvals.cpp @@ -25,6 +25,7 @@ */ #include +#include #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::listbasePointers; // 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,63 +119,31 @@ 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; iv.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) {