2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
progs.h
|
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
(description)
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
2001-08-27 21:13:00 +00:00
|
|
|
#ifndef __QF_progs_h
|
|
|
|
#define __QF_progs_h
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-03-27 23:36:02 +00:00
|
|
|
#include "QF/link.h"
|
2001-05-30 04:34:06 +00:00
|
|
|
#include "QF/vfile.h"
|
2001-03-27 23:36:02 +00:00
|
|
|
#include "QF/pr_comp.h"
|
2001-07-14 23:53:59 +00:00
|
|
|
#include "QF/pr_debug.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
typedef union pr_type_u {
|
|
|
|
float float_var;
|
2001-02-28 09:12:01 +00:00
|
|
|
string_t string_var;
|
|
|
|
func_t func_var;
|
2001-03-01 21:11:35 +00:00
|
|
|
int entity_var;
|
2001-02-28 09:12:01 +00:00
|
|
|
float vector_var[1]; // really 3, but this structure must be 32 bits
|
2001-07-22 20:20:46 +00:00
|
|
|
int integer_var;
|
2001-02-26 20:52:14 +00:00
|
|
|
} pr_type_t;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#define MAX_ENT_LEAFS 16
|
|
|
|
typedef struct edict_s
|
|
|
|
{
|
|
|
|
qboolean free;
|
|
|
|
link_t area; // linked to a division node or leaf
|
|
|
|
|
|
|
|
int num_leafs;
|
|
|
|
short leafnums[MAX_ENT_LEAFS];
|
|
|
|
|
|
|
|
float freetime; // sv.time when the object was freed
|
2001-02-28 22:44:38 +00:00
|
|
|
void *data; // external per-edict data
|
2001-02-28 01:59:31 +00:00
|
|
|
pr_type_t v[1]; // fields from progs
|
2001-02-19 21:15:25 +00:00
|
|
|
} edict_t;
|
|
|
|
#define EDICT_FROM_AREA(l) STRUCT_FROM_LINK(l,edict_t,area)
|
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
#ifndef PROGS_T
|
|
|
|
typedef struct progs_s progs_t;
|
|
|
|
#define PROGS_T
|
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
void PR_Init (void);
|
2001-02-26 20:52:14 +00:00
|
|
|
void PR_Init_Cvars (void);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-06-03 17:36:49 +00:00
|
|
|
void PR_PrintStatement (progs_t * pr, dstatement_t *s);
|
2001-02-26 20:52:14 +00:00
|
|
|
void PR_ExecuteProgram (progs_t *pr, func_t fnum);
|
2001-07-18 02:21:57 +00:00
|
|
|
void PR_LoadProgsFile (progs_t *pr, const char *progsname);
|
2001-07-15 07:04:17 +00:00
|
|
|
void PR_LoadProgs (progs_t *pr, const char *progsname);
|
2001-03-06 04:22:33 +00:00
|
|
|
void PR_LoadStrings (progs_t *pr);
|
2001-07-14 23:53:59 +00:00
|
|
|
void PR_LoadDebug (progs_t *pr);
|
2001-04-20 17:51:57 +00:00
|
|
|
edict_t *PR_InitEdicts (progs_t *pr, int num_edicts);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
void PR_Profile_f (void);
|
|
|
|
|
2001-08-12 04:14:25 +00:00
|
|
|
void ED_ClearEdict (progs_t * pr, edict_t *e, int val);
|
2001-02-26 20:52:14 +00:00
|
|
|
edict_t *ED_Alloc (progs_t *pr);
|
|
|
|
void ED_Free (progs_t *pr, edict_t *ed);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-07-15 07:04:17 +00:00
|
|
|
char *ED_NewString (progs_t *pr, const char *string);
|
2001-02-19 21:15:25 +00:00
|
|
|
// returns a copy of the string allocated from the server's string heap
|
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
void ED_Print (progs_t *pr, edict_t *ed);
|
2001-05-30 03:21:19 +00:00
|
|
|
void ED_Write (progs_t *pr, VFile *f, edict_t *ed);
|
2001-07-15 07:04:17 +00:00
|
|
|
const char *ED_ParseEdict (progs_t *pr, const char *data, edict_t *ent);
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2001-05-30 03:21:19 +00:00
|
|
|
void ED_WriteGlobals (progs_t *pr, VFile *f);
|
2001-07-15 07:04:17 +00:00
|
|
|
void ED_ParseGlobals (progs_t *pr, const char *data);
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2001-07-15 07:04:17 +00:00
|
|
|
void ED_LoadFromFile (progs_t *pr, const char *data);
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2001-08-26 10:13:03 +00:00
|
|
|
ddef_t *ED_FieldAtOfs (progs_t *pr, int ofs);
|
2001-03-27 03:57:17 +00:00
|
|
|
ddef_t *ED_FindField (progs_t *pr, const char *name);
|
2001-07-15 07:04:17 +00:00
|
|
|
int ED_GetFieldIndex (progs_t *pr, const char *name);
|
2001-03-27 03:57:17 +00:00
|
|
|
dfunction_t *ED_FindFunction (progs_t *pr, const char *name);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-03-27 03:57:17 +00:00
|
|
|
int PR_AccessField (progs_t *pr, const char *name, etype_t type,
|
|
|
|
const char *file, int line);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
//define EDICT_NUM(p,n) ((edict_t *)(*(p)->edicts+ (n)*(p)->pr_edict_size))
|
|
|
|
//define NUM_FOR_EDICT(p,e) (((byte *)(e) - *(p)->edicts)/(p)->pr_edict_size)
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
edict_t *EDICT_NUM(progs_t *pr, int n);
|
|
|
|
int NUM_FOR_EDICT(progs_t *pr, edict_t *e);
|
2001-09-23 01:29:52 +00:00
|
|
|
int NUM_FOR_BAD_EDICT(progs_t *pr, edict_t *e);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
#define NEXT_EDICT(p,e) ((edict_t *)( (byte *)e + (p)->pr_edict_size))
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
#define PR_edicts(p) ((byte *)*(p)->edicts)
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
#define EDICT_TO_PROG(p,e) ((byte *)(e) - PR_edicts (p))
|
|
|
|
#define PROG_TO_EDICT(p,e) ((edict_t *)(PR_edicts (p) + (e)))
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
#define G_var(p,o,t) ((p)->pr_globals[o].t##_var)
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
#define G_FLOAT(p,o) G_var (p, o, float)
|
2001-07-22 20:20:46 +00:00
|
|
|
#define G_INT(p,o) G_var (p, o, integer)
|
2001-02-26 20:52:14 +00:00
|
|
|
#define G_EDICT(p,o) ((edict_t *)(PR_edicts (p) + G_INT (p, o)))
|
|
|
|
#define G_EDICTNUM(p,o) NUM_FOR_EDICT(p, G_EDICT(p, o))
|
2001-03-02 23:41:50 +00:00
|
|
|
#define G_VECTOR(p,o) G_var (p, o, vector)
|
2001-02-28 22:44:38 +00:00
|
|
|
#define G_STRING(p,o) PR_GetString (p, G_var (p, o, string))
|
|
|
|
#define G_FUNCTION(p,o) G_var (p, o, func)
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2001-02-28 22:44:38 +00:00
|
|
|
#define E_var(e,o,t) ((e)->v[o].t##_var)
|
2001-02-26 20:52:14 +00:00
|
|
|
|
|
|
|
#define E_FLOAT(e,o) E_var (e, o, float)
|
2001-07-22 20:20:46 +00:00
|
|
|
#define E_INT(e,o) E_var (e, o, integer)
|
2001-03-01 18:44:19 +00:00
|
|
|
#define E_VECTOR(e,o) E_var (e, o, vector)
|
2001-02-28 22:44:38 +00:00
|
|
|
#define E_STRING(p,e,o) (PR_GetString (p, E_var (e, o, string)))
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
extern int type_size[8];
|
|
|
|
|
2001-08-03 06:40:28 +00:00
|
|
|
typedef void (*builtin_proc) (progs_t *pr);
|
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
builtin_proc proc;
|
|
|
|
} builtin_t;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-28 09:12:01 +00:00
|
|
|
ddef_t *PR_FindGlobal (progs_t *pr, const char *name);
|
2001-07-18 02:21:57 +00:00
|
|
|
ddef_t *ED_GlobalAtOfs (progs_t * pr, int ofs);
|
2001-03-27 03:57:17 +00:00
|
|
|
|
2001-06-08 00:13:06 +00:00
|
|
|
pr_type_t *PR_GetGlobalPointer (progs_t *pr, const char *name);
|
2001-03-27 03:57:17 +00:00
|
|
|
func_t PR_GetFunctionIndex (progs_t *pr, const char *name);
|
|
|
|
int PR_GetFieldOffset (progs_t *pr, const char *name);
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2001-07-30 04:33:59 +00:00
|
|
|
void PR_Error (progs_t *pr, const char *error, ...) __attribute__((format(printf,2,3), noreturn));
|
|
|
|
void PR_RunError (progs_t *pr, const char *error, ...) __attribute__((format(printf,2,3), noreturn));
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2001-07-19 03:18:11 +00:00
|
|
|
void ED_PrintEdicts (progs_t *pr, const char *fieldval);
|
2001-02-26 20:52:14 +00:00
|
|
|
void ED_PrintNum (progs_t *pr, int ent);
|
|
|
|
void ED_Count (progs_t *pr);
|
|
|
|
void PR_Profile (progs_t *pr);
|
|
|
|
|
2001-08-13 23:49:04 +00:00
|
|
|
char *PR_GlobalString (progs_t *pr, int ofs, etype_t type);
|
2001-02-26 20:52:14 +00:00
|
|
|
char *PR_GlobalStringNoContents (progs_t *pr, int ofs);
|
|
|
|
|
2001-07-15 07:04:17 +00:00
|
|
|
pr_type_t *GetEdictFieldValue(progs_t *pr, edict_t *ed, const char *field);
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2001-08-03 06:40:28 +00:00
|
|
|
void PR_AddBuiltin (progs_t *pr, const char *name, builtin_proc builtin, int num);
|
2001-08-04 23:44:50 +00:00
|
|
|
int PR_FindBuiltin (progs_t *pr, const char *name);
|
2001-08-03 06:40:28 +00:00
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
//
|
2001-07-14 23:53:59 +00:00
|
|
|
// PR Strings stuff
|
2001-02-26 20:52:14 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
char *PR_GetString(progs_t *pr, int num);
|
2001-07-15 07:04:17 +00:00
|
|
|
int PR_SetString(progs_t *pr, const char *s);
|
2001-06-06 18:10:47 +00:00
|
|
|
void PR_GarbageCollect (progs_t *pr);
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2001-07-14 23:53:59 +00:00
|
|
|
//
|
|
|
|
// PR Debug stuff
|
|
|
|
//
|
|
|
|
|
|
|
|
void PR_Debug_Init (void);
|
|
|
|
void PR_Debug_Init_Cvars (void);
|
|
|
|
pr_auxfunction_t *PR_Get_Lineno_Func (progs_t *pr, pr_lineno_t *lineno);
|
|
|
|
unsigned long PR_Get_Lineno_Addr (progs_t *pr, pr_lineno_t *lineno);
|
|
|
|
unsigned long PR_Get_Lineno_Line (progs_t *pr, pr_lineno_t *lineno);
|
|
|
|
pr_lineno_t *PR_Find_Lineno (progs_t *pr, unsigned long addr);
|
|
|
|
const char *PR_Get_Source_File (progs_t *pr, pr_lineno_t *lineno);
|
|
|
|
const char *PR_Get_Source_Line (progs_t *pr, unsigned long addr);
|
2001-07-19 07:27:14 +00:00
|
|
|
ddef_t *PR_Get_Local_Def (progs_t *pr, int offs);
|
2001-10-08 03:46:44 +00:00
|
|
|
void PR_DumpState (progs_t *pr);
|
|
|
|
void PR_StackTrace (progs_t * pr);
|
2001-07-14 23:53:59 +00:00
|
|
|
|
|
|
|
extern struct cvar_s *pr_debug;
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2001-08-21 22:34:20 +00:00
|
|
|
//
|
|
|
|
// PR Cmds stuff
|
|
|
|
//
|
|
|
|
|
2001-08-22 03:24:25 +00:00
|
|
|
void PR_Cmds_Init (progs_t *pr);
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#define MAX_STACK_DEPTH 32
|
|
|
|
#define LOCALSTACK_SIZE 2048
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int s;
|
|
|
|
dfunction_t *f;
|
|
|
|
} prstack_t;
|
|
|
|
|
2001-03-06 04:22:33 +00:00
|
|
|
typedef struct strref_s {
|
2001-08-13 20:01:37 +00:00
|
|
|
struct strref_s * next;
|
2001-03-06 04:22:33 +00:00
|
|
|
char *string;
|
|
|
|
int count;
|
|
|
|
} strref_t;
|
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
struct progs_s {
|
2001-07-15 07:04:17 +00:00
|
|
|
const char *progs_name;
|
2001-02-26 20:52:14 +00:00
|
|
|
dprograms_t *progs;
|
2001-07-18 02:21:57 +00:00
|
|
|
int progs_size;
|
2001-03-05 05:11:26 +00:00
|
|
|
|
|
|
|
struct hashtab_s *function_hash;
|
|
|
|
struct hashtab_s *global_hash;
|
|
|
|
struct hashtab_s *field_hash;
|
|
|
|
|
2001-03-06 04:22:33 +00:00
|
|
|
// garbage collected strings
|
|
|
|
strref_t *static_strings;
|
2001-08-13 20:01:37 +00:00
|
|
|
strref_t **dynamic_strings;
|
|
|
|
strref_t *free_string_refs;
|
|
|
|
int dyn_str_size;
|
2001-03-06 04:22:33 +00:00
|
|
|
struct hashtab_s *strref_hash;
|
|
|
|
int num_strings;
|
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
dfunction_t *pr_functions;
|
|
|
|
char *pr_strings;
|
2001-03-03 09:09:39 +00:00
|
|
|
int pr_stringsize;
|
2001-02-26 20:52:14 +00:00
|
|
|
ddef_t *pr_globaldefs;
|
|
|
|
ddef_t *pr_fielddefs;
|
|
|
|
dstatement_t *pr_statements;
|
|
|
|
pr_type_t *pr_globals; // same as pr_global_struct
|
|
|
|
|
|
|
|
int pr_edict_size; // in bytes
|
2001-02-28 22:44:38 +00:00
|
|
|
int pr_edictareasize; // for bounds checking, starts at 0
|
2001-02-26 20:52:14 +00:00
|
|
|
|
|
|
|
int pr_argc;
|
|
|
|
|
|
|
|
qboolean pr_trace;
|
|
|
|
dfunction_t *pr_xfunction;
|
|
|
|
int pr_xstatement;
|
|
|
|
|
|
|
|
prstack_t pr_stack[MAX_STACK_DEPTH];
|
|
|
|
int pr_depth;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
int localstack[LOCALSTACK_SIZE];
|
|
|
|
int localstack_used;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
edict_t **edicts;
|
|
|
|
int *num_edicts;
|
2001-02-28 22:44:38 +00:00
|
|
|
int *reserved_edicts; //alloc will start at reserved_edicts+1
|
2001-02-26 20:52:14 +00:00
|
|
|
double *time;
|
|
|
|
int null_bad;
|
2001-06-06 18:10:47 +00:00
|
|
|
int no_exec_limit;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
unsigned short crc;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
void (*unlink)(edict_t *ent);
|
|
|
|
void (*flush)(void);
|
2001-02-28 09:12:01 +00:00
|
|
|
|
2001-07-15 07:04:17 +00:00
|
|
|
int (*parse_field)(progs_t *pr, const char *key, const char *value);
|
2001-03-27 22:39:21 +00:00
|
|
|
int (*prune_edict)(progs_t *pr, edict_t *ent);
|
2001-08-12 04:14:25 +00:00
|
|
|
void (*free_edict)(progs_t *pr, edict_t *ent);
|
2001-03-27 22:39:21 +00:00
|
|
|
|
|
|
|
builtin_t *builtins;
|
|
|
|
int numbuiltins;
|
|
|
|
|
2001-07-14 23:53:59 +00:00
|
|
|
// debug info
|
|
|
|
char *debugfile;
|
|
|
|
struct pr_debug_header_s *debug;
|
|
|
|
struct pr_auxfunction_s *auxfunctions;
|
2001-07-19 07:27:14 +00:00
|
|
|
struct pr_auxfunction_s **auxfunction_map;
|
2001-07-14 23:53:59 +00:00
|
|
|
struct pr_lineno_s *linenos;
|
|
|
|
ddef_t *local_defs;
|
|
|
|
|
2001-02-28 09:12:01 +00:00
|
|
|
// required globals
|
2001-03-01 08:34:30 +00:00
|
|
|
struct {
|
|
|
|
float *time;
|
|
|
|
int *self;
|
|
|
|
} globals;
|
2001-02-28 09:12:01 +00:00
|
|
|
// required fields (offsets into the edict)
|
2001-03-01 08:34:30 +00:00
|
|
|
struct {
|
|
|
|
int nextthink;
|
|
|
|
int frame;
|
|
|
|
int think;
|
|
|
|
} fields;
|
2001-02-26 20:52:14 +00:00
|
|
|
};
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-27 21:13:00 +00:00
|
|
|
#endif//__QF_progs_h
|