Home | History | Annotate | Download | only in server
      1 /*
      2 Copyright (C) 1996-1997 Id Software, Inc.
      3 
      4 This program is free software; you can redistribute it and/or
      5 modify it under the terms of the GNU General Public License
      6 as published by the Free Software Foundation; either version 2
      7 of the License, or (at your option) any later version.
      8 
      9 This program is distributed in the hope that it will be useful,
     10 but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     12 
     13 See the GNU General Public License for more details.
     14 
     15 You should have received a copy of the GNU General Public License
     16 along with this program; if not, write to the Free Software
     17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     18 
     19 */
     20 
     21 #include "pr_comp.h"			// defs shared with qcc
     22 #include "progdefs.h"			// generated by program cdefs
     23 
     24 typedef union eval_s
     25 {
     26 	string_t		string;
     27 	float			_float;
     28 	float			vector[3];
     29 	func_t			function;
     30 	int				_int;
     31 	int				edict;
     32 } eval_t;
     33 
     34 #define	MAX_ENT_LEAFS	16
     35 typedef struct edict_s
     36 {
     37 	qboolean	free;
     38 	link_t		area;				// linked to a division node or leaf
     39 
     40 	int			num_leafs;
     41 	short		leafnums[MAX_ENT_LEAFS];
     42 
     43 	entity_state_t	baseline;
     44 
     45 	float		freetime;			// sv.time when the object was freed
     46 	entvars_t	v;					// C exported fields from progs
     47 // other fields from progs come immediately after
     48 } edict_t;
     49 #define	EDICT_FROM_AREA(l) STRUCT_FROM_LINK(l,edict_t,area)
     50 
     51 //============================================================================
     52 
     53 extern	dprograms_t		*progs;
     54 extern	dfunction_t		*pr_functions;
     55 extern	char			*pr_strings;
     56 extern	ddef_t			*pr_globaldefs;
     57 extern	ddef_t			*pr_fielddefs;
     58 extern	dstatement_t	*pr_statements;
     59 extern	globalvars_t	*pr_global_struct;
     60 extern	float			*pr_globals;			// same as pr_global_struct
     61 
     62 extern	int				pr_edict_size;	// in bytes
     63 
     64 //============================================================================
     65 
     66 void PR_Init (void);
     67 
     68 void PR_ExecuteProgram (func_t fnum);
     69 void PR_LoadProgs (void);
     70 
     71 void PR_Profile_f (void);
     72 
     73 edict_t *ED_Alloc (void);
     74 void ED_Free (edict_t *ed);
     75 
     76 char	*ED_NewString (char *string);
     77 // returns a copy of the string allocated from the server's string heap
     78 
     79 void ED_Print (edict_t *ed);
     80 void ED_Write (FILE *f, edict_t *ed);
     81 char *ED_ParseEdict (char *data, edict_t *ent);
     82 
     83 void ED_WriteGlobals (FILE *f);
     84 void ED_ParseGlobals (char *data);
     85 
     86 void ED_LoadFromFile (char *data);
     87 
     88 //define EDICT_NUM(n) ((edict_t *)(sv.edicts+ (n)*pr_edict_size))
     89 //define NUM_FOR_EDICT(e) (((byte *)(e) - sv.edicts)/pr_edict_size)
     90 
     91 edict_t *EDICT_NUM(int n);
     92 int NUM_FOR_EDICT(edict_t *e);
     93 
     94 #define	NEXT_EDICT(e) ((edict_t *)( (byte *)e + pr_edict_size))
     95 
     96 #define	EDICT_TO_PROG(e) ((byte *)e - (byte *)sv.edicts)
     97 #define PROG_TO_EDICT(e) ((edict_t *)((byte *)sv.edicts + e))
     98 
     99 //============================================================================
    100 
    101 #define	G_FLOAT(o) (pr_globals[o])
    102 #define	G_INT(o) (*(int *)&pr_globals[o])
    103 #define	G_EDICT(o) ((edict_t *)((byte *)sv.edicts+ *(int *)&pr_globals[o]))
    104 #define G_EDICTNUM(o) NUM_FOR_EDICT(G_EDICT(o))
    105 #define	G_VECTOR(o) (&pr_globals[o])
    106 #define	G_STRING(o) (PR_GetString(*(string_t *)&pr_globals[o]))
    107 #define	G_FUNCTION(o) (*(func_t *)&pr_globals[o])
    108 
    109 #define	E_FLOAT(e,o) (((float*)&e->v)[o])
    110 #define	E_INT(e,o) (*(int *)&((float*)&e->v)[o])
    111 #define	E_VECTOR(e,o) (&((float*)&e->v)[o])
    112 #define	E_STRING(e,o) (PR_GetString(*(string_t *)&((float*)&e->v)[o]))
    113 
    114 extern	int		type_size[8];
    115 
    116 typedef void (*builtin_t) (void);
    117 extern	builtin_t *pr_builtins;
    118 extern int pr_numbuiltins;
    119 
    120 extern int		pr_argc;
    121 
    122 extern	qboolean	pr_trace;
    123 extern	dfunction_t	*pr_xfunction;
    124 extern	int			pr_xstatement;
    125 
    126 extern func_t SpectatorConnect;
    127 extern func_t SpectatorThink;
    128 extern func_t SpectatorDisconnect;
    129 
    130 void PR_RunError (char *error, ...);
    131 
    132 void ED_PrintEdicts (void);
    133 void ED_PrintNum (int ent);
    134 
    135 eval_t *GetEdictFieldValue(edict_t *ed, char *field);
    136 
    137 //
    138 // PR STrings stuff
    139 //
    140 #define MAX_PRSTR 1024
    141 
    142 extern char *pr_strtbl[MAX_PRSTR];
    143 extern int num_prstr;
    144 
    145 char *PR_GetString(int num);
    146 int PR_SetString(char *s);
    147 
    148