DEADSOFTWARE

gl: colorize and blend textures
[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 if t = nil then
490 r_Draw_TextureRepeat(nil, p.x, p.y, p.width, p.height, false, 255, 255, 255, 255 - p.alpha, p.blending)
491 else if p.TextureIDs[p.FCurTexture].AnTex.IsValid() then
492 r_Draw_MultiTextureRepeat(t, p.TextureIDs[p.FCurTexture].AnTex, p.x, p.y, p.width, p.height, false, 255, 255, 255, 255 - p.alpha, p.blending)
493 else
494 r_Draw_TextureRepeat(t.GetTexture(0), p.x, p.y, p.width, p.height, false, 255, 255, 255, 255 - p.alpha, p.blending)
495 end;
497 if t = nil then
498 begin
499 case RenTextures[Texture].spec of
500 TEXTURE_SPECIAL_WATER: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 0, 0, 255, 255);
501 TEXTURE_SPECIAL_ACID1: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 0, 230, 0, 255);
502 TEXTURE_SPECIAL_ACID2: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 230, 0, 0, 255);
503 end
504 end
505 end
506 end;
508 procedure r_Map_DrawPanelType (panelTyp: DWORD);
509 var tagMask, i: Integer; p: TPanel;
510 begin
511 i := 0;
512 tagMask := PanelTypeToTag(panelTyp);
513 while plist.count > 0 do
514 begin
515 p := TPanel(plist.Front());
516 if (p.tag and tagMask) = 0 then
517 break;
518 r_Map_DrawPanel(p);
519 Inc(i);
520 plist.PopFront
521 end;
522 end;
524 procedure r_Map_DrawItems (x, y, w, h: Integer; drop: Boolean);
525 var i, fX, fY: Integer; it: PItem; t: TGLMultiTexture;
526 begin
527 if ggItems <> nil then
528 begin
529 for i := 0 to High(ggItems) do
530 begin
531 it := @ggItems[i];
532 if it.used and it.alive and (it.dropped = drop) and (it.ItemType <> ITEM_NONE) then
533 begin
534 t := Items[it.ItemType].tex;
535 if g_Collide(it.obj.x, it.obj.y, t.width, t.height, x, y, w, h) then
536 begin
537 it.obj.Lerp(gLerpFactor, fX, fY);
538 r_Draw_MultiTextureRepeat(t, Items[it.ItemType].anim, fX, fY, t.width, t.height, false, 255, 255, 255, 255, false);
539 // if g_debug_frames then // TODO draw collision frame
540 end;
541 end;
542 end;
543 end;
544 end;
546 function r_Map_GetMonsterTexture (m, a: Integer; d: TDirection; out t: TGLMultiTexture; out dx, dy: Integer; out flip: Boolean): Boolean;
547 // var c: Integer;
548 begin
549 t := nil; dx := 0; dy := 0; flip := false;
550 result := MonTextures[m, a, d] <> nil;
551 if result = false then
552 begin
553 flip := true;
554 if d = TDirection.D_RIGHT then d := TDirection.D_LEFT else d := TDirection.D_RIGHT;
555 result := MonTextures[m, a, d] <> nil;
556 end;
557 if result = true then
558 begin
559 t := MonTextures[m, a, d];
560 if d = TDirection.D_LEFT then
561 begin
562 dx := MONSTER_ANIMTABLE[m].AnimDeltaLeft[a].X;
563 dy := MONSTER_ANIMTABLE[m].AnimDeltaLeft[a].Y;
564 end
565 else
566 begin
567 dx := MONSTER_ANIMTABLE[m].AnimDeltaRight[a].X;
568 dy := MONSTER_ANIMTABLE[m].AnimDeltaRight[a].Y;
569 end;
570 if flip then
571 begin
572 // c := (MONSTERTABLE[MonsterType].Rect.X - dx) + MONSTERTABLE[MonsterType].Rect.Width;
573 // dx := MTABLE[m].width - c - MONSTERTABLE[MonsterType].Rect.X;
574 dx := -dx;
575 end;
576 end;
577 end;
579 procedure r_Map_DrawMonsterAttack (constref mon: TMonster);
580 var o: TObj;
581 begin
582 if VileFire <> nil then
583 if (mon.MonsterType = MONSTER_VILE) and (mon.MonsterState = MONSTATE_SHOOT) then
584 if mon.VileFireAnim.IsValid() and GetPos(mon.MonsterTargetUID, @o) then
585 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, 255, 255, 255, 255, false);
586 end;
588 procedure r_Map_DrawMonster (constref mon: TMonster);
589 var m, a, fX, fY, dx, dy: Integer; d: TDirection; flip: Boolean; t: TGLMultiTexture;
590 begin
591 m := mon.MonsterType;
592 a := mon.MonsterAnim;
593 d := mon.GameDirection;
595 mon.obj.Lerp(gLerpFactor, fX, fY);
597 if r_Map_GetMonsterTexture(m, a, d, t, dx, dy, flip) then
598 r_Draw_MultiTextureRepeat(t, mon.DirAnim[a, d], fX + dx, fY + dy, t.width, t.height, flip, 255, 255, 255, 255, false);
601 if g_debug_frames
602 // TODO draw frame
604 end;
606 procedure r_Map_DrawMonsters (x, y, w, h: Integer);
607 var i: Integer; m: TMonster;
608 begin
609 if gMonsters <> nil then
610 begin
611 for i := 0 to High(gMonsters) do
612 begin
613 m := gMonsters[i];
614 if m <> nil then
615 begin
616 r_Map_DrawMonsterAttack(m);
617 // TODO select from grid
618 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
619 r_Map_DrawMonster(m);
620 end;
621 end;
622 end;
623 end;
625 function r_Map_GetPlayerModelTex (i: Integer; var a: Integer; var d: TDirection; out flip: Boolean): Boolean;
626 begin
627 flip := false;
628 result := Models[i].anim[d, a].base <> nil;
629 if result = false then
630 begin
631 flip := true;
632 if d = TDirection.D_LEFT then d := TDirection.D_RIGHT else d := TDirection.D_LEFT;
633 result := Models[i].anim[d, a].base <> nil;
634 end;
635 end;
637 procedure r_Map_DrawPlayerModel (pm: TPlayerModel; x, y: Integer);
638 var a, pos, act, xx, yy: Integer; d: TDirection; flip: Boolean; t: TGLMultiTexture; tex: TGLTexture; c: TRGB;
639 begin
640 a := pm.CurrentAnimation;
641 d := pm.Direction;
642 // TODO draw flag
643 if PlayerModelsArray[pm.id].HaveWeapon and not (a in [A_DIE1, A_DIE2, A_PAIN]) then
644 begin
645 case a of
646 A_SEEUP, A_ATTACKUP: pos := W_POS_UP;
647 A_SEEDOWN, A_ATTACKDOWN: pos := W_POS_DOWN;
648 else pos := W_POS_NORMAL;
649 end;
650 if (a in [A_ATTACK, A_ATTACKUP, A_ATTACKDOWN]) or pm.GetFire() then
651 act := W_ACT_FIRE
652 else
653 act := W_ACT_NORMAL;
654 tex := WeapTextures[pm.CurrentWeapon, pos, act];
655 if tex <> nil then
656 begin
657 xx := PlayerModelsArray[pm.id].WeaponPoints[pm.CurrentWeapon, a, d, pm.AnimState.CurrentFrame].X;
658 yy := PlayerModelsArray[pm.id].WeaponPoints[pm.CurrentWeapon, a, d, pm.AnimState.CurrentFrame].Y;
659 r_Draw_Texture(
660 tex,
661 x + xx,
662 y + yy,
663 tex.width,
664 tex.height,
665 d = TDirection.D_LEFT,
666 255, 255, 255, 255, false
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, 255, 255, 255, 255, false);
674 t := Models[pm.id].anim[d, a].mask;
675 if t <> nil then
676 begin
677 c := pm.Color;
678 r_Draw_MultiTextureRepeat(t, pm.AnimState, x, y, t.width, t.height, flip, c.r, c.g, c.b, 255, false);
679 end;
680 end;
681 end;
683 procedure r_Map_DrawPlayer (p: TPlayer);
684 var fX, fY, fSlope: Integer;
685 begin
686 if p.alive then
687 begin
688 fX := p.obj.x; fY := p.obj.y;
689 // TODO fix lerp
690 //p.obj.Lerp(gLerpFactor, fX, fY);
691 fSlope := nlerp(p.SlopeOld, p.obj.slopeUpLeft, gLerpFactor);
692 // TODO draw punch
693 // TODO invul pentagram
694 // TODO draw it with transparency
695 r_Map_DrawPlayerModel(p.Model, fX, fY + fSlope);
696 end;
697 // TODO draw g_debug_frames
698 // TODO draw chat bubble
699 // TODO draw aim
700 end;
702 procedure r_Map_DrawPlayers (x, y, w, h: Integer);
703 var i: Integer;
704 begin
705 // TODO draw only visible
706 if gPlayers <> nil then
707 for i := 0 to High(gPlayers) do
708 if gPlayers[i] <> nil then
709 r_Map_DrawPlayer(gPlayers[i]);
710 end;
712 {$IFDEF ENABLE_CORPSES}
713 procedure r_Map_DrawCorpses (x, y, w, h: Integer);
714 var i, fX, fY: Integer; p: TCorpse;
715 begin
716 if gCorpses <> nil then
717 begin
718 for i := 0 to High(gCorpses) do
719 begin
720 p := gCorpses[i];
721 if (p <> nil) and (p.state <> CORPSE_STATE_REMOVEME) and (p.model <> nil) then
722 begin
723 p.obj.Lerp(gLerpFactor, fX, fY);
724 r_Map_DrawPlayerModel(p.model, fX, fY);
725 end;
726 end;
727 end;
728 end;
729 {$ENDIF}
731 {$IFDEF ENABLE_GFX}
732 function r_Map_GetGFXID (): Integer;
733 var i: Integer;
734 begin
735 i := 0;
736 if gfxlist <> nil then
737 begin
738 while (i < Length(gfxlist)) and gfxlist[i].anim.IsValid() do
739 Inc(i);
740 if i >= Length(gfxlist) then
741 SetLength(gfxlist, Length(gfxlist) + 1)
742 end
743 else
744 SetLength(gfxlist, 1);
745 gfxlist[i].typ := R_GFX_NONE;
746 gfxlist[i].anim.Invalidate;
747 result := i
748 end;
750 procedure r_Map_NewGFX (typ, x, y: Integer);
751 var i: Integer;
752 begin
753 if gpart_dbg_enabled and (typ > 0) and (typ <= R_GFX_LAST) then
754 begin
755 i := r_Map_GetGFXID();
756 if i >= 0 then
757 begin
758 gfxlist[i].typ := typ;
759 gfxlist[i].x := x;
760 gfxlist[i].y := y;
761 gfxlist[i].oldX := x;
762 gfxlist[i].oldY := y;
763 gfxlist[i].anim := TAnimState.Create(false, GFXAnim[typ].speed + Random(GFXAnim[typ].rspeed), GFXAnim[typ].count);
764 gfxlist[i].anim.Reset();
765 gfxlist[i].anim.Enable();
766 end;
767 end;
768 end;
770 procedure r_Map_UpdateGFX;
771 var i: Integer;
772 begin
773 if gfxlist <> nil then
774 begin
775 for i := 0 to High(gfxlist) do
776 begin
777 if gfxlist[i].anim.IsValid() then
778 begin
779 gfxlist[i].oldX := gfxlist[i].x;
780 gfxlist[i].oldY := gfxlist[i].y;
781 case gfxlist[i].typ of
782 R_GFX_FLAME, R_GFX_SMOKE:
783 begin
784 if Random(3) = 0 then
785 gfxlist[i].x := gfxlist[i].x - 1 + Random(3);
786 if Random(2) = 0 then
787 gfxlist[i].y := gfxlist[i].y - Random(2);
788 end;
789 end;
790 if gfxlist[i].anim.played then
791 gfxlist[i].anim.Invalidate
792 else
793 gfxlist[i].anim.Update
794 end;
795 end;
796 end;
797 end;
799 procedure r_Map_DrawParticles (x, y, w, h: Integer);
800 var i, fx, fy: Integer;
801 begin
802 if gpart_dbg_enabled and (Particles <> nil) then
803 begin
804 glDisable(GL_TEXTURE_2D);
805 if (g_dbg_scale < 0.6) then
806 glPointSize(1)
807 else if (g_dbg_scale > 1.3) then
808 glPointSize(g_dbg_scale + 1)
809 else
810 glPointSize(2);
811 glDisable(GL_POINT_SMOOTH);
812 glEnable(GL_BLEND);
813 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
815 glBegin(GL_POINTS);
816 for i := 0 to High(Particles) do
817 begin
818 if Particles[i].alive then
819 begin
820 fx := nlerp(Particles[i].oldX, Particles[i].x, gLerpFactor);
821 fy := nlerp(Particles[i].oldY, Particles[i].y, gLerpFactor);
822 glColor4ub(Particles[i].red, Particles[i].green, Particles[i].blue, Particles[i].alpha);
823 glVertex2f(fx, fy);
824 end;
825 end;
826 glEnd;
828 glDisable(GL_BLEND);
829 end;
830 end;
832 procedure r_Map_DrawGFX (x, y, w, h: Integer);
833 var i, fx, fy, typ: Integer; tex: TGLMultiTexture;
834 begin
835 if gfxlist <> nil then
836 begin
837 for i := 0 to High(gfxlist) do
838 begin
839 if gfxlist[i].anim.IsValid() then
840 begin
841 typ := gfxlist[i].typ;
842 tex := GFXTextures[typ];
843 if tex <> nil then
844 begin
845 fx := nlerp(gfxlist[i].oldX, gfxlist[i].x, gLerpFactor);
846 fy := nlerp(gfxlist[i].oldY, gfxlist[i].y, gLerpFactor);
847 r_Draw_MultiTextureRepeat(tex, gfxlist[i].anim, fx, fy, tex.width, tex.height, false, 255, 255, 255, 255 - GFXAnim[typ].alpha, false);
848 end;
849 end;
850 end;
851 end;
852 end;
853 {$ENDIF}
855 procedure r_Map_DrawShots (x, y, w, h: Integer);
856 var i, a, fX, fY, pX, pY, typ: Integer; tex: TGLMultiTexture; anim: ^TAnimState;
857 begin
858 if Shots <> nil then
859 begin
860 for i := 0 to High(Shots) do
861 begin
862 typ := Shots[i].ShotType;
863 if typ <> 0 then
864 begin
865 tex := ShotTextures[typ];
866 if tex <> nil then
867 begin
868 a := 0;
869 case typ of
870 WEAPON_ROCKETLAUNCHER, WEAPON_BARON_FIRE, WEAPON_MANCUB_FIRE, WEAPON_SKEL_FIRE:
871 a := -GetAngle2(Shots[i].Obj.Vel.X, Shots[i].Obj.Vel.Y)
872 end;
873 Shots[i].Obj.Lerp(gLerpFactor, fX, fY);
874 pX := Shots[i].Obj.Rect.Width div 2;
875 pY := Shots[i].Obj.Rect.Height div 2;
876 // TODO fix this hack
877 if Shots[i].Animation.IsValid() then anim := @Shots[i].Animation else anim := @StubShotAnim;
878 r_Draw_MultiTextureRepeatRotate(tex, anim^, fX, fY, tex.width, tex.height, false, 255, 255, 255, 255, pX, pY, a, false);
879 end;
880 end;
881 end;
882 end;
883 end;
885 procedure r_Map_Draw (x, y, w, h, camx, camy: Integer);
886 var iter: TPanelGrid.Iter; p: PPanel; cx, cy, xx, yy, ww, hh: Integer;
887 begin
888 cx := camx - w div 2;
889 cy := camy - h div 2;
890 xx := x + cx;
891 yy := y + cy;
892 ww := w;
893 hh := h;
895 if SkyTexture <> nil then
896 r_Draw_Texture(SkyTexture, x, y, w, h, false, 255, 255, 255, 255, false);
898 plist.Clear;
899 iter := mapGrid.ForEachInAABB(xx, yy, ww, hh, GridDrawableMask);
900 for p in iter do
901 if ((p^.tag and GridTagDoor) <> 0) = p^.door then
902 plist.Insert(p^);
903 iter.Release;
905 glPushMatrix;
906 glTranslatef(-cx, -cy, 0);
907 r_Map_DrawPanelType(PANEL_BACK);
908 r_Map_DrawPanelType(PANEL_STEP);
909 r_Map_DrawItems(xx, yy, ww, hh, false);
910 r_Map_DrawShots(xx, yy, ww, hh);
911 // TODO draw shells
912 r_Map_DrawPlayers(xx, yy, ww, hh);
913 // TODO draw gibs
914 {$IFDEF ENABLE_CORPSES}
915 r_Map_DrawCorpses(xx, yy, ww, hh);
916 {$ENDIF}
917 r_Map_DrawPanelType(PANEL_WALL);
918 r_Map_DrawMonsters(xx, yy, ww, hh);
919 r_Map_DrawItems(xx, yy, ww, hh, true);
920 r_Map_DrawPanelType(PANEL_CLOSEDOOR);
921 {$IFDEF ENABLE_GFX}
922 r_Map_DrawParticles(xx, yy, ww, hh);
923 r_Map_DrawGFX(xx, yy, ww, hh);
924 {$ENDIF}
925 // TODO draw flags
926 r_Map_DrawPanelType(PANEL_ACID1);
927 r_Map_DrawPanelType(PANEL_ACID2);
928 r_Map_DrawPanelType(PANEL_WATER);
929 r_Map_DrawPanelType(PANEL_FORE);
930 glPopMatrix;
931 end;
933 procedure r_Map_Update;
934 var i: Integer;
935 begin
936 for i := 0 to ITEM_MAX do
937 Items[i].anim.Update;
938 r_Map_UpdateGFX;
939 end;
941 end.