cd146a7b9fbeadd62a28e8058a1dc792beaf20ca
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
115 TBinHeapPanelDrawCmp
= class
117 class function less (const a
, b
: TPanel
): Boolean; inline;
120 TBinHeapPanelDraw
= specialize TBinaryHeapBase
<TPanel
, TBinHeapPanelDrawCmp
>;
122 TMonsterAnims
= array [0..ANIM_LAST
, TDirection
] of TGLMultiTexture
;
125 SkyTexture
: TGLTexture
;
126 RenTextures
: array of record
128 tex
: TGLMultiTexture
;
130 Items
: array [0..ITEM_MAX
] of record
131 tex
: TGLMultiTexture
;
134 MonTextures
: array [0..MONSTER_MAN
] of TMonsterAnims
;
135 WeapTextures
: array [0..WP_LAST
, 0..W_POS_LAST
, 0..W_ACT_LAST
] of TGLTexture
;
136 VileFire
: TGLMultiTexture
;
137 Models
: array of record
138 anim
: array [TDirection
, 0..A_LAST
] of record
139 base
, mask
: TGLMultiTexture
;
143 gibs: array of record
144 base, mask: TGLTexture;
152 GFXTextures
: array [0..R_GFX_LAST
] of TGLMultiTexture
;
153 gfxlist
: array of record
162 plist
: TBinHeapPanelDraw
= nil;
164 class function TBinHeapPanelDrawCmp
.less (const a
, b
: TPanel
): Boolean; inline;
166 if a
.tag
< b
.tag
then begin result
:= true; exit
; end;
167 if a
.tag
> b
.tag
then begin result
:= false; exit
; end;
168 result
:= a
.arrIdx
< b
.arrIdx
;
171 procedure r_Map_Initialize
;
173 plist
:= TBinHeapPanelDraw
.Create();
176 procedure r_Map_Finalize
;
181 procedure r_Map_LoadModel (i
: Integer);
182 var prefix
: AnsiString; a
: Integer; d
: TDirection
; m
: ^TPlayerModelInfo
;
184 m
:= @PlayerModelsArray
[i
];
185 prefix
:= m
.FileName
+ ':TEXTURES/';
186 for d
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
188 for a
:= A_STAND
to A_LAST
do
190 Models
[i
].anim
[d
, a
].base
:= nil;
191 Models
[i
].anim
[d
, a
].mask
:= nil;
192 if m
.anim
[d
, a
].resource
<> '' then
193 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);
194 if m
.anim
[d
, a
].mask
<> '' then
195 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);
200 Models[i].gibs := nil;
201 if m.GibsCount > 0 then
203 SetLength(Models[i].gibs, m.GibsCount);
210 procedure r_Map_Load
;
212 WeapName
: array [0..WP_LAST
] of AnsiString = ('', 'CSAW', 'HGUN', 'SG', 'SSG', 'MGUN', 'RKT', 'PLZ', 'BFG', 'SPL', 'FLM');
213 WeapPos
: array [0..W_POS_LAST
] of AnsiString = ('', '_UP', '_DN');
214 WeapAct
: array [0..W_ACT_LAST
] of AnsiString = ('', '_FIRE');
216 i
, j
, k
: Integer; d
: TDirection
;
218 procedure LoadItem (i
: Integer; const name
: AnsiString; w
, h
, delay
, count
: Integer; backanim
: Boolean);
221 ASSERT(i
<= ITEM_MAX
);
222 Items
[i
].tex
:= r_Textures_LoadMultiFromFileAndInfo(GameWAD
+ ':TEXTURES/' + name
, w
, h
, count
, backanim
, false);
223 if backanim
then count
:= count
* 2 - 2;
224 Items
[i
].anim
:= TAnimState
.Create(True, delay
, count
);
225 ASSERT(Items
[i
].tex
<> NIL);
228 procedure LoadMonster (m
, a
: Integer; d
: TDirection
);
230 dir
: array [TDirection
] of AnsiString = ('_L', '');
232 w
, h
, count
: Integer;
234 count
:= MONSTER_ANIMTABLE
[m
].AnimCount
[a
];
239 if (m
= MONSTER_SOUL
) and (a
= ANIM_DIE
) then
245 MonTextures
[m
, a
, d
] := r_Textures_LoadMultiFromFileAndInfo(
246 GameWAD
+ ':MTEXTURES/' + MONSTERTABLE
[m
].name
+ '_' + ANIMTABLE
[a
].name
+ dir
[d
],
255 MonTextures
[m
, a
, d
] := nil
259 // --------- items --------- //
260 // i name w h d n backanim
261 LoadItem(ITEM_NONE
, 'NOTEXTURE', 16, 16, 0, 1, False);
262 LoadItem(ITEM_MEDKIT_SMALL
, 'MED1', 16, 16, 0, 1, False);
263 LoadItem(ITEM_MEDKIT_LARGE
, 'MED2', 32, 32, 0, 1, False);
264 LoadItem(ITEM_MEDKIT_BLACK
, 'BMED', 32, 32, 0, 1, False);
265 LoadItem(ITEM_ARMOR_GREEN
, 'ARMORGREEN', 32, 16, 20, 3, True);
266 LoadItem(ITEM_ARMOR_BLUE
, 'ARMORBLUE', 32, 16, 20, 3, True);
267 LoadItem(ITEM_SPHERE_BLUE
, 'SBLUE', 32, 32, 15, 4, True);
268 LoadItem(ITEM_SPHERE_WHITE
, 'SWHITE', 32, 32, 20, 4, True);
269 LoadItem(ITEM_SUIT
, 'SUIT', 32, 64, 0, 1, False);
270 LoadItem(ITEM_OXYGEN
, 'OXYGEN', 16, 32, 0, 1, False);
271 LoadItem(ITEM_INVUL
, 'INVUL', 32, 32, 20, 4, True);
272 LoadItem(ITEM_WEAPON_SAW
, 'SAW', 64, 32, 0, 1, False);
273 LoadItem(ITEM_WEAPON_SHOTGUN1
, 'SHOTGUN1', 64, 16, 0, 1, False);
274 LoadItem(ITEM_WEAPON_SHOTGUN2
, 'SHOTGUN2', 64, 16, 0, 1, False);
275 LoadItem(ITEM_WEAPON_CHAINGUN
, 'MGUN', 64, 16, 0, 1, False);
276 LoadItem(ITEM_WEAPON_ROCKETLAUNCHER
, 'RLAUNCHER', 64, 16, 0, 1, False);
277 LoadItem(ITEM_WEAPON_PLASMA
, 'PGUN', 64, 16, 0, 1, False);
278 LoadItem(ITEM_WEAPON_BFG
, 'BFG', 64, 64, 0, 1, False);
279 LoadItem(ITEM_WEAPON_SUPERPULEMET
, 'SPULEMET', 64, 16, 0, 1, False);
280 LoadItem(ITEM_AMMO_BULLETS
, 'CLIP', 16, 16, 0, 1, False);
281 LoadItem(ITEM_AMMO_BULLETS_BOX
, 'AMMO', 32, 16, 0, 1, False);
282 LoadItem(ITEM_AMMO_SHELLS
, 'SHELL1', 16, 8, 0, 1, False);
283 LoadItem(ITEM_AMMO_SHELLS_BOX
, 'SHELL2', 32, 16, 0, 1, False);
284 LoadItem(ITEM_AMMO_ROCKET
, 'ROCKET', 16, 32, 0, 1, False);
285 LoadItem(ITEM_AMMO_ROCKET_BOX
, 'ROCKETS', 64, 32, 0, 1, False);
286 LoadItem(ITEM_AMMO_CELL
, 'CELL', 16, 16, 0, 1, False);
287 LoadItem(ITEM_AMMO_CELL_BIG
, 'CELL2', 32, 32, 0, 1, False);
288 LoadItem(ITEM_AMMO_BACKPACK
, 'BPACK', 32, 32, 0, 1, False);
289 LoadItem(ITEM_KEY_RED
, 'KEYR', 16, 16, 0, 1, False);
290 LoadItem(ITEM_KEY_GREEN
, 'KEYG', 16, 16, 0, 1, False);
291 LoadItem(ITEM_KEY_BLUE
, 'KEYB', 16, 16, 0, 1, False);
292 LoadItem(ITEM_WEAPON_KASTET
, 'KASTET', 64, 32, 0, 1, False);
293 LoadItem(ITEM_WEAPON_PISTOL
, 'PISTOL', 64, 16, 0, 1, False);
294 LoadItem(ITEM_BOTTLE
, 'BOTTLE', 16, 32, 20, 4, True);
295 LoadItem(ITEM_HELMET
, 'HELMET', 16, 16, 20, 4, True);
296 LoadItem(ITEM_JETPACK
, 'JETPACK', 32, 32, 15, 3, True);
297 LoadItem(ITEM_INVIS
, 'INVIS', 32, 32, 20, 4, True);
298 LoadItem(ITEM_WEAPON_FLAMETHROWER
, 'FLAMETHROWER', 64, 32, 0, 1, False);
299 LoadItem(ITEM_AMMO_FUELCAN
, 'FUELCAN', 16, 32, 0, 1, False);
300 // fill with NOTEXURE forgotten item
301 for i
:= ITEM_AMMO_FUELCAN
+ 1 to ITEM_MAX
do
302 LoadItem(i
,'NOTEXTURE', 16, 16, 0, 1, False);
303 // --------- monsters --------- //
304 for i
:= MONSTER_DEMON
to MONSTER_MAN
do
305 for j
:= 0 to ANIM_LAST
do
306 for d
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
307 LoadMonster(i
, j
, d
);
308 VileFire
:= r_Textures_LoadMultiFromFileAndInfo(GameWAD
+ ':TEXTURES/FIRE', 64, 128, 8, False, False);
309 // --------- player models --------- //
310 if PlayerModelsArray
<> nil then
312 SetLength(Models
, Length(PlayerModelsArray
));
313 for i
:= 0 to High(PlayerModelsArray
) do
316 // --------- player weapons --------- //
317 for i
:= 1 to WP_LAST
do
318 for j
:= 0 to W_POS_LAST
do
319 for k
:= 0 to W_ACT_LAST
do
320 WeapTextures
[i
, j
, k
] := r_Textures_LoadFromFile(GameWAD
+ ':WEAPONS\' + WeapName
[i
] + WeapPos
[j
] + WeapAct
[k
]);
321 // --------- gfx animations --------- //
323 for i
:= 1 to R_GFX_LAST
do
324 GFXTextures
[i
] := r_Textures_LoadMultiFromFileAndInfo(GameWad
+ ':TEXTURES/' + GFXAnim
[i
].name
, GFXAnim
[i
].w
, GFXAnim
[i
].h
, GFXAnim
[i
].count
, GFXAnim
[i
].back
);
328 procedure r_Map_Free
;
329 var i
, j
, k
, a
: Integer; d
: TDirection
;
333 for i
:= 0 to R_GFX_LAST
do
335 if GFXTextures
[i
] <> nil then
337 GFXTextures
[i
] := nil;
340 for i
:= 1 to WP_LAST
do
342 for j
:= 0 to W_POS_LAST
do
344 for k
:= 0 to W_ACT_LAST
do
346 if WeapTextures
[i
, j
, k
] <> nil then
347 WeapTextures
[i
, j
, k
].Free
;
348 WeapTextures
[i
, j
, k
] := nil;
352 for d
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
354 for a
:= A_STAND
to A_LAST
do
356 if Models
[i
].anim
[d
, a
].base
<> nil then
357 Models
[i
].anim
[d
, a
].base
.Free
;
358 if Models
[i
].anim
[d
, a
].mask
<> nil then
359 Models
[i
].anim
[d
, a
].mask
.Free
;
360 Models
[i
].anim
[d
, a
].base
:= nil;
361 Models
[i
].anim
[d
, a
].mask
:= nil;
364 for i
:= MONSTER_DEMON
to MONSTER_MAN
do
366 for j
:= 0 to ANIM_LAST
do
368 for d
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
370 if MonTextures
[i
, j
, d
] <> nil then
371 MonTextures
[i
, j
, d
].Free
;
372 MonTextures
[i
, j
, d
] := nil;
376 for i
:= 0 to ITEM_MAX
do
378 if Items
[i
].tex
<> nil then
383 Items
[i
].anim
.Invalidate
;
387 procedure r_Map_LoadTextures
;
390 if Textures
<> nil then
392 n
:= Length(Textures
);
393 SetLength(RenTextures
, n
);
394 for i
:= 0 to n
- 1 do
396 RenTextures
[i
].tex
:= nil;
397 case Textures
[i
].TextureName
of
398 TEXTURE_NAME_WATER
: RenTextures
[i
].spec
:= TEXTURE_SPECIAL_WATER
;
399 TEXTURE_NAME_ACID1
: RenTextures
[i
].spec
:= TEXTURE_SPECIAL_ACID1
;
400 TEXTURE_NAME_ACID2
: RenTextures
[i
].spec
:= TEXTURE_SPECIAL_ACID2
;
402 RenTextures
[i
].spec
:= 0;
403 RenTextures
[i
].tex
:= r_Textures_LoadMultiFromFile(Textures
[i
].FullName
);
404 if RenTextures
[i
].tex
= nil then
405 e_LogWritefln('r_Map_LoadTextures: failed to load texture: %s', [Textures
[i
].FullName
]);
409 if gMapInfo
.SkyFullName
<> '' then
410 SkyTexture
:= r_Textures_LoadFromFile(gMapInfo
.SkyFullName
);
414 procedure r_Map_FreeTextures
;
418 if SkyTexture
<> nil then
421 if RenTextures
<> nil then
422 for i
:= 0 to High(RenTextures
) do
423 if RenTextures
[i
].tex
<> nil then
424 RenTextures
[i
].tex
.Free
;
428 procedure r_Map_DrawPanel (p
: TPanel
);
429 var Texture
: Integer; t
: TGLMultiTexture
;
432 if p
.FCurTexture
>= 0 then
434 Texture
:= p
.TextureIDs
[p
.FCurTexture
].Texture
;
435 t
:= RenTextures
[Texture
].tex
;
437 if (RenTextures
[Texture
].spec
= 0) or (t
<> nil) then
439 // TODO set alpha and blending type
441 r_Draw_TextureRepeat(nil, p
.x
, p
.y
, p
.width
, p
.height
, false)
442 else if p
.TextureIDs
[p
.FCurTexture
].AnTex
.IsValid() then
443 r_Draw_MultiTextureRepeat(t
, p
.TextureIDs
[p
.FCurTexture
].AnTex
, p
.x
, p
.y
, p
.width
, p
.height
, false)
445 r_Draw_TextureRepeat(t
.GetTexture(0), p
.x
, p
.y
, p
.width
, p
.height
, false)
450 case RenTextures
[Texture
].spec
of
451 TEXTURE_SPECIAL_WATER
: r_Draw_Filter(p
.x
, p
.y
, p
.x
+ p
.width
, p
.y
+ p
.height
, 0, 0, 255, 255);
452 TEXTURE_SPECIAL_ACID1
: r_Draw_Filter(p
.x
, p
.y
, p
.x
+ p
.width
, p
.y
+ p
.height
, 0, 230, 0, 255);
453 TEXTURE_SPECIAL_ACID2
: r_Draw_Filter(p
.x
, p
.y
, p
.x
+ p
.width
, p
.y
+ p
.height
, 230, 0, 0, 255);
459 procedure r_Map_DrawPanelType (panelTyp
: DWORD
);
460 var tagMask
, i
: Integer; p
: TPanel
;
463 tagMask
:= PanelTypeToTag(panelTyp
);
464 while plist
.count
> 0 do
466 p
:= TPanel(plist
.Front());
467 if (p
.tag
and tagMask
) = 0 then
475 procedure r_Map_DrawItems (x
, y
, w
, h
: Integer; drop
: Boolean);
476 var i
, fX
, fY
: Integer; it
: PItem
; t
: TGLMultiTexture
;
478 if ggItems
<> nil then
480 for i
:= 0 to High(ggItems
) do
483 if it
.used
and it
.alive
and (it
.dropped
= drop
) and (it
.ItemType
<> ITEM_NONE
) then
485 t
:= Items
[it
.ItemType
].tex
;
486 if g_Collide(it
.obj
.x
, it
.obj
.y
, t
.width
, t
.height
, x
, y
, w
, h
) then
488 it
.obj
.Lerp(gLerpFactor
, fX
, fY
);
489 r_Draw_MultiTextureRepeat(t
, Items
[it
.ItemType
].anim
, fX
, fY
, t
.width
, t
.height
, false);
490 // if g_debug_frames then // TODO draw collision frame
497 function r_Map_GetMonsterTexture (m
, a
: Integer; d
: TDirection
; out t
: TGLMultiTexture
; out dx
, dy
: Integer; out flip
: Boolean): Boolean;
500 t
:= nil; dx
:= 0; dy
:= 0; flip
:= false;
501 result
:= MonTextures
[m
, a
, d
] <> nil;
502 if result
= false then
505 if d
= TDirection
.D_RIGHT
then d
:= TDirection
.D_LEFT
else d
:= TDirection
.D_RIGHT
;
506 result
:= MonTextures
[m
, a
, d
] <> nil;
508 if result
= true then
510 t
:= MonTextures
[m
, a
, d
];
511 if d
= TDirection
.D_LEFT
then
513 dx
:= MONSTER_ANIMTABLE
[m
].AnimDeltaLeft
[a
].X
;
514 dy
:= MONSTER_ANIMTABLE
[m
].AnimDeltaLeft
[a
].Y
;
518 dx
:= MONSTER_ANIMTABLE
[m
].AnimDeltaRight
[a
].X
;
519 dy
:= MONSTER_ANIMTABLE
[m
].AnimDeltaRight
[a
].Y
;
523 // c := (MONSTERTABLE[MonsterType].Rect.X - dx) + MONSTERTABLE[MonsterType].Rect.Width;
524 // dx := MTABLE[m].width - c - MONSTERTABLE[MonsterType].Rect.X;
530 procedure r_Map_DrawMonsterAttack (constref mon
: TMonster
);
533 if VileFire
<> nil then
534 if (mon
.MonsterType
= MONSTER_VILE
) and (mon
.MonsterState
= MONSTATE_SHOOT
) then
535 if mon
.VileFireAnim
.IsValid() and GetPos(mon
.MonsterTargetUID
, @o
) then
536 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);
539 procedure r_Map_DrawMonster (constref mon
: TMonster
);
540 var m
, a
, fX
, fY
, dx
, dy
: Integer; d
: TDirection
; flip
: Boolean; t
: TGLMultiTexture
;
542 m
:= mon
.MonsterType
;
543 a
:= mon
.MonsterAnim
;
544 d
:= mon
.GameDirection
;
546 mon
.obj
.Lerp(gLerpFactor
, fX
, fY
);
548 if r_Map_GetMonsterTexture(m
, a
, d
, t
, dx
, dy
, flip
) then
549 r_Draw_MultiTextureRepeat(t
, mon
.DirAnim
[a
, d
], fX
+ dx
, fY
+ dy
, t
.width
, t
.height
, flip
);
557 procedure r_Map_DrawMonsters (x
, y
, w
, h
: Integer);
558 var i
: Integer; m
: TMonster
;
560 if gMonsters
<> nil then
562 for i
:= 0 to High(gMonsters
) do
567 r_Map_DrawMonsterAttack(m
);
568 // TODO select from grid
569 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
570 r_Map_DrawMonster(m
);
576 function r_Map_GetPlayerModelTex (i
: Integer; var a
: Integer; var d
: TDirection
; out flip
: Boolean): Boolean;
579 result
:= Models
[i
].anim
[d
, a
].base
<> nil;
580 if result
= false then
583 if d
= TDirection
.D_LEFT
then d
:= TDirection
.D_RIGHT
else d
:= TDirection
.D_LEFT
;
584 result
:= Models
[i
].anim
[d
, a
].base
<> nil;
588 procedure r_Map_DrawPlayerModel (pm
: TPlayerModel
; x
, y
: Integer);
589 var a
, pos
, act
, xx
, yy
: Integer; d
: TDirection
; flip
: Boolean; t
: TGLMultiTexture
; tex
: TGLTexture
;
591 a
:= pm
.CurrentAnimation
;
594 if PlayerModelsArray
[pm
.id
].HaveWeapon
and not (a
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
597 A_SEEUP
, A_ATTACKUP
: pos
:= W_POS_UP
;
598 A_SEEDOWN
, A_ATTACKDOWN
: pos
:= W_POS_DOWN
;
599 else pos
:= W_POS_NORMAL
;
601 if (a
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
]) or pm
.GetFire() then
605 tex
:= WeapTextures
[pm
.CurrentWeapon
, pos
, act
];
608 xx
:= PlayerModelsArray
[pm
.id
].WeaponPoints
[pm
.CurrentWeapon
, a
, d
, pm
.AnimState
.CurrentFrame
].X
;
609 yy
:= PlayerModelsArray
[pm
.id
].WeaponPoints
[pm
.CurrentWeapon
, a
, d
, pm
.AnimState
.CurrentFrame
].Y
;
616 d
= TDirection
.D_LEFT
620 if r_Map_GetPlayerModelTex(pm
.id
, a
, d
, flip
) then
622 t
:= Models
[pm
.id
].anim
[d
, a
].base
;
623 r_Draw_MultiTextureRepeat(t
, pm
.AnimState
, x
, y
, t
.width
, t
.height
, flip
);
624 // TODO colorize mask
625 t
:= Models
[pm
.id
].anim
[d
, a
].mask
;
627 r_Draw_MultiTextureRepeat(t
, pm
.AnimState
, x
, y
, t
.width
, t
.height
, flip
);
631 procedure r_Map_DrawPlayer (p
: TPlayer
);
632 var fX
, fY
, fSlope
: Integer;
636 fX
:= p
.obj
.x
; fY
:= p
.obj
.y
;
638 //p.obj.Lerp(gLerpFactor, fX, fY);
639 fSlope
:= nlerp(p
.SlopeOld
, p
.obj
.slopeUpLeft
, gLerpFactor
);
641 // TODO invul pentagram
642 // TODO draw it with transparency
643 r_Map_DrawPlayerModel(p
.Model
, fX
, fY
+ fSlope
);
645 // TODO draw g_debug_frames
646 // TODO draw chat bubble
650 procedure r_Map_DrawPlayers (x
, y
, w
, h
: Integer);
653 // TODO draw only visible
654 if gPlayers
<> nil then
655 for i
:= 0 to High(gPlayers
) do
656 if gPlayers
[i
] <> nil then
657 r_Map_DrawPlayer(gPlayers
[i
]);
660 {$IFDEF ENABLE_CORPSES}
661 procedure r_Map_DrawCorpses (x
, y
, w
, h
: Integer);
662 var i
, fX
, fY
: Integer; p
: TCorpse
;
664 if gCorpses
<> nil then
666 for i
:= 0 to High(gCorpses
) do
669 if (p
<> nil) and (p
.state
<> CORPSE_STATE_REMOVEME
) and (p
.model
<> nil) then
671 p
.obj
.Lerp(gLerpFactor
, fX
, fY
);
672 r_Map_DrawPlayerModel(p
.model
, fX
, fY
);
680 function r_Map_GetGFXID (): Integer;
684 if gfxlist
<> nil then
686 while (i
< Length(gfxlist
)) and gfxlist
[i
].anim
.IsValid() do
688 if i
>= Length(gfxlist
) then
689 SetLength(gfxlist
, Length(gfxlist
) + 1)
692 SetLength(gfxlist
, 1);
693 gfxlist
[i
].typ
:= R_GFX_NONE
;
694 gfxlist
[i
].anim
.Invalidate
;
698 procedure r_Map_NewGFX (typ
, x
, y
: Integer);
701 if gpart_dbg_enabled
and (typ
> 0) and (typ
<= R_GFX_LAST
) then
703 i
:= r_Map_GetGFXID();
706 gfxlist
[i
].typ
:= typ
;
709 gfxlist
[i
].oldX
:= x
;
710 gfxlist
[i
].oldY
:= y
;
711 gfxlist
[i
].anim
:= TAnimState
.Create(false, GFXAnim
[typ
].speed
+ Random(GFXAnim
[typ
].rspeed
), GFXAnim
[typ
].count
);
712 gfxlist
[i
].anim
.Reset();
713 gfxlist
[i
].anim
.Enable();
718 procedure r_Map_UpdateGFX
;
721 if gfxlist
<> nil then
723 for i
:= 0 to High(gfxlist
) do
725 if gfxlist
[i
].anim
.IsValid() then
727 gfxlist
[i
].oldX
:= gfxlist
[i
].x
;
728 gfxlist
[i
].oldY
:= gfxlist
[i
].y
;
729 case gfxlist
[i
].typ
of
730 R_GFX_FLAME
, R_GFX_SMOKE
:
732 if Random(3) = 0 then
733 gfxlist
[i
].x
:= gfxlist
[i
].x
- 1 + Random(3);
734 if Random(2) = 0 then
735 gfxlist
[i
].y
:= gfxlist
[i
].y
- Random(2);
738 if gfxlist
[i
].anim
.played
then
739 gfxlist
[i
].anim
.Invalidate
741 gfxlist
[i
].anim
.Update
747 procedure r_Map_DrawParticles (x
, y
, w
, h
: Integer);
748 var i
, fx
, fy
: Integer;
750 if gpart_dbg_enabled
and (Particles
<> nil) then
752 glDisable(GL_TEXTURE_2D
);
753 if (g_dbg_scale
< 0.6) then
755 else if (g_dbg_scale
> 1.3) then
756 glPointSize(g_dbg_scale
+ 1)
759 glDisable(GL_POINT_SMOOTH
);
761 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
764 for i
:= 0 to High(Particles
) do
766 if Particles
[i
].alive
then
768 fx
:= nlerp(Particles
[i
].oldX
, Particles
[i
].x
, gLerpFactor
);
769 fy
:= nlerp(Particles
[i
].oldY
, Particles
[i
].y
, gLerpFactor
);
770 glColor4ub(Particles
[i
].red
, Particles
[i
].green
, Particles
[i
].blue
, Particles
[i
].alpha
);
780 procedure r_Map_DrawGFX (x
, y
, w
, h
: Integer);
781 var i
, fx
, fy
, typ
: Integer; tex
: TGLMultiTexture
;
783 if gfxlist
<> nil then
785 for i
:= 0 to High(gfxlist
) do
787 if gfxlist
[i
].anim
.IsValid() then
789 typ
:= gfxlist
[i
].typ
;
790 tex
:= GFXTextures
[typ
];
793 fx
:= nlerp(gfxlist
[i
].oldX
, gfxlist
[i
].x
, gLerpFactor
);
794 fy
:= nlerp(gfxlist
[i
].oldY
, gfxlist
[i
].y
, gLerpFactor
);
795 // TODO set GFXAnim[typ].alpha
796 r_Draw_MultiTextureRepeat(tex
, gfxlist
[i
].anim
, fx
, fy
, tex
.width
, tex
.height
, false);
804 procedure r_Map_Draw (x
, y
, w
, h
, camx
, camy
: Integer);
805 var iter
: TPanelGrid
.Iter
; p
: PPanel
; cx
, cy
, xx
, yy
, ww
, hh
: Integer;
807 cx
:= camx
- w
div 2;
808 cy
:= camy
- h
div 2;
814 if SkyTexture
<> nil then
815 r_Draw_Texture(SkyTexture
, x
, y
, w
, h
, false);
818 iter
:= mapGrid
.ForEachInAABB(xx
, yy
, ww
, hh
, GridDrawableMask
);
820 if ((p
^.tag
and GridTagDoor
) <> 0) = p
^.door
then
825 glTranslatef(-cx
, -cy
, 0);
826 r_Map_DrawPanelType(PANEL_BACK
);
827 r_Map_DrawPanelType(PANEL_STEP
);
828 r_Map_DrawItems(xx
, yy
, ww
, hh
, false);
831 r_Map_DrawPlayers(xx
, yy
, ww
, hh
);
833 {$IFDEF ENABLE_CORPSES}
834 r_Map_DrawCorpses(xx
, yy
, ww
, hh
);
836 r_Map_DrawPanelType(PANEL_WALL
);
837 r_Map_DrawMonsters(xx
, yy
, ww
, hh
);
838 r_Map_DrawItems(xx
, yy
, ww
, hh
, true);
839 r_Map_DrawPanelType(PANEL_CLOSEDOOR
);
841 r_Map_DrawParticles(xx
, yy
, ww
, hh
);
842 r_Map_DrawGFX(xx
, yy
, ww
, hh
);
845 r_Map_DrawPanelType(PANEL_ACID1
);
846 r_Map_DrawPanelType(PANEL_ACID2
);
847 r_Map_DrawPanelType(PANEL_WATER
);
848 r_Map_DrawPanelType(PANEL_FORE
);
852 procedure r_Map_Update
;
855 for i
:= 0 to ITEM_MAX
do
856 Items
[i
].anim
.Update
;