DEADSOFTWARE

812fd85cd59c5c7f114309e002d690208f5daf77
[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_Update;
43 procedure r_Map_Draw (x, y, w, h, camx, camy: Integer; player: TPlayer);
45 implementation
47 uses
48 Math, SysUtils,
49 {$IFDEF USE_GLES1}
50 GLES11,
51 {$ELSE}
52 GL, GLEXT,
53 {$ENDIF}
54 e_log,
55 binheap, MAPDEF, utils,
56 g_options, g_animations, g_basic, g_phys,
57 g_game, g_map, g_panel, g_items, g_monsters, g_weapons,
58 g_console,
59 {$IFDEF ENABLE_CORPSES}
60 g_corpses,
61 {$ENDIF}
62 {$IFDEF ENABLE_SHELLS}
63 g_shells,
64 {$ENDIF}
65 {$IFDEF ENABLE_GIBS}
66 g_gibs,
67 {$ENDIF}
68 {$IFDEF ENABLE_GFX}
69 g_gfx,
70 {$ENDIF}
71 r_textures, r_draw, r_common
72 ;
74 const
75 MTABLE: array [0..MONSTER_MAN] of record
76 w, h: Integer;
77 end = (
78 (w: 64; h: 64), // NONE
79 (w: 64; h: 64), // DEMON
80 (w: 64; h: 64), // IMP
81 (w: 64; h: 64), // ZOMBY
82 (w: 64; h: 64), // SERG
83 (w: 128; h: 128), // CYBER
84 (w: 64; h: 64), // CGUN
85 (w: 128; h: 128), // BARON
86 (w: 128; h: 128), // KNIGHT
87 (w: 128; h: 128), // CACO
88 (w: 64; h: 64), // SOUL (DIE is 128x128, see load code)
89 (w: 128; h: 128), // PAIN
90 (w: 256; h: 128), // SPIDER
91 (w: 128; h: 64), // BSP
92 (w: 128; h: 128), // MANCUB
93 (w: 128; h: 128), // SKEL
94 (w: 128; h: 128), // VILE
95 (w: 32; h: 32), // FISH
96 (w: 64; h: 64), // BARREL
97 (w: 128; h: 128), // ROBO
98 (w: 64; h: 64) // MAN
99 );
100 VILEFIRE_DX = 32;
101 VILEFIRE_DY = 128;
103 ItemAnim: array [0..ITEM_LAST] of record
104 name: AnsiString;
105 w, h: Integer;
106 anim: TAnimInfo;
107 end = (
108 (name: 'NOTEXTURE'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
109 (name: 'MED1'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
110 (name: 'MED2'; w: 32; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
111 (name: 'BMED'; w: 32; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
112 (name: 'ARMORGREEN'; w: 32; h: 16; anim: (loop: true; delay: 20; frames: 3; back: true)),
113 (name: 'ARMORBLUE'; w: 32; h: 16; anim: (loop: true; delay: 20; frames: 3; back: true)),
114 (name: 'SBLUE'; w: 32; h: 32; anim: (loop: true; delay: 15; frames: 4; back: true)),
115 (name: 'SWHITE'; w: 32; h: 32; anim: (loop: true; delay: 20; frames: 4; back: true)),
116 (name: 'SUIT'; w: 32; h: 64; anim: (loop: true; delay: 1; frames: 1; back: false)),
117 (name: 'OXYGEN'; w: 16; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
118 (name: 'INVUL'; w: 32; h: 32; anim: (loop: true; delay: 20; frames: 4; back: true)),
119 (name: 'SAW'; w: 64; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
120 (name: 'SHOTGUN1'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
121 (name: 'SHOTGUN2'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
122 (name: 'MGUN'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
123 (name: 'RLAUNCHER'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
124 (name: 'PGUN'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
125 (name: 'BFG'; w: 64; h: 64; anim: (loop: true; delay: 1; frames: 1; back: false)),
126 (name: 'SPULEMET'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
127 (name: 'CLIP'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
128 (name: 'AMMO'; w: 32; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
129 (name: 'SHELL1'; w: 16; h: 8; anim: (loop: true; delay: 1; frames: 1; back: false)),
130 (name: 'SHELL2'; w: 32; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
131 (name: 'ROCKET'; w: 16; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
132 (name: 'ROCKETS'; w: 64; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
133 (name: 'CELL'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
134 (name: 'CELL2'; w: 32; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
135 (name: 'BPACK'; w: 32; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
136 (name: 'KEYR'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
137 (name: 'KEYG'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
138 (name: 'KEYB'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
139 (name: 'KASTET'; w: 64; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
140 (name: 'PISTOL'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
141 (name: 'BOTTLE'; w: 16; h: 32; anim: (loop: true; delay: 20; frames: 4; back: true)),
142 (name: 'HELMET'; w: 16; h: 16; anim: (loop: true; delay: 20; frames: 4; back: true)),
143 (name: 'JETPACK'; w: 32; h: 32; anim: (loop: true; delay: 15; frames: 3; back: true)),
144 (name: 'INVIS'; w: 32; h: 32; anim: (loop: true; delay: 20; frames: 4; back: true)),
145 (name: 'FLAMETHROWER'; w: 64; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
146 (name: 'FUELCAN'; w: 16; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false))
147 );
149 {$IFDEF ENABLE_GFX}
150 GFXAnim: array [0..R_GFX_LAST] of record
151 name: AnsiString;
152 w, h: Integer;
153 anim: TAnimInfo;
154 rdelay: Integer;
155 alpha: Integer;
156 end = (
157 (name: ''; w: 0; h: 0; anim: (loop: false; delay: 0; frames: 0; back: false); rdelay: 0; alpha: 0),
158 (name: 'TELEPORT'; w: 64; h: 64; anim: (loop: false; delay: 6; frames: 10; back: false); rdelay: 0; alpha: 0),
159 (name: 'FLAME'; w: 32; h: 32; anim: (loop: false; delay: 3; frames: 11; back: false); rdelay: 0; alpha: 0),
160 (name: 'EROCKET'; w: 128; h: 128; anim: (loop: false; delay: 6; frames: 6; back: false); rdelay: 0; alpha: 0),
161 (name: 'EBFG'; w: 128; h: 128; anim: (loop: false; delay: 6; frames: 6; back: false); rdelay: 0; alpha: 0),
162 (name: 'BFGHIT'; w: 64; h: 64; anim: (loop: false; delay: 4; frames: 4; back: false); rdelay: 0; alpha: 0),
163 (name: 'FIRE'; w: 64; h: 128; anim: (loop: false; delay: 4; frames: 8; back: false); rdelay: 2; alpha: 0),
164 (name: 'ITEMRESPAWN'; w: 32; h: 32; anim: (loop: false; delay: 4; frames: 5; back: true); rdelay: 0; alpha: 0),
165 (name: 'SMOKE'; w: 32; h: 32; anim: (loop: false; delay: 3; frames: 10; back: false); rdelay: 0; alpha: 0),
166 (name: 'ESKELFIRE'; w: 64; h: 64; anim: (loop: false; delay: 8; frames: 3; back: false); rdelay: 0; alpha: 0),
167 (name: 'EPLASMA'; w: 32; h: 32; anim: (loop: false; delay: 3; frames: 4; back: true); rdelay: 0; alpha: 0),
168 (name: 'EBSPFIRE'; w: 32; h: 32; anim: (loop: false; delay: 3; frames: 5; back: false); rdelay: 0; alpha: 0),
169 (name: 'EIMPFIRE'; w: 64; h: 64; anim: (loop: false; delay: 6; frames: 3; back: false); rdelay: 0; alpha: 0),
170 (name: 'ECACOFIRE'; w: 64; h: 64; anim: (loop: false; delay: 6; frames: 3; back: false); rdelay: 0; alpha: 0),
171 (name: 'EBARONFIRE'; w: 64; h: 64; anim: (loop: false; delay: 6; frames: 3; back: false); rdelay: 0; alpha: 0),
172 (name: 'TELEPORT'; w: 64; h: 64; anim: (loop: false; delay: 3; frames: 10; back: false); rdelay: 0; alpha: 0), // fast
173 (name: 'SMOKE'; w: 32; h: 32; anim: (loop: false; delay: 3; frames: 10; back: false); rdelay: 0; alpha: 150), // transparent
174 (name: 'FLAME'; w: 32; h: 32; anim: (loop: false; delay: 3; frames: 11; back: false); rdelay: 2; alpha: 0) // random
175 );
176 {$ENDIF}
178 ShotAnim: array [0..WEAPON_LAST] of record
179 name: AnsiString;
180 w, h: Integer;
181 anim: TAnimInfo;
182 end = (
183 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 0 KASTET
184 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 1 SAW
185 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 2 PISTOL
186 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 3 SHOTGUN1
187 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 4 SHOTGUN2
188 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 5 CHAINGUN
189 (name: 'BROCKET'; w: 64; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)), // 6 ROCKETLAUNCHER
190 (name: 'BPLASMA'; w: 16; h: 16; anim: (loop: true; delay: 5; frames: 2; back: false)), // 7 PLASMA
191 (name: 'BBFG'; w: 64; h: 64; anim: (loop: true; delay: 6; frames: 2; back: false)), // 8 BFG
192 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 9 SUPERPULEMET
193 (name: 'FLAME'; w: 32; h: 32; anim: (loop: true; delay: 6; frames: 0{11}; back: false)), // 10 FLAMETHROWER
194 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 11
195 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 12
196 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 13
197 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 14
198 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 15
199 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 16
200 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 17
201 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 18
202 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 19
203 (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 20 ZOMPY_PISTOL
204 (name: 'BIMPFIRE'; w: 16; h: 16; anim: (loop: true; delay: 4; frames: 2; back: false)), // 21 IMP_FIRE
205 (name: 'BBSPFIRE'; w: 16; h: 16; anim: (loop: true; delay: 4; frames: 2; back: false)), // 22 BSP_FIRE
206 (name: 'BCACOFIRE'; w: 16; h: 16; anim: (loop: true; delay: 4; frames: 2; back: false)), // 23 CACO_FIRE
207 (name: 'BBARONFIRE'; w: 64; h: 16; anim: (loop: true; delay: 4; frames: 2; back: false)), // 24 BARON_FIRE
208 (name: 'BMANCUBFIRE'; w: 64; h: 32; anim: (loop: true; delay: 4; frames: 2; back: false)), // 25 MANCUB_FIRE
209 (name: 'BSKELFIRE'; w: 64; h: 64; anim: (loop: true; delay: 5; frames: 2; back: false)) // 26 SKEL_FIRE
210 );
212 {$IFDEF ENABLE_SHELLS}
213 ShellAnim: array [0..SHELL_LAST] of record
214 name: AnsiString;
215 dx, dy: Integer;
216 end = (
217 (name: 'EBULLET'; dx: 2; dy: 1), // 0 SHELL_BULLET
218 (name: 'ESHELL'; dx: 4; dy: 2), // 1 SHELL_SHELL
219 (name: 'ESHELL'; dx: 4; dy: 2) // 2 SHELL_DBLSHELL
220 );
221 {$ENDIF}
223 PunchAnim: TAnimInfo = (loop: false; delay: 1; frames: 4; back: false);
224 FlagAnim: TAnimInfo = (loop: true; delay: 8; frames: 5; back: false);
225 VileFireAnim: TAnimInfo = (loop: true; delay: 2; frames: 8; back: false);
227 type
228 TBinHeapPanelDrawCmp = class
229 public
230 class function less (const a, b: TPanel): Boolean; inline;
231 end;
233 TBinHeapPanelDraw = specialize TBinaryHeapBase<TPanel, TBinHeapPanelDrawCmp>;
235 TMonsterAnims = array [0..ANIM_LAST, TDirection] of TGLMultiTexture;
237 var
238 DebugCameraScale: Single;
239 SkyTexture: TGLTexture;
240 RenTextures: array of record
241 spec: LongInt;
242 tex: TGLMultiTexture;
243 anim: TAnimInfo;
244 end;
245 Items: array [0..ITEM_LAST] of record
246 tex: TGLMultiTexture;
247 frame: Integer;
248 end;
249 MonTextures: array [0..MONSTER_MAN] of TMonsterAnims;
250 WeapTextures: array [0..WP_LAST, 0..W_POS_LAST, 0..W_ACT_LAST] of TGLTexture;
251 ShotTextures: array [0..WEAPON_LAST] of TGLMultiTexture;
252 FlagTextures: array [0..FLAG_LAST] of TGLMultiTexture;
253 PunchTextures: array [Boolean, 0..2] of TGLMultiTexture; // [berserk, center/up/down]
254 VileFire: TGLMultiTexture;
255 InvulPenta: TGLTexture;
256 Models: array of record
257 anim: array [TDirection, 0..A_LAST] of record
258 base, mask: TGLMultiTexture;
259 end;
260 {$IFDEF ENABLE_GIBS}
261 gibs: record
262 base, mask: TGLTextureArray;
263 rect: TRectArray;
264 end;
265 {$ENDIF}
266 end;
268 {$IFDEF ENABLE_SHELLS}
269 ShellTextures: array [0..SHELL_LAST] of TGLTexture;
270 {$ENDIF}
271 {$IFDEF ENABLE_GFX}
272 GFXTextures: array [0..R_GFX_LAST] of TGLMultiTexture;
273 gfxlist: array of record
274 typ: Byte;
275 x, y: Integer;
276 oldX, oldY: Integer;
277 anim: TAnimInfo;
278 time: LongWord;
279 frame: LongInt;
280 end = nil;
281 {$ENDIF}
283 FlagFrame: LongInt;
284 plist: TBinHeapPanelDraw = nil;
286 class function TBinHeapPanelDrawCmp.less (const a, b: TPanel): Boolean; inline;
287 begin
288 if a.tag < b.tag then begin result := true; exit; end;
289 if a.tag > b.tag then begin result := false; exit; end;
290 result := a.arrIdx < b.arrIdx;
291 end;
293 procedure r_Map_Initialize;
294 begin
295 FlagFrame := 0;
296 plist := TBinHeapPanelDraw.Create();
297 end;
299 procedure r_Map_Finalize;
300 begin
301 plist.Free;
302 FlagFrame := 0;
303 end;
305 procedure r_Map_FreeModel (i: Integer);
306 var a: Integer; d: TDirection;
307 begin
308 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
309 begin
310 for a := A_STAND to A_LAST do
311 begin
312 if Models[i].anim[d, a].base <> nil then
313 Models[i].anim[d, a].base.Free;
314 if Models[i].anim[d, a].mask <> nil then
315 Models[i].anim[d, a].mask.Free;
316 Models[i].anim[d, a].base := nil;
317 Models[i].anim[d, a].mask := nil;
318 end;
319 end;
320 {$IFDEF ENABLE_GIBS}
321 if Models[i].gibs.base <> nil then
322 for a := 0 to High(Models[i].gibs.base) do
323 Models[i].gibs.base[a].Free;
324 if Models[i].gibs.mask <> nil then
325 for a := 0 to High(Models[i].gibs.mask) do
326 Models[i].gibs.mask[a].Free;
327 Models[i].gibs.base := nil;
328 Models[i].gibs.mask := nil;
329 Models[i].gibs.rect := nil;
330 {$ENDIF}
331 end;
333 procedure r_Map_LoadModel (i: Integer);
334 var prefix: AnsiString; a: Integer; d: TDirection; m: ^TPlayerModelInfo;
335 begin
336 ASSERT(i < Length(Models));
337 ASSERT(i < Length(PlayerModelsArray));
338 r_Map_FreeModel(i);
339 m := @PlayerModelsArray[i];
340 prefix := m.FileName + ':TEXTURES/';
341 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
342 begin
343 for a := A_STAND to A_LAST do
344 begin
345 Models[i].anim[d, a].base := nil;
346 Models[i].anim[d, a].mask := nil;
347 if m.anim[d, a].resource <> '' then
348 Models[i].anim[d, a].base := r_Textures_LoadMultiFromFileAndInfo(prefix + m.anim[d, a].resource, 64, 64, m.anim[d, a].frames, true);
349 if m.anim[d, a].mask <> '' then
350 Models[i].anim[d, a].mask := r_Textures_LoadMultiFromFileAndInfo(prefix + m.anim[d, a].mask, 64, 64, m.anim[d, a].frames, true);
351 end
352 end;
353 {$IFDEF ENABLE_GIBS}
354 Models[i].gibs.base := nil;
355 Models[i].gibs.mask := nil;
356 Models[i].gibs.rect := nil;
357 if m.GibsCount > 0 then
358 begin
359 SetLength(Models[i].gibs.base, m.GibsCount);
360 SetLength(Models[i].gibs.mask, m.GibsCount);
361 SetLength(Models[i].gibs.rect, m.GibsCount);
362 for a := 0 to m.GibsCount - 1 do
363 Models[i].gibs.rect[a] := DefaultGibSize;
364 if r_Textures_LoadStreamFromFile(prefix + m.GibsResource, 32, 32, m.GibsCount, m.GibsCount, Models[i].gibs.base, Models[i].gibs.rect) then
365 begin
366 if r_Textures_LoadStreamFromFile(prefix + m.GibsMask, 32, 32, m.GibsCount, m.GibsCount, Models[i].gibs.mask, nil) then
367 begin
368 // ok
369 end;
370 end;
371 end;
372 {$ENDIF}
373 end;
375 procedure r_Map_LoadMonsterAnim (m, a: Integer; d: TDirection);
376 const dir: array [TDirection] of AnsiString = ('_L', '');
377 var w, h, count: Integer;
378 begin
379 count := MONSTER_ANIMTABLE[m].AnimCount[a];
380 if count > 0 then
381 begin
382 w := MTABLE[m].w;
383 h := MTABLE[m].h;
384 if (m = MONSTER_SOUL) and (a = ANIM_DIE) then
385 begin
386 // special case
387 w := 128;
388 h := 128;
389 end;
390 MonTextures[m, a, d] := r_Textures_LoadMultiFromFileAndInfo(
391 GameWAD + ':MTEXTURES/' + MONSTERTABLE[m].name + '_' + ANIMTABLE[a].name + dir[d],
392 w,
393 h,
394 count,
395 False
396 );
397 end
398 else
399 MonTextures[m, a, d] := nil;
400 end;
402 procedure r_Map_Load;
403 const
404 WeapName: array [0..WP_LAST] of AnsiString = ('', 'CSAW', 'HGUN', 'SG', 'SSG', 'MGUN', 'RKT', 'PLZ', 'BFG', 'SPL', 'FLM');
405 WeapPos: array [0..W_POS_LAST] of AnsiString = ('', '_UP', '_DN');
406 WeapAct: array [0..W_ACT_LAST] of AnsiString = ('', '_FIRE');
407 PunchName: array [Boolean] of AnsiString = ('PUNCH', 'PUNCHB');
408 var
409 i, j, k: Integer; d: TDirection; b: Boolean;
410 begin
411 // --------- items --------- //
412 for i := 0 to ITEM_LAST do
413 begin
414 Items[i].tex := r_Textures_LoadMultiFromFileAndInfo(
415 GameWAD + ':TEXTURES/' + ItemAnim[i].name,
416 ItemAnim[i].w,
417 ItemAnim[i].h,
418 ItemAnim[i].anim.frames,
419 false
420 );
421 Items[i].frame := 0;
422 end;
423 // --------- monsters --------- //
424 for i := MONSTER_DEMON to MONSTER_MAN do
425 for j := 0 to ANIM_LAST do
426 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
427 r_Map_LoadMonsterAnim(i, j, d);
428 VileFire := r_Textures_LoadMultiFromFileAndInfo(GameWAD + ':TEXTURES/FIRE', 64, 128, VileFireAnim.frames);
429 // --------- player models --------- //
430 if PlayerModelsArray <> nil then
431 begin
432 SetLength(Models, Length(PlayerModelsArray));
433 for i := 0 to High(PlayerModelsArray) do
434 r_Map_LoadModel(i);
435 end;
436 // --------- player weapons --------- //
437 for i := 1 to WP_LAST do
438 for j := 0 to W_POS_LAST do
439 for k := 0 to W_ACT_LAST do
440 WeapTextures[i, j, k] := r_Textures_LoadFromFile(GameWAD + ':WEAPONS\' + WeapName[i] + WeapPos[j] + WeapAct[k]);
441 // --------- gfx animations --------- //
442 {$IFDEF ENABLE_GFX}
443 for i := 1 to R_GFX_LAST do
444 if GFXAnim[i].anim.frames > 0 then
445 GFXTextures[i] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/' + GFXAnim[i].name, GFXAnim[i].w, GFXAnim[i].h, GFXAnim[i].anim.frames);
446 {$ENDIF}
447 // --------- shots --------- //
448 for i := 0 to WEAPON_LAST do
449 if ShotAnim[i].anim.frames > 0 then
450 ShotTextures[i] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/' + ShotAnim[i].name, ShotAnim[i].w, ShotAnim[i].h, ShotAnim[i].anim.frames);
451 // --------- flags --------- //
452 FlagTextures[FLAG_NONE] := nil;
453 FlagTextures[FLAG_RED] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/FLAGRED', 64, 64, 5);
454 FlagTextures[FLAG_BLUE] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/FLAGBLUE', 64, 64, 5);
455 // FlagTextures[FLAG_DOM] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/FLAGDOM', 64, 64, 8);
456 // --------- shells --------- //
457 {$IFDEF ENABLE_SHELLS}
458 for i := 0 to SHELL_LAST do
459 ShellTextures[i] := r_Textures_LoadFromFile(GameWad + ':TEXTURES/' + ShellAnim[i].name);
460 {$ENDIF}
461 // --------- punch --------- //
462 for b := false to true do
463 begin
464 for i := 0 to 2 do
465 PunchTextures[b, i] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':WEAPONS/' + PunchName[b] + WeapPos[i], 64, 64, PunchAnim.frames);
466 end;
467 // --------- other --------- //
468 InvulPenta := r_Textures_LoadFromFile(GameWad + ':TEXTURES/PENTA');
469 end;
471 procedure r_Map_Free;
472 var i, j, k: Integer; d: TDirection; b: Boolean;
473 begin
474 if InvulPenta <> nil then
475 InvulPenta.Free;
476 InvulPenta := nil;
477 for b := false to true do
478 begin
479 for i := 0 to 2 do
480 begin
481 if PunchTextures[b, i] <> nil then
482 PunchTextures[b, i].Free;
483 PunchTextures[b, i] := nil;
484 end;
485 end;
486 {$IFDEF ENABLE_SHELLS}
487 for i := 0 to SHELL_LAST do
488 begin
489 if ShellTextures[i] <> nil then
490 ShellTextures[i].Free;
491 ShellTextures[i] := nil;
492 end;
493 {$ENDIF}
494 for i := 0 to FLAG_LAST do
495 begin
496 if FlagTextures[i] <> nil then
497 FlagTextures[i].Free;
498 FlagTextures[i] := nil;
499 end;
500 for i := 0 to WEAPON_LAST do
501 begin
502 if ShotTextures[i] <> nil then
503 ShotTextures[i].Free;
504 ShotTextures[i] := nil;
505 end;
506 {$IFDEF ENABLE_GFX}
507 gfxlist := nil;
508 for i := 0 to R_GFX_LAST do
509 begin
510 if GFXTextures[i] <> nil then
511 GFXTextures[i].Free;
512 GFXTextures[i] := nil;
513 end;
514 {$ENDIF}
515 for i := 1 to WP_LAST do
516 begin
517 for j := 0 to W_POS_LAST do
518 begin
519 for k := 0 to W_ACT_LAST do
520 begin
521 if WeapTextures[i, j, k] <> nil then
522 WeapTextures[i, j, k].Free;
523 WeapTextures[i, j, k] := nil;
524 end;
525 end;
526 end;
527 if Models <> nil then
528 for i := 0 to High(Models) do
529 r_Map_FreeModel(i);
530 for i := MONSTER_DEMON to MONSTER_MAN do
531 begin
532 for j := 0 to ANIM_LAST do
533 begin
534 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
535 begin
536 if MonTextures[i, j, d] <> nil then
537 MonTextures[i, j, d].Free;
538 MonTextures[i, j, d] := nil;
539 end;
540 end;
541 end;
542 for i := 0 to ITEM_LAST do
543 begin
544 if Items[i].tex <> nil then
545 Items[i].tex.Free;
546 Items[i].tex := nil;
547 end;
548 end;
550 procedure r_Map_LoadTextures;
551 const DefaultAnimInfo: TAnimInfo = (loop: true; delay: 1; frames: 1; back: false);
552 var i, n: Integer; txt: TAnimTextInfo;
553 begin
554 if Textures <> nil then
555 begin
556 n := Length(Textures);
557 SetLength(RenTextures, n);
558 for i := 0 to n - 1 do
559 begin
560 txt.anim := DefaultAnimInfo;
561 RenTextures[i].tex := nil;
562 case Textures[i].TextureName of
563 TEXTURE_NAME_WATER: RenTextures[i].spec := TEXTURE_SPECIAL_WATER;
564 TEXTURE_NAME_ACID1: RenTextures[i].spec := TEXTURE_SPECIAL_ACID1;
565 TEXTURE_NAME_ACID2: RenTextures[i].spec := TEXTURE_SPECIAL_ACID2;
566 else
567 RenTextures[i].spec := 0;
568 e_LogWritefln('r_Map_LoadTextures: begin load texture: %s', [Textures[i].FullName]);
569 RenTextures[i].tex := r_Textures_LoadMultiTextFromFile(Textures[i].FullName, txt);
570 e_LogWritefln('r_Map_LoadTextures: end load texture: %s', [Textures[i].FullName]);
571 if RenTextures[i].tex = nil then
572 e_LogWritefln('r_Map_LoadTextures: failed to load texture: %s', [Textures[i].FullName]);
573 end;
574 RenTextures[i].anim := txt.anim;
575 end;
576 end;
577 if gMapInfo.SkyFullName <> '' then
578 SkyTexture := r_Textures_LoadFromFile(gMapInfo.SkyFullName);
579 plist.Clear;
580 end;
582 procedure r_Map_FreeTextures;
583 var i: Integer;
584 begin
585 plist.Clear;
586 if SkyTexture <> nil then
587 SkyTexture.Free;
588 SkyTexture := nil;
589 if RenTextures <> nil then
590 for i := 0 to High(RenTextures) do
591 if RenTextures[i].tex <> nil then
592 RenTextures[i].tex.Free;
593 RenTextures := nil;
594 end;
596 procedure r_Map_DrawPanel (p: TPanel);
597 var Texture: Integer; t: TGLMultiTexture; tex: TGLTexture; count, frame: LongInt; a: TAnimInfo;
598 begin
599 ASSERT(p <> nil);
600 if p.FCurTexture >= 0 then
601 begin
602 Texture := p.TextureIDs[p.FCurTexture].Texture;
603 t := RenTextures[Texture].tex;
604 if (RenTextures[Texture].spec = 0) or (t <> nil) then
605 begin
606 count := 0; frame := 0;
607 if p.AnimTime <= gTime then
608 begin
609 a := RenTextures[Texture].anim;
610 a.loop := p.AnimLoop;
611 g_Anim_GetFrameByTime(a, (gTime - p.AnimTime) DIV GAME_TICK, count, frame);
612 end;
613 if t <> nil then
614 begin
615 tex := t.GetTexture(frame);
616 r_Draw_TextureRepeat(tex, p.x, p.y, p.width, p.height, false, 255, 255, 255, 255 - p.alpha, p.blending);
617 end
618 else
619 r_Draw_TextureRepeat(nil, p.x, p.y, p.width, p.height, false, 255, 255, 255, 255, false);
620 end;
622 if t = nil then
623 begin
624 case RenTextures[Texture].spec of
625 TEXTURE_SPECIAL_WATER: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 0, 0, 255, 255);
626 TEXTURE_SPECIAL_ACID1: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 0, 230, 0, 255);
627 TEXTURE_SPECIAL_ACID2: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 230, 0, 0, 255);
628 end
629 end
630 end
631 end;
633 procedure r_Map_DrawPanelType (panelTyp: DWORD);
634 var tagMask, i: Integer; p: TPanel;
635 begin
636 i := 0;
637 tagMask := PanelTypeToTag(panelTyp);
638 while plist.count > 0 do
639 begin
640 p := TPanel(plist.Front());
641 if (p.tag and tagMask) = 0 then
642 break;
643 r_Map_DrawPanel(p);
644 Inc(i);
645 plist.PopFront
646 end;
647 end;
649 procedure r_Map_DrawItems (x, y, w, h: Integer; drop: Boolean);
650 var i, fX, fY: Integer; it: PItem; t: TGLMultiTexture; tex: TGLTexture;
651 begin
652 if ggItems <> nil then
653 begin
654 for i := 0 to High(ggItems) do
655 begin
656 it := @ggItems[i];
657 if it.used and it.alive and (it.dropped = drop) and (it.ItemType > ITEM_NONE) and (it.ItemType <= ITEM_LAST) then
658 begin
659 t := Items[it.ItemType].tex;
660 if g_Collide(it.obj.x, it.obj.y, t.width, t.height, x, y, w, h) then
661 begin
662 it.obj.Lerp(gLerpFactor, fX, fY);
663 tex := t.GetTexture(Items[it.ItemType].frame);
664 r_Draw_TextureRepeat(tex, fX, fY, tex.width, tex.height, false, 255, 255, 255, 255, false);
665 end;
666 end;
667 end;
668 end;
669 // TODO draw g_debug_frames
670 end;
672 function r_Map_GetMonsterTexture (m, a: Integer; d: TDirection; out t: TGLMultiTexture; out dx, dy: Integer; out flip: Boolean): Boolean;
673 // var c: Integer;
674 begin
675 t := nil; dx := 0; dy := 0; flip := false;
676 result := MonTextures[m, a, d] <> nil;
677 if result = false then
678 begin
679 flip := true;
680 if d = TDirection.D_RIGHT then d := TDirection.D_LEFT else d := TDirection.D_RIGHT;
681 result := MonTextures[m, a, d] <> nil;
682 end;
683 if result = true then
684 begin
685 t := MonTextures[m, a, d];
686 if d = TDirection.D_LEFT then
687 begin
688 dx := MONSTER_ANIMTABLE[m].AnimDeltaLeft[a].X;
689 dy := MONSTER_ANIMTABLE[m].AnimDeltaLeft[a].Y;
690 end
691 else
692 begin
693 dx := MONSTER_ANIMTABLE[m].AnimDeltaRight[a].X;
694 dy := MONSTER_ANIMTABLE[m].AnimDeltaRight[a].Y;
695 end;
696 if flip then
697 begin
698 // c := (MONSTERTABLE[MonsterType].Rect.X - dx) + MONSTERTABLE[MonsterType].Rect.Width;
699 // dx := MTABLE[m].width - c - MONSTERTABLE[MonsterType].Rect.X;
700 dx := -dx;
701 end;
702 end;
703 end;
705 procedure r_Map_DrawMonsterAttack (constref mon: TMonster);
706 var o: TObj; count, frame: LongInt; tex: TGLTexture;
707 begin
708 if VileFire <> nil then
709 if (mon.MonsterType = MONSTER_VILE) and (mon.MonsterState = MONSTATE_SHOOT) then
710 if (mon.VileFireTime <= gTime) and GetPos(mon.MonsterTargetUID, @o) then
711 begin
712 g_Anim_GetFrameByTime(VileFireAnim, (gTime - mon.VileFireTime) DIV GAME_TICK, count, frame);
713 tex := VileFire.GetTexture(frame);
714 r_Draw_TextureRepeat(tex, o.x + o.rect.x + (o.rect.width div 2) - VILEFIRE_DX, o.y + o.rect.y + o.rect.height - VILEFIRE_DY, tex.width, tex.height, False, 255, 255, 255, 255, false);
715 end;
716 end;
718 procedure r_Map_DrawMonster (constref mon: TMonster);
719 var m, a, fX, fY, dx, dy: Integer; d: TDirection; flip: Boolean; t: TGLMultiTexture;
720 begin
721 m := mon.MonsterType;
722 a := mon.MonsterAnim;
723 d := mon.GameDirection;
725 mon.obj.Lerp(gLerpFactor, fX, fY);
727 if r_Map_GetMonsterTexture(m, a, d, t, dx, dy, flip) then
728 r_Draw_MultiTextureRepeat(t, mon.DirAnim[a, d], false, fX + dx, fY + dy, t.width, t.height, flip, 255, 255, 255, 255, false);
730 // TODO draw g_debug_frames
731 end;
733 procedure r_Map_DrawMonsters (x, y, w, h: Integer);
734 var i: Integer; m: TMonster;
735 begin
736 if gMonsters <> nil then
737 begin
738 for i := 0 to High(gMonsters) do
739 begin
740 m := gMonsters[i];
741 if m <> nil then
742 begin
743 r_Map_DrawMonsterAttack(m);
744 // TODO select from grid
745 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
746 r_Map_DrawMonster(m);
747 end;
748 end;
749 end;
750 end;
752 function r_Map_GetPlayerModelTex (i: Integer; var a: Integer; var d: TDirection; out flip: Boolean): Boolean;
753 begin
754 flip := false;
755 result := Models[i].anim[d, a].base <> nil;
756 if result = false then
757 begin
758 flip := true;
759 if d = TDirection.D_LEFT then d := TDirection.D_RIGHT else d := TDirection.D_LEFT;
760 result := Models[i].anim[d, a].base <> nil;
761 end;
762 end;
764 procedure r_Map_DrawPlayerModel (pm: TPlayerModel; x, y: Integer; alpha: Byte);
765 var a, pos, act, xx, yy, angle: Integer; d: TDirection; flip, back: Boolean; t: TGLMultiTexture; tex: TGLTexture; c: TRGB;
766 begin
767 a := pm.CurrentAnimation;
768 d := pm.Direction;
770 (* draw flag*)
771 t := FlagTextures[pm.Flag];
772 if (t <> nil) and not (a in [A_DIE1, A_DIE2]) then
773 begin
774 flip := d = TDirection.D_RIGHT;
775 angle := PlayerModelsArray[pm.id].FlagAngle;
776 xx := PlayerModelsArray[pm.id].FlagPoint.X;
777 yy := PlayerModelsArray[pm.id].FlagPoint.Y;
778 tex := t.GetTexture(FlagFrame);
779 r_Draw_TextureRepeatRotate(
780 tex,
781 x + IfThen(flip, 2 * FLAG_BASEPOINT.X - xx + 1, xx - 1) - FLAG_BASEPOINT.X,
782 y + yy - FLAG_BASEPOINT.Y + 1,
783 tex.width,
784 tex.height,
785 flip,
786 255, 255, 255, 255, false,
787 IfThen(flip, 64 - FLAG_BASEPOINT.X, FLAG_BASEPOINT.X),
788 FLAG_BASEPOINT.Y,
789 IfThen(flip, angle, -angle)
790 );
791 end;
793 (* draw weapon *)
794 if PlayerModelsArray[pm.id].HaveWeapon and not (a in [A_DIE1, A_DIE2, A_PAIN]) then
795 begin
796 case a of
797 A_SEEUP, A_ATTACKUP: pos := W_POS_UP;
798 A_SEEDOWN, A_ATTACKDOWN: pos := W_POS_DOWN;
799 else pos := W_POS_NORMAL;
800 end;
801 if (a in [A_ATTACK, A_ATTACKUP, A_ATTACKDOWN]) or pm.GetFire() then
802 act := W_ACT_FIRE
803 else
804 act := W_ACT_NORMAL;
805 tex := WeapTextures[pm.CurrentWeapon, pos, act];
806 if tex <> nil then
807 begin
808 xx := PlayerModelsArray[pm.id].WeaponPoints[pm.CurrentWeapon, a, d, pm.AnimState.CurrentFrame].X;
809 yy := PlayerModelsArray[pm.id].WeaponPoints[pm.CurrentWeapon, a, d, pm.AnimState.CurrentFrame].Y;
810 r_Draw_Texture(
811 tex,
812 x + xx,
813 y + yy,
814 tex.width,
815 tex.height,
816 d = TDirection.D_LEFT,
817 255, 255, 255, alpha, false
818 );
819 end;
820 end;
822 (* draw body *)
823 if r_Map_GetPlayerModelTex(pm.id, a, d, flip) then
824 begin
825 t := Models[pm.id].anim[d, a].base;
826 back := PlayerModelsArray[pm.id].anim[d, a].back;
827 r_Draw_MultiTextureRepeat(t, pm.AnimState, back, x, y, t.width, t.height, flip, 255, 255, 255, alpha, false);
828 t := Models[pm.id].anim[d, a].mask;
829 if t <> nil then
830 begin
831 c := pm.Color;
832 r_Draw_MultiTextureRepeat(t, pm.AnimState, back, x, y, t.width, t.height, flip, c.r, c.g, c.b, alpha, false);
833 end;
834 end;
835 end;
837 procedure r_Map_DrawPlayer (p, drawed: TPlayer);
838 var fX, fY, fSlope, ax, ay, w, h: Integer; b, flip: Boolean; t: TGLMultiTexture; tex: TGLTexture; alpha: Byte; count, frame: LongInt;
839 begin
840 if p.alive then
841 begin
842 fX := p.obj.x; fY := p.obj.y;
843 // TODO fix lerp
844 //p.obj.Lerp(gLerpFactor, fX, fY);
845 fSlope := nlerp(p.SlopeOld, p.obj.slopeUpLeft, gLerpFactor);
847 (* punch effect *)
848 if p.PunchTime <= gTime then
849 begin
850 g_Anim_GetFrameByTime(PunchAnim, (gTime - p.PunchTime) DIV GAME_TICK, count, frame);
851 if count < 1 then
852 begin
853 b := R_BERSERK in p.FRulez;
854 if p.FKeys[KEY_DOWN].pressed then
855 t := PunchTextures[b, 2]
856 else if p.FKeys[KEY_UP].pressed then
857 t := PunchTextures[b, 1]
858 else
859 t := PunchTextures[b, 0];
860 if t <> nil then
861 begin
862 flip := p.Direction = TDirection.D_LEFT;
863 ax := IfThen(flip, 15 - p.Obj.Rect.X, p.Obj.Rect.X - 15); // ???
864 ay := p.Obj.Rect.Y - 11;
865 tex := t.GetTexture(frame);
866 r_Draw_TextureRepeat(tex, fx + ax, fy + fSlope + ay, tex.width, tex.height, flip, 255, 255, 255, 255, false)
867 end;
868 end;
869 end;
871 (* invulnerability effect *)
872 if (InvulPenta <> nil) and (p.FMegaRulez[MR_INVUL] > gTime) and ((p <> drawed) or (p.SpawnInvul >= gTime)) then
873 begin
874 w := InvulPenta.width;
875 h := InvulPenta.height;
876 ax := p.Obj.Rect.X + (p.Obj.Rect.Width div 2) - (w div 2); // + IfThen(flip, +4, -2) // ???
877 ay := p.Obj.Rect.Y + (p.Obj.Rect.Height div 2) - (h div 2) - 7; // ???
878 r_Draw_Texture(InvulPenta, fx + ax, fy + ay + fSlope, w, h, false, 255, 255, 255, 255, false);
879 end;
881 (* invisibility effect *)
882 alpha := 255;
883 if p.FMegaRulez[MR_INVIS] > gTime then
884 begin
885 if (drawed <> nil) and ((p = drawed) or ((p.Team = drawed.Team) and (gGameSettings.GameMode <> GM_DM))) then
886 begin
887 if (p.FMegaRulez[MR_INVIS] - gTime > 2100) or not ODD((p.FMegaRulez[MR_INVIS] - gTime) div 300) then
888 alpha := 55;
889 end
890 else
891 alpha := 1; // ???
892 end;
894 r_Map_DrawPlayerModel(p.Model, fX, fY + fSlope, alpha);
895 end;
896 // TODO draw g_debug_frames
897 // TODO draw chat bubble
898 // TODO draw aim
899 end;
901 procedure r_Map_DrawPlayers (x, y, w, h: Integer; player: TPlayer);
902 var i: Integer;
903 begin
904 if gPlayers <> nil then
905 for i := 0 to High(gPlayers) do
906 if gPlayers[i] <> nil then
907 r_Map_DrawPlayer(gPlayers[i], player);
908 end;
910 {$IFDEF ENABLE_GIBS}
911 function r_Map_GetGibSize (m, i: Integer): TRectWH;
912 begin
913 result := Models[m].gibs.rect[i];
914 end;
916 procedure r_Map_DrawGibs (x, y, w, h: Integer);
917 var i, fx, fy, m, id, rx, ry, ra: Integer; p: PObj; t: TGLTexture;
918 begin
919 if gGibs <> nil then
920 begin
921 for i := 0 to High(gGibs) do
922 begin
923 if gGibs[i].alive then
924 begin
925 p := @gGibs[i].Obj;
926 if g_Obj_Collide(x, y, w, h, p) then
927 begin
928 p.Lerp(gLerpFactor, fx, fy);
929 id := gGibs[i].GibID;
930 m := gGibs[i].ModelID;
931 t := Models[m].gibs.base[id];
932 if t <> nil then
933 begin
934 rx := p.Rect.X + p.Rect.Width div 2;
935 ry := p.Rect.Y + p.Rect.Height div 2;
936 ra := gGibs[i].RAngle;
937 r_Draw_TextureRepeatRotate(t, fx, fy, t.width, t.height, false, 255, 255, 255, 255, false, rx, ry, ra);
938 t := Models[m].gibs.mask[id];
939 if t <> nil then
940 r_Draw_TextureRepeatRotate(t, fx, fy, t.width, t.height, false, gGibs[i].Color.R, gGibs[i].Color.G, gGibs[i].Color.B, 255, false, rx, ry, ra);
941 // r_Draw_TextureRepeatRotate(nil, fx + p.Rect.X, fy + 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);
942 end;
943 end;
944 end;
945 end;
946 end;
947 // TODO draw g_debug_frames
948 end;
949 {$ENDIF}
951 {$IFDEF ENABLE_CORPSES}
952 procedure r_Map_DrawCorpses (x, y, w, h: Integer);
953 var i, fX, fY: Integer; p: TCorpse;
954 begin
955 if gCorpses <> nil then
956 begin
957 for i := 0 to High(gCorpses) do
958 begin
959 p := gCorpses[i];
960 if (p <> nil) and (p.state <> CORPSE_STATE_REMOVEME) and (p.model <> nil) then
961 begin
962 p.obj.Lerp(gLerpFactor, fX, fY);
963 r_Map_DrawPlayerModel(p.model, fX, fY, 255);
964 end;
965 end;
966 end;
967 // TODO draw g_debug_frames
968 end;
969 {$ENDIF}
971 {$IFDEF ENABLE_GFX}
972 function r_Map_GetGFXID (): Integer;
973 var i: Integer;
974 begin
975 i := 0;
976 if gfxlist <> nil then
977 begin
978 while (i < Length(gfxlist)) and (gfxlist[i].typ > 0) do
979 Inc(i);
980 if i >= Length(gfxlist) then
981 SetLength(gfxlist, Length(gfxlist) + 1)
982 end
983 else
984 SetLength(gfxlist, 1);
985 gfxlist[i].typ := R_GFX_NONE;
986 result := i
987 end;
989 procedure r_Map_NewGFX (typ, x, y: Integer);
990 var i: Integer;
991 begin
992 if gpart_dbg_enabled and (typ > 0) and (typ <= R_GFX_LAST) then
993 begin
994 i := r_Map_GetGFXID();
995 if i >= 0 then
996 begin
997 gfxlist[i].typ := typ;
998 gfxlist[i].x := x;
999 gfxlist[i].y := y;
1000 gfxlist[i].oldX := x;
1001 gfxlist[i].oldY := y;
1002 gfxlist[i].anim := GFXAnim[typ].anim;
1003 gfxlist[i].time := gTime DIV GAME_TICK;
1004 gfxlist[i].frame := 0;
1005 INC(gfxlist[i].anim.delay, Random(GFXAnim[typ].rdelay));
1006 end;
1007 end;
1008 end;
1010 procedure r_Map_UpdateGFX (tick: LongWord);
1011 var i: Integer; count: LongInt;
1012 begin
1013 if gfxlist <> nil then
1014 begin
1015 for i := 0 to High(gfxlist) do
1016 begin
1017 if (gfxlist[i].typ > 0) and (tick >= gfxlist[i].time) then
1018 begin
1019 g_Anim_GetFrameByTime(gfxlist[i].anim, tick - gfxlist[i].time, count, gfxlist[i].frame);
1020 if count < 1 then
1021 begin
1022 gfxlist[i].oldX := gfxlist[i].x;
1023 gfxlist[i].oldY := gfxlist[i].y;
1024 case gfxlist[i].typ of
1025 R_GFX_FLAME, R_GFX_SMOKE:
1026 begin
1027 if Random(3) = 0 then
1028 gfxlist[i].x := gfxlist[i].x - 1 + Random(3);
1029 if Random(2) = 0 then
1030 gfxlist[i].y := gfxlist[i].y - Random(2);
1031 end;
1032 end;
1033 end
1034 else
1035 gfxlist[i].typ := R_GFX_NONE;
1036 end;
1037 end;
1038 end;
1039 end;
1041 procedure r_Map_DrawGFX (x, y, w, h: Integer);
1042 var i, fx, fy, typ: Integer; t: TGLMultiTexture; tex: TGLTexture;
1043 begin
1044 if gfxlist <> nil then
1045 begin
1046 for i := 0 to High(gfxlist) do
1047 begin
1048 if gfxlist[i].typ > 0 then
1049 begin
1050 typ := gfxlist[i].typ;
1051 t := GFXTextures[typ];
1052 if t <> nil then
1053 begin
1054 fx := nlerp(gfxlist[i].oldX, gfxlist[i].x, gLerpFactor);
1055 fy := nlerp(gfxlist[i].oldY, gfxlist[i].y, gLerpFactor);
1056 tex := t.GetTexture(gfxlist[i].frame);
1057 r_Draw_TextureRepeat(tex, fx, fy, tex.width, tex.height, false, 255, 255, 255, 255 - GFXAnim[typ].alpha, false);
1058 end;
1059 end;
1060 end;
1061 end;
1062 end;
1064 procedure r_Map_DrawParticles (x, y, w, h: Integer);
1065 var i, fx, fy: Integer;
1066 begin
1067 if gpart_dbg_enabled and (Particles <> nil) then
1068 begin
1069 glDisable(GL_TEXTURE_2D);
1070 if (g_dbg_scale < 0.6) then
1071 glPointSize(1)
1072 else if (g_dbg_scale > 1.3) then
1073 glPointSize(g_dbg_scale + 1)
1074 else
1075 glPointSize(2);
1076 glDisable(GL_POINT_SMOOTH);
1077 glEnable(GL_BLEND);
1078 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1080 glBegin(GL_POINTS);
1081 for i := 0 to High(Particles) do
1082 begin
1083 if Particles[i].alive then
1084 begin
1085 fx := nlerp(Particles[i].oldX, Particles[i].x, gLerpFactor);
1086 fy := nlerp(Particles[i].oldY, Particles[i].y, gLerpFactor);
1087 glColor4ub(Particles[i].red, Particles[i].green, Particles[i].blue, Particles[i].alpha);
1088 glVertex2f(fx, fy);
1089 end;
1090 end;
1091 glEnd;
1093 glDisable(GL_BLEND);
1094 end;
1095 end;
1096 {$ENDIF}
1098 procedure r_Map_DrawShots (x, y, w, h: Integer);
1099 var i, a, fX, fY, pX, pY, typ: Integer; count, frame: LongInt; t: TGLMultiTexture; tex: TGLTexture;
1100 begin
1101 if Shots <> nil then
1102 begin
1103 for i := 0 to High(Shots) do
1104 begin
1105 typ := Shots[i].ShotType;
1106 if typ <> 0 then
1107 begin
1108 t := ShotTextures[typ];
1109 if t <> nil then
1110 begin
1111 a := 0;
1112 case typ of
1113 WEAPON_ROCKETLAUNCHER, WEAPON_BARON_FIRE, WEAPON_MANCUB_FIRE, WEAPON_SKEL_FIRE:
1114 a := -GetAngle2(Shots[i].Obj.Vel.X, Shots[i].Obj.Vel.Y)
1115 end;
1116 Shots[i].Obj.Lerp(gLerpFactor, fX, fY);
1117 pX := Shots[i].Obj.Rect.Width div 2;
1118 pY := Shots[i].Obj.Rect.Height div 2;
1119 g_Anim_GetFrameByTime(ShotAnim[typ].anim, (gTime - Shots[i].time) DIV GAME_TICK, count, frame);
1120 tex := t.GetTexture(frame);
1121 r_Draw_TextureRepeatRotate(tex, fX, fY, tex.width, tex.height, false, 255, 255, 255, 255, false, pX, pY, a);
1122 end;
1123 end;
1124 end;
1125 end;
1126 // TODO draw g_debug_frames
1127 end;
1129 procedure r_Map_DrawFlags (x, y, w, h: Integer);
1130 var i, dx, fx, fy: Integer; flip: Boolean; t: TGLMultiTexture; tex: TGLTexture;
1131 begin
1132 if gGameSettings.GameMode = GM_CTF then
1133 begin
1134 for i := FLAG_RED to FLAG_BLUE do
1135 begin
1136 if not (gFlags[i].state in [FLAG_STATE_NONE, FLAG_STATE_CAPTURED]) then
1137 begin
1138 gFlags[i].Obj.Lerp(gLerpFactor, fx, fy);
1139 flip := gFlags[i].Direction = TDirection.D_LEFT;
1140 if flip then dx := -1 else dx := +1;
1141 t := FlagTextures[i];
1142 tex := t.GetTexture(FlagFrame);
1143 r_Draw_TextureRepeat(tex, fx + dx, fy + 1, tex.width, tex.height, flip, 255, 255, 255, 255, false)
1144 end;
1145 end;
1146 end;
1147 // TODO g_debug_frames
1148 end;
1150 {$IFDEF ENABLE_SHELLS}
1151 procedure r_Map_DrawShells (x, y, w, h: Integer);
1152 var i, fx, fy, typ: Integer; t: TGLTexture; p: PObj;
1153 begin
1154 if gShells <> nil then
1155 begin
1156 for i := 0 to High(gShells) do
1157 begin
1158 if gShells[i].alive then
1159 begin
1160 typ := gShells[i].SType;
1161 if typ <= SHELL_LAST then
1162 begin
1163 p := @gShells[i].Obj;
1164 if g_Obj_Collide(x, y, w, h, p) then
1165 begin
1166 t := ShellTextures[typ];
1167 if t <> nil then
1168 begin
1169 p.Lerp(gLerpFactor, fx, fy);
1170 r_Draw_TextureRepeatRotate(t, fx, fy, t.width, t.height, false, 255, 255, 255, 255, false, ShellAnim[typ].dx, ShellAnim[typ].dy, gShells[i].RAngle);
1171 end;
1172 end;
1173 end;
1174 end;
1175 end;
1176 end;
1177 end;
1178 {$ENDIF}
1180 procedure r_Map_CalcSkyParallax (cx, cy, vw, vh, sw, sh, mw, mh: LongInt; out x, y, w, h: LongInt);
1181 const
1182 factor = 120; (* size ratio between view and sky (120%) *)
1183 limit = 100; (* max speed for parallax *)
1184 var
1185 msw, msh, mvw, mvh, svw, svh: LongInt;
1186 begin
1187 msw := vw * factor div 100;
1188 msh := vh * factor div 100;
1189 r_Common_CalcAspect(sw, sh, msw, msh, (sw / sh) <= (msw / msh), w, h);
1191 (* calc x parallax or sky center on speed limit *)
1192 mvw := MAX(1, mw - vw);
1193 svw := w - vw;
1194 if 100 * svw div mvw <= limit then
1195 x := -cx * svw div mvw
1196 else
1197 x := -svw div 2;
1199 (* calc y parallax or sky center on speed limit *)
1200 mvh := MAX(1, mh - vh);
1201 svh := h - vh;
1202 if 100 * svh div mvh <= limit then
1203 y := -cy * svh div mvh
1204 else
1205 y := -svh div 2;
1207 (* handle out of map bounds *)
1208 if x > 0 then x := 0;
1209 if y > 0 then y := 0;
1210 if x < -svw then x := -svw;
1211 if y < -svh then y := -svh;
1212 end;
1214 procedure r_Map_DrawScreenEffect (x, y, w, h, level: Integer; r, g, b: Byte);
1215 var i: Integer;
1216 begin
1217 if level > 0 then
1218 begin
1219 case level of
1220 0..14: i := 0;
1221 15..34: i := 1;
1222 35..54: i := 2;
1223 55..74: i := 3;
1224 75..94: i := 4;
1225 else i := 5
1226 end;
1227 r_Draw_FillRect(x, y, x + w, y + h, r, g, b, i * 50)
1228 end;
1229 end;
1231 procedure r_Map_DrawScreenEffects (x, y, w, h: Integer; p: TPlayer);
1232 begin
1233 if p <> nil then
1234 begin
1235 r_Map_DrawScreenEffect(x, y, w, h, p.pain, 255, 0, 0);
1236 r_Map_DrawScreenEffect(x, y, w, h, p.pickup, 150, 200, 150);
1237 if (p.FMegaRulez[MR_INVUL] >= gTime) and (p.SpawnInvul < gTime) then
1238 begin
1239 if ((p.FMegaRulez[MR_INVUL] - gTime) > 2100) or not ODD((p.FMegaRulez[MR_INVUL] - gTime) div 300) then
1240 r_Draw_InvertRect(x, y, x + w, y + h, 191, 191, 191, 255);
1241 end;
1242 if p.FMegaRulez[MR_SUIT] >= gTime then
1243 begin
1244 if ((p.FMegaRulez[MR_SUIT] - gTime) > 2100) or not ODD((p.FMegaRulez[MR_SUIT] - gTime) div 300) then
1245 r_Draw_FillRect(x, y, x + w, y + h, 0, 96, 0, 55);
1246 end;
1247 if (p.Berserk >= 0) and (p.Berserk >= gTime) and (gFlash = 2) then
1248 begin
1249 r_Draw_FillRect(x, y, x + w, y + h, 255, 0, 0, 55);
1250 end;
1251 end;
1252 end;
1254 procedure r_Map_Draw (x, y, w, h, camx, camy: Integer; player: TPlayer);
1255 var iter: TPanelGrid.Iter; p: PPanel; cx, cy, cw, ch, xx, yy, ww, hh: Integer; sx, sy, sw, sh: LongInt; l, t, r, b: Integer;
1256 begin
1257 r_Draw_GetRect(l, t, r, b);
1258 r_Draw_SetRect(x, y, x + w, y + h);
1259 glTranslatef(x, y, 0);
1261 (* camera rect *)
1262 cx := (camx - w) + w div 2;
1263 cy := (camy - h) + h div 2;
1264 cw := w;
1265 ch := h;
1267 (* camera bounds *)
1268 if g_dbg_ignore_bounds = false then
1269 begin
1270 if cx + cw > gMapInfo.Width then
1271 cx := gMapInfo.Width - cw;
1272 if cy + ch > gMapInfo.Height then
1273 cy := gMapInfo.Height - ch;
1274 if cx < 0 then
1275 cx := 0;
1276 if cy < 0 then
1277 cy := 0;
1278 end;
1280 (* map bounds *)
1281 xx := cx;
1282 yy := cy;
1283 ww := cw;
1284 hh := ch;
1285 if xx + ww > gMapInfo.Width then
1286 xx := gMapInfo.Width - ww;
1287 if yy + hh > gMapInfo.Height then
1288 yy := gMapInfo.Height - hh;
1289 if xx < 0 then
1290 xx := 0;
1291 if yy < 0 then
1292 yy := 0;
1294 plist.Clear;
1295 iter := mapGrid.ForEachInAABB(xx, yy, ww, hh, GridDrawableMask);
1296 for p in iter do
1297 if ((p^.tag and GridTagDoor) <> 0) = p^.door then
1298 plist.Insert(p^);
1299 iter.Release;
1301 glPushMatrix;
1302 if DebugCameraScale <> 1.0 then
1303 begin
1304 glTranslatef(cw div 2, ch div 2, 0);
1305 glScalef(DebugCameraScale, DebugCameraScale, 1);
1306 glTranslatef(-w div 2, -h div 2, 0);
1307 end;
1309 if SkyTexture <> nil then
1310 begin
1311 r_Map_CalcSkyParallax(cx, cy, w, h, SkyTexture.width, SkyTexture.height, gMapInfo.Width, gMapInfo.Height, sx, sy, sw, sh);
1312 r_Draw_Texture(SkyTexture, sx, sy, sw, sh, false, 255, 255, 255, 255, false);
1313 end;
1315 glTranslatef(-cx, -cy, 0);
1316 r_Map_DrawPanelType(PANEL_BACK);
1317 r_Map_DrawPanelType(PANEL_STEP);
1318 r_Map_DrawItems(xx, yy, ww, hh, false);
1319 r_Map_DrawShots(xx, yy, ww, hh);
1320 {$IFDEF ENABLE_SHELLS}
1321 r_Map_DrawShells(xx, yy, ww, hh);
1322 {$ENDIF}
1323 r_Map_DrawPlayers(xx, yy, ww, hh, player);
1324 {$IFDEF ENABLE_GIBS}
1325 r_Map_DrawGibs(xx, yy, ww, hh);
1326 {$ENDIF}
1327 {$IFDEF ENABLE_CORPSES}
1328 r_Map_DrawCorpses(xx, yy, ww, hh);
1329 {$ENDIF}
1330 r_Map_DrawPanelType(PANEL_WALL);
1331 r_Map_DrawMonsters(xx, yy, ww, hh);
1332 r_Map_DrawItems(xx, yy, ww, hh, true);
1333 r_Map_DrawPanelType(PANEL_CLOSEDOOR);
1334 {$IFDEF ENABLE_GFX}
1335 r_Map_DrawParticles(xx, yy, ww, hh);
1336 r_Map_DrawGFX(xx, yy, ww, hh);
1337 {$ENDIF}
1338 r_Map_DrawFlags(xx, yy, ww, hh);
1339 r_Map_DrawPanelType(PANEL_ACID1);
1340 r_Map_DrawPanelType(PANEL_ACID2);
1341 r_Map_DrawPanelType(PANEL_WATER);
1342 r_Map_DrawPanelType(PANEL_FORE);
1343 // TODO draw monsters health bar
1344 // TODO draw players health bar
1345 // TODO draw players indicators
1346 if DebugCameraScale <> 1.0 then
1347 begin
1348 r_Draw_Rect (cx, cy, cx + cw, cy + ch, 0, 255, 0, 255);
1349 r_Draw_Rect (xx, yy, xx + ww, yy + hh, 255, 0, 0, 255);
1350 end;
1351 glPopMatrix;
1353 r_Map_DrawScreenEffects(x, y, w, h, player);
1355 // TODO draw minimap (gShowMap)
1356 // TODO draw g_debug_player
1358 glTranslatef(-x, -y, 0);
1359 r_Draw_SetRect(l, t, r, b);
1360 end;
1362 procedure r_Map_Update;
1363 var i, count, tick: LongInt;
1364 begin
1365 tick := gTime div GAME_TICK;
1366 for i := 0 to ITEM_LAST do
1367 g_Anim_GetFrameByTime(ItemAnim[i].anim, tick, count, Items[i].frame);
1368 r_Map_UpdateGFX(tick);
1369 g_Anim_GetFrameByTime(FlagAnim, tick, count, FlagFrame);
1370 end;
1372 initialization
1373 conRegVar('r_debug_camera_scale', @DebugCameraScale, 0.0001, 1000.0, '', '');
1374 DebugCameraScale := 1.0;
1375 end.