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	256
35  //PENTA: increased this for dynamic lights, darn this is really big
36 						    //but for dynamic lights with large radiusses is is really needed
37 typedef struct edict_s
38 {
39 	qboolean	free;
40 	link_t		area;				// linked to a division node or leaf
41 
42 	int			num_leafs;
43 	short		leafnums[MAX_ENT_LEAFS];
44 
45 	entity_state_t	baseline;
46 
47 	float		freetime;			// sv.time when the object was freed
48 	entvars_t	v;					// C exported fields from progs
49 // other fields from progs come immediately after
50 } edict_t;
51 #define	EDICT_FROM_AREA(l) STRUCT_FROM_LINK(l,edict_t,area)
52 
53 extern int eval_color;
54 extern int eval_alpha;
55 extern int eval_pflags;
56 extern int eval_light_lev;
57 extern int eval_style;
58 
59 #define HACKY_GETFIELD(ed, fieldname, type, default) (fieldname ? (*((type*)((char*)&ed->v + fieldname))) : default)
60 
61 //============================================================================
62 
63 extern	dprograms_t		*progs;
64 extern	dfunction_t		*pr_functions;
65 extern	char			*pr_strings;
66 extern	ddef_t			*pr_globaldefs;
67 extern	ddef_t			*pr_fielddefs;
68 extern	dstatement_t	*pr_statements;
69 extern	globalvars_t	*pr_global_struct;
70 extern	float			*pr_globals;			// same as pr_global_struct
71 
72 extern	int				pr_edict_size;	// in bytes
73 
74 //============================================================================
75 
76 void PR_Init (void);
77 
78 void PR_ExecuteProgram (func_t fnum);
79 void PR_LoadProgs (void);
80 
81 void PR_Profile_f (void);
82 
83 edict_t *ED_Alloc (void);
84 void ED_Free (edict_t *ed);
85 
86 char	*ED_NewString (char *string);
87 // returns a copy of the string allocated from the server's string heap
88 
89 void ED_Print (edict_t *ed);
90 void ED_Write (FILE *f, edict_t *ed);
91 char *ED_ParseEdict (char *data, edict_t *ent);
92 
93 void ED_WriteGlobals (FILE *f);
94 void ED_ParseGlobals (char *data);
95 
96 void ED_LoadFromFile (char *data);
97 
98 //define EDICT_NUM(n) ((edict_t *)(sv.edicts+ (n)*pr_edict_size))
99 //define NUM_FOR_EDICT(e) (((byte *)(e) - sv.edicts)/pr_edict_size)
100 
101 edict_t *EDICT_NUM(int n);
102 int NUM_FOR_EDICT(edict_t *e);
103 
104 #define	NEXT_EDICT(e) ((edict_t *)( (byte *)e + pr_edict_size))
105 
106 #define	EDICT_TO_PROG(e) ((byte *)e - (byte *)sv.edicts)
107 #define PROG_TO_EDICT(e) ((edict_t *)((byte *)sv.edicts + e))
108 
109 //============================================================================
110 
111 #define	G_FLOAT(o) (pr_globals[o])
112 #define	G_INT(o) (*(int *)&pr_globals[o])
113 #define	G_EDICT(o) ((edict_t *)((byte *)sv.edicts+ *(int *)&pr_globals[o]))
114 #define G_EDICTNUM(o) NUM_FOR_EDICT(G_EDICT(o))
115 #define	G_VECTOR(o) (&pr_globals[o])
116 #define	G_STRING(o) (pr_strings + *(string_t *)&pr_globals[o])
117 #define	G_FUNCTION(o) (*(func_t *)&pr_globals[o])
118 
119 #define	E_FLOAT(e,o) (((float*)&e->v)[o])
120 #define	E_INT(e,o) (*(int *)&((float*)&e->v)[o])
121 #define	E_VECTOR(e,o) (&((float*)&e->v)[o])
122 #define	E_STRING(e,o) (pr_strings + *(string_t *)&((float*)&e->v)[o])
123 
124 extern	int		type_size[8];
125 
126 typedef void (*builtin_t) (void);
127 extern	builtin_t *pr_builtins;
128 extern int pr_numbuiltins;
129 
130 extern int		pr_argc;
131 
132 extern	qboolean	pr_trace;
133 extern	dfunction_t	*pr_xfunction;
134 extern	int			pr_xstatement;
135 
136 extern	unsigned short		pr_crc;
137 
138 void PR_RunError (char *error, ...);
139 
140 void ED_PrintEdicts (void);
141 void ED_PrintNum (int ent);
142 
143 eval_t *GetEdictFieldValue(edict_t *ed, char *field);
144 
145