8438e2d35db92e44cf931e8c34881487d55f10e0
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);
45 binheap
, MAPDEF
, utils
,
46 g_options
, g_textures
, g_basic
, g_base
, g_phys
,
47 g_game
, g_map
, g_panel
, g_items
, g_monsters
, g_playermodel
, g_player
, g_weapons
,
48 {$IFDEF ENABLE_CORPSES}
58 MTABLE
: array [0..MONSTER_MAN
] of record
61 (w
: 64; h
: 64), // NONE
62 (w
: 64; h
: 64), // DEMON
63 (w
: 64; h
: 64), // IMP
64 (w
: 64; h
: 64), // ZOMBY
65 (w
: 64; h
: 64), // SERG
66 (w
: 128; h
: 128), // CYBER
67 (w
: 64; h
: 64), // CGUN
68 (w
: 128; h
: 128), // BARON
69 (w
: 128; h
: 128), // KNIGHT
70 (w
: 128; h
: 128), // CACO
71 (w
: 64; h
: 64), // SOUL (DIE is 128x128, see load code)
72 (w
: 128; h
: 128), // PAIN
73 (w
: 256; h
: 128), // SPIDER
74 (w
: 128; h
: 64), // BSP
75 (w
: 128; h
: 128), // MANCUB
76 (w
: 128; h
: 128), // SKEL
77 (w
: 128; h
: 128), // VILE
78 (w
: 32; h
: 32), // FISH
79 (w
: 64; h
: 64), // BARREL
80 (w
: 128; h
: 128), // ROBO
86 GFXAnim
: array [0..R_GFX_LAST
] of record
95 (name
: ''; w
: 0; h
: 0; count
: 0; back
: false; speed
: 0; rspeed
: 0; alpha
: 0),
96 (name
: 'TELEPORT'; w
: 64; h
: 64; count
: 10; back
: false; speed
: 6; rspeed
: 0; alpha
: 0),
97 (name
: 'FLAME'; w
: 32; h
: 32; count
: 11; back
: false; speed
: 3; rspeed
: 0; alpha
: 0),
98 (name
: 'EROCKET'; w
: 128; h
: 128; count
: 6; back
: false; speed
: 6; rspeed
: 0; alpha
: 0),
99 (name
: 'EBFG'; w
: 128; h
: 128; count
: 6; back
: false; speed
: 6; rspeed
: 0; alpha
: 0),
100 (name
: 'BFGHIT'; w
: 64; h
: 64; count
: 4; back
: false; speed
: 4; rspeed
: 0; alpha
: 0),
101 (name
: 'FIRE'; w
: 64; h
: 128; count
: 8; back
: false; speed
: 4; rspeed
: 2; alpha
: 0),
102 (name
: 'ITEMRESPAWN'; w
: 32; h
: 32; count
: 5; back
: true; speed
: 4; rspeed
: 0; alpha
: 0),
103 (name
: 'SMOKE'; w
: 32; h
: 32; count
: 10; back
: false; speed
: 3; rspeed
: 0; alpha
: 0),
104 (name
: 'ESKELFIRE'; w
: 64; h
: 64; count
: 3; back
: false; speed
: 8; rspeed
: 0; alpha
: 0),
105 (name
: 'EPLASMA'; w
: 32; h
: 32; count
: 4; back
: true; speed
: 3; rspeed
: 0; alpha
: 0),
106 (name
: 'EBSPFIRE'; w
: 32; h
: 32; count
: 5; back
: false; speed
: 3; rspeed
: 0; alpha
: 0),
107 (name
: 'EIMPFIRE'; w
: 64; h
: 64; count
: 3; back
: false; speed
: 6; rspeed
: 0; alpha
: 0),
108 (name
: 'ECACOFIRE'; w
: 64; h
: 64; count
: 3; back
: false; speed
: 6; rspeed
: 0; alpha
: 0),
109 (name
: 'EBARONFIRE'; w
: 64; h
: 64; count
: 3; back
: false; speed
: 6; rspeed
: 0; alpha
: 0),
110 (name
: 'TELEPORT'; w
: 64; h
: 64; count
: 10; back
: false; speed
: 3; rspeed
: 0; alpha
: 0), // fast
111 (name
: 'SMOKE'; w
: 32; h
: 32; count
: 10; back
: false; speed
: 3; rspeed
: 0; alpha
: 150), // transparent
112 (name
: 'FLAME'; w
: 32; h
: 32; count
: 11; back
: false; speed
: 3; rspeed
: 2; alpha
: 0) // random
115 ShotAnim
: array [0..WEAPON_LAST
] of record
120 (name
: ''; w
: 0; h
: 0; count
: 0), // 0 KASTET
121 (name
: ''; w
: 0; h
: 0; count
: 0), // 1 SAW
122 (name
: ''; w
: 0; h
: 0; count
: 0), // 2 PISTOL
123 (name
: ''; w
: 0; h
: 0; count
: 0), // 3 SHOTGUN1
124 (name
: ''; w
: 0; h
: 0; count
: 0), // 4 SHOTGUN2
125 (name
: ''; w
: 0; h
: 0; count
: 0), // 5 CHAINGUN
126 (name
: 'BROCKET'; w
: 64; h
: 32; count
: 1), // 6 ROCKETLAUNCHER
127 (name
: 'BPLASMA'; w
: 16; h
: 16; count
: 2), // 7 PLASMA
128 (name
: 'BBFG'; w
: 64; h
: 64; count
: 2), // 8 BFG
129 (name
: ''; w
: 0; h
: 0; count
: 0), // 9 SUPERPULEMET
130 (name
: 'FLAME'; w
: 32; h
: 32; count
: 0{11}), // 10 FLAMETHROWER
131 (name
: ''; w
: 0; h
: 0; count
: 0), // 11
132 (name
: ''; w
: 0; h
: 0; count
: 0), // 12
133 (name
: ''; w
: 0; h
: 0; count
: 0), // 13
134 (name
: ''; w
: 0; h
: 0; count
: 0), // 14
135 (name
: ''; w
: 0; h
: 0; count
: 0), // 15
136 (name
: ''; w
: 0; h
: 0; count
: 0), // 16
137 (name
: ''; w
: 0; h
: 0; count
: 0), // 17
138 (name
: ''; w
: 0; h
: 0; count
: 0), // 18
139 (name
: ''; w
: 0; h
: 0; count
: 0), // 19
140 (name
: ''; w
: 0; h
: 0; count
: 0), // 20 ZOMPY_PISTOL
141 (name
: 'BIMPFIRE'; w
: 16; h
: 16; count
: 2), // 21 IMP_FIRE
142 (name
: 'BBSPFIRE'; w
: 16; h
: 16; count
: 2), // 22 BSP_FIRE
143 (name
: 'BCACOFIRE'; w
: 16; h
: 16; count
: 2), // 23 CACO_FIRE
144 (name
: 'BBARONFIRE'; w
: 64; h
: 16; count
: 2), // 24 BARON_FIRE
145 (name
: 'BMANCUBFIRE'; w
: 64; h
: 32; count
: 2), // 25 MANCUB_FIRE
146 (name
: 'BSKELFIRE'; w
: 64; h
: 64; count
: 2) // 26 SKEL_FIRE
150 TBinHeapPanelDrawCmp
= class
152 class function less (const a
, b
: TPanel
): Boolean; inline;
155 TBinHeapPanelDraw
= specialize TBinaryHeapBase
<TPanel
, TBinHeapPanelDrawCmp
>;
157 TMonsterAnims
= array [0..ANIM_LAST
, TDirection
] of TGLMultiTexture
;
160 SkyTexture
: TGLTexture
;
161 RenTextures
: array of record
163 tex
: TGLMultiTexture
;
165 Items
: array [0..ITEM_MAX
] of record
166 tex
: TGLMultiTexture
;
169 MonTextures
: array [0..MONSTER_MAN
] of TMonsterAnims
;
170 WeapTextures
: array [0..WP_LAST
, 0..W_POS_LAST
, 0..W_ACT_LAST
] of TGLTexture
;
171 ShotTextures
: array [0..WEAPON_LAST
] of TGLMultiTexture
;
172 FlagTextures
: array [0..FLAG_LAST
] of TGLMultiTexture
;
173 VileFire
: TGLMultiTexture
;
174 Models
: array of record
175 anim
: array [TDirection
, 0..A_LAST
] of record
176 base
, mask
: TGLMultiTexture
;
180 gibs: array of record
181 base, mask: TGLTexture;
188 StubShotAnim
: TAnimState
;
189 FlagAnim
: TAnimState
;
192 GFXTextures
: array [0..R_GFX_LAST
] of TGLMultiTexture
;
193 gfxlist
: array of record
202 plist
: TBinHeapPanelDraw
= nil;
204 class function TBinHeapPanelDrawCmp
.less (const a
, b
: TPanel
): Boolean; inline;
206 if a
.tag
< b
.tag
then begin result
:= true; exit
; end;
207 if a
.tag
> b
.tag
then begin result
:= false; exit
; end;
208 result
:= a
.arrIdx
< b
.arrIdx
;
211 procedure r_Map_Initialize
;
213 StubShotAnim
:= TAnimState
.Create(true, 1, 1);
214 FlagAnim
:= TAnimState
.Create(true, 8, 5);
215 plist
:= TBinHeapPanelDraw
.Create();
218 procedure r_Map_Finalize
;
221 StubShotAnim
.Invalidate
;
224 procedure r_Map_LoadModel (i
: Integer);
225 var prefix
: AnsiString; a
: Integer; d
: TDirection
; m
: ^TPlayerModelInfo
;
227 m
:= @PlayerModelsArray
[i
];
228 prefix
:= m
.FileName
+ ':TEXTURES/';
229 for d
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
231 for a
:= A_STAND
to A_LAST
do
233 Models
[i
].anim
[d
, a
].base
:= nil;
234 Models
[i
].anim
[d
, a
].mask
:= nil;
235 if m
.anim
[d
, a
].resource
<> '' then
236 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);
237 if m
.anim
[d
, a
].mask
<> '' then
238 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);
243 Models[i].gibs := nil;
244 if m.GibsCount > 0 then
246 SetLength(Models[i].gibs, m.GibsCount);
253 procedure r_Map_Load
;
255 WeapName
: array [0..WP_LAST
] of AnsiString = ('', 'CSAW', 'HGUN', 'SG', 'SSG', 'MGUN', 'RKT', 'PLZ', 'BFG', 'SPL', 'FLM');
256 WeapPos
: array [0..W_POS_LAST
] of AnsiString = ('', '_UP', '_DN');
257 WeapAct
: array [0..W_ACT_LAST
] of AnsiString = ('', '_FIRE');
259 i
, j
, k
: Integer; d
: TDirection
;
261 procedure LoadItem (i
: Integer; const name
: AnsiString; w
, h
, delay
, count
: Integer; backanim
: Boolean);
264 ASSERT(i
<= ITEM_MAX
);
265 Items
[i
].tex
:= r_Textures_LoadMultiFromFileAndInfo(GameWAD
+ ':TEXTURES/' + name
, w
, h
, count
, backanim
, false);
266 if backanim
then count
:= count
* 2 - 2;
267 Items
[i
].anim
:= TAnimState
.Create(True, delay
, count
);
268 ASSERT(Items
[i
].tex
<> NIL);
271 procedure LoadMonster (m
, a
: Integer; d
: TDirection
);
273 dir
: array [TDirection
] of AnsiString = ('_L', '');
275 w
, h
, count
: Integer;
277 count
:= MONSTER_ANIMTABLE
[m
].AnimCount
[a
];
282 if (m
= MONSTER_SOUL
) and (a
= ANIM_DIE
) then
288 MonTextures
[m
, a
, d
] := r_Textures_LoadMultiFromFileAndInfo(
289 GameWAD
+ ':MTEXTURES/' + MONSTERTABLE
[m
].name
+ '_' + ANIMTABLE
[a
].name
+ dir
[d
],
298 MonTextures
[m
, a
, d
] := nil
302 // --------- items --------- //
303 // i name w h d n backanim
304 LoadItem(ITEM_NONE
, 'NOTEXTURE', 16, 16, 0, 1, False);
305 LoadItem(ITEM_MEDKIT_SMALL
, 'MED1', 16, 16, 0, 1, False);
306 LoadItem(ITEM_MEDKIT_LARGE
, 'MED2', 32, 32, 0, 1, False);
307 LoadItem(ITEM_MEDKIT_BLACK
, 'BMED', 32, 32, 0, 1, False);
308 LoadItem(ITEM_ARMOR_GREEN
, 'ARMORGREEN', 32, 16, 20, 3, True);
309 LoadItem(ITEM_ARMOR_BLUE
, 'ARMORBLUE', 32, 16, 20, 3, True);
310 LoadItem(ITEM_SPHERE_BLUE
, 'SBLUE', 32, 32, 15, 4, True);
311 LoadItem(ITEM_SPHERE_WHITE
, 'SWHITE', 32, 32, 20, 4, True);
312 LoadItem(ITEM_SUIT
, 'SUIT', 32, 64, 0, 1, False);
313 LoadItem(ITEM_OXYGEN
, 'OXYGEN', 16, 32, 0, 1, False);
314 LoadItem(ITEM_INVUL
, 'INVUL', 32, 32, 20, 4, True);
315 LoadItem(ITEM_WEAPON_SAW
, 'SAW', 64, 32, 0, 1, False);
316 LoadItem(ITEM_WEAPON_SHOTGUN1
, 'SHOTGUN1', 64, 16, 0, 1, False);
317 LoadItem(ITEM_WEAPON_SHOTGUN2
, 'SHOTGUN2', 64, 16, 0, 1, False);
318 LoadItem(ITEM_WEAPON_CHAINGUN
, 'MGUN', 64, 16, 0, 1, False);
319 LoadItem(ITEM_WEAPON_ROCKETLAUNCHER
, 'RLAUNCHER', 64, 16, 0, 1, False);
320 LoadItem(ITEM_WEAPON_PLASMA
, 'PGUN', 64, 16, 0, 1, False);
321 LoadItem(ITEM_WEAPON_BFG
, 'BFG', 64, 64, 0, 1, False);
322 LoadItem(ITEM_WEAPON_SUPERPULEMET
, 'SPULEMET', 64, 16, 0, 1, False);
323 LoadItem(ITEM_AMMO_BULLETS
, 'CLIP', 16, 16, 0, 1, False);
324 LoadItem(ITEM_AMMO_BULLETS_BOX
, 'AMMO', 32, 16, 0, 1, False);
325 LoadItem(ITEM_AMMO_SHELLS
, 'SHELL1', 16, 8, 0, 1, False);
326 LoadItem(ITEM_AMMO_SHELLS_BOX
, 'SHELL2', 32, 16, 0, 1, False);
327 LoadItem(ITEM_AMMO_ROCKET
, 'ROCKET', 16, 32, 0, 1, False);
328 LoadItem(ITEM_AMMO_ROCKET_BOX
, 'ROCKETS', 64, 32, 0, 1, False);
329 LoadItem(ITEM_AMMO_CELL
, 'CELL', 16, 16, 0, 1, False);
330 LoadItem(ITEM_AMMO_CELL_BIG
, 'CELL2', 32, 32, 0, 1, False);
331 LoadItem(ITEM_AMMO_BACKPACK
, 'BPACK', 32, 32, 0, 1, False);
332 LoadItem(ITEM_KEY_RED
, 'KEYR', 16, 16, 0, 1, False);
333 LoadItem(ITEM_KEY_GREEN
, 'KEYG', 16, 16, 0, 1, False);
334 LoadItem(ITEM_KEY_BLUE
, 'KEYB', 16, 16, 0, 1, False);
335 LoadItem(ITEM_WEAPON_KASTET
, 'KASTET', 64, 32, 0, 1, False);
336 LoadItem(ITEM_WEAPON_PISTOL
, 'PISTOL', 64, 16, 0, 1, False);
337 LoadItem(ITEM_BOTTLE
, 'BOTTLE', 16, 32, 20, 4, True);
338 LoadItem(ITEM_HELMET
, 'HELMET', 16, 16, 20, 4, True);
339 LoadItem(ITEM_JETPACK
, 'JETPACK', 32, 32, 15, 3, True);
340 LoadItem(ITEM_INVIS
, 'INVIS', 32, 32, 20, 4, True);
341 LoadItem(ITEM_WEAPON_FLAMETHROWER
, 'FLAMETHROWER', 64, 32, 0, 1, False);
342 LoadItem(ITEM_AMMO_FUELCAN
, 'FUELCAN', 16, 32, 0, 1, False);
343 // fill with NOTEXURE forgotten item
344 for i
:= ITEM_AMMO_FUELCAN
+ 1 to ITEM_MAX
do
345 LoadItem(i
,'NOTEXTURE', 16, 16, 0, 1, False);
346 // --------- monsters --------- //
347 for i
:= MONSTER_DEMON
to MONSTER_MAN
do
348 for j
:= 0 to ANIM_LAST
do
349 for d
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
350 LoadMonster(i
, j
, d
);
351 VileFire
:= r_Textures_LoadMultiFromFileAndInfo(GameWAD
+ ':TEXTURES/FIRE', 64, 128, 8, False, False);
352 // --------- player models --------- //
353 if PlayerModelsArray
<> nil then
355 SetLength(Models
, Length(PlayerModelsArray
));
356 for i
:= 0 to High(PlayerModelsArray
) do
359 // --------- player weapons --------- //
360 for i
:= 1 to WP_LAST
do
361 for j
:= 0 to W_POS_LAST
do
362 for k
:= 0 to W_ACT_LAST
do
363 WeapTextures
[i
, j
, k
] := r_Textures_LoadFromFile(GameWAD
+ ':WEAPONS\' + WeapName
[i
] + WeapPos
[j
] + WeapAct
[k
]);
364 // --------- gfx animations --------- //
366 for i
:= 1 to R_GFX_LAST
do
367 if GFXAnim
[i
].count
> 0 then
368 GFXTextures
[i
] := r_Textures_LoadMultiFromFileAndInfo(GameWad
+ ':TEXTURES/' + GFXAnim
[i
].name
, GFXAnim
[i
].w
, GFXAnim
[i
].h
, GFXAnim
[i
].count
, GFXAnim
[i
].back
);
370 // --------- shots --------- //
371 for i
:= 0 to WEAPON_LAST
do
372 if ShotAnim
[i
].count
> 0 then
373 ShotTextures
[i
] := r_Textures_LoadMultiFromFileAndInfo(GameWad
+ ':TEXTURES/' + ShotAnim
[i
].name
, ShotAnim
[i
].w
, ShotAnim
[i
].h
, ShotAnim
[i
].count
, false);
374 // --------- flags --------- //
375 FlagTextures
[FLAG_NONE
] := nil;
376 FlagTextures
[FLAG_RED
] := r_Textures_LoadMultiFromFileAndInfo(GameWad
+ ':TEXTURES/FLAGRED', 64, 64, 5, false);
377 FlagTextures
[FLAG_BLUE
] := r_Textures_LoadMultiFromFileAndInfo(GameWad
+ ':TEXTURES/FLAGBLUE', 64, 64, 5, false);
378 // FlagTextures[FLAG_DOM] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/FLAGDOM', 64, 64, 8, false);
381 procedure r_Map_Free
;
382 var i
, j
, k
, a
: Integer; d
: TDirection
;
384 for i
:= 0 to FLAG_LAST
do
386 if FlagTextures
[i
] <> nil then
387 FlagTextures
[i
].Free
;
388 FlagTextures
[i
] := nil;
390 for i
:= 0 to WEAPON_LAST
do
392 if ShotTextures
[i
] <> nil then
393 ShotTextures
[i
].Free
;
394 ShotTextures
[i
] := nil;
398 for i
:= 0 to R_GFX_LAST
do
400 if GFXTextures
[i
] <> nil then
402 GFXTextures
[i
] := nil;
405 for i
:= 1 to WP_LAST
do
407 for j
:= 0 to W_POS_LAST
do
409 for k
:= 0 to W_ACT_LAST
do
411 if WeapTextures
[i
, j
, k
] <> nil then
412 WeapTextures
[i
, j
, k
].Free
;
413 WeapTextures
[i
, j
, k
] := nil;
417 for d
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
419 for a
:= A_STAND
to A_LAST
do
421 if Models
[i
].anim
[d
, a
].base
<> nil then
422 Models
[i
].anim
[d
, a
].base
.Free
;
423 if Models
[i
].anim
[d
, a
].mask
<> nil then
424 Models
[i
].anim
[d
, a
].mask
.Free
;
425 Models
[i
].anim
[d
, a
].base
:= nil;
426 Models
[i
].anim
[d
, a
].mask
:= nil;
429 for i
:= MONSTER_DEMON
to MONSTER_MAN
do
431 for j
:= 0 to ANIM_LAST
do
433 for d
:= TDirection
.D_LEFT
to TDirection
.D_RIGHT
do
435 if MonTextures
[i
, j
, d
] <> nil then
436 MonTextures
[i
, j
, d
].Free
;
437 MonTextures
[i
, j
, d
] := nil;
441 for i
:= 0 to ITEM_MAX
do
443 if Items
[i
].tex
<> nil then
448 Items
[i
].anim
.Invalidate
;
452 procedure r_Map_LoadTextures
;
455 if Textures
<> nil then
457 n
:= Length(Textures
);
458 SetLength(RenTextures
, n
);
459 for i
:= 0 to n
- 1 do
461 RenTextures
[i
].tex
:= nil;
462 case Textures
[i
].TextureName
of
463 TEXTURE_NAME_WATER
: RenTextures
[i
].spec
:= TEXTURE_SPECIAL_WATER
;
464 TEXTURE_NAME_ACID1
: RenTextures
[i
].spec
:= TEXTURE_SPECIAL_ACID1
;
465 TEXTURE_NAME_ACID2
: RenTextures
[i
].spec
:= TEXTURE_SPECIAL_ACID2
;
467 RenTextures
[i
].spec
:= 0;
468 RenTextures
[i
].tex
:= r_Textures_LoadMultiFromFile(Textures
[i
].FullName
);
469 if RenTextures
[i
].tex
= nil then
470 e_LogWritefln('r_Map_LoadTextures: failed to load texture: %s', [Textures
[i
].FullName
]);
474 if gMapInfo
.SkyFullName
<> '' then
475 SkyTexture
:= r_Textures_LoadFromFile(gMapInfo
.SkyFullName
);
479 procedure r_Map_FreeTextures
;
483 if SkyTexture
<> nil then
486 if RenTextures
<> nil then
487 for i
:= 0 to High(RenTextures
) do
488 if RenTextures
[i
].tex
<> nil then
489 RenTextures
[i
].tex
.Free
;
493 procedure r_Map_DrawPanel (p
: TPanel
);
494 var Texture
: Integer; t
: TGLMultiTexture
;
497 if p
.FCurTexture
>= 0 then
499 Texture
:= p
.TextureIDs
[p
.FCurTexture
].Texture
;
500 t
:= RenTextures
[Texture
].tex
;
502 if (RenTextures
[Texture
].spec
= 0) or (t
<> nil) then
505 r_Draw_TextureRepeat(nil, p
.x
, p
.y
, p
.width
, p
.height
, false, 255, 255, 255, 255 - p
.alpha
, p
.blending
)
506 else if p
.TextureIDs
[p
.FCurTexture
].AnTex
.IsValid() then
507 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
)
509 r_Draw_TextureRepeat(t
.GetTexture(0), p
.x
, p
.y
, p
.width
, p
.height
, false, 255, 255, 255, 255 - p
.alpha
, p
.blending
)
514 case RenTextures
[Texture
].spec
of
515 TEXTURE_SPECIAL_WATER
: r_Draw_Filter(p
.x
, p
.y
, p
.x
+ p
.width
, p
.y
+ p
.height
, 0, 0, 255, 255);
516 TEXTURE_SPECIAL_ACID1
: r_Draw_Filter(p
.x
, p
.y
, p
.x
+ p
.width
, p
.y
+ p
.height
, 0, 230, 0, 255);
517 TEXTURE_SPECIAL_ACID2
: r_Draw_Filter(p
.x
, p
.y
, p
.x
+ p
.width
, p
.y
+ p
.height
, 230, 0, 0, 255);
523 procedure r_Map_DrawPanelType (panelTyp
: DWORD
);
524 var tagMask
, i
: Integer; p
: TPanel
;
527 tagMask
:= PanelTypeToTag(panelTyp
);
528 while plist
.count
> 0 do
530 p
:= TPanel(plist
.Front());
531 if (p
.tag
and tagMask
) = 0 then
539 procedure r_Map_DrawItems (x
, y
, w
, h
: Integer; drop
: Boolean);
540 var i
, fX
, fY
: Integer; it
: PItem
; t
: TGLMultiTexture
;
542 if ggItems
<> nil then
544 for i
:= 0 to High(ggItems
) do
547 if it
.used
and it
.alive
and (it
.dropped
= drop
) and (it
.ItemType
<> ITEM_NONE
) then
549 t
:= Items
[it
.ItemType
].tex
;
550 if g_Collide(it
.obj
.x
, it
.obj
.y
, t
.width
, t
.height
, x
, y
, w
, h
) then
552 it
.obj
.Lerp(gLerpFactor
, fX
, fY
);
553 r_Draw_MultiTextureRepeat(t
, Items
[it
.ItemType
].anim
, fX
, fY
, t
.width
, t
.height
, false, 255, 255, 255, 255, false);
554 // if g_debug_frames then // TODO draw collision frame
561 function r_Map_GetMonsterTexture (m
, a
: Integer; d
: TDirection
; out t
: TGLMultiTexture
; out dx
, dy
: Integer; out flip
: Boolean): Boolean;
564 t
:= nil; dx
:= 0; dy
:= 0; flip
:= false;
565 result
:= MonTextures
[m
, a
, d
] <> nil;
566 if result
= false then
569 if d
= TDirection
.D_RIGHT
then d
:= TDirection
.D_LEFT
else d
:= TDirection
.D_RIGHT
;
570 result
:= MonTextures
[m
, a
, d
] <> nil;
572 if result
= true then
574 t
:= MonTextures
[m
, a
, d
];
575 if d
= TDirection
.D_LEFT
then
577 dx
:= MONSTER_ANIMTABLE
[m
].AnimDeltaLeft
[a
].X
;
578 dy
:= MONSTER_ANIMTABLE
[m
].AnimDeltaLeft
[a
].Y
;
582 dx
:= MONSTER_ANIMTABLE
[m
].AnimDeltaRight
[a
].X
;
583 dy
:= MONSTER_ANIMTABLE
[m
].AnimDeltaRight
[a
].Y
;
587 // c := (MONSTERTABLE[MonsterType].Rect.X - dx) + MONSTERTABLE[MonsterType].Rect.Width;
588 // dx := MTABLE[m].width - c - MONSTERTABLE[MonsterType].Rect.X;
594 procedure r_Map_DrawMonsterAttack (constref mon
: TMonster
);
597 if VileFire
<> nil then
598 if (mon
.MonsterType
= MONSTER_VILE
) and (mon
.MonsterState
= MONSTATE_SHOOT
) then
599 if mon
.VileFireAnim
.IsValid() and GetPos(mon
.MonsterTargetUID
, @o
) then
600 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);
603 procedure r_Map_DrawMonster (constref mon
: TMonster
);
604 var m
, a
, fX
, fY
, dx
, dy
: Integer; d
: TDirection
; flip
: Boolean; t
: TGLMultiTexture
;
606 m
:= mon
.MonsterType
;
607 a
:= mon
.MonsterAnim
;
608 d
:= mon
.GameDirection
;
610 mon
.obj
.Lerp(gLerpFactor
, fX
, fY
);
612 if r_Map_GetMonsterTexture(m
, a
, d
, t
, dx
, dy
, flip
) then
613 r_Draw_MultiTextureRepeat(t
, mon
.DirAnim
[a
, d
], fX
+ dx
, fY
+ dy
, t
.width
, t
.height
, flip
, 255, 255, 255, 255, false);
621 procedure r_Map_DrawMonsters (x
, y
, w
, h
: Integer);
622 var i
: Integer; m
: TMonster
;
624 if gMonsters
<> nil then
626 for i
:= 0 to High(gMonsters
) do
631 r_Map_DrawMonsterAttack(m
);
632 // TODO select from grid
633 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
634 r_Map_DrawMonster(m
);
640 function r_Map_GetPlayerModelTex (i
: Integer; var a
: Integer; var d
: TDirection
; out flip
: Boolean): Boolean;
643 result
:= Models
[i
].anim
[d
, a
].base
<> nil;
644 if result
= false then
647 if d
= TDirection
.D_LEFT
then d
:= TDirection
.D_RIGHT
else d
:= TDirection
.D_LEFT
;
648 result
:= Models
[i
].anim
[d
, a
].base
<> nil;
652 procedure r_Map_DrawPlayerModel (pm
: TPlayerModel
; x
, y
: Integer);
653 var a
, pos
, act
, xx
, yy
, angle
: Integer; d
: TDirection
; flip
: Boolean; t
: TGLMultiTexture
; tex
: TGLTexture
; c
: TRGB
;
655 a
:= pm
.CurrentAnimation
;
659 t
:= FlagTextures
[pm
.Flag
];
660 if (t
<> nil) and not (a
in [A_DIE1
, A_DIE2
]) then
662 flip
:= d
= TDirection
.D_RIGHT
;
663 angle
:= PlayerModelsArray
[pm
.id
].FlagAngle
;
664 xx
:= PlayerModelsArray
[pm
.id
].FlagPoint
.X
;
665 yy
:= PlayerModelsArray
[pm
.id
].FlagPoint
.Y
;
666 r_Draw_MultiTextureRepeatRotate(
669 x
+ IfThen(flip
, 2 * FLAG_BASEPOINT
.X
- xx
+ 1, xx
- 1) - FLAG_BASEPOINT
.X
,
670 y
+ yy
- FLAG_BASEPOINT
.Y
+ 1,
674 255, 255, 255, 255, false,
675 IfThen(flip
, 64 - FLAG_BASEPOINT
.X
, FLAG_BASEPOINT
.X
),
677 IfThen(flip
, angle
, -angle
)
682 if PlayerModelsArray
[pm
.id
].HaveWeapon
and not (a
in [A_DIE1
, A_DIE2
, A_PAIN
]) then
685 A_SEEUP
, A_ATTACKUP
: pos
:= W_POS_UP
;
686 A_SEEDOWN
, A_ATTACKDOWN
: pos
:= W_POS_DOWN
;
687 else pos
:= W_POS_NORMAL
;
689 if (a
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
]) or pm
.GetFire() then
693 tex
:= WeapTextures
[pm
.CurrentWeapon
, pos
, act
];
696 xx
:= PlayerModelsArray
[pm
.id
].WeaponPoints
[pm
.CurrentWeapon
, a
, d
, pm
.AnimState
.CurrentFrame
].X
;
697 yy
:= PlayerModelsArray
[pm
.id
].WeaponPoints
[pm
.CurrentWeapon
, a
, d
, pm
.AnimState
.CurrentFrame
].Y
;
704 d
= TDirection
.D_LEFT
,
705 255, 255, 255, 255, false
711 if r_Map_GetPlayerModelTex(pm
.id
, a
, d
, flip
) then
713 t
:= Models
[pm
.id
].anim
[d
, a
].base
;
714 r_Draw_MultiTextureRepeat(t
, pm
.AnimState
, x
, y
, t
.width
, t
.height
, flip
, 255, 255, 255, 255, false);
715 t
:= Models
[pm
.id
].anim
[d
, a
].mask
;
719 r_Draw_MultiTextureRepeat(t
, pm
.AnimState
, x
, y
, t
.width
, t
.height
, flip
, c
.r
, c
.g
, c
.b
, 255, false);
724 procedure r_Map_DrawPlayer (p
: TPlayer
);
725 var fX
, fY
, fSlope
: Integer;
729 fX
:= p
.obj
.x
; fY
:= p
.obj
.y
;
731 //p.obj.Lerp(gLerpFactor, fX, fY);
732 fSlope
:= nlerp(p
.SlopeOld
, p
.obj
.slopeUpLeft
, gLerpFactor
);
734 // TODO invul pentagram
735 // TODO draw it with transparency
736 r_Map_DrawPlayerModel(p
.Model
, fX
, fY
+ fSlope
);
738 // TODO draw g_debug_frames
739 // TODO draw chat bubble
743 procedure r_Map_DrawPlayers (x
, y
, w
, h
: Integer);
746 // TODO draw only visible
747 if gPlayers
<> nil then
748 for i
:= 0 to High(gPlayers
) do
749 if gPlayers
[i
] <> nil then
750 r_Map_DrawPlayer(gPlayers
[i
]);
753 {$IFDEF ENABLE_CORPSES}
754 procedure r_Map_DrawCorpses (x
, y
, w
, h
: Integer);
755 var i
, fX
, fY
: Integer; p
: TCorpse
;
757 if gCorpses
<> nil then
759 for i
:= 0 to High(gCorpses
) do
762 if (p
<> nil) and (p
.state
<> CORPSE_STATE_REMOVEME
) and (p
.model
<> nil) then
764 p
.obj
.Lerp(gLerpFactor
, fX
, fY
);
765 r_Map_DrawPlayerModel(p
.model
, fX
, fY
);
773 function r_Map_GetGFXID (): Integer;
777 if gfxlist
<> nil then
779 while (i
< Length(gfxlist
)) and gfxlist
[i
].anim
.IsValid() do
781 if i
>= Length(gfxlist
) then
782 SetLength(gfxlist
, Length(gfxlist
) + 1)
785 SetLength(gfxlist
, 1);
786 gfxlist
[i
].typ
:= R_GFX_NONE
;
787 gfxlist
[i
].anim
.Invalidate
;
791 procedure r_Map_NewGFX (typ
, x
, y
: Integer);
794 if gpart_dbg_enabled
and (typ
> 0) and (typ
<= R_GFX_LAST
) then
796 i
:= r_Map_GetGFXID();
799 gfxlist
[i
].typ
:= typ
;
802 gfxlist
[i
].oldX
:= x
;
803 gfxlist
[i
].oldY
:= y
;
804 gfxlist
[i
].anim
:= TAnimState
.Create(false, GFXAnim
[typ
].speed
+ Random(GFXAnim
[typ
].rspeed
), GFXAnim
[typ
].count
);
805 gfxlist
[i
].anim
.Reset();
806 gfxlist
[i
].anim
.Enable();
811 procedure r_Map_UpdateGFX
;
814 if gfxlist
<> nil then
816 for i
:= 0 to High(gfxlist
) do
818 if gfxlist
[i
].anim
.IsValid() then
820 gfxlist
[i
].oldX
:= gfxlist
[i
].x
;
821 gfxlist
[i
].oldY
:= gfxlist
[i
].y
;
822 case gfxlist
[i
].typ
of
823 R_GFX_FLAME
, R_GFX_SMOKE
:
825 if Random(3) = 0 then
826 gfxlist
[i
].x
:= gfxlist
[i
].x
- 1 + Random(3);
827 if Random(2) = 0 then
828 gfxlist
[i
].y
:= gfxlist
[i
].y
- Random(2);
831 if gfxlist
[i
].anim
.played
then
832 gfxlist
[i
].anim
.Invalidate
834 gfxlist
[i
].anim
.Update
840 procedure r_Map_DrawParticles (x
, y
, w
, h
: Integer);
841 var i
, fx
, fy
: Integer;
843 if gpart_dbg_enabled
and (Particles
<> nil) then
845 glDisable(GL_TEXTURE_2D
);
846 if (g_dbg_scale
< 0.6) then
848 else if (g_dbg_scale
> 1.3) then
849 glPointSize(g_dbg_scale
+ 1)
852 glDisable(GL_POINT_SMOOTH
);
854 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
857 for i
:= 0 to High(Particles
) do
859 if Particles
[i
].alive
then
861 fx
:= nlerp(Particles
[i
].oldX
, Particles
[i
].x
, gLerpFactor
);
862 fy
:= nlerp(Particles
[i
].oldY
, Particles
[i
].y
, gLerpFactor
);
863 glColor4ub(Particles
[i
].red
, Particles
[i
].green
, Particles
[i
].blue
, Particles
[i
].alpha
);
873 procedure r_Map_DrawGFX (x
, y
, w
, h
: Integer);
874 var i
, fx
, fy
, typ
: Integer; tex
: TGLMultiTexture
;
876 if gfxlist
<> nil then
878 for i
:= 0 to High(gfxlist
) do
880 if gfxlist
[i
].anim
.IsValid() then
882 typ
:= gfxlist
[i
].typ
;
883 tex
:= GFXTextures
[typ
];
886 fx
:= nlerp(gfxlist
[i
].oldX
, gfxlist
[i
].x
, gLerpFactor
);
887 fy
:= nlerp(gfxlist
[i
].oldY
, gfxlist
[i
].y
, gLerpFactor
);
888 r_Draw_MultiTextureRepeat(tex
, gfxlist
[i
].anim
, fx
, fy
, tex
.width
, tex
.height
, false, 255, 255, 255, 255 - GFXAnim
[typ
].alpha
, false);
896 procedure r_Map_DrawShots (x
, y
, w
, h
: Integer);
897 var i
, a
, fX
, fY
, pX
, pY
, typ
: Integer; tex
: TGLMultiTexture
; anim
: ^TAnimState
;
901 for i
:= 0 to High(Shots
) do
903 typ
:= Shots
[i
].ShotType
;
906 tex
:= ShotTextures
[typ
];
911 WEAPON_ROCKETLAUNCHER
, WEAPON_BARON_FIRE
, WEAPON_MANCUB_FIRE
, WEAPON_SKEL_FIRE
:
912 a
:= -GetAngle2(Shots
[i
].Obj
.Vel
.X
, Shots
[i
].Obj
.Vel
.Y
)
914 Shots
[i
].Obj
.Lerp(gLerpFactor
, fX
, fY
);
915 pX
:= Shots
[i
].Obj
.Rect
.Width
div 2;
916 pY
:= Shots
[i
].Obj
.Rect
.Height
div 2;
917 // TODO fix this hack
918 if Shots
[i
].Animation
.IsValid() then anim
:= @Shots
[i
].Animation
else anim
:= @StubShotAnim
;
919 r_Draw_MultiTextureRepeatRotate(tex
, anim
^, fX
, fY
, tex
.width
, tex
.height
, false, 255, 255, 255, 255, false, pX
, pY
, a
);
926 procedure r_Map_DrawFlags (x
, y
, w
, h
: Integer);
927 var i
, dx
, fx
, fy
: Integer; flip
: Boolean; tex
: TGLMultiTexture
;
929 if gGameSettings
.GameMode
= GM_CTF
then
931 for i
:= FLAG_RED
to FLAG_BLUE
do
933 if not (gFlags
[i
].state
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then
935 gFlags
[i
].Obj
.Lerp(gLerpFactor
, fx
, fy
);
936 flip
:= gFlags
[i
].Direction
= TDirection
.D_LEFT
;
937 if flip
then dx
:= -1 else dx
:= +1;
938 tex
:= FlagTextures
[i
];
939 r_Draw_MultiTextureRepeat(tex
, FlagAnim
, fx
+ dx
, fy
+ 1, tex
.width
, tex
.height
, flip
, 255, 255, 255, 255, false)
940 // TODO g_debug_frames
946 procedure r_Map_Draw (x
, y
, w
, h
, camx
, camy
: Integer);
947 var iter
: TPanelGrid
.Iter
; p
: PPanel
; cx
, cy
, xx
, yy
, ww
, hh
: Integer;
949 cx
:= camx
- w
div 2;
950 cy
:= camy
- h
div 2;
956 if SkyTexture
<> nil then
957 r_Draw_Texture(SkyTexture
, x
, y
, w
, h
, false, 255, 255, 255, 255, false);
960 iter
:= mapGrid
.ForEachInAABB(xx
, yy
, ww
, hh
, GridDrawableMask
);
962 if ((p
^.tag
and GridTagDoor
) <> 0) = p
^.door
then
967 glTranslatef(-cx
, -cy
, 0);
968 r_Map_DrawPanelType(PANEL_BACK
);
969 r_Map_DrawPanelType(PANEL_STEP
);
970 r_Map_DrawItems(xx
, yy
, ww
, hh
, false);
971 r_Map_DrawShots(xx
, yy
, ww
, hh
);
973 r_Map_DrawPlayers(xx
, yy
, ww
, hh
);
975 {$IFDEF ENABLE_CORPSES}
976 r_Map_DrawCorpses(xx
, yy
, ww
, hh
);
978 r_Map_DrawPanelType(PANEL_WALL
);
979 r_Map_DrawMonsters(xx
, yy
, ww
, hh
);
980 r_Map_DrawItems(xx
, yy
, ww
, hh
, true);
981 r_Map_DrawPanelType(PANEL_CLOSEDOOR
);
983 r_Map_DrawParticles(xx
, yy
, ww
, hh
);
984 r_Map_DrawGFX(xx
, yy
, ww
, hh
);
986 r_Map_DrawFlags(xx
, yy
, ww
, hh
);
987 r_Map_DrawPanelType(PANEL_ACID1
);
988 r_Map_DrawPanelType(PANEL_ACID2
);
989 r_Map_DrawPanelType(PANEL_WATER
);
990 r_Map_DrawPanelType(PANEL_FORE
);
994 procedure r_Map_Update
;
997 for i
:= 0 to ITEM_MAX
do
998 Items
[i
].anim
.Update
;