mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 13:47:58 +03:00
Used clang-format on some common files
This commit is contained in:
parent
37d8938e91
commit
68d48d9889
27 changed files with 7275 additions and 8076 deletions
|
@ -2054,6 +2054,7 @@ static int yy_get_next_buffer (void)
|
|||
#else
|
||||
static int input (void)
|
||||
#endif
|
||||
|
||||
{
|
||||
int c;
|
||||
|
||||
|
@ -2241,6 +2242,7 @@ static void yy_load_buffer_state (void)
|
|||
* such as during a yyrestart() or at EOF.
|
||||
*/
|
||||
static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file )
|
||||
|
||||
{
|
||||
int oerrno = errno;
|
||||
|
||||
|
|
|
@ -26,73 +26,76 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
#include "../fgame/gamecvars.h"
|
||||
#include "../qcommon/mem_tempalloc.h"
|
||||
|
||||
MEM_TempAlloc parsetree_allocator;
|
||||
MEM_TempAlloc parsetree_allocator;
|
||||
yyparsedata parsedata;
|
||||
sval_u node_none = {0};
|
||||
|
||||
yyparsedata parsedata;
|
||||
sval_u node_none = { 0 };
|
||||
char *str_replace(char *orig, const char *rep, const char *with)
|
||||
{
|
||||
char *result; // the return string
|
||||
char *ins; // the next insert point
|
||||
char *tmp; // varies
|
||||
size_t len_rep; // length of rep
|
||||
size_t len_with; // length of with
|
||||
size_t len_front; // distance between rep and end of last rep
|
||||
int count; // number of replacements
|
||||
|
||||
char* str_replace(char* orig, const char* rep, const char* with) {
|
||||
char* result; // the return string
|
||||
char* ins; // the next insert point
|
||||
char* tmp; // varies
|
||||
size_t len_rep; // length of rep
|
||||
size_t len_with; // length of with
|
||||
size_t len_front; // distance between rep and end of last rep
|
||||
int count; // number of replacements
|
||||
if (!orig) {
|
||||
return NULL;
|
||||
}
|
||||
if (!rep) {
|
||||
rep = "";
|
||||
}
|
||||
len_rep = strlen(rep);
|
||||
if (!with) {
|
||||
with = "";
|
||||
}
|
||||
len_with = strlen(with);
|
||||
|
||||
if (!orig)
|
||||
return NULL;
|
||||
if (!rep)
|
||||
rep = "";
|
||||
len_rep = strlen(rep);
|
||||
if (!with)
|
||||
with = "";
|
||||
len_with = strlen(with);
|
||||
ins = orig;
|
||||
for (count = 0; (tmp = strstr(ins, rep)) != nullptr; ++count) {
|
||||
ins = tmp + len_rep;
|
||||
}
|
||||
|
||||
ins = orig;
|
||||
for (count = 0; (tmp = strstr(ins, rep)) != nullptr; ++count) {
|
||||
ins = tmp + len_rep;
|
||||
}
|
||||
// first time through the loop, all the variable are set correctly
|
||||
// from here on,
|
||||
// tmp points to the end of the result string
|
||||
// ins points to the next occurrence of rep in orig
|
||||
// orig points to the remainder of orig after "end of rep"
|
||||
tmp = result = (char *)parsetree_allocator.Alloc(strlen(orig) + (len_with - len_rep) * count + 1);
|
||||
|
||||
// first time through the loop, all the variable are set correctly
|
||||
// from here on,
|
||||
// tmp points to the end of the result string
|
||||
// ins points to the next occurrence of rep in orig
|
||||
// orig points to the remainder of orig after "end of rep"
|
||||
tmp = result = (char*)parsetree_allocator.Alloc(strlen(orig) + (len_with - len_rep) * count + 1);
|
||||
if (!result) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
||||
while (count--) {
|
||||
ins = strstr(orig, rep);
|
||||
len_front = ins - orig;
|
||||
tmp = strncpy(tmp, orig, len_front) + len_front;
|
||||
tmp = strcpy(tmp, with) + len_with;
|
||||
orig += len_front + len_rep; // move to next "end of rep"
|
||||
}
|
||||
strcpy(tmp, orig);
|
||||
return result;
|
||||
while (count--) {
|
||||
ins = strstr(orig, rep);
|
||||
len_front = ins - orig;
|
||||
tmp = strncpy(tmp, orig, len_front) + len_front;
|
||||
tmp = strcpy(tmp, with) + len_with;
|
||||
orig += len_front + len_rep; // move to next "end of rep"
|
||||
}
|
||||
strcpy(tmp, orig);
|
||||
return result;
|
||||
}
|
||||
|
||||
void parsetree_freeall()
|
||||
{
|
||||
parsetree_allocator.FreeAll();
|
||||
parsetree_allocator.FreeAll();
|
||||
|
||||
if (g_showopcodes->integer)
|
||||
{
|
||||
gi.DPrintf("%d bytes freed\n", parsedata.total_length);
|
||||
}
|
||||
if (g_showopcodes->integer) {
|
||||
gi.DPrintf("%d bytes freed\n", parsedata.total_length);
|
||||
}
|
||||
}
|
||||
|
||||
void parsetree_init()
|
||||
{
|
||||
parsedata.total_length = 0;
|
||||
parsedata.total_length = 0;
|
||||
}
|
||||
|
||||
size_t parsetree_length()
|
||||
{
|
||||
return parsedata.total_length;
|
||||
return parsedata.total_length;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -129,216 +132,213 @@ char* parsetree_string(const char* string)
|
|||
extern size_t yyleng;
|
||||
extern size_t prev_yyleng;
|
||||
|
||||
char* parsetree_malloc(size_t s)
|
||||
char *parsetree_malloc(size_t s)
|
||||
{
|
||||
parsedata.total_length += s;
|
||||
return (char*)parsetree_allocator.Alloc(s);
|
||||
parsedata.total_length += s;
|
||||
return (char *)parsetree_allocator.Alloc(s);
|
||||
}
|
||||
|
||||
sval_u append_lists(sval_u val1, sval_u val2)
|
||||
{
|
||||
val1.node[1].node[1] = val2.node[0];
|
||||
val1.node[1] = val2.node[1];
|
||||
val1.node[1].node[1] = val2.node[0];
|
||||
val1.node[1] = val2.node[1];
|
||||
|
||||
return val1;
|
||||
return val1;
|
||||
}
|
||||
|
||||
sval_u append_node(sval_u val1, sval_u val2)
|
||||
{
|
||||
sval_u* node;
|
||||
sval_u *node;
|
||||
|
||||
node = (sval_u*)parsetree_malloc(sizeof(sval_t[2]));
|
||||
node = (sval_u *)parsetree_malloc(sizeof(sval_t[2]));
|
||||
|
||||
node[1].node = NULL;
|
||||
node[0] = val2;
|
||||
node[1].node = NULL;
|
||||
node[0] = val2;
|
||||
|
||||
val1.node[1].node[1].node = node;
|
||||
val1.node[1].node = node;
|
||||
val1.node[1].node[1].node = node;
|
||||
val1.node[1].node = node;
|
||||
|
||||
return val1;
|
||||
return val1;
|
||||
}
|
||||
|
||||
sval_u prepend_node(sval_u val1, sval_u val2)
|
||||
{
|
||||
sval_u* node;
|
||||
sval_u *node;
|
||||
|
||||
node = (sval_u*)parsetree_malloc(sizeof(sval_t[2]));
|
||||
node = (sval_u *)parsetree_malloc(sizeof(sval_t[2]));
|
||||
|
||||
node[0] = val1;
|
||||
node[1] = val2;
|
||||
node[0] = val1;
|
||||
node[1] = val2;
|
||||
|
||||
val2.node = node;
|
||||
val2.node = node;
|
||||
|
||||
return val2;
|
||||
return val2;
|
||||
}
|
||||
|
||||
sval_u linked_list_end(sval_u val)
|
||||
{
|
||||
sval_u* node;
|
||||
sval_u end;
|
||||
sval_u *node;
|
||||
sval_u end;
|
||||
|
||||
node = (sval_u*)parsetree_malloc(sizeof(sval_t[2]));
|
||||
node = (sval_u *)parsetree_malloc(sizeof(sval_t[2]));
|
||||
|
||||
node[0] = val;
|
||||
node[1].node = NULL;
|
||||
node[0] = val;
|
||||
node[1].node = NULL;
|
||||
|
||||
end.node = (sval_u*)parsetree_malloc(sizeof(sval_t[2]));
|
||||
end.node = (sval_u *)parsetree_malloc(sizeof(sval_t[2]));
|
||||
|
||||
end.node[0].node = node;
|
||||
end.node[1].node = node;
|
||||
end.node[0].node = node;
|
||||
end.node[1].node = node;
|
||||
|
||||
return end;
|
||||
return end;
|
||||
}
|
||||
|
||||
sval_u node1_(int val1)
|
||||
{
|
||||
sval_u val;
|
||||
sval_u val;
|
||||
|
||||
val.intValue = val1;
|
||||
val.intValue = val1;
|
||||
|
||||
return val;
|
||||
return val;
|
||||
}
|
||||
|
||||
sval_u node1b(int val1)
|
||||
{
|
||||
sval_u val;
|
||||
sval_u val;
|
||||
|
||||
val.byteValue = val1;
|
||||
val.byteValue = val1;
|
||||
|
||||
return val;
|
||||
return val;
|
||||
}
|
||||
|
||||
sval_u node_pos(unsigned int pos)
|
||||
{
|
||||
sval_u val;
|
||||
sval_u val;
|
||||
|
||||
val.sourcePosValue = pos;
|
||||
val.sourcePosValue = pos;
|
||||
|
||||
return val;
|
||||
return val;
|
||||
}
|
||||
|
||||
sval_u node_string(char* text)
|
||||
sval_u node_string(char *text)
|
||||
{
|
||||
sval_u val;
|
||||
sval_u val;
|
||||
|
||||
val.stringValue = text;
|
||||
val.stringValue = text;
|
||||
|
||||
return val;
|
||||
return val;
|
||||
}
|
||||
|
||||
sval_u node0(int type)
|
||||
{
|
||||
sval_u val;
|
||||
sval_u val;
|
||||
|
||||
if (type == sval_none)
|
||||
{
|
||||
// memory optimization
|
||||
val.node = &node_none;
|
||||
}
|
||||
else
|
||||
{
|
||||
val.node = (sval_u*)parsetree_malloc(sizeof(sval_u));
|
||||
if (type == sval_none) {
|
||||
// memory optimization
|
||||
val.node = &node_none;
|
||||
} else {
|
||||
val.node = (sval_u *)parsetree_malloc(sizeof(sval_u));
|
||||
|
||||
val.node[0].node = NULL;
|
||||
val.node[0].type = type;
|
||||
}
|
||||
val.node[0].node = NULL;
|
||||
val.node[0].type = type;
|
||||
}
|
||||
|
||||
return val;
|
||||
return val;
|
||||
}
|
||||
|
||||
sval_u node1(int type, sval_u val1)
|
||||
{
|
||||
sval_u val;
|
||||
sval_u val;
|
||||
|
||||
val.node = (sval_u*)parsetree_malloc(sizeof(sval_u[2]));
|
||||
val.node = (sval_u *)parsetree_malloc(sizeof(sval_u[2]));
|
||||
|
||||
val.node[0].type = type;
|
||||
val.node[1] = val1;
|
||||
val.node[0].type = type;
|
||||
val.node[1] = val1;
|
||||
|
||||
return val;
|
||||
return val;
|
||||
}
|
||||
|
||||
sval_u node2(int type, sval_u val1, sval_u val2)
|
||||
{
|
||||
sval_u val;
|
||||
sval_u val;
|
||||
|
||||
assert(type != sval_none);
|
||||
assert(type != sval_none);
|
||||
|
||||
val.node = (sval_u*)parsetree_malloc(sizeof(sval_t[3]));
|
||||
val.node = (sval_u *)parsetree_malloc(sizeof(sval_t[3]));
|
||||
|
||||
val.node[0].type = type;
|
||||
val.node[1] = val1;
|
||||
val.node[2] = val2;
|
||||
val.node[0].type = type;
|
||||
val.node[1] = val1;
|
||||
val.node[2] = val2;
|
||||
|
||||
return val;
|
||||
return val;
|
||||
}
|
||||
|
||||
sval_u node3(int type, sval_u val1, sval_u val2, sval_u val3)
|
||||
{
|
||||
sval_u val;
|
||||
sval_u val;
|
||||
|
||||
assert(type != sval_none);
|
||||
assert(type != sval_none);
|
||||
|
||||
val.node = (sval_u*)parsetree_malloc(sizeof(sval_t[4]));
|
||||
val.node = (sval_u *)parsetree_malloc(sizeof(sval_t[4]));
|
||||
|
||||
val.node[0].type = type;
|
||||
val.node[1] = val1;
|
||||
val.node[2] = val2;
|
||||
val.node[3] = val3;
|
||||
val.node[0].type = type;
|
||||
val.node[1] = val1;
|
||||
val.node[2] = val2;
|
||||
val.node[3] = val3;
|
||||
|
||||
return val;
|
||||
return val;
|
||||
}
|
||||
|
||||
sval_u node4(int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4)
|
||||
{
|
||||
sval_u val;
|
||||
sval_u val;
|
||||
|
||||
assert(type != sval_none);
|
||||
assert(type != sval_none);
|
||||
|
||||
val.node = (sval_u*)parsetree_malloc(sizeof(sval_t[5]));
|
||||
val.node = (sval_u *)parsetree_malloc(sizeof(sval_t[5]));
|
||||
|
||||
val.node[0].type = type;
|
||||
val.node[1] = val1;
|
||||
val.node[2] = val2;
|
||||
val.node[3] = val3;
|
||||
val.node[4] = val4;
|
||||
val.node[0].type = type;
|
||||
val.node[1] = val1;
|
||||
val.node[2] = val2;
|
||||
val.node[3] = val3;
|
||||
val.node[4] = val4;
|
||||
|
||||
return val;
|
||||
return val;
|
||||
}
|
||||
|
||||
sval_u node5(int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4, sval_u val5)
|
||||
{
|
||||
sval_u val;
|
||||
sval_u val;
|
||||
|
||||
assert(type != sval_none);
|
||||
assert(type != sval_none);
|
||||
|
||||
val.node = (sval_u*)parsetree_malloc(sizeof(sval_t[6]));
|
||||
val.node = (sval_u *)parsetree_malloc(sizeof(sval_t[6]));
|
||||
|
||||
val.node[0].type = type;
|
||||
val.node[1] = val1;
|
||||
val.node[2] = val2;
|
||||
val.node[3] = val3;
|
||||
val.node[4] = val4;
|
||||
val.node[5] = val5;
|
||||
val.node[0].type = type;
|
||||
val.node[1] = val1;
|
||||
val.node[2] = val2;
|
||||
val.node[3] = val3;
|
||||
val.node[4] = val4;
|
||||
val.node[5] = val5;
|
||||
|
||||
return val;
|
||||
return val;
|
||||
}
|
||||
|
||||
sval_u node6(int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4, sval_u val5, sval_u val6)
|
||||
{
|
||||
sval_u val;
|
||||
sval_u val;
|
||||
|
||||
assert(type != sval_none);
|
||||
assert(type != sval_none);
|
||||
|
||||
val.node = (sval_u*)parsetree_malloc(sizeof(sval_t[7]));
|
||||
val.node = (sval_u *)parsetree_malloc(sizeof(sval_t[7]));
|
||||
|
||||
val.node[0].type = type;
|
||||
val.node[1] = val1;
|
||||
val.node[2] = val2;
|
||||
val.node[3] = val3;
|
||||
val.node[4] = val4;
|
||||
val.node[5] = val5;
|
||||
val.node[6] = val6;
|
||||
val.node[0].type = type;
|
||||
val.node[1] = val1;
|
||||
val.node[2] = val2;
|
||||
val.node[3] = val3;
|
||||
val.node[4] = val4;
|
||||
val.node[5] = val5;
|
||||
val.node[6] = val6;
|
||||
|
||||
return val;
|
||||
return val;
|
||||
}
|
||||
|
|
|
@ -26,121 +26,125 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
#include "str.h"
|
||||
|
||||
#if defined ( GAME_DLL )
|
||||
#define showopcodes g_showopcodes
|
||||
#elif defined( CGAME_DLL )
|
||||
#define showopcodes cg_showopcodes
|
||||
#if defined(GAME_DLL)
|
||||
# define showopcodes g_showopcodes
|
||||
#elif defined(CGAME_DLL)
|
||||
# define showopcodes cg_showopcodes
|
||||
#else
|
||||
#define showopcodes g_showopcodes
|
||||
# define showopcodes g_showopcodes
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
sval_none,
|
||||
sval_next,
|
||||
sval_statement_list,
|
||||
sval_label,
|
||||
sval_case,
|
||||
sval_negative,
|
||||
sval_assignment,
|
||||
sval_if,
|
||||
sval_ifelse,
|
||||
sval_while,
|
||||
sval_and,
|
||||
sval_or,
|
||||
sval_cmd_method,
|
||||
sval_cmd_method_ret,
|
||||
sval_cmd,
|
||||
sval_cmd_default_ret,
|
||||
sval_field,
|
||||
sval_store_method,
|
||||
sval_store_string,
|
||||
sval_store_integer,
|
||||
sval_store_float,
|
||||
sval_calc_vector,
|
||||
sval_store_null,
|
||||
sval_store_nil,
|
||||
sval_func1,
|
||||
sval_operation,
|
||||
sval_not,
|
||||
sval_array,
|
||||
sval_constarray,
|
||||
sval_makearray,
|
||||
sval_catch,
|
||||
sval_switch,
|
||||
sval_break,
|
||||
sval_continue,
|
||||
sval_do,
|
||||
sval_privatelabel,
|
||||
sval_define
|
||||
typedef enum {
|
||||
sval_none,
|
||||
sval_next,
|
||||
sval_statement_list,
|
||||
sval_label,
|
||||
sval_case,
|
||||
sval_negative,
|
||||
sval_assignment,
|
||||
sval_if,
|
||||
sval_ifelse,
|
||||
sval_while,
|
||||
sval_and,
|
||||
sval_or,
|
||||
sval_cmd_method,
|
||||
sval_cmd_method_ret,
|
||||
sval_cmd,
|
||||
sval_cmd_default_ret,
|
||||
sval_field,
|
||||
sval_store_method,
|
||||
sval_store_string,
|
||||
sval_store_integer,
|
||||
sval_store_float,
|
||||
sval_calc_vector,
|
||||
sval_store_null,
|
||||
sval_store_nil,
|
||||
sval_func1,
|
||||
sval_operation,
|
||||
sval_not,
|
||||
sval_array,
|
||||
sval_constarray,
|
||||
sval_makearray,
|
||||
sval_catch,
|
||||
sval_switch,
|
||||
sval_break,
|
||||
sval_continue,
|
||||
sval_do,
|
||||
sval_privatelabel,
|
||||
sval_define
|
||||
} sval_type_e;
|
||||
|
||||
typedef union sval_u {
|
||||
int type;
|
||||
char *stringValue;
|
||||
float floatValue;
|
||||
int intValue;
|
||||
char charValue;
|
||||
unsigned char byteValue;
|
||||
unsigned char *posValue;
|
||||
int MaxVarStackOffset;
|
||||
int HasExternal;
|
||||
union sval_u *node;
|
||||
unsigned int sourcePosValue;
|
||||
int type;
|
||||
char *stringValue;
|
||||
float floatValue;
|
||||
int intValue;
|
||||
char charValue;
|
||||
unsigned char byteValue;
|
||||
unsigned char *posValue;
|
||||
int MaxVarStackOffset;
|
||||
int HasExternal;
|
||||
union sval_u *node;
|
||||
unsigned int sourcePosValue;
|
||||
} sval_t;
|
||||
|
||||
typedef struct {
|
||||
sval_t val;
|
||||
unsigned int sourcePos;
|
||||
sval_t val;
|
||||
unsigned int sourcePos;
|
||||
} stype_t;
|
||||
|
||||
void parsetree_freeall();
|
||||
void parsetree_init();
|
||||
size_t parsetree_length();
|
||||
char *parsetree_malloc( size_t s );
|
||||
void parsetree_freeall();
|
||||
void parsetree_init();
|
||||
size_t parsetree_length();
|
||||
char *parsetree_malloc(size_t s);
|
||||
|
||||
sval_u append_lists(sval_u val1, sval_u val2);
|
||||
sval_u append_node(sval_u val1, sval_u val2);
|
||||
sval_u prepend_node(sval_u val1, sval_u val2);
|
||||
|
||||
sval_u append_lists( sval_u val1, sval_u val2 );
|
||||
sval_u append_node( sval_u val1, sval_u val2 );
|
||||
sval_u prepend_node( sval_u val1, sval_u val2 );
|
||||
sval_u linked_list_end(sval_u val);
|
||||
|
||||
sval_u linked_list_end( sval_u val );
|
||||
sval_u node1_(int val1);
|
||||
sval_u node1b(int val1);
|
||||
sval_u node_pos(unsigned int pos);
|
||||
sval_u node_string(char *text);
|
||||
|
||||
sval_u node1_( int val1 );
|
||||
sval_u node1b( int val1 );
|
||||
sval_u node_pos( unsigned int pos );
|
||||
sval_u node_string( char *text );
|
||||
|
||||
sval_u node0( int type );
|
||||
sval_u node1( int type, sval_u val1 );
|
||||
sval_u node2( int type, sval_u val1, sval_u val2 );
|
||||
sval_u node3( int type, sval_u val1, sval_u val2, sval_u val3 );
|
||||
sval_u node4( int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4 );
|
||||
sval_u node5( int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4, sval_u val5 );
|
||||
sval_u node6( int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4, sval_u val5, sval_u val6 );
|
||||
sval_u node0(int type);
|
||||
sval_u node1(int type, sval_u val1);
|
||||
sval_u node2(int type, sval_u val1, sval_u val2);
|
||||
sval_u node3(int type, sval_u val1, sval_u val2, sval_u val3);
|
||||
sval_u node4(int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4);
|
||||
sval_u node5(int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4, sval_u val5);
|
||||
sval_u node6(int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4, sval_u val5, sval_u val6);
|
||||
|
||||
struct yyexception {
|
||||
int yylineno;
|
||||
str yytext;
|
||||
str yytoken;
|
||||
int yylineno;
|
||||
str yytext;
|
||||
str yytoken;
|
||||
|
||||
yyexception() { yylineno = 0; }
|
||||
yyexception() { yylineno = 0; }
|
||||
};
|
||||
|
||||
struct yyparsedata {
|
||||
size_t total_length;
|
||||
size_t total_length;
|
||||
|
||||
int braces_count;
|
||||
int line_count;
|
||||
unsigned int pos;
|
||||
sval_t val;
|
||||
int braces_count;
|
||||
int line_count;
|
||||
unsigned int pos;
|
||||
sval_t val;
|
||||
|
||||
char *sourceBuffer;
|
||||
class GameScript *gameScript;
|
||||
char *sourceBuffer;
|
||||
class GameScript *gameScript;
|
||||
|
||||
yyexception exc;
|
||||
yyexception exc;
|
||||
|
||||
yyparsedata() { total_length = 0, braces_count = 0, line_count = 0, pos = 0; val = sval_t(); sourceBuffer = NULL; gameScript = NULL; }
|
||||
yyparsedata()
|
||||
{
|
||||
total_length = 0, braces_count = 0, line_count = 0, pos = 0;
|
||||
val = sval_t();
|
||||
sourceBuffer = NULL;
|
||||
gameScript = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
extern yyparsedata parsedata;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -28,30 +28,30 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
//
|
||||
// game dll specific defines
|
||||
//
|
||||
#include "../fgame/g_local.h"
|
||||
# include "../fgame/g_local.h"
|
||||
|
||||
#define CONTAINER_Error gi.Error
|
||||
#define CONTAINER_DPrintf gi.DPrintf
|
||||
#define CONTAINER_WDPrintf(text) gi.DPrintf(text)
|
||||
# define CONTAINER_Error gi.Error
|
||||
# define CONTAINER_DPrintf gi.DPrintf
|
||||
# define CONTAINER_WDPrintf(text) gi.DPrintf(text)
|
||||
|
||||
#elif defined(CGAME_DLL)
|
||||
//
|
||||
// cgame dll specific defines
|
||||
//
|
||||
#include "../cgame/cg_local.h"
|
||||
# include "../cgame/cg_local.h"
|
||||
|
||||
#define CONTAINER_Error cgi.Error
|
||||
#define CONTAINER_DPrintf cgi.DPrintf
|
||||
#define CONTAINER_WDPrintf(text) cgi.DPrintf(text)
|
||||
# define CONTAINER_Error cgi.Error
|
||||
# define CONTAINER_DPrintf cgi.DPrintf
|
||||
# define CONTAINER_WDPrintf(text) cgi.DPrintf(text)
|
||||
|
||||
#else
|
||||
|
||||
//
|
||||
// client specific defines
|
||||
//
|
||||
#define CONTAINER_Error Com_Error
|
||||
#define CONTAINER_DPrintf Com_DPrintf
|
||||
#define CONTAINER_WDPrintf(text) Com_DPrintf(text)
|
||||
# define CONTAINER_Error Com_Error
|
||||
# define CONTAINER_DPrintf Com_DPrintf
|
||||
# define CONTAINER_WDPrintf(text) Com_DPrintf(text)
|
||||
#endif
|
||||
|
||||
class Archiver;
|
||||
|
@ -60,9 +60,9 @@ template<class Type>
|
|||
class Container
|
||||
{
|
||||
private:
|
||||
Type* objlist;
|
||||
int numobjects;
|
||||
int maxobjects;
|
||||
Type *objlist;
|
||||
int numobjects;
|
||||
int maxobjects;
|
||||
|
||||
private:
|
||||
void Copy(const Container<Type>& container);
|
||||
|
@ -73,36 +73,36 @@ public:
|
|||
~Container();
|
||||
|
||||
void Archive(Archiver& arc);
|
||||
void Archive(Archiver& arc, void (*ArchiveFunc)(Archiver& arc, Type* obj));
|
||||
void Archive(Archiver& arc, void (*ArchiveFunc)(Archiver& arc, Type *obj));
|
||||
|
||||
int AddObject(const Type& obj);
|
||||
int AddUniqueObject(const Type& obj);
|
||||
void AddObjectAt(int index, const Type& obj);
|
||||
Type* AddressOfObjectAt(int index);
|
||||
int AddObject(const Type &obj);
|
||||
int AddUniqueObject(const Type &obj);
|
||||
void AddObjectAt(int index, const Type &obj);
|
||||
Type *AddressOfObjectAt(int index);
|
||||
// void Archive( Archiver &arc );
|
||||
void ClearObjectList(void);
|
||||
void Fix(void);
|
||||
void FreeObjectList(void);
|
||||
int IndexOfObject(const Type& obj);
|
||||
void InsertObjectAt(int index, const Type& obj);
|
||||
int MaxObjects(void) const;
|
||||
int NumObjects(void) const;
|
||||
Type& ObjectAt(const size_t index) const;
|
||||
bool ObjectInList(const Type& obj);
|
||||
void RemoveObjectAt(int index);
|
||||
void RemoveObject(const Type& obj);
|
||||
void Reset(void);
|
||||
void Resize(int maxelements);
|
||||
void SetObjectAt(int index, const Type& obj);
|
||||
void Sort(int (*compare)(const void* elem1, const void* elem2));
|
||||
Type& operator[](const int index) const;
|
||||
void ClearObjectList(void);
|
||||
void Fix(void);
|
||||
void FreeObjectList(void);
|
||||
int IndexOfObject(const Type &obj);
|
||||
void InsertObjectAt(int index, const Type &obj);
|
||||
int MaxObjects(void) const;
|
||||
int NumObjects(void) const;
|
||||
Type & ObjectAt(const size_t index) const;
|
||||
bool ObjectInList(const Type &obj);
|
||||
void RemoveObjectAt(int index);
|
||||
void RemoveObject(const Type &obj);
|
||||
void Reset(void);
|
||||
void Resize(int maxelements);
|
||||
void SetObjectAt(int index, const Type &obj);
|
||||
void Sort(int (*compare)(const void *elem1, const void *elem2));
|
||||
Type & operator[](const int index) const;
|
||||
Container<Type>& operator=(const Container<Type>& container);
|
||||
};
|
||||
|
||||
template<class Type>
|
||||
Container<Type>::Container()
|
||||
{
|
||||
objlist = NULL;
|
||||
objlist = NULL;
|
||||
numobjects = 0;
|
||||
maxobjects = 0;
|
||||
}
|
||||
|
@ -167,12 +167,10 @@ void Container<Type>::AddObjectAt(int index, const Type& obj)
|
|||
}
|
||||
|
||||
template<class Type>
|
||||
Type* Container<Type>::AddressOfObjectAt(int index)
|
||||
Type *Container<Type>::AddressOfObjectAt(int index)
|
||||
{
|
||||
if (index > maxobjects) {
|
||||
CONTAINER_Error(
|
||||
ERR_DROP,
|
||||
"Container::AddressOfObjectAt : index is greater than maxobjects");
|
||||
CONTAINER_Error(ERR_DROP, "Container::AddressOfObjectAt : index is greater than maxobjects");
|
||||
}
|
||||
|
||||
if (index > numobjects) {
|
||||
|
@ -199,7 +197,7 @@ void Container<Type>::ClearObjectList(void)
|
|||
return;
|
||||
}
|
||||
|
||||
objlist = new Type[maxobjects];
|
||||
objlist = new Type[maxobjects];
|
||||
numobjects = 0;
|
||||
}
|
||||
}
|
||||
|
@ -211,8 +209,8 @@ void Container<Type>::Fix(void)
|
|||
return;
|
||||
}
|
||||
|
||||
Type* newlist = new Type[numobjects];
|
||||
int j = 0;
|
||||
Type *newlist = new Type[numobjects];
|
||||
int j = 0;
|
||||
|
||||
for (int i = 0; i < numobjects; i++) {
|
||||
if (objlist[i] == NULL) {
|
||||
|
@ -240,7 +238,7 @@ void Container<Type>::FreeObjectList(void)
|
|||
delete[] objlist;
|
||||
}
|
||||
|
||||
objlist = NULL;
|
||||
objlist = NULL;
|
||||
numobjects = 0;
|
||||
maxobjects = 0;
|
||||
}
|
||||
|
@ -267,8 +265,7 @@ template<class Type>
|
|||
void Container<Type>::InsertObjectAt(int index, const Type& obj)
|
||||
{
|
||||
if ((index <= 0) || (index > numobjects + 1)) {
|
||||
CONTAINER_Error(ERR_DROP,
|
||||
"Container::InsertObjectAt : index out of range");
|
||||
CONTAINER_Error(ERR_DROP, "Container::InsertObjectAt : index out of range");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -278,11 +275,11 @@ void Container<Type>::InsertObjectAt(int index, const Type& obj)
|
|||
if (numobjects > maxobjects) {
|
||||
maxobjects = numobjects;
|
||||
if (!objlist) {
|
||||
objlist = new Type[maxobjects];
|
||||
objlist = new Type[maxobjects];
|
||||
objlist[arrayIndex] = obj;
|
||||
return;
|
||||
} else {
|
||||
Type* temp = objlist;
|
||||
Type *temp = objlist;
|
||||
if (maxobjects < numobjects) {
|
||||
maxobjects = numobjects;
|
||||
}
|
||||
|
@ -381,7 +378,7 @@ void Container<Type>::RemoveObject(const Type& obj)
|
|||
template<class Type>
|
||||
void Container<Type>::Reset()
|
||||
{
|
||||
objlist = NULL;
|
||||
objlist = NULL;
|
||||
numobjects = 0;
|
||||
maxobjects = 0;
|
||||
}
|
||||
|
@ -389,8 +386,8 @@ void Container<Type>::Reset()
|
|||
template<class Type>
|
||||
void Container<Type>::Resize(int maxelements)
|
||||
{
|
||||
Type* temp;
|
||||
int i;
|
||||
Type *temp;
|
||||
int i;
|
||||
|
||||
if (maxelements <= 0) {
|
||||
FreeObjectList();
|
||||
|
@ -399,7 +396,7 @@ void Container<Type>::Resize(int maxelements)
|
|||
|
||||
if (!objlist) {
|
||||
maxobjects = maxelements;
|
||||
objlist = new Type[maxobjects];
|
||||
objlist = new Type[maxobjects];
|
||||
} else {
|
||||
temp = objlist;
|
||||
|
||||
|
@ -427,21 +424,20 @@ void Container<Type>::SetObjectAt(int index, const Type& obj)
|
|||
}
|
||||
|
||||
if ((index <= 0) || (index > numobjects)) {
|
||||
CONTAINER_Error(ERR_DROP,
|
||||
"Container::SetObjectAt : index out of range");
|
||||
CONTAINER_Error(ERR_DROP, "Container::SetObjectAt : index out of range");
|
||||
}
|
||||
|
||||
objlist[index - 1] = obj;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
void Container<Type>::Sort(int (*compare)(const void* elem1, const void* elem2))
|
||||
void Container<Type>::Sort(int (*compare)(const void *elem1, const void *elem2))
|
||||
{
|
||||
if (!objlist) {
|
||||
return;
|
||||
}
|
||||
|
||||
qsort((void*)objlist, (size_t)numobjects, sizeof(Type), compare);
|
||||
qsort((void *)objlist, (size_t)numobjects, sizeof(Type), compare);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
|
@ -463,7 +459,7 @@ void Container<Type>::Copy(const Container<Type>& container)
|
|||
|
||||
numobjects = container.numobjects;
|
||||
maxobjects = container.maxobjects;
|
||||
objlist = NULL;
|
||||
objlist = NULL;
|
||||
|
||||
if (container.objlist == NULL || !container.maxobjects) {
|
||||
return;
|
||||
|
|
|
@ -34,28 +34,17 @@ class ContainerClass : public Class
|
|||
|
||||
public:
|
||||
virtual ~ContainerClass() { value.FreeObjectList(); }
|
||||
|
||||
virtual void Archive(Archiver& arc);
|
||||
|
||||
int AddObject(const Type& obj) { return value.AddObject(obj); }
|
||||
int AddUniqueObject(const Type& obj) { return value.AddUniqueObject(obj); }
|
||||
void AddObjectAt(int index, const Type& obj)
|
||||
{
|
||||
return value.AddObjectAt(index, obj);
|
||||
}
|
||||
Type* AddressOfObjectAt(int index)
|
||||
{
|
||||
return value.AddressOfObjectAt(index);
|
||||
}
|
||||
|
||||
void AddObjectAt(int index, const Type& obj) { return value.AddObjectAt(index, obj); }
|
||||
Type *AddressOfObjectAt(int index) { return value.AddressOfObjectAt(index); }
|
||||
void ClearObjectList(void) { return value.ClearObjectList(); }
|
||||
void Fix(void) { return value.Fix(); }
|
||||
void FreeObjectList(void) { return value.FreeObjectList(); }
|
||||
int IndexOfObject(const Type& obj) { return value.IndexOfObject(obj); }
|
||||
void InsertObjectAt(int index, const Type& obj)
|
||||
{
|
||||
return value.InsertObjectAt(index, obj);
|
||||
}
|
||||
void InsertObjectAt(int index, const Type& obj) { return value.InsertObjectAt(index, obj); }
|
||||
int NumObjects(void) const { return value.NumObjects(); }
|
||||
Type& ObjectAt(const size_t index) const { return value.ObjectAt(index); }
|
||||
bool ObjectInList(const Type& obj) { return value.ObjectInList(obj); }
|
||||
|
@ -63,17 +52,8 @@ public:
|
|||
void RemoveObject(const Type& obj) { return value.RemoveObject(obj); }
|
||||
void Reset(void) { return value.Reset(); }
|
||||
void Resize(int maxelements) { return value.Resize(maxelements); }
|
||||
void SetObjectAt(int index, const Type& obj)
|
||||
{
|
||||
return value.SetObjectAt(index, obj);
|
||||
}
|
||||
void Sort(int (*compare)(const void* elem1, const void* elem2))
|
||||
{
|
||||
return value.Sort(compare);
|
||||
}
|
||||
void SetObjectAt(int index, const Type& obj) { return value.SetObjectAt(index, obj); }
|
||||
void Sort(int (*compare)(const void *elem1, const void *elem2)) { return value.Sort(compare); }
|
||||
Type& operator[](const int index) const { return value[index]; }
|
||||
Container<Type>& operator=(const Container<Type>& container)
|
||||
{
|
||||
return value = container;
|
||||
}
|
||||
Container<Type>& operator=(const Container<Type>& container) { return value = container; }
|
||||
};
|
||||
|
|
|
@ -24,26 +24,44 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
#if defined(GAME_DLL)
|
||||
|
||||
#include "../fgame/g_local.h"
|
||||
# include "../fgame/g_local.h"
|
||||
|
||||
void* MEM_Alloc(int size) { return gi.Malloc(size); }
|
||||
void *MEM_Alloc(int size)
|
||||
{
|
||||
return gi.Malloc(size);
|
||||
}
|
||||
|
||||
void MEM_Free(void* ptr) { return gi.Free(ptr); }
|
||||
void MEM_Free(void *ptr)
|
||||
{
|
||||
return gi.Free(ptr);
|
||||
}
|
||||
|
||||
#elif defined(CGAME_DLL)
|
||||
|
||||
#include "../cgame/cg_local.h"
|
||||
# include "../cgame/cg_local.h"
|
||||
|
||||
void* MEM_Alloc(int size) { return cgi.Malloc(size); }
|
||||
void *MEM_Alloc(int size)
|
||||
{
|
||||
return cgi.Malloc(size);
|
||||
}
|
||||
|
||||
void MEM_Free(void* ptr) { return cgi.Free(ptr); }
|
||||
void MEM_Free(void *ptr)
|
||||
{
|
||||
return cgi.Free(ptr);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include "qcommon.h"
|
||||
# include "qcommon.h"
|
||||
|
||||
void* MEM_Alloc(int size) { return Z_Malloc(size); }
|
||||
void *MEM_Alloc(int size)
|
||||
{
|
||||
return Z_Malloc(size);
|
||||
}
|
||||
|
||||
void MEM_Free(void* ptr) { return Z_Free(ptr); }
|
||||
void MEM_Free(void *ptr)
|
||||
{
|
||||
return Z_Free(ptr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -31,12 +31,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
#include <type_traits>
|
||||
#include <new>
|
||||
|
||||
void* MEM_Alloc(int size);
|
||||
void MEM_Free(void* ptr);
|
||||
void *MEM_Alloc(int size);
|
||||
void MEM_Free(void *ptr);
|
||||
|
||||
static constexpr size_t DefaultBlock = 256;
|
||||
|
||||
enum class alloc_source_e { SourceBlock = 174, SourceMalloc };
|
||||
enum class alloc_source_e {
|
||||
SourceBlock = 174,
|
||||
SourceMalloc
|
||||
};
|
||||
|
||||
template<typename aclass, size_t blocksize>
|
||||
class MEM_BlockAlloc_enum;
|
||||
|
@ -46,29 +49,32 @@ struct block_selectType_t;
|
|||
|
||||
template<>
|
||||
struct block_selectType_t<8> {
|
||||
using type = uint8_t;
|
||||
using type = uint8_t;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct block_selectType_t<16> {
|
||||
using type = uint16_t;
|
||||
using type = uint16_t;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct block_selectType_t<32> {
|
||||
using type = uint32_t;
|
||||
using type = uint32_t;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct block_selectType_t<64> {
|
||||
using type = uint64_t;
|
||||
using type = uint64_t;
|
||||
};
|
||||
|
||||
template<typename aclass, size_t blocksize>
|
||||
class block_s
|
||||
{
|
||||
private:
|
||||
static constexpr size_t bitsNeeded = blocksize <= 0x80 ? 8
|
||||
: blocksize <= 0x8000 ? 16
|
||||
: blocksize <= 0x80000000 ? 32
|
||||
: 64;
|
||||
static constexpr size_t bitsNeeded = blocksize <= 0x80 ? 8
|
||||
: blocksize <= 0x8000 ? 16
|
||||
: blocksize <= 0x80000000 ? 32
|
||||
: 64;
|
||||
|
||||
public:
|
||||
block_s();
|
||||
|
@ -82,63 +88,64 @@ public:
|
|||
using offset_t = typename block_selectType_t<bitsNeeded>::type;
|
||||
|
||||
struct info_t {
|
||||
offset_t index;
|
||||
alloc_source_e source;
|
||||
offset_t index;
|
||||
alloc_source_e source;
|
||||
static constexpr uint16_t typeSize = sizeof(aclass);
|
||||
alignas(alignof(aclass)) char data[sizeof(aclass)];
|
||||
};
|
||||
|
||||
public:
|
||||
#if !_DEBUG_MEMBLOCK
|
||||
info_t data[blocksize];
|
||||
info_t data[blocksize];
|
||||
offset_t prev_data[blocksize];
|
||||
offset_t next_data[blocksize];
|
||||
|
||||
offset_t free_data;
|
||||
offset_t used_data;
|
||||
bool has_free_data : 1;
|
||||
bool has_used_data : 1;
|
||||
bool has_free_data : 1;
|
||||
bool has_used_data : 1;
|
||||
#else
|
||||
offset_t data[sizeof(aclass)];
|
||||
#endif
|
||||
|
||||
block_s<aclass, blocksize>* prev_block;
|
||||
block_s<aclass, blocksize>* next_block;
|
||||
block_s<aclass, blocksize> *prev_block;
|
||||
block_s<aclass, blocksize> *next_block;
|
||||
|
||||
public:
|
||||
static constexpr size_t headersize = offsetof(info_t, data);
|
||||
static constexpr size_t dataoffset = 0;
|
||||
static constexpr size_t datasize = sizeof(info_t);
|
||||
static constexpr size_t datasize = sizeof(info_t);
|
||||
};
|
||||
|
||||
template<typename aclass, size_t blocksize>
|
||||
block_s<aclass, blocksize>::block_s()
|
||||
#if !_DEBUG_MEMBLOCK
|
||||
{
|
||||
info_t* header;
|
||||
info_t *header;
|
||||
offset_t curr;
|
||||
for (curr = 0; curr < blocksize - 1; ++curr) {
|
||||
offset_t next = curr + 1;
|
||||
header = &data[curr];
|
||||
header->source = alloc_source_e::SourceBlock;
|
||||
header->index = curr;
|
||||
offset_t next = curr + 1;
|
||||
header = &data[curr];
|
||||
header->source = alloc_source_e::SourceBlock;
|
||||
header->index = curr;
|
||||
prev_data[next] = curr;
|
||||
next_data[curr] = next;
|
||||
}
|
||||
|
||||
header = &data[curr];
|
||||
header->source = alloc_source_e::SourceBlock;
|
||||
header->index = blocksize - 1;
|
||||
prev_data[0] = blocksize - 1;
|
||||
header = &data[curr];
|
||||
header->source = alloc_source_e::SourceBlock;
|
||||
header->index = blocksize - 1;
|
||||
prev_data[0] = blocksize - 1;
|
||||
next_data[blocksize - 1] = 0;
|
||||
free_data = 0;
|
||||
free_data = 0;
|
||||
prev_block = next_block = nullptr;
|
||||
|
||||
has_free_data = true;
|
||||
has_used_data = false;
|
||||
}
|
||||
#else
|
||||
: prev_block(nullptr), next_block(nullptr)
|
||||
: prev_block(nullptr)
|
||||
, next_block(nullptr)
|
||||
{}
|
||||
#endif
|
||||
|
||||
|
@ -165,30 +172,30 @@ public:
|
|||
MEM_BlockAlloc();
|
||||
~MEM_BlockAlloc();
|
||||
|
||||
void* Alloc();
|
||||
void Free(void* ptr) noexcept;
|
||||
void FreeAll() noexcept;
|
||||
void *Alloc();
|
||||
void Free(void *ptr) noexcept;
|
||||
void FreeAll() noexcept;
|
||||
size_t Count();
|
||||
size_t BlockCount();
|
||||
size_t BlockMemory();
|
||||
|
||||
private:
|
||||
friend class MEM_BlockAlloc_enum<aclass, blocksize>;
|
||||
using block_t = block_s<aclass, blocksize>;
|
||||
using block_t = block_s<aclass, blocksize>;
|
||||
using block_offset_t = typename block_t::offset_t;
|
||||
|
||||
#if !_DEBUG_MEMBLOCK
|
||||
block_t* m_FreeBlock;
|
||||
block_t* m_StartUsedBlock;
|
||||
block_t* m_StartFullBlock;
|
||||
block_t *m_FreeBlock;
|
||||
block_t *m_StartUsedBlock;
|
||||
block_t *m_StartFullBlock;
|
||||
#else
|
||||
block_t* m_Block;
|
||||
block_t *m_Block;
|
||||
#endif
|
||||
size_t m_BlockCount;
|
||||
|
||||
private:
|
||||
void* TakeFree(block_t* block, uintptr_t free_data);
|
||||
size_t Count(const block_t* block);
|
||||
void *TakeFree(block_t *block, uintptr_t free_data);
|
||||
size_t Count(const block_t *block);
|
||||
};
|
||||
|
||||
template<typename aclass, size_t blocksize = DefaultBlock>
|
||||
|
@ -197,20 +204,23 @@ class MEM_BlockAlloc_enum
|
|||
public:
|
||||
MEM_BlockAlloc_enum(MEM_BlockAlloc<aclass, blocksize>& owner);
|
||||
|
||||
aclass* NextElement();
|
||||
aclass* CurrentElement();
|
||||
aclass *NextElement();
|
||||
aclass *CurrentElement();
|
||||
|
||||
enum blockType_e { used, full };
|
||||
enum blockType_e {
|
||||
used,
|
||||
full
|
||||
};
|
||||
|
||||
private:
|
||||
using block_t = block_s<aclass, blocksize>;
|
||||
using block_t = block_s<aclass, blocksize>;
|
||||
using offset_t = typename block_t::offset_t;
|
||||
|
||||
MEM_BlockAlloc<aclass, blocksize>* m_Owner;
|
||||
block_t* m_CurrentBlock;
|
||||
MEM_BlockAlloc<aclass, blocksize> *m_Owner;
|
||||
block_t *m_CurrentBlock;
|
||||
|
||||
#if !_DEBUG_MEMBLOCK
|
||||
offset_t m_CurrentData;
|
||||
offset_t m_CurrentData;
|
||||
blockType_e m_CurrentBlockType;
|
||||
#endif
|
||||
};
|
||||
|
@ -218,9 +228,10 @@ private:
|
|||
template<typename a, size_t b>
|
||||
MEM_BlockAlloc<a, b>::MEM_BlockAlloc()
|
||||
#if !_DEBUG_MEMBLOCK
|
||||
: m_StartUsedBlock(), m_StartFullBlock()
|
||||
: m_StartUsedBlock()
|
||||
, m_StartFullBlock()
|
||||
{
|
||||
m_FreeBlock = nullptr;
|
||||
m_FreeBlock = nullptr;
|
||||
m_BlockCount = 0;
|
||||
}
|
||||
#else
|
||||
|
@ -237,17 +248,17 @@ MEM_BlockAlloc<a, b>::~MEM_BlockAlloc()
|
|||
}
|
||||
|
||||
template<typename a, size_t b>
|
||||
void* MEM_BlockAlloc<a, b>::Alloc()
|
||||
void *MEM_BlockAlloc<a, b>::Alloc()
|
||||
{
|
||||
#if _DEBUG_MEMBLOCK
|
||||
block_t* block = new (MEM_Alloc(sizeof(block_t))) block_t();
|
||||
block_t *block = new (MEM_Alloc(sizeof(block_t))) block_t();
|
||||
|
||||
m_Block.AddFirst(block);
|
||||
|
||||
m_BlockCount++;
|
||||
return (void*)block->data;
|
||||
return (void *)block->data;
|
||||
#else
|
||||
block_t* used_block;
|
||||
block_t *used_block;
|
||||
block_offset_t free_data;
|
||||
block_offset_t next_data;
|
||||
|
||||
|
@ -262,10 +273,8 @@ void* MEM_BlockAlloc<a, b>::Alloc()
|
|||
// available
|
||||
m_StartUsedBlock = used_block->next_block;
|
||||
|
||||
LL_SafeRemoveRoot(m_StartUsedBlock, used_block, next_block,
|
||||
prev_block);
|
||||
LL_SafeAddFirst(m_StartFullBlock, used_block, next_block,
|
||||
prev_block);
|
||||
LL_SafeRemoveRoot(m_StartUsedBlock, used_block, next_block, prev_block);
|
||||
LL_SafeAddFirst(m_StartFullBlock, used_block, next_block, prev_block);
|
||||
|
||||
used_block->has_free_data = false;
|
||||
return TakeFree(used_block, free_data);
|
||||
|
@ -273,10 +282,10 @@ void* MEM_BlockAlloc<a, b>::Alloc()
|
|||
} else {
|
||||
if (m_FreeBlock) {
|
||||
// start from the free block
|
||||
used_block = m_FreeBlock;
|
||||
used_block = m_FreeBlock;
|
||||
m_FreeBlock = nullptr;
|
||||
free_data = used_block->free_data;
|
||||
next_data = used_block->next_data[free_data];
|
||||
free_data = used_block->free_data;
|
||||
next_data = used_block->next_data[free_data];
|
||||
} else {
|
||||
m_BlockCount++;
|
||||
// allocate and construct a new block
|
||||
|
@ -293,12 +302,12 @@ void* MEM_BlockAlloc<a, b>::Alloc()
|
|||
|
||||
used_block->next_data[prev_data] = next_data;
|
||||
used_block->prev_data[next_data] = prev_data;
|
||||
used_block->free_data = next_data;
|
||||
used_block->has_free_data = true;
|
||||
used_block->free_data = next_data;
|
||||
used_block->has_free_data = true;
|
||||
|
||||
if (!used_block->usedDataAvailable()) {
|
||||
used_block->used_data = free_data;
|
||||
used_block->has_used_data = true;
|
||||
used_block->used_data = free_data;
|
||||
used_block->has_used_data = true;
|
||||
used_block->next_data[free_data] = free_data;
|
||||
used_block->prev_data[free_data] = free_data;
|
||||
return used_block->data[free_data].data;
|
||||
|
@ -309,8 +318,7 @@ void* MEM_BlockAlloc<a, b>::Alloc()
|
|||
}
|
||||
|
||||
template<typename aclass, size_t blocksize>
|
||||
void* MEM_BlockAlloc<aclass, blocksize>::TakeFree(block_t* block,
|
||||
uintptr_t free_data)
|
||||
void *MEM_BlockAlloc<aclass, blocksize>::TakeFree(block_t *block, uintptr_t free_data)
|
||||
{
|
||||
const block_offset_t used_data = block->used_data;
|
||||
const block_offset_t prev_data = block->prev_data[used_data];
|
||||
|
@ -323,10 +331,10 @@ void* MEM_BlockAlloc<aclass, blocksize>::TakeFree(block_t* block,
|
|||
}
|
||||
|
||||
template<typename a, size_t b>
|
||||
void MEM_BlockAlloc<a, b>::Free(void* ptr) noexcept
|
||||
void MEM_BlockAlloc<a, b>::Free(void *ptr) noexcept
|
||||
{
|
||||
#if _DEBUG_MEMBLOCK
|
||||
block_s<a, b>* block = (block_s<a, b>*)ptr;
|
||||
block_s<a, b> *block = (block_s<a, b> *)ptr;
|
||||
|
||||
m_Block.Remove(block);
|
||||
|
||||
|
@ -334,14 +342,11 @@ void MEM_BlockAlloc<a, b>::Free(void* ptr) noexcept
|
|||
MEM::Free(block);
|
||||
#else
|
||||
// get the header of the pointer
|
||||
typename block_t::info_t* header =
|
||||
reinterpret_cast<typename block_t::info_t*>(
|
||||
static_cast<unsigned char*>(ptr) - block_t::headersize);
|
||||
typename block_t::info_t *header =
|
||||
reinterpret_cast<typename block_t::info_t *>(static_cast<unsigned char *>(ptr) - block_t::headersize);
|
||||
const block_offset_t used_data = header->index;
|
||||
// get the block from the header
|
||||
block_t* const block =
|
||||
(block_t*)((uint8_t*)header - used_data * block_t::datasize -
|
||||
block_t::dataoffset);
|
||||
block_t *const block = (block_t *)((uint8_t *)header - used_data * block_t::datasize - block_t::dataoffset);
|
||||
const block_offset_t next_data = block->next_data[used_data];
|
||||
if (next_data == used_data) {
|
||||
LL_SafeRemoveRoot(m_StartUsedBlock, block, next_block, prev_block);
|
||||
|
@ -353,7 +358,7 @@ void MEM_BlockAlloc<a, b>::Free(void* ptr) noexcept
|
|||
m_FreeBlock = nullptr;
|
||||
}
|
||||
|
||||
m_FreeBlock = block;
|
||||
m_FreeBlock = block;
|
||||
block->has_used_data = false;
|
||||
|
||||
const block_offset_t free_data = block->free_data;
|
||||
|
@ -368,8 +373,8 @@ void MEM_BlockAlloc<a, b>::Free(void* ptr) noexcept
|
|||
|
||||
block->next_data[prev_data] = next_data;
|
||||
block->prev_data[next_data] = prev_data;
|
||||
block->used_data = next_data;
|
||||
block->has_used_data = true;
|
||||
block->used_data = next_data;
|
||||
block->has_used_data = true;
|
||||
|
||||
if (block->freeDataAvailable()) {
|
||||
const block_offset_t free_data = block->free_data;
|
||||
|
@ -389,8 +394,8 @@ void MEM_BlockAlloc<a, b>::Free(void* ptr) noexcept
|
|||
LL_SafeRemoveRoot(m_StartFullBlock, block, next_block, prev_block);
|
||||
LL_SafeAddFirst(m_StartUsedBlock, block, next_block, prev_block);
|
||||
|
||||
block->free_data = used_data;
|
||||
block->has_free_data = true;
|
||||
block->free_data = used_data;
|
||||
block->has_free_data = true;
|
||||
block->prev_data[used_data] = used_data;
|
||||
block->next_data[used_data] = used_data;
|
||||
}
|
||||
|
@ -400,13 +405,13 @@ void MEM_BlockAlloc<a, b>::Free(void* ptr) noexcept
|
|||
template<typename a, size_t b>
|
||||
void MEM_BlockAlloc<a, b>::FreeAll() noexcept
|
||||
{
|
||||
block_t* block;
|
||||
block_t *block;
|
||||
#if _DEBUG_MEMBLOCK
|
||||
block_t* next = m_Block.Root();
|
||||
block_t *next = m_Block.Root();
|
||||
for (block = next; block; block = next) {
|
||||
next = block->next_block;
|
||||
m_BlockCount--;
|
||||
a* ptr = (a*)block->data;
|
||||
a *ptr = (a *)block->data;
|
||||
ptr->~a();
|
||||
MEM::Free(block);
|
||||
}
|
||||
|
@ -414,7 +419,7 @@ void MEM_BlockAlloc<a, b>::FreeAll() noexcept
|
|||
#else
|
||||
while ((block = m_StartFullBlock) != nullptr) {
|
||||
if (block->usedDataAvailable()) {
|
||||
a* ptr = (a*)block->data[block->used_data].data;
|
||||
a *ptr = (a *)block->data[block->used_data].data;
|
||||
ptr->~a();
|
||||
Free(ptr);
|
||||
block = m_StartFullBlock;
|
||||
|
@ -423,7 +428,7 @@ void MEM_BlockAlloc<a, b>::FreeAll() noexcept
|
|||
|
||||
while ((block = m_StartUsedBlock) != nullptr) {
|
||||
if (block->usedDataAvailable()) {
|
||||
a* ptr = (a*)block->data[block->used_data].data;
|
||||
a *ptr = (a *)block->data[block->used_data].data;
|
||||
ptr->~a();
|
||||
Free(ptr);
|
||||
}
|
||||
|
@ -438,23 +443,23 @@ void MEM_BlockAlloc<a, b>::FreeAll() noexcept
|
|||
}
|
||||
|
||||
template<typename a, size_t b>
|
||||
size_t MEM_BlockAlloc<a, b>::Count(const block_t* list)
|
||||
size_t MEM_BlockAlloc<a, b>::Count(const block_t *list)
|
||||
{
|
||||
int count = 0;
|
||||
#if _DEBUG_MEMBLOCK
|
||||
for (const block_t* block = list; block; block = block->next_block) {
|
||||
for (const block_t *block = list; block; block = block->next_block) {
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
#else
|
||||
|
||||
for (const block_t* block = list; block; block = block->next_block) {
|
||||
for (const block_t *block = list; block; block = block->next_block) {
|
||||
if (!block->usedDataAvailable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const block_offset_t used_data = block->used_data;
|
||||
block_offset_t current_used_data = used_data;
|
||||
const block_offset_t used_data = block->used_data;
|
||||
block_offset_t current_used_data = used_data;
|
||||
|
||||
do {
|
||||
count++;
|
||||
|
@ -491,7 +496,7 @@ size_t MEM_BlockAlloc<a, b>::BlockMemory()
|
|||
template<typename a, size_t b>
|
||||
MEM_BlockAlloc_enum<a, b>::MEM_BlockAlloc_enum(MEM_BlockAlloc<a, b>& owner)
|
||||
{
|
||||
m_Owner = &owner;
|
||||
m_Owner = &owner;
|
||||
m_CurrentBlock = nullptr;
|
||||
#if !_DEBUG_MEMBLOCK
|
||||
m_CurrentBlockType = MEM_BlockAlloc_enum::used;
|
||||
|
@ -499,7 +504,7 @@ MEM_BlockAlloc_enum<a, b>::MEM_BlockAlloc_enum(MEM_BlockAlloc<a, b>& owner)
|
|||
}
|
||||
|
||||
template<typename a, size_t b>
|
||||
a* MEM_BlockAlloc_enum<a, b>::NextElement()
|
||||
a *MEM_BlockAlloc_enum<a, b>::NextElement()
|
||||
{
|
||||
#if _DEBUG_MEMBLOCK
|
||||
if (!m_CurrentBlock) {
|
||||
|
@ -507,7 +512,7 @@ a* MEM_BlockAlloc_enum<a, b>::NextElement()
|
|||
} else {
|
||||
m_CurrentBlock = m_CurrentBlock->next_block;
|
||||
}
|
||||
return (a*)m_CurrentBlock;
|
||||
return (a *)m_CurrentBlock;
|
||||
#else
|
||||
// search for a valid block type
|
||||
while (!m_CurrentBlock) {
|
||||
|
@ -528,8 +533,7 @@ a* MEM_BlockAlloc_enum<a, b>::NextElement()
|
|||
for (; m_CurrentBlock; m_CurrentBlock = m_CurrentBlock->next_block) {
|
||||
if (m_CurrentBlock->usedDataAvailable()) {
|
||||
m_CurrentData = m_CurrentBlock->used_data;
|
||||
return reinterpret_cast<a*>(
|
||||
m_CurrentBlock->data[m_CurrentData].data);
|
||||
return reinterpret_cast<a *>(m_CurrentBlock->data[m_CurrentData].data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -542,24 +546,24 @@ a* MEM_BlockAlloc_enum<a, b>::NextElement()
|
|||
goto _label;
|
||||
}
|
||||
|
||||
return reinterpret_cast<a*>(m_CurrentBlock->data[m_CurrentData].data);
|
||||
return reinterpret_cast<a *>(m_CurrentBlock->data[m_CurrentData].data);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename a, size_t b>
|
||||
a* MEM_BlockAlloc_enum<a, b>::CurrentElement()
|
||||
a *MEM_BlockAlloc_enum<a, b>::CurrentElement()
|
||||
{
|
||||
return m_CurrentBlock;
|
||||
}
|
||||
|
||||
template<typename a, size_t b>
|
||||
void* operator new(size_t, MEM_BlockAlloc<a, b>& allocator)
|
||||
void *operator new(size_t, MEM_BlockAlloc<a, b>& allocator)
|
||||
{
|
||||
return allocator.Alloc();
|
||||
}
|
||||
|
||||
template<typename a, size_t b>
|
||||
void operator delete(void* ptr, MEM_BlockAlloc<a, b>& allocator) noexcept
|
||||
void operator delete(void *ptr, MEM_BlockAlloc<a, b>& allocator) noexcept
|
||||
{
|
||||
return allocator.Free(ptr);
|
||||
}
|
||||
|
|
|
@ -25,48 +25,48 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
#include "mem_tempalloc.h"
|
||||
|
||||
#ifdef GAME_DLL
|
||||
#include "../fgame/g_local.h"
|
||||
# include "../fgame/g_local.h"
|
||||
|
||||
#define MEM_TempAllocate(x) gi.Malloc(x)
|
||||
#define MEM_TempFree(x) gi.Free(x)
|
||||
# define MEM_TempAllocate(x) gi.Malloc(x)
|
||||
# define MEM_TempFree(x) gi.Free(x)
|
||||
|
||||
#elif defined(CGAME_DLL)
|
||||
|
||||
#include "../cgame/cg_local.h"
|
||||
# include "../cgame/cg_local.h"
|
||||
|
||||
#define MEM_TempAllocate(x) cgi.Malloc(x)
|
||||
#define MEM_TempFree(x) cgi.Free(x)
|
||||
# define MEM_TempAllocate(x) cgi.Malloc(x)
|
||||
# define MEM_TempFree(x) cgi.Free(x)
|
||||
|
||||
#else
|
||||
#include "qcommon.h"
|
||||
# include "qcommon.h"
|
||||
|
||||
#define MEM_TempAllocate(x) Z_Malloc(x)
|
||||
#define MEM_TempFree(x) Z_Free(x)
|
||||
# define MEM_TempAllocate(x) Z_Malloc(x)
|
||||
# define MEM_TempFree(x) Z_Free(x)
|
||||
#endif
|
||||
|
||||
class tempBlock_t
|
||||
{
|
||||
public:
|
||||
void* GetData();
|
||||
void* GetData(size_t pos);
|
||||
void *GetData();
|
||||
void *GetData(size_t pos);
|
||||
|
||||
public:
|
||||
tempBlock_t* prev;
|
||||
tempBlock_t *prev;
|
||||
};
|
||||
|
||||
MEM_TempAlloc::MEM_TempAlloc()
|
||||
{
|
||||
m_CurrentMemoryBlock = nullptr;
|
||||
m_CurrentMemoryPos = 0;
|
||||
m_BlockSize = 0;
|
||||
m_LastPos = 0;
|
||||
m_CurrentMemoryPos = 0;
|
||||
m_BlockSize = 0;
|
||||
m_LastPos = 0;
|
||||
}
|
||||
|
||||
void* MEM_TempAlloc::Alloc(size_t len)
|
||||
void *MEM_TempAlloc::Alloc(size_t len)
|
||||
{
|
||||
if (m_CurrentMemoryBlock && m_CurrentMemoryPos + len <= m_BlockSize) {
|
||||
void* data = m_CurrentMemoryBlock->GetData(m_CurrentMemoryPos);
|
||||
m_LastPos = m_CurrentMemoryPos;
|
||||
void *data = m_CurrentMemoryBlock->GetData(m_CurrentMemoryPos);
|
||||
m_LastPos = m_CurrentMemoryPos;
|
||||
m_CurrentMemoryPos += len;
|
||||
return data;
|
||||
} else {
|
||||
|
@ -74,7 +74,7 @@ void* MEM_TempAlloc::Alloc(size_t len)
|
|||
}
|
||||
}
|
||||
|
||||
void* MEM_TempAlloc::Alloc(size_t len, size_t alignment)
|
||||
void *MEM_TempAlloc::Alloc(size_t len, size_t alignment)
|
||||
{
|
||||
if (m_CurrentMemoryBlock) {
|
||||
if (m_CurrentMemoryPos % alignment != 0) {
|
||||
|
@ -82,8 +82,8 @@ void* MEM_TempAlloc::Alloc(size_t len, size_t alignment)
|
|||
}
|
||||
|
||||
if (m_CurrentMemoryPos + len <= m_BlockSize) {
|
||||
void* data = m_CurrentMemoryBlock->GetData(m_CurrentMemoryPos);
|
||||
m_LastPos = m_CurrentMemoryPos;
|
||||
void *data = m_CurrentMemoryBlock->GetData(m_CurrentMemoryPos);
|
||||
m_LastPos = m_CurrentMemoryPos;
|
||||
m_CurrentMemoryPos += len;
|
||||
return data;
|
||||
}
|
||||
|
@ -95,24 +95,29 @@ void* MEM_TempAlloc::Alloc(size_t len, size_t alignment)
|
|||
void MEM_TempAlloc::FreeAll(void)
|
||||
{
|
||||
while (m_CurrentMemoryBlock) {
|
||||
tempBlock_t* prev_block = m_CurrentMemoryBlock->prev;
|
||||
tempBlock_t *prev_block = m_CurrentMemoryBlock->prev;
|
||||
MEM_TempFree(m_CurrentMemoryBlock);
|
||||
m_CurrentMemoryBlock = prev_block;
|
||||
}
|
||||
}
|
||||
|
||||
void* MEM_TempAlloc::CreateBlock(size_t len)
|
||||
void *MEM_TempAlloc::CreateBlock(size_t len)
|
||||
{
|
||||
m_CurrentMemoryPos = len;
|
||||
|
||||
// allocate a new block
|
||||
tempBlock_t* prev_block = m_CurrentMemoryBlock;
|
||||
m_CurrentMemoryBlock = (tempBlock_t*)MEM_TempAllocate(
|
||||
sizeof(tempBlock_t) + Q_max(m_BlockSize, len));
|
||||
tempBlock_t *prev_block = m_CurrentMemoryBlock;
|
||||
m_CurrentMemoryBlock = (tempBlock_t *)MEM_TempAllocate(sizeof(tempBlock_t) + Q_max(m_BlockSize, len));
|
||||
m_CurrentMemoryBlock->prev = prev_block;
|
||||
return m_CurrentMemoryBlock->GetData();
|
||||
}
|
||||
|
||||
void* tempBlock_t::GetData() { return (void*)(this + 1); }
|
||||
void *tempBlock_t::GetData()
|
||||
{
|
||||
return (void *)(this + 1);
|
||||
}
|
||||
|
||||
void* tempBlock_t::GetData(size_t pos) { return (uint8_t*)(this + 1) + pos; }
|
||||
void *tempBlock_t::GetData(size_t pos)
|
||||
{
|
||||
return (uint8_t *)(this + 1) + pos;
|
||||
}
|
||||
|
|
|
@ -33,15 +33,15 @@ class MEM_TempAlloc
|
|||
public:
|
||||
MEM_TempAlloc();
|
||||
|
||||
void* Alloc(size_t len);
|
||||
void* Alloc(size_t len, size_t alignment);
|
||||
void FreeAll(void);
|
||||
void *Alloc(size_t len);
|
||||
void *Alloc(size_t len, size_t alignment);
|
||||
void FreeAll(void);
|
||||
// This was added to fix issues with alignment
|
||||
void* CreateBlock(size_t len);
|
||||
void *CreateBlock(size_t len);
|
||||
|
||||
private:
|
||||
tempBlock_t* m_CurrentMemoryBlock;
|
||||
size_t m_CurrentMemoryPos;
|
||||
size_t m_BlockSize;
|
||||
size_t m_LastPos;
|
||||
tempBlock_t *m_CurrentMemoryBlock;
|
||||
size_t m_CurrentMemoryPos;
|
||||
size_t m_BlockSize;
|
||||
size_t m_LastPos;
|
||||
};
|
||||
|
|
|
@ -34,52 +34,55 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
#if defined(GAME_DLL)
|
||||
|
||||
#include "../fgame/g_local.h"
|
||||
# include "../fgame/g_local.h"
|
||||
|
||||
#define FILE_FS_FreeFile gi.FS_FreeFile
|
||||
#define FILE_FS_ReadFile(a, b) gi.FS_ReadFile(a, b, true)
|
||||
#define FILE_Malloc gi.Malloc
|
||||
#define FILE_Free gi.Free
|
||||
#define FILE_Error gi.Error
|
||||
# define FILE_FS_FreeFile gi.FS_FreeFile
|
||||
# define FILE_FS_ReadFile(a, b) gi.FS_ReadFile(a, b, true)
|
||||
# define FILE_Malloc gi.Malloc
|
||||
# define FILE_Free gi.Free
|
||||
# define FILE_Error gi.Error
|
||||
|
||||
#elif defined(CGAME_DLL)
|
||||
|
||||
#define FILE_FS_FreeFile cgi.FS_FreeFile
|
||||
#define FILE_FS_ReadFile(a, b) cgi.FS_ReadFile(a, b, qtrue)
|
||||
#define FILE_Malloc cgi.Malloc
|
||||
#define FILE_Free cgi.Free
|
||||
#define FILE_Error cgi.Error
|
||||
# define FILE_FS_FreeFile cgi.FS_FreeFile
|
||||
# define FILE_FS_ReadFile(a, b) cgi.FS_ReadFile(a, b, qtrue)
|
||||
# define FILE_Malloc cgi.Malloc
|
||||
# define FILE_Free cgi.Free
|
||||
# define FILE_Error cgi.Error
|
||||
|
||||
#else
|
||||
|
||||
#include "qcommon.h"
|
||||
# include "qcommon.h"
|
||||
|
||||
#define FILE_FS_FreeFile FS_FreeFile
|
||||
#define FILE_FS_ReadFile(a, b) FS_ReadFile(a, b)
|
||||
#define FILE_Malloc Z_Malloc
|
||||
#define FILE_Free Z_Free
|
||||
#define FILE_Error Com_Error
|
||||
# define FILE_FS_FreeFile FS_FreeFile
|
||||
# define FILE_FS_ReadFile(a, b) FS_ReadFile(a, b)
|
||||
# define FILE_Malloc Z_Malloc
|
||||
# define FILE_Free Z_Free
|
||||
# define FILE_Error Com_Error
|
||||
|
||||
#endif
|
||||
|
||||
typedef unsigned char byte;
|
||||
|
||||
CLASS_DECLARATION(Class, Script, NULL){
|
||||
CLASS_DECLARATION(Class, Script, NULL) {
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
Script::~Script() { Close(); }
|
||||
|
||||
Script::Script(const char* filename /*= 0*/)
|
||||
Script::~Script()
|
||||
{
|
||||
buffer = NULL;
|
||||
script_p = NULL;
|
||||
end_p = NULL;
|
||||
line = 0;
|
||||
length = 0;
|
||||
Close();
|
||||
}
|
||||
|
||||
Script::Script(const char *filename /*= 0*/)
|
||||
{
|
||||
buffer = NULL;
|
||||
script_p = NULL;
|
||||
end_p = NULL;
|
||||
line = 0;
|
||||
length = 0;
|
||||
releaseBuffer = false;
|
||||
tokenready = false;
|
||||
token[0] = 0;
|
||||
tokenready = false;
|
||||
token[0] = 0;
|
||||
|
||||
if (filename != 0) {
|
||||
LoadFile(filename);
|
||||
|
@ -88,29 +91,29 @@ Script::Script(const char* filename /*= 0*/)
|
|||
|
||||
Script::Script()
|
||||
{
|
||||
buffer = NULL;
|
||||
script_p = NULL;
|
||||
end_p = NULL;
|
||||
line = 0;
|
||||
length = 0;
|
||||
buffer = NULL;
|
||||
script_p = NULL;
|
||||
end_p = NULL;
|
||||
line = 0;
|
||||
length = 0;
|
||||
releaseBuffer = false;
|
||||
tokenready = false;
|
||||
token[0] = 0;
|
||||
tokenready = false;
|
||||
token[0] = 0;
|
||||
}
|
||||
|
||||
void Script::Close(void)
|
||||
{
|
||||
if (releaseBuffer && buffer) {
|
||||
FILE_Free((void*)buffer);
|
||||
FILE_Free((void *)buffer);
|
||||
}
|
||||
|
||||
buffer = NULL;
|
||||
script_p = NULL;
|
||||
end_p = NULL;
|
||||
line = 0;
|
||||
buffer = NULL;
|
||||
script_p = NULL;
|
||||
end_p = NULL;
|
||||
line = 0;
|
||||
releaseBuffer = false;
|
||||
tokenready = false;
|
||||
token[0] = 0;
|
||||
tokenready = false;
|
||||
token[0] = 0;
|
||||
|
||||
// Loop Through the macro container and delete (del33t -hehe) them all
|
||||
for (int i = 1; i <= macrolist.NumObjects(); i++) {
|
||||
|
@ -129,7 +132,10 @@ void Script::Close(void)
|
|||
==============
|
||||
*/
|
||||
|
||||
const char* Script::Filename(void) { return filename.c_str(); }
|
||||
const char *Script::Filename(void)
|
||||
{
|
||||
return filename.c_str();
|
||||
}
|
||||
|
||||
/*
|
||||
==============
|
||||
|
@ -139,7 +145,10 @@ const char* Script::Filename(void) { return filename.c_str(); }
|
|||
==============
|
||||
*/
|
||||
|
||||
int Script::GetLineNumber(void) { return line; }
|
||||
int Script::GetLineNumber(void)
|
||||
{
|
||||
return line;
|
||||
}
|
||||
|
||||
/*
|
||||
==============
|
||||
|
@ -151,10 +160,10 @@ int Script::GetLineNumber(void) { return line; }
|
|||
|
||||
void Script::Reset(void)
|
||||
{
|
||||
script_p = buffer;
|
||||
line = 1;
|
||||
script_p = buffer;
|
||||
line = 1;
|
||||
tokenready = false;
|
||||
hasError = false;
|
||||
hasError = false;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -165,13 +174,13 @@ void Script::Reset(void)
|
|||
==============
|
||||
*/
|
||||
|
||||
void Script::MarkPosition(scriptmarker_t* mark)
|
||||
void Script::MarkPosition(scriptmarker_t *mark)
|
||||
{
|
||||
assert(mark);
|
||||
|
||||
mark->tokenready = tokenready;
|
||||
mark->offset = script_p - buffer;
|
||||
mark->line = line;
|
||||
mark->offset = script_p - buffer;
|
||||
mark->line = line;
|
||||
strcpy(mark->token, token);
|
||||
}
|
||||
|
||||
|
@ -183,13 +192,13 @@ void Script::MarkPosition(scriptmarker_t* mark)
|
|||
==============
|
||||
*/
|
||||
|
||||
void Script::RestorePosition(const scriptmarker_t* mark)
|
||||
void Script::RestorePosition(const scriptmarker_t *mark)
|
||||
{
|
||||
assert(mark);
|
||||
|
||||
tokenready = mark->tokenready;
|
||||
script_p = buffer + mark->offset;
|
||||
line = mark->line;
|
||||
script_p = buffer + mark->offset;
|
||||
line = mark->line;
|
||||
strcpy(token, mark->token);
|
||||
|
||||
assert(script_p <= end_p);
|
||||
|
@ -232,9 +241,7 @@ qboolean Script::SkipToEOL(void)
|
|||
void Script::CheckOverflow(void)
|
||||
{
|
||||
if (script_p >= end_p) {
|
||||
FILE_Error(ERR_DROP,
|
||||
"End of token file reached prematurely reading %s\n",
|
||||
filename.c_str());
|
||||
FILE_Error(ERR_DROP, "End of token file reached prematurely reading %s\n", filename.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -256,8 +263,7 @@ void Script::SkipWhiteSpace(qboolean crossline)
|
|||
while (*script_p <= TOKENSPACE) {
|
||||
if (*script_p++ == TOKENEOL) {
|
||||
if (!crossline) {
|
||||
FILE_Error(ERR_DROP, "Line %i is incomplete in file %s\n", line,
|
||||
filename.c_str());
|
||||
FILE_Error(ERR_DROP, "Line %i is incomplete in file %s\n", line, filename.c_str());
|
||||
}
|
||||
|
||||
line++;
|
||||
|
@ -374,7 +380,7 @@ qboolean Script::TokenAvailable(qboolean crossline)
|
|||
|
||||
qboolean Script::CommentAvailable(qboolean crossline)
|
||||
{
|
||||
const char* searchptr;
|
||||
const char *searchptr;
|
||||
|
||||
searchptr = script_p;
|
||||
|
||||
|
@ -412,7 +418,10 @@ GetToken (false);
|
|||
==============
|
||||
*/
|
||||
|
||||
void Script::UnGetToken(void) { tokenready = true; }
|
||||
void Script::UnGetToken(void)
|
||||
{
|
||||
tokenready = true;
|
||||
}
|
||||
|
||||
/*
|
||||
==============
|
||||
|
@ -478,11 +487,9 @@ qboolean Script::AtAssignment(qboolean crossline)
|
|||
//
|
||||
SkipNonToken(crossline);
|
||||
|
||||
return (*script_p == '=') ||
|
||||
((*script_p == '+') && (*(script_p + 1) == '=')) ||
|
||||
((*script_p == '-') && (*(script_p + 1) == '=')) ||
|
||||
((*script_p == '*') && (*(script_p + 1) == '=')) ||
|
||||
((*script_p == '/') && (*(script_p + 1) == '='));
|
||||
return (*script_p == '=') || ((*script_p == '+') && (*(script_p + 1) == '='))
|
||||
|| ((*script_p == '-') && (*(script_p + 1) == '=')) || ((*script_p == '*') && (*(script_p + 1) == '='))
|
||||
|| ((*script_p == '/') && (*(script_p + 1) == '='));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -493,10 +500,9 @@ qboolean Script::AtAssignment(qboolean crossline)
|
|||
==============
|
||||
*/
|
||||
|
||||
const char* Script::GetToken(qboolean crossline)
|
||||
const char *Script::GetToken(qboolean crossline)
|
||||
{
|
||||
|
||||
str token_p = token;
|
||||
str token_p = token;
|
||||
qboolean is_Macro = false;
|
||||
|
||||
// is a token already waiting?
|
||||
|
@ -510,7 +516,6 @@ const char* Script::GetToken(qboolean crossline)
|
|||
token_p = GrabNextToken(crossline);
|
||||
|
||||
if (is_Macro && (token_p != "$include")) {
|
||||
|
||||
// Check to see if we need to add any definitions
|
||||
while ((token_p == "$define") || (token_p == "$Define")) {
|
||||
AddMacroDefinition(crossline);
|
||||
|
@ -521,8 +526,7 @@ const char* Script::GetToken(qboolean crossline)
|
|||
}
|
||||
|
||||
// Check to see if we need return any defines strings
|
||||
if (is_Macro && (token_p != "$include") &&
|
||||
(token_p[token_p.length() - 1] == '$')) {
|
||||
if (is_Macro && (token_p != "$include") && (token_p[token_p.length() - 1] == '$')) {
|
||||
return GetMacroString(token_p);
|
||||
}
|
||||
}
|
||||
|
@ -537,9 +541,9 @@ const char* Script::GetToken(qboolean crossline)
|
|||
=
|
||||
==============
|
||||
*/
|
||||
const char* Script::GrabNextToken(qboolean crossline)
|
||||
const char *Script::GrabNextToken(qboolean crossline)
|
||||
{
|
||||
char* token_p;
|
||||
char *token_p;
|
||||
|
||||
//
|
||||
// skip space
|
||||
|
@ -583,8 +587,7 @@ const char* Script::GrabNextToken(qboolean crossline)
|
|||
}
|
||||
|
||||
if (token_p == &token[SCRIPT_MAXTOKEN]) {
|
||||
FILE_Error(ERR_DROP, "Token too large on line %i in file %s\n",
|
||||
line, filename.c_str());
|
||||
FILE_Error(ERR_DROP, "Token too large on line %i in file %s\n", line, filename.c_str());
|
||||
}
|
||||
|
||||
if (script_p == end_p) {
|
||||
|
@ -606,7 +609,7 @@ const char* Script::GrabNextToken(qboolean crossline)
|
|||
*/
|
||||
void Script::AddMacroDefinition(qboolean crossline)
|
||||
{
|
||||
macro* theMacro;
|
||||
macro *theMacro;
|
||||
|
||||
// Create a new macro structure. This new macro will be deleted in the
|
||||
// script close()
|
||||
|
@ -615,8 +618,7 @@ void Script::AddMacroDefinition(qboolean crossline)
|
|||
// Grab the macro name
|
||||
theMacro->macroName = "$";
|
||||
theMacro->macroName.append(GrabNextToken(crossline));
|
||||
theMacro->macroName.append(
|
||||
"$"); //<-- Adding closing ($) to keep formatting consistant
|
||||
theMacro->macroName.append("$"); //<-- Adding closing ($) to keep formatting consistant
|
||||
|
||||
// Grab the macro string
|
||||
str tmpstr;
|
||||
|
@ -638,17 +640,15 @@ void Script::AddMacroDefinition(qboolean crossline)
|
|||
=
|
||||
==============
|
||||
*/
|
||||
const char* Script::GetMacroString(const char* theMacroName)
|
||||
const char *Script::GetMacroString(const char *theMacroName)
|
||||
{
|
||||
|
||||
macro* theMacro = 0; // Initialize this puppy
|
||||
macro *theMacro = 0; // Initialize this puppy
|
||||
|
||||
for (int i = 1; i <= macrolist.NumObjects(); i++) {
|
||||
theMacro = macrolist.ObjectAt(i);
|
||||
|
||||
if (!theMacro->macroName.cmp(theMacro->macroName.c_str(),
|
||||
theMacroName)) {
|
||||
const char* text = theMacro->macroText.c_str();
|
||||
if (!theMacro->macroName.cmp(theMacro->macroName.c_str(), theMacroName)) {
|
||||
const char *text = theMacro->macroText.c_str();
|
||||
|
||||
// If our define value is another define...
|
||||
if (text[0] == '$') {
|
||||
|
@ -665,8 +665,7 @@ const char* Script::GetMacroString(const char* theMacroName)
|
|||
sptr++;
|
||||
|
||||
// We didn't find what we were looking for
|
||||
FILE_Error(ERR_DROP, "No Macro Text found for %s in file %s\n",
|
||||
theMacroName, filename.c_str());
|
||||
FILE_Error(ERR_DROP, "No Macro Text found for %s in file %s\n", theMacroName, filename.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -682,7 +681,7 @@ const char* Script::GetMacroString(const char* theMacroName)
|
|||
// Returns: None
|
||||
//
|
||||
//================================================================
|
||||
void Script::AddMacro(const char* name, const char* value) {}
|
||||
void Script::AddMacro(const char *name, const char *value) {}
|
||||
|
||||
/*
|
||||
==============
|
||||
|
@ -691,31 +690,31 @@ void Script::AddMacro(const char* name, const char* value) {}
|
|||
=
|
||||
==============
|
||||
*/
|
||||
char* Script::EvaluateMacroString(const char* theMacroString)
|
||||
char *Script::EvaluateMacroString(const char *theMacroString)
|
||||
{
|
||||
static char evalText[255];
|
||||
char buffer[255], *bufferptr = buffer, oper = '+', newoper = '+';
|
||||
bool haveoper = false;
|
||||
int i;
|
||||
float value = 0.0f, val = 0.0f;
|
||||
char buffer[255], *bufferptr = buffer, oper = '+', newoper = '+';
|
||||
bool haveoper = false;
|
||||
int i;
|
||||
float value = 0.0f, val = 0.0f;
|
||||
memset(buffer, 0, 255);
|
||||
|
||||
for (i = 0; i <= strlen(theMacroString); i++) {
|
||||
if (theMacroString[i] == '+') {
|
||||
haveoper = true;
|
||||
newoper = '+';
|
||||
newoper = '+';
|
||||
}
|
||||
if (theMacroString[i] == '-') {
|
||||
haveoper = true;
|
||||
newoper = '-';
|
||||
newoper = '-';
|
||||
}
|
||||
if (theMacroString[i] == '*') {
|
||||
haveoper = true;
|
||||
newoper = '*';
|
||||
newoper = '*';
|
||||
}
|
||||
if (theMacroString[i] == '/') {
|
||||
haveoper = true;
|
||||
newoper = '/';
|
||||
newoper = '/';
|
||||
}
|
||||
if (theMacroString[i] == 0) {
|
||||
haveoper = true;
|
||||
|
@ -729,7 +728,7 @@ char* Script::EvaluateMacroString(const char* theMacroString)
|
|||
}
|
||||
|
||||
value = EvaluateMacroMath(value, val, oper);
|
||||
oper = newoper;
|
||||
oper = newoper;
|
||||
|
||||
// Reset everything
|
||||
haveoper = false;
|
||||
|
@ -802,10 +801,10 @@ qboolean Script::isMacro(void)
|
|||
==============
|
||||
*/
|
||||
|
||||
const char* Script::GetLine(qboolean crossline)
|
||||
const char *Script::GetLine(qboolean crossline)
|
||||
{
|
||||
const char* start;
|
||||
int size;
|
||||
const char *start;
|
||||
int size;
|
||||
|
||||
// is a token already waiting?
|
||||
if (tokenready) {
|
||||
|
@ -828,8 +827,7 @@ const char* Script::GetLine(qboolean crossline)
|
|||
memcpy(token, start, size);
|
||||
token[size] = '\0';
|
||||
} else {
|
||||
FILE_Error(ERR_DROP, "Token too large on line %i in file %s\n", line,
|
||||
filename.c_str());
|
||||
FILE_Error(ERR_DROP, "Token too large on line %i in file %s\n", line, filename.c_str());
|
||||
}
|
||||
|
||||
return token;
|
||||
|
@ -843,10 +841,10 @@ const char* Script::GetLine(qboolean crossline)
|
|||
==============
|
||||
*/
|
||||
|
||||
const char* Script::GetRaw(void)
|
||||
const char *Script::GetRaw(void)
|
||||
{
|
||||
const char* start;
|
||||
int size;
|
||||
const char *start;
|
||||
int size;
|
||||
|
||||
//
|
||||
// skip white space
|
||||
|
@ -863,8 +861,7 @@ const char* Script::GetRaw(void)
|
|||
memset(token, 0, sizeof(token));
|
||||
memcpy(token, start, size);
|
||||
} else {
|
||||
FILE_Error(ERR_DROP, "Token too large on line %i in file %s\n", line,
|
||||
filename.c_str());
|
||||
FILE_Error(ERR_DROP, "Token too large on line %i in file %s\n", line, filename.c_str());
|
||||
}
|
||||
|
||||
return token;
|
||||
|
@ -878,10 +875,10 @@ const char* Script::GetRaw(void)
|
|||
==============
|
||||
*/
|
||||
|
||||
const char* Script::GetString(qboolean crossline)
|
||||
const char *Script::GetString(qboolean crossline)
|
||||
{
|
||||
int startline;
|
||||
char* token_p;
|
||||
int startline;
|
||||
char *token_p;
|
||||
|
||||
// is a token already waiting?
|
||||
if (tokenready) {
|
||||
|
@ -895,20 +892,16 @@ const char* Script::GetString(qboolean crossline)
|
|||
SkipNonToken(crossline);
|
||||
|
||||
if (*script_p != '"') {
|
||||
FILE_Error(ERR_DROP, "Expecting string on line %i in file %s\n", line,
|
||||
filename.c_str());
|
||||
FILE_Error(ERR_DROP, "Expecting string on line %i in file %s\n", line, filename.c_str());
|
||||
}
|
||||
|
||||
script_p++;
|
||||
|
||||
startline = line;
|
||||
token_p = token;
|
||||
token_p = token;
|
||||
while (*script_p != '"') {
|
||||
if (*script_p == TOKENEOL) {
|
||||
FILE_Error(
|
||||
ERR_DROP,
|
||||
"Line %i is incomplete while reading string in file %s\n", line,
|
||||
filename.c_str());
|
||||
FILE_Error(ERR_DROP, "Line %i is incomplete while reading string in file %s\n", line, filename.c_str());
|
||||
}
|
||||
|
||||
if ((*script_p == '\\') && (script_p < (end_p - 1))) {
|
||||
|
@ -939,16 +932,18 @@ const char* Script::GetString(qboolean crossline)
|
|||
}
|
||||
|
||||
if (script_p >= end_p) {
|
||||
FILE_Error(ERR_DROP,
|
||||
"End of token file reached prematurely while reading "
|
||||
"string on\n"
|
||||
"line %d in file %s\n",
|
||||
startline, filename.c_str());
|
||||
FILE_Error(
|
||||
ERR_DROP,
|
||||
"End of token file reached prematurely while reading "
|
||||
"string on\n"
|
||||
"line %d in file %s\n",
|
||||
startline,
|
||||
filename.c_str()
|
||||
);
|
||||
}
|
||||
|
||||
if (token_p == &token[SCRIPT_MAXTOKEN]) {
|
||||
FILE_Error(ERR_DROP, "String too large on line %i in file %s\n",
|
||||
line, filename.c_str());
|
||||
FILE_Error(ERR_DROP, "String too large on line %i in file %s\n", line, filename.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -968,7 +963,7 @@ const char* Script::GetString(qboolean crossline)
|
|||
==============
|
||||
*/
|
||||
|
||||
qboolean Script::GetSpecific(const char* string)
|
||||
qboolean Script::GetSpecific(const char *string)
|
||||
{
|
||||
do {
|
||||
if (!TokenAvailable(true)) {
|
||||
|
@ -1072,15 +1067,15 @@ Vector Script::GetVector(qboolean crossline)
|
|||
*/
|
||||
int Script::LinesInFile(void)
|
||||
{
|
||||
qboolean temp_tokenready;
|
||||
const char* temp_script_p;
|
||||
int temp_line;
|
||||
char temp_token[SCRIPT_MAXTOKEN];
|
||||
int numentries;
|
||||
qboolean temp_tokenready;
|
||||
const char *temp_script_p;
|
||||
int temp_line;
|
||||
char temp_token[SCRIPT_MAXTOKEN];
|
||||
int numentries;
|
||||
|
||||
temp_tokenready = tokenready;
|
||||
temp_script_p = script_p;
|
||||
temp_line = line;
|
||||
temp_script_p = script_p;
|
||||
temp_line = line;
|
||||
strcpy(temp_token, token);
|
||||
|
||||
numentries = 0;
|
||||
|
@ -1092,8 +1087,8 @@ int Script::LinesInFile(void)
|
|||
}
|
||||
|
||||
tokenready = temp_tokenready;
|
||||
script_p = temp_script_p;
|
||||
line = temp_line;
|
||||
script_p = temp_script_p;
|
||||
line = temp_line;
|
||||
strcpy(token, temp_token);
|
||||
|
||||
return numentries;
|
||||
|
@ -1107,15 +1102,15 @@ int Script::LinesInFile(void)
|
|||
==============
|
||||
*/
|
||||
|
||||
void Script::Parse(const char* data, size_t length, const char* name)
|
||||
void Script::Parse(const char *data, size_t length, const char *name)
|
||||
{
|
||||
Close();
|
||||
|
||||
buffer = data;
|
||||
Reset();
|
||||
this->length = length;
|
||||
end_p = script_p + length;
|
||||
filename = name;
|
||||
end_p = script_p + length;
|
||||
filename = name;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1126,16 +1121,16 @@ void Script::Parse(const char* data, size_t length, const char* name)
|
|||
==============
|
||||
*/
|
||||
|
||||
void Script::LoadFile(const char* name)
|
||||
void Script::LoadFile(const char *name)
|
||||
{
|
||||
int length;
|
||||
byte* buffer;
|
||||
byte* tempbuf;
|
||||
const char* const_buffer;
|
||||
int length;
|
||||
byte *buffer;
|
||||
byte *tempbuf;
|
||||
const char *const_buffer;
|
||||
|
||||
Close();
|
||||
|
||||
length = FILE_FS_ReadFile(name, (void**)&tempbuf);
|
||||
length = FILE_FS_ReadFile(name, (void **)&tempbuf);
|
||||
|
||||
hasError = false;
|
||||
|
||||
|
@ -1145,14 +1140,14 @@ void Script::LoadFile(const char* name)
|
|||
}
|
||||
|
||||
// create our own space
|
||||
buffer = (byte*)FILE_Malloc(length + 1);
|
||||
buffer = (byte *)FILE_Malloc(length + 1);
|
||||
// copy the file over to our space
|
||||
memcpy(buffer, tempbuf, length);
|
||||
buffer[length] = 0;
|
||||
// free the file
|
||||
FILE_FS_FreeFile(tempbuf);
|
||||
|
||||
const_buffer = (char*)buffer;
|
||||
const_buffer = (char *)buffer;
|
||||
|
||||
Parse(const_buffer, length, name);
|
||||
releaseBuffer = true;
|
||||
|
@ -1166,22 +1161,31 @@ void Script::LoadFile(const char* name)
|
|||
==============
|
||||
*/
|
||||
|
||||
void Script::LoadFile(const char* name, int length, const char* buf)
|
||||
void Script::LoadFile(const char *name, int length, const char *buf)
|
||||
{
|
||||
Close();
|
||||
|
||||
// create our own space
|
||||
this->buffer = (const char*)FILE_Malloc(length);
|
||||
this->buffer = (const char *)FILE_Malloc(length);
|
||||
this->length = length;
|
||||
// copy the file over to our space
|
||||
memcpy((void*)this->buffer, buf, length);
|
||||
memcpy((void *)this->buffer, buf, length);
|
||||
|
||||
Parse(buffer, this->length, name);
|
||||
releaseBuffer = true;
|
||||
}
|
||||
|
||||
qboolean Script::isValid() { return !hasError; }
|
||||
qboolean Script::isValid()
|
||||
{
|
||||
return !hasError;
|
||||
}
|
||||
|
||||
qboolean Script::EndOfFile(void) { return script_p >= end_p; }
|
||||
qboolean Script::EndOfFile(void)
|
||||
{
|
||||
return script_p >= end_p;
|
||||
}
|
||||
|
||||
const char* Script::Token(void) { return token; }
|
||||
const char *Script::Token(void)
|
||||
{
|
||||
return token;
|
||||
}
|
||||
|
|
|
@ -30,23 +30,23 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
#include "str.h"
|
||||
|
||||
#if defined(ARCHIVE_SUPPORTED)
|
||||
#include "../fgame/archive.h"
|
||||
# include "../fgame/archive.h"
|
||||
#endif
|
||||
|
||||
#define TOKENCOMMENT (';')
|
||||
#define TOKENCOMMENT2 ('#')
|
||||
#define TOKENEOL ('\n')
|
||||
// #define TOKENNULL ('\0')
|
||||
#define TOKENSPACE (' ')
|
||||
#define TOKENSPECIAL ('$')
|
||||
#define TOKENSPACE (' ')
|
||||
#define TOKENSPECIAL ('$')
|
||||
|
||||
#define SCRIPT_MAXTOKEN 512
|
||||
#define SCRIPT_MAXTOKEN 512
|
||||
|
||||
typedef struct {
|
||||
qboolean tokenready;
|
||||
int offset;
|
||||
int line;
|
||||
char token[SCRIPT_MAXTOKEN];
|
||||
int offset;
|
||||
int line;
|
||||
char token[SCRIPT_MAXTOKEN];
|
||||
} scriptmarker_t;
|
||||
|
||||
typedef struct {
|
||||
|
@ -61,23 +61,23 @@ class Script : public Class
|
|||
protected:
|
||||
qboolean tokenready;
|
||||
|
||||
str filename;
|
||||
const char* script_p;
|
||||
const char* end_p;
|
||||
Container<macro*> macrolist;
|
||||
str filename;
|
||||
const char *script_p;
|
||||
const char *end_p;
|
||||
Container<macro *> macrolist;
|
||||
|
||||
int line;
|
||||
int line;
|
||||
char token[SCRIPT_MAXTOKEN];
|
||||
|
||||
qboolean releaseBuffer;
|
||||
qboolean hasError;
|
||||
|
||||
qboolean AtComment(void);
|
||||
void CheckOverflow(void);
|
||||
void CheckOverflow(void);
|
||||
|
||||
public:
|
||||
const char* buffer;
|
||||
size_t length;
|
||||
const char *buffer;
|
||||
size_t length;
|
||||
|
||||
CLASS_PROTOTYPE(Script);
|
||||
|
||||
|
@ -86,55 +86,56 @@ public:
|
|||
#endif
|
||||
|
||||
~Script();
|
||||
Script(const char* filename);
|
||||
Script(const char *filename);
|
||||
Script();
|
||||
|
||||
void Close(void);
|
||||
const char* Filename(void);
|
||||
int GetLineNumber(void);
|
||||
void Reset(void);
|
||||
void MarkPosition(scriptmarker_t* mark);
|
||||
void RestorePosition(const scriptmarker_t* mark);
|
||||
qboolean SkipToEOL(void);
|
||||
void SkipWhiteSpace(qboolean crossline);
|
||||
void SkipNonToken(qboolean crossline);
|
||||
qboolean TokenAvailable(qboolean crossline);
|
||||
qboolean CommentAvailable(qboolean crossline);
|
||||
void UnGetToken(void);
|
||||
qboolean AtString(qboolean crossline);
|
||||
qboolean AtOpenParen(qboolean crossline);
|
||||
qboolean AtCloseParen(qboolean crossline);
|
||||
qboolean AtComma(qboolean crossline);
|
||||
qboolean AtDot(qboolean crossline);
|
||||
qboolean AtAssignment(qboolean crossline);
|
||||
const char* GetToken(qboolean crossline);
|
||||
const char* GetLine(qboolean crossline);
|
||||
const char* GetRaw(void);
|
||||
const char* GetString(qboolean crossline);
|
||||
qboolean GetSpecific(const char* string);
|
||||
qboolean GetBoolean(qboolean crossline);
|
||||
int GetInteger(qboolean crossline);
|
||||
double GetDouble(qboolean crossline);
|
||||
float GetFloat(qboolean crossline);
|
||||
Vector GetVector(qboolean crossline);
|
||||
int LinesInFile(void);
|
||||
void Parse(const char* data, size_t length, const char* name);
|
||||
void LoadFile(const char* name);
|
||||
void LoadFile(const char* name, int length, const char* buf);
|
||||
const char* Token(void);
|
||||
void AddMacroDefinition(qboolean crossline);
|
||||
const char* GetMacroString(const char* theMacroName);
|
||||
char* EvaluateMacroString(const char* theMacroString);
|
||||
float EvaluateMacroMath(float value, float newval, char oper);
|
||||
const char* GetExprToken(const char* ptr, char* token);
|
||||
const char* GrabNextToken(qboolean crossline);
|
||||
qboolean isMacro(void);
|
||||
void Close(void);
|
||||
const char *Filename(void);
|
||||
int GetLineNumber(void);
|
||||
void Reset(void);
|
||||
void MarkPosition(scriptmarker_t *mark);
|
||||
void RestorePosition(const scriptmarker_t *mark);
|
||||
qboolean SkipToEOL(void);
|
||||
void SkipWhiteSpace(qboolean crossline);
|
||||
void SkipNonToken(qboolean crossline);
|
||||
qboolean TokenAvailable(qboolean crossline);
|
||||
qboolean CommentAvailable(qboolean crossline);
|
||||
void UnGetToken(void);
|
||||
qboolean AtString(qboolean crossline);
|
||||
qboolean AtOpenParen(qboolean crossline);
|
||||
qboolean AtCloseParen(qboolean crossline);
|
||||
qboolean AtComma(qboolean crossline);
|
||||
qboolean AtDot(qboolean crossline);
|
||||
qboolean AtAssignment(qboolean crossline);
|
||||
const char *GetToken(qboolean crossline);
|
||||
const char *GetLine(qboolean crossline);
|
||||
const char *GetRaw(void);
|
||||
const char *GetString(qboolean crossline);
|
||||
qboolean GetSpecific(const char *string);
|
||||
qboolean GetBoolean(qboolean crossline);
|
||||
int GetInteger(qboolean crossline);
|
||||
double GetDouble(qboolean crossline);
|
||||
float GetFloat(qboolean crossline);
|
||||
Vector GetVector(qboolean crossline);
|
||||
int LinesInFile(void);
|
||||
void Parse(const char *data, size_t length, const char *name);
|
||||
void LoadFile(const char *name);
|
||||
void LoadFile(const char *name, int length, const char *buf);
|
||||
const char *Token(void);
|
||||
void AddMacroDefinition(qboolean crossline);
|
||||
const char *GetMacroString(const char *theMacroName);
|
||||
char *EvaluateMacroString(const char *theMacroString);
|
||||
float EvaluateMacroMath(float value, float newval, char oper);
|
||||
const char *GetExprToken(const char *ptr, char *token);
|
||||
const char *GrabNextToken(qboolean crossline);
|
||||
qboolean isMacro(void);
|
||||
|
||||
qboolean EndOfFile();
|
||||
qboolean isValid(void);
|
||||
|
||||
Container<macro*>* GetMacroList() { return ¯olist; }
|
||||
void AddMacro(const char* name, const char* value);
|
||||
Container<macro *> *GetMacroList() { return ¯olist; }
|
||||
|
||||
void AddMacro(const char *name, const char *value);
|
||||
};
|
||||
|
||||
#if defined(ARCHIVE_SUPPORTED)
|
||||
|
|
|
@ -29,155 +29,136 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
//
|
||||
// game dll specific defines
|
||||
//
|
||||
#include "g_local.h"
|
||||
# include "g_local.h"
|
||||
|
||||
#define STACK_Error gi.Error
|
||||
#define STACK_DPrintf gi.DPrintf
|
||||
#define STACK_WDPrintf(text) gi.DPrintf(text)
|
||||
# define STACK_Error gi.Error
|
||||
# define STACK_DPrintf gi.DPrintf
|
||||
# define STACK_WDPrintf(text) gi.DPrintf(text)
|
||||
|
||||
#elif defined(CGAME_DLL)
|
||||
//
|
||||
// cgame dll specific defines
|
||||
//
|
||||
#include "cg_local.h"
|
||||
# include "cg_local.h"
|
||||
|
||||
#define STACK_Error cgi.Error
|
||||
#define STACK_DPrintf cgi.DPrintf
|
||||
#define STACK_WDPrintf(text) cgi.DPrintf(text)
|
||||
# define STACK_Error cgi.Error
|
||||
# define STACK_DPrintf cgi.DPrintf
|
||||
# define STACK_WDPrintf(text) cgi.DPrintf(text)
|
||||
|
||||
#else
|
||||
|
||||
//
|
||||
// client specific defines
|
||||
//
|
||||
#define STACK_Error Com_Error
|
||||
#define STACK_DPrintf Com_DPrintf
|
||||
#define STACK_WDPrintf(text) Com_DPrintf(text)
|
||||
# define STACK_Error Com_Error
|
||||
# define STACK_DPrintf Com_DPrintf
|
||||
# define STACK_WDPrintf(text) Com_DPrintf(text)
|
||||
#endif
|
||||
|
||||
template <class Type>
|
||||
template<class Type>
|
||||
class StackNode
|
||||
{
|
||||
public:
|
||||
Type data;
|
||||
StackNode *next;
|
||||
Type data;
|
||||
StackNode *next;
|
||||
|
||||
StackNode( Type d );
|
||||
StackNode(Type d);
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
inline StackNode<Type>::StackNode( Type d ) : data( d )
|
||||
template<class Type>
|
||||
inline StackNode<Type>::StackNode(Type d)
|
||||
: data(d)
|
||||
{
|
||||
next = NULL;
|
||||
next = NULL;
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
template<class Type>
|
||||
class Stack
|
||||
{
|
||||
private:
|
||||
StackNode<Type> *head;
|
||||
StackNode<Type> *head;
|
||||
|
||||
public:
|
||||
Stack();
|
||||
~Stack<Type>();
|
||||
void Clear( void );
|
||||
qboolean Empty( void );
|
||||
void Push( Type data );
|
||||
Type Pop( void );
|
||||
Type Head( void );
|
||||
Stack();
|
||||
~Stack<Type>();
|
||||
void Clear(void);
|
||||
qboolean Empty(void);
|
||||
void Push(Type data);
|
||||
Type Pop(void);
|
||||
Type Head(void);
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
template<class Type>
|
||||
inline Stack<Type>::Stack()
|
||||
{
|
||||
head = NULL;
|
||||
head = NULL;
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
template<class Type>
|
||||
inline Stack<Type>::~Stack()
|
||||
{
|
||||
Clear();
|
||||
Clear();
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
inline void Stack<Type>::Clear
|
||||
(
|
||||
void
|
||||
)
|
||||
template<class Type>
|
||||
inline void Stack<Type>::Clear(void)
|
||||
{
|
||||
while( !Empty() )
|
||||
{
|
||||
Pop();
|
||||
}
|
||||
while (!Empty()) {
|
||||
Pop();
|
||||
}
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
inline qboolean Stack<Type>::Empty
|
||||
(
|
||||
void
|
||||
)
|
||||
template<class Type>
|
||||
inline qboolean Stack<Type>::Empty(void)
|
||||
{
|
||||
if( head == NULL )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (head == NULL) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
inline void Stack<Type>::Push
|
||||
(
|
||||
Type data
|
||||
)
|
||||
template<class Type>
|
||||
inline void Stack<Type>::Push(Type data)
|
||||
{
|
||||
StackNode<Type> *tmp;
|
||||
StackNode<Type> *tmp;
|
||||
|
||||
tmp = new StackNode<Type>( data );
|
||||
if( !tmp )
|
||||
{
|
||||
assert( NULL );
|
||||
STACK_Error( ERR_DROP, "Stack::Push : Out of memory" );
|
||||
}
|
||||
tmp = new StackNode<Type>(data);
|
||||
if (!tmp) {
|
||||
assert(NULL);
|
||||
STACK_Error(ERR_DROP, "Stack::Push : Out of memory");
|
||||
}
|
||||
|
||||
tmp->next = head;
|
||||
head = tmp;
|
||||
tmp->next = head;
|
||||
head = tmp;
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
inline Type Stack<Type>::Pop
|
||||
(
|
||||
void
|
||||
)
|
||||
template<class Type>
|
||||
inline Type Stack<Type>::Pop(void)
|
||||
{
|
||||
Type ret;
|
||||
StackNode<Type> *node;
|
||||
Type ret;
|
||||
StackNode<Type> *node;
|
||||
|
||||
if( !head )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (!head) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
node = head;
|
||||
ret = node->data;
|
||||
head = node->next;
|
||||
node = head;
|
||||
ret = node->data;
|
||||
head = node->next;
|
||||
|
||||
delete node;
|
||||
delete node;
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
inline Type Stack<Type>::Head
|
||||
(
|
||||
void
|
||||
)
|
||||
template<class Type>
|
||||
inline Type Stack<Type>::Head(void)
|
||||
{
|
||||
if( !head )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (!head) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return head->data;
|
||||
return head->data;
|
||||
}
|
||||
|
||||
#endif /* stack.h */
|
||||
|
|
1246
code/qcommon/str.cpp
1246
code/qcommon/str.cpp
File diff suppressed because it is too large
Load diff
1164
code/qcommon/str.h
1164
code/qcommon/str.h
File diff suppressed because it is too large
Load diff
|
@ -9,9 +9,8 @@
|
|||
|
||||
MEM_BlockAlloc<ScriptClass> ScriptClass_allocator;
|
||||
|
||||
CLASS_DECLARATION(Listener, ScriptClass, NULL)
|
||||
{
|
||||
{ NULL, NULL }
|
||||
CLASS_DECLARATION(Listener, ScriptClass, NULL) {
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -19,9 +18,9 @@ CLASS_DECLARATION(Listener, ScriptClass, NULL)
|
|||
new ScriptClass
|
||||
====================
|
||||
*/
|
||||
void* ScriptClass::operator new(size_t size)
|
||||
void *ScriptClass::operator new(size_t size)
|
||||
{
|
||||
return ScriptClass_allocator.Alloc();
|
||||
return ScriptClass_allocator.Alloc();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -29,9 +28,9 @@ void* ScriptClass::operator new(size_t size)
|
|||
delete ptr
|
||||
====================
|
||||
*/
|
||||
void ScriptClass::operator delete(void* ptr)
|
||||
void ScriptClass::operator delete(void *ptr)
|
||||
{
|
||||
ScriptClass_allocator.Free(ptr);
|
||||
ScriptClass_allocator.Free(ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -39,11 +38,11 @@ void ScriptClass::operator delete(void* ptr)
|
|||
ScriptClass
|
||||
====================
|
||||
*/
|
||||
ScriptClass::ScriptClass(GameScript* gameScript, Listener* self)
|
||||
ScriptClass::ScriptClass(GameScript *gameScript, Listener *self)
|
||||
{
|
||||
m_Self = self;
|
||||
m_Script = gameScript;
|
||||
m_Threads = NULL;
|
||||
m_Self = self;
|
||||
m_Script = gameScript;
|
||||
m_Threads = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -53,9 +52,9 @@ ScriptClass
|
|||
*/
|
||||
ScriptClass::ScriptClass()
|
||||
{
|
||||
m_Self = NULL;
|
||||
m_Script = NULL;
|
||||
m_Threads = NULL;
|
||||
m_Self = NULL;
|
||||
m_Script = NULL;
|
||||
m_Threads = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -65,17 +64,16 @@ ScriptClass::ScriptClass()
|
|||
*/
|
||||
ScriptClass::~ScriptClass()
|
||||
{
|
||||
if (m_Script == NULL) {
|
||||
throw ScriptException("Attempting to delete dead class.");
|
||||
}
|
||||
if (m_Script == NULL) {
|
||||
throw ScriptException("Attempting to delete dead class.");
|
||||
}
|
||||
|
||||
KillThreads();
|
||||
KillThreads();
|
||||
|
||||
if (!m_Script->m_Filename)
|
||||
{
|
||||
// This is a temporary gamescript
|
||||
delete m_Script;
|
||||
}
|
||||
if (!m_Script->m_Filename) {
|
||||
// This is a temporary gamescript
|
||||
delete m_Script;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -83,9 +81,7 @@ ScriptClass::~ScriptClass()
|
|||
Archive
|
||||
====================
|
||||
*/
|
||||
void ScriptClass::Archive(Archiver& arc)
|
||||
{
|
||||
}
|
||||
void ScriptClass::Archive(Archiver& arc) {}
|
||||
|
||||
/*
|
||||
====================
|
||||
|
@ -94,11 +90,11 @@ ArchiveInternal
|
|||
*/
|
||||
void ScriptClass::ArchiveInternal(Archiver& arc)
|
||||
{
|
||||
Listener::Archive(arc);
|
||||
Listener::Archive(arc);
|
||||
|
||||
arc.ArchiveObjectPosition(this);
|
||||
arc.ArchiveSafePointer(&m_Self);
|
||||
GameScript::Archive(arc, m_Script);
|
||||
arc.ArchiveObjectPosition(this);
|
||||
arc.ArchiveSafePointer(&m_Self);
|
||||
GameScript::Archive(arc, m_Script);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -106,43 +102,41 @@ void ScriptClass::ArchiveInternal(Archiver& arc)
|
|||
ArchiveScript
|
||||
====================
|
||||
*/
|
||||
void ScriptClass::ArchiveScript(Archiver& arc, ScriptClass** obj)
|
||||
void ScriptClass::ArchiveScript(Archiver& arc, ScriptClass **obj)
|
||||
{
|
||||
ScriptClass* scr;
|
||||
ScriptVM* m_current;
|
||||
ScriptThread* m_thread;
|
||||
int num;
|
||||
int i;
|
||||
ScriptClass *scr;
|
||||
ScriptVM *m_current;
|
||||
ScriptThread *m_thread;
|
||||
int num;
|
||||
int i;
|
||||
|
||||
if (arc.Saving())
|
||||
{
|
||||
scr = *obj;
|
||||
scr->ArchiveInternal(arc);
|
||||
if (arc.Saving()) {
|
||||
scr = *obj;
|
||||
scr->ArchiveInternal(arc);
|
||||
|
||||
num = 0;
|
||||
for (m_current = scr->m_Threads; m_current != NULL; m_current = m_current->next)
|
||||
num++;
|
||||
num = 0;
|
||||
for (m_current = scr->m_Threads; m_current != NULL; m_current = m_current->next) {
|
||||
num++;
|
||||
}
|
||||
|
||||
arc.ArchiveInteger(&num);
|
||||
arc.ArchiveInteger(&num);
|
||||
|
||||
for (m_current = scr->m_Threads; m_current != NULL; m_current = m_current->next)
|
||||
m_current->m_Thread->ArchiveInternal(arc);
|
||||
}
|
||||
else
|
||||
{
|
||||
scr = new ScriptClass();
|
||||
scr->ArchiveInternal(arc);
|
||||
for (m_current = scr->m_Threads; m_current != NULL; m_current = m_current->next) {
|
||||
m_current->m_Thread->ArchiveInternal(arc);
|
||||
}
|
||||
} else {
|
||||
scr = new ScriptClass();
|
||||
scr->ArchiveInternal(arc);
|
||||
|
||||
arc.ArchiveInteger(&num);
|
||||
arc.ArchiveInteger(&num);
|
||||
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
m_thread = new ScriptThread(scr, NULL);
|
||||
m_thread->ArchiveInternal(arc);
|
||||
}
|
||||
for (i = 0; i < num; i++) {
|
||||
m_thread = new ScriptThread(scr, NULL);
|
||||
m_thread->ArchiveInternal(arc);
|
||||
}
|
||||
|
||||
*obj = scr;
|
||||
}
|
||||
*obj = scr;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -150,9 +144,9 @@ void ScriptClass::ArchiveScript(Archiver& arc, ScriptClass** obj)
|
|||
ArchiveCodePos
|
||||
====================
|
||||
*/
|
||||
void ScriptClass::ArchiveCodePos(Archiver& arc, unsigned char** codePos)
|
||||
void ScriptClass::ArchiveCodePos(Archiver& arc, unsigned char **codePos)
|
||||
{
|
||||
m_Script->ArchiveCodePos(arc, codePos);
|
||||
m_Script->ArchiveCodePos(arc, codePos);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -160,42 +154,40 @@ void ScriptClass::ArchiveCodePos(Archiver& arc, unsigned char** codePos)
|
|||
CreateThreadInternal
|
||||
====================
|
||||
*/
|
||||
ScriptThread* ScriptClass::CreateThreadInternal(const ScriptVariable& label)
|
||||
ScriptThread *ScriptClass::CreateThreadInternal(const ScriptVariable& label)
|
||||
{
|
||||
GameScript* scr;
|
||||
ScriptThread* thread = NULL;
|
||||
GameScript *scr;
|
||||
ScriptThread *thread = NULL;
|
||||
|
||||
if (label.GetType() == VARIABLE_STRING || label.GetType() == VARIABLE_CONSTSTRING)
|
||||
{
|
||||
ScriptClass* scriptClass = Director.CurrentScriptClass();
|
||||
scr = scriptClass->GetScript();
|
||||
if (label.GetType() == VARIABLE_STRING || label.GetType() == VARIABLE_CONSTSTRING) {
|
||||
ScriptClass *scriptClass = Director.CurrentScriptClass();
|
||||
scr = scriptClass->GetScript();
|
||||
|
||||
if (label.GetType() == VARIABLE_CONSTSTRING)
|
||||
thread = Director.CreateScriptThread(scr, m_Self, label.constStringValue());
|
||||
else
|
||||
thread = Director.CreateScriptThread(scr, m_Self, label.stringValue());
|
||||
}
|
||||
else if (label.GetType() == VARIABLE_CONSTARRAY && label.arraysize() > 1)
|
||||
{
|
||||
ScriptVariable* script = label[1];
|
||||
ScriptVariable* labelname = label[2];
|
||||
if (label.GetType() == VARIABLE_CONSTSTRING) {
|
||||
thread = Director.CreateScriptThread(scr, m_Self, label.constStringValue());
|
||||
} else {
|
||||
thread = Director.CreateScriptThread(scr, m_Self, label.stringValue());
|
||||
}
|
||||
} else if (label.GetType() == VARIABLE_CONSTARRAY && label.arraysize() > 1) {
|
||||
ScriptVariable *script = label[1];
|
||||
ScriptVariable *labelname = label[2];
|
||||
|
||||
if (script->GetType() == VARIABLE_CONSTSTRING)
|
||||
scr = Director.GetGameScript(script->constStringValue());
|
||||
else
|
||||
scr = Director.GetGameScript(script->stringValue());
|
||||
if (script->GetType() == VARIABLE_CONSTSTRING) {
|
||||
scr = Director.GetGameScript(script->constStringValue());
|
||||
} else {
|
||||
scr = Director.GetGameScript(script->stringValue());
|
||||
}
|
||||
|
||||
if (labelname->GetType() == VARIABLE_CONSTSTRING)
|
||||
thread = Director.CreateScriptThread(scr, m_Self, labelname->constStringValue());
|
||||
else
|
||||
thread = Director.CreateScriptThread(scr, m_Self, labelname->stringValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
ScriptError("ScriptClass::CreateThreadInternal: bad argument format");
|
||||
}
|
||||
if (labelname->GetType() == VARIABLE_CONSTSTRING) {
|
||||
thread = Director.CreateScriptThread(scr, m_Self, labelname->constStringValue());
|
||||
} else {
|
||||
thread = Director.CreateScriptThread(scr, m_Self, labelname->stringValue());
|
||||
}
|
||||
} else {
|
||||
ScriptError("ScriptClass::CreateThreadInternal: bad argument format");
|
||||
}
|
||||
|
||||
return thread;
|
||||
return thread;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -203,39 +195,37 @@ ScriptThread* ScriptClass::CreateThreadInternal(const ScriptVariable& label)
|
|||
CreateScriptInternal
|
||||
====================
|
||||
*/
|
||||
ScriptThread* ScriptClass::CreateScriptInternal(const ScriptVariable& label)
|
||||
ScriptThread *ScriptClass::CreateScriptInternal(const ScriptVariable& label)
|
||||
{
|
||||
GameScript* scr;
|
||||
ScriptThread* thread = NULL;
|
||||
GameScript *scr;
|
||||
ScriptThread *thread = NULL;
|
||||
|
||||
if (label.GetType() == VARIABLE_STRING || label.GetType() == VARIABLE_CONSTSTRING)
|
||||
{
|
||||
if (label.GetType() == VARIABLE_CONSTSTRING)
|
||||
thread = Director.CreateScriptThread(Director.GetGameScript(label.stringValue()), m_Self, "");
|
||||
else
|
||||
thread = Director.CreateScriptThread(Director.GetGameScript(label.constStringValue()), m_Self, "");
|
||||
}
|
||||
else if (label.GetType() == VARIABLE_CONSTARRAY && label.arraysize() > 1)
|
||||
{
|
||||
ScriptVariable* script = label[1];
|
||||
ScriptVariable* labelname = label[2];
|
||||
if (label.GetType() == VARIABLE_STRING || label.GetType() == VARIABLE_CONSTSTRING) {
|
||||
if (label.GetType() == VARIABLE_CONSTSTRING) {
|
||||
thread = Director.CreateScriptThread(Director.GetGameScript(label.stringValue()), m_Self, "");
|
||||
} else {
|
||||
thread = Director.CreateScriptThread(Director.GetGameScript(label.constStringValue()), m_Self, "");
|
||||
}
|
||||
} else if (label.GetType() == VARIABLE_CONSTARRAY && label.arraysize() > 1) {
|
||||
ScriptVariable *script = label[1];
|
||||
ScriptVariable *labelname = label[2];
|
||||
|
||||
if (script->GetType() == VARIABLE_CONSTSTRING)
|
||||
scr = Director.GetGameScript(script->constStringValue());
|
||||
else
|
||||
scr = Director.GetGameScript(script->stringValue());
|
||||
if (script->GetType() == VARIABLE_CONSTSTRING) {
|
||||
scr = Director.GetGameScript(script->constStringValue());
|
||||
} else {
|
||||
scr = Director.GetGameScript(script->stringValue());
|
||||
}
|
||||
|
||||
if (labelname->GetType() == VARIABLE_CONSTSTRING)
|
||||
thread = Director.CreateScriptThread(scr, m_Self, labelname->constStringValue());
|
||||
else
|
||||
thread = Director.CreateScriptThread(scr, m_Self, labelname->stringValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
ScriptError("ScriptClass::CreateScriptInternal: bad label type '%s'", label.GetTypeName());
|
||||
}
|
||||
if (labelname->GetType() == VARIABLE_CONSTSTRING) {
|
||||
thread = Director.CreateScriptThread(scr, m_Self, labelname->constStringValue());
|
||||
} else {
|
||||
thread = Director.CreateScriptThread(scr, m_Self, labelname->stringValue());
|
||||
}
|
||||
} else {
|
||||
ScriptError("ScriptClass::CreateScriptInternal: bad label type '%s'", label.GetTypeName());
|
||||
}
|
||||
|
||||
return thread;
|
||||
return thread;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -243,10 +233,10 @@ ScriptThread* ScriptClass::CreateScriptInternal(const ScriptVariable& label)
|
|||
AddThread
|
||||
====================
|
||||
*/
|
||||
void ScriptClass::AddThread(ScriptVM* m_ScriptVM)
|
||||
void ScriptClass::AddThread(ScriptVM *m_ScriptVM)
|
||||
{
|
||||
m_ScriptVM->next = m_Threads;
|
||||
m_Threads = m_ScriptVM;
|
||||
m_ScriptVM->next = m_Threads;
|
||||
m_Threads = m_ScriptVM;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -256,25 +246,24 @@ KillThreads
|
|||
*/
|
||||
void ScriptClass::KillThreads()
|
||||
{
|
||||
if (!m_Threads) {
|
||||
return;
|
||||
}
|
||||
if (!m_Threads) {
|
||||
return;
|
||||
}
|
||||
|
||||
ScriptVM* m_current;
|
||||
ScriptVM* m_next;
|
||||
ScriptVM *m_current;
|
||||
ScriptVM *m_next;
|
||||
|
||||
m_current = m_Threads;
|
||||
m_current = m_Threads;
|
||||
|
||||
do
|
||||
{
|
||||
m_current->m_ScriptClass = NULL;
|
||||
do {
|
||||
m_current->m_ScriptClass = NULL;
|
||||
|
||||
m_next = m_current->next;
|
||||
delete m_current->m_Thread;
|
||||
m_next = m_current->next;
|
||||
delete m_current->m_Thread;
|
||||
|
||||
} while ((m_current = m_next) != nullptr);
|
||||
} while ((m_current = m_next) != nullptr);
|
||||
|
||||
m_Threads = NULL;
|
||||
m_Threads = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -282,27 +271,24 @@ void ScriptClass::KillThreads()
|
|||
RemoveThread
|
||||
====================
|
||||
*/
|
||||
void ScriptClass::RemoveThread(ScriptVM* m_ScriptVM)
|
||||
void ScriptClass::RemoveThread(ScriptVM *m_ScriptVM)
|
||||
{
|
||||
if (m_Threads == m_ScriptVM)
|
||||
{
|
||||
m_Threads = m_ScriptVM->next;
|
||||
if (m_Threads == m_ScriptVM) {
|
||||
m_Threads = m_ScriptVM->next;
|
||||
|
||||
if (m_Threads == NULL) {
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ScriptVM* m_current = m_Threads;
|
||||
ScriptVM* i;
|
||||
if (m_Threads == NULL) {
|
||||
delete this;
|
||||
}
|
||||
} else {
|
||||
ScriptVM *m_current = m_Threads;
|
||||
ScriptVM *i;
|
||||
|
||||
for (i = m_Threads->next; i != m_ScriptVM; i = i->next) {
|
||||
m_current = i;
|
||||
}
|
||||
for (i = m_Threads->next; i != m_ScriptVM; i = i->next) {
|
||||
m_current = i;
|
||||
}
|
||||
|
||||
m_current->next = i->next;
|
||||
}
|
||||
m_current->next = i->next;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -312,7 +298,7 @@ Filename
|
|||
*/
|
||||
str ScriptClass::Filename()
|
||||
{
|
||||
return m_Script->Filename();
|
||||
return m_Script->Filename();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -320,9 +306,9 @@ str ScriptClass::Filename()
|
|||
FindLabel
|
||||
====================
|
||||
*/
|
||||
unsigned char* ScriptClass::FindLabel(str label)
|
||||
unsigned char *ScriptClass::FindLabel(str label)
|
||||
{
|
||||
return m_Script->m_State.FindLabel(label);
|
||||
return m_Script->m_State.FindLabel(label);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -330,9 +316,9 @@ unsigned char* ScriptClass::FindLabel(str label)
|
|||
FindLabel
|
||||
====================
|
||||
*/
|
||||
unsigned char* ScriptClass::FindLabel(const_str label)
|
||||
unsigned char *ScriptClass::FindLabel(const_str label)
|
||||
{
|
||||
return m_Script->m_State.FindLabel(label);
|
||||
return m_Script->m_State.FindLabel(label);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -340,9 +326,9 @@ unsigned char* ScriptClass::FindLabel(const_str label)
|
|||
NearestLabel
|
||||
====================
|
||||
*/
|
||||
const_str ScriptClass::NearestLabel(unsigned char* pos)
|
||||
const_str ScriptClass::NearestLabel(unsigned char *pos)
|
||||
{
|
||||
return m_Script->m_State.NearestLabel(pos);
|
||||
return m_Script->m_State.NearestLabel(pos);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -350,9 +336,9 @@ const_str ScriptClass::NearestLabel(unsigned char* pos)
|
|||
GetCatchStateScript
|
||||
====================
|
||||
*/
|
||||
StateScript* ScriptClass::GetCatchStateScript(unsigned char* in, unsigned char*& out)
|
||||
StateScript *ScriptClass::GetCatchStateScript(unsigned char *in, unsigned char *& out)
|
||||
{
|
||||
return m_Script->GetCatchStateScript(in, out);
|
||||
return m_Script->GetCatchStateScript(in, out);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -360,9 +346,9 @@ StateScript* ScriptClass::GetCatchStateScript(unsigned char* in, unsigned char*&
|
|||
GetScript
|
||||
====================
|
||||
*/
|
||||
GameScript* ScriptClass::GetScript()
|
||||
GameScript *ScriptClass::GetScript()
|
||||
{
|
||||
return m_Script;
|
||||
return m_Script;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -370,7 +356,7 @@ GameScript* ScriptClass::GetScript()
|
|||
GetSelf
|
||||
====================
|
||||
*/
|
||||
Listener* ScriptClass::GetSelf()
|
||||
Listener *ScriptClass::GetSelf()
|
||||
{
|
||||
return static_cast<Listener*>(m_Self.Pointer());
|
||||
return static_cast<Listener *>(m_Self.Pointer());
|
||||
}
|
||||
|
|
|
@ -33,50 +33,50 @@ class StateScript;
|
|||
|
||||
class ScriptClass : public Listener
|
||||
{
|
||||
friend GameScript;
|
||||
friend StateScript;
|
||||
friend GameScript;
|
||||
friend StateScript;
|
||||
|
||||
public:
|
||||
// script variable
|
||||
GameScript* m_Script; // current game script
|
||||
// script variable
|
||||
GameScript *m_Script; // current game script
|
||||
|
||||
// listener variable
|
||||
SafePtr<Listener> m_Self; // self
|
||||
// listener variable
|
||||
SafePtr<Listener> m_Self; // self
|
||||
|
||||
// thread variable
|
||||
ScriptVM* m_Threads; // threads list
|
||||
// thread variable
|
||||
ScriptVM *m_Threads; // threads list
|
||||
|
||||
public:
|
||||
CLASS_PROTOTYPE(ScriptClass);
|
||||
CLASS_PROTOTYPE(ScriptClass);
|
||||
|
||||
#ifndef _DEBUG_MEM
|
||||
void* operator new(size_t size);
|
||||
void operator delete(void* ptr);
|
||||
void *operator new(size_t size);
|
||||
void operator delete(void *ptr);
|
||||
#endif
|
||||
|
||||
ScriptClass(GameScript* gameScript, Listener* self);
|
||||
ScriptClass();
|
||||
~ScriptClass();
|
||||
ScriptClass(GameScript *gameScript, Listener *self);
|
||||
ScriptClass();
|
||||
~ScriptClass();
|
||||
|
||||
void Archive(Archiver& arc) override;
|
||||
void ArchiveInternal(Archiver& arc);
|
||||
static void ArchiveScript(Archiver& arc, ScriptClass** obj);
|
||||
void ArchiveCodePos(Archiver& arc, unsigned char** codePos);
|
||||
void Archive(Archiver &arc) override;
|
||||
void ArchiveInternal(Archiver &arc);
|
||||
static void ArchiveScript(Archiver& arc, ScriptClass **obj);
|
||||
void ArchiveCodePos(Archiver &arc, unsigned char **codePos);
|
||||
|
||||
ScriptThread* CreateThreadInternal(const ScriptVariable& label) override;
|
||||
ScriptThread* CreateScriptInternal(const ScriptVariable& label) override;
|
||||
ScriptThread *CreateThreadInternal(const ScriptVariable& label) override;
|
||||
ScriptThread *CreateScriptInternal(const ScriptVariable& label) override;
|
||||
|
||||
void AddThread(ScriptVM* m_ScriptVM);
|
||||
void KillThreads(void);
|
||||
void RemoveThread(ScriptVM* m_ScriptVM);
|
||||
void AddThread(ScriptVM *m_ScriptVM);
|
||||
void KillThreads(void);
|
||||
void RemoveThread(ScriptVM *m_ScriptVM);
|
||||
|
||||
str Filename();
|
||||
unsigned char* FindLabel(str label);
|
||||
unsigned char* FindLabel(const_str label);
|
||||
const_str NearestLabel(unsigned char* pos);
|
||||
str Filename();
|
||||
unsigned char *FindLabel(str label);
|
||||
unsigned char *FindLabel(const_str label);
|
||||
const_str NearestLabel(unsigned char *pos);
|
||||
|
||||
StateScript* GetCatchStateScript(unsigned char* in, unsigned char*& out);
|
||||
StateScript *GetCatchStateScript(unsigned char *in, unsigned char *& out);
|
||||
|
||||
GameScript* GetScript();
|
||||
Listener* GetSelf();
|
||||
GameScript *GetScript();
|
||||
Listener *GetSelf();
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -31,160 +31,159 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
class ScriptVariable;
|
||||
|
||||
enum
|
||||
{
|
||||
method_game,
|
||||
method_level,
|
||||
method_local,
|
||||
method_parm,
|
||||
method_self,
|
||||
method_group,
|
||||
method_owner,
|
||||
method_field,
|
||||
method_array,
|
||||
enum {
|
||||
method_game,
|
||||
method_level,
|
||||
method_local,
|
||||
method_parm,
|
||||
method_self,
|
||||
method_group,
|
||||
method_owner,
|
||||
method_field,
|
||||
method_array,
|
||||
};
|
||||
|
||||
typedef struct scriptmacro {
|
||||
str name;
|
||||
str parameters;
|
||||
str name;
|
||||
str parameters;
|
||||
} scriptmacro_t;
|
||||
|
||||
#define BREAK_JUMP_LOCATION_COUNT 100
|
||||
#define CONTINUE_JUMP_LOCATION_COUNT 100
|
||||
#define BREAK_JUMP_LOCATION_COUNT 100
|
||||
#define CONTINUE_JUMP_LOCATION_COUNT 100
|
||||
|
||||
class ScriptCompiler
|
||||
{
|
||||
public:
|
||||
unsigned char *code_pos;
|
||||
unsigned char *code_ptr;
|
||||
unsigned char *prog_ptr;
|
||||
unsigned char *prog_end_ptr;
|
||||
unsigned char *code_pos;
|
||||
unsigned char *code_ptr;
|
||||
unsigned char *prog_ptr;
|
||||
unsigned char *prog_end_ptr;
|
||||
|
||||
GameScript *script;
|
||||
StateScript *stateScript;
|
||||
GameScript *script;
|
||||
StateScript *stateScript;
|
||||
|
||||
bool bCanBreak;
|
||||
bool bCanContinue;
|
||||
bool bCanBreak;
|
||||
bool bCanContinue;
|
||||
|
||||
opcode_info_t prev_opcodes[ 100 ];
|
||||
unsigned int prev_opcode_pos;
|
||||
opcode_info_t prev_opcodes[100];
|
||||
unsigned int prev_opcode_pos;
|
||||
|
||||
int m_iVarStackOffset;
|
||||
int m_iInternalMaxVarStackOffset;
|
||||
int m_iMaxExternalVarStackOffset;
|
||||
int m_iMaxCallStackOffset;
|
||||
int m_iHasExternal;
|
||||
int m_iVarStackOffset;
|
||||
int m_iInternalMaxVarStackOffset;
|
||||
int m_iMaxExternalVarStackOffset;
|
||||
int m_iMaxCallStackOffset;
|
||||
int m_iHasExternal;
|
||||
|
||||
unsigned char *apucBreakJumpLocations[ BREAK_JUMP_LOCATION_COUNT ];
|
||||
int iBreakJumpLocCount;
|
||||
unsigned char *apucContinueJumpLocations[ CONTINUE_JUMP_LOCATION_COUNT ];
|
||||
int iContinueJumpLocCount;
|
||||
unsigned char *apucBreakJumpLocations[BREAK_JUMP_LOCATION_COUNT];
|
||||
int iBreakJumpLocCount;
|
||||
unsigned char *apucContinueJumpLocations[CONTINUE_JUMP_LOCATION_COUNT];
|
||||
int iContinueJumpLocCount;
|
||||
|
||||
bool compileSuccess;
|
||||
bool compileSuccess;
|
||||
|
||||
static int current_label;
|
||||
static int current_label;
|
||||
|
||||
public:
|
||||
ScriptCompiler();
|
||||
void Reset();
|
||||
ScriptCompiler();
|
||||
void Reset();
|
||||
|
||||
unsigned char PrevOpcode();
|
||||
char PrevVarStackOffset();
|
||||
void AbsorbPrevOpcode();
|
||||
void ClearPrevOpcode();
|
||||
unsigned char PrevOpcode();
|
||||
char PrevVarStackOffset();
|
||||
void AbsorbPrevOpcode();
|
||||
void ClearPrevOpcode();
|
||||
|
||||
void AddBreakJumpLocation( unsigned char *pos );
|
||||
void AddContinueJumpLocation( unsigned char *pos );
|
||||
void AddJumpLocation( unsigned char *pos );
|
||||
void AddJumpBackLocation( unsigned char *pos );
|
||||
void AddJumpToLocation( unsigned char *pos );
|
||||
void AddBreakJumpLocation(unsigned char *pos);
|
||||
void AddContinueJumpLocation(unsigned char *pos);
|
||||
void AddJumpLocation(unsigned char *pos);
|
||||
void AddJumpBackLocation(unsigned char *pos);
|
||||
void AddJumpToLocation(unsigned char *pos);
|
||||
|
||||
bool BuiltinReadVariable( unsigned int sourcePos, int type, int eventnum );
|
||||
bool BuiltinWriteVariable( unsigned int sourcePos, int type, int eventnum );
|
||||
bool BuiltinReadVariable(unsigned int sourcePos, int type, int eventnum);
|
||||
bool BuiltinWriteVariable(unsigned int sourcePos, int type, int eventnum);
|
||||
|
||||
void EmitAssignmentStatement( sval_t lhs, unsigned int sourcePos );
|
||||
void EmitAssignmentStatement(sval_t lhs, unsigned int sourcePos);
|
||||
|
||||
void EmitBoolJumpFalse( unsigned int sourcePos );
|
||||
void EmitBoolJumpTrue( unsigned int sourcePos );
|
||||
void EmitBoolNot( unsigned int sourcePos );
|
||||
void EmitBoolToVar( unsigned int sourcePos );
|
||||
void EmitBoolJumpFalse(unsigned int sourcePos);
|
||||
void EmitBoolJumpTrue(unsigned int sourcePos);
|
||||
void EmitBoolNot(unsigned int sourcePos);
|
||||
void EmitBoolToVar(unsigned int sourcePos);
|
||||
|
||||
void EmitBreak( unsigned int sourcePos );
|
||||
void EmitCatch( sval_t val, unsigned char *try_begin_code_pos, unsigned int sourcePos );
|
||||
void EmitConstArray( sval_t lhs, sval_t rhs, unsigned int sourcePos );
|
||||
void EmitConstArrayOpcode( int iCount );
|
||||
void EmitContinue( unsigned int sourcePos );
|
||||
void EmitDoWhileJump( sval_t while_stmt, sval_t while_expr, unsigned int sourcePos );
|
||||
void EmitEof( unsigned int sourcePos );
|
||||
void EmitField( sval_t listener_val, sval_t field_val, unsigned int sourcePos );
|
||||
void EmitFloat( float value, unsigned int sourcePos );
|
||||
void EmitFunc1( int opcode, unsigned int sourcePos );
|
||||
void EmitFunction( int iParamCount, sval_t val, unsigned int sourcePos );
|
||||
void EmitIfElseJump( sval_t if_stmt, sval_t else_stmt, unsigned int sourcePos );
|
||||
void EmitIfJump( sval_t if_stmt, unsigned int sourcePos );
|
||||
void EmitInteger( unsigned int value, unsigned int sourcePos );
|
||||
void EmitJump( unsigned char *pos, unsigned int sourcePos );
|
||||
void EmitJumpBack( unsigned char *pos, unsigned int sourcePos );
|
||||
void EmitLabel( str name, unsigned int sourcePos );
|
||||
void EmitLabelParameterList( sval_t parameter_list, unsigned int sourcePos );
|
||||
void EmitLabelPrivate( str name, unsigned int sourcePos );
|
||||
void EmitLogicJump( sval_t logic_stmt, bool isOr, unsigned int sourcePos );
|
||||
void EmitMakeArray( sval_t val );
|
||||
void EmitMethodExpression( int iParamCount, int eventnum, unsigned int sourcePos );
|
||||
void EmitNil( unsigned int sourcePos );
|
||||
void EmitNop();
|
||||
int EmitNot( unsigned int sourcePos );
|
||||
void EmitOpcode( int opcode, unsigned int sourcePos );
|
||||
void EmitParameter( sval_u lhs, unsigned int sourcePos );
|
||||
int EmitParameterList( sval_t event_parameter_list );
|
||||
void EmitRef( sval_t val, unsigned int sourcePos );
|
||||
void EmitStatementList( sval_t val );
|
||||
void EmitString( str value, unsigned int sourcePos );
|
||||
void EmitSwitch( sval_t val, unsigned int sourcePos );
|
||||
void EmitValue( sval_t val );
|
||||
void EmitValue( ScriptVariable& var, unsigned int sourcePos );
|
||||
void EmitVarToBool( unsigned int sourcePos );
|
||||
void EmitWhileJump( sval_t while_expr, sval_t while_stmt, sval_t inc_stmt, unsigned int sourcePos );
|
||||
void EmitBreak(unsigned int sourcePos);
|
||||
void EmitCatch(sval_t val, unsigned char *try_begin_code_pos, unsigned int sourcePos);
|
||||
void EmitConstArray(sval_t lhs, sval_t rhs, unsigned int sourcePos);
|
||||
void EmitConstArrayOpcode(int iCount);
|
||||
void EmitContinue(unsigned int sourcePos);
|
||||
void EmitDoWhileJump(sval_t while_stmt, sval_t while_expr, unsigned int sourcePos);
|
||||
void EmitEof(unsigned int sourcePos);
|
||||
void EmitField(sval_t listener_val, sval_t field_val, unsigned int sourcePos);
|
||||
void EmitFloat(float value, unsigned int sourcePos);
|
||||
void EmitFunc1(int opcode, unsigned int sourcePos);
|
||||
void EmitFunction(int iParamCount, sval_t val, unsigned int sourcePos);
|
||||
void EmitIfElseJump(sval_t if_stmt, sval_t else_stmt, unsigned int sourcePos);
|
||||
void EmitIfJump(sval_t if_stmt, unsigned int sourcePos);
|
||||
void EmitInteger(unsigned int value, unsigned int sourcePos);
|
||||
void EmitJump(unsigned char *pos, unsigned int sourcePos);
|
||||
void EmitJumpBack(unsigned char *pos, unsigned int sourcePos);
|
||||
void EmitLabel(str name, unsigned int sourcePos);
|
||||
void EmitLabelParameterList(sval_t parameter_list, unsigned int sourcePos);
|
||||
void EmitLabelPrivate(str name, unsigned int sourcePos);
|
||||
void EmitLogicJump(sval_t logic_stmt, bool isOr, unsigned int sourcePos);
|
||||
void EmitMakeArray(sval_t val);
|
||||
void EmitMethodExpression(int iParamCount, int eventnum, unsigned int sourcePos);
|
||||
void EmitNil(unsigned int sourcePos);
|
||||
void EmitNop();
|
||||
int EmitNot(unsigned int sourcePos);
|
||||
void EmitOpcode(int opcode, unsigned int sourcePos);
|
||||
void EmitParameter(sval_u lhs, unsigned int sourcePos);
|
||||
int EmitParameterList(sval_t event_parameter_list);
|
||||
void EmitRef(sval_t val, unsigned int sourcePos);
|
||||
void EmitStatementList(sval_t val);
|
||||
void EmitString(str value, unsigned int sourcePos);
|
||||
void EmitSwitch(sval_t val, unsigned int sourcePos);
|
||||
void EmitValue(sval_t val);
|
||||
void EmitValue(ScriptVariable& var, unsigned int sourcePos);
|
||||
void EmitVarToBool(unsigned int sourcePos);
|
||||
void EmitWhileJump(sval_t while_expr, sval_t while_stmt, sval_t inc_stmt, unsigned int sourcePos);
|
||||
|
||||
bool EvalPrevValue( ScriptVariable& var );
|
||||
bool EvalPrevValue(ScriptVariable& var);
|
||||
|
||||
void ProcessBreakJumpLocations( int iStartBreakJumpLocCount );
|
||||
void ProcessContinueJumpLocations( int iStartContinueJumpLocCount );
|
||||
void ProcessBreakJumpLocations(int iStartBreakJumpLocCount);
|
||||
void ProcessContinueJumpLocations(int iStartContinueJumpLocCount);
|
||||
|
||||
unsigned char *GetPosition();
|
||||
unsigned char *GetPosition();
|
||||
|
||||
// compile
|
||||
void CompileError( unsigned int sourcePos, const char *format, ... );
|
||||
// compile
|
||||
void CompileError(unsigned int sourcePos, const char *format, ...);
|
||||
|
||||
scriptmacro_t *GetMacro( char *sourceLine );
|
||||
scriptmacro_t *GetMacro(char *sourceLine);
|
||||
|
||||
char *Preprocess( char *sourceBuffer );
|
||||
void Preclean( char *processedBuffer );
|
||||
size_t Parse( GameScript *m_GameScript, char *sourceBuffer );
|
||||
size_t Compile( GameScript *m_GameScript, unsigned char *progBuffer );
|
||||
char *Preprocess(char *sourceBuffer);
|
||||
void Preclean(char *processedBuffer);
|
||||
size_t Parse(GameScript *m_GameScript, char *sourceBuffer);
|
||||
size_t Compile(GameScript *m_GameScript, unsigned char *progBuffer);
|
||||
|
||||
static str GetLine( str content, int line );
|
||||
static str GetLine(str content, int line);
|
||||
|
||||
private:
|
||||
template<typename Value>
|
||||
void EmitOpcodeValue(const Value& value, size_t size);
|
||||
template<typename Value>
|
||||
void EmitOpcodeValue(const Value& value, size_t size);
|
||||
|
||||
template<typename Value>
|
||||
void EmitAt(unsigned char* location, const Value& value, size_t size);
|
||||
template<typename Value>
|
||||
void EmitAt(unsigned char *location, const Value& value, size_t size);
|
||||
|
||||
template<typename Value>
|
||||
void SetOpcodeValue(const Value& value);
|
||||
template<typename Value>
|
||||
void SetOpcodeValue(const Value& value);
|
||||
|
||||
template<typename Value>
|
||||
Value GetOpcodeValue(size_t size) const;
|
||||
template<typename Value>
|
||||
Value GetOpcodeValue(size_t size) const;
|
||||
|
||||
template<typename Value>
|
||||
Value GetOpcodeValue(size_t offset, size_t size) const;
|
||||
template<typename Value>
|
||||
Value GetOpcodeValue(size_t offset, size_t size) const;
|
||||
};
|
||||
|
||||
extern ScriptCompiler Compiler;
|
||||
|
||||
void CompileAssemble( const char *filename, const char *outputfile );
|
||||
bool GetCompiledScript( GameScript *scr );
|
||||
void CompileAssemble(const char *filename, const char *outputfile);
|
||||
bool GetCompiledScript(GameScript *scr);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,49 +26,49 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
#include <cstdarg>
|
||||
|
||||
int ScriptException::next_abort = 0;
|
||||
int ScriptException::next_abort = 0;
|
||||
int ScriptException::next_bIsForAnim = 0;
|
||||
|
||||
void ScriptException::CreateException( const char *data )
|
||||
void ScriptException::CreateException(const char *data)
|
||||
{
|
||||
string = data;
|
||||
string = data;
|
||||
|
||||
bAbort = next_abort;
|
||||
next_abort = 0;
|
||||
bIsForAnim = next_bIsForAnim;
|
||||
next_bIsForAnim = 0;
|
||||
bAbort = next_abort;
|
||||
next_abort = 0;
|
||||
bIsForAnim = next_bIsForAnim;
|
||||
next_bIsForAnim = 0;
|
||||
}
|
||||
|
||||
ScriptException::ScriptException( str text )
|
||||
ScriptException::ScriptException(str text)
|
||||
{
|
||||
CreateException( text.c_str() );
|
||||
CreateException(text.c_str());
|
||||
}
|
||||
|
||||
ScriptException::ScriptException( const char *format, ... )
|
||||
ScriptException::ScriptException(const char *format, ...)
|
||||
{
|
||||
va_list va;
|
||||
char data[4100];
|
||||
va_list va;
|
||||
char data[4100];
|
||||
|
||||
va_start( va, format );
|
||||
vsprintf( data, format, va);
|
||||
va_end( va );
|
||||
va_start(va, format);
|
||||
vsprintf(data, format, va);
|
||||
va_end(va);
|
||||
|
||||
CreateException( data );
|
||||
CreateException(data);
|
||||
}
|
||||
|
||||
ScriptException::ScriptException( char *text )
|
||||
ScriptException::ScriptException(char *text)
|
||||
{
|
||||
CreateException( text );
|
||||
CreateException(text);
|
||||
}
|
||||
|
||||
void Error( const char * format, ... )
|
||||
void Error(const char *format, ...)
|
||||
{
|
||||
va_list va;
|
||||
char data[4100];
|
||||
va_list va;
|
||||
char data[4100];
|
||||
|
||||
va_start( va, format );
|
||||
vsprintf( data, format, va);
|
||||
va_end( va );
|
||||
va_start(va, format);
|
||||
vsprintf(data, format, va);
|
||||
va_end(va);
|
||||
|
||||
throw ScriptException( ( const char * )data );
|
||||
throw ScriptException((const char *)data);
|
||||
}
|
||||
|
|
|
@ -30,25 +30,25 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
class ScriptException
|
||||
{
|
||||
public:
|
||||
str string;
|
||||
int bAbort;
|
||||
int bIsForAnim;
|
||||
str string;
|
||||
int bAbort;
|
||||
int bIsForAnim;
|
||||
|
||||
private:
|
||||
void CreateException( const char *data );
|
||||
void CreateException(const char *data);
|
||||
|
||||
public:
|
||||
ScriptException( str text );
|
||||
ScriptException( const char *format, ... );
|
||||
ScriptException( char *text );
|
||||
ScriptException(str text);
|
||||
ScriptException(const char *format, ...);
|
||||
ScriptException(char *text);
|
||||
|
||||
static int next_abort;
|
||||
static int next_bIsForAnim;
|
||||
static int next_abort;
|
||||
static int next_bIsForAnim;
|
||||
};
|
||||
|
||||
void Error( const char * format, ... );
|
||||
void Error(const char *format, ...);
|
||||
|
||||
#define ScriptDeprecated( function ) throw ScriptException( function ": DEPRECATED. DON'T USE IT ANYMORE" )
|
||||
#define ScriptError throw ScriptException
|
||||
#define ScriptDeprecated(function) throw ScriptException(function ": DEPRECATED. DON'T USE IT ANYMORE")
|
||||
#define ScriptError throw ScriptException
|
||||
|
||||
#endif /* __EXCEPT_H__ */
|
||||
|
|
|
@ -26,164 +26,156 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
#include "short3.h"
|
||||
#include "vector.h"
|
||||
|
||||
static opcode_t OpcodeInfo[] =
|
||||
{
|
||||
{ "OPCODE_EOF", 0, 0, 0 },
|
||||
{ "OPCODE_BOOL_JUMP_FALSE4", 5, -1, 0 },
|
||||
{ "OPCODE_BOOL_JUMP_TRUE4", 5, -1, 0 },
|
||||
{ "OPCODE_VAR_JUMP_FALSE4", 5, -1, 0 },
|
||||
{ "OPCODE_VAR_JUMP_TRUE4", 5, -1, 0 },
|
||||
static opcode_t OpcodeInfo[] = {
|
||||
{"OPCODE_EOF", 0, 0, 0},
|
||||
{"OPCODE_BOOL_JUMP_FALSE4", 5, -1, 0},
|
||||
{"OPCODE_BOOL_JUMP_TRUE4", 5, -1, 0},
|
||||
{"OPCODE_VAR_JUMP_FALSE4", 5, -1, 0},
|
||||
{"OPCODE_VAR_JUMP_TRUE4", 5, -1, 0},
|
||||
|
||||
{ "OPCODE_BOOL_LOGICAL_AND", 5, -1, 0 },
|
||||
{ "OPCODE_BOOL_LOGICAL_OR", 5, -1, 0 },
|
||||
{ "OPCODE_VAR_LOGICAL_AND", 5, -1, 0 },
|
||||
{ "OPCODE_VAR_LOGICAL_OR", 5, -1, 0 },
|
||||
{"OPCODE_BOOL_LOGICAL_AND", 5, -1, 0},
|
||||
{"OPCODE_BOOL_LOGICAL_OR", 5, -1, 0},
|
||||
{"OPCODE_VAR_LOGICAL_AND", 5, -1, 0},
|
||||
{"OPCODE_VAR_LOGICAL_OR", 5, -1, 0},
|
||||
|
||||
{ "OPCODE_BOOL_TO_VAR", 0, 0, 0 },
|
||||
{"OPCODE_BOOL_TO_VAR", 0, 0, 0},
|
||||
|
||||
{ "OPCODE_JUMP4", 1 + sizeof( unsigned int ), 0, 0 },
|
||||
{ "OPCODE_JUMP_BACK4", 1 + sizeof( unsigned int ), 0, 0 },
|
||||
{"OPCODE_JUMP4", 1 + sizeof(unsigned int), 0, 0},
|
||||
{"OPCODE_JUMP_BACK4", 1 + sizeof(unsigned int), 0, 0},
|
||||
|
||||
{ "OPCODE_STORE_INT0", 1, 1, 0 },
|
||||
{ "OPCODE_STORE_INT1", 1 + sizeof( char ), 1, 0 },
|
||||
{ "OPCODE_STORE_INT2", 1 + sizeof( short ), 1, 0 },
|
||||
{ "OPCODE_STORE_INT3", 1 + sizeof( short3 ), 1, 0 },
|
||||
{ "OPCODE_STORE_INT4", 1 + sizeof( int ), 1, 0 },
|
||||
{"OPCODE_STORE_INT0", 1, 1, 0},
|
||||
{"OPCODE_STORE_INT1", 1 + sizeof(char), 1, 0},
|
||||
{"OPCODE_STORE_INT2", 1 + sizeof(short), 1, 0},
|
||||
{"OPCODE_STORE_INT3", 1 + sizeof(short3), 1, 0},
|
||||
{"OPCODE_STORE_INT4", 1 + sizeof(int), 1, 0},
|
||||
|
||||
{ "OPCODE_BOOL_STORE_FALSE", 1, 1, 0 },
|
||||
{ "OPCODE_BOOL_STORE_TRUE", 1, 1, 0 },
|
||||
{"OPCODE_BOOL_STORE_FALSE", 1, 1, 0},
|
||||
{"OPCODE_BOOL_STORE_TRUE", 1, 1, 0},
|
||||
|
||||
{ "OPCODE_STORE_STRING", 1 + sizeof( unsigned int ), 1, 0 },
|
||||
{ "OPCODE_STORE_FLOAT", 1 + sizeof( float ), 1, 0 },
|
||||
{ "OPCODE_STORE_VECTOR", 1 + sizeof( Vector ), 1, 0 },
|
||||
{ "OPCODE_CALC_VECTOR", 1, -2, 0 },
|
||||
{ "OPCODE_STORE_NULL", 1, 1, 0 },
|
||||
{ "OPCODE_STORE_NIL", 1, 1, 0 },
|
||||
{"OPCODE_STORE_STRING", 1 + sizeof(unsigned int), 1, 0},
|
||||
{"OPCODE_STORE_FLOAT", 1 + sizeof(float), 1, 0},
|
||||
{"OPCODE_STORE_VECTOR", 1 + sizeof(Vector), 1, 0},
|
||||
{"OPCODE_CALC_VECTOR", 1, -2, 0},
|
||||
{"OPCODE_STORE_NULL", 1, 1, 0},
|
||||
{"OPCODE_STORE_NIL", 1, 1, 0},
|
||||
|
||||
{ "OPCODE_EXEC_CMD0", 5, 0, 1 },
|
||||
{ "OPCODE_EXEC_CMD1", 5, -1, 1 },
|
||||
{ "OPCODE_EXEC_CMD2", 5, -2, 1 },
|
||||
{ "OPCODE_EXEC_CMD3", 5, -3, 1 },
|
||||
{ "OPCODE_EXEC_CMD4", 5, -4, 1 },
|
||||
{ "OPCODE_EXEC_CMD5", 5, -5, 1 },
|
||||
{ "OPCODE_EXEC_CMD_COUNT1", 6, -128, 1 },
|
||||
{"OPCODE_EXEC_CMD0", 5, 0, 1},
|
||||
{"OPCODE_EXEC_CMD1", 5, -1, 1},
|
||||
{"OPCODE_EXEC_CMD2", 5, -2, 1},
|
||||
{"OPCODE_EXEC_CMD3", 5, -3, 1},
|
||||
{"OPCODE_EXEC_CMD4", 5, -4, 1},
|
||||
{"OPCODE_EXEC_CMD5", 5, -5, 1},
|
||||
{"OPCODE_EXEC_CMD_COUNT1", 6, -128, 1},
|
||||
|
||||
{ "OPCODE_EXEC_CMD_METHOD0", 5, -1, 1 },
|
||||
{ "OPCODE_EXEC_CMD_METHOD1", 5, -2, 1 },
|
||||
{ "OPCODE_EXEC_CMD_METHOD2", 5, -3, 1 },
|
||||
{ "OPCODE_EXEC_CMD_METHOD3", 5, -4, 1 },
|
||||
{ "OPCODE_EXEC_CMD_METHOD4", 5, -5, 1 },
|
||||
{ "OPCODE_EXEC_CMD_METHOD5", 5, -6, 1 },
|
||||
{ "OPCODE_EXEC_CMD_METHOD_COUNT1", 6, -128, 1 },
|
||||
{"OPCODE_EXEC_CMD_METHOD0", 5, -1, 1},
|
||||
{"OPCODE_EXEC_CMD_METHOD1", 5, -2, 1},
|
||||
{"OPCODE_EXEC_CMD_METHOD2", 5, -3, 1},
|
||||
{"OPCODE_EXEC_CMD_METHOD3", 5, -4, 1},
|
||||
{"OPCODE_EXEC_CMD_METHOD4", 5, -5, 1},
|
||||
{"OPCODE_EXEC_CMD_METHOD5", 5, -6, 1},
|
||||
{"OPCODE_EXEC_CMD_METHOD_COUNT1", 6, -128, 1},
|
||||
|
||||
{ "OPCODE_EXEC_METHOD0", 5, 0, 1 },
|
||||
{ "OPCODE_EXEC_METHOD1", 5, -1, 1 },
|
||||
{ "OPCODE_EXEC_METHOD2", 5, -2, 1 },
|
||||
{ "OPCODE_EXEC_METHOD3", 5, -3, 1 },
|
||||
{ "OPCODE_EXEC_METHOD4", 5, -4, 1 },
|
||||
{ "OPCODE_EXEC_METHOD5", 5, -5, 1 },
|
||||
{ "OPCODE_EXEC_METHOD_COUNT1", 6, -128, 1 },
|
||||
{"OPCODE_EXEC_METHOD0", 5, 0, 1},
|
||||
{"OPCODE_EXEC_METHOD1", 5, -1, 1},
|
||||
{"OPCODE_EXEC_METHOD2", 5, -2, 1},
|
||||
{"OPCODE_EXEC_METHOD3", 5, -3, 1},
|
||||
{"OPCODE_EXEC_METHOD4", 5, -4, 1},
|
||||
{"OPCODE_EXEC_METHOD5", 5, -5, 1},
|
||||
{"OPCODE_EXEC_METHOD_COUNT1", 6, -128, 1},
|
||||
|
||||
{ "OPCODE_LOAD_GAME_VAR", 5, -1, 0 },
|
||||
{ "OPCODE_LOAD_LEVEL_VAR", 5, -1, 0 },
|
||||
{ "OPCODE_LOAD_LOCAL_VAR", 5, -1, 0 },
|
||||
{ "OPCODE_LOAD_PARM_VAR", 5, -1, 0 },
|
||||
{ "OPCODE_LOAD_SELF_VAR", 5, -1, 0 },
|
||||
{ "OPCODE_LOAD_GROUP_VAR", 5, -1, 0 },
|
||||
{ "OPCODE_LOAD_OWNER_VAR", 5, -1, 0 },
|
||||
{ "OPCODE_LOAD_FIELD_VAR", 5, -2, 0 },
|
||||
{ "OPCODE_LOAD_ARRAY_VAR", 1, -3, 0 },
|
||||
{ "OPCODE_LOAD_CONST_ARRAY1", 2, -128, 0 },
|
||||
{"OPCODE_LOAD_GAME_VAR", 5, -1, 0},
|
||||
{"OPCODE_LOAD_LEVEL_VAR", 5, -1, 0},
|
||||
{"OPCODE_LOAD_LOCAL_VAR", 5, -1, 0},
|
||||
{"OPCODE_LOAD_PARM_VAR", 5, -1, 0},
|
||||
{"OPCODE_LOAD_SELF_VAR", 5, -1, 0},
|
||||
{"OPCODE_LOAD_GROUP_VAR", 5, -1, 0},
|
||||
{"OPCODE_LOAD_OWNER_VAR", 5, -1, 0},
|
||||
{"OPCODE_LOAD_FIELD_VAR", 5, -2, 0},
|
||||
{"OPCODE_LOAD_ARRAY_VAR", 1, -3, 0},
|
||||
{"OPCODE_LOAD_CONST_ARRAY1", 2, -128, 0},
|
||||
|
||||
{ "OPCODE_STORE_FIELD_REF", 5, 0, 0 },
|
||||
{ "OPCODE_STORE_ARRAY_REF", 1, -1, 0 },
|
||||
{"OPCODE_STORE_FIELD_REF", 5, 0, 0},
|
||||
{"OPCODE_STORE_ARRAY_REF", 1, -1, 0},
|
||||
|
||||
{ "OPCODE_MARK_STACK_POS", 1, 0, 0 },
|
||||
{"OPCODE_MARK_STACK_POS", 1, 0, 0},
|
||||
|
||||
{ "OPCODE_STORE_PARAM", 1, 1, 0 },
|
||||
{"OPCODE_STORE_PARAM", 1, 1, 0},
|
||||
|
||||
{ "OPCODE_RESTORE_STACK_POS", 1, 0, 0 },
|
||||
{"OPCODE_RESTORE_STACK_POS", 1, 0, 0},
|
||||
|
||||
{ "OPCODE_LOAD_STORE_GAME_VAR", 5, 0, 0 },
|
||||
{ "OPCODE_LOAD_STORE_LEVEL_VAR", 5, 0, 0 },
|
||||
{ "OPCODE_LOAD_STORE_LOCAL_VAR", 5, 0, 0 },
|
||||
{ "OPCODE_LOAD_STORE_PARM_VAR", 5, 0, 0 },
|
||||
{ "OPCODE_LOAD_STORE_SELF_VAR", 5, 0, 0 },
|
||||
{ "OPCODE_LOAD_STORE_GROUP_VAR", 5, 0, 0 },
|
||||
{ "OPCODE_LOAD_STORE_OWNER_VAR", 5, 0, 0 },
|
||||
{"OPCODE_LOAD_STORE_GAME_VAR", 5, 0, 0},
|
||||
{"OPCODE_LOAD_STORE_LEVEL_VAR", 5, 0, 0},
|
||||
{"OPCODE_LOAD_STORE_LOCAL_VAR", 5, 0, 0},
|
||||
{"OPCODE_LOAD_STORE_PARM_VAR", 5, 0, 0},
|
||||
{"OPCODE_LOAD_STORE_SELF_VAR", 5, 0, 0},
|
||||
{"OPCODE_LOAD_STORE_GROUP_VAR", 5, 0, 0},
|
||||
{"OPCODE_LOAD_STORE_OWNER_VAR", 5, 0, 0},
|
||||
|
||||
{ "OPCODE_STORE_GAME_VAR", 5, 1, 0 },
|
||||
{ "OPCODE_STORE_LEVEL_VAR", 5, 1, 0 },
|
||||
{ "OPCODE_STORE_LOCAL_VAR", 5, 1, 0 },
|
||||
{ "OPCODE_STORE_PARM_VAR", 5, 1, 0 },
|
||||
{ "OPCODE_STORE_SELF_VAR", 5, 1, 0 },
|
||||
{ "OPCODE_STORE_GROUP_VAR", 5, 1, 0 },
|
||||
{ "OPCODE_STORE_OWNER_VAR", 5, 1, 0 },
|
||||
{ "OPCODE_STORE_FIELD", 5, 0, 1 },
|
||||
{ "OPCODE_STORE_ARRAY", 1, -1, 0 },
|
||||
{ "OPCODE_STORE_GAME", 1, 1, 0 },
|
||||
{ "OPCODE_STORE_LEVEL", 1, 1, 0 },
|
||||
{ "OPCODE_STORE_LOCAL", 1, 1, 0 },
|
||||
{ "OPCODE_STORE_PARM", 1, 1, 0 },
|
||||
{ "OPCODE_STORE_SELF", 1, 1, 0 },
|
||||
{ "OPCODE_STORE_GROUP", 1, 1, 0 },
|
||||
{ "OPCODE_STORE_OWNER", 1, 1, 0 },
|
||||
{"OPCODE_STORE_GAME_VAR", 5, 1, 0},
|
||||
{"OPCODE_STORE_LEVEL_VAR", 5, 1, 0},
|
||||
{"OPCODE_STORE_LOCAL_VAR", 5, 1, 0},
|
||||
{"OPCODE_STORE_PARM_VAR", 5, 1, 0},
|
||||
{"OPCODE_STORE_SELF_VAR", 5, 1, 0},
|
||||
{"OPCODE_STORE_GROUP_VAR", 5, 1, 0},
|
||||
{"OPCODE_STORE_OWNER_VAR", 5, 1, 0},
|
||||
{"OPCODE_STORE_FIELD", 5, 0, 1},
|
||||
{"OPCODE_STORE_ARRAY", 1, -1, 0},
|
||||
{"OPCODE_STORE_GAME", 1, 1, 0},
|
||||
{"OPCODE_STORE_LEVEL", 1, 1, 0},
|
||||
{"OPCODE_STORE_LOCAL", 1, 1, 0},
|
||||
{"OPCODE_STORE_PARM", 1, 1, 0},
|
||||
{"OPCODE_STORE_SELF", 1, 1, 0},
|
||||
{"OPCODE_STORE_GROUP", 1, 1, 0},
|
||||
{"OPCODE_STORE_OWNER", 1, 1, 0},
|
||||
|
||||
{ "OPCODE_BIN_BITWISE_AND", 1, -1, 0 },
|
||||
{ "OPCODE_BIN_BITWISE_OR", 1, -1, 0 },
|
||||
{ "OPCODE_BIN_BITWISE_EXCL_OR", 1, -1, 0 },
|
||||
{ "OPCODE_BIN_EQUALITY", 1, -1, 0 },
|
||||
{ "OPCODE_BIN_INEQUALITY", 1, -1, 0 },
|
||||
{ "OPCODE_BIN_LESS_THAN", 1, -1, 0 },
|
||||
{ "OPCODE_BIN_GREATER_THAN", 1, -1, 0 },
|
||||
{ "OPCODE_BIN_LESS_THAN_OR_EQUAL", 1, -1, 0 },
|
||||
{ "OPCODE_BIN_GREATER_THAN_OR_EQUAL", 1, -1, 0 },
|
||||
{ "OPCODE_BIN_PLUS", 1, -1, 0 },
|
||||
{ "OPCODE_BIN_MINUS", 1, -1, 0 },
|
||||
{ "OPCODE_BIN_MULTIPLY", 1, -1, 0 },
|
||||
{ "OPCODE_BIN_DIVIDE", 1, -1, 0 },
|
||||
{ "OPCODE_BIN_PERCENTAGE", 1, -1, 0 },
|
||||
{"OPCODE_BIN_BITWISE_AND", 1, -1, 0},
|
||||
{"OPCODE_BIN_BITWISE_OR", 1, -1, 0},
|
||||
{"OPCODE_BIN_BITWISE_EXCL_OR", 1, -1, 0},
|
||||
{"OPCODE_BIN_EQUALITY", 1, -1, 0},
|
||||
{"OPCODE_BIN_INEQUALITY", 1, -1, 0},
|
||||
{"OPCODE_BIN_LESS_THAN", 1, -1, 0},
|
||||
{"OPCODE_BIN_GREATER_THAN", 1, -1, 0},
|
||||
{"OPCODE_BIN_LESS_THAN_OR_EQUAL", 1, -1, 0},
|
||||
{"OPCODE_BIN_GREATER_THAN_OR_EQUAL", 1, -1, 0},
|
||||
{"OPCODE_BIN_PLUS", 1, -1, 0},
|
||||
{"OPCODE_BIN_MINUS", 1, -1, 0},
|
||||
{"OPCODE_BIN_MULTIPLY", 1, -1, 0},
|
||||
{"OPCODE_BIN_DIVIDE", 1, -1, 0},
|
||||
{"OPCODE_BIN_PERCENTAGE", 1, -1, 0},
|
||||
|
||||
{ "OPCODE_UN_MINUS", 1, 0, 0 },
|
||||
{ "OPCODE_UN_COMPLEMENT", 1, 0, 0 },
|
||||
{ "OPCODE_UN_TARGETNAME", 1, 0, 0 },
|
||||
{ "OPCODE_BOOL_UN_NOT", 1, 0, 0 },
|
||||
{ "OPCODE_VAR_UN_NOT", 1, 0, 0 },
|
||||
{ "OPCODE_UN_CAST_BOOLEAN", 1, 0, 0 },
|
||||
{ "OPCODE_UN_INC", 1, 0, 0 },
|
||||
{ "OPCODE_UN_DEC", 1, 0, 0 },
|
||||
{ "OPCODE_UN_SIZE", 1, 0, 0 },
|
||||
{"OPCODE_UN_MINUS", 1, 0, 0},
|
||||
{"OPCODE_UN_COMPLEMENT", 1, 0, 0},
|
||||
{"OPCODE_UN_TARGETNAME", 1, 0, 0},
|
||||
{"OPCODE_BOOL_UN_NOT", 1, 0, 0},
|
||||
{"OPCODE_VAR_UN_NOT", 1, 0, 0},
|
||||
{"OPCODE_UN_CAST_BOOLEAN", 1, 0, 0},
|
||||
{"OPCODE_UN_INC", 1, 0, 0},
|
||||
{"OPCODE_UN_DEC", 1, 0, 0},
|
||||
{"OPCODE_UN_SIZE", 1, 0, 0},
|
||||
|
||||
{ "OPCODE_SWITCH", 5, -1, 0 },
|
||||
{"OPCODE_SWITCH", 5, -1, 0},
|
||||
|
||||
{ "OPCODE_FUNC", 11, -128, 1 },
|
||||
{"OPCODE_FUNC", 11, -128, 1},
|
||||
|
||||
{ "OPCODE_NOP", 1, 0, 0 },
|
||||
{"OPCODE_NOP", 1, 0, 0},
|
||||
|
||||
{ "OPCODE_BIN_SHIFT_LEFT", 1, -1, 0 },
|
||||
{ "OPCODE_BIN_SHIFT_RIGHT", 1, -1, 0 },
|
||||
{"OPCODE_BIN_SHIFT_LEFT", 1, -1, 0},
|
||||
{"OPCODE_BIN_SHIFT_RIGHT", 1, -1, 0},
|
||||
|
||||
{ "OPCODE_END", 1, -1, 0 },
|
||||
{ "OPCODE_RETURN", 1, -1, 0 },
|
||||
{"OPCODE_END", 1, -1, 0},
|
||||
{"OPCODE_RETURN", 1, -1, 0},
|
||||
};
|
||||
|
||||
static const char *aszVarGroupNames[] =
|
||||
{
|
||||
"game",
|
||||
"level",
|
||||
"local",
|
||||
"parm",
|
||||
"self"
|
||||
};
|
||||
static const char *aszVarGroupNames[] = {"game", "level", "local", "parm", "self"};
|
||||
|
||||
/*
|
||||
====================
|
||||
VarGroupName
|
||||
====================
|
||||
*/
|
||||
const char *VarGroupName( int iVarGroup )
|
||||
const char *VarGroupName(int iVarGroup)
|
||||
{
|
||||
return aszVarGroupNames[ iVarGroup ];
|
||||
return aszVarGroupNames[iVarGroup];
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -191,9 +183,9 @@ const char *VarGroupName( int iVarGroup )
|
|||
OpcodeName
|
||||
====================
|
||||
*/
|
||||
const char *OpcodeName( int opcode )
|
||||
const char *OpcodeName(int opcode)
|
||||
{
|
||||
return OpcodeInfo[ opcode ].opcodename;
|
||||
return OpcodeInfo[opcode].opcodename;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -201,9 +193,9 @@ const char *OpcodeName( int opcode )
|
|||
OpcodeLength
|
||||
====================
|
||||
*/
|
||||
int OpcodeLength( int opcode )
|
||||
int OpcodeLength(int opcode)
|
||||
{
|
||||
return OpcodeInfo[ opcode ].opcodelength;
|
||||
return OpcodeInfo[opcode].opcodelength;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -211,9 +203,9 @@ int OpcodeLength( int opcode )
|
|||
OpcodeVarStackOffset
|
||||
====================
|
||||
*/
|
||||
int OpcodeVarStackOffset( int opcode )
|
||||
int OpcodeVarStackOffset(int opcode)
|
||||
{
|
||||
return OpcodeInfo[ opcode ].opcodestackoffset;
|
||||
return OpcodeInfo[opcode].opcodestackoffset;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -221,9 +213,9 @@ int OpcodeVarStackOffset( int opcode )
|
|||
SetOpcodeVarStackOffset
|
||||
====================
|
||||
*/
|
||||
void SetOpcodeVarStackOffset( int opcode, int iVarStackOffset )
|
||||
void SetOpcodeVarStackOffset(int opcode, int iVarStackOffset)
|
||||
{
|
||||
OpcodeInfo[ opcode ].opcodestackoffset = iVarStackOffset;
|
||||
OpcodeInfo[opcode].opcodestackoffset = iVarStackOffset;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -231,7 +223,7 @@ void SetOpcodeVarStackOffset( int opcode, int iVarStackOffset )
|
|||
IsExternalOpcode
|
||||
====================
|
||||
*/
|
||||
bool IsExternalOpcode( int opcode )
|
||||
bool IsExternalOpcode(int opcode)
|
||||
{
|
||||
return OpcodeInfo[ opcode ].isexternal ? true : false;
|
||||
return OpcodeInfo[opcode].isexternal ? true : false;
|
||||
}
|
||||
|
|
|
@ -42,164 +42,163 @@ using op_parmNum_t = uint8_t;
|
|||
using op_arrayParmNum_t = uint16_t;
|
||||
|
||||
typedef struct {
|
||||
const char *opcodename;
|
||||
int opcodelength;
|
||||
short opcodestackoffset;
|
||||
char isexternal;
|
||||
const char *opcodename;
|
||||
int opcodelength;
|
||||
short opcodestackoffset;
|
||||
char isexternal;
|
||||
} opcode_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned char opcode;
|
||||
char VarStackOffset;
|
||||
unsigned char opcode;
|
||||
char VarStackOffset;
|
||||
} opcode_info_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
OP_DONE,
|
||||
OP_BOOL_JUMP_FALSE4,
|
||||
OP_BOOL_JUMP_TRUE4,
|
||||
OP_VAR_JUMP_FALSE4,
|
||||
OP_VAR_JUMP_TRUE4,
|
||||
typedef enum {
|
||||
OP_DONE,
|
||||
OP_BOOL_JUMP_FALSE4,
|
||||
OP_BOOL_JUMP_TRUE4,
|
||||
OP_VAR_JUMP_FALSE4,
|
||||
OP_VAR_JUMP_TRUE4,
|
||||
|
||||
OP_BOOL_LOGICAL_AND,
|
||||
OP_BOOL_LOGICAL_OR,
|
||||
OP_VAR_LOGICAL_AND,
|
||||
OP_VAR_LOGICAL_OR,
|
||||
OP_BOOL_LOGICAL_AND,
|
||||
OP_BOOL_LOGICAL_OR,
|
||||
OP_VAR_LOGICAL_AND,
|
||||
OP_VAR_LOGICAL_OR,
|
||||
|
||||
OP_BOOL_TO_VAR,
|
||||
OP_BOOL_TO_VAR,
|
||||
|
||||
OP_JUMP4,
|
||||
OP_JUMP_BACK4,
|
||||
OP_JUMP4,
|
||||
OP_JUMP_BACK4,
|
||||
|
||||
OP_STORE_INT0,
|
||||
OP_STORE_INT1,
|
||||
OP_STORE_INT2,
|
||||
OP_STORE_INT3,
|
||||
OP_STORE_INT4,
|
||||
OP_STORE_INT0,
|
||||
OP_STORE_INT1,
|
||||
OP_STORE_INT2,
|
||||
OP_STORE_INT3,
|
||||
OP_STORE_INT4,
|
||||
|
||||
OP_BOOL_STORE_FALSE,
|
||||
OP_BOOL_STORE_TRUE,
|
||||
OP_BOOL_STORE_FALSE,
|
||||
OP_BOOL_STORE_TRUE,
|
||||
|
||||
OP_STORE_STRING,
|
||||
OP_STORE_FLOAT,
|
||||
OP_STORE_VECTOR,
|
||||
OP_CALC_VECTOR,
|
||||
OP_STORE_NULL,
|
||||
OP_STORE_NIL,
|
||||
OP_STORE_STRING,
|
||||
OP_STORE_FLOAT,
|
||||
OP_STORE_VECTOR,
|
||||
OP_CALC_VECTOR,
|
||||
OP_STORE_NULL,
|
||||
OP_STORE_NIL,
|
||||
|
||||
OP_EXEC_CMD0, // exec normal
|
||||
OP_EXEC_CMD1,
|
||||
OP_EXEC_CMD2,
|
||||
OP_EXEC_CMD3,
|
||||
OP_EXEC_CMD4,
|
||||
OP_EXEC_CMD5,
|
||||
OP_EXEC_CMD_COUNT1,
|
||||
OP_EXEC_CMD0, // exec normal
|
||||
OP_EXEC_CMD1,
|
||||
OP_EXEC_CMD2,
|
||||
OP_EXEC_CMD3,
|
||||
OP_EXEC_CMD4,
|
||||
OP_EXEC_CMD5,
|
||||
OP_EXEC_CMD_COUNT1,
|
||||
|
||||
OP_EXEC_CMD_METHOD0, // exec from listener
|
||||
OP_EXEC_CMD_METHOD1,
|
||||
OP_EXEC_CMD_METHOD2,
|
||||
OP_EXEC_CMD_METHOD3,
|
||||
OP_EXEC_CMD_METHOD4,
|
||||
OP_EXEC_CMD_METHOD5,
|
||||
OP_EXEC_CMD_METHOD_COUNT1,
|
||||
OP_EXEC_CMD_METHOD0, // exec from listener
|
||||
OP_EXEC_CMD_METHOD1,
|
||||
OP_EXEC_CMD_METHOD2,
|
||||
OP_EXEC_CMD_METHOD3,
|
||||
OP_EXEC_CMD_METHOD4,
|
||||
OP_EXEC_CMD_METHOD5,
|
||||
OP_EXEC_CMD_METHOD_COUNT1,
|
||||
|
||||
OP_EXEC_METHOD0, // exec from listener with return
|
||||
OP_EXEC_METHOD1,
|
||||
OP_EXEC_METHOD2,
|
||||
OP_EXEC_METHOD3,
|
||||
OP_EXEC_METHOD4,
|
||||
OP_EXEC_METHOD5,
|
||||
OP_EXEC_METHOD_COUNT1,
|
||||
OP_EXEC_METHOD0, // exec from listener with return
|
||||
OP_EXEC_METHOD1,
|
||||
OP_EXEC_METHOD2,
|
||||
OP_EXEC_METHOD3,
|
||||
OP_EXEC_METHOD4,
|
||||
OP_EXEC_METHOD5,
|
||||
OP_EXEC_METHOD_COUNT1,
|
||||
|
||||
OP_LOAD_GAME_VAR,
|
||||
OP_LOAD_LEVEL_VAR,
|
||||
OP_LOAD_LOCAL_VAR,
|
||||
OP_LOAD_PARM_VAR,
|
||||
OP_LOAD_SELF_VAR,
|
||||
OP_LOAD_GROUP_VAR,
|
||||
OP_LOAD_OWNER_VAR,
|
||||
OP_LOAD_FIELD_VAR,
|
||||
OP_LOAD_ARRAY_VAR,
|
||||
OP_LOAD_CONST_ARRAY1,
|
||||
OP_LOAD_GAME_VAR,
|
||||
OP_LOAD_LEVEL_VAR,
|
||||
OP_LOAD_LOCAL_VAR,
|
||||
OP_LOAD_PARM_VAR,
|
||||
OP_LOAD_SELF_VAR,
|
||||
OP_LOAD_GROUP_VAR,
|
||||
OP_LOAD_OWNER_VAR,
|
||||
OP_LOAD_FIELD_VAR,
|
||||
OP_LOAD_ARRAY_VAR,
|
||||
OP_LOAD_CONST_ARRAY1,
|
||||
|
||||
OP_STORE_FIELD_REF,
|
||||
OP_STORE_ARRAY_REF,
|
||||
OP_STORE_FIELD_REF,
|
||||
OP_STORE_ARRAY_REF,
|
||||
|
||||
OP_MARK_STACK_POS,
|
||||
OP_MARK_STACK_POS,
|
||||
|
||||
OP_STORE_PARAM,
|
||||
OP_STORE_PARAM,
|
||||
|
||||
OP_RESTORE_STACK_POS,
|
||||
OP_RESTORE_STACK_POS,
|
||||
|
||||
OP_LOAD_STORE_GAME_VAR,
|
||||
OP_LOAD_STORE_LEVEL_VAR,
|
||||
OP_LOAD_STORE_LOCAL_VAR,
|
||||
OP_LOAD_STORE_PARM_VAR,
|
||||
OP_LOAD_STORE_SELF_VAR,
|
||||
OP_LOAD_STORE_GROUP_VAR,
|
||||
OP_LOAD_STORE_OWNER_VAR,
|
||||
OP_LOAD_STORE_GAME_VAR,
|
||||
OP_LOAD_STORE_LEVEL_VAR,
|
||||
OP_LOAD_STORE_LOCAL_VAR,
|
||||
OP_LOAD_STORE_PARM_VAR,
|
||||
OP_LOAD_STORE_SELF_VAR,
|
||||
OP_LOAD_STORE_GROUP_VAR,
|
||||
OP_LOAD_STORE_OWNER_VAR,
|
||||
|
||||
OP_STORE_GAME_VAR,
|
||||
OP_STORE_LEVEL_VAR,
|
||||
OP_STORE_LOCAL_VAR,
|
||||
OP_STORE_PARM_VAR,
|
||||
OP_STORE_SELF_VAR,
|
||||
OP_STORE_GROUP_VAR,
|
||||
OP_STORE_OWNER_VAR,
|
||||
OP_STORE_FIELD,
|
||||
OP_STORE_ARRAY,
|
||||
OP_STORE_GAME,
|
||||
OP_STORE_LEVEL,
|
||||
OP_STORE_LOCAL,
|
||||
OP_STORE_PARM,
|
||||
OP_STORE_SELF,
|
||||
OP_STORE_GROUP,
|
||||
OP_STORE_OWNER,
|
||||
OP_STORE_GAME_VAR,
|
||||
OP_STORE_LEVEL_VAR,
|
||||
OP_STORE_LOCAL_VAR,
|
||||
OP_STORE_PARM_VAR,
|
||||
OP_STORE_SELF_VAR,
|
||||
OP_STORE_GROUP_VAR,
|
||||
OP_STORE_OWNER_VAR,
|
||||
OP_STORE_FIELD,
|
||||
OP_STORE_ARRAY,
|
||||
OP_STORE_GAME,
|
||||
OP_STORE_LEVEL,
|
||||
OP_STORE_LOCAL,
|
||||
OP_STORE_PARM,
|
||||
OP_STORE_SELF,
|
||||
OP_STORE_GROUP,
|
||||
OP_STORE_OWNER,
|
||||
|
||||
OP_BIN_BITWISE_AND,
|
||||
OP_BIN_BITWISE_OR,
|
||||
OP_BIN_BITWISE_EXCL_OR,
|
||||
OP_BIN_EQUALITY,
|
||||
OP_BIN_INEQUALITY,
|
||||
OP_BIN_LESS_THAN,
|
||||
OP_BIN_GREATER_THAN,
|
||||
OP_BIN_LESS_THAN_OR_EQUAL,
|
||||
OP_BIN_GREATER_THAN_OR_EQUAL,
|
||||
OP_BIN_PLUS,
|
||||
OP_BIN_MINUS,
|
||||
OP_BIN_MULTIPLY,
|
||||
OP_BIN_DIVIDE,
|
||||
OP_BIN_PERCENTAGE,
|
||||
OP_BIN_BITWISE_AND,
|
||||
OP_BIN_BITWISE_OR,
|
||||
OP_BIN_BITWISE_EXCL_OR,
|
||||
OP_BIN_EQUALITY,
|
||||
OP_BIN_INEQUALITY,
|
||||
OP_BIN_LESS_THAN,
|
||||
OP_BIN_GREATER_THAN,
|
||||
OP_BIN_LESS_THAN_OR_EQUAL,
|
||||
OP_BIN_GREATER_THAN_OR_EQUAL,
|
||||
OP_BIN_PLUS,
|
||||
OP_BIN_MINUS,
|
||||
OP_BIN_MULTIPLY,
|
||||
OP_BIN_DIVIDE,
|
||||
OP_BIN_PERCENTAGE,
|
||||
|
||||
OP_UN_MINUS,
|
||||
OP_UN_COMPLEMENT,
|
||||
OP_UN_TARGETNAME,
|
||||
OP_BOOL_UN_NOT,
|
||||
OP_VAR_UN_NOT,
|
||||
OP_UN_CAST_BOOLEAN,
|
||||
OP_UN_INC,
|
||||
OP_UN_DEC,
|
||||
OP_UN_SIZE,
|
||||
OP_UN_MINUS,
|
||||
OP_UN_COMPLEMENT,
|
||||
OP_UN_TARGETNAME,
|
||||
OP_BOOL_UN_NOT,
|
||||
OP_VAR_UN_NOT,
|
||||
OP_UN_CAST_BOOLEAN,
|
||||
OP_UN_INC,
|
||||
OP_UN_DEC,
|
||||
OP_UN_SIZE,
|
||||
|
||||
OP_SWITCH,
|
||||
OP_SWITCH,
|
||||
|
||||
OP_FUNC,
|
||||
OP_FUNC,
|
||||
|
||||
OP_NOP,
|
||||
OP_NOP,
|
||||
|
||||
OP_BIN_SHIFT_LEFT,
|
||||
OP_BIN_SHIFT_RIGHT,
|
||||
OP_BIN_SHIFT_LEFT,
|
||||
OP_BIN_SHIFT_RIGHT,
|
||||
|
||||
OP_END,
|
||||
OP_RETURN,
|
||||
OP_END,
|
||||
OP_RETURN,
|
||||
|
||||
OP_PREVIOUS,
|
||||
OP_MAX = OP_PREVIOUS
|
||||
OP_PREVIOUS,
|
||||
OP_MAX = OP_PREVIOUS
|
||||
} opcode_e;
|
||||
|
||||
const char *VarGroupName( int iVarGroup );
|
||||
const char *OpcodeName( int opcode );
|
||||
int OpcodeLength( int opcode );
|
||||
int OpcodeVarStackOffset( int opcode );
|
||||
void SetOpcodeVarStackOffset( int opcode, int iVarStackOffset );
|
||||
bool IsExternalOpcode( int opcode );
|
||||
const char *VarGroupName(int iVarGroup);
|
||||
const char *OpcodeName(int opcode);
|
||||
int OpcodeLength(int opcode);
|
||||
int OpcodeVarStackOffset(int opcode);
|
||||
void SetOpcodeVarStackOffset(int opcode, int iVarStackOffset);
|
||||
bool IsExternalOpcode(int opcode);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -29,253 +29,255 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
#include "../qcommon/short3.h"
|
||||
|
||||
#ifdef GAME_DLL
|
||||
#include "../fgame/misc.h"
|
||||
# include "../fgame/misc.h"
|
||||
#endif
|
||||
|
||||
enum variabletype
|
||||
{
|
||||
VARIABLE_NONE,
|
||||
VARIABLE_STRING,
|
||||
VARIABLE_INTEGER,
|
||||
VARIABLE_FLOAT,
|
||||
VARIABLE_CHAR,
|
||||
VARIABLE_CONSTSTRING,
|
||||
VARIABLE_LISTENER,
|
||||
VARIABLE_REF,
|
||||
VARIABLE_ARRAY,
|
||||
VARIABLE_CONSTARRAY,
|
||||
VARIABLE_CONTAINER,
|
||||
VARIABLE_SAFECONTAINER,
|
||||
VARIABLE_POINTER,
|
||||
VARIABLE_VECTOR,
|
||||
VARIABLE_MAX
|
||||
enum variabletype {
|
||||
VARIABLE_NONE,
|
||||
VARIABLE_STRING,
|
||||
VARIABLE_INTEGER,
|
||||
VARIABLE_FLOAT,
|
||||
VARIABLE_CHAR,
|
||||
VARIABLE_CONSTSTRING,
|
||||
VARIABLE_LISTENER,
|
||||
VARIABLE_REF,
|
||||
VARIABLE_ARRAY,
|
||||
VARIABLE_CONSTARRAY,
|
||||
VARIABLE_CONTAINER,
|
||||
VARIABLE_SAFECONTAINER,
|
||||
VARIABLE_POINTER,
|
||||
VARIABLE_VECTOR,
|
||||
VARIABLE_MAX
|
||||
};
|
||||
|
||||
static const char *typenames[] =
|
||||
{
|
||||
"none",
|
||||
"string",
|
||||
"int",
|
||||
"float",
|
||||
"char",
|
||||
"const string",
|
||||
"listener",
|
||||
"ref",
|
||||
"array",
|
||||
"const array",
|
||||
"array",
|
||||
"array",
|
||||
"pointer",
|
||||
"vector",
|
||||
"double"
|
||||
};
|
||||
static const char *typenames[] = {
|
||||
"none",
|
||||
"string",
|
||||
"int",
|
||||
"float",
|
||||
"char",
|
||||
"const string",
|
||||
"listener",
|
||||
"ref",
|
||||
"array",
|
||||
"const array",
|
||||
"array",
|
||||
"array",
|
||||
"pointer",
|
||||
"vector",
|
||||
"double"};
|
||||
|
||||
class ScriptArrayHolder;
|
||||
class ScriptConstArrayHolder;
|
||||
class ScriptPointer;
|
||||
|
||||
class ScriptVariable {
|
||||
class ScriptVariable
|
||||
{
|
||||
public:
|
||||
#ifdef GAME_DLL
|
||||
short3 key; // variable name
|
||||
short3 key; // variable name
|
||||
#endif
|
||||
unsigned char type; // variable type
|
||||
union anon393 {
|
||||
public:
|
||||
char charValue;
|
||||
float floatValue;
|
||||
int intValue;
|
||||
SafePtr<Listener> *listenerValue;
|
||||
str *stringValue;
|
||||
float *vectorValue;
|
||||
unsigned char type; // variable type
|
||||
|
||||
ScriptVariable *refValue;
|
||||
union anon393 {
|
||||
public:
|
||||
char charValue;
|
||||
float floatValue;
|
||||
int intValue;
|
||||
SafePtr<Listener> *listenerValue;
|
||||
str *stringValue;
|
||||
float *vectorValue;
|
||||
|
||||
ScriptArrayHolder *arrayValue;
|
||||
ScriptConstArrayHolder *constArrayValue;
|
||||
ScriptVariable *refValue;
|
||||
|
||||
Container< SafePtr< Listener > > *containerValue;
|
||||
SafePtr< ContainerClass< SafePtr< Listener > > > *safeContainerValue;
|
||||
ScriptArrayHolder *arrayValue;
|
||||
ScriptConstArrayHolder *constArrayValue;
|
||||
|
||||
ScriptPointer *pointerValue;
|
||||
} m_data;
|
||||
Container<SafePtr<Listener>> *containerValue;
|
||||
SafePtr<ContainerClass<SafePtr<Listener>>> *safeContainerValue;
|
||||
|
||||
ScriptPointer *pointerValue;
|
||||
} m_data;
|
||||
|
||||
private:
|
||||
void ClearInternal();
|
||||
void ClearPointerInternal();
|
||||
void ClearInternal();
|
||||
void ClearPointerInternal();
|
||||
|
||||
public:
|
||||
ScriptVariable();
|
||||
ScriptVariable(const ScriptVariable& variable);
|
||||
ScriptVariable(ScriptVariable&& variable);
|
||||
ScriptVariable();
|
||||
ScriptVariable(const ScriptVariable& variable);
|
||||
ScriptVariable(ScriptVariable&& variable);
|
||||
|
||||
~ScriptVariable();
|
||||
~ScriptVariable();
|
||||
|
||||
void Archive( Archiver& arc );
|
||||
static void Archive( Archiver& arc, ScriptVariable **obj );
|
||||
void ArchiveInternal( Archiver& arc );
|
||||
void Archive(Archiver &arc);
|
||||
static void Archive(Archiver& arc, ScriptVariable **obj);
|
||||
void ArchiveInternal(Archiver &arc);
|
||||
|
||||
void CastBoolean( void );
|
||||
void CastConstArrayValue( void );
|
||||
void CastEntity( void );
|
||||
void CastFloat( void );
|
||||
void CastInteger( void );
|
||||
void CastString( void );
|
||||
void CastBoolean(void);
|
||||
void CastConstArrayValue(void);
|
||||
void CastEntity(void);
|
||||
void CastFloat(void);
|
||||
void CastInteger(void);
|
||||
void CastString(void);
|
||||
|
||||
void Clear();
|
||||
void ClearPointer();
|
||||
void Clear();
|
||||
void ClearPointer();
|
||||
|
||||
const char *GetTypeName( void ) const;
|
||||
variabletype GetType( void ) const;
|
||||
const char *GetTypeName(void) const;
|
||||
variabletype GetType(void) const;
|
||||
|
||||
qboolean IsEntity( void );
|
||||
qboolean IsListener( void );
|
||||
qboolean IsNumeric( void );
|
||||
qboolean IsConstArray() const;
|
||||
qboolean IsEntity(void);
|
||||
qboolean IsListener(void);
|
||||
qboolean IsNumeric(void);
|
||||
qboolean IsConstArray() const;
|
||||
#ifdef WITH_SCRIPT_ENGINE
|
||||
qboolean IsSimpleEntity( void );
|
||||
qboolean IsSimpleEntity(void);
|
||||
#endif
|
||||
qboolean IsString( void );
|
||||
qboolean IsVector( void );
|
||||
qboolean IsString(void);
|
||||
qboolean IsVector(void);
|
||||
|
||||
void PrintValue( void );
|
||||
void PrintValue(void);
|
||||
|
||||
void SetFalse( void );
|
||||
void SetTrue( void );
|
||||
void SetFalse(void);
|
||||
void SetTrue(void);
|
||||
|
||||
int arraysize( void ) const;
|
||||
size_t size( void ) const;
|
||||
int arraysize(void) const;
|
||||
size_t size(void) const;
|
||||
|
||||
bool booleanNumericValue( void );
|
||||
bool booleanValue( void ) const;
|
||||
bool booleanNumericValue(void);
|
||||
bool booleanValue(void) const;
|
||||
|
||||
#ifdef WITH_SCRIPT_ENGINE
|
||||
str& getName( void );
|
||||
str& getName(void);
|
||||
|
||||
short3& GetKey();
|
||||
void SetKey( const short3& key );
|
||||
short3& GetKey();
|
||||
void SetKey(const short3 &key);
|
||||
#endif
|
||||
|
||||
Entity *entityValue( void );
|
||||
Entity *entityValue(void);
|
||||
|
||||
void evalArrayAt( ScriptVariable &var );
|
||||
void evalArrayAt(ScriptVariable& var);
|
||||
|
||||
void setArrayAt( ScriptVariable &index, ScriptVariable &value );
|
||||
void setArrayAtRef( ScriptVariable &index, ScriptVariable &value );
|
||||
void setArrayRefValue( ScriptVariable &var );
|
||||
void setArrayAt(ScriptVariable& index, ScriptVariable& value);
|
||||
void setArrayAtRef(ScriptVariable& index, ScriptVariable& value);
|
||||
void setArrayRefValue(ScriptVariable& var);
|
||||
|
||||
char charValue( void ) const;
|
||||
void setCharValue( char newvalue );
|
||||
char charValue(void) const;
|
||||
void setCharValue(char newvalue);
|
||||
|
||||
ScriptVariable *constArrayValue( void );
|
||||
void setConstArrayValue( ScriptVariable *pVar, unsigned int size );
|
||||
ScriptVariable *constArrayValue(void);
|
||||
void setConstArrayValue(ScriptVariable *pVar, unsigned int size);
|
||||
|
||||
#ifdef WITH_SCRIPT_ENGINE
|
||||
const_str constStringValue( void ) const;
|
||||
void setConstStringValue( const_str s );
|
||||
const_str constStringValue(void) const;
|
||||
void setConstStringValue(const_str s);
|
||||
#endif
|
||||
|
||||
void setContainerValue( Container< SafePtr< Listener > > *newvalue );
|
||||
void setSafeContainerValue( ContainerClass< SafePtr< Listener > > *newvalue );
|
||||
void setContainerValue(Container<SafePtr<Listener>> *newvalue);
|
||||
void setSafeContainerValue(ContainerClass<SafePtr<Listener>> *newvalue);
|
||||
|
||||
float floatValue( void ) const;
|
||||
void setFloatValue( float newvalue );
|
||||
float floatValue(void) const;
|
||||
void setFloatValue(float newvalue);
|
||||
|
||||
int intValue( void ) const;
|
||||
void setIntValue( int newvalue );
|
||||
int intValue(void) const;
|
||||
void setIntValue(int newvalue);
|
||||
|
||||
Listener *listenerValue( void ) const;
|
||||
Listener* listenerAt(uintptr_t index) const;
|
||||
void setListenerValue( Listener * newvalue );
|
||||
Listener *listenerValue(void) const;
|
||||
Listener *listenerAt(uintptr_t index) const;
|
||||
void setListenerValue(Listener *newvalue);
|
||||
|
||||
void newPointer( void );
|
||||
void setPointer( const ScriptVariable& newvalue );
|
||||
void newPointer(void);
|
||||
void setPointer(const ScriptVariable& newvalue);
|
||||
|
||||
void setRefValue( ScriptVariable * ref );
|
||||
void setRefValue(ScriptVariable *ref);
|
||||
|
||||
//const char *stringValue( void );
|
||||
str stringValue( void ) const;
|
||||
void setStringValue( str newvalue );
|
||||
//const char *stringValue( void );
|
||||
str stringValue(void) const;
|
||||
void setStringValue(str newvalue);
|
||||
|
||||
#ifdef WITH_SCRIPT_ENGINE
|
||||
SimpleEntity *simpleEntityValue( void ) const;
|
||||
SimpleEntity *simpleEntityValue(void) const;
|
||||
#endif
|
||||
|
||||
Vector vectorValue( void ) const;
|
||||
void setVectorValue( const Vector &newvector );
|
||||
Vector vectorValue(void) const;
|
||||
void setVectorValue(const Vector &newvector);
|
||||
|
||||
class PathNode *pathNodeValue( void ) const;
|
||||
class Waypoint *waypointValue( void ) const;
|
||||
class PathNode *pathNodeValue(void) const;
|
||||
class Waypoint *waypointValue(void) const;
|
||||
|
||||
void greaterthan( ScriptVariable &variable );
|
||||
void greaterthanorequal( ScriptVariable &variable );
|
||||
void lessthan( ScriptVariable &variable );
|
||||
void lessthanorequal( ScriptVariable &variable );
|
||||
void greaterthan(ScriptVariable& variable);
|
||||
void greaterthanorequal(ScriptVariable& variable);
|
||||
void lessthan(ScriptVariable& variable);
|
||||
void lessthanorequal(ScriptVariable& variable);
|
||||
|
||||
void complement( void );
|
||||
void minus( void );
|
||||
ScriptVariable& operator=(const ScriptVariable& variable);
|
||||
ScriptVariable& operator=(ScriptVariable&& variable);
|
||||
ScriptVariable &operator[]( ScriptVariable& index );
|
||||
ScriptVariable *operator[]( unsigned index ) const;
|
||||
ScriptVariable *operator*( );
|
||||
void operator+=( const ScriptVariable& value );
|
||||
void operator-=( const ScriptVariable& value );
|
||||
void operator*=( const ScriptVariable& value );
|
||||
void operator/=( const ScriptVariable& value );
|
||||
void operator%=( const ScriptVariable& value );
|
||||
void operator&=( const ScriptVariable& value );
|
||||
void operator^=( const ScriptVariable& value );
|
||||
void operator|=( const ScriptVariable& value );
|
||||
void operator<<=( const ScriptVariable& value );
|
||||
void operator>>=( const ScriptVariable& value );
|
||||
void complement(void);
|
||||
void minus(void);
|
||||
ScriptVariable& operator=(const ScriptVariable& variable);
|
||||
ScriptVariable& operator=(ScriptVariable&& variable);
|
||||
ScriptVariable& operator[](ScriptVariable& index);
|
||||
ScriptVariable *operator[](unsigned index) const;
|
||||
ScriptVariable *operator*();
|
||||
void operator+=(const ScriptVariable &value);
|
||||
void operator-=(const ScriptVariable &value);
|
||||
void operator*=(const ScriptVariable &value);
|
||||
void operator/=(const ScriptVariable &value);
|
||||
void operator%=(const ScriptVariable &value);
|
||||
void operator&=(const ScriptVariable &value);
|
||||
void operator^=(const ScriptVariable &value);
|
||||
void operator|=(const ScriptVariable &value);
|
||||
void operator<<=(const ScriptVariable &value);
|
||||
void operator>>=(const ScriptVariable &value);
|
||||
|
||||
bool operator!=( const ScriptVariable& value );
|
||||
bool operator==( const ScriptVariable& value );
|
||||
bool operator!=(const ScriptVariable& value);
|
||||
bool operator==(const ScriptVariable& value);
|
||||
|
||||
ScriptVariable operator++( int );
|
||||
ScriptVariable operator--( int );
|
||||
ScriptVariable operator++(int);
|
||||
ScriptVariable operator--(int);
|
||||
};
|
||||
|
||||
class ScriptArrayHolder {
|
||||
class ScriptArrayHolder
|
||||
{
|
||||
public:
|
||||
con_map< ScriptVariable, ScriptVariable > arrayValue;
|
||||
unsigned int refCount;
|
||||
con_map<ScriptVariable, ScriptVariable> arrayValue;
|
||||
unsigned int refCount;
|
||||
|
||||
public:
|
||||
void Archive( Archiver& arc );
|
||||
static void Archive( Archiver& arc, ScriptArrayHolder *& arrayValue );
|
||||
void Archive(Archiver &arc);
|
||||
static void Archive(Archiver& arc, ScriptArrayHolder *& arrayValue);
|
||||
};
|
||||
|
||||
class ScriptConstArrayHolder {
|
||||
class ScriptConstArrayHolder
|
||||
{
|
||||
public:
|
||||
ScriptVariable *constArrayValue;
|
||||
unsigned int refCount;
|
||||
unsigned int size;
|
||||
ScriptVariable *constArrayValue;
|
||||
unsigned int refCount;
|
||||
unsigned int size;
|
||||
|
||||
public:
|
||||
void Archive( Archiver& arc );
|
||||
static void Archive( Archiver& arc, ScriptConstArrayHolder *& constArrayValue );
|
||||
void Archive(Archiver &arc);
|
||||
static void Archive(Archiver& arc, ScriptConstArrayHolder *& constArrayValue);
|
||||
|
||||
ScriptConstArrayHolder( ScriptVariable *pVar, unsigned int size );
|
||||
ScriptConstArrayHolder( unsigned int size );
|
||||
ScriptConstArrayHolder();
|
||||
~ScriptConstArrayHolder();
|
||||
ScriptConstArrayHolder(ScriptVariable *pVar, unsigned int size);
|
||||
ScriptConstArrayHolder(unsigned int size);
|
||||
ScriptConstArrayHolder();
|
||||
~ScriptConstArrayHolder();
|
||||
};
|
||||
|
||||
class ScriptPointer {
|
||||
class ScriptPointer
|
||||
{
|
||||
public:
|
||||
Container< ScriptVariable * > list;
|
||||
Container<ScriptVariable *> list;
|
||||
|
||||
public:
|
||||
void Archive( Archiver& arc );
|
||||
static void Archive( Archiver& arc, ScriptPointer *& pointerValue );
|
||||
void Archive(Archiver &arc);
|
||||
static void Archive(Archiver& arc, ScriptPointer *& pointerValue);
|
||||
|
||||
void Clear();
|
||||
void Clear();
|
||||
|
||||
void add( ScriptVariable *var );
|
||||
void remove( ScriptVariable *var );
|
||||
void setValue( const ScriptVariable& var );
|
||||
void add(ScriptVariable *var);
|
||||
void remove(ScriptVariable *var);
|
||||
void setValue(const ScriptVariable& var);
|
||||
};
|
||||
|
||||
#ifdef WITH_SCRIPT_ENGINE
|
||||
|
@ -283,32 +285,32 @@ public:
|
|||
class ScriptVariableList : public Class
|
||||
{
|
||||
private:
|
||||
con_set< short3, ScriptVariable > list;
|
||||
con_set<short3, ScriptVariable> list;
|
||||
|
||||
public:
|
||||
CLASS_PROTOTYPE( ScriptVariableList );
|
||||
CLASS_PROTOTYPE(ScriptVariableList);
|
||||
|
||||
ScriptVariableList();
|
||||
ScriptVariableList();
|
||||
|
||||
void Archive( Archiver &arc ) override;
|
||||
void Archive(Archiver& arc) override;
|
||||
|
||||
void ClearList( void );
|
||||
void ClearList(void);
|
||||
|
||||
ScriptVariable *GetOrCreateVariable( str name );
|
||||
ScriptVariable *GetOrCreateVariable( unsigned int name );
|
||||
ScriptVariable *GetOrCreateVariable(str name);
|
||||
ScriptVariable *GetOrCreateVariable(unsigned int name);
|
||||
|
||||
ScriptVariable *GetVariable( str name );
|
||||
ScriptVariable *GetVariable( unsigned int name );
|
||||
ScriptVariable *GetVariable(str name);
|
||||
ScriptVariable *GetVariable(unsigned int name);
|
||||
|
||||
ScriptVariable *SetVariable( const char *name, int value );
|
||||
ScriptVariable *SetVariable( const char *name, float value );
|
||||
ScriptVariable *SetVariable( const char *name, const char *value );
|
||||
ScriptVariable *SetVariable( const char *name, Entity *value );
|
||||
ScriptVariable *SetVariable( const char *name, Listener *value );
|
||||
ScriptVariable *SetVariable( const char *name, Vector &value );
|
||||
ScriptVariable* SetVariable(const char* name, ScriptVariable& value);
|
||||
ScriptVariable* SetVariable(unsigned int name, ScriptVariable& value);
|
||||
ScriptVariable* SetVariable(unsigned int name, ScriptVariable&& value);
|
||||
ScriptVariable *SetVariable(const char *name, int value);
|
||||
ScriptVariable *SetVariable(const char *name, float value);
|
||||
ScriptVariable *SetVariable(const char *name, const char *value);
|
||||
ScriptVariable *SetVariable(const char *name, Entity *value);
|
||||
ScriptVariable *SetVariable(const char *name, Listener *value);
|
||||
ScriptVariable *SetVariable(const char *name, Vector& value);
|
||||
ScriptVariable *SetVariable(const char *name, ScriptVariable& value);
|
||||
ScriptVariable *SetVariable(unsigned int name, ScriptVariable& value);
|
||||
ScriptVariable *SetVariable(unsigned int name, ScriptVariable&& value);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -33,218 +33,223 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
#include "scriptopcodes.h"
|
||||
#include "../qcommon/con_set.h"
|
||||
|
||||
#define MAX_STACK_DEPTH 20 // 9 in mohaa
|
||||
#define MAX_STACK_DEPTH 20 // 9 in mohaa
|
||||
//#define LOCALSTACK_SIZE 255 // pre-allocated localstack size for each VM
|
||||
#define MAX_SCRIPTCYCLES 9999 // max cmds
|
||||
#define MAX_SCRIPTCYCLES 9999 // max cmds
|
||||
|
||||
#define STATE_RUNNING 0 // Running
|
||||
#define STATE_SUSPENDED 1 // Suspended
|
||||
#define STATE_WAITING 2 // Waiting for something
|
||||
#define STATE_EXECUTION 3 // Resume to execution
|
||||
#define STATE_DESTROYED 4 // Pending deletion
|
||||
#define STATE_RUNNING 0 // Running
|
||||
#define STATE_SUSPENDED 1 // Suspended
|
||||
#define STATE_WAITING 2 // Waiting for something
|
||||
#define STATE_EXECUTION 3 // Resume to execution
|
||||
#define STATE_DESTROYED 4 // Pending deletion
|
||||
|
||||
#define THREAD_RUNNING 0 // Running
|
||||
#define THREAD_WAITING 1 // Waiting
|
||||
#define THREAD_SUSPENDED 2 // Suspended
|
||||
#define THREAD_CONTEXT_SWITCH 3 // Resume from context switch
|
||||
#define THREAD_RUNNING 0 // Running
|
||||
#define THREAD_WAITING 1 // Waiting
|
||||
#define THREAD_SUSPENDED 2 // Suspended
|
||||
#define THREAD_CONTEXT_SWITCH 3 // Resume from context switch
|
||||
|
||||
class ScriptException;
|
||||
class ScriptThread;
|
||||
class ScriptVM;
|
||||
|
||||
class ScriptCallStack {
|
||||
class ScriptCallStack
|
||||
{
|
||||
public:
|
||||
// opcode variable
|
||||
unsigned char *codePos; // opcode will be restored once a DONE was hit
|
||||
// opcode variable
|
||||
unsigned char *codePos; // opcode will be restored once a DONE was hit
|
||||
|
||||
// stack variables
|
||||
ScriptVariable *localStack;
|
||||
ScriptVariable *pTop;
|
||||
// stack variables
|
||||
ScriptVariable *localStack;
|
||||
ScriptVariable *pTop;
|
||||
|
||||
// return variable
|
||||
ScriptVariable returnValue;
|
||||
// return variable
|
||||
ScriptVariable returnValue;
|
||||
|
||||
// OLD self value
|
||||
SafePtr< Listener > m_Self;
|
||||
// OLD self value
|
||||
SafePtr<Listener> m_Self;
|
||||
};
|
||||
|
||||
// Ley0k: I'm unsure about this class, MOHAA use it
|
||||
class ScriptStack
|
||||
{
|
||||
public:
|
||||
ScriptVariable *m_Array;
|
||||
int m_Count;
|
||||
ScriptVariable *m_Array;
|
||||
int m_Count;
|
||||
};
|
||||
|
||||
class ScriptVMStack
|
||||
{
|
||||
public:
|
||||
ScriptVMStack();
|
||||
ScriptVMStack(size_t stackSize);
|
||||
~ScriptVMStack();
|
||||
ScriptVMStack();
|
||||
ScriptVMStack(size_t stackSize);
|
||||
~ScriptVMStack();
|
||||
|
||||
ScriptVMStack(const ScriptVMStack& other) = delete;
|
||||
ScriptVMStack& operator=(const ScriptVMStack& other) = delete;
|
||||
ScriptVMStack(ScriptVMStack&& other);
|
||||
ScriptVMStack& operator=(ScriptVMStack&& other);
|
||||
ScriptVMStack(const ScriptVMStack& other) = delete;
|
||||
ScriptVMStack& operator=(const ScriptVMStack& other) = delete;
|
||||
ScriptVMStack(ScriptVMStack&& other);
|
||||
ScriptVMStack& operator=(ScriptVMStack&& other);
|
||||
|
||||
size_t GetStackSize() const;
|
||||
ScriptVariable& SetTop(ScriptVariable& newTop);
|
||||
ScriptVariable& GetTop() const;
|
||||
ScriptVariable& GetTop(size_t offset) const;
|
||||
ScriptVariable* GetTopPtr() const;
|
||||
ScriptVariable* GetTopPtr(size_t offset) const;
|
||||
ScriptVariable* GetTopArray(size_t offset = 0) const;
|
||||
uintptr_t GetIndex() const;
|
||||
void MoveTop(ScriptVariable&& other);
|
||||
ScriptVariable* GetListenerVar(uintptr_t index);
|
||||
void SetListenerVar(uintptr_t index, ScriptVariable* newVar);
|
||||
size_t GetStackSize() const;
|
||||
ScriptVariable& SetTop(ScriptVariable& newTop);
|
||||
ScriptVariable& GetTop() const;
|
||||
ScriptVariable& GetTop(size_t offset) const;
|
||||
ScriptVariable *GetTopPtr() const;
|
||||
ScriptVariable *GetTopPtr(size_t offset) const;
|
||||
ScriptVariable *GetTopArray(size_t offset = 0) const;
|
||||
uintptr_t GetIndex() const;
|
||||
void MoveTop(ScriptVariable &&other);
|
||||
ScriptVariable *GetListenerVar(uintptr_t index);
|
||||
void SetListenerVar(uintptr_t index, ScriptVariable *newVar);
|
||||
|
||||
/** Pop and return the previous value. */
|
||||
ScriptVariable& Pop();
|
||||
ScriptVariable& Pop(size_t offset);
|
||||
ScriptVariable& PopAndGet();
|
||||
ScriptVariable& PopAndGet(size_t offset);
|
||||
/** Push and return the previous value. */
|
||||
ScriptVariable& Push();
|
||||
ScriptVariable& Push(size_t offset);
|
||||
ScriptVariable& PushAndGet();
|
||||
ScriptVariable& PushAndGet(size_t offset);
|
||||
/** Pop and return the previous value. */
|
||||
ScriptVariable& Pop();
|
||||
ScriptVariable& Pop(size_t offset);
|
||||
ScriptVariable& PopAndGet();
|
||||
ScriptVariable& PopAndGet(size_t offset);
|
||||
/** Push and return the previous value. */
|
||||
ScriptVariable& Push();
|
||||
ScriptVariable& Push(size_t offset);
|
||||
ScriptVariable& PushAndGet();
|
||||
ScriptVariable& PushAndGet(size_t offset);
|
||||
|
||||
private:
|
||||
/** The VM's local stack. */
|
||||
ScriptVariable* localStack;
|
||||
/** The local stack size. */
|
||||
ScriptVariable* stackBottom;
|
||||
/** Variable from the top stack of the local stack. */
|
||||
ScriptVariable* pTop;
|
||||
ScriptVariable** listenerVarPtr;
|
||||
/** The VM's local stack. */
|
||||
ScriptVariable *localStack;
|
||||
/** The local stack size. */
|
||||
ScriptVariable *stackBottom;
|
||||
/** Variable from the top stack of the local stack. */
|
||||
ScriptVariable *pTop;
|
||||
ScriptVariable **listenerVarPtr;
|
||||
};
|
||||
|
||||
class ScriptVM
|
||||
{
|
||||
friend class ScriptThread;
|
||||
friend class ScriptThread;
|
||||
|
||||
public:
|
||||
// important thread variables
|
||||
ScriptVM *next; // next VM in the current ScriptClass
|
||||
// important thread variables
|
||||
ScriptVM *next; // next VM in the current ScriptClass
|
||||
|
||||
ScriptThread *m_Thread; // script thread
|
||||
ScriptClass *m_ScriptClass; // current group of threads
|
||||
ScriptThread *m_Thread; // script thread
|
||||
ScriptClass *m_ScriptClass; // current group of threads
|
||||
|
||||
public:
|
||||
// return variables
|
||||
ScriptStack *m_Stack; // Currently unused
|
||||
ScriptVMStack m_VMStack;
|
||||
ScriptVariable m_ReturnValue; // VM return value
|
||||
// return variables
|
||||
ScriptStack *m_Stack; // Currently unused
|
||||
ScriptVMStack m_VMStack;
|
||||
ScriptVariable m_ReturnValue; // VM return value
|
||||
|
||||
// opcode variables
|
||||
unsigned char *m_PrevCodePos; // previous opcode, for use with script exceptions
|
||||
unsigned char *m_CodePos; // check compiler.h for the list of all opcodes
|
||||
// opcode variables
|
||||
unsigned char *m_PrevCodePos; // previous opcode, for use with script exceptions
|
||||
unsigned char *m_CodePos; // check compiler.h for the list of all opcodes
|
||||
|
||||
public:
|
||||
// states
|
||||
unsigned char state; // current VM state
|
||||
unsigned char m_ThreadState; // current thread state
|
||||
// states
|
||||
unsigned char state; // current VM state
|
||||
unsigned char m_ThreadState; // current thread state
|
||||
|
||||
// stack variables
|
||||
Container< ScriptCallStack * > callStack; // thread's call stack
|
||||
ScriptVariable *m_StackPos; // marked stack position
|
||||
// stack variables
|
||||
Container<ScriptCallStack *> callStack; // thread's call stack
|
||||
ScriptVariable *m_StackPos; // marked stack position
|
||||
|
||||
// parameters variables
|
||||
ScriptVariable *m_pOldData; // old fastEvent data, to cleanup
|
||||
int m_OldDataSize;
|
||||
bool m_bMarkStack; // changed by OP_MARK_STACK_POS and OP_RESTORE_STACK_POS
|
||||
Event fastEvent; // parameter list, set when the VM is executed
|
||||
// parameters variables
|
||||
ScriptVariable *m_pOldData; // old fastEvent data, to cleanup
|
||||
int m_OldDataSize;
|
||||
bool m_bMarkStack; // changed by OP_MARK_STACK_POS and OP_RESTORE_STACK_POS
|
||||
Event fastEvent; // parameter list, set when the VM is executed
|
||||
|
||||
private:
|
||||
void error( const char *format, ... );
|
||||
void error(const char *format, ...);
|
||||
|
||||
template<bool bMethod = false, bool bReturn = false>
|
||||
void executeCommand(Listener* listener, op_parmNum_t iParamCount, op_evName_t eventnum);
|
||||
template<bool bReturn>
|
||||
void executeCommandInternal(Event& ev, Listener* listener, ScriptVariable* fromVar, op_parmNum_t iParamCount);
|
||||
bool executeGetter(Listener* listener, op_evName_t eventName);
|
||||
bool executeSetter(Listener* listener, op_evName_t eventName);
|
||||
void transferVarsToEvent(Event& ev, ScriptVariable* fromVar, op_parmNum_t count);
|
||||
template<bool bMethod = false, bool bReturn = false>
|
||||
void executeCommand(Listener *listener, op_parmNum_t iParamCount, op_evName_t eventnum);
|
||||
template<bool bReturn>
|
||||
void executeCommandInternal(Event& ev, Listener *listener, ScriptVariable *fromVar, op_parmNum_t iParamCount);
|
||||
bool executeGetter(Listener *listener, op_evName_t eventName);
|
||||
bool executeSetter(Listener *listener, op_evName_t eventName);
|
||||
void transferVarsToEvent(Event& ev, ScriptVariable *fromVar, op_parmNum_t count);
|
||||
|
||||
void jump( int offset );
|
||||
void jumpBool(int offset, bool value);
|
||||
void loadTopInternal(Listener* listener);
|
||||
ScriptVariable* storeTopInternal(Listener* listener);
|
||||
template<bool noTop = false> void loadTop(Listener* listener);
|
||||
template<bool noTop = false> ScriptVariable* storeTop(Listener* listener);
|
||||
void jump(int offset);
|
||||
void jumpBool(int offset, bool value);
|
||||
void loadTopInternal(Listener *listener);
|
||||
ScriptVariable *storeTopInternal(Listener *listener);
|
||||
template<bool noTop = false>
|
||||
void loadTop(Listener *listener);
|
||||
template<bool noTop = false>
|
||||
ScriptVariable *storeTop(Listener *listener);
|
||||
|
||||
void fetchOpcodeValue(void* outValue, size_t size);
|
||||
void fetchActualOpcodeValue(void* outValue, size_t size);
|
||||
void fetchOpcodeValue(void *outValue, size_t size);
|
||||
void fetchActualOpcodeValue(void *outValue, size_t size);
|
||||
|
||||
template<typename T> T fetchOpcodeValue()
|
||||
{
|
||||
T value;
|
||||
fetchOpcodeValue(&value, sizeof(T));
|
||||
return value;
|
||||
}
|
||||
template<typename T>
|
||||
T fetchOpcodeValue()
|
||||
{
|
||||
T value;
|
||||
fetchOpcodeValue(&value, sizeof(T));
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename T> T fetchOpcodeValue(size_t offset)
|
||||
{
|
||||
T value;
|
||||
fetchOpcodeValue(&value, sizeof(T));
|
||||
return value;
|
||||
}
|
||||
template<typename T>
|
||||
T fetchOpcodeValue(size_t offset)
|
||||
{
|
||||
T value;
|
||||
fetchOpcodeValue(&value, sizeof(T));
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename T> T fetchActualOpcodeValue()
|
||||
{
|
||||
T value;
|
||||
fetchActualOpcodeValue(&value, sizeof(T));
|
||||
return value;
|
||||
}
|
||||
template<typename T>
|
||||
T fetchActualOpcodeValue()
|
||||
{
|
||||
T value;
|
||||
fetchActualOpcodeValue(&value, sizeof(T));
|
||||
return value;
|
||||
}
|
||||
|
||||
void execCmdCommon(op_parmNum_t param);
|
||||
void execCmdMethodCommon(op_parmNum_t param);
|
||||
void execMethodCommon(op_parmNum_t param);
|
||||
void execFunction(ScriptMaster& Director);
|
||||
void execCmdCommon(op_parmNum_t param);
|
||||
void execCmdMethodCommon(op_parmNum_t param);
|
||||
void execMethodCommon(op_parmNum_t param);
|
||||
void execFunction(ScriptMaster& Director);
|
||||
|
||||
void SetFastData( ScriptVariable *data, int dataSize );
|
||||
void SetFastData(ScriptVariable *data, int dataSize);
|
||||
|
||||
bool Switch( StateScript *stateScript, ScriptVariable &var );
|
||||
bool Switch(StateScript *stateScript, ScriptVariable& var);
|
||||
|
||||
unsigned char *ProgBuffer();
|
||||
void HandleScriptException( ScriptException& exc );
|
||||
unsigned char *ProgBuffer();
|
||||
void HandleScriptException(ScriptException &exc);
|
||||
|
||||
public:
|
||||
#ifndef _DEBUG_MEM
|
||||
void *operator new( size_t size );
|
||||
void operator delete( void *ptr );
|
||||
void *operator new(size_t size);
|
||||
void operator delete(void *ptr);
|
||||
#endif
|
||||
|
||||
ScriptVM( ScriptClass *scriptClass, unsigned char *pCodePos, ScriptThread *thread );
|
||||
~ScriptVM();
|
||||
ScriptVM(ScriptClass *scriptClass, unsigned char *pCodePos, ScriptThread *thread);
|
||||
~ScriptVM();
|
||||
|
||||
void Archive( Archiver& arc );
|
||||
void Archive(Archiver& arc);
|
||||
|
||||
void EnterFunction(Container<ScriptVariable>&&);
|
||||
void LeaveFunction();
|
||||
void EnterFunction(Container<ScriptVariable>&&);
|
||||
void LeaveFunction();
|
||||
|
||||
void End( const ScriptVariable& returnValue );
|
||||
void End( void );
|
||||
void End(const ScriptVariable& returnValue);
|
||||
void End(void);
|
||||
|
||||
void Execute( ScriptVariable *data = NULL, int dataSize = 0, str label = "" );
|
||||
void NotifyDelete( void );
|
||||
void Resume( qboolean bForce = false );
|
||||
void Suspend( void );
|
||||
void Execute(ScriptVariable *data = NULL, int dataSize = 0, str label = "");
|
||||
void NotifyDelete(void);
|
||||
void Resume(qboolean bForce = false);
|
||||
void Suspend(void);
|
||||
|
||||
str Filename( void );
|
||||
str Label( void );
|
||||
ScriptClass *GetScriptClass( void );
|
||||
str Filename(void);
|
||||
str Label(void);
|
||||
ScriptClass *GetScriptClass(void);
|
||||
|
||||
bool IsSuspended( void );
|
||||
int State( void );
|
||||
int ThreadState( void );
|
||||
bool IsSuspended(void);
|
||||
int State(void);
|
||||
int ThreadState(void);
|
||||
|
||||
void EventGoto( Event *ev );
|
||||
bool EventThrow( Event *ev );
|
||||
void EventGoto(Event *ev);
|
||||
bool EventThrow(Event *ev);
|
||||
|
||||
bool CanScriptTracePrint( void );
|
||||
bool CanScriptTracePrint(void);
|
||||
};
|
||||
|
||||
extern MEM_BlockAlloc<ScriptClass> ScriptClass_allocator;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue