-
Notifications
You must be signed in to change notification settings - Fork 4
/
progs_h.pas
171 lines (139 loc) · 4.23 KB
/
progs_h.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// ------------------------------------------------------------------------------
// DelphiQuake, Copyright (C) 2005-2011 by Jim Valavanis
// E-Mail: [email protected]
//
// 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 the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// ------------------------------------------------------------------------------
{$I dquake.inc}
{$Z4}
unit progs_h;
interface
uses
q_delphi,
q_vector,
common,
pr_comp, // defs shared with qcc
progdefs, // generated by program cdefs
quakedef;
type
Peval_t = ^eval_t;
eval_t = record
case integer of
0: (_string: string_t);
1: (_float: single);
2: (vector: array[0..2] of single);
3: (func: func_t);
4: (_int: integer);
5: (edict: integer);
end;
const
MAX_ENT_LEAFS = 16;
type
Pedict_t = ^edict_t;
edict_t = record
free: qboolean;
area: link_t; // linked to a division node or leaf
num_leafs: integer;
leafnums: array[0..MAX_ENT_LEAFS - 1] of short;
baseline: entity_state_t;
freetime: single; // sv.time when the object was freed
v: entvars_t; // C exported fields from progs
// other fields from progs come immediately after
end;
function EDICT_FROM_AREA(l: Plink_t): Pedict_t;
function NEXT_EDICT(e: Pedict_t): Pedict_t;
function EDICT_TO_PROG(e: Pedict_t): integer;
function PROG_TO_EDICT(e: integer): Pedict_t;
function G_FLOAT(o: integer): Psingle;
function G_STRING(o: integer): PChar;
function G_INT(o: integer): PInteger;
function G_EDICT(o: integer): Pedict_t;
function E_STRING(e: Pedict_t; o: integer): PChar;
function EDICT_NUM(n: integer): Pedict_t;
function NUM_FOR_EDICT(e: Pedict_t): integer;
function G_EDICTNUM(o: integer): integer;
function G_VECTOR(o: integer): PVector3f;
type
builtin_t = procedure;
Pbuiltin_t = ^builtin_t;
implementation
uses
pr_edict,
sv_main,
sys_win;
function EDICT_FROM_AREA(l: Plink_t): Pedict_t; // JVAL SOS
begin
result := Pedict_t(integer(l) - integer(@Pedict_t(0).area));
end;
function NEXT_EDICT(e: Pedict_t): Pedict_t;
begin
result := Pedict_t(integer(e) + pr_edict_size);
end;
function EDICT_TO_PROG(e: Pedict_t): integer;
begin
result := integer(e) - integer(sv.edicts);
end;
function PROG_TO_EDICT(e: integer): Pedict_t;
begin
result := Pedict_t(integer(sv.edicts) + e);
end;
//============================================================================
function G_FLOAT(o: integer): Psingle;
begin
result := @pr_globals[o];
end;
function G_STRING(o: integer): PChar;
begin
result := @pr_strings[Pstring_t(@pr_globals[o])^];
end;
function G_INT(o: integer): PInteger;
begin
result := PInteger(@pr_globals[o]);
end;
function G_EDICT(o: integer): Pedict_t;
begin
result := Pedict_t(integer(sv.edicts) + PInteger(@pr_globals[o])^); // JVAL CHECK!
end;
function E_STRING(e: Pedict_t; o: integer): PChar;
begin
result := @pr_strings[PIntegerArray(@e.v)[o]]; // JVAL SOS
end;
//#define E_STRING(e,o) (pr_strings + *(string_t *)&((float*)&e->v)[o])
function EDICT_NUM(n: integer): Pedict_t;
begin
if (n < 0) or (n >= sv.max_edicts) then
Sys_Error('EDICT_NUM: bad number %d', [n]);
result := Pedict_t(integer(sv.edicts) + n * pr_edict_size);
end;
function NUM_FOR_EDICT(e: Pedict_t): integer;
begin
result := integer(e) - integer(sv.edicts);
result := result div pr_edict_size;
if (result < 0) or (result >= sv.num_edicts) then
Sys_Error('NUM_FOR_EDICT: bad pointer');
end;
function G_EDICTNUM(o: integer): integer;
begin
result := NUM_FOR_EDICT(G_EDICT(o))
end;
function G_VECTOR(o: integer): PVector3f;
begin
result := PVector3f(@pr_globals[o]);
end;
end.