DEADSOFTWARE

gl: disable flamethrower shots
[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 procedure r_Map_Initialize;
21 procedure r_Map_Finalize;
23 procedure r_Map_Load;
24 procedure r_Map_Free;
26 procedure r_Map_LoadTextures;
27 procedure r_Map_FreeTextures;
29 procedure r_Map_NewGFX (typ, x, y: Integer);
31 procedure r_Map_Update;
33 procedure r_Map_Draw (x, y, w, h, camx, camy: Integer);
35 implementation
37 uses
38 {$IFDEF USE_GLES1}
39 GLES11,
40 {$ELSE}
41 GL, GLEXT,
42 {$ENDIF}
43 e_log,
44 binheap, MAPDEF, utils,
45 g_options, g_textures, g_basic, g_base, g_phys,
46 g_game, g_map, g_panel, g_items, g_monsters, g_playermodel, g_player, g_weapons,
47 {$IFDEF ENABLE_CORPSES}
48 g_corpses,
49 {$ENDIF}
50 {$IFDEF ENABLE_GFX}
51 g_gfx,
52 {$ENDIF}
53 r_textures, r_draw
54 ;
56 const
57 MTABLE: array [0..MONSTER_MAN] of record
58 w, h: Integer;
59 end = (
60 (w: 64; h: 64), // NONE
61 (w: 64; h: 64), // DEMON
62 (w: 64; h: 64), // IMP
63 (w: 64; h: 64), // ZOMBY
64 (w: 64; h: 64), // SERG
65 (w: 128; h: 128), // CYBER
66 (w: 64; h: 64), // CGUN
67 (w: 128; h: 128), // BARON
68 (w: 128; h: 128), // KNIGHT
69 (w: 128; h: 128), // CACO
70 (w: 64; h: 64), // SOUL (DIE is 128x128, see load code)
71 (w: 128; h: 128), // PAIN
72 (w: 256; h: 128), // SPIDER
73 (w: 128; h: 64), // BSP
74 (w: 128; h: 128), // MANCUB
75 (w: 128; h: 128), // SKEL
76 (w: 128; h: 128), // VILE
77 (w: 32; h: 32), // FISH
78 (w: 64; h: 64), // BARREL
79 (w: 128; h: 128), // ROBO
80 (w: 64; h: 64) // MAN
81 );
82 VILEFIRE_DX = 32;
83 VILEFIRE_DY = 128;
85 GFXAnim: array [0..R_GFX_LAST] of record
86 name: AnsiString;
87 w, h: Integer;
88 count: Integer;
89 back: Boolean;
90 speed: Integer;
91 rspeed: Integer;
92 alpha: Integer;
93 end = (
94 (name: ''; w: 0; h: 0; count: 0; back: false; speed: 0; rspeed: 0; alpha: 0),
95 (name: 'TELEPORT'; w: 64; h: 64; count: 10; back: false; speed: 6; rspeed: 0; alpha: 0),
96 (name: 'FLAME'; w: 32; h: 32; count: 11; back: false; speed: 3; rspeed: 0; alpha: 0),
97 (name: 'EROCKET'; w: 128; h: 128; count: 6; back: false; speed: 6; rspeed: 0; alpha: 0),
98 (name: 'EBFG'; w: 128; h: 128; count: 6; back: false; speed: 6; rspeed: 0; alpha: 0),
99 (name: 'BFGHIT'; w: 64; h: 64; count: 4; back: false; speed: 4; rspeed: 0; alpha: 0),
100 (name: 'FIRE'; w: 64; h: 128; count: 8; back: false; speed: 4; rspeed: 2; alpha: 0),
101 (name: 'ITEMRESPAWN'; w: 32; h: 32; count: 5; back: true; speed: 4; rspeed: 0; alpha: 0),
102 (name: 'SMOKE'; w: 32; h: 32; count: 10; back: false; speed: 3; rspeed: 0; alpha: 0),
103 (name: 'ESKELFIRE'; w: 64; h: 64; count: 3; back: false; speed: 8; rspeed: 0; alpha: 0),
104 (name: 'EPLASMA'; w: 32; h: 32; count: 4; back: true; speed: 3; rspeed: 0; alpha: 0),
105 (name: 'EBSPFIRE'; w: 32; h: 32; count: 5; back: false; speed: 3; rspeed: 0; alpha: 0),
106 (name: 'EIMPFIRE'; w: 64; h: 64; count: 3; back: false; speed: 6; rspeed: 0; alpha: 0),
107 (name: 'ECACOFIRE'; w: 64; h: 64; count: 3; back: false; speed: 6; rspeed: 0; alpha: 0),
108 (name: 'EBARONFIRE'; w: 64; h: 64; count: 3; back: false; speed: 6; rspeed: 0; alpha: 0),
109 (name: 'TELEPORT'; w: 64; h: 64; count: 10; back: false; speed: 3; rspeed: 0; alpha: 0), // fast
110 (name: 'SMOKE'; w: 32; h: 32; count: 10; back: false; speed: 3; rspeed: 0; alpha: 150), // transparent
111 (name: 'FLAME'; w: 32; h: 32; count: 11; back: false; speed: 3; rspeed: 2; alpha: 0) // random
112 );
114 ShotAnim: array [0..WEAPON_LAST] of record
115 name: AnsiString;
116 w, h: Integer;
117 count: Integer;
118 end = (
119 (name: ''; w: 0; h: 0; count: 0), // 0 KASTET
120 (name: ''; w: 0; h: 0; count: 0), // 1 SAW
121 (name: ''; w: 0; h: 0; count: 0), // 2 PISTOL
122 (name: ''; w: 0; h: 0; count: 0), // 3 SHOTGUN1
123 (name: ''; w: 0; h: 0; count: 0), // 4 SHOTGUN2
124 (name: ''; w: 0; h: 0; count: 0), // 5 CHAINGUN
125 (name: 'BROCKET'; w: 64; h: 32; count: 1), // 6 ROCKETLAUNCHER
126 (name: 'BPLASMA'; w: 16; h: 16; count: 2), // 7 PLASMA
127 (name: 'BBFG'; w: 64; h: 64; count: 2), // 8 BFG
128 (name: ''; w: 0; h: 0; count: 0), // 9 SUPERPULEMET
129 (name: 'FLAME'; w: 32; h: 32; count: 0{11}), // 10 FLAMETHROWER
130 (name: ''; w: 0; h: 0; count: 0), // 11
131 (name: ''; w: 0; h: 0; count: 0), // 12
132 (name: ''; w: 0; h: 0; count: 0), // 13
133 (name: ''; w: 0; h: 0; count: 0), // 14
134 (name: ''; w: 0; h: 0; count: 0), // 15
135 (name: ''; w: 0; h: 0; count: 0), // 16
136 (name: ''; w: 0; h: 0; count: 0), // 17
137 (name: ''; w: 0; h: 0; count: 0), // 18
138 (name: ''; w: 0; h: 0; count: 0), // 19
139 (name: ''; w: 0; h: 0; count: 0), // 20 ZOMPY_PISTOL
140 (name: 'BIMPFIRE'; w: 16; h: 16; count: 2), // 21 IMP_FIRE
141 (name: 'BBSPFIRE'; w: 16; h: 16; count: 2), // 22 BSP_FIRE
142 (name: 'BCACOFIRE'; w: 16; h: 16; count: 2), // 23 CACO_FIRE
143 (name: 'BBARONFIRE'; w: 64; h: 16; count: 2), // 24 BARON_FIRE
144 (name: 'BMANCUBFIRE'; w: 64; h: 32; count: 2), // 25 MANCUB_FIRE
145 (name: 'BSKELFIRE'; w: 64; h: 64; count: 2) // 26 SKEL_FIRE
146 );
148 type
149 TBinHeapPanelDrawCmp = class
150 public
151 class function less (const a, b: TPanel): Boolean; inline;
152 end;
154 TBinHeapPanelDraw = specialize TBinaryHeapBase<TPanel, TBinHeapPanelDrawCmp>;
156 TMonsterAnims = array [0..ANIM_LAST, TDirection] of TGLMultiTexture;
158 var
159 SkyTexture: TGLTexture;
160 RenTextures: array of record
161 spec: LongInt;
162 tex: TGLMultiTexture;
163 end;
164 Items: array [0..ITEM_MAX] of record
165 tex: TGLMultiTexture;
166 anim: TAnimState;
167 end;
168 MonTextures: array [0..MONSTER_MAN] of TMonsterAnims;
169 WeapTextures: array [0..WP_LAST, 0..W_POS_LAST, 0..W_ACT_LAST] of TGLTexture;
170 ShotTextures: array [0..WEAPON_LAST] of TGLMultiTexture;
171 VileFire: TGLMultiTexture;
172 Models: array of record
173 anim: array [TDirection, 0..A_LAST] of record
174 base, mask: TGLMultiTexture;
175 end;
176 (*
177 {$IFDEF ENABLE_GIBS}
178 gibs: array of record
179 base, mask: TGLTexture;
180 rect: TRectWH;
181 end;
182 {$ENDIF}
183 *)
184 end;
186 StubShotAnim: TAnimState;
188 {$IFDEF ENABLE_GFX}
189 GFXTextures: array [0..R_GFX_LAST] of TGLMultiTexture;
190 gfxlist: array of record
191 typ: Byte;
192 alpha: Byte;
193 x, y: Integer;
194 oldX, oldY: Integer;
195 anim: TAnimState;
196 end = nil;
197 {$ENDIF}
199 plist: TBinHeapPanelDraw = nil;
201 class function TBinHeapPanelDrawCmp.less (const a, b: TPanel): Boolean; inline;
202 begin
203 if a.tag < b.tag then begin result := true; exit; end;
204 if a.tag > b.tag then begin result := false; exit; end;
205 result := a.arrIdx < b.arrIdx;
206 end;
208 procedure r_Map_Initialize;
209 begin
210 StubShotAnim := TAnimState.Create(true, 1, 1);
211 plist := TBinHeapPanelDraw.Create();
212 end;
214 procedure r_Map_Finalize;
215 begin
216 plist.Free;
217 StubShotAnim.Invalidate;
218 end;
220 procedure r_Map_LoadModel (i: Integer);
221 var prefix: AnsiString; a: Integer; d: TDirection; m: ^TPlayerModelInfo;
222 begin
223 m := @PlayerModelsArray[i];
224 prefix := m.FileName + ':TEXTURES/';
225 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
226 begin
227 for a := A_STAND to A_LAST do
228 begin
229 Models[i].anim[d, a].base := nil;
230 Models[i].anim[d, a].mask := nil;
231 if m.anim[d, a].resource <> '' then
232 Models[i].anim[d, a].base := r_Textures_LoadMultiFromFileAndInfo(prefix + m.anim[d, a].resource, 64, 64, m.anim[d, a].frames, m.anim[d, a].back, true);
233 if m.anim[d, a].mask <> '' then
234 Models[i].anim[d, a].mask := r_Textures_LoadMultiFromFileAndInfo(prefix + m.anim[d, a].mask, 64, 64, m.anim[d, a].frames, m.anim[d, a].back, true);
235 end
236 end;
237 (*
238 {$IFDEF ENABLE_GIBS}
239 Models[i].gibs := nil;
240 if m.GibsCount > 0 then
241 begin
242 SetLength(Models[i].gibs, m.GibsCount);
243 end;
244 {$ENDIF}
245 *)
246 end;
249 procedure r_Map_Load;
250 const
251 WeapName: array [0..WP_LAST] of AnsiString = ('', 'CSAW', 'HGUN', 'SG', 'SSG', 'MGUN', 'RKT', 'PLZ', 'BFG', 'SPL', 'FLM');
252 WeapPos: array [0..W_POS_LAST] of AnsiString = ('', '_UP', '_DN');
253 WeapAct: array [0..W_ACT_LAST] of AnsiString = ('', '_FIRE');
254 var
255 i, j, k: Integer; d: TDirection;
257 procedure LoadItem (i: Integer; const name: AnsiString; w, h, delay, count: Integer; backanim: Boolean);
258 begin
259 ASSERT(i >= 0);
260 ASSERT(i <= ITEM_MAX);
261 Items[i].tex := r_Textures_LoadMultiFromFileAndInfo(GameWAD + ':TEXTURES/' + name, w, h, count, backanim, false);
262 if backanim then count := count * 2 - 2;
263 Items[i].anim := TAnimState.Create(True, delay, count);
264 ASSERT(Items[i].tex <> NIL);
265 end;
267 procedure LoadMonster (m, a: Integer; d: TDirection);
268 const
269 dir: array [TDirection] of AnsiString = ('_L', '');
270 var
271 w, h, count: Integer;
272 begin
273 count := MONSTER_ANIMTABLE[m].AnimCount[a];
274 if count > 0 then
275 begin
276 w := MTABLE[m].w;
277 h := MTABLE[m].h;
278 if (m = MONSTER_SOUL) and (a = ANIM_DIE) then
279 begin
280 // special case
281 w := 128;
282 h := 128;
283 end;
284 MonTextures[m, a, d] := r_Textures_LoadMultiFromFileAndInfo(
285 GameWAD + ':MTEXTURES/' + MONSTERTABLE[m].name + '_' + ANIMTABLE[a].name + dir[d],
286 w,
287 h,
288 count,
289 False,
290 False
292 end
293 else
294 MonTextures[m, a, d] := nil
295 end;
297 begin
298 // --------- items --------- //
299 // i name w h d n backanim
300 LoadItem(ITEM_NONE, 'NOTEXTURE', 16, 16, 0, 1, False);
301 LoadItem(ITEM_MEDKIT_SMALL, 'MED1', 16, 16, 0, 1, False);
302 LoadItem(ITEM_MEDKIT_LARGE, 'MED2', 32, 32, 0, 1, False);
303 LoadItem(ITEM_MEDKIT_BLACK, 'BMED', 32, 32, 0, 1, False);
304 LoadItem(ITEM_ARMOR_GREEN, 'ARMORGREEN', 32, 16, 20, 3, True);
305 LoadItem(ITEM_ARMOR_BLUE, 'ARMORBLUE', 32, 16, 20, 3, True);
306 LoadItem(ITEM_SPHERE_BLUE, 'SBLUE', 32, 32, 15, 4, True);
307 LoadItem(ITEM_SPHERE_WHITE, 'SWHITE', 32, 32, 20, 4, True);
308 LoadItem(ITEM_SUIT, 'SUIT', 32, 64, 0, 1, False);
309 LoadItem(ITEM_OXYGEN, 'OXYGEN', 16, 32, 0, 1, False);
310 LoadItem(ITEM_INVUL, 'INVUL', 32, 32, 20, 4, True);
311 LoadItem(ITEM_WEAPON_SAW, 'SAW', 64, 32, 0, 1, False);
312 LoadItem(ITEM_WEAPON_SHOTGUN1, 'SHOTGUN1', 64, 16, 0, 1, False);
313 LoadItem(ITEM_WEAPON_SHOTGUN2, 'SHOTGUN2', 64, 16, 0, 1, False);
314 LoadItem(ITEM_WEAPON_CHAINGUN, 'MGUN', 64, 16, 0, 1, False);
315 LoadItem(ITEM_WEAPON_ROCKETLAUNCHER, 'RLAUNCHER', 64, 16, 0, 1, False);
316 LoadItem(ITEM_WEAPON_PLASMA, 'PGUN', 64, 16, 0, 1, False);
317 LoadItem(ITEM_WEAPON_BFG, 'BFG', 64, 64, 0, 1, False);
318 LoadItem(ITEM_WEAPON_SUPERPULEMET, 'SPULEMET', 64, 16, 0, 1, False);
319 LoadItem(ITEM_AMMO_BULLETS, 'CLIP', 16, 16, 0, 1, False);
320 LoadItem(ITEM_AMMO_BULLETS_BOX, 'AMMO', 32, 16, 0, 1, False);
321 LoadItem(ITEM_AMMO_SHELLS, 'SHELL1', 16, 8, 0, 1, False);
322 LoadItem(ITEM_AMMO_SHELLS_BOX, 'SHELL2', 32, 16, 0, 1, False);
323 LoadItem(ITEM_AMMO_ROCKET, 'ROCKET', 16, 32, 0, 1, False);
324 LoadItem(ITEM_AMMO_ROCKET_BOX, 'ROCKETS', 64, 32, 0, 1, False);
325 LoadItem(ITEM_AMMO_CELL, 'CELL', 16, 16, 0, 1, False);
326 LoadItem(ITEM_AMMO_CELL_BIG, 'CELL2', 32, 32, 0, 1, False);
327 LoadItem(ITEM_AMMO_BACKPACK, 'BPACK', 32, 32, 0, 1, False);
328 LoadItem(ITEM_KEY_RED, 'KEYR', 16, 16, 0, 1, False);
329 LoadItem(ITEM_KEY_GREEN, 'KEYG', 16, 16, 0, 1, False);
330 LoadItem(ITEM_KEY_BLUE, 'KEYB', 16, 16, 0, 1, False);
331 LoadItem(ITEM_WEAPON_KASTET, 'KASTET', 64, 32, 0, 1, False);
332 LoadItem(ITEM_WEAPON_PISTOL, 'PISTOL', 64, 16, 0, 1, False);
333 LoadItem(ITEM_BOTTLE, 'BOTTLE', 16, 32, 20, 4, True);
334 LoadItem(ITEM_HELMET, 'HELMET', 16, 16, 20, 4, True);
335 LoadItem(ITEM_JETPACK, 'JETPACK', 32, 32, 15, 3, True);
336 LoadItem(ITEM_INVIS, 'INVIS', 32, 32, 20, 4, True);
337 LoadItem(ITEM_WEAPON_FLAMETHROWER, 'FLAMETHROWER', 64, 32, 0, 1, False);
338 LoadItem(ITEM_AMMO_FUELCAN, 'FUELCAN', 16, 32, 0, 1, False);
339 // fill with NOTEXURE forgotten item
340 for i := ITEM_AMMO_FUELCAN + 1 to ITEM_MAX do
341 LoadItem(i,'NOTEXTURE', 16, 16, 0, 1, False);
342 // --------- monsters --------- //
343 for i := MONSTER_DEMON to MONSTER_MAN do
344 for j := 0 to ANIM_LAST do
345 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
346 LoadMonster(i, j, d);
347 VileFire := r_Textures_LoadMultiFromFileAndInfo(GameWAD + ':TEXTURES/FIRE', 64, 128, 8, False, False);
348 // --------- player models --------- //
349 if PlayerModelsArray <> nil then
350 begin
351 SetLength(Models, Length(PlayerModelsArray));
352 for i := 0 to High(PlayerModelsArray) do
353 r_Map_LoadModel(i);
354 end;
355 // --------- player weapons --------- //
356 for i := 1 to WP_LAST do
357 for j := 0 to W_POS_LAST do
358 for k := 0 to W_ACT_LAST do
359 WeapTextures[i, j, k] := r_Textures_LoadFromFile(GameWAD + ':WEAPONS\' + WeapName[i] + WeapPos[j] + WeapAct[k]);
360 // --------- gfx animations --------- //
361 {$IFDEF ENABLE_GFX}
362 for i := 1 to R_GFX_LAST do
363 if GFXAnim[i].count > 0 then
364 GFXTextures[i] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/' + GFXAnim[i].name, GFXAnim[i].w, GFXAnim[i].h, GFXAnim[i].count, GFXAnim[i].back);
365 {$ENDIF}
366 // --------- shots --------- //
367 for i := 0 to WEAPON_LAST do
368 if ShotAnim[i].count > 0 then
369 ShotTextures[i] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/' + ShotAnim[i].name, ShotAnim[i].w, ShotAnim[i].h, ShotAnim[i].count, false);
370 end;
372 procedure r_Map_Free;
373 var i, j, k, a: Integer; d: TDirection;
374 begin
375 for i := 0 to WEAPON_LAST do
376 begin
377 if ShotTextures[i] <> nil then
378 ShotTextures[i].Free;
379 ShotTextures[i] := nil;
380 end;
381 {$IFDEF ENABLE_GFX}
382 gfxlist := nil;
383 for i := 0 to R_GFX_LAST do
384 begin
385 if GFXTextures[i] <> nil then
386 GFXTextures[i].Free;
387 GFXTextures[i] := nil;
388 end;
389 {$ENDIF}
390 for i := 1 to WP_LAST do
391 begin
392 for j := 0 to W_POS_LAST do
393 begin
394 for k := 0 to W_ACT_LAST do
395 begin
396 if WeapTextures[i, j, k] <> nil then
397 WeapTextures[i, j, k].Free;
398 WeapTextures[i, j, k] := nil;
399 end;
400 end;
401 end;
402 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
403 begin
404 for a := A_STAND to A_LAST do
405 begin
406 if Models[i].anim[d, a].base <> nil then
407 Models[i].anim[d, a].base.Free;
408 if Models[i].anim[d, a].mask <> nil then
409 Models[i].anim[d, a].mask.Free;
410 Models[i].anim[d, a].base := nil;
411 Models[i].anim[d, a].mask := nil;
412 end;
413 end;
414 for i := MONSTER_DEMON to MONSTER_MAN do
415 begin
416 for j := 0 to ANIM_LAST do
417 begin
418 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
419 begin
420 if MonTextures[i, j, d] <> nil then
421 MonTextures[i, j, d].Free;
422 MonTextures[i, j, d] := nil;
423 end;
424 end;
425 end;
426 for i := 0 to ITEM_MAX do
427 begin
428 if Items[i].tex <> nil then
429 begin
430 Items[i].tex.Free;
431 Items[i].tex := nil;
432 end;
433 Items[i].anim.Invalidate;
434 end;
435 end;
437 procedure r_Map_LoadTextures;
438 var i, n: Integer;
439 begin
440 if Textures <> nil then
441 begin
442 n := Length(Textures);
443 SetLength(RenTextures, n);
444 for i := 0 to n - 1 do
445 begin
446 RenTextures[i].tex := nil;
447 case Textures[i].TextureName of
448 TEXTURE_NAME_WATER: RenTextures[i].spec := TEXTURE_SPECIAL_WATER;
449 TEXTURE_NAME_ACID1: RenTextures[i].spec := TEXTURE_SPECIAL_ACID1;
450 TEXTURE_NAME_ACID2: RenTextures[i].spec := TEXTURE_SPECIAL_ACID2;
451 else
452 RenTextures[i].spec := 0;
453 RenTextures[i].tex := r_Textures_LoadMultiFromFile(Textures[i].FullName);
454 if RenTextures[i].tex = nil then
455 e_LogWritefln('r_Map_LoadTextures: failed to load texture: %s', [Textures[i].FullName]);
456 end;
457 end;
458 end;
459 if gMapInfo.SkyFullName <> '' then
460 SkyTexture := r_Textures_LoadFromFile(gMapInfo.SkyFullName);
461 plist.Clear;
462 end;
464 procedure r_Map_FreeTextures;
465 var i: Integer;
466 begin
467 plist.Clear;
468 if SkyTexture <> nil then
469 SkyTexture.Free;
470 SkyTexture := nil;
471 if RenTextures <> nil then
472 for i := 0 to High(RenTextures) do
473 if RenTextures[i].tex <> nil then
474 RenTextures[i].tex.Free;
475 RenTextures := nil;
476 end;
478 procedure r_Map_DrawPanel (p: TPanel);
479 var Texture: Integer; t: TGLMultiTexture;
480 begin
481 ASSERT(p <> nil);
482 if p.FCurTexture >= 0 then
483 begin
484 Texture := p.TextureIDs[p.FCurTexture].Texture;
485 t := RenTextures[Texture].tex;
487 if (RenTextures[Texture].spec = 0) or (t <> nil) then
488 begin
489 // TODO set alpha and blending type
490 if t = nil then
491 r_Draw_TextureRepeat(nil, p.x, p.y, p.width, p.height, false)
492 else if p.TextureIDs[p.FCurTexture].AnTex.IsValid() then
493 r_Draw_MultiTextureRepeat(t, p.TextureIDs[p.FCurTexture].AnTex, p.x, p.y, p.width, p.height, false)
494 else
495 r_Draw_TextureRepeat(t.GetTexture(0), p.x, p.y, p.width, p.height, false)
496 end;
498 if t = nil then
499 begin
500 case RenTextures[Texture].spec of
501 TEXTURE_SPECIAL_WATER: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 0, 0, 255, 255);
502 TEXTURE_SPECIAL_ACID1: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 0, 230, 0, 255);
503 TEXTURE_SPECIAL_ACID2: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 230, 0, 0, 255);
504 end
505 end
506 end
507 end;
509 procedure r_Map_DrawPanelType (panelTyp: DWORD);
510 var tagMask, i: Integer; p: TPanel;
511 begin
512 i := 0;
513 tagMask := PanelTypeToTag(panelTyp);
514 while plist.count > 0 do
515 begin
516 p := TPanel(plist.Front());
517 if (p.tag and tagMask) = 0 then
518 break;
519 r_Map_DrawPanel(p);
520 Inc(i);
521 plist.PopFront
522 end;
523 end;
525 procedure r_Map_DrawItems (x, y, w, h: Integer; drop: Boolean);
526 var i, fX, fY: Integer; it: PItem; t: TGLMultiTexture;
527 begin
528 if ggItems <> nil then
529 begin
530 for i := 0 to High(ggItems) do
531 begin
532 it := @ggItems[i];
533 if it.used and it.alive and (it.dropped = drop) and (it.ItemType <> ITEM_NONE) then
534 begin
535 t := Items[it.ItemType].tex;
536 if g_Collide(it.obj.x, it.obj.y, t.width, t.height, x, y, w, h) then
537 begin
538 it.obj.Lerp(gLerpFactor, fX, fY);
539 r_Draw_MultiTextureRepeat(t, Items[it.ItemType].anim, fX, fY, t.width, t.height, false);
540 // if g_debug_frames then // TODO draw collision frame
541 end;
542 end;
543 end;
544 end;
545 end;
547 function r_Map_GetMonsterTexture (m, a: Integer; d: TDirection; out t: TGLMultiTexture; out dx, dy: Integer; out flip: Boolean): Boolean;
548 // var c: Integer;
549 begin
550 t := nil; dx := 0; dy := 0; flip := false;
551 result := MonTextures[m, a, d] <> nil;
552 if result = false then
553 begin
554 flip := true;
555 if d = TDirection.D_RIGHT then d := TDirection.D_LEFT else d := TDirection.D_RIGHT;
556 result := MonTextures[m, a, d] <> nil;
557 end;
558 if result = true then
559 begin
560 t := MonTextures[m, a, d];
561 if d = TDirection.D_LEFT then
562 begin
563 dx := MONSTER_ANIMTABLE[m].AnimDeltaLeft[a].X;
564 dy := MONSTER_ANIMTABLE[m].AnimDeltaLeft[a].Y;
565 end
566 else
567 begin
568 dx := MONSTER_ANIMTABLE[m].AnimDeltaRight[a].X;
569 dy := MONSTER_ANIMTABLE[m].AnimDeltaRight[a].Y;
570 end;
571 if flip then
572 begin
573 // c := (MONSTERTABLE[MonsterType].Rect.X - dx) + MONSTERTABLE[MonsterType].Rect.Width;
574 // dx := MTABLE[m].width - c - MONSTERTABLE[MonsterType].Rect.X;
575 dx := -dx;
576 end;
577 end;
578 end;
580 procedure r_Map_DrawMonsterAttack (constref mon: TMonster);
581 var o: TObj;
582 begin
583 if VileFire <> nil then
584 if (mon.MonsterType = MONSTER_VILE) and (mon.MonsterState = MONSTATE_SHOOT) then
585 if mon.VileFireAnim.IsValid() and GetPos(mon.MonsterTargetUID, @o) then
586 r_Draw_MultiTextureRepeat(VileFire, mon.VileFireAnim, o.x + o.rect.x + (o.rect.width div 2) - VILEFIRE_DX, o.y + o.rect.y + o.rect.height - VILEFIRE_DY, VileFire.width, VileFire.height, False);
587 end;
589 procedure r_Map_DrawMonster (constref mon: TMonster);
590 var m, a, fX, fY, dx, dy: Integer; d: TDirection; flip: Boolean; t: TGLMultiTexture;
591 begin
592 m := mon.MonsterType;
593 a := mon.MonsterAnim;
594 d := mon.GameDirection;
596 mon.obj.Lerp(gLerpFactor, fX, fY);
598 if r_Map_GetMonsterTexture(m, a, d, t, dx, dy, flip) then
599 r_Draw_MultiTextureRepeat(t, mon.DirAnim[a, d], fX + dx, fY + dy, t.width, t.height, flip);
602 if g_debug_frames
603 // TODO draw frame
605 end;
607 procedure r_Map_DrawMonsters (x, y, w, h: Integer);
608 var i: Integer; m: TMonster;
609 begin
610 if gMonsters <> nil then
611 begin
612 for i := 0 to High(gMonsters) do
613 begin
614 m := gMonsters[i];
615 if m <> nil then
616 begin
617 r_Map_DrawMonsterAttack(m);
618 // TODO select from grid
619 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
620 r_Map_DrawMonster(m);
621 end;
622 end;
623 end;
624 end;
626 function r_Map_GetPlayerModelTex (i: Integer; var a: Integer; var d: TDirection; out flip: Boolean): Boolean;
627 begin
628 flip := false;
629 result := Models[i].anim[d, a].base <> nil;
630 if result = false then
631 begin
632 flip := true;
633 if d = TDirection.D_LEFT then d := TDirection.D_RIGHT else d := TDirection.D_LEFT;
634 result := Models[i].anim[d, a].base <> nil;
635 end;
636 end;
638 procedure r_Map_DrawPlayerModel (pm: TPlayerModel; x, y: Integer);
639 var a, pos, act, xx, yy: Integer; d: TDirection; flip: Boolean; t: TGLMultiTexture; tex: TGLTexture;
640 begin
641 a := pm.CurrentAnimation;
642 d := pm.Direction;
643 // TODO draw flag
644 if PlayerModelsArray[pm.id].HaveWeapon and not (a in [A_DIE1, A_DIE2, A_PAIN]) then
645 begin
646 case a of
647 A_SEEUP, A_ATTACKUP: pos := W_POS_UP;
648 A_SEEDOWN, A_ATTACKDOWN: pos := W_POS_DOWN;
649 else pos := W_POS_NORMAL;
650 end;
651 if (a in [A_ATTACK, A_ATTACKUP, A_ATTACKDOWN]) or pm.GetFire() then
652 act := W_ACT_FIRE
653 else
654 act := W_ACT_NORMAL;
655 tex := WeapTextures[pm.CurrentWeapon, pos, act];
656 if tex <> nil then
657 begin
658 xx := PlayerModelsArray[pm.id].WeaponPoints[pm.CurrentWeapon, a, d, pm.AnimState.CurrentFrame].X;
659 yy := PlayerModelsArray[pm.id].WeaponPoints[pm.CurrentWeapon, a, d, pm.AnimState.CurrentFrame].Y;
660 r_Draw_Texture(
661 tex,
662 x + xx,
663 y + yy,
664 tex.width,
665 tex.height,
666 d = TDirection.D_LEFT
667 );
668 end;
669 end;
670 if r_Map_GetPlayerModelTex(pm.id, a, d, flip) then
671 begin
672 t := Models[pm.id].anim[d, a].base;
673 r_Draw_MultiTextureRepeat(t, pm.AnimState, x, y, t.width, t.height, flip);
674 // TODO colorize mask
675 t := Models[pm.id].anim[d, a].mask;
676 if t <> nil then
677 r_Draw_MultiTextureRepeat(t, pm.AnimState, x, y, t.width, t.height, flip);
678 end;
679 end;
681 procedure r_Map_DrawPlayer (p: TPlayer);
682 var fX, fY, fSlope: Integer;
683 begin
684 if p.alive then
685 begin
686 fX := p.obj.x; fY := p.obj.y;
687 // TODO fix lerp
688 //p.obj.Lerp(gLerpFactor, fX, fY);
689 fSlope := nlerp(p.SlopeOld, p.obj.slopeUpLeft, gLerpFactor);
690 // TODO draw punch
691 // TODO invul pentagram
692 // TODO draw it with transparency
693 r_Map_DrawPlayerModel(p.Model, fX, fY + fSlope);
694 end;
695 // TODO draw g_debug_frames
696 // TODO draw chat bubble
697 // TODO draw aim
698 end;
700 procedure r_Map_DrawPlayers (x, y, w, h: Integer);
701 var i: Integer;
702 begin
703 // TODO draw only visible
704 if gPlayers <> nil then
705 for i := 0 to High(gPlayers) do
706 if gPlayers[i] <> nil then
707 r_Map_DrawPlayer(gPlayers[i]);
708 end;
710 {$IFDEF ENABLE_CORPSES}
711 procedure r_Map_DrawCorpses (x, y, w, h: Integer);
712 var i, fX, fY: Integer; p: TCorpse;
713 begin
714 if gCorpses <> nil then
715 begin
716 for i := 0 to High(gCorpses) do
717 begin
718 p := gCorpses[i];
719 if (p <> nil) and (p.state <> CORPSE_STATE_REMOVEME) and (p.model <> nil) then
720 begin
721 p.obj.Lerp(gLerpFactor, fX, fY);
722 r_Map_DrawPlayerModel(p.model, fX, fY);
723 end;
724 end;
725 end;
726 end;
727 {$ENDIF}
729 {$IFDEF ENABLE_GFX}
730 function r_Map_GetGFXID (): Integer;
731 var i: Integer;
732 begin
733 i := 0;
734 if gfxlist <> nil then
735 begin
736 while (i < Length(gfxlist)) and gfxlist[i].anim.IsValid() do
737 Inc(i);
738 if i >= Length(gfxlist) then
739 SetLength(gfxlist, Length(gfxlist) + 1)
740 end
741 else
742 SetLength(gfxlist, 1);
743 gfxlist[i].typ := R_GFX_NONE;
744 gfxlist[i].anim.Invalidate;
745 result := i
746 end;
748 procedure r_Map_NewGFX (typ, x, y: Integer);
749 var i: Integer;
750 begin
751 if gpart_dbg_enabled and (typ > 0) and (typ <= R_GFX_LAST) then
752 begin
753 i := r_Map_GetGFXID();
754 if i >= 0 then
755 begin
756 gfxlist[i].typ := typ;
757 gfxlist[i].x := x;
758 gfxlist[i].y := y;
759 gfxlist[i].oldX := x;
760 gfxlist[i].oldY := y;
761 gfxlist[i].anim := TAnimState.Create(false, GFXAnim[typ].speed + Random(GFXAnim[typ].rspeed), GFXAnim[typ].count);
762 gfxlist[i].anim.Reset();
763 gfxlist[i].anim.Enable();
764 end;
765 end;
766 end;
768 procedure r_Map_UpdateGFX;
769 var i: Integer;
770 begin
771 if gfxlist <> nil then
772 begin
773 for i := 0 to High(gfxlist) do
774 begin
775 if gfxlist[i].anim.IsValid() then
776 begin
777 gfxlist[i].oldX := gfxlist[i].x;
778 gfxlist[i].oldY := gfxlist[i].y;
779 case gfxlist[i].typ of
780 R_GFX_FLAME, R_GFX_SMOKE:
781 begin
782 if Random(3) = 0 then
783 gfxlist[i].x := gfxlist[i].x - 1 + Random(3);
784 if Random(2) = 0 then
785 gfxlist[i].y := gfxlist[i].y - Random(2);
786 end;
787 end;
788 if gfxlist[i].anim.played then
789 gfxlist[i].anim.Invalidate
790 else
791 gfxlist[i].anim.Update
792 end;
793 end;
794 end;
795 end;
797 procedure r_Map_DrawParticles (x, y, w, h: Integer);
798 var i, fx, fy: Integer;
799 begin
800 if gpart_dbg_enabled and (Particles <> nil) then
801 begin
802 glDisable(GL_TEXTURE_2D);
803 if (g_dbg_scale < 0.6) then
804 glPointSize(1)
805 else if (g_dbg_scale > 1.3) then
806 glPointSize(g_dbg_scale + 1)
807 else
808 glPointSize(2);
809 glDisable(GL_POINT_SMOOTH);
810 glEnable(GL_BLEND);
811 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
813 glBegin(GL_POINTS);
814 for i := 0 to High(Particles) do
815 begin
816 if Particles[i].alive then
817 begin
818 fx := nlerp(Particles[i].oldX, Particles[i].x, gLerpFactor);
819 fy := nlerp(Particles[i].oldY, Particles[i].y, gLerpFactor);
820 glColor4ub(Particles[i].red, Particles[i].green, Particles[i].blue, Particles[i].alpha);
821 glVertex2f(fx, fy);
822 end;
823 end;
824 glEnd;
826 glDisable(GL_BLEND);
827 end;
828 end;
830 procedure r_Map_DrawGFX (x, y, w, h: Integer);
831 var i, fx, fy, typ: Integer; tex: TGLMultiTexture;
832 begin
833 if gfxlist <> nil then
834 begin
835 for i := 0 to High(gfxlist) do
836 begin
837 if gfxlist[i].anim.IsValid() then
838 begin
839 typ := gfxlist[i].typ;
840 tex := GFXTextures[typ];
841 if tex <> nil then
842 begin
843 fx := nlerp(gfxlist[i].oldX, gfxlist[i].x, gLerpFactor);
844 fy := nlerp(gfxlist[i].oldY, gfxlist[i].y, gLerpFactor);
845 // TODO set GFXAnim[typ].alpha
846 r_Draw_MultiTextureRepeat(tex, gfxlist[i].anim, fx, fy, tex.width, tex.height, false);
847 end;
848 end;
849 end;
850 end;
851 end;
852 {$ENDIF}
854 procedure r_Map_DrawShots (x, y, w, h: Integer);
855 var i, a, fX, fY, pX, pY, typ: Integer; tex: TGLMultiTexture; anim: ^TAnimState;
856 begin
857 if Shots <> nil then
858 begin
859 for i := 0 to High(Shots) do
860 begin
861 typ := Shots[i].ShotType;
862 if typ <> 0 then
863 begin
864 e_logwritefln('draw shot %s typ %s', [i, typ]);
865 tex := ShotTextures[typ];
866 if tex <> nil then
867 begin
868 e_logwritefln('draw shot %s typ %s <> nil', [i, typ]);
869 a := 0;
870 case typ of
871 WEAPON_ROCKETLAUNCHER, WEAPON_BARON_FIRE, WEAPON_MANCUB_FIRE, WEAPON_SKEL_FIRE:
872 a := -GetAngle2(Shots[i].Obj.Vel.X, Shots[i].Obj.Vel.Y)
873 end;
874 Shots[i].Obj.Lerp(gLerpFactor, fX, fY);
875 pX := Shots[i].Obj.Rect.Width div 2;
876 pY := Shots[i].Obj.Rect.Height div 2;
877 // TODO fix this
878 if Shots[i].Animation.IsValid() then anim := @Shots[i].Animation else anim := @StubShotAnim;
879 // TODO: change angle and base point
880 r_Draw_MultiTextureRepeat(tex, anim^, fX, fY, tex.width, tex.height, false);
881 end;
882 end;
883 end;
884 end;
885 end;
887 procedure r_Map_Draw (x, y, w, h, camx, camy: Integer);
888 var iter: TPanelGrid.Iter; p: PPanel; cx, cy, xx, yy, ww, hh: Integer;
889 begin
890 cx := camx - w div 2;
891 cy := camy - h div 2;
892 xx := x + cx;
893 yy := y + cy;
894 ww := w;
895 hh := h;
897 if SkyTexture <> nil then
898 r_Draw_Texture(SkyTexture, x, y, w, h, false);
900 plist.Clear;
901 iter := mapGrid.ForEachInAABB(xx, yy, ww, hh, GridDrawableMask);
902 for p in iter do
903 if ((p^.tag and GridTagDoor) <> 0) = p^.door then
904 plist.Insert(p^);
905 iter.Release;
907 glPushMatrix;
908 glTranslatef(-cx, -cy, 0);
909 r_Map_DrawPanelType(PANEL_BACK);
910 r_Map_DrawPanelType(PANEL_STEP);
911 r_Map_DrawItems(xx, yy, ww, hh, false);
912 r_Map_DrawShots(xx, yy, ww, hh);
913 // TODO draw shells
914 r_Map_DrawPlayers(xx, yy, ww, hh);
915 // TODO draw gibs
916 {$IFDEF ENABLE_CORPSES}
917 r_Map_DrawCorpses(xx, yy, ww, hh);
918 {$ENDIF}
919 r_Map_DrawPanelType(PANEL_WALL);
920 r_Map_DrawMonsters(xx, yy, ww, hh);
921 r_Map_DrawItems(xx, yy, ww, hh, true);
922 r_Map_DrawPanelType(PANEL_CLOSEDOOR);
923 {$IFDEF ENABLE_GFX}
924 r_Map_DrawParticles(xx, yy, ww, hh);
925 r_Map_DrawGFX(xx, yy, ww, hh);
926 {$ENDIF}
927 // TODO draw flags
928 r_Map_DrawPanelType(PANEL_ACID1);
929 r_Map_DrawPanelType(PANEL_ACID2);
930 r_Map_DrawPanelType(PANEL_WATER);
931 r_Map_DrawPanelType(PANEL_FORE);
932 glPopMatrix;
933 end;
935 procedure r_Map_Update;
936 var i: Integer;
937 begin
938 for i := 0 to ITEM_MAX do
939 Items[i].anim.Update;
940 r_Map_UpdateGFX;
941 end;
943 end.