DEADSOFTWARE

gl: free player model 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_Update;
31 procedure r_Map_Draw (x, y, w, h, camx, camy: Integer);
33 implementation
35 uses
36 {$IFDEF USE_GLES1}
37 GLES11,
38 {$ELSE}
39 GL, GLEXT,
40 {$ENDIF}
41 e_log,
42 binheap, MAPDEF, utils,
43 g_options, g_textures, g_basic, g_base, g_phys,
44 g_game, g_map, g_panel, g_items, g_monsters, g_playermodel, g_player, g_weapons,
45 {$IFDEF ENABLE_CORPSES}
46 g_corpses,
47 {$ENDIF}
48 r_textures, r_draw
49 ;
51 const
52 MTABLE: array [0..MONSTER_MAN] of record
53 w, h: Integer;
54 end = (
55 (w: 64; h: 64), // NONE
56 (w: 64; h: 64), // DEMON
57 (w: 64; h: 64), // IMP
58 (w: 64; h: 64), // ZOMBY
59 (w: 64; h: 64), // SERG
60 (w: 128; h: 128), // CYBER
61 (w: 64; h: 64), // CGUN
62 (w: 128; h: 128), // BARON
63 (w: 128; h: 128), // KNIGHT
64 (w: 128; h: 128), // CACO
65 (w: 64; h: 64), // SOUL (DIE is 128x128, see load code)
66 (w: 128; h: 128), // PAIN
67 (w: 256; h: 128), // SPIDER
68 (w: 128; h: 64), // BSP
69 (w: 128; h: 128), // MANCUB
70 (w: 128; h: 128), // SKEL
71 (w: 128; h: 128), // VILE
72 (w: 32; h: 32), // FISH
73 (w: 64; h: 64), // BARREL
74 (w: 128; h: 128), // ROBO
75 (w: 64; h: 64) // MAN
76 );
77 VILEFIRE_DX = 32;
78 VILEFIRE_DY = 128;
80 type
81 TBinHeapPanelDrawCmp = class
82 public
83 class function less (const a, b: TPanel): Boolean; inline;
84 end;
86 TBinHeapPanelDraw = specialize TBinaryHeapBase<TPanel, TBinHeapPanelDrawCmp>;
88 TMonsterAnims = array [0..ANIM_LAST, TDirection] of TGLMultiTexture;
90 var
91 SkyTexture: TGLTexture;
92 RenTextures: array of record
93 spec: LongInt;
94 tex: TGLMultiTexture;
95 end;
96 Items: array [0..ITEM_MAX] of record
97 tex: TGLMultiTexture;
98 anim: TAnimState;
99 end;
100 MonTextures: array [0..MONSTER_MAN] of TMonsterAnims;
101 WeapTextures: array [0..WP_LAST, 0..W_POS_LAST, 0..W_ACT_LAST] of TGLTexture;
102 VileFire: TGLMultiTexture;
103 Models: array of record
104 anim: array [TDirection, 0..A_LAST] of record
105 base, mask: TGLMultiTexture;
106 end;
107 (*
108 {$IFDEF ENABLE_GIBS}
109 gibs: array of record
110 base, mask: TGLTexture;
111 rect: TRectWH;
112 end;
113 {$ENDIF}
114 *)
115 end;
117 plist: TBinHeapPanelDraw = nil;
119 class function TBinHeapPanelDrawCmp.less (const a, b: TPanel): Boolean; inline;
120 begin
121 if a.tag < b.tag then begin result := true; exit; end;
122 if a.tag > b.tag then begin result := false; exit; end;
123 result := a.arrIdx < b.arrIdx;
124 end;
126 procedure r_Map_Initialize;
127 begin
128 plist := TBinHeapPanelDraw.Create();
129 end;
131 procedure r_Map_Finalize;
132 begin
133 plist.Free
134 end;
136 procedure r_Map_LoadModel (i: Integer);
137 var prefix: AnsiString; a: Integer; d: TDirection; m: ^TPlayerModelInfo;
138 begin
139 m := @PlayerModelsArray[i];
140 prefix := m.FileName + ':TEXTURES/';
141 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
142 begin
143 for a := A_STAND to A_LAST do
144 begin
145 Models[i].anim[d, a].base := nil;
146 Models[i].anim[d, a].mask := nil;
147 if m.anim[d, a].resource <> '' then
148 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);
149 if m.anim[d, a].mask <> '' then
150 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);
151 end
152 end;
153 (*
154 {$IFDEF ENABLE_GIBS}
155 Models[i].gibs := nil;
156 if m.GibsCount > 0 then
157 begin
158 SetLength(Models[i].gibs, m.GibsCount);
159 end;
160 {$ENDIF}
161 *)
162 end;
165 procedure r_Map_Load;
166 const
167 WeapName: array [0..WP_LAST] of AnsiString = ('', 'CSAW', 'HGUN', 'SG', 'SSG', 'MGUN', 'RKT', 'PLZ', 'BFG', 'SPL', 'FLM');
168 WeapPos: array [0..W_POS_LAST] of AnsiString = ('', '_UP', '_DN');
169 WeapAct: array [0..W_ACT_LAST] of AnsiString = ('', '_FIRE');
170 var
171 i, j, k: Integer; d: TDirection;
173 procedure LoadItem (i: Integer; const name: AnsiString; w, h, delay, count: Integer; backanim: Boolean);
174 begin
175 ASSERT(i >= 0);
176 ASSERT(i <= ITEM_MAX);
177 Items[i].tex := r_Textures_LoadMultiFromFileAndInfo(GameWAD + ':TEXTURES/' + name, w, h, count, backanim, false);
178 if backanim then count := count * 2 - 2;
179 Items[i].anim := TAnimState.Create(True, delay, count);
180 ASSERT(Items[i].tex <> NIL);
181 end;
183 procedure LoadMonster (m, a: Integer; d: TDirection);
184 const
185 dir: array [TDirection] of AnsiString = ('_L', '');
186 var
187 w, h, count: Integer;
188 begin
189 count := MONSTER_ANIMTABLE[m].AnimCount[a];
190 if count > 0 then
191 begin
192 w := MTABLE[m].w;
193 h := MTABLE[m].h;
194 if (m = MONSTER_SOUL) and (a = ANIM_DIE) then
195 begin
196 // special case
197 w := 128;
198 h := 128;
199 end;
200 MonTextures[m, a, d] := r_Textures_LoadMultiFromFileAndInfo(
201 GameWAD + ':MTEXTURES/' + MONSTERTABLE[m].name + '_' + ANIMTABLE[a].name + dir[d],
202 w,
203 h,
204 count,
205 False,
206 False
208 end
209 else
210 MonTextures[m, a, d] := nil
211 end;
213 begin
214 // --------- items --------- //
215 // i name w h d n backanim
216 LoadItem(ITEM_NONE, 'NOTEXTURE', 16, 16, 0, 1, False);
217 LoadItem(ITEM_MEDKIT_SMALL, 'MED1', 16, 16, 0, 1, False);
218 LoadItem(ITEM_MEDKIT_LARGE, 'MED2', 32, 32, 0, 1, False);
219 LoadItem(ITEM_MEDKIT_BLACK, 'BMED', 32, 32, 0, 1, False);
220 LoadItem(ITEM_ARMOR_GREEN, 'ARMORGREEN', 32, 16, 20, 3, True);
221 LoadItem(ITEM_ARMOR_BLUE, 'ARMORBLUE', 32, 16, 20, 3, True);
222 LoadItem(ITEM_SPHERE_BLUE, 'SBLUE', 32, 32, 15, 4, True);
223 LoadItem(ITEM_SPHERE_WHITE, 'SWHITE', 32, 32, 20, 4, True);
224 LoadItem(ITEM_SUIT, 'SUIT', 32, 64, 0, 1, False);
225 LoadItem(ITEM_OXYGEN, 'OXYGEN', 16, 32, 0, 1, False);
226 LoadItem(ITEM_INVUL, 'INVUL', 32, 32, 20, 4, True);
227 LoadItem(ITEM_WEAPON_SAW, 'SAW', 64, 32, 0, 1, False);
228 LoadItem(ITEM_WEAPON_SHOTGUN1, 'SHOTGUN1', 64, 16, 0, 1, False);
229 LoadItem(ITEM_WEAPON_SHOTGUN2, 'SHOTGUN2', 64, 16, 0, 1, False);
230 LoadItem(ITEM_WEAPON_CHAINGUN, 'MGUN', 64, 16, 0, 1, False);
231 LoadItem(ITEM_WEAPON_ROCKETLAUNCHER, 'RLAUNCHER', 64, 16, 0, 1, False);
232 LoadItem(ITEM_WEAPON_PLASMA, 'PGUN', 64, 16, 0, 1, False);
233 LoadItem(ITEM_WEAPON_BFG, 'BFG', 64, 64, 0, 1, False);
234 LoadItem(ITEM_WEAPON_SUPERPULEMET, 'SPULEMET', 64, 16, 0, 1, False);
235 LoadItem(ITEM_AMMO_BULLETS, 'CLIP', 16, 16, 0, 1, False);
236 LoadItem(ITEM_AMMO_BULLETS_BOX, 'AMMO', 32, 16, 0, 1, False);
237 LoadItem(ITEM_AMMO_SHELLS, 'SHELL1', 16, 8, 0, 1, False);
238 LoadItem(ITEM_AMMO_SHELLS_BOX, 'SHELL2', 32, 16, 0, 1, False);
239 LoadItem(ITEM_AMMO_ROCKET, 'ROCKET', 16, 32, 0, 1, False);
240 LoadItem(ITEM_AMMO_ROCKET_BOX, 'ROCKETS', 64, 32, 0, 1, False);
241 LoadItem(ITEM_AMMO_CELL, 'CELL', 16, 16, 0, 1, False);
242 LoadItem(ITEM_AMMO_CELL_BIG, 'CELL2', 32, 32, 0, 1, False);
243 LoadItem(ITEM_AMMO_BACKPACK, 'BPACK', 32, 32, 0, 1, False);
244 LoadItem(ITEM_KEY_RED, 'KEYR', 16, 16, 0, 1, False);
245 LoadItem(ITEM_KEY_GREEN, 'KEYG', 16, 16, 0, 1, False);
246 LoadItem(ITEM_KEY_BLUE, 'KEYB', 16, 16, 0, 1, False);
247 LoadItem(ITEM_WEAPON_KASTET, 'KASTET', 64, 32, 0, 1, False);
248 LoadItem(ITEM_WEAPON_PISTOL, 'PISTOL', 64, 16, 0, 1, False);
249 LoadItem(ITEM_BOTTLE, 'BOTTLE', 16, 32, 20, 4, True);
250 LoadItem(ITEM_HELMET, 'HELMET', 16, 16, 20, 4, True);
251 LoadItem(ITEM_JETPACK, 'JETPACK', 32, 32, 15, 3, True);
252 LoadItem(ITEM_INVIS, 'INVIS', 32, 32, 20, 4, True);
253 LoadItem(ITEM_WEAPON_FLAMETHROWER, 'FLAMETHROWER', 64, 32, 0, 1, False);
254 LoadItem(ITEM_AMMO_FUELCAN, 'FUELCAN', 16, 32, 0, 1, False);
255 // fill with NOTEXURE forgotten item
256 for i := ITEM_AMMO_FUELCAN + 1 to ITEM_MAX do
257 LoadItem(i,'NOTEXTURE', 16, 16, 0, 1, False);
258 // --------- monsters --------- //
259 for i := MONSTER_DEMON to MONSTER_MAN do
260 for j := 0 to ANIM_LAST do
261 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
262 LoadMonster(i, j, d);
263 VileFire := r_Textures_LoadMultiFromFileAndInfo(GameWAD + ':TEXTURES/FIRE', 64, 128, 8, False, False);
264 // --------- player models --------- //
265 if PlayerModelsArray <> nil then
266 begin
267 SetLength(Models, Length(PlayerModelsArray));
268 for i := 0 to High(PlayerModelsArray) do
269 r_Map_LoadModel(i);
270 end;
271 // --------- player weapons --------- //
272 for i := 1 to WP_LAST do
273 for j := 0 to W_POS_LAST do
274 for k := 0 to W_ACT_LAST do
275 WeapTextures[i, j, k] := r_Textures_LoadFromFile(GameWAD + ':WEAPONS\' + WeapName[i] + WeapPos[j] + WeapAct[k]);
276 end;
278 procedure r_Map_Free;
279 var i, j, k, a: Integer; d: TDirection;
280 begin
281 for i := 1 to WP_LAST do
282 begin
283 for j := 0 to W_POS_LAST do
284 begin
285 for k := 0 to W_ACT_LAST do
286 begin
287 if WeapTextures[i, j, k] <> nil then
288 WeapTextures[i, j, k].Free;
289 WeapTextures[i, j, k] := nil;
290 end;
291 end;
292 end;
293 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
294 begin
295 for a := A_STAND to A_LAST do
296 begin
297 if Models[i].anim[d, a].base <> nil then
298 Models[i].anim[d, a].base.Free;
299 if Models[i].anim[d, a].mask <> nil then
300 Models[i].anim[d, a].mask.Free;
301 Models[i].anim[d, a].base := nil;
302 Models[i].anim[d, a].mask := nil;
303 end;
304 end;
305 for i := MONSTER_DEMON to MONSTER_MAN do
306 begin
307 for j := 0 to ANIM_LAST do
308 begin
309 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
310 begin
311 if MonTextures[i, j, d] <> nil then
312 MonTextures[i, j, d].Free;
313 MonTextures[i, j, d] := nil;
314 end;
315 end;
316 end;
317 for i := 0 to ITEM_MAX do
318 begin
319 if Items[i].tex <> nil then
320 begin
321 Items[i].tex.Free;
322 Items[i].tex := nil;
323 end;
324 Items[i].anim.Invalidate;
325 end;
326 end;
328 procedure r_Map_LoadTextures;
329 var i, n: Integer;
330 begin
331 if Textures <> nil then
332 begin
333 n := Length(Textures);
334 SetLength(RenTextures, n);
335 for i := 0 to n - 1 do
336 begin
337 RenTextures[i].tex := nil;
338 case Textures[i].TextureName of
339 TEXTURE_NAME_WATER: RenTextures[i].spec := TEXTURE_SPECIAL_WATER;
340 TEXTURE_NAME_ACID1: RenTextures[i].spec := TEXTURE_SPECIAL_ACID1;
341 TEXTURE_NAME_ACID2: RenTextures[i].spec := TEXTURE_SPECIAL_ACID2;
342 else
343 RenTextures[i].spec := 0;
344 RenTextures[i].tex := r_Textures_LoadMultiFromFile(Textures[i].FullName);
345 if RenTextures[i].tex = nil then
346 e_LogWritefln('r_Map_LoadTextures: failed to load texture: %s', [Textures[i].FullName]);
347 end;
348 end;
349 end;
350 if gMapInfo.SkyFullName <> '' then
351 SkyTexture := r_Textures_LoadFromFile(gMapInfo.SkyFullName);
352 plist.Clear;
353 end;
355 procedure r_Map_FreeTextures;
356 var i: Integer;
357 begin
358 plist.Clear;
359 if SkyTexture <> nil then
360 SkyTexture.Free;
361 SkyTexture := nil;
362 if RenTextures <> nil then
363 for i := 0 to High(RenTextures) do
364 if RenTextures[i].tex <> nil then
365 RenTextures[i].tex.Free;
366 RenTextures := nil;
367 end;
369 procedure r_Map_Update;
370 var i: Integer;
371 begin
372 for i := 0 to ITEM_MAX do
373 Items[i].anim.Update;
374 end;
376 procedure r_Map_DrawPanel (p: TPanel);
377 var Texture: Integer; t: TGLMultiTexture;
378 begin
379 ASSERT(p <> nil);
380 if p.FCurTexture >= 0 then
381 begin
382 Texture := p.TextureIDs[p.FCurTexture].Texture;
383 t := RenTextures[Texture].tex;
385 if (RenTextures[Texture].spec = 0) or (t <> nil) then
386 begin
387 // TODO set alpha and blending type
388 if t = nil then
389 r_Draw_TextureRepeat(nil, p.x, p.y, p.width, p.height, false)
390 else if p.TextureIDs[p.FCurTexture].AnTex.IsValid() then
391 r_Draw_MultiTextureRepeat(t, p.TextureIDs[p.FCurTexture].AnTex, p.x, p.y, p.width, p.height, false)
392 else
393 r_Draw_TextureRepeat(t.GetTexture(0), p.x, p.y, p.width, p.height, false)
394 end;
396 if t = nil then
397 begin
398 case RenTextures[Texture].spec of
399 TEXTURE_SPECIAL_WATER: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 0, 0, 255, 255);
400 TEXTURE_SPECIAL_ACID1: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 0, 230, 0, 255);
401 TEXTURE_SPECIAL_ACID2: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 230, 0, 0, 255);
402 end
403 end
404 end
405 end;
407 procedure r_Map_DrawPanelType (panelTyp: DWORD);
408 var tagMask, i: Integer; p: TPanel;
409 begin
410 i := 0;
411 tagMask := PanelTypeToTag(panelTyp);
412 while plist.count > 0 do
413 begin
414 p := TPanel(plist.Front());
415 if (p.tag and tagMask) = 0 then
416 break;
417 r_Map_DrawPanel(p);
418 Inc(i);
419 plist.PopFront
420 end;
421 end;
423 procedure r_Map_DrawItems (x, y, w, h: Integer; drop: Boolean);
424 var i, fX, fY: Integer; it: PItem; t: TGLMultiTexture;
425 begin
426 if ggItems <> nil then
427 begin
428 for i := 0 to High(ggItems) do
429 begin
430 it := @ggItems[i];
431 if it.used and it.alive and (it.dropped = drop) and (it.ItemType <> ITEM_NONE) then
432 begin
433 t := Items[it.ItemType].tex;
434 if g_Collide(it.obj.x, it.obj.y, t.width, t.height, x, y, w, h) then
435 begin
436 it.obj.Lerp(gLerpFactor, fX, fY);
437 r_Draw_MultiTextureRepeat(t, Items[it.ItemType].anim, fX, fY, t.width, t.height, false);
438 // if g_debug_frames then // TODO draw collision frame
439 end;
440 end;
441 end;
442 end;
443 end;
445 function r_Map_GetMonsterTexture (m, a: Integer; d: TDirection; out t: TGLMultiTexture; out dx, dy: Integer; out flip: Boolean): Boolean;
446 // var c: Integer;
447 begin
448 t := nil; dx := 0; dy := 0; flip := false;
449 result := MonTextures[m, a, d] <> nil;
450 if result = false then
451 begin
452 flip := true;
453 if d = TDirection.D_RIGHT then d := TDirection.D_LEFT else d := TDirection.D_RIGHT;
454 result := MonTextures[m, a, d] <> nil;
455 end;
456 if result = true then
457 begin
458 t := MonTextures[m, a, d];
459 if d = TDirection.D_LEFT then
460 begin
461 dx := MONSTER_ANIMTABLE[m].AnimDeltaLeft[a].X;
462 dy := MONSTER_ANIMTABLE[m].AnimDeltaLeft[a].Y;
463 end
464 else
465 begin
466 dx := MONSTER_ANIMTABLE[m].AnimDeltaRight[a].X;
467 dy := MONSTER_ANIMTABLE[m].AnimDeltaRight[a].Y;
468 end;
469 if flip then
470 begin
471 // c := (MONSTERTABLE[MonsterType].Rect.X - dx) + MONSTERTABLE[MonsterType].Rect.Width;
472 // dx := MTABLE[m].width - c - MONSTERTABLE[MonsterType].Rect.X;
473 dx := -dx;
474 end;
475 end;
476 end;
478 procedure r_Map_DrawMonsterAttack (constref mon: TMonster);
479 var o: TObj;
480 begin
481 if VileFire <> nil then
482 if (mon.MonsterType = MONSTER_VILE) and (mon.MonsterState = MONSTATE_SHOOT) then
483 if mon.VileFireAnim.IsValid() and GetPos(mon.MonsterTargetUID, @o) then
484 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);
485 end;
487 procedure r_Map_DrawMonster (constref mon: TMonster);
488 var m, a, fX, fY, dx, dy: Integer; d: TDirection; flip: Boolean; t: TGLMultiTexture;
489 begin
490 m := mon.MonsterType;
491 a := mon.MonsterAnim;
492 d := mon.GameDirection;
494 mon.obj.Lerp(gLerpFactor, fX, fY);
496 if r_Map_GetMonsterTexture(m, a, d, t, dx, dy, flip) then
497 r_Draw_MultiTextureRepeat(t, mon.DirAnim[a, d], fX + dx, fY + dy, t.width, t.height, flip);
500 if g_debug_frames
501 // TODO draw frame
503 end;
505 procedure r_Map_DrawMonsters (x, y, w, h: Integer);
506 var i: Integer; m: TMonster;
507 begin
508 if gMonsters <> nil then
509 begin
510 for i := 0 to High(gMonsters) do
511 begin
512 m := gMonsters[i];
513 if m <> nil then
514 begin
515 r_Map_DrawMonsterAttack(m);
516 // TODO select from grid
517 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
518 r_Map_DrawMonster(m);
519 end;
520 end;
521 end;
522 end;
524 function r_Map_GetPlayerModelTex (i: Integer; var a: Integer; var d: TDirection; out flip: Boolean): Boolean;
525 begin
526 flip := false;
527 result := Models[i].anim[d, a].base <> nil;
528 if result = false then
529 begin
530 flip := true;
531 if d = TDirection.D_LEFT then d := TDirection.D_RIGHT else d := TDirection.D_LEFT;
532 result := Models[i].anim[d, a].base <> nil;
533 end;
534 end;
536 procedure r_Map_DrawPlayerModel (pm: TPlayerModel; x, y: Integer);
537 var a, pos, act, xx, yy: Integer; d: TDirection; flip: Boolean; t: TGLMultiTexture; tex: TGLTexture;
538 begin
539 a := pm.CurrentAnimation;
540 d := pm.Direction;
541 // TODO draw flag
542 if PlayerModelsArray[pm.id].HaveWeapon and not (a in [A_DIE1, A_DIE2, A_PAIN]) then
543 begin
544 case a of
545 A_SEEUP, A_ATTACKUP: pos := W_POS_UP;
546 A_SEEDOWN, A_ATTACKDOWN: pos := W_POS_DOWN;
547 else pos := W_POS_NORMAL;
548 end;
549 if (a in [A_ATTACK, A_ATTACKUP, A_ATTACKDOWN]) or pm.GetFire() then
550 act := W_ACT_FIRE
551 else
552 act := W_ACT_NORMAL;
553 tex := WeapTextures[pm.CurrentWeapon, pos, act];
554 if tex <> nil then
555 begin
556 xx := PlayerModelsArray[pm.id].WeaponPoints[pm.CurrentWeapon, a, d, pm.AnimState.CurrentFrame].X;
557 yy := PlayerModelsArray[pm.id].WeaponPoints[pm.CurrentWeapon, a, d, pm.AnimState.CurrentFrame].Y;
558 r_Draw_Texture(
559 tex,
560 x + xx,
561 y + yy,
562 tex.width,
563 tex.height,
564 d = TDirection.D_LEFT
565 );
566 end;
567 end;
568 if r_Map_GetPlayerModelTex(pm.id, a, d, flip) then
569 begin
570 t := Models[pm.id].anim[d, a].base;
571 r_Draw_MultiTextureRepeat(t, pm.AnimState, x, y, t.width, t.height, flip);
572 // TODO colorize mask
573 t := Models[pm.id].anim[d, a].mask;
574 if t <> nil then
575 r_Draw_MultiTextureRepeat(t, pm.AnimState, x, y, t.width, t.height, flip);
576 end;
577 end;
579 procedure r_Map_DrawPlayer (p: TPlayer);
580 var fX, fY, fSlope: Integer;
581 begin
582 if p.alive then
583 begin
584 fX := p.obj.x; fY := p.obj.y;
585 // TODO fix lerp
586 //p.obj.Lerp(gLerpFactor, fX, fY);
587 fSlope := nlerp(p.SlopeOld, p.obj.slopeUpLeft, gLerpFactor);
588 // TODO draw punch
589 // TODO invul pentagram
590 // TODO draw it with transparency
591 r_Map_DrawPlayerModel(p.Model, fX, fY + fSlope);
592 end;
593 // TODO draw g_debug_frames
594 // TODO draw chat bubble
595 // TODO draw aim
596 end;
598 procedure r_Map_DrawPlayers (x, y, w, h: Integer);
599 var i: Integer;
600 begin
601 // TODO draw only visible
602 if gPlayers <> nil then
603 for i := 0 to High(gPlayers) do
604 if gPlayers[i] <> nil then
605 r_Map_DrawPlayer(gPlayers[i]);
606 end;
608 {$IFDEF ENABLE_CORPSES}
609 procedure r_Map_DrawCorpses (x, y, w, h: Integer);
610 var i, fX, fY: Integer; p: TCorpse;
611 begin
612 if gCorpses <> nil then
613 begin
614 for i := 0 to High(gCorpses) do
615 begin
616 p := gCorpses[i];
617 if (p <> nil) and (p.state <> CORPSE_STATE_REMOVEME) and (p.model <> nil) then
618 begin
619 p.obj.Lerp(gLerpFactor, fX, fY);
620 r_Map_DrawPlayerModel(p.model, fX, fY);
621 end;
622 end;
623 end;
624 end;
625 {$ENDIF}
627 procedure r_Map_Draw (x, y, w, h, camx, camy: Integer);
628 var iter: TPanelGrid.Iter; p: PPanel; cx, cy, xx, yy, ww, hh: Integer;
629 begin
630 cx := camx - w div 2;
631 cy := camy - h div 2;
632 xx := x + cx;
633 yy := y + cy;
634 ww := w;
635 hh := h;
637 if SkyTexture <> nil then
638 r_Draw_Texture(SkyTexture, x, y, w, h, false);
640 plist.Clear;
641 iter := mapGrid.ForEachInAABB(xx, yy, ww, hh, GridDrawableMask);
642 for p in iter do
643 if ((p^.tag and GridTagDoor) <> 0) = p^.door then
644 plist.Insert(p^);
645 iter.Release;
647 glPushMatrix;
648 glTranslatef(-cx, -cy, 0);
649 r_Map_DrawPanelType(PANEL_BACK);
650 r_Map_DrawPanelType(PANEL_STEP);
651 r_Map_DrawItems(xx, yy, ww, hh, false);
652 // TODO draw weapons
653 // TODO draw shells
654 r_Map_DrawPlayers(xx, yy, ww, hh);
655 // TODO draw gibs
656 {$IFDEF ENABLE_CORPSES}
657 r_Map_DrawCorpses(xx, yy, ww, hh);
658 {$ENDIF}
659 r_Map_DrawPanelType(PANEL_WALL);
660 r_Map_DrawMonsters(xx, yy, ww, hh);
661 r_Map_DrawItems(xx, yy, ww, hh, true);
662 r_Map_DrawPanelType(PANEL_CLOSEDOOR);
663 // TODO draw gfx
664 // TODO draw flags
665 r_Map_DrawPanelType(PANEL_ACID1);
666 r_Map_DrawPanelType(PANEL_ACID2);
667 r_Map_DrawPanelType(PANEL_WATER);
668 r_Map_DrawPanelType(PANEL_FORE);
669 glPopMatrix;
670 end;
672 end.