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"
|
|
|
|
#include "QF/pr_comp.h"
|
2001-07-14 23:53:59 +00:00
|
|
|
#include "QF/pr_debug.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakeio.h"
|
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
|
|
|
|
2002-01-30 06:21:20 +00:00
|
|
|
#ifndef PR_RESOURCE_T
|
|
|
|
typedef struct pr_resource_s pr_resource_t;
|
|
|
|
#define PR_RESOURCE_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);
|
2002-10-22 15:07:54 +00:00
|
|
|
void PR_EnterFunction (progs_t * pr, dfunction_t *f);
|
2001-02-26 20:52:14 +00:00
|
|
|
void PR_ExecuteProgram (progs_t *pr, func_t fnum);
|
2002-08-27 07:16:28 +00:00
|
|
|
void PR_LoadProgsFile (progs_t * pr, QFile *file, int size, int edicts,
|
2002-01-29 20:53:44 +00:00
|
|
|
int zone);
|
|
|
|
void PR_LoadProgs (progs_t *pr, const char *progsname, int edicts, int zone);
|
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-11-02 22:41:11 +00:00
|
|
|
void PR_Check_Opcodes (progs_t *pr);
|
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-02-26 20:52:14 +00:00
|
|
|
void ED_Print (progs_t *pr, edict_t *ed);
|
2002-08-27 07:16:28 +00:00
|
|
|
void ED_Write (progs_t *pr, QFile *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
|
|
|
|
2002-08-27 07:16:28 +00:00
|
|
|
void ED_WriteGlobals (progs_t *pr, QFile *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);
|
2002-10-29 05:07:10 +00:00
|
|
|
qboolean PR_EdictValid (progs_t *pr, int 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)
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
#define G_UINT(p,o) G_var (p, o, uinteger)
|
2001-03-02 23:41:50 +00:00
|
|
|
#define G_VECTOR(p,o) G_var (p, o, vector)
|
2003-04-22 18:20:15 +00:00
|
|
|
#define G_STRING(p,o) G_var (p, o, string)
|
2001-02-28 22:44:38 +00:00
|
|
|
#define G_FUNCTION(p,o) G_var (p, o, func)
|
2003-04-22 18:20:15 +00:00
|
|
|
#define G_POINTER(p,o) G_var (p, o, pointer)
|
|
|
|
|
|
|
|
#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))
|
|
|
|
#define G_GSTRING(p,o) PR_GetString (p, G_STRING (p, o))
|
|
|
|
#define G_GPOINTER(p,o) PR_GetPointer (p, o)
|
|
|
|
#define G_STRUCT(p,t,o) (*(t *)G_GPOINTER (p, o))
|
|
|
|
|
2003-04-22 20:11:16 +00:00
|
|
|
#define P_var(p,n,t) ((p)->pr_params[n]->t##_var)
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2002-05-22 22:35:37 +00:00
|
|
|
#define P_FLOAT(p,n) P_var (p, n, float)
|
|
|
|
#define P_INT(p,n) P_var (p, n, integer)
|
|
|
|
#define P_UINT(p,n) P_var (p, n, uinteger)
|
|
|
|
#define P_VECTOR(p,n) P_var (p, n, vector)
|
2003-04-22 18:20:15 +00:00
|
|
|
#define P_STRING(p,n) P_var (p, n, string)
|
2002-05-22 22:35:37 +00:00
|
|
|
#define P_FUNCTION(p,n) P_var (p, n, func)
|
2003-04-22 18:20:15 +00:00
|
|
|
#define P_POINTER(p,n) P_var (p, n, pointer)
|
|
|
|
|
|
|
|
#define P_EDICT(p,n) ((edict_t *)(PR_edicts (p) + P_INT (p, n)))
|
|
|
|
#define P_EDICTNUM(p,n) NUM_FOR_EDICT (p, P_EDICT (p, n))
|
|
|
|
#define P_GSTRING(p,n) PR_GetString (p, P_STRING (p, n))
|
|
|
|
#define P_GPOINTER(p,n) PR_GetPointer (p, P_POINTER (p, n))
|
|
|
|
#define P_STRUCT(p,t,n) (*(t *)P_GPOINTER (p, n))
|
2002-05-22 22:35:37 +00:00
|
|
|
|
2003-04-22 20:11:16 +00:00
|
|
|
#define R_var(p,t) ((p)->pr_return->t##_var)
|
2003-04-22 18:20:15 +00:00
|
|
|
|
2002-05-22 22:35:37 +00:00
|
|
|
#define R_FLOAT(p) R_var (p, float)
|
|
|
|
#define R_INT(p) R_var (p, integer)
|
|
|
|
#define R_UINT(p) R_var (p, uinteger)
|
|
|
|
#define R_VECTOR(p) R_var (p, vector)
|
2003-04-22 18:20:15 +00:00
|
|
|
#define R_STRING(p) R_var (p, string)
|
2002-05-22 22:35:37 +00:00
|
|
|
#define R_FUNCTION(p) R_var (p, func)
|
2003-04-22 18:20:15 +00:00
|
|
|
#define R_POINTER(p) R_var (p, pointer)
|
2002-05-22 22:35:37 +00:00
|
|
|
|
2003-04-22 18:20:15 +00:00
|
|
|
#define RETURN_STRING(p, s) (R_STRING (p) = PR_SetString((p), s))
|
|
|
|
#define RETURN_EDICT(p, e) (R_STRING (p) = EDICT_TO_PROG(p, e))
|
|
|
|
#define RETURN_POINTER(pr,p) (R_POINTER (pr) = POINTER_TO_PROG (pr, p))
|
2002-05-22 22:35:37 +00:00
|
|
|
#define RETURN_VECTOR(p, v) (VectorCopy (v, R_VECTOR (p)))
|
2002-01-23 22:35:48 +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)
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
#define E_UINT(e,o) E_var (e, o, uinteger)
|
2001-03-01 18:44:19 +00:00
|
|
|
#define E_VECTOR(e,o) E_var (e, o, vector)
|
2003-04-22 18:20:15 +00:00
|
|
|
#define E_STRING(e,o) E_var (e, o, string)
|
|
|
|
#define E_FUNCTION(p) E_var (p, o, func)
|
|
|
|
#define E_POINTER(p) E_var (p, o, pointer)
|
|
|
|
|
|
|
|
#define E_GSTRING(p,e,o) (PR_GetString (p, E_STRING (e, o)))
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-03 06:40:28 +00:00
|
|
|
typedef void (*builtin_proc) (progs_t *pr);
|
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
builtin_proc proc;
|
2002-01-19 03:31:51 +00:00
|
|
|
int first_statement;
|
2001-08-03 06:40:28 +00:00
|
|
|
} 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);
|
|
|
|
|
2003-07-30 22:24:16 +00:00
|
|
|
const char *PR_GlobalString (progs_t *pr, int ofs, etype_t type);
|
|
|
|
const char *PR_GlobalStringNoContents (progs_t *pr, int ofs, etype_t type);
|
2001-02-26 20:52:14 +00:00
|
|
|
|
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-12-14 08:15:04 +00:00
|
|
|
builtin_t *PR_FindBuiltin (progs_t *pr, const char *name);
|
2002-01-18 19:19:33 +00:00
|
|
|
int PR_RelocateBuiltins (progs_t *pr);
|
2002-01-18 22:02:59 +00:00
|
|
|
int PR_ResolveGlobals (progs_t *pr);
|
2001-08-03 06:40:28 +00:00
|
|
|
|
2002-05-21 21:29:49 +00:00
|
|
|
//
|
|
|
|
// PR Obj stuff
|
|
|
|
//
|
|
|
|
void PR_Obj_Progs_Init (progs_t *pr);
|
|
|
|
void PR_InitRuntime (progs_t *pr);
|
|
|
|
|
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
|
|
|
//
|
|
|
|
|
2002-10-29 05:07:10 +00:00
|
|
|
qboolean PR_StringValid (progs_t *pr, int num);
|
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
|
|
|
|
2002-01-30 06:21:20 +00:00
|
|
|
//
|
|
|
|
// PR Resources stuff
|
|
|
|
//
|
|
|
|
|
2002-01-30 06:29:32 +00:00
|
|
|
void PR_Resources_Init (progs_t *pr);
|
2002-01-30 06:21:20 +00:00
|
|
|
void PR_Resources_Clear (progs_t *pr);
|
|
|
|
void PR_Resources_Register (progs_t *pr, const char *name, void *data,
|
|
|
|
void (*clear)(progs_t *, void *));
|
|
|
|
void *PR_Resources_Find (progs_t *pr, const char *name);
|
|
|
|
|
2002-01-29 20:53:44 +00:00
|
|
|
//
|
|
|
|
// PR Zone stuff
|
|
|
|
//
|
|
|
|
|
|
|
|
void PR_Zone_Init (progs_t *pr);
|
|
|
|
void PR_Zone_Free (progs_t *pr, void *ptr);
|
2002-01-30 08:09:53 +00:00
|
|
|
void *PR_Zone_Malloc (progs_t *pr, int size);
|
2002-05-29 20:58:53 +00:00
|
|
|
void *PR_Zone_Realloc (progs_t *pr, void *ptr, int size);
|
2002-01-29 20:53:44 +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);
|
2001-11-29 19:35:25 +00:00
|
|
|
unsigned int PR_Get_Lineno_Addr (progs_t *pr, pr_lineno_t *lineno);
|
|
|
|
unsigned int PR_Get_Lineno_Line (progs_t *pr, pr_lineno_t *lineno);
|
|
|
|
pr_lineno_t *PR_Find_Lineno (progs_t *pr, unsigned int addr);
|
2001-07-14 23:53:59 +00:00
|
|
|
const char *PR_Get_Source_File (progs_t *pr, pr_lineno_t *lineno);
|
2001-11-29 19:35:25 +00:00
|
|
|
const char *PR_Get_Source_Line (progs_t *pr, unsigned int 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;
|
2002-01-28 17:15:36 +00:00
|
|
|
extern struct cvar_s *pr_deadbeef_ents;
|
2001-10-28 04:23:37 +00:00
|
|
|
extern struct cvar_s *pr_deadbeef_locals;
|
|
|
|
extern struct cvar_s *pr_boundscheck;
|
2002-11-13 19:26:44 +00:00
|
|
|
extern struct cvar_s *pr_faultchecks;
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2002-01-20 03:09:03 +00:00
|
|
|
extern const char *pr_gametype;
|
|
|
|
|
2001-08-21 22:34:20 +00:00
|
|
|
//
|
|
|
|
// PR Cmds stuff
|
|
|
|
//
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
const char *PF_VarString (progs_t *pr, int first);
|
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
|
|
|
|
2002-01-23 22:35:48 +00:00
|
|
|
struct memzone_s *zone;
|
2002-01-29 20:53:44 +00:00
|
|
|
int zone_size;
|
2002-01-23 22:35:48 +00:00
|
|
|
|
2001-12-14 08:15:04 +00:00
|
|
|
struct hashtab_s *builtin_hash;
|
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;
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned 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
|
2002-01-29 20:53:44 +00:00
|
|
|
int globals_size;
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2003-04-22 20:11:16 +00:00
|
|
|
pr_type_t *pr_return;
|
|
|
|
pr_type_t *pr_params[MAX_PARMS];
|
|
|
|
int pr_param_size; // covers both params and return
|
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
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
|
|
|
|
2003-03-12 22:31:44 +00:00
|
|
|
void (*file_error)(progs_t *pr, const char *path);
|
2002-06-11 17:24:37 +00:00
|
|
|
void *(*load_file)(progs_t *pr, const char *path);
|
2002-01-29 20:53:44 +00:00
|
|
|
void *(*allocate_progs_mem)(progs_t *pr, int size);
|
2002-01-30 06:21:20 +00:00
|
|
|
void (*free_progs_mem)(progs_t *pr, void *mem);
|
2002-01-29 20:53:44 +00:00
|
|
|
|
2002-01-19 03:31:51 +00:00
|
|
|
builtin_t **builtins;
|
2001-03-27 22:39:21 +00:00
|
|
|
int numbuiltins;
|
|
|
|
|
2002-01-30 06:21:20 +00:00
|
|
|
pr_resource_t *resources;
|
|
|
|
struct hashtab_s *resource_hash;
|
|
|
|
|
2002-05-21 21:29:49 +00:00
|
|
|
// obj info
|
2003-08-23 22:16:42 +00:00
|
|
|
struct hashtab_s *selectors;
|
2002-05-21 21:29:49 +00:00
|
|
|
struct hashtab_s *classes;
|
|
|
|
struct hashtab_s *categories;
|
|
|
|
struct hashtab_s *protocols;
|
|
|
|
|
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;
|
2002-05-31 17:21:38 +00:00
|
|
|
int this;
|
2001-03-01 08:34:30 +00:00
|
|
|
} fields;
|
2001-02-26 20:52:14 +00:00
|
|
|
};
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-05-22 21:50:24 +00:00
|
|
|
static inline pr_type_t *
|
2003-04-22 18:20:15 +00:00
|
|
|
PR_GetPointer (progs_t *pr, int o)
|
2002-05-22 21:50:24 +00:00
|
|
|
{
|
|
|
|
return o ? pr->pr_globals + o : 0;
|
|
|
|
}
|
|
|
|
|
2002-05-22 22:35:37 +00:00
|
|
|
static inline pointer_t
|
|
|
|
POINTER_TO_PROG (progs_t *pr, void *p)
|
|
|
|
{
|
|
|
|
return p ? (pr_type_t *) p - pr->pr_globals : 0;
|
|
|
|
}
|
|
|
|
|
2001-08-27 21:13:00 +00:00
|
|
|
#endif//__QF_progs_h
|