1 (* Copyright (C) Doom 2D: Forever Developers
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.
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.
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/>.
15 {$INCLUDE ../../../shared/a_modes.inc}
20 procedure r_Map_Initialize
;
21 procedure r_Map_Finalize
;
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);
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}
57 MTABLE
: array [0..MONSTER_MAN
] of record
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
85 GFXAnim
: array [0..R_GFX_LAST
] of record
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
114 ShotAnim
: array [0..WEAPON_LAST
] of record
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
149 TBinHeapPanelDrawCmp
= class
151 class function less (const a
, b
: TPanel
): Boolean; inline;
154 TBinHeapPanelDraw
= specialize TBinaryHeapBase
<TPanel
, TBinHeapPanelDrawCmp
>;
156 TMonsterAnims
= array [0..ANIM_LAST
, TDirection
] of TGLMultiTexture
;
159 SkyTexture
: TGLTexture
;
160 RenTextures
: array of record
162 tex
: TGLMultiTexture
;
164 Items
: array [0..ITEM_MAX
] of record
165 tex
: TGLMultiTexture
;
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
;
178 gibs: array of record
179 base, mask: TGLTexture;
186 StubShotAnim
: TAnimState
;
189 GFXTextures
: array [0..R_GFX_LAST
] of TGLMultiTexture
;
190 gfxlist
: array of record
199 plist
: TBinHeapPanelDraw
= nil;
201 class function TBinHeapPanelDrawCmp
.less (const a
, b
: TPanel
): Boolean; inline;
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
;
208 procedure r_Map_Initialize
;
210 StubShotAnim
:= TAnimState
.Create(true, 1, 1);
211 plist
:= TBinHeapPanelDraw
.Create();
214 procedure r_Map_Finalize
;
217 StubShotAnim
.Invalidate
;
220 procedure r_Map_LoadModel (i
: Integer);
221 var prefix
: AnsiString; a
: Integer; d
: TDirection
; m
: ^TPlayerModelInfo
;
223 m
:= @PlayerModelsArray
[i
];
224 prefix
:= m
.FileName
+ ':TEXTURES/';
225 for d
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
227 for a
:= A_STAND
to A_LAST
do
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);
239 Models[i].gibs := nil;
240 if m.GibsCount > 0 then
242 SetLength(Models[i].gibs, m.GibsCount);
249 procedure r_Map_Load
;
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');
255 i
, j
, k
: Integer; d
: TDirection
;
257 procedure LoadItem (i
: Integer; const name
: AnsiString; w
, h
, delay
, count
: Integer; backanim
: Boolean);
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);
267 procedure LoadMonster (m
, a
: Integer; d
: TDirection
);
269 dir
: array [TDirection
] of AnsiString = ('_L', '');
271 w
, h
, count
: Integer;
273 count
:= MONSTER_ANIMTABLE
[m
].AnimCount
[a
];
278 if (m
= MONSTER_SOUL
) and (a
= ANIM_DIE
) then
284 MonTextures
[m
, a
, d
] := r_Textures_LoadMultiFromFileAndInfo(
285 GameWAD
+ ':MTEXTURES/' + MONSTERTABLE
[m
].name
+ '_' + ANIMTABLE
[a
].name
+ dir
[d
],
294 MonTextures
[m
, a
, d
] := nil
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
351 SetLength(Models
, Length(PlayerModelsArray
));
352 for i
:= 0 to High(PlayerModelsArray
) do
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 --------- //
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
);
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);
372 procedure r_Map_Free
;
373 var i
, j
, k
, a
: Integer; d
: TDirection
;
375 for i
:= 0 to WEAPON_LAST
do
377 if ShotTextures
[i
] <> nil then
378 ShotTextures
[i
].Free
;
379 ShotTextures
[i
] := nil;
383 for i
:= 0 to R_GFX_LAST
do
385 if GFXTextures
[i
] <> nil then
387 GFXTextures
[i
] := nil;
390 for i
:= 1 to WP_LAST
do
392 for j
:= 0 to W_POS_LAST
do
394 for k
:= 0 to W_ACT_LAST
do
396 if WeapTextures
[i
, j
, k
] <> nil then
397 WeapTextures
[i
, j
, k
].Free
;
398 WeapTextures
[i
, j
, k
] := nil;
402 for d
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
404 for a
:= A_STAND
to A_LAST
do
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;
414 for i
:= MONSTER_DEMON
to MONSTER_MAN
do
416 for j
:= 0 to ANIM_LAST
do
418 for d
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
420 if MonTextures
[i
, j
, d
] <> nil then
421 MonTextures
[i
, j
, d
].Free
;
422 MonTextures
[i
, j
, d
] := nil;
426 for i
:= 0 to ITEM_MAX
do
428 if Items
[i
].tex
<> nil then
433 Items
[i
].anim
.Invalidate
;
437 procedure r_Map_LoadTextures
;
440 if Textures
<> nil then
442 n
:= Length(Textures
);
443 SetLength(RenTextures
, n
);
444 for i
:= 0 to n
- 1 do
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
;
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
]);
459 if gMapInfo
.SkyFullName
<> '' then
460 SkyTexture
:= r_Textures_LoadFromFile(gMapInfo
.SkyFullName
);
464 procedure r_Map_FreeTextures
;
468 if SkyTexture
<> nil then
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
;
478 procedure r_Map_DrawPanel (p
: TPanel
);
479 var Texture
: Integer; t
: TGLMultiTexture
;
482 if p
.FCurTexture
>= 0 then
484 Texture
:= p
.TextureIDs
[p
.FCurTexture
].Texture
;
485 t
:= RenTextures
[Texture
].tex
;
487 if (RenTextures
[Texture
].spec
= 0) or (t
<> nil) then
489 // TODO set alpha and blending type
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)
495 r_Draw_TextureRepeat(t
.GetTexture(0), p
.x
, p
.y
, p
.width
, p
.height
, false)
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);
509 procedure r_Map_DrawPanelType (panelTyp
: DWORD
);
510 var tagMask
, i
: Integer; p
: TPanel
;
513 tagMask
:= PanelTypeToTag(panelTyp
);
514 while plist
.count
> 0 do
516 p
:= TPanel(plist
.Front());
517 if (p
.tag
and tagMask
) = 0 then
525 procedure r_Map_DrawItems (x
, y
, w
, h
: Integer; drop
: Boolean);
526 var i
, fX
, fY
: Integer; it
: PItem
; t
: TGLMultiTexture
;
528 if ggItems
<> nil then
530 for i
:= 0 to High(ggItems
) do
533 if it
.used
and it
.alive
and (it
.dropped
= drop
) and (it
.ItemType
<> ITEM_NONE
) then
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
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
547 function r_Map_GetMonsterTexture (m
, a
: Integer; d
: TDirection
; out t
: TGLMultiTexture
; out dx
, dy
: Integer; out flip
: Boolean): Boolean;
550 t
:= nil; dx
:= 0; dy
:= 0; flip
:= false;
551 result
:= MonTextures
[m
, a
, d
] <> nil;
552 if result
= false then
555 if d
= TDirection
.D_RIGHT
then d
:= TDirection
.D_LEFT
else d
:= TDirection
.D_RIGHT
;
556 result
:= MonTextures
[m
, a
, d
] <> nil;
558 if result
= true then
560 t
:= MonTextures
[m
, a
, d
];
561 if d
= TDirection
.D_LEFT
then
563 dx
:= MONSTER_ANIMTABLE
[m
].AnimDeltaLeft
[a
].X
;
564 dy
:= MONSTER_ANIMTABLE
[m
].AnimDeltaLeft
[a
].Y
;
568 dx
:= MONSTER_ANIMTABLE
[m
].AnimDeltaRight
[a
].X
;
569 dy
:= MONSTER_ANIMTABLE
[m
].AnimDeltaRight
[a
].Y
;
573 // c := (MONSTERTABLE[MonsterType].Rect.X - dx) + MONSTERTABLE[MonsterType].Rect.Width;
574 // dx := MTABLE[m].width - c - MONSTERTABLE[MonsterType].Rect.X;
580 procedure r_Map_DrawMonsterAttack (constref mon
: TMonster
);
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);
589 procedure r_Map_DrawMonster (constref mon
: TMonster
);
590 var m
, a
, fX
, fY
, dx
, dy
: Integer; d
: TDirection
; flip
: Boolean; t
: TGLMultiTexture
;
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
);
607 procedure r_Map_DrawMonsters (x
, y
, w
, h
: Integer);
608 var i
: Integer; m
: TMonster
;
610 if gMonsters
<> nil then
612 for i
:= 0 to High(gMonsters
) do
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
);
626 function r_Map_GetPlayerModelTex (i
: Integer; var a
: Integer; var d
: TDirection
; out flip
: Boolean): Boolean;
629 result
:= Models
[i
].anim
[d
, a
].base
<> nil;
630 if result
= false then
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;
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
;
641 a
:= pm
.CurrentAnimation
;
644 if PlayerModelsArray
[pm
.id
].HaveWeapon
and not (a
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
647 A_SEEUP
, A_ATTACKUP
: pos
:= W_POS_UP
;
648 A_SEEDOWN
, A_ATTACKDOWN
: pos
:= W_POS_DOWN
;
649 else pos
:= W_POS_NORMAL
;
651 if (a
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
]) or pm
.GetFire() then
655 tex
:= WeapTextures
[pm
.CurrentWeapon
, pos
, act
];
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
;
666 d
= TDirection
.D_LEFT
670 if r_Map_GetPlayerModelTex(pm
.id
, a
, d
, flip
) then
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
;
677 r_Draw_MultiTextureRepeat(t
, pm
.AnimState
, x
, y
, t
.width
, t
.height
, flip
);
681 procedure r_Map_DrawPlayer (p
: TPlayer
);
682 var fX
, fY
, fSlope
: Integer;
686 fX
:= p
.obj
.x
; fY
:= p
.obj
.y
;
688 //p.obj.Lerp(gLerpFactor, fX, fY);
689 fSlope
:= nlerp(p
.SlopeOld
, p
.obj
.slopeUpLeft
, gLerpFactor
);
691 // TODO invul pentagram
692 // TODO draw it with transparency
693 r_Map_DrawPlayerModel(p
.Model
, fX
, fY
+ fSlope
);
695 // TODO draw g_debug_frames
696 // TODO draw chat bubble
700 procedure r_Map_DrawPlayers (x
, y
, w
, h
: Integer);
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
]);
710 {$IFDEF ENABLE_CORPSES}
711 procedure r_Map_DrawCorpses (x
, y
, w
, h
: Integer);
712 var i
, fX
, fY
: Integer; p
: TCorpse
;
714 if gCorpses
<> nil then
716 for i
:= 0 to High(gCorpses
) do
719 if (p
<> nil) and (p
.state
<> CORPSE_STATE_REMOVEME
) and (p
.model
<> nil) then
721 p
.obj
.Lerp(gLerpFactor
, fX
, fY
);
722 r_Map_DrawPlayerModel(p
.model
, fX
, fY
);
730 function r_Map_GetGFXID (): Integer;
734 if gfxlist
<> nil then
736 while (i
< Length(gfxlist
)) and gfxlist
[i
].anim
.IsValid() do
738 if i
>= Length(gfxlist
) then
739 SetLength(gfxlist
, Length(gfxlist
) + 1)
742 SetLength(gfxlist
, 1);
743 gfxlist
[i
].typ
:= R_GFX_NONE
;
744 gfxlist
[i
].anim
.Invalidate
;
748 procedure r_Map_NewGFX (typ
, x
, y
: Integer);
751 if gpart_dbg_enabled
and (typ
> 0) and (typ
<= R_GFX_LAST
) then
753 i
:= r_Map_GetGFXID();
756 gfxlist
[i
].typ
:= typ
;
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();
768 procedure r_Map_UpdateGFX
;
771 if gfxlist
<> nil then
773 for i
:= 0 to High(gfxlist
) do
775 if gfxlist
[i
].anim
.IsValid() then
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
:
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);
788 if gfxlist
[i
].anim
.played
then
789 gfxlist
[i
].anim
.Invalidate
791 gfxlist
[i
].anim
.Update
797 procedure r_Map_DrawParticles (x
, y
, w
, h
: Integer);
798 var i
, fx
, fy
: Integer;
800 if gpart_dbg_enabled
and (Particles
<> nil) then
802 glDisable(GL_TEXTURE_2D
);
803 if (g_dbg_scale
< 0.6) then
805 else if (g_dbg_scale
> 1.3) then
806 glPointSize(g_dbg_scale
+ 1)
809 glDisable(GL_POINT_SMOOTH
);
811 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
814 for i
:= 0 to High(Particles
) do
816 if Particles
[i
].alive
then
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
);
830 procedure r_Map_DrawGFX (x
, y
, w
, h
: Integer);
831 var i
, fx
, fy
, typ
: Integer; tex
: TGLMultiTexture
;
833 if gfxlist
<> nil then
835 for i
:= 0 to High(gfxlist
) do
837 if gfxlist
[i
].anim
.IsValid() then
839 typ
:= gfxlist
[i
].typ
;
840 tex
:= GFXTextures
[typ
];
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);
854 procedure r_Map_DrawShots (x
, y
, w
, h
: Integer);
855 var i
, a
, fX
, fY
, pX
, pY
, typ
: Integer; tex
: TGLMultiTexture
; anim
: ^TAnimState
;
859 for i
:= 0 to High(Shots
) do
861 typ
:= Shots
[i
].ShotType
;
864 e_logwritefln('draw shot %s typ %s', [i
, typ
]);
865 tex
:= ShotTextures
[typ
];
868 e_logwritefln('draw shot %s typ %s <> nil', [i
, typ
]);
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
)
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;
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);
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;
890 cx
:= camx
- w
div 2;
891 cy
:= camy
- h
div 2;
897 if SkyTexture
<> nil then
898 r_Draw_Texture(SkyTexture
, x
, y
, w
, h
, false);
901 iter
:= mapGrid
.ForEachInAABB(xx
, yy
, ww
, hh
, GridDrawableMask
);
903 if ((p
^.tag
and GridTagDoor
) <> 0) = p
^.door
then
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
);
914 r_Map_DrawPlayers(xx
, yy
, ww
, hh
);
916 {$IFDEF ENABLE_CORPSES}
917 r_Map_DrawCorpses(xx
, yy
, ww
, hh
);
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
);
924 r_Map_DrawParticles(xx
, yy
, ww
, hh
);
925 r_Map_DrawGFX(xx
, yy
, ww
, hh
);
928 r_Map_DrawPanelType(PANEL_ACID1
);
929 r_Map_DrawPanelType(PANEL_ACID2
);
930 r_Map_DrawPanelType(PANEL_WATER
);
931 r_Map_DrawPanelType(PANEL_FORE
);
935 procedure r_Map_Update
;
938 for i
:= 0 to ITEM_MAX
do
939 Items
[i
].anim
.Update
;