DEADSOFTWARE

05cdffa4baecf6e00753e619c5413de0b60fb069
[d2df-sdl.git] / src / game / renders / opengl / r_map.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../../../shared/a_modes.inc}
16 unit r_map;
18 interface
20 uses g_base, g_player, g_playermodel; // TRectWH, TPlayer, TPlayerModel
22 procedure r_Map_Initialize;
23 procedure r_Map_Finalize;
25 procedure r_Map_Load;
26 procedure r_Map_Free;
28 procedure r_Map_LoadTextures;
29 procedure r_Map_FreeTextures;
31 {$IFDEF ENABLE_GFX}
32 procedure r_Map_NewGFX (typ, x, y: Integer);
33 {$ENDIF}
34 {$IFDEF ENABLE_GIBS}
35 function r_Map_GetGibSize (m, i: Integer): TRectWH;
36 {$ENDIF}
37 {$IFDEF ENABLE_MENU}
38 procedure r_Map_DrawPlayerModel (pm: TPlayerModel; x, y: Integer; alpha: Byte);
39 {$ENDIF}
41 procedure r_Map_Reset;
42 procedure r_Map_Update;
44 procedure r_Map_Draw (x, y, w, h, camx, camy: Integer; player: TPlayer; out acx, acy: Integer);
45 procedure r_Map_GetSpectatorLimits (out x0, y0, x1, y1: Integer);
47 implementation
49 uses
50 {$I ../../../nogl/noGLuses.inc}
51 Math, SysUtils,
52 e_log,
53 binheap, MAPDEF, utils,
54 g_options, g_animations, g_basic, g_phys,
55 g_game, g_map, g_panel, g_items, g_monsters, g_weapons,
56 g_console, g_language,
57 {$IFDEF ENABLE_CORPSES}
58 g_corpses,
59 {$ENDIF}
60 {$IFDEF ENABLE_SHELLS}
61 g_shells,
62 {$ENDIF}
63 {$IFDEF ENABLE_GIBS}
64 g_gibs,
65 {$ENDIF}
66 {$IFDEF ENABLE_GFX}
67 g_gfx,
68 {$ENDIF}
69 r_textures, r_draw, r_common
70 ;
72 const
73 MAXGIBW = 32;
74 MAXGIBH = 32;
76 MAXMONW = 256;
77 MAXMONH = 128;
78 MTABLE: array [0..MONSTER_MAN] of record
79 w, h: Integer;
80 end = (
81 (w: 64; h: 64), // NONE
82 (w: 64; h: 64), // DEMON
83 (w: 64; h: 64), // IMP
84 (w: 64; h: 64), // ZOMBY
85 (w: 64; h: 64), // SERG
86 (w: 128; h: 128), // CYBER
87 (w: 64; h: 64), // CGUN
88 (w: 128; h: 128), // BARON
89 (w: 128; h: 128), // KNIGHT
90 (w: 128; h: 128), // CACO
91 (w: 64; h: 64), // SOUL (DIE is 128x128, see load code)
92 (w: 128; h: 128), // PAIN
93 (w: 256; h: 128), // SPIDER
94 (w: 128; h: 64), // BSP
95 (w: 128; h: 128), // MANCUB
96 (w: 128; h: 128), // SKEL
97 (w: 128; h: 128), // VILE
98 (w: 32; h: 32), // FISH
99 (w: 64; h: 64), // BARREL
100 (w: 128; h: 128), // ROBO
101 (w: 64; h: 64) // MAN
102 );
103 VILEFIRE_DX = 32;
104 VILEFIRE_DY = 128;
106 MAXITEMW = 64;
107 MAXITEMH = 64;
108 ItemAnim: array [0..ITEM_LAST] of record
109 name: AnsiString;
110 w, h: Integer;
111 anim: TAnimInfo;
112 end = (
113 (name: 'NOTEXTURE'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
114 (name: 'MED1'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
115 (name: 'MED2'; w: 32; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
116 (name: 'BMED'; w: 32; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
117 (name: 'ARMORGREEN'; w: 32; h: 16; anim: (loop: true; delay: 20; frames: 3; back: true)),
118 (name: 'ARMORBLUE'; w: 32; h: 16; anim: (loop: true; delay: 20; frames: 3; back: true)),
119 (name: 'SBLUE'; w: 32; h: 32; anim: (loop: true; delay: 15; frames: 4; back: true)),
120 (name: 'SWHITE'; w: 32; h: 32; anim: (loop: true; delay: 20; frames: 4; back: true)),
121 (name: 'SUIT'; w: 32; h: 64; anim: (loop: true; delay: 1; frames: 1; back: false)),
122 (name: 'OXYGEN'; w: 16; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
123 (name: 'INVUL'; w: 32; h: 32; anim: (loop: true; delay: 20; frames: 4; back: true)),
124 (name: 'SAW'; w: 64; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
125 (name: 'SHOTGUN1'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
126 (name: 'SHOTGUN2'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
127 (name: 'MGUN'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
128 (name: 'RLAUNCHER'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
129 (name: 'PGUN'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
130 (name: 'BFG'; w: 64; h: 64; anim: (loop: true; delay: 1; frames: 1; back: false)),
131 (name: 'SPULEMET'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
132 (name: 'CLIP'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
133 (name: 'AMMO'; w: 32; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
134 (name: 'SHELL1'; w: 16; h: 8; anim: (loop: true; delay: 1; frames: 1; back: false)),
135 (name: 'SHELL2'; w: 32; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
136 (name: 'ROCKET'; w: 16; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
137 (name: 'ROCKETS'; w: 64; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
138 (name: 'CELL'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
139 (name: 'CELL2'; w: 32; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
140 (name: 'BPACK'; w: 32; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
141 (name: 'KEYR'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
142 (name: 'KEYG'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
143 (name: 'KEYB'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
144 (name: 'KASTET'; w: 64; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
145 (name: 'PISTOL'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
146 (name: 'BOTTLE'; w: 16; h: 32; anim: (loop: true; delay: 20; frames: 4; back: true)),
147 (name: 'HELMET'; w: 16; h: 16; anim: (loop: true; delay: 20; frames: 4; back: true)),
148 (name: 'JETPACK'; w: 32; h: 32; anim: (loop: true; delay: 15; frames: 3; back: true)),
149 (name: 'INVIS'; w: 32; h: 32; anim: (loop: true; delay: 20; frames: 4; back: true)),
150 (name: 'FLAMETHROWER'; w: 64; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
151 (name: 'FUELCAN'; w: 16; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false))
152 );
154 {$IFDEF ENABLE_GFX}
155 GFXAnim: array [0..R_GFX_LAST] of record
156 name: AnsiString;
157 w, h: Integer;
158 anim: TAnimInfo;
159 rdelay: Integer;
160 alpha: Integer;
161 end = (
162 (name: ''; w: 0; h: 0; anim: (loop: false; delay: 0; frames: 0; back: false); rdelay: 0; alpha: 0),
163 (name: 'TELEPORT'; w: 64; h: 64; anim: (loop: false; delay: 6; frames: 10; back: false); rdelay: 0; alpha: 0),
164 (name: 'FLAME'; w: 32; h: 32; anim: (loop: false; delay: 3; frames: 11; back: false); rdelay: 0; alpha: 0),
165 (name: 'EROCKET'; w: 128; h: 128; anim: (loop: false; delay: 6; frames: 6; back: false); rdelay: 0; alpha: 0),
166 (name: 'EBFG'; w: 128; h: 128; anim: (loop: false; delay: 6; frames: 6; back: false); rdelay: 0; alpha: 0),
167 (name: 'BFGHIT'; w: 64; h: 64; anim: (loop: false; delay: 4; frames: 4; back: false); rdelay: 0; alpha: 0),
168 (name: 'FIRE'; w: 64; h: 128; anim: (loop: false; delay: 4; frames: 8; back: false); rdelay: 2; alpha: 0),
169 (name: 'ITEMRESPAWN'; w: 32; h: 32; anim: (loop: false; delay: 4; frames: 5; back: true); rdelay: 0; alpha: 0),
170 (name: 'SMOKE'; w: 32; h: 32; anim: (loop: false; delay: 3; frames: 10; back: false); rdelay: 0; alpha: 0),
171 (name: 'ESKELFIRE'; w: 64; h: 64; anim: (loop: false; delay: 8; frames: 3; back: false); rdelay: 0; alpha: 0),
172 (name: 'EPLASMA'; w: 32; h: 32; anim: (loop: false; delay: 3; frames: 4; back: true); rdelay: 0; alpha: 0),
173 (name: 'EBSPFIRE'; w: 32; h: 32; anim: (loop: false; delay: 3; frames: 5; back: false); rdelay: 0; alpha: 0),
174 (name: 'EIMPFIRE'; w: 64; h: 64; anim: (loop: false; delay: 6; frames: 3; back: false); rdelay: 0; alpha: 0),
175 (name: 'ECACOFIRE'; w: 64; h: 64; anim: (loop: false; delay: 6; frames: 3; back: false); rdelay: 0; alpha: 0),
176 (name: 'EBARONFIRE'; w: 64; h: 64; anim: (loop: false; delay: 6; frames: 3; back: false); rdelay: 0; alpha: 0),
177 (name: 'TELEPORT'; w: 64; h: 64; anim: (loop: false; delay: 3; frames: 10; back: false); rdelay: 0; alpha: 0), // fast
178 (name: 'SMOKE'; w: 32; h: 32; anim: (loop: false; delay: 3; frames: 10; back: false); rdelay: 0; alpha: 150), // transparent
179 (name: 'FLAME'; w: 32; h: 32; anim: (loop: false; delay: 3; frames: 11; back: false); rdelay: 2; alpha: 0) // random
180 );
181 {$ENDIF}
183 ShotAnim: array [0..WEAPON_LAST] of record
184 name: AnsiString;
185 w, h: Integer;
186 anim: TAnimInfo;
187 end = (
188 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 0 KASTET
189 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 1 SAW
190 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 2 PISTOL
191 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 3 SHOTGUN1
192 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 4 SHOTGUN2
193 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 5 CHAINGUN
194 (name: 'BROCKET'; w: 64; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)), // 6 ROCKETLAUNCHER
195 (name: 'BPLASMA'; w: 16; h: 16; anim: (loop: true; delay: 5; frames: 2; back: false)), // 7 PLASMA
196 (name: 'BBFG'; w: 64; h: 64; anim: (loop: true; delay: 6; frames: 2; back: false)), // 8 BFG
197 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 9 SUPERPULEMET
198 (name: 'FLAME'; w: 32; h: 32; anim: (loop: true; delay: 6; frames: 0{11}; back: false)), // 10 FLAMETHROWER
199 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 11
200 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 12
201 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 13
202 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 14
203 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 15
204 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 16
205 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 17
206 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 18
207 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 19
208 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 20 ZOMPY_PISTOL
209 (name: 'BIMPFIRE'; w: 16; h: 16; anim: (loop: true; delay: 4; frames: 2; back: false)), // 21 IMP_FIRE
210 (name: 'BBSPFIRE'; w: 16; h: 16; anim: (loop: true; delay: 4; frames: 2; back: false)), // 22 BSP_FIRE
211 (name: 'BCACOFIRE'; w: 16; h: 16; anim: (loop: true; delay: 4; frames: 2; back: false)), // 23 CACO_FIRE
212 (name: 'BBARONFIRE'; w: 64; h: 16; anim: (loop: true; delay: 4; frames: 2; back: false)), // 24 BARON_FIRE
213 (name: 'BMANCUBFIRE'; w: 64; h: 32; anim: (loop: true; delay: 4; frames: 2; back: false)), // 25 MANCUB_FIRE
214 (name: 'BSKELFIRE'; w: 64; h: 64; anim: (loop: true; delay: 5; frames: 2; back: false)) // 26 SKEL_FIRE
215 );
217 {$IFDEF ENABLE_SHELLS}
218 ShellAnim: array [0..SHELL_LAST] of record
219 name: AnsiString;
220 dx, dy: Integer;
221 end = (
222 (name: 'EBULLET'; dx: 2; dy: 1), // 0 SHELL_BULLET
223 (name: 'ESHELL'; dx: 4; dy: 2), // 1 SHELL_SHELL
224 (name: 'ESHELL'; dx: 4; dy: 2) // 2 SHELL_DBLSHELL
225 );
226 {$ENDIF}
228 PunchAnim: TAnimInfo = (loop: false; delay: 1; frames: 4; back: false);
229 FlagAnim: TAnimInfo = (loop: true; delay: 8; frames: 5; back: false);
230 VileFireAnim: TAnimInfo = (loop: true; delay: 2; frames: 8; back: false);
232 type
233 TBinHeapPanelDrawCmp = class
234 public
235 class function less (const a, b: TPanel): Boolean; inline;
236 end;
238 TBinHeapPanelDraw = specialize TBinaryHeapBase<TPanel, TBinHeapPanelDrawCmp>;
240 TMonsterAnims = array [0..ANIM_LAST, TDirection] of TGLMultiTexture;
242 var
243 UseAccel: Boolean;
244 DebugFrames: Boolean;
245 DebugHealth: Boolean;
246 DebugCameraScale: Single;
247 FillOutsizeArea: Boolean;
248 SkyTexture: TGLTexture;
249 RenTextures: array of record
250 spec: LongInt;
251 tex: TGLMultiTexture;
252 anim: TAnimInfo;
253 end;
254 Items: array [0..ITEM_LAST] of record
255 tex: TGLMultiTexture;
256 frame: Integer;
257 end;
258 MonTextures: array [0..MONSTER_MAN] of TMonsterAnims;
259 WeapTextures: array [0..WP_LAST, 0..W_POS_LAST, 0..W_ACT_LAST] of TGLTexture;
260 ShotTextures: array [0..WEAPON_LAST] of TGLMultiTexture;
261 FlagTextures: array [0..FLAG_LAST] of TGLMultiTexture;
262 PunchTextures: array [Boolean, 0..2] of TGLMultiTexture; // [berserk, center/up/down]
263 VileFire: TGLMultiTexture;
264 InvulPenta: TGLTexture;
265 IndicatorTexture: TGLTexture;
266 TalkTexture: TGLTexture;
267 Models: array of record
268 anim: array [TDirection, 0..A_LAST] of record
269 base, mask: TGLMultiTexture;
270 end;
271 {$IFDEF ENABLE_GIBS}
272 gibs: record
273 base, mask: TGLTextureArray;
274 rect: TRectArray;
275 end;
276 {$ENDIF}
277 end;
279 {$IFDEF ENABLE_SHELLS}
280 ShellTextures: array [0..SHELL_LAST] of TGLTexture;
281 {$ENDIF}
282 {$IFDEF ENABLE_GFX}
283 GFXTextures: array [0..R_GFX_LAST] of TGLMultiTexture;
284 gfxlist: array of record
285 typ: Byte;
286 x, y: Integer;
287 oldX, oldY: Integer;
288 anim: TAnimInfo;
289 time: LongWord;
290 frame: LongInt;
291 end = nil;
292 {$ENDIF}
294 FlagFrame: LongInt;
295 plist: TBinHeapPanelDraw = nil;
297 class function TBinHeapPanelDrawCmp.less (const a, b: TPanel): Boolean; inline;
298 begin
299 if a.tag < b.tag then result := true
300 else if a.tag > b.tag then result := false
301 else result := a.arrIdx < b.arrIdx;
302 end;
304 procedure r_Map_Initialize;
305 begin
306 FlagFrame := 0;
307 plist := TBinHeapPanelDraw.Create();
308 end;
310 procedure r_Map_Finalize;
311 begin
312 r_Common_FreeAndNil(plist);
313 FlagFrame := 0;
314 end;
316 procedure r_Map_FreeModel (i: Integer);
317 var a: Integer; d: TDirection;
318 begin
319 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
320 begin
321 for a := A_STAND to A_LAST do
322 begin
323 r_Common_FreeAndNil(Models[i].anim[d, a].base);
324 r_Common_FreeAndNil(Models[i].anim[d, a].mask);
325 end;
326 end;
327 {$IFDEF ENABLE_GIBS}
328 if Models[i].gibs.base <> nil then
329 for a := 0 to High(Models[i].gibs.base) do
330 r_Common_FreeAndNil(Models[i].gibs.base[a]);
331 if Models[i].gibs.mask <> nil then
332 for a := 0 to High(Models[i].gibs.mask) do
333 r_Common_FreeAndNil(Models[i].gibs.mask[a]);
334 Models[i].gibs.base := nil;
335 Models[i].gibs.mask := nil;
336 Models[i].gibs.rect := nil;
337 {$ENDIF}
338 end;
340 procedure r_Map_LoadModel (i: Integer);
341 var prefix: AnsiString; a: Integer; d: TDirection; m: ^TPlayerModelInfo;
342 begin
343 ASSERT(i < Length(Models));
344 ASSERT(i < Length(PlayerModelsArray));
345 r_Map_FreeModel(i);
346 m := @PlayerModelsArray[i];
347 prefix := m.FileName + ':TEXTURES/';
348 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
349 begin
350 for a := A_STAND to A_LAST do
351 begin
352 Models[i].anim[d, a].base := nil;
353 Models[i].anim[d, a].mask := nil;
354 if m.anim[d, a].resource <> '' then
355 Models[i].anim[d, a].base := r_Textures_LoadMultiFromFileAndInfo(prefix + m.anim[d, a].resource, 64, 64, m.anim[d, a].frames, [TGLHints.txNoRepeat], true);
356 if m.anim[d, a].mask <> '' then
357 Models[i].anim[d, a].mask := r_Textures_LoadMultiFromFileAndInfo(prefix + m.anim[d, a].mask, 64, 64, m.anim[d, a].frames, [TGLHints.txNoRepeat], true);
358 end
359 end;
360 {$IFDEF ENABLE_GIBS}
361 Models[i].gibs.base := nil;
362 Models[i].gibs.mask := nil;
363 Models[i].gibs.rect := nil;
364 if m.GibsCount > 0 then
365 begin
366 SetLength(Models[i].gibs.base, m.GibsCount);
367 SetLength(Models[i].gibs.mask, m.GibsCount);
368 SetLength(Models[i].gibs.rect, m.GibsCount);
369 for a := 0 to m.GibsCount - 1 do
370 Models[i].gibs.rect[a] := DefaultGibSize;
371 if r_Textures_LoadStreamFromFile(prefix + m.GibsResource, 32, 32, m.GibsCount, m.GibsCount, Models[i].gibs.base, Models[i].gibs.rect, [TGLHints.txNoRepeat]) then
372 begin
373 if r_Textures_LoadStreamFromFile(prefix + m.GibsMask, 32, 32, m.GibsCount, m.GibsCount, Models[i].gibs.mask, nil, [TGLHints.txNoRepeat]) then
374 begin
375 // ok
376 end;
377 end;
378 end;
379 {$ENDIF}
380 end;
382 procedure r_Map_LoadMonsterAnim (m, a: Integer; d: TDirection);
383 const dir: array [TDirection] of AnsiString = ('_L', '');
384 var w, h, count: Integer;
385 begin
386 count := MONSTER_ANIMTABLE[m].AnimCount[a];
387 if count > 0 then
388 begin
389 w := MTABLE[m].w;
390 h := MTABLE[m].h;
391 if (m = MONSTER_SOUL) and (a = ANIM_DIE) then
392 begin
393 // special case
394 w := 128;
395 h := 128;
396 end;
397 MonTextures[m, a, d] := r_Textures_LoadMultiFromFileAndInfo(
398 GameWAD + ':MTEXTURES/' + MONSTERTABLE[m].name + '_' + ANIMTABLE[a].name + dir[d],
399 w,
400 h,
401 count,
402 [TGLHints.txNoRepeat],
403 False
404 );
405 end
406 else
407 MonTextures[m, a, d] := nil;
408 end;
410 procedure r_Map_Load;
411 const
412 WeapName: array [0..WP_LAST] of AnsiString = ('', 'CSAW', 'HGUN', 'SG', 'SSG', 'MGUN', 'RKT', 'PLZ', 'BFG', 'SPL', 'FLM');
413 WeapPos: array [0..W_POS_LAST] of AnsiString = ('', '_UP', '_DN');
414 WeapAct: array [0..W_ACT_LAST] of AnsiString = ('', '_FIRE');
415 PunchName: array [Boolean] of AnsiString = ('PUNCH', 'PUNCHB');
416 var
417 i, j, k: Integer; d: TDirection; b: Boolean;
418 begin
419 // --------- items --------- //
420 r_Common_SetLoading(_lc[I_LOAD_ITEMS_DATA], ITEM_LAST + 1);
421 for i := 0 to ITEM_LAST do
422 begin
423 Items[i].tex := r_Common_LoadTextureMultiFromFileAndInfo(
424 GameWAD + ':TEXTURES/' + ItemAnim[i].name,
425 ItemAnim[i].w,
426 ItemAnim[i].h,
427 ItemAnim[i].anim.frames,
428 [TGLHints.txNoRepeat],
429 false
430 );
431 Items[i].frame := 0;
432 end;
433 // --------- monsters --------- //
434 r_Common_SetLoading(_lc[I_LOAD_MONSTER_TEXTURES], MONSTER_MAN - MONSTER_DEMON + 1);
435 for i := MONSTER_DEMON to MONSTER_MAN do
436 begin
437 for j := 0 to ANIM_LAST do
438 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
439 r_Map_LoadMonsterAnim(i, j, d);
440 r_Common_StepLoading(1);
441 end;
442 VileFire := r_Textures_LoadMultiFromFileAndInfo(GameWAD + ':TEXTURES/FIRE', 64, 128, VileFireAnim.frames, [TGLHints.txNoRepeat]);
443 // --------- player models --------- //
444 if PlayerModelsArray <> nil then
445 begin
446 r_Common_SetLoading(_lc[I_LOAD_MODELS], Length(PlayerModelsArray));
447 SetLength(Models, Length(PlayerModelsArray));
448 for i := 0 to High(PlayerModelsArray) do
449 begin
450 r_Map_LoadModel(i);
451 r_Common_StepLoading(1);
452 end;
453 end;
454 // --------- player weapons --------- //
455 r_Common_SetLoading(_lc[I_LOAD_WEAPONS_DATA], WP_LAST);
456 for i := 1 to WP_LAST do
457 begin
458 for j := 0 to W_POS_LAST do
459 for k := 0 to W_ACT_LAST do
460 WeapTextures[i, j, k] := r_Textures_LoadFromFile(GameWAD + ':WEAPONS\' + WeapName[i] + WeapPos[j] + WeapAct[k], [TGLHints.txNoRepeat]);
461 r_Common_StepLoading(1);
462 end;
463 // --------- gfx animations --------- //
464 {$IFDEF ENABLE_GFX}
465 r_Common_SetLoading('GFX Effects', R_GFX_LAST);
466 for i := 1 to R_GFX_LAST do
467 begin
468 if GFXAnim[i].anim.frames > 0 then
469 GFXTextures[i] := r_Common_LoadTextureMultiFromFileAndInfo(GameWad + ':TEXTURES/' + GFXAnim[i].name, GFXAnim[i].w, GFXAnim[i].h, GFXAnim[i].anim.frames, [TGLHints.txNoRepeat]);
470 end;
471 {$ENDIF}
472 // --------- shots --------- //
473 r_Common_SetLoading('Weapon splahses', WEAPON_LAST + 1);
474 for i := 0 to WEAPON_LAST do
475 begin
476 if ShotAnim[i].anim.frames > 0 then
477 ShotTextures[i] := r_Common_LoadTextureMultiFromFileAndInfo(GameWad + ':TEXTURES/' + ShotAnim[i].name, ShotAnim[i].w, ShotAnim[i].h, ShotAnim[i].anim.frames, [TGLHints.txNoRepeat]);
478 end;
479 // --------- flags --------- //
480 r_Common_SetLoading('Flags', 2);
481 FlagTextures[FLAG_NONE] := nil;
482 FlagTextures[FLAG_RED] := r_Common_LoadTextureMultiFromFileAndInfo(GameWad + ':TEXTURES/FLAGRED', 64, 64, 5, [TGLHints.txNoRepeat]);
483 FlagTextures[FLAG_BLUE] := r_Common_LoadTextureMultiFromFileAndInfo(GameWad + ':TEXTURES/FLAGBLUE', 64, 64, 5, [TGLHints.txNoRepeat]);
484 // FlagTextures[FLAG_DOM] := r_Common_LoadTextureMultiFromFileAndInfo(GameWad + ':TEXTURES/FLAGDOM', 64, 64, 8, [TGLHints.txNoRepeat]);
485 // --------- shells --------- //
486 {$IFDEF ENABLE_SHELLS}
487 r_Common_SetLoading('Shells', SHELL_LAST + 1);
488 for i := 0 to SHELL_LAST do
489 ShellTextures[i] := r_Common_LoadTextureFromFile(GameWad + ':TEXTURES/' + ShellAnim[i].name, [TGLHints.txNoRepeat]);
490 {$ENDIF}
491 // --------- other --------- //
492 r_Common_SetLoading('Effects', 3 * 2 + 3);
493 for b := false to true do
494 begin
495 for i := 0 to 2 do
496 PunchTextures[b, i] := r_Common_LoadTextureMultiFromFileAndInfo(GameWad + ':WEAPONS/' + PunchName[b] + WeapPos[i], 64, 64, PunchAnim.frames, [TGLHints.txNoRepeat]);
497 end;
498 InvulPenta := r_Common_LoadTextureFromFile(GameWad + ':TEXTURES/PENTA', [TGLHints.txNoRepeat]);
499 IndicatorTexture := r_Common_LoadTextureFromFile(GameWad + ':TEXTURES/PLRIND', [TGLHints.txNoRepeat]);
500 TalkTexture := r_Common_LoadTextureFromFile(GameWad + ':TEXTURES/TALKBUBBLE', [TGLHints.txNoRepeat]);
501 end;
503 procedure r_Map_Free;
504 var i, j, k: Integer; d: TDirection; b: Boolean;
505 begin
506 r_Common_FreeAndNil(TalkTexture);
507 r_Common_FreeAndNil(IndicatorTexture);
508 r_Common_FreeAndNil(InvulPenta);
509 for b := false to true do
510 for i := 0 to 2 do
511 r_Common_FreeAndNil(PunchTextures[b, i]);
512 {$IFDEF ENABLE_SHELLS}
513 for i := 0 to SHELL_LAST do
514 r_Common_FreeAndNil(ShellTextures[i]);
515 {$ENDIF}
516 for i := 0 to FLAG_LAST do
517 r_Common_FreeAndNil(FlagTextures[i]);
518 for i := 0 to WEAPON_LAST do
519 r_Common_FreeAndNil(ShotTextures[i]);
520 {$IFDEF ENABLE_GFX}
521 SetLength(gfxlist, 0);
522 for i := 0 to R_GFX_LAST do
523 r_Common_FreeAndNil(GFXTextures[i]);
524 {$ENDIF}
525 for i := 1 to WP_LAST do
526 for j := 0 to W_POS_LAST do
527 for k := 0 to W_ACT_LAST do
528 r_Common_FreeAndNil(WeapTextures[i, j, k]);
529 if Models <> nil then
530 for i := 0 to High(Models) do
531 r_Map_FreeModel(i);
532 for i := MONSTER_DEMON to MONSTER_MAN do
533 for j := 0 to ANIM_LAST do
534 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
535 r_Common_FreeAndNil(MonTextures[i, j, d]);
536 for i := 0 to ITEM_LAST do
537 r_Common_FreeAndNil(Items[i].tex);
538 end;
540 procedure r_Map_FreeTextures;
541 var i: Integer;
542 begin
543 plist.Clear;
544 r_Common_FreeAndNil(SkyTexture);
545 if RenTextures <> nil then
546 for i := 0 to High(RenTextures) do
547 r_Common_FreeAndNil(RenTextures[i].tex);
548 SetLength(RenTextures, 0);
549 end;
551 procedure r_Map_LoadTextures;
552 const DefaultAnimInfo: TAnimInfo = (loop: true; delay: 1; frames: 1; back: false);
553 var i, n: Integer; txt: TAnimTextInfo;
554 begin
555 r_Map_FreeTextures;
556 if Textures <> nil then
557 begin
558 n := Length(Textures);
559 SetLength(RenTextures, n);
560 r_Common_SetLoading(_lc[I_LOAD_TEXTURES], n);
561 for i := 0 to n - 1 do
562 begin
563 RenTextures[i].tex := nil;
564 RenTextures[i].anim := DefaultAnimInfo;
565 case Textures[i].TextureName of
566 TEXTURE_NAME_WATER: RenTextures[i].spec := TEXTURE_SPECIAL_WATER;
567 TEXTURE_NAME_ACID1: RenTextures[i].spec := TEXTURE_SPECIAL_ACID1;
568 TEXTURE_NAME_ACID2: RenTextures[i].spec := TEXTURE_SPECIAL_ACID2;
569 else
570 RenTextures[i].spec := 0;
571 RenTextures[i].tex := r_Textures_LoadMultiTextFromFile(Textures[i].FullName, txt, []);
572 if RenTextures[i].tex <> nil then
573 begin
574 RenTextures[i].anim := txt.anim;
575 r_Common_StepLoading(1);
576 end
577 else
578 begin
579 e_LogWritefln('r_Map_LoadTextures: failed to load texture: %s', [Textures[i].FullName]);
580 end;
581 end;
582 ASSERT(RenTextures[i].anim.frames > 0);
583 ASSERT(RenTextures[i].anim.delay > 0);
584 end;
585 end;
586 if gMapInfo.SkyFullName <> '' then
587 begin
588 r_Common_SetLoading(_lc[I_LOAD_SKY], 1);
589 SkyTexture := r_Common_LoadTextureFromFile(gMapInfo.SkyFullName, [TGLHints.txNoRepeat]);
590 end;
591 plist.Clear;
592 end;
594 procedure r_Map_DrawPanel (p: TPanel);
595 var Texture, x, y, w, h: Integer; t: TGLMultiTexture; count, frame: LongInt; a: TAnimInfo;
596 begin
597 ASSERT(p <> nil);
598 ASSERT(p.FCurTexture >= -1); (* p.FCurTexture = -1 -> invisible texture *)
599 if p.FCurTexture >= 0 then
600 begin
601 r_Common_GetPanelPos(p, x, y, w, h);
602 ASSERT(p.FCurTexture <= High(p.TextureIDs));
603 Texture := p.TextureIDs[p.FCurTexture].Texture;
604 ASSERT(Texture >= -1); (* Texture = -1 -> texture not found *)
605 if Texture >= 0 then
606 begin
607 ASSERT(Texture <= High(RenTextures));
608 t := RenTextures[Texture].tex;
609 if t <> nil then
610 begin
611 count := 0; frame := 0;
612 if p.AnimTime <= gTime then
613 begin
614 a := RenTextures[Texture].anim;
615 a.loop := p.AnimLoop;
616 g_Anim_GetFrameByTime(a, (gTime - p.AnimTime) DIV GAME_TICK, count, frame);
617 end;
618 r_Draw_TextureRepeat(t.GetTexture(frame), x, y, w, h, false, 255, 255, 255, 255 - p.alpha, p.blending);
619 end
620 else if RenTextures[Texture].spec = 0 then
621 begin
622 r_Draw_TextureRepeat(nil, x, y, w, h, false, 255, 255, 255, 255, false);
623 end;
624 case RenTextures[Texture].spec of
625 TEXTURE_SPECIAL_WATER: r_Draw_Filter(x, y, x + w, y + h, 0, 0, 255, 255);
626 TEXTURE_SPECIAL_ACID1: r_Draw_Filter(x, y, x + w, y + h, 0, 230, 0, 255);
627 TEXTURE_SPECIAL_ACID2: r_Draw_Filter(x, y, x + w, y + h, 230, 0, 0, 255);
628 end;
629 end
630 else
631 begin
632 r_Draw_TextureRepeat(nil, x, y, w, h, false, 255, 255, 255, 255, false);
633 end;
634 end;
635 end;
637 procedure r_Map_DrawPanels (constref panels: TPanelArray; drawDoors: Boolean = false);
638 var i: Integer; p: TPanel;
639 begin
640 if panels <> nil then
641 begin
642 for i := 0 to High(panels) do
643 begin
644 p := panels[i];
645 if p.enabled and not (drawDoors xor p.door) then
646 r_Map_DrawPanel(p);
647 end;
648 end;
649 end;
651 procedure r_Map_DrawPanelType (panelTyp: DWORD);
652 var tagMask: Integer; p: TPanel;
653 begin
654 if UseAccel then
655 begin
656 tagMask := PanelTypeToTag(panelTyp);
657 while plist.count > 0 do
658 begin
659 p := TPanel(plist.Front());
660 if (p.tag and tagMask) = 0 then
661 break;
662 r_Map_DrawPanel(p);
663 plist.PopFront;
664 end;
665 end
666 else
667 begin
668 case panelTyp of
669 PANEL_BACK: if g_rlayer_back then r_Map_DrawPanels(gRenderBackgrounds);
670 PANEL_STEP: if g_rlayer_step then r_Map_DrawPanels(gSteps);
671 PANEL_WALL: if g_rlayer_wall then r_Map_DrawPanels(gWalls);
672 PANEL_CLOSEDOOR: if g_rlayer_door then r_Map_DrawPanels(gWalls, True);
673 PANEL_ACID1: if g_rlayer_acid1 then r_Map_DrawPanels(gAcid1);
674 PANEL_ACID2: if g_rlayer_acid2 then r_Map_DrawPanels(gAcid2);
675 PANEL_WATER: if g_rlayer_water then r_Map_DrawPanels(gWater);
676 PANEL_FORE: if g_rlayer_fore then r_Map_DrawPanels(gRenderForegrounds);
677 end;
678 end;
679 end;
681 procedure r_Map_DrawItems (x, y, w, h: Integer; drop: Boolean);
682 var i, xx, yy: Integer; it: PItem; t: TGLMultiTexture; tex: TGLTexture;
683 begin
684 if ggItems <> nil then
685 begin
686 (* hack: prevent visual disappearance *)
687 x := x - MAXITEMW;
688 y := y - MAXITEMH;
689 w := w + MAXITEMW*2;
690 h := h + MAXITEMH*2;
691 for i := 0 to High(ggItems) do
692 begin
693 it := @ggItems[i];
694 if it.used and it.alive and (it.dropped = drop) and (it.ItemType > ITEM_NONE) and (it.ItemType <= ITEM_LAST) then
695 begin
696 r_Common_GetObjectPos(it.obj, xx, yy);
697 if g_Collide(xx + it.obj.rect.x, yy + it.obj.rect.y, it.obj.rect.width, it.obj.rect.height, x, y, w, h) then
698 begin
699 t := Items[it.ItemType].tex;
700 tex := t.GetTexture(Items[it.ItemType].frame);
701 r_Draw_TextureRepeat(tex, xx, yy, tex.width, tex.height, false, 255, 255, 255, 255, false);
702 if DebugFrames then
703 begin
704 r_Draw_Rect(
705 xx + it.obj.rect.x, // it.obj.x + it.obj.rect.x,
706 yy + it.obj.rect.y, // it.obj.y + it.obj.rect.y,
707 xx + it.obj.rect.x + it.obj.rect.width, // it.obj.x + it.obj.rect.x + it.obj.rect.width,
708 yy + it.obj.rect.y + it.obj.rect.height, // it.obj.y + it.obj.rect.y + it.obj.rect.height,
709 0, 255, 0, 255
710 );
711 end;
712 end;
713 end;
714 end;
715 end;
716 end;
718 function r_Map_GetMonsterTexture (m, a: Integer; d: TDirection; out t: TGLMultiTexture; out dx, dy: Integer; out flip: Boolean): Boolean;
719 var w: Integer;
720 begin
721 t := nil; dx := 0; dy := 0; flip := false;
722 result := MonTextures[m, a, d] <> nil;
723 if result = false then
724 begin
725 flip := true;
726 if d = TDirection.D_RIGHT then d := TDirection.D_LEFT else d := TDirection.D_RIGHT;
727 result := MonTextures[m, a, d] <> nil;
728 end;
729 if result = true then
730 begin
731 t := MonTextures[m, a, d];
732 if d = TDirection.D_LEFT then
733 begin
734 dx := MONSTER_ANIMTABLE[m].AnimDeltaLeft[a].X;
735 dy := MONSTER_ANIMTABLE[m].AnimDeltaLeft[a].Y;
736 end
737 else
738 begin
739 dx := MONSTER_ANIMTABLE[m].AnimDeltaRight[a].X;
740 dy := MONSTER_ANIMTABLE[m].AnimDeltaRight[a].Y;
741 end;
742 if flip then
743 begin
744 if (m = MONSTER_SOUL) and (a = ANIM_DIE) then w := 64 else w := 0;
745 dx := -dx - w;
746 end;
747 end;
748 end;
750 procedure r_Map_DrawMonsterAttack (constref mon: TMonster);
751 var o: TObj; count, frame, xx, yy: LongInt; tex: TGLTexture;
752 begin
753 if VileFire <> nil then
754 begin
755 if (mon.MonsterType = MONSTER_VILE) and (mon.MonsterState = MONSTATE_SHOOT) and (mon.VileFireTime <= gTime) then
756 begin
757 if r_Common_GetPosByUID(mon.MonsterTargetUID, o, xx, yy) then
758 begin
759 g_Anim_GetFrameByTime(VileFireAnim, (gTime - mon.VileFireTime) DIV GAME_TICK, count, frame);
760 tex := VileFire.GetTexture(frame);
761 r_Draw_TextureRepeat(tex, xx + o.rect.x + (o.rect.width div 2) - VILEFIRE_DX, yy + o.rect.y + o.rect.height - VILEFIRE_DY, tex.width, tex.height, False, 255, 255, 255, 255, false);
762 end;
763 end;
764 end;
765 end;
767 procedure r_Map_DrawMonster (constref mon: TMonster);
768 var m, a, xx, yy, dx, dy: Integer; d, da: TDirection; flip: Boolean; t: TGLMultiTexture;
769 begin
770 m := mon.MonsterType;
771 a := mon.MonsterAnim;
772 d := mon.GameDirection;
774 (* hack: barrel tracks player, fix it in game logic *)
775 if m = MONSTER_BARREL then d := TDirection.D_LEFT;
777 r_Common_GetObjectPos(mon.obj, xx, yy);
778 if r_Map_GetMonsterTexture(m, a, d, t, dx, dy, flip) then
779 begin
780 da := mon.GameDirection;
781 r_Draw_MultiTextureRepeat(t, mon.DirAnim[a, da], false, xx + dx, yy + dy, t.width, t.height, flip, 255, 255, 255, 255, false);
782 end;
783 if DebugFrames then
784 begin
785 r_Draw_Rect(
786 xx + mon.obj.rect.x, // mon.obj.x + mon.obj.rect.x,
787 yy + mon.obj.rect.y, // mon.obj.y + mon.obj.rect.y,
788 xx + mon.obj.rect.x + mon.obj.rect.width, // mon.obj.x + mon.obj.rect.x + mon.obj.rect.width,
789 yy + mon.obj.rect.y + mon.obj.rect.height, // mon.obj.y + mon.obj.rect.y + mon.obj.rect.height,
790 0, 255, 0, 255
791 );
792 end;
793 if DebugHealth and mon.alive then
794 begin
795 r_Common_DrawText(
796 IntToStr(mon.MonsterHealth),
797 xx + mon.obj.rect.x + mon.obj.rect.width div 2,
798 yy + mon.obj.rect.y,
799 255, 255, 255, 255,
800 stdfont,
801 TBasePoint.BP_DOWN
802 );
803 end;
804 end;
806 procedure r_Map_DrawMonsters (x, y, w, h: Integer);
807 var i: Integer; m: TMonster;
808 begin
809 if gMonsters <> nil then
810 begin
811 (* hack: prevent visual disappearance *)
812 x := x - MAXMONW;
813 y := y - MAXMONH;
814 w := w + MAXMONW*2;
815 h := h + MAXMONH*2;
816 for i := 0 to High(gMonsters) do
817 begin
818 m := gMonsters[i];
819 if m <> nil then
820 begin
821 r_Map_DrawMonsterAttack(m);
822 // TODO select from grid
823 if g_Collide(m.obj.x + m.obj.rect.x, m.obj.y + m.obj.rect.y, m.obj.rect.width, m.obj.rect.height, x, y, w, h) then
824 r_Map_DrawMonster(m);
825 end;
826 end;
827 end;
828 end;
830 function r_Map_GetPlayerModelTex (i: Integer; var a: Integer; var d: TDirection; out flip: Boolean): Boolean;
831 begin
832 flip := false;
833 result := Models[i].anim[d, a].base <> nil;
834 if result = false then
835 begin
836 flip := true;
837 if d = TDirection.D_LEFT then d := TDirection.D_RIGHT else d := TDirection.D_LEFT;
838 result := Models[i].anim[d, a].base <> nil;
839 end;
840 end;
842 procedure r_Map_DrawPlayerModel (pm: TPlayerModel; x, y: Integer; alpha: Byte);
843 var a, pos, act, xx, yy, angle: Integer; d: TDirection; flip, back: Boolean; t: TGLMultiTexture; tex: TGLTexture; c: TRGB;
844 begin
845 a := pm.CurrentAnimation;
846 d := pm.Direction;
848 (* draw flag*)
849 t := FlagTextures[pm.Flag];
850 if (t <> nil) and not (a in [A_DIE1, A_DIE2]) then
851 begin
852 flip := d = TDirection.D_RIGHT;
853 angle := PlayerModelsArray[pm.id].FlagAngle;
854 xx := PlayerModelsArray[pm.id].FlagPoint.X;
855 yy := PlayerModelsArray[pm.id].FlagPoint.Y;
856 tex := t.GetTexture(FlagFrame);
857 r_Draw_TextureRepeatRotate(
858 tex,
859 x + IfThen(flip, 2 * FLAG_BASEPOINT.X - xx + 1, xx - 1) - FLAG_BASEPOINT.X,
860 y + yy - FLAG_BASEPOINT.Y + 1,
861 tex.width,
862 tex.height,
863 flip,
864 255, 255, 255, 255, false,
865 IfThen(flip, 64 - FLAG_BASEPOINT.X, FLAG_BASEPOINT.X),
866 FLAG_BASEPOINT.Y,
867 IfThen(flip, angle, -angle)
868 );
869 end;
871 (* draw weapon *)
872 if PlayerModelsArray[pm.id].HaveWeapon and not (a in [A_DIE1, A_DIE2, A_PAIN]) then
873 begin
874 case a of
875 A_SEEUP, A_ATTACKUP: pos := W_POS_UP;
876 A_SEEDOWN, A_ATTACKDOWN: pos := W_POS_DOWN;
877 else pos := W_POS_NORMAL;
878 end;
879 if (a in [A_ATTACK, A_ATTACKUP, A_ATTACKDOWN]) or pm.GetFire() then
880 act := W_ACT_FIRE
881 else
882 act := W_ACT_NORMAL;
883 tex := WeapTextures[pm.CurrentWeapon, pos, act];
884 if tex <> nil then
885 begin
886 xx := PlayerModelsArray[pm.id].WeaponPoints[pm.CurrentWeapon, a, d, pm.AnimState.CurrentFrame].X;
887 yy := PlayerModelsArray[pm.id].WeaponPoints[pm.CurrentWeapon, a, d, pm.AnimState.CurrentFrame].Y;
888 r_Draw_Texture(
889 tex,
890 x + xx,
891 y + yy,
892 tex.width,
893 tex.height,
894 d = TDirection.D_LEFT,
895 255, 255, 255, alpha, false
896 );
897 end;
898 end;
900 (* draw body *)
901 if r_Map_GetPlayerModelTex(pm.id, a, d, flip) then
902 begin
903 t := Models[pm.id].anim[d, a].base;
904 back := PlayerModelsArray[pm.id].anim[d, a].back;
905 r_Draw_MultiTextureRepeat(t, pm.AnimState, back, x, y, t.width, t.height, flip, 255, 255, 255, alpha, false);
906 t := Models[pm.id].anim[d, a].mask;
907 if t <> nil then
908 begin
909 c := pm.Color;
910 r_Draw_MultiTextureRepeat(t, pm.AnimState, back, x, y, t.width, t.height, flip, c.r, c.g, c.b, alpha, false);
911 end;
912 end;
913 end;
915 procedure r_Map_DrawBubble (x, y: Integer; cb, cf: TRGB);
916 const w = 20; h = 14;
917 const dx = 6; dy = 8; dot = 6; size = 2;
918 const tx = 6; ty = h - 1;
919 begin
920 // Outer box (top/down)
921 r_Draw_FillRect(x + 1, y, x + w - 1, y + 1, cb.R, cb.G, cb.B, 255);
922 r_Draw_FillRect(x + 1, y + h - 1, x + w - 1, y + h, cb.R, cb.G, cb.B, 255);
923 // Outer box (left/right)
924 r_Draw_FillRect(x, y + 1, x + 1, y + h - 1, cb.R, cb.G, cb.B, 255);
925 r_Draw_FillRect(x + w - 1, y + 1, x + w, y + h - 1, cb.R, cb.G, cb.B, 255);
926 // Outer tail
927 r_Draw_FillRect(x + tx - 1, y + ty + 0, x + tx + 3 + 1, y + ty + 1, cb.R, cb.G, cb.B, 255);
928 r_Draw_FillRect(x + tx - 1, y + ty + 1, x + tx + 2 + 1, y + ty + 2, cb.R, cb.G, cb.B, 255);
929 r_Draw_FillRect(x + tx - 1, y + ty + 2, x + tx + 1 + 1, y + ty + 3, cb.R, cb.G, cb.B, 255);
930 r_Draw_FillRect(x + tx - 1, y + ty + 3, x + tx + 0 + 1, y + ty + 4, cb.R, cb.G, cb.B, 255);
931 // Inner tail
932 r_Draw_FillRect(x + tx, y + ty + 0, x + tx + 3, y + ty + 1, cf.R, cf.G, cf.B, 255);
933 r_Draw_FillRect(x + tx, y + ty + 1, x + tx + 2, y + ty + 2, cf.R, cf.G, cf.B, 255);
934 r_Draw_FillRect(x + tx, y + ty + 2, x + tx + 1, y + ty + 3, cf.R, cf.G, cf.B, 255);
935 // Inner box
936 r_Draw_FillRect(x + 1, y + 1, x + w - 1, y + h - 1, cf.R, cf.G, cf.B, 255);
937 // Dots
938 r_Draw_FillRect(x + dx + 0*3, y + dy, x + dx + 0*3 + size, y + dy + size, cb.R, cb.G, cb.B, 255);
939 r_Draw_FillRect(x + dx + 1*3, y + dy, x + dx + 1*3 + size, y + dy + size, cb.R, cb.G, cb.B, 255);
940 r_Draw_FillRect(x + dx + 2*3, y + dy, x + dx + 2*3 + size, y + dy + size, cb.R, cb.G, cb.B, 255);
941 end;
943 procedure r_Map_DrawTalkBubble (p: TPlayer);
944 var xx, yy, x, y: Integer; cb, cf: TRGB;
945 begin
946 r_Common_GetPlayerPos(p, xx, yy);
947 x := xx + p.obj.rect.x + p.obj.rect.width div 2;
948 y := yy;
949 cb := _RGB(63, 63, 63);
950 cf := _RGB(240, 240, 240);
951 case gChatBubble of
952 1: // simple text
953 begin
954 r_Common_DrawText('[...]', x, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
955 end;
956 2: // adv team color
957 begin
958 case p.Team of
959 TEAM_RED: cb := _RGB(255, 63, 63);
960 TEAM_BLUE: cb := _RGB(63, 63, 255);
961 end;
962 r_Map_DrawBubble(x, y - 18, cb, cf);
963 end;
964 3: // adv player color
965 begin
966 cb := p.Model.Color;
967 cf.R := MIN(cb.R * 2 + 64, 255);
968 cf.G := MIN(cb.G * 2 + 64, 255);
969 cf.B := MIN(cb.B * 2 + 64, 255);
970 if (ABS(cf.R - cb.R) < 32) or (ABS(cf.G - cb.G) < 32) or (ABS(cf.B - cb.B) < 32) then
971 begin
972 cb.R := MAX(cf.R div 2 - 16, 0);
973 cb.G := MAX(cf.G div 2 - 16, 0);
974 cb.B := MAX(cf.B div 2 - 16, 0);
975 end;
976 r_Map_DrawBubble(x, y - 18, cb, cf);
977 end;
978 4: // textured
979 if TalkTexture <> nil then
980 begin
981 r_Common_DrawTexture(TalkTexture, x + 5, y, TalkTexture.width, TalkTexture.height, TBasePoint.BP_DOWN);
982 end;
983 end;
984 end;
986 procedure r_Map_DrawPlayer (p, drawed: TPlayer);
987 var x, y, ax, ay, w, h: Integer; b, flip: Boolean; t: TGLMultiTexture; tex: TGLTexture; alpha: Byte; count, frame: LongInt;
988 begin
989 if p.alive then
990 begin
991 r_Common_GetPlayerPos(p, x, y);
993 (* punch effect *)
994 if p.PunchTime <= gTime then
995 begin
996 g_Anim_GetFrameByTime(PunchAnim, (gTime - p.PunchTime) DIV GAME_TICK, count, frame);
997 if count < 1 then
998 begin
999 b := R_BERSERK in p.FRulez;
1000 if p.FKeys[KEY_DOWN].pressed then
1001 t := PunchTextures[b, 2]
1002 else if p.FKeys[KEY_UP].pressed then
1003 t := PunchTextures[b, 1]
1004 else
1005 t := PunchTextures[b, 0];
1006 if t <> nil then
1007 begin
1008 flip := p.Direction = TDirection.D_LEFT;
1009 ax := IfThen(flip, 15 - p.Obj.Rect.X, p.Obj.Rect.X - 15); // ???
1010 ay := p.Obj.Rect.Y - 11;
1011 tex := t.GetTexture(frame);
1012 r_Draw_TextureRepeat(tex, x + ax, y + ay, tex.width, tex.height, flip, 255, 255, 255, 255, false)
1013 end;
1014 end;
1015 end;
1017 (* invulnerability effect *)
1018 if (InvulPenta <> nil) and (p.FMegaRulez[MR_INVUL] > gTime) and ((p <> drawed) or (p.SpawnInvul >= gTime)) then
1019 begin
1020 w := InvulPenta.width;
1021 h := InvulPenta.height;
1022 ax := p.Obj.Rect.X + (p.Obj.Rect.Width div 2) - (w div 2); // + IfThen(flip, +4, -2) // ???
1023 ay := p.Obj.Rect.Y + (p.Obj.Rect.Height div 2) - (h div 2) - 7; // ???
1024 r_Draw_Texture(InvulPenta, x + ax, y + ay, w, h, false, 255, 255, 255, 255, false);
1025 end;
1027 (* invisibility effect *)
1028 alpha := 255;
1029 if p.FMegaRulez[MR_INVIS] > gTime then
1030 begin
1031 if (drawed <> nil) and ((p = drawed) or ((p.Team = drawed.Team) and (gGameSettings.GameMode <> GM_DM))) then
1032 begin
1033 if (p.FMegaRulez[MR_INVIS] - gTime > 2100) or not ODD((p.FMegaRulez[MR_INVIS] - gTime) div 300) then
1034 alpha := 55;
1035 end
1036 else
1037 alpha := 1; // ???
1038 end;
1040 r_Map_DrawPlayerModel(p.Model, x, y, alpha);
1041 end;
1043 if DebugFrames then
1044 begin
1045 r_Draw_Rect(
1046 x + p.obj.rect.x, // p.obj.x + p.obj.rect.x,
1047 y + p.obj.rect.y, // p.obj.y + p.obj.rect.y,
1048 x + p.obj.rect.x + p.obj.rect.width, // p.obj.x + p.obj.rect.x + p.obj.rect.width,
1049 y + p.obj.rect.y + p.obj.rect.height, // p.obj.y + p.obj.rect.y + p.obj.rect.height,
1050 0, 255, 0, 255
1051 );
1052 end;
1054 if DebugHealth and p.alive then
1055 begin
1056 r_Common_DrawText(
1057 IntToStr(p.health) + '/' + IntToStr(p.armor),
1058 x + p.obj.rect.x + p.obj.rect.width div 2,
1059 y - 24,
1060 255, 255, 255, 255,
1061 stdfont,
1062 TBasePoint.BP_DOWN
1063 );
1064 end;
1066 if (gChatBubble > 0) and p.FKeys[KEY_CHAT].Pressed and (p.Ghost = false) then
1067 if (p.FMegaRulez[MR_INVIS] <= gTime) or ((drawed <> nil) and ((p = drawed) or (p.Team = drawed.Team) and (gGameSettings.GameMode <> GM_DM))) then
1068 r_Map_DrawTalkBubble(p);
1070 // TODO draw aim
1071 end;
1073 procedure r_Map_DrawPlayers (x, y, w, h: Integer; player: TPlayer);
1074 var i: Integer;
1075 begin
1076 if gPlayers <> nil then
1077 for i := 0 to High(gPlayers) do
1078 if gPlayers[i] <> nil then
1079 r_Map_DrawPlayer(gPlayers[i], player);
1080 end;
1082 {$IFDEF ENABLE_GIBS}
1083 function r_Map_GetGibSize (m, i: Integer): TRectWH;
1084 begin
1085 result := Models[m].gibs.rect[i];
1086 end;
1088 procedure r_Map_DrawGibs (x, y, w, h: Integer);
1089 var i, xx, yy, m, id, rx, ry, ra: Integer; p: PObj; t: TGLTexture;
1090 begin
1091 if gGibs <> nil then
1092 begin
1093 (* hack: prevent visual disappearance *)
1094 x := x - MAXGIBW;
1095 y := y - MAXGIBH;
1096 w := w + MAXGIBW*2;
1097 h := h + MAXGIBH*2;
1098 for i := 0 to High(gGibs) do
1099 begin
1100 if gGibs[i].alive then
1101 begin
1102 p := @gGibs[i].Obj;
1103 if g_Obj_Collide(x, y, w, h, p) then
1104 begin
1105 r_Common_GetObjectPos(p^, xx, yy);
1106 id := gGibs[i].GibID;
1107 m := gGibs[i].ModelID;
1108 t := Models[m].gibs.base[id];
1109 if t <> nil then
1110 begin
1111 rx := p.Rect.X + p.Rect.Width div 2;
1112 ry := p.Rect.Y + p.Rect.Height div 2;
1113 ra := gGibs[i].RAngle;
1114 r_Draw_TextureRepeatRotate(t, xx, yy, t.width, t.height, false, 255, 255, 255, 255, false, rx, ry, ra);
1115 t := Models[m].gibs.mask[id];
1116 if t <> nil then
1117 r_Draw_TextureRepeatRotate(t, xx, yy, t.width, t.height, false, gGibs[i].Color.R, gGibs[i].Color.G, gGibs[i].Color.B, 255, false, rx, ry, ra);
1118 // r_Draw_TextureRepeatRotate(nil, xx + p.Rect.X, yy + p.Rect.Y, p.Rect.Width, p.Rect.Height, false, 255, 255, 255, 255, false, p.Rect.Width div 2, p.Rect.Height div 2, ra);
1119 end;
1120 end;
1121 end;
1122 end;
1123 end;
1124 end;
1125 {$ENDIF}
1127 {$IFDEF ENABLE_CORPSES}
1128 procedure r_Map_DrawCorpses (x, y, w, h: Integer);
1129 var i, xx, yy: Integer; p: TCorpse;
1130 begin
1131 if gCorpses <> nil then
1132 begin
1133 for i := 0 to High(gCorpses) do
1134 begin
1135 p := gCorpses[i];
1136 if (p <> nil) and (p.state <> CORPSE_STATE_REMOVEME) and (p.model <> nil) then
1137 begin
1138 r_Common_GetObjectPos(p.obj, xx, yy);
1139 r_Map_DrawPlayerModel(p.model, xx, yy, 255);
1140 end;
1141 end;
1142 end;
1143 end;
1144 {$ENDIF}
1146 {$IFDEF ENABLE_GFX}
1147 function r_Map_GetGFXID (): Integer;
1148 var i: Integer;
1149 begin
1150 i := 0;
1151 if gfxlist <> nil then
1152 begin
1153 while (i < Length(gfxlist)) and (gfxlist[i].typ > 0) do
1154 Inc(i);
1155 if i >= Length(gfxlist) then
1156 SetLength(gfxlist, Length(gfxlist) + 1)
1157 end
1158 else
1159 SetLength(gfxlist, 1);
1160 gfxlist[i].typ := R_GFX_NONE;
1161 result := i
1162 end;
1164 procedure r_Map_NewGFX (typ, x, y: Integer);
1165 var i: Integer;
1166 begin
1167 if gpart_dbg_enabled and (typ > 0) and (typ <= R_GFX_LAST) then
1168 begin
1169 i := r_Map_GetGFXID();
1170 if i >= 0 then
1171 begin
1172 gfxlist[i].typ := typ;
1173 gfxlist[i].x := x;
1174 gfxlist[i].y := y;
1175 gfxlist[i].oldX := x;
1176 gfxlist[i].oldY := y;
1177 gfxlist[i].anim := GFXAnim[typ].anim;
1178 gfxlist[i].time := gTime DIV GAME_TICK;
1179 gfxlist[i].frame := 0;
1180 INC(gfxlist[i].anim.delay, Random(GFXAnim[typ].rdelay));
1181 end;
1182 end;
1183 end;
1185 procedure r_Map_ResetGFX;
1186 begin
1187 SetLength(gfxlist, 0);
1188 end;
1190 procedure r_Map_UpdateGFX (tick: LongWord);
1191 var i: Integer; count: LongInt;
1192 begin
1193 if gfxlist <> nil then
1194 begin
1195 for i := 0 to High(gfxlist) do
1196 begin
1197 if (gfxlist[i].typ > 0) and (tick >= gfxlist[i].time) then
1198 begin
1199 g_Anim_GetFrameByTime(gfxlist[i].anim, tick - gfxlist[i].time, count, gfxlist[i].frame);
1200 if count < 1 then
1201 begin
1202 gfxlist[i].oldX := gfxlist[i].x;
1203 gfxlist[i].oldY := gfxlist[i].y;
1204 case gfxlist[i].typ of
1205 R_GFX_FLAME, R_GFX_SMOKE:
1206 begin
1207 if Random(3) = 0 then
1208 gfxlist[i].x := gfxlist[i].x - 1 + Random(3);
1209 if Random(2) = 0 then
1210 gfxlist[i].y := gfxlist[i].y - Random(2);
1211 end;
1212 end;
1213 end
1214 else
1215 gfxlist[i].typ := R_GFX_NONE;
1216 end;
1217 end;
1218 end;
1219 end;
1221 procedure r_Map_DrawGFX (x, y, w, h: Integer);
1222 var i, fx, fy, typ: Integer; t: TGLMultiTexture; tex: TGLTexture;
1223 begin
1224 if gfxlist <> nil then
1225 begin
1226 for i := 0 to High(gfxlist) do
1227 begin
1228 if gfxlist[i].typ > 0 then
1229 begin
1230 typ := gfxlist[i].typ;
1231 t := GFXTextures[typ];
1232 if t <> nil then
1233 begin
1234 fx := nlerp(gfxlist[i].oldX, gfxlist[i].x, gLerpFactor);
1235 fy := nlerp(gfxlist[i].oldY, gfxlist[i].y, gLerpFactor);
1236 tex := t.GetTexture(gfxlist[i].frame);
1237 r_Draw_TextureRepeat(tex, fx, fy, tex.width, tex.height, false, 255, 255, 255, 255 - GFXAnim[typ].alpha, false);
1238 end;
1239 end;
1240 end;
1241 end;
1242 end;
1244 procedure r_Map_DrawParticles (x, y, w, h: Integer);
1245 var i, fx, fy: Integer; factor: Single;
1246 begin
1247 if gpart_dbg_enabled and (Particles <> nil) then
1248 begin
1249 r_Draw_EnableTexture2D(false);
1250 factor := r_pixel_scale * g_dbg_scale;
1251 if factor < 0.6 then
1252 glPointSize(1)
1253 else if factor > 1.3 then
1254 glPointSize(factor + 1)
1255 else
1256 glPointSize(2);
1257 glDisable(GL_POINT_SMOOTH);
1258 glEnable(GL_BLEND);
1259 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1261 r_Draw_SetColor(255, 255, 255, 255);
1262 glBegin(GL_POINTS);
1263 for i := 0 to High(Particles) do
1264 begin
1265 if Particles[i].alive then
1266 begin
1267 fx := nlerp(Particles[i].oldX, Particles[i].x, gLerpFactor);
1268 fy := nlerp(Particles[i].oldY, Particles[i].y, gLerpFactor);
1269 glColor4ub(Particles[i].red, Particles[i].green, Particles[i].blue, Particles[i].alpha);
1270 glVertex2i(fx, fy);
1271 end;
1272 end;
1273 glEnd;
1274 r_Draw_SetColor(0, 0, 0, 255);
1276 glDisable(GL_BLEND);
1277 end;
1278 end;
1279 {$ENDIF}
1281 procedure r_Map_DrawShots (x, y, w, h: Integer);
1282 var i, a, xx, yy, pX, pY, typ: Integer; count, frame: LongInt; t: TGLMultiTexture; tex: TGLTexture;
1283 begin
1284 if Shots <> nil then
1285 begin
1286 for i := 0 to High(Shots) do
1287 begin
1288 typ := Shots[i].ShotType;
1289 if typ <> 0 then
1290 begin
1291 t := ShotTextures[typ];
1292 if t <> nil then
1293 begin
1294 a := 0;
1295 case typ of
1296 WEAPON_ROCKETLAUNCHER, WEAPON_BARON_FIRE, WEAPON_MANCUB_FIRE, WEAPON_SKEL_FIRE:
1297 a := -GetAngle2(Shots[i].Obj.Vel.X, Shots[i].Obj.Vel.Y)
1298 end;
1299 r_Common_GetObjectPos(Shots[i].Obj, xx, yy);
1300 pX := Shots[i].Obj.Rect.Width div 2;
1301 pY := Shots[i].Obj.Rect.Height div 2;
1302 g_Anim_GetFrameByTime(ShotAnim[typ].anim, (gTime - Shots[i].time) DIV GAME_TICK, count, frame);
1303 tex := t.GetTexture(frame);
1304 r_Draw_TextureRepeatRotate(tex, xx, yy, tex.width, tex.height, false, 255, 255, 255, 255, false, pX, pY, a);
1305 if DebugFrames then
1306 begin
1307 r_Draw_Rect(
1308 xx + Shots[i].obj.rect.x, // Shots[i].obj.x + Shots[i].obj.rect.x,
1309 yy + Shots[i].obj.rect.y, // Shots[i].obj.y + Shots[i].obj.rect.y,
1310 xx + Shots[i].obj.rect.x + Shots[i].obj.rect.width, // Shots[i].obj.x + Shots[i].obj.rect.x + Shots[i].obj.rect.width,
1311 yy + Shots[i].obj.rect.y + Shots[i].obj.rect.height, // Shots[i].obj.y + Shots[i].obj.rect.y + Shots[i].obj.rect.height,
1312 0, 255, 0, 255
1313 );
1314 end;
1315 end;
1316 end;
1317 end;
1318 end;
1319 end;
1321 procedure r_Map_DrawFlags (x, y, w, h: Integer);
1322 var i, dx, xx, yy: Integer; flip: Boolean; t: TGLMultiTexture; tex: TGLTexture;
1323 begin
1324 if gGameSettings.GameMode = GM_CTF then
1325 begin
1326 for i := FLAG_RED to FLAG_BLUE do
1327 begin
1328 if not (gFlags[i].state in [FLAG_STATE_NONE, FLAG_STATE_CAPTURED]) then
1329 begin
1330 r_Common_GetObjectPos(gFlags[i].Obj, xx, yy);
1331 flip := gFlags[i].Direction = TDirection.D_LEFT;
1332 if flip then dx := -1 else dx := +1;
1333 t := FlagTextures[i];
1334 tex := t.GetTexture(FlagFrame);
1335 r_Draw_TextureRepeat(tex, xx + dx, yy + 1, tex.width, tex.height, flip, 255, 255, 255, 255, false);
1336 if DebugFrames then
1337 begin
1338 r_Draw_Rect(
1339 xx + gFlags[i].obj.rect.x, // gFlags[i].obj.x + gFlags[i].obj.rect.x,
1340 yy + gFlags[i].obj.rect.y, // gFlags[i].obj.y + gFlags[i].obj.rect.y,
1341 xx + gFlags[i].obj.rect.x + gFlags[i].obj.rect.width, // gFlags[i].obj.x + gFlags[i].obj.rect.x + gFlags[i].obj.rect.width,
1342 yy + gFlags[i].obj.rect.y + gFlags[i].obj.rect.height, // gFlags[i].obj.y + gFlags[i].obj.rect.y + gFlags[i].obj.rect.height,
1343 0, 255, 0, 255
1344 );
1345 end;
1346 end;
1347 end;
1348 end;
1349 end;
1351 {$IFDEF ENABLE_SHELLS}
1352 procedure r_Map_DrawShells (x, y, w, h: Integer);
1353 var i, xx, yy, typ: Integer; t: TGLTexture; p: PObj;
1354 begin
1355 if gShells <> nil then
1356 begin
1357 for i := 0 to High(gShells) do
1358 begin
1359 if gShells[i].alive then
1360 begin
1361 typ := gShells[i].SType;
1362 if typ <= SHELL_LAST then
1363 begin
1364 p := @gShells[i].Obj;
1365 if g_Obj_Collide(x, y, w, h, p) then
1366 begin
1367 t := ShellTextures[typ];
1368 if t <> nil then
1369 begin
1370 r_Common_GetObjectPos(p^, xx, yy);
1371 r_Draw_TextureRepeatRotate(t, xx, yy, t.width, t.height, false, 255, 255, 255, 255, false, ShellAnim[typ].dx, ShellAnim[typ].dy, gShells[i].RAngle);
1372 end;
1373 end;
1374 end;
1375 end;
1376 end;
1377 end;
1378 end;
1379 {$ENDIF}
1381 procedure r_Map_CalcSkyParallax (cx, cy, vw, vh, sw, sh, mw, mh: LongInt; out x, y, w, h: LongInt);
1382 const
1383 factor = 120; (* size ratio between view and sky (120%) *)
1384 limit = 100; (* max speed for parallax *)
1385 var
1386 msw, msh, mvw, mvh, svw, svh: LongInt;
1387 begin
1388 msw := vw * factor div 100;
1389 msh := vh * factor div 100;
1390 r_Common_CalcAspect(sw, sh, msw, msh, (sw / sh) <= (msw / msh), w, h);
1392 (* calc x parallax or sky center on speed limit *)
1393 mvw := MAX(1, mw - vw);
1394 svw := w - vw;
1395 if 100 * svw div mvw <= limit then
1396 x := -cx * svw div mvw
1397 else
1398 x := -svw div 2;
1400 (* calc y parallax or sky center on speed limit *)
1401 mvh := MAX(1, mh - vh);
1402 svh := h - vh;
1403 if 100 * svh div mvh <= limit then
1404 y := -cy * svh div mvh
1405 else
1406 y := -svh div 2;
1408 (* handle out of map bounds *)
1409 if x > 0 then x := 0;
1410 if y > 0 then y := 0;
1411 if x < -svw then x := -svw;
1412 if y < -svh then y := -svh;
1413 end;
1415 procedure r_Map_DrawScreenEffect (x, y, w, h, level: Integer; r, g, b: Byte);
1416 var i: Integer;
1417 begin
1418 if level > 0 then
1419 begin
1420 case level of
1421 0..14: i := 0;
1422 15..34: i := 1;
1423 35..54: i := 2;
1424 55..74: i := 3;
1425 75..94: i := 4;
1426 else i := 5
1427 end;
1428 r_Draw_FillRect(x, y, x + w, y + h, r, g, b, i * 50)
1429 end;
1430 end;
1432 procedure r_Map_DrawScreenEffects (x, y, w, h: Integer; p: TPlayer);
1433 begin
1434 if p <> nil then
1435 begin
1436 r_Map_DrawScreenEffect(x, y, w, h, p.pain, 255, 0, 0);
1437 r_Map_DrawScreenEffect(x, y, w, h, p.pickup, 150, 200, 150);
1438 if (p.FMegaRulez[MR_INVUL] >= gTime) and (p.SpawnInvul < gTime) then
1439 begin
1440 if ((p.FMegaRulez[MR_INVUL] - gTime) > 2100) or not ODD((p.FMegaRulez[MR_INVUL] - gTime) div 300) then
1441 r_Draw_InvertRect(x, y, x + w, y + h, 191, 191, 191, 255);
1442 end;
1443 if p.FMegaRulez[MR_SUIT] >= gTime then
1444 begin
1445 if ((p.FMegaRulez[MR_SUIT] - gTime) > 2100) or not ODD((p.FMegaRulez[MR_SUIT] - gTime) div 300) then
1446 r_Draw_FillRect(x, y, x + w, y + h, 0, 96, 0, 55);
1447 end;
1448 if (p.Berserk >= 0) and (p.Berserk >= gTime) and (gFlash = 2) then
1449 begin
1450 r_Draw_FillRect(x, y, x + w, y + h, 255, 0, 0, 55);
1451 end;
1452 end;
1453 end;
1455 procedure r_Map_DrawIndicator (p: TPlayer; color: TRGB; cx, cy, cw, ch: Integer);
1456 var a, ax, ay, fx, fy, xx, yy: Integer;
1457 begin
1458 if (p <> nil) and p.Alive and (p.Spectator = false) then
1459 begin
1460 r_Common_GetPlayerPos(p, fx, fy);
1461 case gPlayerIndicatorStyle of
1462 0:
1463 if IndicatorTexture <> nil then
1464 begin
1465 ax := IndicatorTexture.width div 2;
1466 ay := IndicatorTexture.height div 2;
1467 if (p.obj.x + p.obj.rect.x) < cx then
1468 begin
1469 a := 90;
1470 xx := fx + p.obj.rect.x + p.obj.rect.width;
1471 yy := fy + p.obj.rect.y + (p.obj.rect.height - IndicatorTexture.width) div 2;
1472 end
1473 else if (p.obj.x + p.obj.rect.x + p.obj.rect.width) > (cx + cw) then
1474 begin
1475 a := 270;
1476 xx := fx + p.obj.rect.x - IndicatorTexture.height;
1477 yy := fy + p.obj.rect.y - (p.obj.rect.height - IndicatorTexture.width) div 2;
1478 end
1479 else if (p.obj.y - IndicatorTexture.height) < cy then
1480 begin
1481 a := 180;
1482 xx := fx + p.obj.rect.x + (p.obj.rect.width - IndicatorTexture.width) div 2;
1483 yy := fy + p.obj.rect.y + p.obj.rect.height;
1484 end
1485 else
1486 begin
1487 a := 0;
1488 xx := fx + p.obj.rect.x + (p.obj.rect.width - IndicatorTexture.width) div 2;
1489 yy := fy - IndicatorTexture.height;
1490 end;
1491 xx := MIN(MAX(xx, cx), cx + cw - IndicatorTexture.width);
1492 yy := MIN(MAX(yy, cy), cy + ch - IndicatorTexture.height);
1493 r_Draw_TextureRepeatRotate(IndicatorTexture, xx, yy, IndicatorTexture.width, IndicatorTexture.height, false, color.r, color.g, color.b, 255, false, ax, ay, a);
1494 end;
1495 1:
1496 begin
1497 xx := fx + p.obj.rect.x + p.obj.rect.width div 2;
1498 yy := fy;
1499 r_Common_DrawText(p.Name, xx, yy, color.r, color.g, color.b, 255, stdfont, TBasePoint.BP_DOWN);
1500 end;
1501 end;
1502 end;
1503 end;
1505 procedure r_Map_DrawPlayerIndicators (player: TPlayer; cx, cy, cw, ch: Integer);
1506 var i: Integer; p: TPlayer;
1507 begin
1508 case gPlayerIndicator of
1509 1:
1510 if player <> nil then
1511 begin
1512 r_Map_DrawIndicator(player, _RGB(255, 255, 255), cx, cy, cw, ch);
1513 end;
1514 2:
1515 if gPlayers <> nil then
1516 begin
1517 for i := 0 to HIGH(gPlayers) do
1518 begin
1519 p := gPlayers[i];
1520 if p <> nil then
1521 begin
1522 if (player <> nil) and (p = player) then
1523 begin
1524 r_Map_DrawIndicator(p, _RGB(255, 255, 255), cx, cy, cw, ch);
1525 end
1526 else if (player = nil) or ((p.Team = player.Team) and (p.Team <> TEAM_NONE)) then
1527 begin
1528 case gPlayerIndicatorStyle of
1529 0: r_Map_DrawIndicator(p, p.GetColor(), cx, cy, cw, ch);
1530 1: r_Map_DrawIndicator(p, _RGB(192, 192, 192), cx, cy, cw, ch);
1531 end;
1532 end;
1533 end;
1534 end;
1535 end;
1536 end;
1537 end;
1539 function r_Map_GetDrawableGridMask (): Integer;
1540 var mask: Integer;
1541 begin
1542 mask := 0;
1543 if g_rlayer_back then mask := mask or GridTagBack;
1544 if g_rlayer_step then mask := mask or GridTagStep;
1545 if g_rlayer_wall then mask := mask or GridTagWall;
1546 if g_rlayer_door then mask := mask or GridTagDoor;
1547 if g_rlayer_acid1 then mask := mask or GridTagAcid1;
1548 if g_rlayer_acid2 then mask := mask or GridTagAcid2;
1549 if g_rlayer_water then mask := mask or GridTagWater;
1550 if g_rlayer_fore then mask := mask or GridTagFore;
1551 result := mask;
1552 end;
1554 procedure r_Map_DrawGame (xx, yy, ww, hh: Integer; player: TPlayer);
1555 (* xx/yy/ww/hh are in map units *)
1556 var iter: TPanelGrid.Iter; p: PPanel;
1557 begin
1558 if UseAccel then
1559 begin
1560 plist.Clear;
1561 iter := mapGrid.ForEachInAABB(xx, yy, ww, hh, r_Map_GetDrawableGridMask());
1562 for p in iter do
1563 if ((p^.tag and GridTagDoor) <> 0) = p^.door then
1564 plist.Insert(p^);
1565 iter.Release;
1566 end;
1568 r_Map_DrawPanelType(PANEL_BACK);
1569 r_Map_DrawPanelType(PANEL_STEP);
1570 r_Map_DrawItems(xx, yy, ww, hh, false);
1571 r_Map_DrawShots(xx, yy, ww, hh);
1572 {$IFDEF ENABLE_SHELLS}
1573 r_Map_DrawShells(xx, yy, ww, hh);
1574 {$ENDIF}
1575 r_Map_DrawPlayers(xx, yy, ww, hh, player);
1576 {$IFDEF ENABLE_GIBS}
1577 r_Map_DrawGibs(xx, yy, ww, hh);
1578 {$ENDIF}
1579 {$IFDEF ENABLE_CORPSES}
1580 r_Map_DrawCorpses(xx, yy, ww, hh);
1581 {$ENDIF}
1582 r_Map_DrawPanelType(PANEL_WALL);
1583 r_Map_DrawMonsters(xx, yy, ww, hh);
1584 r_Map_DrawItems(xx, yy, ww, hh, true);
1585 r_Map_DrawPanelType(PANEL_CLOSEDOOR);
1586 {$IFDEF ENABLE_GFX}
1587 r_Map_DrawParticles(xx, yy, ww, hh);
1588 r_Map_DrawGFX(xx, yy, ww, hh);
1589 {$ENDIF}
1590 r_Map_DrawFlags(xx, yy, ww, hh);
1591 r_Map_DrawPanelType(PANEL_ACID1);
1592 r_Map_DrawPanelType(PANEL_ACID2);
1593 r_Map_DrawPanelType(PANEL_WATER);
1594 r_Map_DrawPanelType(PANEL_FORE);
1595 end;
1597 procedure r_Map_DrawScaled (w, h, camx, camy: Integer; player: TPlayer; out acx, acy, acw, ach, axx, ayy, aww, ahh: Integer);
1598 (* w/h/camx/camy are in map units (scaled) *)
1599 const limit = 32767;
1600 var cx, cy, cw, ch, xx, yy, ww, hh{, ml, mt, mr, mb}: Integer; sx, sy, sw, sh: LongInt;
1601 begin
1602 (* camera rect *)
1603 cx := camx - w div 2;
1604 cy := camy - h div 2;
1605 cw := w;
1606 ch := h;
1608 (* camera bounds *)
1609 if g_dbg_ignore_bounds = false then
1610 begin
1611 if w > gMapInfo.Width then
1612 cx := gMapInfo.Width div 2 - w div 2
1613 else if cx + cw > gMapInfo.Width then
1614 cx := gMapInfo.Width - cw
1615 else if cx < 0 then
1616 cx := 0;
1618 if h > gMapInfo.Height then
1619 cy := gMapInfo.Height div 2 - h div 2
1620 else if cy + ch > gMapInfo.Height then
1621 cy := gMapInfo.Height - ch
1622 else if cy < 0 then
1623 cy := 0;
1624 end;
1626 acx := cx;
1627 acy := cy;
1628 acw := cw;
1629 ach := ch;
1631 (* map bounds *)
1632 xx := cx;
1633 yy := cy;
1634 ww := cw;
1635 hh := ch;
1636 if xx + ww > gMapInfo.Width then
1637 xx := gMapInfo.Width - ww;
1638 if yy + hh > gMapInfo.Height then
1639 yy := gMapInfo.Height - hh;
1640 if xx < 0 then
1641 xx := 0;
1642 if yy < 0 then
1643 yy := 0;
1644 axx := xx;
1645 ayy := yy;
1646 aww := ww;
1647 ahh := hh;
1650 (* view bounds *)
1651 ml := x; mt := y; mr := x + w; mb := y + h;
1652 if FillOutsizeArea and (DebugCameraScale = 1.0) then
1653 begin
1654 ml := MAX(cx + ml, 0) - cx;
1655 mt := MAX(cy + mt, 0) - cy;
1656 mr := MIN(cx + mr, gMapInfo.Width - 1) - cx;
1657 mb := MIN(cy + mb, gMapInfo.Height - 1) - cy;
1658 end;
1659 r_Draw_SetRect(ml, mt, mr, mb);
1662 if DebugCameraScale <> 1.0 then
1663 begin
1664 glTranslatef(cw div 2, ch div 2, 0);
1665 glScalef(DebugCameraScale, DebugCameraScale, 1);
1666 glTranslatef(-w div 2, -h div 2, 0);
1667 end;
1669 if gDrawBackGround and (SkyTexture <> nil) then
1670 begin
1671 r_Map_CalcSkyParallax(cx, cy, w, h, SkyTexture.width, SkyTexture.height, gMapInfo.Width, gMapInfo.Height, sx, sy, sw, sh);
1672 r_Draw_Texture(SkyTexture, sx, sy, sw, sh, false, 255, 255, 255, 255, false);
1673 end;
1675 glTranslatef(-cx, -cy, 0);
1676 r_Map_DrawGame(xx, yy, ww, hh, player);
1677 if FillOutsizeArea and (DebugCameraScale = 1.0) then
1678 begin
1679 (* top *) r_Draw_FillRect(0 - limit, 0 - limit, gMapInfo.Width + limit, 0, 0, 0, 0, 255);
1680 (* left *) r_Draw_FillRect(0 - limit, 0, 0, gMapInfo.Height + limit, 0, 0, 0, 255);
1681 (* right *) r_Draw_FillRect(gMapInfo.Width, 0, gMapInfo.Width + limit, gMapInfo.Height + limit, 0, 0, 0, 255);
1682 (* bottom *) r_Draw_FillRect(0 - limit, gMapInfo.Height, gMapInfo.Width + limit, gMapInfo.Height + limit, 0, 0, 0, 255);
1683 end;
1684 glTranslatef(cx, cy, 0);
1685 end;
1687 procedure r_Map_Draw (x, y, w, h, camx, camy: Integer; player: TPlayer; out acx, acy: Integer);
1688 var cx, cy, cw, ch, xx, yy, ww, hh, ml, mt, mr, mb, mcx, mcy: Integer; l, t, r, b: Integer;
1689 begin
1690 glPushMatrix;
1691 r_Draw_GetRect(l, t, r, b);
1692 glTranslatef(x, y, 0);
1693 glScalef(g_dbg_scale, g_dbg_scale, 0);
1695 r_Draw_SetRect(x, y, x + w, y + h);
1696 r_Map_DrawScaled(Round(w / g_dbg_scale), Round(h / g_dbg_scale), camx, camy, player, cx, cy, cw, ch, xx, yy, ww, hh);
1697 acx := cx;
1698 acy := cy;
1699 r_Draw_SetRect(x, y, x + w, y + h);
1701 if DebugCameraScale <> 1.0 then
1702 begin
1703 r_Draw_Rect(0, 0, cw, ch, 0, 255, 0, 255);
1704 r_Draw_Rect(-cx + xx, -cy + yy, -cx + xx + ww, -cy + yy + hh, 255, 0, 0, 255);
1705 end;
1707 if gGameSettings.GameMode <> GM_SINGLE then
1708 begin
1709 glTranslatef(-cx, -cy, 0);
1710 r_Map_DrawPlayerIndicators(player, cx, cy, cw, ch);
1711 end;
1713 //glTranslatef(-x, -y, 0);
1714 r_Draw_SetRect(l, t, r, b);
1715 glPopMatrix;
1717 r_Map_DrawScreenEffects(x, y, w, h, player);
1718 end;
1720 procedure r_Map_Reset;
1721 begin
1722 {$IFDEF ENABLE_GFX}
1723 r_Map_ResetGFX;
1724 {$ENDIF}
1725 end;
1727 procedure r_Map_Update;
1728 var i, count, tick: LongInt;
1729 begin
1730 tick := gTime div GAME_TICK;
1731 for i := 0 to ITEM_LAST do
1732 g_Anim_GetFrameByTime(ItemAnim[i].anim, tick, count, Items[i].frame);
1733 r_Map_UpdateGFX(tick);
1734 g_Anim_GetFrameByTime(FlagAnim, tick, count, FlagFrame);
1735 end;
1737 procedure r_Map_GetSpectatorLimits (out x0, y0, x1, y1: Integer);
1738 var w, h: Integer;
1739 begin
1740 w := Round(gScreenWidth / g_dbg_scale);
1741 if gMapInfo.Width > w then
1742 begin
1743 x0 := w div 2;
1744 x1 := gMapInfo.Width - w div 2 - 1;
1745 end
1746 else
1747 begin
1748 x0 := gMapInfo.Width div 2;
1749 x1 := gMapInfo.Width div 2;
1750 end;
1752 h := Round(gScreenHeight / g_dbg_scale);
1753 if gMapInfo.Height > h then
1754 begin
1755 y0 := h div 2;
1756 y1 := gMapInfo.Height - h div 2 - 1;
1757 end
1758 else
1759 begin
1760 y0 := gMapInfo.Height div 2;
1761 y1 := gMapInfo.Height div 2;
1762 end;
1763 end;
1765 initialization
1766 conRegVar('r_sq_draw', @UseAccel, 'accelerated spatial queries in rendering', 'accelerated rendering');
1767 conRegVar('r_debug_camera_scale', @DebugCameraScale, 0.0001, 1000.0, '', '');
1768 conRegVar('r_gl_fill_outside', @FillOutsizeArea, '', '');
1769 conRegVar('d_frames', @DebugFrames, '', '');
1770 conRegVar('d_health', @DebugHealth, '', '');
1771 UseAccel := true;
1772 DebugCameraScale := 1.0;
1773 FillOutsizeArea := true;
1774 DebugFrames := false;
1775 DebugHealth := false;
1776 end.