All lower case now.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@155 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
5f54ced9b8
commit
5a872df165
6 changed files with 5745 additions and 0 deletions
238
engine/qclib/comprout.c
Normal file
238
engine/qclib/comprout.c
Normal file
|
@ -0,0 +1,238 @@
|
|||
//compile routines
|
||||
|
||||
#include "qcc.h"
|
||||
#undef progfuncs
|
||||
|
||||
char errorfile[128];
|
||||
int errorline;
|
||||
|
||||
progfuncs_t *qccprogfuncs;
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
extern int qcc_compileactive;
|
||||
jmp_buf qcccompileerror;
|
||||
char qcc_gamedir[128];
|
||||
|
||||
|
||||
|
||||
#ifdef MINIMAL
|
||||
|
||||
#else
|
||||
|
||||
int qccalloced;
|
||||
int qcchunksize;
|
||||
char *qcchunk;
|
||||
void *qccHunkAlloc(size_t mem)
|
||||
{
|
||||
qccalloced+=mem;
|
||||
if (qccalloced > qcchunksize)
|
||||
QCC_Error(ERR_INTERNAL, "Compile hunk was filled");
|
||||
|
||||
memset(qcchunk+qccalloced-mem, 0, mem);
|
||||
return qcchunk+qccalloced-mem;
|
||||
}
|
||||
void qccClearHunk(void)
|
||||
{
|
||||
if (qcchunk)
|
||||
{
|
||||
free(qcchunk);
|
||||
qcchunk=NULL;
|
||||
}
|
||||
}
|
||||
void PostCompile(void)
|
||||
{
|
||||
#ifndef QCCONLY //QCCONLY has a frontend that browses defs.
|
||||
qccClearHunk();
|
||||
#endif
|
||||
|
||||
if (asmfile)
|
||||
{
|
||||
fclose(asmfile);
|
||||
asmfile = NULL;
|
||||
}
|
||||
}
|
||||
void PreCompile(void)
|
||||
{
|
||||
qccClearHunk();
|
||||
strcpy(qcc_gamedir, "");
|
||||
qcchunk = malloc(qcchunksize=16*1024*1024);
|
||||
qccalloced=0;
|
||||
}
|
||||
|
||||
void QCC_main (int argc, char **argv);
|
||||
void QCC_ContinueCompile(void);
|
||||
void QCC_FinishCompile(void);
|
||||
|
||||
int comp_nump;char **comp_parms;
|
||||
//void Editor(char *fname, int line, int numparms, char **compileparms);
|
||||
pbool CompileParams(progfuncs_t *progfuncs, int doall, int nump, char **parms)
|
||||
{
|
||||
comp_nump = nump;
|
||||
comp_parms = parms;
|
||||
*errorfile = '\0';
|
||||
qccprogfuncs = progfuncs;
|
||||
if (setjmp(qcccompileerror))
|
||||
{
|
||||
PostCompile();
|
||||
if (*errorfile)
|
||||
{
|
||||
if (!externs->useeditor)
|
||||
printf("Error in %s on line %i\n", errorfile, errorline);
|
||||
else
|
||||
externs->useeditor(errorfile, errorline, nump, parms);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
PreCompile();
|
||||
QCC_main(nump, parms);
|
||||
|
||||
while(qcc_compileactive)
|
||||
QCC_ContinueCompile();
|
||||
|
||||
PostCompile();
|
||||
|
||||
return true;
|
||||
}
|
||||
int Comp_Begin(progfuncs_t *progfuncs, int nump, char **parms)
|
||||
{
|
||||
comp_nump = nump;
|
||||
comp_parms = parms;
|
||||
qccprogfuncs = progfuncs;
|
||||
*errorfile = '\0';
|
||||
if (setjmp(qcccompileerror))
|
||||
{
|
||||
PostCompile();
|
||||
if (*errorfile)
|
||||
externs->useeditor(errorfile, errorline, nump, parms);
|
||||
return false;
|
||||
}
|
||||
|
||||
PreCompile();
|
||||
QCC_main(nump, parms);
|
||||
|
||||
return true;
|
||||
}
|
||||
int Comp_Continue(progfuncs_t *progfuncs)
|
||||
{
|
||||
qccprogfuncs = progfuncs;
|
||||
if (setjmp(qcccompileerror))
|
||||
{
|
||||
PostCompile();
|
||||
if (*errorfile)
|
||||
externs->useeditor(errorfile, errorline, comp_nump, comp_parms);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (qcc_compileactive)
|
||||
QCC_ContinueCompile();
|
||||
else
|
||||
{
|
||||
PostCompile();
|
||||
|
||||
if (*errorfile)
|
||||
externs->useeditor(errorfile, errorline, comp_nump, comp_parms);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
pbool CompileFile(progfuncs_t *progfuncs, char *filename)
|
||||
{
|
||||
#ifdef MINIMAL
|
||||
return false;
|
||||
#else
|
||||
char srcfile[32];
|
||||
char newname[32];
|
||||
static char *p[5];
|
||||
int parms;
|
||||
char *s, *s2;
|
||||
|
||||
p[0] = NULL;
|
||||
parms = 1;
|
||||
|
||||
strcpy(newname, filename);
|
||||
s = newname;
|
||||
if (strchr(s+1, '/'))
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
s2 = strchr(s+1, '/');
|
||||
if (!s2)
|
||||
{
|
||||
*s = '\0';
|
||||
break;
|
||||
}
|
||||
s = s2;
|
||||
}
|
||||
p[parms] = "-src";
|
||||
p[parms+1] = newname;
|
||||
parms+=2;
|
||||
|
||||
strcpy(srcfile, s+1);
|
||||
srcfile[strlen(srcfile)-4] = '\0';
|
||||
strcat(srcfile, ".src");
|
||||
|
||||
if (externs->FileSize(qcva("%s/%s", newname, srcfile))>0)
|
||||
{
|
||||
p[parms] = "-srcfile";
|
||||
p[parms+1] = srcfile;
|
||||
parms+=2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
p[parms] = "-srcfile";
|
||||
p[parms+1] = newname;
|
||||
newname[strlen(newname)-4] = '\0';
|
||||
strcat(newname, ".src");
|
||||
parms+=2;
|
||||
}
|
||||
// p[2][strlen(p[2])-4] = '\0';
|
||||
// strcat(p[2], "/");
|
||||
|
||||
while (!CompileParams(progfuncs, true, parms, p))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
int QC_strncasecmp(const char *s1, const char *s2, int n)
|
||||
{
|
||||
int c1, c2;
|
||||
|
||||
while (1)
|
||||
{
|
||||
c1 = *s1++;
|
||||
c2 = *s2++;
|
||||
|
||||
if (!n--)
|
||||
return 0; // strings are equal until end point
|
||||
|
||||
if (c1 != c2)
|
||||
{
|
||||
if (c1 >= 'a' && c1 <= 'z')
|
||||
c1 -= ('a' - 'A');
|
||||
if (c2 >= 'a' && c2 <= 'z')
|
||||
c2 -= ('a' - 'A');
|
||||
if (c1 != c2)
|
||||
return -1; // strings not equal
|
||||
}
|
||||
if (!c1)
|
||||
return 0; // strings are equal
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void editbadfile(char *fname, int line)
|
||||
{
|
||||
strcpy(errorfile, fname);
|
||||
errorline = line;
|
||||
}
|
||||
|
490
engine/qclib/pr_comp.h
Normal file
490
engine/qclib/pr_comp.h
Normal file
|
@ -0,0 +1,490 @@
|
|||
// this file is shared by the execution and compiler
|
||||
|
||||
/*i'm part way through making this work
|
||||
I've given up now that I can't work out a way to load pointers.
|
||||
Setting them should be fine.
|
||||
*/
|
||||
#ifndef __PR_COMP_H__
|
||||
#define __PR_COMP_H__
|
||||
|
||||
|
||||
/*this distinction is made as the execution uses c pointers while compiler uses pointers from the start of the string table of the current progs*/
|
||||
#ifdef COMPILER
|
||||
typedef int QCC_string_t;
|
||||
#else
|
||||
//typedef char *string_t;
|
||||
#endif
|
||||
|
||||
//typedef enum {ev_void, ev_string, ev_float, ev_vector, ev_entity, ev_field, ev_function, ev_pointer, ev_integer, ev_struct, ev_union} etype_t;
|
||||
// 0 1 2 3 4 5 6 7 8 9 10
|
||||
|
||||
#define OFS_NULL 0
|
||||
#define OFS_RETURN 1
|
||||
#define OFS_PARM0 4 // leave 3 ofs for each parm to hold vectors
|
||||
#define OFS_PARM1 7
|
||||
#define OFS_PARM2 10
|
||||
#define OFS_PARM3 13
|
||||
#define OFS_PARM4 16
|
||||
#define OFS_PARM5 19
|
||||
#define OFS_PARM6 22
|
||||
#define OFS_PARM7 25
|
||||
#define RESERVED_OFS 28
|
||||
|
||||
|
||||
enum {
|
||||
OP_DONE, //0
|
||||
OP_MUL_F,
|
||||
OP_MUL_V,
|
||||
OP_MUL_FV,
|
||||
OP_MUL_VF,
|
||||
OP_DIV_F,
|
||||
OP_ADD_F,
|
||||
OP_ADD_V,
|
||||
OP_SUB_F,
|
||||
OP_SUB_V,
|
||||
|
||||
OP_EQ_F, //10
|
||||
OP_EQ_V,
|
||||
OP_EQ_S,
|
||||
OP_EQ_E,
|
||||
OP_EQ_FNC,
|
||||
|
||||
OP_NE_F,
|
||||
OP_NE_V,
|
||||
OP_NE_S,
|
||||
OP_NE_E,
|
||||
OP_NE_FNC,
|
||||
|
||||
OP_LE, //20
|
||||
OP_GE,
|
||||
OP_LT,
|
||||
OP_GT,
|
||||
|
||||
OP_LOAD_F,
|
||||
OP_LOAD_V,
|
||||
OP_LOAD_S,
|
||||
OP_LOAD_ENT,
|
||||
OP_LOAD_FLD,
|
||||
OP_LOAD_FNC,
|
||||
|
||||
OP_ADDRESS, //30
|
||||
|
||||
OP_STORE_F,
|
||||
OP_STORE_V,
|
||||
OP_STORE_S,
|
||||
OP_STORE_ENT,
|
||||
OP_STORE_FLD,
|
||||
OP_STORE_FNC,
|
||||
|
||||
OP_STOREP_F,
|
||||
OP_STOREP_V,
|
||||
OP_STOREP_S,
|
||||
OP_STOREP_ENT, //40
|
||||
OP_STOREP_FLD,
|
||||
OP_STOREP_FNC,
|
||||
|
||||
OP_RETURN,
|
||||
OP_NOT_F,
|
||||
OP_NOT_V,
|
||||
OP_NOT_S,
|
||||
OP_NOT_ENT,
|
||||
OP_NOT_FNC,
|
||||
OP_IF,
|
||||
OP_IFNOT, //50
|
||||
OP_CALL0, //careful... hexen2 and q1 have different calling conventions
|
||||
OP_CALL1, //remap hexen2 calls to OP_CALL2H
|
||||
OP_CALL2,
|
||||
OP_CALL3,
|
||||
OP_CALL4,
|
||||
OP_CALL5,
|
||||
OP_CALL6,
|
||||
OP_CALL7,
|
||||
OP_CALL8,
|
||||
OP_STATE, //60
|
||||
OP_GOTO,
|
||||
OP_AND,
|
||||
OP_OR,
|
||||
|
||||
OP_BITAND,
|
||||
OP_BITOR,
|
||||
|
||||
|
||||
//these following ones are Hexen 2 constants.
|
||||
|
||||
OP_MULSTORE_F,
|
||||
OP_MULSTORE_V,
|
||||
OP_MULSTOREP_F,
|
||||
OP_MULSTOREP_V,
|
||||
|
||||
OP_DIVSTORE_F, //70
|
||||
OP_DIVSTOREP_F,
|
||||
|
||||
OP_ADDSTORE_F,
|
||||
OP_ADDSTORE_V,
|
||||
OP_ADDSTOREP_F,
|
||||
OP_ADDSTOREP_V,
|
||||
|
||||
OP_SUBSTORE_F,
|
||||
OP_SUBSTORE_V,
|
||||
OP_SUBSTOREP_F,
|
||||
OP_SUBSTOREP_V,
|
||||
|
||||
OP_FETCH_GBL_F, //80
|
||||
OP_FETCH_GBL_V,
|
||||
OP_FETCH_GBL_S,
|
||||
OP_FETCH_GBL_E,
|
||||
OP_FETCH_GBL_FNC,
|
||||
|
||||
OP_CSTATE,
|
||||
OP_CWSTATE,
|
||||
|
||||
OP_THINKTIME,
|
||||
|
||||
OP_BITSET,
|
||||
OP_BITSETP,
|
||||
OP_BITCLR, //90
|
||||
OP_BITCLRP,
|
||||
|
||||
OP_RAND0,
|
||||
OP_RAND1,
|
||||
OP_RAND2,
|
||||
OP_RANDV0,
|
||||
OP_RANDV1,
|
||||
OP_RANDV2,
|
||||
|
||||
OP_SWITCH_F,
|
||||
OP_SWITCH_V,
|
||||
OP_SWITCH_S, //100
|
||||
OP_SWITCH_E,
|
||||
OP_SWITCH_FNC,
|
||||
|
||||
OP_CASE,
|
||||
OP_CASERANGE,
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//the rest are added
|
||||
//mostly they are various different ways of adding two vars with conversions.
|
||||
|
||||
OP_CALL1H,
|
||||
OP_CALL2H,
|
||||
OP_CALL3H,
|
||||
OP_CALL4H,
|
||||
OP_CALL5H,
|
||||
OP_CALL6H, //110
|
||||
OP_CALL7H,
|
||||
OP_CALL8H,
|
||||
|
||||
|
||||
OP_STORE_I,
|
||||
OP_STORE_IF,
|
||||
OP_STORE_FI,
|
||||
|
||||
OP_ADD_I,
|
||||
OP_ADD_FI,
|
||||
OP_ADD_IF, //110
|
||||
|
||||
OP_SUB_I,
|
||||
OP_SUB_FI,
|
||||
OP_SUB_IF,
|
||||
|
||||
OP_CONV_ITOF,
|
||||
OP_CONV_FTOI,
|
||||
OP_CP_ITOF,
|
||||
OP_CP_FTOI,
|
||||
OP_LOAD_I,
|
||||
OP_STOREP_I,
|
||||
OP_STOREP_IF, //120
|
||||
OP_STOREP_FI,
|
||||
|
||||
OP_BITAND_I,
|
||||
OP_BITOR_I,
|
||||
|
||||
OP_MUL_I,
|
||||
OP_DIV_I,
|
||||
OP_EQ_I,
|
||||
OP_NE_I,
|
||||
|
||||
OP_IFNOTS,
|
||||
OP_IFS,
|
||||
|
||||
OP_NOT_I, //130
|
||||
|
||||
OP_DIV_VF,
|
||||
|
||||
OP_POWER_I,
|
||||
OP_RSHIFT_I,
|
||||
OP_LSHIFT_I,
|
||||
|
||||
OP_GLOBALADDRESS,
|
||||
OP_POINTER_ADD, //32 bit pointers
|
||||
|
||||
OP_LOADA_F,
|
||||
OP_LOADA_V,
|
||||
OP_LOADA_S,
|
||||
OP_LOADA_ENT, //140
|
||||
OP_LOADA_FLD,
|
||||
OP_LOADA_FNC,
|
||||
OP_LOADA_I,
|
||||
|
||||
OP_STORE_P,
|
||||
OP_LOAD_P,
|
||||
|
||||
OP_LOADP_F,
|
||||
OP_LOADP_V,
|
||||
OP_LOADP_S,
|
||||
OP_LOADP_ENT,
|
||||
OP_LOADP_FLD, //150
|
||||
OP_LOADP_FNC,
|
||||
OP_LOADP_I,
|
||||
|
||||
OP_LE_I,
|
||||
OP_GE_I,
|
||||
OP_LT_I,
|
||||
OP_GT_I,
|
||||
|
||||
OP_LE_IF,
|
||||
OP_GE_IF,
|
||||
OP_LT_IF,
|
||||
OP_GT_IF, //160
|
||||
|
||||
OP_LE_FI,
|
||||
OP_GE_FI,
|
||||
OP_LT_FI,
|
||||
OP_GT_FI,
|
||||
|
||||
OP_EQ_IF,
|
||||
OP_EQ_FI,
|
||||
|
||||
//-------------------------------------
|
||||
//string manipulation.
|
||||
OP_ADD_SF, //(char*)c = (char*)a + (float)b
|
||||
OP_SUB_S, //(float)c = (char*)a - (char*)b
|
||||
OP_STOREP_C,//(float)c = *(char*)b = (float)a
|
||||
OP_LOADP_C, //(float)c = *(char*) //170
|
||||
//-------------------------------------
|
||||
|
||||
|
||||
OP_MUL_IF,
|
||||
OP_MUL_FI,
|
||||
OP_MUL_VI,
|
||||
OP_MUL_IV,
|
||||
OP_DIV_IF,
|
||||
OP_DIV_FI,
|
||||
OP_BITAND_IF,
|
||||
OP_BITOR_IF,
|
||||
OP_BITAND_FI,
|
||||
OP_BITOR_FI, //180
|
||||
OP_AND_I,
|
||||
OP_OR_I,
|
||||
OP_AND_IF,
|
||||
OP_OR_IF,
|
||||
OP_AND_FI,
|
||||
OP_OR_FI,
|
||||
OP_NE_IF,
|
||||
OP_NE_FI,
|
||||
OP_GSTOREP_I,
|
||||
OP_GSTOREP_F, //190
|
||||
OP_GSTOREP_ENT,
|
||||
OP_GSTOREP_FLD, // integers
|
||||
OP_GSTOREP_S,
|
||||
OP_GSTOREP_FNC, // pointers
|
||||
OP_GSTOREP_V,
|
||||
OP_GADDRESS,
|
||||
OP_GLOAD_I,
|
||||
OP_GLOAD_F,
|
||||
OP_GLOAD_FLD,
|
||||
OP_GLOAD_ENT, //200
|
||||
OP_GLOAD_S,
|
||||
OP_GLOAD_FNC,
|
||||
OP_BOUNDCHECK,
|
||||
|
||||
OP_NUMOPS
|
||||
};
|
||||
|
||||
|
||||
#ifndef COMPILER
|
||||
typedef struct statement16_s
|
||||
{
|
||||
unsigned short op;
|
||||
unsigned short a,b,c;
|
||||
} dstatement16_t;
|
||||
typedef struct statement32_s
|
||||
{
|
||||
unsigned int op;
|
||||
unsigned int a,b,c;
|
||||
} dstatement32_t;
|
||||
#else
|
||||
typedef struct QCC_statement16_s
|
||||
{
|
||||
unsigned short op;
|
||||
unsigned short a,b,c;
|
||||
} QCC_dstatement16_t;
|
||||
typedef struct QCC_statement32_s
|
||||
{
|
||||
unsigned int op;
|
||||
unsigned int a,b,c;
|
||||
} QCC_dstatement32_t;
|
||||
#define QCC_dstatement_t QCC_dstatement32_t
|
||||
#endif
|
||||
|
||||
//these should be the same except the string type
|
||||
#ifndef COMPILER
|
||||
typedef struct ddef16_s
|
||||
{
|
||||
unsigned short type; // if DEF_SAVEGLOBAL bit is set
|
||||
// the variable needs to be saved in savegames
|
||||
unsigned short ofs;
|
||||
string_t s_name;
|
||||
} ddef16_t;
|
||||
|
||||
typedef struct ddef32_s
|
||||
{
|
||||
unsigned int type; // if DEF_SAVEGLOBAL bit is set
|
||||
// the variable needs to be saved in savegames
|
||||
unsigned int ofs;
|
||||
string_t s_name;
|
||||
} ddef32_t;
|
||||
|
||||
typedef struct fdef_s
|
||||
{
|
||||
unsigned int type; // if DEF_SAVEGLOBAL bit is set
|
||||
// the variable needs to be saved in savegames
|
||||
unsigned int ofs;
|
||||
unsigned int requestedofs;
|
||||
string_t s_name;
|
||||
} fdef_t;
|
||||
|
||||
typedef void *ddefXX_t;
|
||||
#else
|
||||
typedef struct QCC_ddef16_s
|
||||
{
|
||||
unsigned short type; // if DEF_SAVEGLOBAL bit is set
|
||||
// the variable needs to be saved in savegames
|
||||
unsigned short ofs;
|
||||
QCC_string_t s_name;
|
||||
} QCC_ddef16_t;
|
||||
|
||||
typedef struct QCC_ddef32_s
|
||||
{
|
||||
unsigned int type; // if DEF_SAVEGLOBAL bit is set
|
||||
// the variable needs to be saved in savegames
|
||||
unsigned int ofs;
|
||||
QCC_string_t s_name;
|
||||
} QCC_ddef32_t;
|
||||
|
||||
#define QCC_ddef_t QCC_ddef32_t
|
||||
#endif
|
||||
|
||||
#define DEF_SAVEGLOBAL (1<<15)
|
||||
#define DEF_SHARED (1<<14)
|
||||
|
||||
#define MAX_PARMS 8
|
||||
|
||||
#ifndef COMPILER
|
||||
typedef struct
|
||||
{
|
||||
int first_statement; // negative numbers are builtins
|
||||
int parm_start;
|
||||
int locals; // total ints of parms + locals
|
||||
|
||||
int profile; // runtime
|
||||
|
||||
string_t s_name;
|
||||
string_t s_file; // source file defined in
|
||||
|
||||
int numparms;
|
||||
qbyte parm_size[MAX_PARMS];
|
||||
} dfunction_t;
|
||||
#else
|
||||
typedef struct
|
||||
{
|
||||
unsigned int first_statement; // negative numbers are builtins
|
||||
unsigned int parm_start;
|
||||
int locals; // total ints of parms + locals
|
||||
|
||||
int profile; // runtime
|
||||
|
||||
QCC_string_t s_name;
|
||||
QCC_string_t s_file; // source file defined in
|
||||
|
||||
int numparms;
|
||||
qbyte parm_size[MAX_PARMS];
|
||||
} QCC_dfunction_t;
|
||||
#endif
|
||||
|
||||
|
||||
#define PROG_VERSION 6
|
||||
#define PROG_DEBUGVERSION 7
|
||||
#define PROG_SECONDARYVERSION16 (*(int*)"1FTE" ^ *(int*)"PROG") //something unlikly and still meaningful (to me)
|
||||
#define PROG_SECONDARYVERSION32 (*(int*)"1FTE" ^ *(int*)"32B ") //something unlikly and still meaningful (to me)
|
||||
typedef struct
|
||||
{
|
||||
int version;
|
||||
int crc; // check of header file
|
||||
|
||||
unsigned int ofs_statements; //comp 1
|
||||
unsigned int numstatements; // statement 0 is an error
|
||||
|
||||
unsigned int ofs_globaldefs; //comp 2
|
||||
unsigned int numglobaldefs;
|
||||
|
||||
unsigned int ofs_fielddefs; //comp 4
|
||||
unsigned int numfielddefs;
|
||||
|
||||
unsigned int ofs_functions; //comp 8
|
||||
unsigned int numfunctions; // function 0 is an empty
|
||||
|
||||
unsigned int ofs_strings; //comp 16
|
||||
unsigned int numstrings; // first string is a null string
|
||||
|
||||
unsigned int ofs_globals; //comp 32
|
||||
unsigned int numglobals;
|
||||
|
||||
unsigned int entityfields;
|
||||
|
||||
//debug / version 7 extensions
|
||||
unsigned int ofsfiles; //non list format. no comp
|
||||
unsigned int ofslinenums; //numstatements big //comp 64
|
||||
unsigned int ofsbodylessfuncs; //no comp
|
||||
unsigned int numbodylessfuncs;
|
||||
|
||||
unsigned int ofs_types; //comp 128
|
||||
unsigned int numtypes;
|
||||
unsigned int blockscompressed;
|
||||
|
||||
int secondaryversion; //Constant - to say that any version 7 progs are actually ours, not someone else's alterations.
|
||||
} dprograms_t;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
char filename[128];
|
||||
int size;
|
||||
int compsize;
|
||||
int compmethod;
|
||||
int ofs;
|
||||
} includeddatafile_t;
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct typeinfo_s
|
||||
{
|
||||
etype_t type;
|
||||
|
||||
int next;
|
||||
int aux_type;
|
||||
int num_parms;
|
||||
|
||||
int ofs; //inside a structure.
|
||||
int size;
|
||||
char *name;
|
||||
} typeinfo_t;
|
1090
engine/qclib/pr_exec.c
Normal file
1090
engine/qclib/pr_exec.c
Normal file
File diff suppressed because it is too large
Load diff
446
engine/qclib/progsint.h
Normal file
446
engine/qclib/progsint.h
Normal file
|
@ -0,0 +1,446 @@
|
|||
#ifdef WIN32
|
||||
|
||||
#ifndef AVAIL_ZLIB
|
||||
#ifdef _MSC_VER
|
||||
//#define AVAIL_ZLIB
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
enum{false, true};
|
||||
#else
|
||||
#include <stdarg.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <setjmp.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifndef __declspec
|
||||
#define __declspec(mode)
|
||||
#endif
|
||||
typedef enum{false, true} boolean;
|
||||
//#define _inline inline
|
||||
#endif
|
||||
typedef unsigned char qbyte;
|
||||
#include <stdio.h>
|
||||
|
||||
#define DLL_PROG
|
||||
#ifndef PROGSUSED
|
||||
#define PROGSUSED
|
||||
#endif
|
||||
|
||||
#define DYNAMIC_ENTS
|
||||
|
||||
extern int maxedicts;
|
||||
extern int maxprogs;
|
||||
extern int hunksize;
|
||||
|
||||
#include "progtype.h"
|
||||
#include "progslib.h"
|
||||
|
||||
//extern progfuncs_t *progfuncs;
|
||||
|
||||
#define prinst progfuncs->prinst
|
||||
#define externs progfuncs->parms
|
||||
|
||||
#include "pr_comp.h"
|
||||
|
||||
#include "qcd.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int targetflags; //weather we need to mark the progs as a newer version
|
||||
char *name;
|
||||
char *opname;
|
||||
int priority;
|
||||
enum {ASSOC_LEFT, ASSOC_RIGHT, ASSOC_RIGHT_RESULT} associative;
|
||||
struct QCC_type_s **type_a, **type_b, **type_c;
|
||||
} QCC_opcode_t;
|
||||
extern QCC_opcode_t pr_opcodes[]; // sized by initialization
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define Q_vsnprintf _vsnprintf
|
||||
#else
|
||||
#define Q_vsnprintf vsnprintf
|
||||
#endif
|
||||
|
||||
|
||||
#define sv_num_edicts (*externs->sv_num_edicts)
|
||||
#define sv_edicts (*externs->sv_edicts)
|
||||
|
||||
#define printf externs->printf
|
||||
#define Sys_Error externs->Sys_Error
|
||||
#define Abort externs->Abort
|
||||
|
||||
#define memalloc externs->memalloc
|
||||
#define memfree externs->memfree
|
||||
|
||||
int PRHunkMark(progfuncs_t *progfuncs);
|
||||
void PRHunkFree(progfuncs_t *progfuncs, int mark);
|
||||
void *PRHunkAlloc(progfuncs_t *progfuncs, int size);
|
||||
|
||||
//void *HunkAlloc (int size);
|
||||
char *VARGS qcva (char *text, ...);
|
||||
void QC_InitShares(progfuncs_t *progfuncs);
|
||||
void QC_StartShares(progfuncs_t *progfuncs);
|
||||
void QC_AddSharedVar(progfuncs_t *progfuncs, int num, int type);
|
||||
void QC_AddSharedFieldVar(progfuncs_t *progfuncs, int num);
|
||||
int QC_RegisterFieldVar(progfuncs_t *progfuncs, unsigned int type, char *name, int requestedpos, int origionalofs);
|
||||
pbool Decompile(progfuncs_t *progfuncs, char *fname);
|
||||
int PR_ToggleBreakpoint(progfuncs_t *progfuncs, char *filename, int linenum, int flag);
|
||||
|
||||
|
||||
#define edvars(ed) (((char *)ed)+externs->edictsize) //pointer to the field vars, given an edict
|
||||
|
||||
|
||||
|
||||
extern short (*BigShort) (short l);
|
||||
extern short (*LittleShort) (short l);
|
||||
extern long (*BigLong) (long l);
|
||||
extern long (*LittleLong) (long l);
|
||||
extern float (*BigFloat) (float l);
|
||||
extern float (*LittleFloat) (float l);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
#ifndef COMPILER
|
||||
typedef union eval_s
|
||||
{
|
||||
string_t string;
|
||||
float _float;
|
||||
float vector[3];
|
||||
func_t function;
|
||||
int _int;
|
||||
int edict;
|
||||
progsnum_t prog; //so it can easily be changed
|
||||
} eval_t;
|
||||
#endif
|
||||
*/
|
||||
|
||||
|
||||
#define MAX_ENT_LEAFS 16
|
||||
typedef struct edictrun_s
|
||||
{
|
||||
pbool isfree;
|
||||
|
||||
float freetime; // realtime when the object was freed
|
||||
int entnum;
|
||||
pbool readonly; //causes error when QC tries writing to it. (quake's world entity)
|
||||
|
||||
// other fields from progs come immediately after
|
||||
} edictrun_t;
|
||||
#define EDICT_FROM_AREA(l) STRUCT_FROM_LINK(l,edictrun_t,area)
|
||||
|
||||
|
||||
int Comp_Begin(progfuncs_t *progfuncs, int nump, char **parms);
|
||||
int Comp_Continue(progfuncs_t *progfuncs);
|
||||
|
||||
char *EvaluateDebugString(progfuncs_t *progfuncs, char *key);
|
||||
char *SaveEnts(progfuncs_t *progfuncs, char *mem, int *size, int mode);
|
||||
int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags);
|
||||
char *SaveEnt (progfuncs_t *progfuncs, char *buf, int *size, struct edict_s *ed);
|
||||
struct edict_s *RestoreEnt (progfuncs_t *progfuncs, char *buf, int *size, struct edict_s *ed);
|
||||
char *PF_VarString (int first);
|
||||
void PR_StackTrace (progfuncs_t *progfuncs);
|
||||
|
||||
extern int outputversion;
|
||||
extern int noextensions;
|
||||
|
||||
#ifndef COMPILER
|
||||
typedef struct progstate_s
|
||||
{
|
||||
dprograms_t *progs;
|
||||
dfunction_t *functions;
|
||||
char *strings;
|
||||
union {
|
||||
ddefXX_t *globaldefs;
|
||||
ddef16_t *globaldefs16;
|
||||
ddef32_t *globaldefs32;
|
||||
};
|
||||
union {
|
||||
ddefXX_t *fielddefs;
|
||||
ddef16_t *fielddefs16;
|
||||
ddef32_t *fielddefs32;
|
||||
};
|
||||
void *statements;
|
||||
// void *global_struct;
|
||||
float *globals; // same as pr_global_struct
|
||||
|
||||
typeinfo_t *types;
|
||||
|
||||
int edict_size; // in bytes
|
||||
|
||||
char filename[128];
|
||||
|
||||
builtin_t *builtins;
|
||||
int numbuiltins;
|
||||
|
||||
int *linenums; //debug versions only
|
||||
|
||||
int intsize; //16 for standard (more limiting) versions
|
||||
} progstate_t;
|
||||
|
||||
typedef struct extensionbuiltin_s {
|
||||
char *name;
|
||||
builtin_t func;
|
||||
struct extensionbuiltin_s *prev;
|
||||
} extensionbuiltin_t;
|
||||
|
||||
//============================================================================
|
||||
|
||||
|
||||
#define pr_progs current_progstate->progs
|
||||
#define pr_functions current_progstate->functions
|
||||
#define pr_strings current_progstate->strings
|
||||
#define pr_globaldefs16 ((ddef16_t*)current_progstate->globaldefs)
|
||||
#define pr_globaldefs32 ((ddef32_t*)current_progstate->globaldefs)
|
||||
#define pr_fielddefs16 ((ddef16_t*)current_progstate->fielddefs)
|
||||
#define pr_fielddefs32 ((ddef32_t*)current_progstate->fielddefs)
|
||||
#define pr_statements16 ((dstatement16_t*)current_progstate->statements)
|
||||
#define pr_statements32 ((dstatement32_t*)current_progstate->statements)
|
||||
//#define pr_global_struct current_progstate->global_struct
|
||||
#define pr_globals current_progstate->globals
|
||||
#define pr_linenums current_progstate->linenums
|
||||
#define pr_types current_progstate->types
|
||||
|
||||
|
||||
|
||||
//============================================================================
|
||||
|
||||
void PR_Init (void);
|
||||
|
||||
void PR_ExecuteProgram (progfuncs_t *progfuncs, func_t fnum);
|
||||
int PR_LoadProgs(progfuncs_t *progfncs, char *s, int headercrc, builtin_t *builtins, int numbuiltins);
|
||||
int PR_ReallyLoadProgs (progfuncs_t *progfuncs, char *filename, int headercrc, progstate_t *progstate, pbool complain);
|
||||
|
||||
void *PRHunkAlloc(progfuncs_t *progfuncs, int ammount);
|
||||
|
||||
void PR_Profile_f (void);
|
||||
|
||||
struct edict_s *ED_Alloc (progfuncs_t *progfuncs);
|
||||
void ED_Free (progfuncs_t *progfuncs, struct edict_s *ed);
|
||||
|
||||
char *ED_NewString (progfuncs_t *progfuncs, char *string);
|
||||
// returns a copy of the string allocated from the server's string heap
|
||||
|
||||
void ED_Print (progfuncs_t *progfuncs, struct edict_s *ed);
|
||||
//void ED_Write (FILE *f, edictrun_t *ed);
|
||||
char *ED_ParseEdict (progfuncs_t *progfuncs, char *data, edictrun_t *ent);
|
||||
|
||||
//void ED_WriteGlobals (FILE *f);
|
||||
void ED_ParseGlobals (char *data);
|
||||
|
||||
//void ED_LoadFromFile (char *data);
|
||||
|
||||
//define EDICT_NUM(n) ((edict_t *)(sv.edicts+ (n)*pr_edict_size))
|
||||
//define NUM_FOR_EDICT(e) (((byte *)(e) - sv.edicts)/pr_edict_size)
|
||||
|
||||
struct edict_s *EDICT_NUM(progfuncs_t *progfuncs, int n);
|
||||
int NUM_FOR_EDICT(progfuncs_t *progfuncs, struct edict_s *e);
|
||||
|
||||
//#define NEXT_EDICT(e) ((edictrun_t *)( (byte *)e + pr_edict_size))
|
||||
|
||||
#define EDICT_TO_PROG(e) ((qbyte *)e - (qbyte *)sv_edicts)
|
||||
#define PROG_TO_EDICT(e) ((edictrun_t *)((qbyte *)sv_edicts + e))
|
||||
|
||||
//============================================================================
|
||||
|
||||
#define G_FLOAT(o) (pr_globals[o])
|
||||
#define G_FLOAT2(o) (pr_globals[OFS_PARM0 + o*3])
|
||||
#define G_INT(o) (*(int *)&pr_globals[o])
|
||||
#define G_EDICT(o) ((edict_t *)((qbyte *)sv_edicts+ *(int *)&pr_globals[o]))
|
||||
#define G_EDICTNUM(o) NUM_FOR_EDICT(G_EDICT(o))
|
||||
#define G_VECTOR(o) (&pr_globals[o])
|
||||
#define G_STRING(o) (*(string_t *)&pr_globals[o])
|
||||
#define G_STRING2(o) ((char*)*(string_t *)&pr_globals[o])
|
||||
#define GQ_STRING(o) (*(QCC_string_t *)&pr_globals[o])
|
||||
#define GQ_STRING2(o) ((char*)*(QCC_string_t *)&pr_globals[o])
|
||||
#define G_FUNCTION(o) (*(func_t *)&pr_globals[o])
|
||||
#define G_PROG(o) (*(progsnum_t *)&pr_globals[o]) //simply so it's nice and easy to change...
|
||||
|
||||
#define RETURN_EDICT(e) (((int *)pr_globals)[OFS_RETURN] = EDICT_TO_PROG(e))
|
||||
|
||||
#define E_FLOAT(e,o) (((float*)&e->v)[o])
|
||||
#define E_INT(e,o) (*(int *)&((float*)&e->v)[o])
|
||||
#define E_VECTOR(e,o) (&((float*)&e->v)[o])
|
||||
#define E_STRING(e,o) (*(string_t *)&((float*)(e+1))[o])
|
||||
|
||||
extern int type_size[9];
|
||||
|
||||
|
||||
extern unsigned short pr_crc;
|
||||
|
||||
void VARGS PR_RunError (progfuncs_t *progfuncs, char *error, ...);
|
||||
|
||||
void ED_PrintEdicts (progfuncs_t *progfuncs);
|
||||
void ED_PrintNum (progfuncs_t *progfuncs, int ent);
|
||||
|
||||
|
||||
pbool PR_SwitchProgs(progfuncs_t *progfuncs, progsnum_t type);
|
||||
void PR_MoveParms(progfuncs_t *progfuncs, progsnum_t progs1, progsnum_t progs2);
|
||||
|
||||
|
||||
|
||||
|
||||
eval_t *GetEdictFieldValue(progfuncs_t *progfuncs, struct edict_s *ed, char *name, evalc_t *cache);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef COMPILER
|
||||
|
||||
//this is windows - all files are written with this endian standard
|
||||
//optimisation
|
||||
//leave undefined if in doubt over os.
|
||||
#ifndef WIN32
|
||||
#define NOENDIAN
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct {
|
||||
int varofs;
|
||||
int size;
|
||||
} sharedvar_t;
|
||||
typedef struct
|
||||
{
|
||||
int s;
|
||||
dfunction_t *f;
|
||||
int progsnum;
|
||||
} prstack_t;
|
||||
|
||||
|
||||
|
||||
//pr_multi.c
|
||||
void PR_SetBuiltins(int type);
|
||||
|
||||
#define var(type, name) type name
|
||||
#define vars(type, name, size) type name[size]
|
||||
|
||||
typedef struct prinst_s {
|
||||
var(progstate_t *, pr_progstate);
|
||||
#define pr_progstate prinst->pr_progstate
|
||||
|
||||
var(progsnum_t, pr_typecurrent);
|
||||
#define pr_typecurrent prinst->pr_typecurrent
|
||||
var(int, maxprogs);
|
||||
#define maxprogs prinst->maxprogs
|
||||
|
||||
var(progstate_t *,current_progstate);
|
||||
#define current_progstate prinst->current_progstate
|
||||
|
||||
var(unsigned int, numshares);
|
||||
#define numshares prinst->numshares
|
||||
var(sharedvar_t *,shares); //shared globals, not including parms
|
||||
#define shares prinst->shares
|
||||
var(unsigned int, maxshares);
|
||||
#define maxshares prinst->maxshares
|
||||
|
||||
var(struct prmemb_s *, memblocks);
|
||||
#define memb prinst->memblocks
|
||||
|
||||
var(unsigned int, maxfields);
|
||||
#define maxfields prinst->maxfields
|
||||
var(unsigned int, numfields);
|
||||
#define numfields prinst->numfields
|
||||
var(fdef_t*, field); //biggest size
|
||||
#define field prinst->field
|
||||
|
||||
int reorganisefields;
|
||||
|
||||
|
||||
//pr_exec.c
|
||||
#define MAX_STACK_DEPTH 64
|
||||
vars(prstack_t, pr_stack, MAX_STACK_DEPTH);
|
||||
#define pr_stack prinst->pr_stack
|
||||
var(int, pr_depth);
|
||||
#define pr_depth prinst->pr_depth
|
||||
|
||||
#define LOCALSTACK_SIZE 16384
|
||||
vars(int, localstack, LOCALSTACK_SIZE);
|
||||
#define localstack prinst->localstack
|
||||
var(int, localstack_used);
|
||||
#define localstack_used prinst->localstack_used
|
||||
|
||||
var(int, continuestatement);
|
||||
var(int, exitdepth);
|
||||
|
||||
var(int, pr_trace);
|
||||
#define pr_trace prinst->pr_trace
|
||||
var(dfunction_t *, pr_xfunction);
|
||||
#define pr_xfunction prinst->pr_xfunction
|
||||
var(int, pr_xstatement);
|
||||
#define pr_xstatement prinst->pr_xstatement
|
||||
|
||||
var(int, pr_argc);
|
||||
#define pr_argc prinst->pr_argc
|
||||
|
||||
//pr_edict.c
|
||||
|
||||
var(int, maxedicts);
|
||||
#define maxedicts prinst->maxedicts
|
||||
|
||||
var(evalc_t, spawnflagscache);
|
||||
#define spawnflagscache prinst->spawnflagscache
|
||||
|
||||
|
||||
|
||||
|
||||
var(int, pr_edict_size); // in bytes
|
||||
#define pr_edict_size prinst->pr_edict_size
|
||||
var(int, pr_max_edict_size);
|
||||
#define pr_max_edict_size prinst->pr_max_edict_size
|
||||
|
||||
|
||||
//initlib.c
|
||||
var(char *, progshunk);
|
||||
#define progshunk prinst->progshunk
|
||||
var(int, hunkused);
|
||||
#define hunkused prinst->hunkused
|
||||
var(int, hunksize);
|
||||
#define hunksize prinst->hunksize
|
||||
|
||||
|
||||
var(extensionbuiltin_t *, extensionbuiltin);
|
||||
#define extensionbuiltin prinst->extensionbuiltin
|
||||
|
||||
#ifdef DYNAMIC_ENTS
|
||||
struct edict_s **edicttable;
|
||||
#endif
|
||||
|
||||
} prinst_t;
|
||||
extern vec3_t vec3_origin;
|
||||
|
||||
eval_t *PR_FindGlobal(progfuncs_t *prfuncs, char *globname, progsnum_t pnum);
|
||||
ddef16_t *ED_FindTypeGlobalFromProgs16 (progfuncs_t *progfuncs, char *name, progsnum_t prnum, int type);
|
||||
ddef32_t *ED_FindTypeGlobalFromProgs32 (progfuncs_t *progfuncs, char *name, progsnum_t prnum, int type);
|
||||
ddef16_t *ED_FindGlobalFromProgs16 (progfuncs_t *progfuncs, char *name, progsnum_t prnum);
|
||||
ddef32_t *ED_FindGlobalFromProgs32 (progfuncs_t *progfuncs, char *name, progsnum_t prnum);
|
||||
fdef_t *ED_FindField (progfuncs_t *progfuncs, char *name);
|
||||
dfunction_t *ED_FindFunction (progfuncs_t *progfuncs, char *name, int *pnum, int fromprogs);
|
||||
func_t PR_FindFunc(progfuncs_t *progfncs, char *funcname, progsnum_t pnum);
|
||||
void PR_Configure (progfuncs_t *progfncs, void *mem, int mem_size, int max_progs);
|
||||
int PR_InitEnts(progfuncs_t *progfncs, int maxents);
|
||||
char *PR_ValueString (progfuncs_t *progfuncs, etype_t type, eval_t *val);
|
||||
|
||||
ddef16_t *ED_GlobalAtOfs16 (progfuncs_t *progfuncs, int ofs);
|
||||
ddef16_t *ED_FindGlobal16 (progfuncs_t *progfuncs, char *name);
|
||||
ddef32_t *ED_FindGlobal32 (progfuncs_t *progfuncs, char *name);
|
||||
ddef32_t *ED_GlobalAtOfs32 (progfuncs_t *progfuncs, unsigned int ofs);
|
||||
|
||||
char *PR_GlobalString (progfuncs_t *progfuncs, int ofs);
|
||||
char *PR_GlobalStringNoContents (progfuncs_t *progfuncs, int ofs);
|
||||
|
||||
pbool CompileFile(progfuncs_t *progfuncs, char *filename);
|
||||
|
||||
char *QCC_COM_Parse (char *data);
|
||||
extern char qcc_token[1024];
|
||||
#endif
|
280
engine/qclib/progslib.h
Normal file
280
engine/qclib/progslib.h
Normal file
|
@ -0,0 +1,280 @@
|
|||
/*#define true 1
|
||||
#define false 0
|
||||
|
||||
#define PITCH 0
|
||||
#define YAW 1
|
||||
#define ROLL 2
|
||||
|
||||
typedef char bool;
|
||||
//typedef float vec3_t[3];
|
||||
typedef int progsnum_t;
|
||||
typedef int func_t;
|
||||
#ifndef COMPILER
|
||||
typedef char *string_t;
|
||||
#endif
|
||||
//typedef struct globalvars_s globalvars_t;
|
||||
//typedef struct edict_s edict_t;
|
||||
#define globalvars_t void
|
||||
#define edict_t void
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define VARGS __cdecl
|
||||
#endif
|
||||
#ifndef VARGS
|
||||
#define VARGS
|
||||
#endif
|
||||
|
||||
|
||||
struct edict_s;
|
||||
struct globalvars_s;
|
||||
typedef struct progfuncs_s progfuncs_t;
|
||||
typedef void (*builtin_t) (progfuncs_t *prinst, struct globalvars_s *gvars);
|
||||
|
||||
//used by progs engine. All nulls is reset.
|
||||
typedef struct {
|
||||
char *varname;
|
||||
struct fdef_s *ofs32;
|
||||
|
||||
int spare[2];
|
||||
} evalc_t;
|
||||
#define sizeofevalc sizeof(evalc_t)
|
||||
typedef enum {ev_void, ev_string, ev_float, ev_vector, ev_entity, ev_field, ev_function, ev_pointer, ev_integer, ev_struct, ev_union} etype_t;
|
||||
|
||||
struct progfuncs_s {
|
||||
int progsversion; //PROGSTRUCT_VERSION
|
||||
|
||||
|
||||
void (*PR_Configure) (progfuncs_t *prinst, void *mem, int memsize, int max_progs); //configure buffers and memory. Used to reset and must be called first.
|
||||
progsnum_t (*PR_LoadProgs) (progfuncs_t *prinst, char *s, int headercrc, builtin_t *builtins, int numbuiltins); //load a progs
|
||||
int (*PR_InitEnts) (progfuncs_t *prinst, int max_ents); //returns size of edicts for use with nextedict macro
|
||||
void (*PR_ExecuteProgram) (progfuncs_t *prinst, func_t fnum); //start execution
|
||||
pbool (*PR_SwitchProgs) (progfuncs_t *prinst, progsnum_t num); //switch to a different progs - my aim is to make this obsolete
|
||||
struct globalvars_s *(*globals) (progfuncs_t *prinst, progsnum_t num); //get the globals of a progs
|
||||
struct entvars_s *(*entvars) (progfuncs_t *prinst, struct edict_s *ent); //return a pointer to the entvars of an ent
|
||||
|
||||
void (VARGS *PR_RunError) (progfuncs_t *prinst, char *msg, ...); //builtins call this to say there was a problem
|
||||
void (*PR_PrintEdict) (progfuncs_t *prinst, struct edict_s *ed); //get a listing of all vars on an edict (sent back via 'print')
|
||||
|
||||
struct edict_s *(*ED_Alloc) (progfuncs_t *prinst);
|
||||
void (*ED_Free) (progfuncs_t *prinst, struct edict_s *ed);
|
||||
|
||||
struct edict_s *(*EDICT_NUM) (progfuncs_t *prinst, int n); //get the nth edict
|
||||
int (*NUM_FOR_EDICT) (progfuncs_t *prinst, struct edict_s *e); //so you can find out what that 'n' will be
|
||||
|
||||
void (*SetGlobalEdict) (progfuncs_t *prinst, struct edict_s *ed, int ofs); //set a global to an edict (partially obsolete)
|
||||
|
||||
char *(*PR_VarString) (progfuncs_t *prinst, int first); //returns a string made up of multiple arguments
|
||||
|
||||
struct progstate_s **progstate; //these are so the macros work properly
|
||||
// struct edict_s **sv_edicts;
|
||||
|
||||
// int *sv_num_edicts;
|
||||
|
||||
func_t (*PR_FindFunction) (progfuncs_t *prinst, char *funcname, progsnum_t num);
|
||||
|
||||
int (*PR_StartCompile) (progfuncs_t *prinst, int argv, char **argc); //1 if can compile, 0 if failed to compile
|
||||
int (*PR_ContinueCompile) (progfuncs_t *prinst); //2 if finished, 1 if more to go, 0 if failed
|
||||
|
||||
char *(*filefromprogs) (progfuncs_t *prinst, progsnum_t prnum, char *fname, int *size, char *buffer); //reveals encoded/added files from already loaded progs
|
||||
char *(*filefromnewprogs) (progfuncs_t *prinst, char *prname, char *fname, int *size, char *buffer); //reveals encoded/added files from a progs on the disk somewhere
|
||||
|
||||
char *(*save_ents) (progfuncs_t *prinst, char *buf, int *size, int mode); //dump the entire progs info into one big self allocated string
|
||||
int (*load_ents) (progfuncs_t *prinst, char *s, float killonspawnflags); //restore the entire progs state (or just add some more ents) (returns edicts ize)
|
||||
|
||||
char *(*saveent) (progfuncs_t *prinst, char *buf, int *size, struct edict_s *ed); //will save just one entities vars
|
||||
struct edict_s *(*restoreent) (progfuncs_t *prinst, char *buf, int *size, struct edict_s *ed); //will restore the entity that had it's values saved (can use NULL for ed)
|
||||
|
||||
union eval_s *(*FindGlobal) (progfuncs_t *prinst, char *name, progsnum_t num); //find a pointer to the globals value
|
||||
char *(*AddString) (progfuncs_t *prinst, char *val); //dump a string into the progs memory (for setting globals and whatnot)
|
||||
void *(*Tempmem) (progfuncs_t *prinst, int ammount, char *whatfor); //grab some mem for as long as the progs stays loaded (for strings)
|
||||
|
||||
union eval_s *(*GetEdictFieldValue) (progfuncs_t *prinst, struct edict_s *ent, char *name, evalc_t *s); //get an entityvar (cache it) and return the possible values
|
||||
struct edict_s *(*ProgsToEdict) (progfuncs_t *prinst, int progs); //edicts are stored as ints and need to be adjusted
|
||||
int (*EdictToProgs) (progfuncs_t *prinst, struct edict_s *ed); //edicts are stored as ints and need to be adjusted
|
||||
|
||||
char *(*EvaluateDebugString) (progfuncs_t *prinst, char *key); //evaluate a string and return it's value (according to current progs) (expands edict vars)
|
||||
|
||||
int *pr_trace; //start calling the editor for each line executed
|
||||
|
||||
void (*PR_StackTrace) (progfuncs_t *prinst);
|
||||
|
||||
int (*ToggleBreak) (progfuncs_t *prinst, char *filename, int linenum, int mode);
|
||||
|
||||
int numprogs;
|
||||
|
||||
struct progexterns_s *parms; //these are the initial parms, they may be changed
|
||||
|
||||
pbool (*Decompile) (progfuncs_t *prinst, char *fname);
|
||||
|
||||
|
||||
struct prinst_s *prinst; //internal variables. Leave alone.
|
||||
|
||||
int *callargc; //number of args of built-in call
|
||||
void (*RegisterBuiltin) (progfuncs_t *prinst, char *, builtin_t);
|
||||
|
||||
int stringtable; //qc strings are all relative. add to a qc string. this is required for support of frikqcc progs that strip string immediates.
|
||||
int fieldadjust; //FrikQCC style arrays can cause problems due to field remapping. This causes us to leave gaps but offsets identical.
|
||||
|
||||
struct qcthread_s *(*Fork) (progfuncs_t *prinst);
|
||||
void (*RunThread) (progfuncs_t *prinst, struct qcthread_s *thread);
|
||||
void (*AbortStack) (progfuncs_t *prinst);
|
||||
|
||||
int lastcalledbuiltinnumber;
|
||||
};
|
||||
|
||||
typedef struct progexterns_s {
|
||||
int progsversion; //PROGSTRUCT_VERSION
|
||||
|
||||
unsigned char *(*ReadFile) (char *fname, void *buffer, int len);
|
||||
int (*FileSize) (char *fname); //-1 if file does not exist
|
||||
pbool (*WriteFile) (char *name, void *data, int len);
|
||||
int (VARGS *printf) (const char *, ...);
|
||||
void (VARGS *Sys_Error) (const char *, ...);
|
||||
void (VARGS *Abort) (char *, ...);
|
||||
int edictsize; //size of edict_t
|
||||
|
||||
void (*entspawn) (struct edict_s *ent); //ent has been spawned, but may not have all the extra variables (that may need to be set) set
|
||||
pbool (*entcanfree) (struct edict_s *ent); //return true to stop ent from being freed
|
||||
void (*stateop) (progfuncs_t *prinst, float var, func_t func);
|
||||
void (*cstateop) (progfuncs_t *prinst, float vara, float varb, func_t currentfunc);
|
||||
void (*cwstateop) (progfuncs_t *prinst, float vara, float varb, func_t currentfunc);
|
||||
void (*thinktimeop) (progfuncs_t *prinst, struct edict_s *ent, float varb);
|
||||
|
||||
|
||||
//used when loading a game
|
||||
builtin_t *(*builtinsfor) (int num, int headercrc); //must return a pointer to the builtins that were used before the state was saved.
|
||||
void (*loadcompleate) (int edictsize); //notification to reset any pointers.
|
||||
|
||||
void *(VARGS *memalloc) (int size); //small string allocation malloced and freed randomly by the executor. (use malloc if you want)
|
||||
void (VARGS *memfree) (void * mem);
|
||||
|
||||
|
||||
builtin_t *globalbuiltins; //these are available to all progs
|
||||
int numglobalbuiltins;
|
||||
|
||||
enum {PR_NOCOMPILE, PR_COMPILENEXIST, PR_COMPILECHANGED, PR_COMPILEALWAYS, PR_COMPILEIGNORE} autocompile;
|
||||
|
||||
double *gametime;
|
||||
|
||||
struct edict_s **sv_edicts;
|
||||
int *sv_num_edicts;
|
||||
|
||||
int (*useeditor) (char *filename, int line, int nump, char **parms);
|
||||
} progparms_t, progexterns_t;
|
||||
|
||||
void QC_AddSharedVar(progfuncs_t *progfuncs, int start, int size);
|
||||
|
||||
|
||||
#if defined(QCLIBDLL_EXPORTS)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
progfuncs_t * InitProgs(progparms_t *ext);
|
||||
#if defined(QCLIBDLL_EXPORTS)
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void CloseProgs(progfuncs_t *inst);
|
||||
|
||||
#ifndef COMPILER
|
||||
typedef union eval_s
|
||||
{
|
||||
string_t string;
|
||||
float _float;
|
||||
float vector[3];
|
||||
func_t function;
|
||||
int _int;
|
||||
int edict;
|
||||
progsnum_t prog; //so it can easily be changed
|
||||
} eval_t;
|
||||
#endif
|
||||
|
||||
#define PR_CURRENT -1
|
||||
#define PR_ANY -2 //not always valid. Use for finding funcs
|
||||
#define PROGSTRUCT_VERSION 1
|
||||
|
||||
|
||||
#ifndef DLL_PROG
|
||||
#define PR_Configure(pf, mem, memsize, max_progs) (*pf->PR_Configure) (pf, mem, memsize, max_progs)
|
||||
#define PR_LoadProgs(pf, s, headercrc, builtins, numb) (*pf->PR_LoadProgs) (pf, s, headercrc, builtins, numb)
|
||||
#define PR_InitEnts(pf, maxents) (*pf->PR_InitEnts) (pf, maxents)
|
||||
#define PR_ExecuteProgram(pf, fnum) (*pf->PR_ExecuteProgram) (pf, fnum)
|
||||
#define PR_SwitchProgs(pf, num) (*pf->PR_SwitchProgs) (pf, num);
|
||||
#define PR_globals(pf, num) (*pf->globals) (pf, num)
|
||||
#define PR_entvars(pf, ent) (*pf->entvars) (pf, ent)
|
||||
|
||||
#define ED_Alloc(pf) (*pf->ED_Alloc) (pf)
|
||||
#define ED_Free(pf, ed) (*pf->ED_Free) (pf, ed)
|
||||
|
||||
#define PR_LoadEnts(pf, s, kf) (*pf->load_ents) (pf, s, kf)
|
||||
#define PR_SaveEnts(pf, buf, size, mode) (*pf->save_ents) (pf, buf, size, mode)
|
||||
|
||||
#define EDICT_NUM(pf, num) (*pf->EDICT_NUM) (pf, num)
|
||||
#define NUM_FOR_EDICT(pf, e) (*pf->NUM_FOR_EDICT) (pf, e)
|
||||
#define SetGlobalEdict(pf, ed, ofs) (*pf->SetGlobalEdict) (pf, ed, ofs)
|
||||
#define PR_VarString (*progfuncs->PR_VarString)
|
||||
|
||||
//#define sv_edicts (*progfuncs->sv_edicts)
|
||||
#define current_progstate (*progfuncs->progstate)
|
||||
|
||||
//#define pr_num_edicts (*progfuncs->sv_num_edicts)
|
||||
|
||||
#define PR_FindFunction(pf, name, num) (*pf->PR_FindFunction) (pf, name, num)
|
||||
#define PR_FindGlobal(pf, name, progs) (*pf->FindGlobal) (pf, name, progs)
|
||||
#define PR_AddString(pf, ed) (*pf->AddString) (pf, ed)
|
||||
#define PR_Alloc (*progfuncs->Tempmem)
|
||||
|
||||
#define PROG_TO_EDICT(pf, ed) (*pf->ProgsToEdict) (pf, ed)
|
||||
#define EDICT_TO_PROG(pf, ed) (*pf->EdictToProgs) (pf, ed)
|
||||
|
||||
#define PR_RunError (*progfuncs->PR_RunError)
|
||||
#define PR_PrintEdict (*progfuncs->PR_PrintEdict)
|
||||
|
||||
#define PR_RegisterBuiltin(pf, name, func) (*pf->RegisterBuiltin) (pf, name, func)
|
||||
|
||||
//#ifdef DYNAMIC_ENTS
|
||||
#define NEXT_EDICT(pf,o) EDICT_NUM(pf, NUM_FOR_EDICT(pf, o)+1)
|
||||
/*#else
|
||||
#define NEXT_EDICT(pf, o) (edict_t *)(((char *)o)+ pr_edict_size)
|
||||
#endif*/
|
||||
#define RETURN_EDICT(pf, e) (((int *)pr_globals)[OFS_RETURN] = EDICT_TO_PROG(pf, e))
|
||||
|
||||
|
||||
//builtin funcs (which operate on globals)
|
||||
#define G_FLOAT(o) (((float *)pr_globals)[o])
|
||||
#define G_FLOAT2(o) (((float *)pr_globals)[OFS_PARM0 + o*3])
|
||||
#define G_INT(o) (((int *)pr_globals)[o])
|
||||
#define G_EDICT(pf, o) PROG_TO_EDICT(pf, G_INT(o)) //((edict_t *)((char *) sv.edicts+ *(int *)&((float *)pr_globals)[o]))
|
||||
#define G_EDICTNUM(pf, o) NUM_FOR_EDICT(pf, G_EDICT(pf, o))
|
||||
#define G_VECTOR(o) (&((float *)pr_globals)[o])
|
||||
#define G_FUNCTION(o) (*(func_t *)&((float *)pr_globals)[o])
|
||||
#define G_PROG(o) (*(progsnum_t *)&((float *)pr_globals)[o]) //simply so it's nice and easy to change...
|
||||
|
||||
#define PR_GetString(p,s) (s?s + p->stringtable:"")
|
||||
#define PR_GetStringOfs(p,o) (G_INT(o)?(char *)G_INT(o) + p->stringtable:"")
|
||||
#define PR_SetString(p, s) ((s&&*s)?(s - p->stringtable):0)
|
||||
#define PR_NewString(p, s) (PR_AddString(p, s) - p->stringtable)
|
||||
|
||||
#define ev_prog ev_integer
|
||||
|
||||
#define E_STRING(o) (char *)(((int *)((char *)ed) + progparms.edictsize)[o])
|
||||
|
||||
//#define pr_global_struct pr_globals
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#define OFS_NULL 0
|
||||
#define OFS_RETURN 1
|
||||
#define OFS_PARM0 4 // leave 3 ofs for each parm to hold vectors
|
||||
#define OFS_PARM1 7
|
||||
#define OFS_PARM2 10
|
||||
#define OFS_PARM3 13
|
||||
#define OFS_PARM4 16
|
||||
#define OFS_PARM5 19
|
||||
#define OFS_PARM6 22
|
||||
#define OFS_PARM7 25
|
||||
#define RESERVED_OFS 28
|
||||
|
||||
|
||||
#undef edict_t
|
||||
#undef globalvars_t
|
3201
engine/qclib/qccmain.c
Normal file
3201
engine/qclib/qccmain.c
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue