DEADSOFTWARE

gl: fix bfg ball offset
[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 uses g_base, g_player, g_playermodel; // TRectWH, TPlayer, TPlayerModel
22 procedure r_Map_Initialize;
23 procedure r_Map_Finalize;
25 procedure r_Map_Load;
26 procedure r_Map_Free;
28 procedure r_Map_LoadTextures;
29 procedure r_Map_FreeTextures;
31 {$IFDEF ENABLE_GFX}
32 procedure r_Map_NewGFX (typ, x, y: Integer);
33 {$ENDIF}
34 {$IFDEF ENABLE_GIBS}
35 function r_Map_GetGibSize (m, i: Integer): TRectWH;
36 {$ENDIF}
37 {$IFDEF ENABLE_MENU}
38 procedure r_Map_DrawPlayerModel (pm: TPlayerModel; x, y: Integer; alpha: Byte);
39 {$ENDIF}
41 procedure r_Map_Reset;
42 procedure r_Map_Update;
44 procedure r_Map_Draw (x, y, w, h, camx, camy: Integer; player: TPlayer; out acx, acy: Integer);
45 procedure r_Map_GetSpectatorLimits (out x0, y0, x1, y1: Integer);
47 implementation
49 uses
50 {$I ../../../nogl/noGLuses.inc}
51 Math, SysUtils,
52 e_log,
53 binheap, MAPDEF, utils,
54 g_options, g_animations, g_basic, g_phys,
55 g_game, g_map, g_panel, g_items, g_monsters, g_weapons,
56 g_console, g_language,
57 {$IFDEF ENABLE_CORPSES}
58 g_corpses,
59 {$ENDIF}
60 {$IFDEF ENABLE_SHELLS}
61 g_shells,
62 {$ENDIF}
63 {$IFDEF ENABLE_GIBS}
64 g_gibs,
65 {$ENDIF}
66 {$IFDEF ENABLE_GFX}
67 g_gfx,
68 {$ENDIF}
69 r_textures, r_draw, r_common
70 ;
72 const
73 MAXGIBW = 32;
74 MAXGIBH = 32;
76 MAXMONW = 256;
77 MAXMONH = 128;
78 MTABLE: array [0..MONSTER_MAN] of record
79 w, h: Integer;
80 end = (
81 (w: 64; h: 64), // NONE
82 (w: 64; h: 64), // DEMON
83 (w: 64; h: 64), // IMP
84 (w: 64; h: 64), // ZOMBY
85 (w: 64; h: 64), // SERG
86 (w: 128; h: 128), // CYBER
87 (w: 64; h: 64), // CGUN
88 (w: 128; h: 128), // BARON
89 (w: 128; h: 128), // KNIGHT
90 (w: 128; h: 128), // CACO
91 (w: 64; h: 64), // SOUL (DIE is 128x128, see load code)
92 (w: 128; h: 128), // PAIN
93 (w: 256; h: 128), // SPIDER
94 (w: 128; h: 64), // BSP
95 (w: 128; h: 128), // MANCUB
96 (w: 128; h: 128), // SKEL
97 (w: 128; h: 128), // VILE
98 (w: 32; h: 32), // FISH
99 (w: 64; h: 64), // BARREL
100 (w: 128; h: 128), // ROBO
101 (w: 64; h: 64) // MAN
102 );
103 VILEFIRE_DX = 32;
104 VILEFIRE_DY = 128;
106 MAXITEMW = 64;
107 MAXITEMH = 64;
108 ItemAnim: array [0..ITEM_LAST] of record
109 name: AnsiString;
110 w, h: Integer;
111 anim: TAnimInfo;
112 end = (
113 (name: 'NOTEXTURE'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
114 (name: 'MED1'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
115 (name: 'MED2'; w: 32; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
116 (name: 'BMED'; w: 32; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
117 (name: 'ARMORGREEN'; w: 32; h: 16; anim: (loop: true; delay: 20; frames: 3; back: true)),
118 (name: 'ARMORBLUE'; w: 32; h: 16; anim: (loop: true; delay: 20; frames: 3; back: true)),
119 (name: 'SBLUE'; w: 32; h: 32; anim: (loop: true; delay: 15; frames: 4; back: true)),
120 (name: 'SWHITE'; w: 32; h: 32; anim: (loop: true; delay: 20; frames: 4; back: true)),
121 (name: 'SUIT'; w: 32; h: 64; anim: (loop: true; delay: 1; frames: 1; back: false)),
122 (name: 'OXYGEN'; w: 16; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
123 (name: 'INVUL'; w: 32; h: 32; anim: (loop: true; delay: 20; frames: 4; back: true)),
124 (name: 'SAW'; w: 64; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
125 (name: 'SHOTGUN1'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
126 (name: 'SHOTGUN2'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
127 (name: 'MGUN'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
128 (name: 'RLAUNCHER'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
129 (name: 'PGUN'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
130 (name: 'BFG'; w: 64; h: 64; anim: (loop: true; delay: 1; frames: 1; back: false)),
131 (name: 'SPULEMET'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
132 (name: 'CLIP'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
133 (name: 'AMMO'; w: 32; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
134 (name: 'SHELL1'; w: 16; h: 8; anim: (loop: true; delay: 1; frames: 1; back: false)),
135 (name: 'SHELL2'; w: 32; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
136 (name: 'ROCKET'; w: 16; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
137 (name: 'ROCKETS'; w: 64; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
138 (name: 'CELL'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
139 (name: 'CELL2'; w: 32; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
140 (name: 'BPACK'; w: 32; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
141 (name: 'KEYR'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
142 (name: 'KEYG'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
143 (name: 'KEYB'; w: 16; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
144 (name: 'KASTET'; w: 64; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
145 (name: 'PISTOL'; w: 64; h: 16; anim: (loop: true; delay: 1; frames: 1; back: false)),
146 (name: 'BOTTLE'; w: 16; h: 32; anim: (loop: true; delay: 20; frames: 4; back: true)),
147 (name: 'HELMET'; w: 16; h: 16; anim: (loop: true; delay: 20; frames: 4; back: true)),
148 (name: 'JETPACK'; w: 32; h: 32; anim: (loop: true; delay: 15; frames: 3; back: true)),
149 (name: 'INVIS'; w: 32; h: 32; anim: (loop: true; delay: 20; frames: 4; back: true)),
150 (name: 'FLAMETHROWER'; w: 64; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)),
151 (name: 'FUELCAN'; w: 16; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false))
152 );
154 {$IFDEF ENABLE_GFX}
155 GFXAnim: array [0..R_GFX_LAST] of record
156 name: AnsiString;
157 w, h: Integer;
158 anim: TAnimInfo;
159 rdelay: Integer;
160 alpha: Integer;
161 end = (
162 (name: ''; w: 0; h: 0; anim: (loop: false; delay: 0; frames: 0; back: false); rdelay: 0; alpha: 0),
163 (name: 'TELEPORT'; w: 64; h: 64; anim: (loop: false; delay: 6; frames: 10; back: false); rdelay: 0; alpha: 0),
164 (name: 'FLAME'; w: 32; h: 32; anim: (loop: false; delay: 3; frames: 11; back: false); rdelay: 0; alpha: 0),
165 (name: 'EROCKET'; w: 128; h: 128; anim: (loop: false; delay: 6; frames: 6; back: false); rdelay: 0; alpha: 0),
166 (name: 'EBFG'; w: 128; h: 128; anim: (loop: false; delay: 6; frames: 6; back: false); rdelay: 0; alpha: 0),
167 (name: 'BFGHIT'; w: 64; h: 64; anim: (loop: false; delay: 4; frames: 4; back: false); rdelay: 0; alpha: 0),
168 (name: 'FIRE'; w: 64; h: 128; anim: (loop: false; delay: 4; frames: 8; back: false); rdelay: 2; alpha: 0),
169 (name: 'ITEMRESPAWN'; w: 32; h: 32; anim: (loop: false; delay: 4; frames: 5; back: true); rdelay: 0; alpha: 0),
170 (name: 'SMOKE'; w: 32; h: 32; anim: (loop: false; delay: 3; frames: 10; back: false); rdelay: 0; alpha: 0),
171 (name: 'ESKELFIRE'; w: 64; h: 64; anim: (loop: false; delay: 8; frames: 3; back: false); rdelay: 0; alpha: 0),
172 (name: 'EPLASMA'; w: 32; h: 32; anim: (loop: false; delay: 3; frames: 4; back: true); rdelay: 0; alpha: 0),
173 (name: 'EBSPFIRE'; w: 32; h: 32; anim: (loop: false; delay: 3; frames: 5; back: false); rdelay: 0; alpha: 0),
174 (name: 'EIMPFIRE'; w: 64; h: 64; anim: (loop: false; delay: 6; frames: 3; back: false); rdelay: 0; alpha: 0),
175 (name: 'ECACOFIRE'; w: 64; h: 64; anim: (loop: false; delay: 6; frames: 3; back: false); rdelay: 0; alpha: 0),
176 (name: 'EBARONFIRE'; w: 64; h: 64; anim: (loop: false; delay: 6; frames: 3; back: false); rdelay: 0; alpha: 0),
177 (name: 'TELEPORT'; w: 64; h: 64; anim: (loop: false; delay: 3; frames: 10; back: false); rdelay: 0; alpha: 0), // fast
178 (name: 'SMOKE'; w: 32; h: 32; anim: (loop: false; delay: 3; frames: 10; back: false); rdelay: 0; alpha: 150), // transparent
179 (name: 'FLAME'; w: 32; h: 32; anim: (loop: false; delay: 3; frames: 11; back: false); rdelay: 2; alpha: 0) // random
180 );
181 {$ENDIF}
183 ShotAnim: array [0..WEAPON_LAST] of record
184 name: AnsiString;
185 x, y: Integer;
186 w, h: Integer;
187 anim: TAnimInfo;
188 end = (
189 (name: ''; x: 0; y: 0; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 0 KASTET
190 (name: ''; x: 0; y: 0; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 1 SAW
191 (name: ''; x: 0; y: 0; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 2 PISTOL
192 (name: ''; x: 0; y: 0; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 3 SHOTGUN1
193 (name: ''; x: 0; y: 0; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 4 SHOTGUN2
194 (name: ''; x: 0; y: 0; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 5 CHAINGUN
195 (name: 'BROCKET'; x: 0; y: 0; w: 64; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)), // 6 ROCKETLAUNCHER
196 (name: 'BPLASMA'; x: 0; y: 0; w: 16; h: 16; anim: (loop: true; delay: 5; frames: 2; back: false)), // 7 PLASMA
197 (name: 'BBFG'; x: 8; y: 8; w: 64; h: 64; anim: (loop: true; delay: 6; frames: 2; back: false)), // 8 BFG
198 (name: ''; x: 0; y: 0; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 9 SUPERPULEMET
199 (name: 'FLAME'; x: 0; y: 0; w: 32; h: 32; anim: (loop: true; delay: 6; frames: 0{11}; back: false)), // 10 FLAMETHROWER
200 (name: ''; x: 0; y: 0; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 11
201 (name: ''; x: 0; y: 0; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 12
202 (name: ''; x: 0; y: 0; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 13
203 (name: ''; x: 0; y: 0; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 14
204 (name: ''; x: 0; y: 0; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 15
205 (name: ''; x: 0; y: 0; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 16
206 (name: ''; x: 0; y: 0; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 17
207 (name: ''; x: 0; y: 0; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 18
208 (name: ''; x: 0; y: 0; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 19
209 (name: ''; x: 0; y: 0; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 20 ZOMPY_PISTOL
210 (name: 'BIMPFIRE'; x: 0; y: 0; w: 16; h: 16; anim: (loop: true; delay: 4; frames: 2; back: false)), // 21 IMP_FIRE
211 (name: 'BBSPFIRE'; x: 0; y: 0; w: 16; h: 16; anim: (loop: true; delay: 4; frames: 2; back: false)), // 22 BSP_FIRE
212 (name: 'BCACOFIRE'; x: 0; y: 0; w: 16; h: 16; anim: (loop: true; delay: 4; frames: 2; back: false)), // 23 CACO_FIRE
213 (name: 'BBARONFIRE'; x: 0; y: 0; w: 64; h: 16; anim: (loop: true; delay: 4; frames: 2; back: false)), // 24 BARON_FIRE
214 (name: 'BMANCUBFIRE'; x: 0; y: 0; w: 64; h: 32; anim: (loop: true; delay: 4; frames: 2; back: false)), // 25 MANCUB_FIRE
215 (name: 'BSKELFIRE'; x: 0; y: 0; w: 64; h: 64; anim: (loop: true; delay: 5; frames: 2; back: false)) // 26 SKEL_FIRE
216 );
218 {$IFDEF ENABLE_SHELLS}
219 ShellAnim: array [0..SHELL_LAST] of record
220 name: AnsiString;
221 dx, dy: Integer;
222 end = (
223 (name: 'EBULLET'; dx: 2; dy: 1), // 0 SHELL_BULLET
224 (name: 'ESHELL'; dx: 4; dy: 2), // 1 SHELL_SHELL
225 (name: 'ESHELL'; dx: 4; dy: 2) // 2 SHELL_DBLSHELL
226 );
227 {$ENDIF}
229 PunchAnim: TAnimInfo = (loop: false; delay: 1; frames: 4; back: false);
230 FlagAnim: TAnimInfo = (loop: true; delay: 8; frames: 5; back: false);
231 VileFireAnim: TAnimInfo = (loop: true; delay: 2; frames: 8; back: false);
233 type
234 TBinHeapPanelDrawCmp = class
235 public
236 class function less (const a, b: TPanel): Boolean; inline;
237 end;
239 TBinHeapPanelDraw = specialize TBinaryHeapBase<TPanel, TBinHeapPanelDrawCmp>;
241 TMonsterAnims = array [0..ANIM_LAST, TDirection] of TGLMultiTexture;
243 var
244 UseAccel: Boolean;
245 DebugFrames: Boolean;
246 DebugHealth: Boolean;
247 DebugCameraScale: Single;
248 FillOutsizeArea: Boolean;
249 SkyTexture: TGLTexture;
250 RenTextures: array of record
251 spec: LongInt;
252 tex: TGLMultiTexture;
253 anim: TAnimInfo;
254 end;
255 Items: array [0..ITEM_LAST] of record
256 tex: TGLMultiTexture;
257 frame: Integer;
258 end;
259 MonTextures: array [0..MONSTER_MAN] of TMonsterAnims;
260 WeapTextures: array [0..WP_LAST, 0..W_POS_LAST, 0..W_ACT_LAST] of TGLTexture;
261 ShotTextures: array [0..WEAPON_LAST] of TGLMultiTexture;
262 FlagTextures: array [0..FLAG_LAST] of TGLMultiTexture;
263 PunchTextures: array [Boolean, 0..2] of TGLMultiTexture; // [berserk, center/up/down]
264 VileFire: TGLMultiTexture;
265 InvulPenta: TGLTexture;
266 IndicatorTexture: TGLTexture;
267 TalkTexture: TGLTexture;
268 Models: array of record
269 anim: array [TDirection, 0..A_LAST] of record
270 base, mask: TGLMultiTexture;
271 end;
272 {$IFDEF ENABLE_GIBS}
273 gibs: record
274 base, mask: TGLTextureArray;
275 rect: TRectArray;
276 end;
277 {$ENDIF}
278 end;
280 {$IFDEF ENABLE_SHELLS}
281 ShellTextures: array [0..SHELL_LAST] of TGLTexture;
282 {$ENDIF}
283 {$IFDEF ENABLE_GFX}
284 GFXTextures: array [0..R_GFX_LAST] of TGLMultiTexture;
285 gfxlist: array of record
286 typ: Byte;
287 x, y: Integer;
288 oldX, oldY: Integer;
289 anim: TAnimInfo;
290 time: LongWord;
291 frame: LongInt;
292 end = nil;
293 {$ENDIF}
295 FlagFrame: LongInt;
296 plist: TBinHeapPanelDraw = nil;
298 class function TBinHeapPanelDrawCmp.less (const a, b: TPanel): Boolean; inline;
299 begin
300 if a.tag < b.tag then result := true
301 else if a.tag > b.tag then result := false
302 else result := a.arrIdx < b.arrIdx;
303 end;
305 procedure r_Map_Initialize;
306 begin
307 FlagFrame := 0;
308 plist := TBinHeapPanelDraw.Create();
309 end;
311 procedure r_Map_Finalize;
312 begin
313 r_Common_FreeAndNil(plist);
314 FlagFrame := 0;
315 end;
317 procedure r_Map_FreeModel (i: Integer);
318 var a: Integer; d: TDirection;
319 begin
320 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
321 begin
322 for a := A_STAND to A_LAST do
323 begin
324 r_Common_FreeAndNil(Models[i].anim[d, a].base);
325 r_Common_FreeAndNil(Models[i].anim[d, a].mask);
326 end;
327 end;
328 {$IFDEF ENABLE_GIBS}
329 if Models[i].gibs.base <> nil then
330 for a := 0 to High(Models[i].gibs.base) do
331 r_Common_FreeAndNil(Models[i].gibs.base[a]);
332 if Models[i].gibs.mask <> nil then
333 for a := 0 to High(Models[i].gibs.mask) do
334 r_Common_FreeAndNil(Models[i].gibs.mask[a]);
335 Models[i].gibs.base := nil;
336 Models[i].gibs.mask := nil;
337 Models[i].gibs.rect := nil;
338 {$ENDIF}
339 end;
341 procedure r_Map_LoadModel (i: Integer);
342 var prefix: AnsiString; a: Integer; d: TDirection; m: ^TPlayerModelInfo;
343 begin
344 ASSERT(i < Length(Models));
345 ASSERT(i < Length(PlayerModelsArray));
346 r_Map_FreeModel(i);
347 m := @PlayerModelsArray[i];
348 prefix := m.FileName + ':TEXTURES/';
349 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
350 begin
351 for a := A_STAND to A_LAST do
352 begin
353 Models[i].anim[d, a].base := nil;
354 Models[i].anim[d, a].mask := nil;
355 if m.anim[d, a].resource <> '' then
356 Models[i].anim[d, a].base := r_Textures_LoadMultiFromFileAndInfo(prefix + m.anim[d, a].resource, 64, 64, m.anim[d, a].frames, [TGLHints.txNoRepeat], true);
357 if m.anim[d, a].mask <> '' then
358 Models[i].anim[d, a].mask := r_Textures_LoadMultiFromFileAndInfo(prefix + m.anim[d, a].mask, 64, 64, m.anim[d, a].frames, [TGLHints.txNoRepeat], true);
359 end
360 end;
361 {$IFDEF ENABLE_GIBS}
362 Models[i].gibs.base := nil;
363 Models[i].gibs.mask := nil;
364 Models[i].gibs.rect := nil;
365 if m.GibsCount > 0 then
366 begin
367 SetLength(Models[i].gibs.base, m.GibsCount);
368 SetLength(Models[i].gibs.mask, m.GibsCount);
369 SetLength(Models[i].gibs.rect, m.GibsCount);
370 for a := 0 to m.GibsCount - 1 do
371 Models[i].gibs.rect[a] := DefaultGibSize;
372 if r_Textures_LoadStreamFromFile(prefix + m.GibsResource, 32, 32, m.GibsCount, m.GibsCount, Models[i].gibs.base, Models[i].gibs.rect, [TGLHints.txNoRepeat]) then
373 begin
374 if r_Textures_LoadStreamFromFile(prefix + m.GibsMask, 32, 32, m.GibsCount, m.GibsCount, Models[i].gibs.mask, nil, [TGLHints.txNoRepeat]) then
375 begin
376 // ok
377 end;
378 end;
379 end;
380 {$ENDIF}
381 end;
383 procedure r_Map_LoadMonsterAnim (m, a: Integer; d: TDirection);
384 const dir: array [TDirection] of AnsiString = ('_L', '');
385 var w, h, count: Integer;
386 begin
387 count := MONSTER_ANIMTABLE[m].AnimCount[a];
388 if count > 0 then
389 begin
390 w := MTABLE[m].w;
391 h := MTABLE[m].h;
392 if (m = MONSTER_SOUL) and (a = ANIM_DIE) then
393 begin
394 // special case
395 w := 128;
396 h := 128;
397 end;
398 MonTextures[m, a, d] := r_Textures_LoadMultiFromFileAndInfo(
399 GameWAD + ':MTEXTURES/' + MONSTERTABLE[m].name + '_' + ANIMTABLE[a].name + dir[d],
400 w,
401 h,
402 count,
403 [TGLHints.txNoRepeat],
404 False
405 );
406 end
407 else
408 MonTextures[m, a, d] := nil;
409 end;
411 procedure r_Map_Load;
412 const
413 WeapName: array [0..WP_LAST] of AnsiString = ('', 'CSAW', 'HGUN', 'SG', 'SSG', 'MGUN', 'RKT', 'PLZ', 'BFG', 'SPL', 'FLM');
414 WeapPos: array [0..W_POS_LAST] of AnsiString = ('', '_UP', '_DN');
415 WeapAct: array [0..W_ACT_LAST] of AnsiString = ('', '_FIRE');
416 PunchName: array [Boolean] of AnsiString = ('PUNCH', 'PUNCHB');
417 var
418 i, j, k: Integer; d: TDirection; b: Boolean;
419 begin
420 // --------- items --------- //
421 r_Common_SetLoading(_lc[I_LOAD_ITEMS_DATA], ITEM_LAST + 1);
422 for i := 0 to ITEM_LAST do
423 begin
424 Items[i].tex := r_Common_LoadTextureMultiFromFileAndInfo(
425 GameWAD + ':TEXTURES/' + ItemAnim[i].name,
426 ItemAnim[i].w,
427 ItemAnim[i].h,
428 ItemAnim[i].anim.frames,
429 [TGLHints.txNoRepeat],
430 false
431 );
432 Items[i].frame := 0;
433 end;
434 // --------- monsters --------- //
435 r_Common_SetLoading(_lc[I_LOAD_MONSTER_TEXTURES], MONSTER_MAN - MONSTER_DEMON + 1);
436 for i := MONSTER_DEMON to MONSTER_MAN do
437 begin
438 for j := 0 to ANIM_LAST do
439 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
440 r_Map_LoadMonsterAnim(i, j, d);
441 r_Common_StepLoading(1);
442 end;
443 VileFire := r_Textures_LoadMultiFromFileAndInfo(GameWAD + ':TEXTURES/FIRE', 64, 128, VileFireAnim.frames, [TGLHints.txNoRepeat]);
444 // --------- player models --------- //
445 if PlayerModelsArray <> nil then
446 begin
447 r_Common_SetLoading(_lc[I_LOAD_MODELS], Length(PlayerModelsArray));
448 SetLength(Models, Length(PlayerModelsArray));
449 for i := 0 to High(PlayerModelsArray) do
450 begin
451 r_Map_LoadModel(i);
452 r_Common_StepLoading(1);
453 end;
454 end;
455 // --------- player weapons --------- //
456 r_Common_SetLoading(_lc[I_LOAD_WEAPONS_DATA], WP_LAST);
457 for i := 1 to WP_LAST do
458 begin
459 for j := 0 to W_POS_LAST do
460 for k := 0 to W_ACT_LAST do
461 WeapTextures[i, j, k] := r_Textures_LoadFromFile(GameWAD + ':WEAPONS\' + WeapName[i] + WeapPos[j] + WeapAct[k], [TGLHints.txNoRepeat]);
462 r_Common_StepLoading(1);
463 end;
464 // --------- gfx animations --------- //
465 {$IFDEF ENABLE_GFX}
466 r_Common_SetLoading('GFX Effects', R_GFX_LAST);
467 for i := 1 to R_GFX_LAST do
468 begin
469 if GFXAnim[i].anim.frames > 0 then
470 GFXTextures[i] := r_Common_LoadTextureMultiFromFileAndInfo(GameWad + ':TEXTURES/' + GFXAnim[i].name, GFXAnim[i].w, GFXAnim[i].h, GFXAnim[i].anim.frames, [TGLHints.txNoRepeat]);
471 end;
472 {$ENDIF}
473 // --------- shots --------- //
474 r_Common_SetLoading('Weapon splashes', WEAPON_LAST + 1);
475 for i := 0 to WEAPON_LAST do
476 begin
477 if ShotAnim[i].anim.frames > 0 then
478 ShotTextures[i] := r_Common_LoadTextureMultiFromFileAndInfo(GameWad + ':TEXTURES/' + ShotAnim[i].name, ShotAnim[i].w, ShotAnim[i].h, ShotAnim[i].anim.frames, [TGLHints.txNoRepeat]);
479 end;
480 // --------- flags --------- //
481 r_Common_SetLoading('Flags', 2);
482 FlagTextures[FLAG_NONE] := nil;
483 FlagTextures[FLAG_RED] := r_Common_LoadTextureMultiFromFileAndInfo(GameWad + ':TEXTURES/FLAGRED', 64, 64, 5, [TGLHints.txNoRepeat]);
484 FlagTextures[FLAG_BLUE] := r_Common_LoadTextureMultiFromFileAndInfo(GameWad + ':TEXTURES/FLAGBLUE', 64, 64, 5, [TGLHints.txNoRepeat]);
485 // FlagTextures[FLAG_DOM] := r_Common_LoadTextureMultiFromFileAndInfo(GameWad + ':TEXTURES/FLAGDOM', 64, 64, 8, [TGLHints.txNoRepeat]);
486 // --------- shells --------- //
487 {$IFDEF ENABLE_SHELLS}
488 r_Common_SetLoading('Shells', SHELL_LAST + 1);
489 for i := 0 to SHELL_LAST do
490 ShellTextures[i] := r_Common_LoadTextureFromFile(GameWad + ':TEXTURES/' + ShellAnim[i].name, [TGLHints.txNoRepeat]);
491 {$ENDIF}
492 // --------- other --------- //
493 r_Common_SetLoading('Effects', 3 * 2 + 3);
494 for b := false to true do
495 begin
496 for i := 0 to 2 do
497 PunchTextures[b, i] := r_Common_LoadTextureMultiFromFileAndInfo(GameWad + ':WEAPONS/' + PunchName[b] + WeapPos[i], 64, 64, PunchAnim.frames, [TGLHints.txNoRepeat]);
498 end;
499 InvulPenta := r_Common_LoadTextureFromFile(GameWad + ':TEXTURES/PENTA', [TGLHints.txNoRepeat]);
500 IndicatorTexture := r_Common_LoadTextureFromFile(GameWad + ':TEXTURES/PLRIND', [TGLHints.txNoRepeat]);
501 TalkTexture := r_Common_LoadTextureFromFile(GameWad + ':TEXTURES/TALKBUBBLE', [TGLHints.txNoRepeat]);
502 end;
504 procedure r_Map_Free;
505 var i, j, k: Integer; d: TDirection; b: Boolean;
506 begin
507 r_Common_FreeAndNil(TalkTexture);
508 r_Common_FreeAndNil(IndicatorTexture);
509 r_Common_FreeAndNil(InvulPenta);
510 for b := false to true do
511 for i := 0 to 2 do
512 r_Common_FreeAndNil(PunchTextures[b, i]);
513 {$IFDEF ENABLE_SHELLS}
514 for i := 0 to SHELL_LAST do
515 r_Common_FreeAndNil(ShellTextures[i]);
516 {$ENDIF}
517 for i := 0 to FLAG_LAST do
518 r_Common_FreeAndNil(FlagTextures[i]);
519 for i := 0 to WEAPON_LAST do
520 r_Common_FreeAndNil(ShotTextures[i]);
521 {$IFDEF ENABLE_GFX}
522 SetLength(gfxlist, 0);
523 for i := 0 to R_GFX_LAST do
524 r_Common_FreeAndNil(GFXTextures[i]);
525 {$ENDIF}
526 for i := 1 to WP_LAST do
527 for j := 0 to W_POS_LAST do
528 for k := 0 to W_ACT_LAST do
529 r_Common_FreeAndNil(WeapTextures[i, j, k]);
530 if Models <> nil then
531 for i := 0 to High(Models) do
532 r_Map_FreeModel(i);
533 for i := MONSTER_DEMON to MONSTER_MAN do
534 for j := 0 to ANIM_LAST do
535 for d := TDirection.D_LEFT to TDirection.D_RIGHT do
536 r_Common_FreeAndNil(MonTextures[i, j, d]);
537 for i := 0 to ITEM_LAST do
538 r_Common_FreeAndNil(Items[i].tex);
539 end;
541 procedure r_Map_FreeTextures;
542 var i: Integer;
543 begin
544 plist.Clear;
545 r_Common_FreeAndNil(SkyTexture);
546 if RenTextures <> nil then
547 for i := 0 to High(RenTextures) do
548 r_Common_FreeAndNil(RenTextures[i].tex);
549 SetLength(RenTextures, 0);
550 end;
552 procedure r_Map_LoadTextures;
553 const DefaultAnimInfo: TAnimInfo = (loop: true; delay: 1; frames: 1; back: false);
554 var i, n: Integer; txt: TAnimTextInfo;
555 begin
556 r_Map_FreeTextures;
557 if Textures <> nil then
558 begin
559 n := Length(Textures);
560 SetLength(RenTextures, n);
561 r_Common_SetLoading(_lc[I_LOAD_TEXTURES], n);
562 for i := 0 to n - 1 do
563 begin
564 RenTextures[i].tex := nil;
565 RenTextures[i].anim := DefaultAnimInfo;
566 case Textures[i].TextureName of
567 TEXTURE_NAME_WATER: RenTextures[i].spec := TEXTURE_SPECIAL_WATER;
568 TEXTURE_NAME_ACID1: RenTextures[i].spec := TEXTURE_SPECIAL_ACID1;
569 TEXTURE_NAME_ACID2: RenTextures[i].spec := TEXTURE_SPECIAL_ACID2;
570 else
571 RenTextures[i].spec := 0;
572 RenTextures[i].tex := r_Textures_LoadMultiTextFromFile(Textures[i].FullName, txt, []);
573 if RenTextures[i].tex <> nil then
574 begin
575 RenTextures[i].anim := txt.anim;
576 r_Common_StepLoading(1);
577 end
578 else
579 begin
580 e_LogWritefln('r_Map_LoadTextures: failed to load texture: %s', [Textures[i].FullName]);
581 end;
582 end;
583 ASSERT(RenTextures[i].anim.frames > 0);
584 ASSERT(RenTextures[i].anim.delay > 0);
585 end;
586 end;
587 if gMapInfo.SkyFullName <> '' then
588 begin
589 r_Common_SetLoading(_lc[I_LOAD_SKY], 1);
590 SkyTexture := r_Common_LoadTextureFromFile(gMapInfo.SkyFullName, [TGLHints.txNoRepeat]);
591 end;
592 plist.Clear;
593 end;
595 procedure r_Map_DrawPanel (p: TPanel);
596 var Texture, x, y, w, h: Integer; t: TGLMultiTexture; count, frame: LongInt; a: TAnimInfo;
597 begin
598 ASSERT(p <> nil);
599 ASSERT(p.FCurTexture >= -1); (* p.FCurTexture = -1 -> invisible texture *)
600 if p.FCurTexture >= 0 then
601 begin
602 r_Common_GetPanelPos(p, x, y, w, h);
603 ASSERT(p.FCurTexture <= High(p.TextureIDs));
604 Texture := p.TextureIDs[p.FCurTexture].Texture;
605 ASSERT(Texture >= -1); (* Texture = -1 -> texture not found *)
606 if Texture >= 0 then
607 begin
608 ASSERT(Texture <= High(RenTextures));
609 t := RenTextures[Texture].tex;
610 if t <> nil then
611 begin
612 count := 0; frame := 0;
613 if p.AnimTime <= gTime then
614 begin
615 a := RenTextures[Texture].anim;
616 a.loop := p.AnimLoop;
617 g_Anim_GetFrameByTime(a, (gTime - p.AnimTime) DIV GAME_TICK, count, frame);
618 end;
619 r_Draw_TextureRepeat(t.GetTexture(frame), x, y, w, h, false, 255, 255, 255, 255 - p.alpha, p.blending);
620 end
621 else if RenTextures[Texture].spec = 0 then
622 begin
623 r_Draw_TextureRepeat(nil, x, y, w, h, false, 255, 255, 255, 255, false);
624 end;
625 case RenTextures[Texture].spec of
626 TEXTURE_SPECIAL_WATER: r_Draw_Filter(x, y, x + w, y + h, 0, 0, 255, 255);
627 TEXTURE_SPECIAL_ACID1: r_Draw_Filter(x, y, x + w, y + h, 0, 230, 0, 255);
628 TEXTURE_SPECIAL_ACID2: r_Draw_Filter(x, y, x + w, y + h, 230, 0, 0, 255);
629 end;
630 end
631 else
632 begin
633 r_Draw_TextureRepeat(nil, x, y, w, h, false, 255, 255, 255, 255, false);
634 end;
635 end;
636 end;
638 procedure r_Map_DrawPanels (constref panels: TPanelArray; drawDoors: Boolean = false);
639 var i: Integer; p: TPanel;
640 begin
641 if panels <> nil then
642 begin
643 for i := 0 to High(panels) do
644 begin
645 p := panels[i];
646 if p.enabled and not (drawDoors xor p.door) then
647 r_Map_DrawPanel(p);
648 end;
649 end;
650 end;
652 procedure r_Map_DrawPanelType (panelTyp: DWORD);
653 var tagMask: Integer; p: TPanel;
654 begin
655 if UseAccel then
656 begin
657 tagMask := PanelTypeToTag(panelTyp);
658 while plist.count > 0 do
659 begin
660 p := TPanel(plist.Front());
661 if (p.tag and tagMask) = 0 then
662 break;
663 r_Map_DrawPanel(p);
664 plist.PopFront;
665 end;
666 end
667 else
668 begin
669 case panelTyp of
670 PANEL_BACK: if g_rlayer_back then r_Map_DrawPanels(gRenderBackgrounds);
671 PANEL_STEP: if g_rlayer_step then r_Map_DrawPanels(gSteps);
672 PANEL_WALL: if g_rlayer_wall then r_Map_DrawPanels(gWalls);
673 PANEL_CLOSEDOOR: if g_rlayer_door then r_Map_DrawPanels(gWalls, True);
674 PANEL_ACID1: if g_rlayer_acid1 then r_Map_DrawPanels(gAcid1);
675 PANEL_ACID2: if g_rlayer_acid2 then r_Map_DrawPanels(gAcid2);
676 PANEL_WATER: if g_rlayer_water then r_Map_DrawPanels(gWater);
677 PANEL_FORE: if g_rlayer_fore then r_Map_DrawPanels(gRenderForegrounds);
678 end;
679 end;
680 end;
682 procedure r_Map_DrawItems (x, y, w, h: Integer; drop: Boolean);
683 var i, xx, yy: Integer; it: PItem; t: TGLMultiTexture; tex: TGLTexture;
684 begin
685 if ggItems <> nil then
686 begin
687 (* hack: prevent visual disappearance *)
688 x := x - MAXITEMW;
689 y := y - MAXITEMH;
690 w := w + MAXITEMW*2;
691 h := h + MAXITEMH*2;
692 for i := 0 to High(ggItems) do
693 begin
694 it := @ggItems[i];
695 if it.used and it.alive and (it.dropped = drop) and (it.ItemType > ITEM_NONE) and (it.ItemType <= ITEM_LAST) then
696 begin
697 r_Common_GetObjectPos(it.obj, xx, yy);
698 if g_Collide(xx + it.obj.rect.x, yy + it.obj.rect.y, it.obj.rect.width, it.obj.rect.height, x, y, w, h) then
699 begin
700 t := Items[it.ItemType].tex;
701 tex := t.GetTexture(Items[it.ItemType].frame);
702 r_Draw_TextureRepeat(tex, xx, yy, tex.width, tex.height, false, 255, 255, 255, 255, false);
703 if DebugFrames then
704 begin
705 r_Draw_Rect(
706 xx + it.obj.rect.x, // it.obj.x + it.obj.rect.x,
707 yy + it.obj.rect.y, // it.obj.y + it.obj.rect.y,
708 xx + it.obj.rect.x + it.obj.rect.width, // it.obj.x + it.obj.rect.x + it.obj.rect.width,
709 yy + it.obj.rect.y + it.obj.rect.height, // it.obj.y + it.obj.rect.y + it.obj.rect.height,
710 0, 255, 0, 255
711 );
712 end;
713 end;
714 end;
715 end;
716 end;
717 end;
719 function r_Map_GetMonsterTexture (m, a: Integer; d: TDirection; out t: TGLMultiTexture; out dx, dy: Integer; out flip: Boolean): Boolean;
720 var w: Integer;
721 begin
722 t := nil; dx := 0; dy := 0; flip := false;
723 result := MonTextures[m, a, d] <> nil;
724 if result = false then
725 begin
726 flip := true;
727 if d = TDirection.D_RIGHT then d := TDirection.D_LEFT else d := TDirection.D_RIGHT;
728 result := MonTextures[m, a, d] <> nil;
729 end;
730 if result = true then
731 begin
732 t := MonTextures[m, a, d];
733 if d = TDirection.D_LEFT then
734 begin
735 dx := MONSTER_ANIMTABLE[m].AnimDeltaLeft[a].X;
736 dy := MONSTER_ANIMTABLE[m].AnimDeltaLeft[a].Y;
737 end
738 else
739 begin
740 dx := MONSTER_ANIMTABLE[m].AnimDeltaRight[a].X;
741 dy := MONSTER_ANIMTABLE[m].AnimDeltaRight[a].Y;
742 end;
743 if flip then
744 begin
745 if (m = MONSTER_SOUL) and (a = ANIM_DIE) then w := 64 else w := 0;
746 dx := -dx - w;
747 end;
748 end;
749 end;
751 procedure r_Map_DrawMonsterAttack (constref mon: TMonster);
752 var o: TObj; count, frame, xx, yy: LongInt; tex: TGLTexture;
753 begin
754 if VileFire <> nil then
755 begin
756 if (mon.MonsterType = MONSTER_VILE) and (mon.MonsterState = MONSTATE_SHOOT) and (mon.VileFireTime <= gTime) then
757 begin
758 if r_Common_GetPosByUID(mon.MonsterTargetUID, o, xx, yy) then
759 begin
760 g_Anim_GetFrameByTime(VileFireAnim, (gTime - mon.VileFireTime) DIV GAME_TICK, count, frame);
761 tex := VileFire.GetTexture(frame);
762 r_Draw_TextureRepeat(tex, xx + o.rect.x + (o.rect.width div 2) - VILEFIRE_DX, yy + o.rect.y + o.rect.height - VILEFIRE_DY, tex.width, tex.height, False, 255, 255, 255, 255, false);
763 end;
764 end;
765 end;
766 end;
768 procedure r_Map_DrawMonster (constref mon: TMonster);
769 var m, a, xx, yy, dx, dy: Integer; d, da: TDirection; flip: Boolean; t: TGLMultiTexture;
770 begin
771 m := mon.MonsterType;
772 a := mon.MonsterAnim;
773 d := mon.GameDirection;
775 (* hack: barrel tracks player, fix it in game logic *)
776 if m = MONSTER_BARREL then d := TDirection.D_LEFT;
778 r_Common_GetObjectPos(mon.obj, xx, yy);
779 if r_Map_GetMonsterTexture(m, a, d, t, dx, dy, flip) then
780 begin
781 da := mon.GameDirection;
782 r_Draw_MultiTextureRepeat(t, mon.DirAnim[a, da], false, xx + dx, yy + dy, t.width, t.height, flip, 255, 255, 255, 255, false);
783 end;
784 if DebugFrames then
785 begin
786 r_Draw_Rect(
787 xx + mon.obj.rect.x, // mon.obj.x + mon.obj.rect.x,
788 yy + mon.obj.rect.y, // mon.obj.y + mon.obj.rect.y,
789 xx + mon.obj.rect.x + mon.obj.rect.width, // mon.obj.x + mon.obj.rect.x + mon.obj.rect.width,
790 yy + mon.obj.rect.y + mon.obj.rect.height, // mon.obj.y + mon.obj.rect.y + mon.obj.rect.height,
791 0, 255, 0, 255
792 );
793 end;
794 if DebugHealth and mon.alive then
795 begin
796 r_Common_DrawText(
797 IntToStr(mon.MonsterHealth),
798 xx + mon.obj.rect.x + mon.obj.rect.width div 2,
799 yy + mon.obj.rect.y,
800 255, 255, 255, 255,
801 stdfont,
802 TBasePoint.BP_DOWN
803 );
804 end;
805 end;
807 procedure r_Map_DrawMonsters (x, y, w, h: Integer);
808 var i: Integer; m: TMonster;
809 begin
810 if gMonsters <> nil then
811 begin
812 (* hack: prevent visual disappearance *)
813 x := x - MAXMONW;
814 y := y - MAXMONH;
815 w := w + MAXMONW*2;
816 h := h + MAXMONH*2;
817 for i := 0 to High(gMonsters) do
818 begin
819 m := gMonsters[i];
820 if m <> nil then
821 begin
822 r_Map_DrawMonsterAttack(m);
823 // TODO select from grid
824 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
825 r_Map_DrawMonster(m);
826 end;
827 end;
828 end;
829 end;
831 function r_Map_GetPlayerModelTex (i: Integer; var a: Integer; var d: TDirection; out flip: Boolean): Boolean;
832 begin
833 flip := false;
834 result := Models[i].anim[d, a].base <> nil;
835 if result = false then
836 begin
837 flip := true;
838 if d = TDirection.D_LEFT then d := TDirection.D_RIGHT else d := TDirection.D_LEFT;
839 result := Models[i].anim[d, a].base <> nil;
840 end;
841 end;
843 procedure r_Map_DrawPlayerModel (pm: TPlayerModel; x, y: Integer; alpha: Byte);
844 var a, pos, act, xx, yy, angle: Integer; d: TDirection; flip, back: Boolean; t: TGLMultiTexture; tex: TGLTexture; c: TRGB;
845 begin
846 a := pm.CurrentAnimation;
847 d := pm.Direction;
849 (* draw flag*)
850 t := FlagTextures[pm.Flag];
851 if (t <> nil) and not (a in [A_DIE1, A_DIE2]) then
852 begin
853 flip := d = TDirection.D_RIGHT;
854 angle := PlayerModelsArray[pm.id].FlagAngle;
855 xx := PlayerModelsArray[pm.id].FlagPoint.X;
856 yy := PlayerModelsArray[pm.id].FlagPoint.Y;
857 tex := t.GetTexture(FlagFrame);
858 r_Draw_TextureRepeatRotate(
859 tex,
860 x + IfThen(flip, 2 * FLAG_BASEPOINT.X - xx + 1, xx - 1) - FLAG_BASEPOINT.X,
861 y + yy - FLAG_BASEPOINT.Y + 1,
862 tex.width,
863 tex.height,
864 flip,
865 255, 255, 255, 255, false,
866 IfThen(flip, 64 - FLAG_BASEPOINT.X, FLAG_BASEPOINT.X),
867 FLAG_BASEPOINT.Y,
868 IfThen(flip, angle, -angle)
869 );
870 end;
872 (* draw weapon *)
873 if PlayerModelsArray[pm.id].HaveWeapon and not (a in [A_DIE1, A_DIE2, A_PAIN]) then
874 begin
875 case a of
876 A_SEEUP, A_ATTACKUP: pos := W_POS_UP;
877 A_SEEDOWN, A_ATTACKDOWN: pos := W_POS_DOWN;
878 else pos := W_POS_NORMAL;
879 end;
880 if (a in [A_ATTACK, A_ATTACKUP, A_ATTACKDOWN]) or pm.GetFire() then
881 act := W_ACT_FIRE
882 else
883 act := W_ACT_NORMAL;
884 tex := WeapTextures[pm.CurrentWeapon, pos, act];
885 if tex <> nil then
886 begin
887 xx := PlayerModelsArray[pm.id].WeaponPoints[pm.CurrentWeapon, a, d, pm.AnimState.CurrentFrame].X;
888 yy := PlayerModelsArray[pm.id].WeaponPoints[pm.CurrentWeapon, a, d, pm.AnimState.CurrentFrame].Y;
889 r_Draw_Texture(
890 tex,
891 x + xx,
892 y + yy,
893 tex.width,
894 tex.height,
895 d = TDirection.D_LEFT,
896 255, 255, 255, alpha, false
897 );
898 end;
899 end;
901 (* draw body *)
902 if r_Map_GetPlayerModelTex(pm.id, a, d, flip) then
903 begin
904 t := Models[pm.id].anim[d, a].base;
905 back := PlayerModelsArray[pm.id].anim[d, a].back;
906 r_Draw_MultiTextureRepeat(t, pm.AnimState, back, x, y, t.width, t.height, flip, 255, 255, 255, alpha, false);
907 t := Models[pm.id].anim[d, a].mask;
908 if t <> nil then
909 begin
910 c := pm.Color;
911 r_Draw_MultiTextureRepeat(t, pm.AnimState, back, x, y, t.width, t.height, flip, c.r, c.g, c.b, alpha, false);
912 end;
913 end;
914 end;
916 procedure r_Map_DrawBubble (x, y: Integer; cb, cf: TRGB);
917 const w = 20; h = 14;
918 const dx = 6; dy = 8; dot = 6; size = 2;
919 const tx = 6; ty = h - 1;
920 begin
921 // Outer box (top/down)
922 r_Draw_FillRect(x + 1, y, x + w - 1, y + 1, cb.R, cb.G, cb.B, 255);
923 r_Draw_FillRect(x + 1, y + h - 1, x + w - 1, y + h, cb.R, cb.G, cb.B, 255);
924 // Outer box (left/right)
925 r_Draw_FillRect(x, y + 1, x + 1, y + h - 1, cb.R, cb.G, cb.B, 255);
926 r_Draw_FillRect(x + w - 1, y + 1, x + w, y + h - 1, cb.R, cb.G, cb.B, 255);
927 // Outer tail
928 r_Draw_FillRect(x + tx - 1, y + ty + 0, x + tx + 3 + 1, y + ty + 1, cb.R, cb.G, cb.B, 255);
929 r_Draw_FillRect(x + tx - 1, y + ty + 1, x + tx + 2 + 1, y + ty + 2, cb.R, cb.G, cb.B, 255);
930 r_Draw_FillRect(x + tx - 1, y + ty + 2, x + tx + 1 + 1, y + ty + 3, cb.R, cb.G, cb.B, 255);
931 r_Draw_FillRect(x + tx - 1, y + ty + 3, x + tx + 0 + 1, y + ty + 4, cb.R, cb.G, cb.B, 255);
932 // Inner tail
933 r_Draw_FillRect(x + tx, y + ty + 0, x + tx + 3, y + ty + 1, cf.R, cf.G, cf.B, 255);
934 r_Draw_FillRect(x + tx, y + ty + 1, x + tx + 2, y + ty + 2, cf.R, cf.G, cf.B, 255);
935 r_Draw_FillRect(x + tx, y + ty + 2, x + tx + 1, y + ty + 3, cf.R, cf.G, cf.B, 255);
936 // Inner box
937 r_Draw_FillRect(x + 1, y + 1, x + w - 1, y + h - 1, cf.R, cf.G, cf.B, 255);
938 // Dots
939 r_Draw_FillRect(x + dx + 0*3, y + dy, x + dx + 0*3 + size, y + dy + size, cb.R, cb.G, cb.B, 255);
940 r_Draw_FillRect(x + dx + 1*3, y + dy, x + dx + 1*3 + size, y + dy + size, cb.R, cb.G, cb.B, 255);
941 r_Draw_FillRect(x + dx + 2*3, y + dy, x + dx + 2*3 + size, y + dy + size, cb.R, cb.G, cb.B, 255);
942 end;
944 procedure r_Map_DrawTalkBubble (p: TPlayer);
945 var xx, yy, x, y: Integer; cb, cf: TRGB;
946 begin
947 r_Common_GetPlayerPos(p, xx, yy);
948 x := xx + p.obj.rect.x + p.obj.rect.width div 2;
949 y := yy;
950 cb := _RGB(63, 63, 63);
951 cf := _RGB(240, 240, 240);
952 case gChatBubble of
953 1: // simple text
954 begin
955 r_Common_DrawText('[...]', x, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
956 end;
957 2: // adv team color
958 begin
959 case p.Team of
960 TEAM_RED: cb := _RGB(255, 63, 63);
961 TEAM_BLUE: cb := _RGB(63, 63, 255);
962 end;
963 r_Map_DrawBubble(x, y - 18, cb, cf);
964 end;
965 3: // adv player color
966 begin
967 cb := p.Model.Color;
968 cf.R := MIN(cb.R * 2 + 64, 255);
969 cf.G := MIN(cb.G * 2 + 64, 255);
970 cf.B := MIN(cb.B * 2 + 64, 255);
971 if (ABS(cf.R - cb.R) < 32) or (ABS(cf.G - cb.G) < 32) or (ABS(cf.B - cb.B) < 32) then
972 begin
973 cb.R := MAX(cf.R div 2 - 16, 0);
974 cb.G := MAX(cf.G div 2 - 16, 0);
975 cb.B := MAX(cf.B div 2 - 16, 0);
976 end;
977 r_Map_DrawBubble(x, y - 18, cb, cf);
978 end;
979 4: // textured
980 if TalkTexture <> nil then
981 begin
982 r_Common_DrawTexture(TalkTexture, x + 5, y, TalkTexture.width, TalkTexture.height, TBasePoint.BP_DOWN);
983 end;
984 end;
985 end;
987 procedure r_Map_DrawPlayer (p, drawed: TPlayer);
988 var x, y, ax, ay, w, h: Integer; b, flip: Boolean; t: TGLMultiTexture; tex: TGLTexture; alpha: Byte; count, frame: LongInt;
989 begin
990 if p.alive then
991 begin
992 r_Common_GetPlayerPos(p, x, y);
994 (* punch effect *)
995 if p.PunchTime <= gTime then
996 begin
997 g_Anim_GetFrameByTime(PunchAnim, (gTime - p.PunchTime) DIV GAME_TICK, count, frame);
998 if count < 1 then
999 begin
1000 b := R_BERSERK in p.FRulez;
1001 if p.FKeys[KEY_DOWN].pressed then
1002 t := PunchTextures[b, 2]
1003 else if p.FKeys[KEY_UP].pressed then
1004 t := PunchTextures[b, 1]
1005 else
1006 t := PunchTextures[b, 0];
1007 if t <> nil then
1008 begin
1009 flip := p.Direction = TDirection.D_LEFT;
1010 ax := IfThen(flip, 15 - p.Obj.Rect.X, p.Obj.Rect.X - 15); // ???
1011 ay := p.Obj.Rect.Y - 11;
1012 tex := t.GetTexture(frame);
1013 r_Draw_TextureRepeat(tex, x + ax, y + ay, tex.width, tex.height, flip, 255, 255, 255, 255, false)
1014 end;
1015 end;
1016 end;
1018 (* invulnerability effect *)
1019 if (InvulPenta <> nil) and (p.FMegaRulez[MR_INVUL] > gTime) and ((p <> drawed) or (p.SpawnInvul >= gTime)) then
1020 begin
1021 w := InvulPenta.width;
1022 h := InvulPenta.height;
1023 ax := p.Obj.Rect.X + (p.Obj.Rect.Width div 2) - (w div 2); // + IfThen(flip, +4, -2) // ???
1024 ay := p.Obj.Rect.Y + (p.Obj.Rect.Height div 2) - (h div 2) - 7; // ???
1025 r_Draw_Texture(InvulPenta, x + ax, y + ay, w, h, false, 255, 255, 255, 255, false);
1026 end;
1028 (* invisibility effect *)
1029 alpha := 255;
1030 if p.FMegaRulez[MR_INVIS] > gTime then
1031 begin
1032 if (drawed <> nil) and ((p = drawed) or ((p.Team = drawed.Team) and (gGameSettings.GameMode <> GM_DM))) then
1033 begin
1034 if (p.FMegaRulez[MR_INVIS] - gTime > 2100) or not ODD((p.FMegaRulez[MR_INVIS] - gTime) div 300) then
1035 alpha := 55;
1036 end
1037 else
1038 alpha := 1; // ???
1039 end;
1041 r_Map_DrawPlayerModel(p.Model, x, y, alpha);
1042 end;
1044 if DebugFrames then
1045 begin
1046 r_Draw_Rect(
1047 x + p.obj.rect.x, // p.obj.x + p.obj.rect.x,
1048 y + p.obj.rect.y, // p.obj.y + p.obj.rect.y,
1049 x + p.obj.rect.x + p.obj.rect.width, // p.obj.x + p.obj.rect.x + p.obj.rect.width,
1050 y + p.obj.rect.y + p.obj.rect.height, // p.obj.y + p.obj.rect.y + p.obj.rect.height,
1051 0, 255, 0, 255
1052 );
1053 end;
1055 if DebugHealth and p.alive then
1056 begin
1057 r_Common_DrawText(
1058 IntToStr(p.health) + '/' + IntToStr(p.armor),
1059 x + p.obj.rect.x + p.obj.rect.width div 2,
1060 y - 24,
1061 255, 255, 255, 255,
1062 stdfont,
1063 TBasePoint.BP_DOWN
1064 );
1065 end;
1067 if (gChatBubble > 0) and p.FKeys[KEY_CHAT].Pressed and (p.Ghost = false) then
1068 if (p.FMegaRulez[MR_INVIS] <= gTime) or ((drawed <> nil) and ((p = drawed) or (p.Team = drawed.Team) and (gGameSettings.GameMode <> GM_DM))) then
1069 r_Map_DrawTalkBubble(p);
1071 // TODO draw aim
1072 end;
1074 procedure r_Map_DrawPlayers (x, y, w, h: Integer; player: TPlayer);
1075 var i: Integer;
1076 begin
1077 if gPlayers <> nil then
1078 for i := 0 to High(gPlayers) do
1079 if gPlayers[i] <> nil then
1080 r_Map_DrawPlayer(gPlayers[i], player);
1081 end;
1083 {$IFDEF ENABLE_GIBS}
1084 function r_Map_GetGibSize (m, i: Integer): TRectWH;
1085 begin
1086 result := Models[m].gibs.rect[i];
1087 end;
1089 procedure r_Map_DrawGibs (x, y, w, h: Integer);
1090 var i, xx, yy, m, id, rx, ry, ra: Integer; p: PObj; t: TGLTexture;
1091 begin
1092 if gGibs <> nil then
1093 begin
1094 (* hack: prevent visual disappearance *)
1095 x := x - MAXGIBW;
1096 y := y - MAXGIBH;
1097 w := w + MAXGIBW*2;
1098 h := h + MAXGIBH*2;
1099 for i := 0 to High(gGibs) do
1100 begin
1101 if gGibs[i].alive then
1102 begin
1103 p := @gGibs[i].Obj;
1104 if g_Obj_Collide(x, y, w, h, p) then
1105 begin
1106 r_Common_GetObjectPos(p^, xx, yy);
1107 id := gGibs[i].GibID;
1108 m := gGibs[i].ModelID;
1109 t := Models[m].gibs.base[id];
1110 if t <> nil then
1111 begin
1112 rx := p.Rect.X + p.Rect.Width div 2;
1113 ry := p.Rect.Y + p.Rect.Height div 2;
1114 ra := gGibs[i].RAngle;
1115 r_Draw_TextureRepeatRotate(t, xx, yy, t.width, t.height, false, 255, 255, 255, 255, false, rx, ry, ra);
1116 t := Models[m].gibs.mask[id];
1117 if t <> nil then
1118 r_Draw_TextureRepeatRotate(t, xx, yy, t.width, t.height, false, gGibs[i].Color.R, gGibs[i].Color.G, gGibs[i].Color.B, 255, false, rx, ry, ra);
1119 // r_Draw_TextureRepeatRotate(nil, xx + p.Rect.X, yy + p.Rect.Y, p.Rect.Width, p.Rect.Height, false, 255, 255, 255, 255, false, p.Rect.Width div 2, p.Rect.Height div 2, ra);
1120 end;
1121 end;
1122 end;
1123 end;
1124 end;
1125 end;
1126 {$ENDIF}
1128 {$IFDEF ENABLE_CORPSES}
1129 procedure r_Map_DrawCorpses (x, y, w, h: Integer);
1130 var i, xx, yy: Integer; p: TCorpse;
1131 begin
1132 if gCorpses <> nil then
1133 begin
1134 for i := 0 to High(gCorpses) do
1135 begin
1136 p := gCorpses[i];
1137 if (p <> nil) and (p.state <> CORPSE_STATE_REMOVEME) and (p.model <> nil) then
1138 begin
1139 r_Common_GetObjectPos(p.obj, xx, yy);
1140 r_Map_DrawPlayerModel(p.model, xx, yy, 255);
1141 end;
1142 end;
1143 end;
1144 end;
1145 {$ENDIF}
1147 {$IFDEF ENABLE_GFX}
1148 function r_Map_GetGFXID (): Integer;
1149 var i: Integer;
1150 begin
1151 i := 0;
1152 if gfxlist <> nil then
1153 begin
1154 while (i < Length(gfxlist)) and (gfxlist[i].typ > 0) do
1155 Inc(i);
1156 if i >= Length(gfxlist) then
1157 SetLength(gfxlist, Length(gfxlist) + 1)
1158 end
1159 else
1160 SetLength(gfxlist, 1);
1161 gfxlist[i].typ := R_GFX_NONE;
1162 result := i
1163 end;
1165 procedure r_Map_NewGFX (typ, x, y: Integer);
1166 var i: Integer;
1167 begin
1168 if gpart_dbg_enabled and (typ > 0) and (typ <= R_GFX_LAST) then
1169 begin
1170 i := r_Map_GetGFXID();
1171 if i >= 0 then
1172 begin
1173 gfxlist[i].typ := typ;
1174 gfxlist[i].x := x;
1175 gfxlist[i].y := y;
1176 gfxlist[i].oldX := x;
1177 gfxlist[i].oldY := y;
1178 gfxlist[i].anim := GFXAnim[typ].anim;
1179 gfxlist[i].time := gTime DIV GAME_TICK;
1180 gfxlist[i].frame := 0;
1181 INC(gfxlist[i].anim.delay, Random(GFXAnim[typ].rdelay));
1182 end;
1183 end;
1184 end;
1186 procedure r_Map_ResetGFX;
1187 begin
1188 SetLength(gfxlist, 0);
1189 end;
1191 procedure r_Map_UpdateGFX (tick: LongWord);
1192 var i: Integer; count: LongInt;
1193 begin
1194 if gfxlist <> nil then
1195 begin
1196 for i := 0 to High(gfxlist) do
1197 begin
1198 if (gfxlist[i].typ > 0) and (tick >= gfxlist[i].time) then
1199 begin
1200 g_Anim_GetFrameByTime(gfxlist[i].anim, tick - gfxlist[i].time, count, gfxlist[i].frame);
1201 if count < 1 then
1202 begin
1203 gfxlist[i].oldX := gfxlist[i].x;
1204 gfxlist[i].oldY := gfxlist[i].y;
1205 case gfxlist[i].typ of
1206 R_GFX_FLAME, R_GFX_SMOKE:
1207 begin
1208 if Random(3) = 0 then
1209 gfxlist[i].x := gfxlist[i].x - 1 + Random(3);
1210 if Random(2) = 0 then
1211 gfxlist[i].y := gfxlist[i].y - Random(2);
1212 end;
1213 end;
1214 end
1215 else
1216 gfxlist[i].typ := R_GFX_NONE;
1217 end;
1218 end;
1219 end;
1220 end;
1222 procedure r_Map_DrawGFX (x, y, w, h: Integer);
1223 var i, fx, fy, typ: Integer; t: TGLMultiTexture; tex: TGLTexture;
1224 begin
1225 if gfxlist <> nil then
1226 begin
1227 for i := 0 to High(gfxlist) do
1228 begin
1229 if gfxlist[i].typ > 0 then
1230 begin
1231 typ := gfxlist[i].typ;
1232 t := GFXTextures[typ];
1233 if t <> nil then
1234 begin
1235 fx := nlerp(gfxlist[i].oldX, gfxlist[i].x, gLerpFactor);
1236 fy := nlerp(gfxlist[i].oldY, gfxlist[i].y, gLerpFactor);
1237 tex := t.GetTexture(gfxlist[i].frame);
1238 r_Draw_TextureRepeat(tex, fx, fy, tex.width, tex.height, false, 255, 255, 255, 255 - GFXAnim[typ].alpha, false);
1239 end;
1240 end;
1241 end;
1242 end;
1243 end;
1245 procedure r_Map_DrawParticles (x, y, w, h: Integer);
1246 var i, fx, fy: Integer; factor: Single;
1247 begin
1248 if gpart_dbg_enabled and (Particles <> nil) then
1249 begin
1250 r_Draw_EnableTexture2D(false);
1251 factor := r_pixel_scale * g_dbg_scale;
1252 if factor < 0.6 then
1253 glPointSize(1)
1254 else if factor > 1.3 then
1255 glPointSize(factor + 1)
1256 else
1257 glPointSize(2);
1258 glDisable(GL_POINT_SMOOTH);
1259 glEnable(GL_BLEND);
1260 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1262 r_Draw_SetColor(255, 255, 255, 255);
1263 glBegin(GL_POINTS);
1264 for i := 0 to High(Particles) do
1265 begin
1266 if Particles[i].alive then
1267 begin
1268 fx := nlerp(Particles[i].oldX, Particles[i].x, gLerpFactor);
1269 fy := nlerp(Particles[i].oldY, Particles[i].y, gLerpFactor);
1270 glColor4ub(Particles[i].red, Particles[i].green, Particles[i].blue, Particles[i].alpha);
1271 glVertex2i(fx, fy);
1272 end;
1273 end;
1274 glEnd;
1275 r_Draw_SetColor(0, 0, 0, 255);
1277 glDisable(GL_BLEND);
1278 end;
1279 end;
1280 {$ENDIF}
1282 procedure r_Map_DrawShots (x, y, w, h: Integer);
1283 var i, a, xx, yy, pX, pY, typ: Integer; count, frame: LongInt; t: TGLMultiTexture; tex: TGLTexture;
1284 begin
1285 if Shots <> nil then
1286 begin
1287 for i := 0 to High(Shots) do
1288 begin
1289 typ := Shots[i].ShotType;
1290 if typ <> 0 then
1291 begin
1292 t := ShotTextures[typ];
1293 if t <> nil then
1294 begin
1295 a := 0;
1296 case typ of
1297 WEAPON_ROCKETLAUNCHER, WEAPON_BARON_FIRE, WEAPON_MANCUB_FIRE, WEAPON_SKEL_FIRE:
1298 a := -GetAngle2(Shots[i].Obj.Vel.X, Shots[i].Obj.Vel.Y)
1299 end;
1300 r_Common_GetObjectPos(Shots[i].Obj, xx, yy);
1301 pX := Shots[i].Obj.Rect.Width div 2;
1302 pY := Shots[i].Obj.Rect.Height div 2;
1303 g_Anim_GetFrameByTime(ShotAnim[typ].anim, (gTime - Shots[i].time) DIV GAME_TICK, count, frame);
1304 tex := t.GetTexture(frame);
1305 r_Draw_TextureRepeatRotate(tex, xx - ShotAnim[typ].x, yy - ShotAnim[typ].y, tex.width, tex.height, false, 255, 255, 255, 255, false, pX, pY, a);
1306 if DebugFrames then
1307 begin
1308 r_Draw_Rect(
1309 xx + Shots[i].obj.rect.x, // Shots[i].obj.x + Shots[i].obj.rect.x,
1310 yy + Shots[i].obj.rect.y, // Shots[i].obj.y + Shots[i].obj.rect.y,
1311 xx + Shots[i].obj.rect.x + Shots[i].obj.rect.width, // Shots[i].obj.x + Shots[i].obj.rect.x + Shots[i].obj.rect.width,
1312 yy + Shots[i].obj.rect.y + Shots[i].obj.rect.height, // Shots[i].obj.y + Shots[i].obj.rect.y + Shots[i].obj.rect.height,
1313 0, 255, 0, 255
1314 );
1315 end;
1316 end;
1317 end;
1318 end;
1319 end;
1320 end;
1322 procedure r_Map_DrawFlags (x, y, w, h: Integer);
1323 var i, dx, xx, yy: Integer; flip: Boolean; t: TGLMultiTexture; tex: TGLTexture;
1324 begin
1325 if gGameSettings.GameMode = GM_CTF then
1326 begin
1327 for i := FLAG_RED to FLAG_BLUE do
1328 begin
1329 if not (gFlags[i].state in [FLAG_STATE_NONE, FLAG_STATE_CAPTURED]) then
1330 begin
1331 r_Common_GetObjectPos(gFlags[i].Obj, xx, yy);
1332 flip := gFlags[i].Direction = TDirection.D_LEFT;
1333 if flip then dx := -1 else dx := +1;
1334 t := FlagTextures[i];
1335 tex := t.GetTexture(FlagFrame);
1336 r_Draw_TextureRepeat(tex, xx + dx, yy + 1, tex.width, tex.height, flip, 255, 255, 255, 255, false);
1337 if DebugFrames then
1338 begin
1339 r_Draw_Rect(
1340 xx + gFlags[i].obj.rect.x, // gFlags[i].obj.x + gFlags[i].obj.rect.x,
1341 yy + gFlags[i].obj.rect.y, // gFlags[i].obj.y + gFlags[i].obj.rect.y,
1342 xx + gFlags[i].obj.rect.x + gFlags[i].obj.rect.width, // gFlags[i].obj.x + gFlags[i].obj.rect.x + gFlags[i].obj.rect.width,
1343 yy + gFlags[i].obj.rect.y + gFlags[i].obj.rect.height, // gFlags[i].obj.y + gFlags[i].obj.rect.y + gFlags[i].obj.rect.height,
1344 0, 255, 0, 255
1345 );
1346 end;
1347 end;
1348 end;
1349 end;
1350 end;
1352 {$IFDEF ENABLE_SHELLS}
1353 procedure r_Map_DrawShells (x, y, w, h: Integer);
1354 var i, xx, yy, typ: Integer; t: TGLTexture; p: PObj;
1355 begin
1356 if gShells <> nil then
1357 begin
1358 for i := 0 to High(gShells) do
1359 begin
1360 if gShells[i].alive then
1361 begin
1362 typ := gShells[i].SType;
1363 if typ <= SHELL_LAST then
1364 begin
1365 p := @gShells[i].Obj;
1366 if g_Obj_Collide(x, y, w, h, p) then
1367 begin
1368 t := ShellTextures[typ];
1369 if t <> nil then
1370 begin
1371 r_Common_GetObjectPos(p^, xx, yy);
1372 r_Draw_TextureRepeatRotate(t, xx, yy, t.width, t.height, false, 255, 255, 255, 255, false, ShellAnim[typ].dx, ShellAnim[typ].dy, gShells[i].RAngle);
1373 end;
1374 end;
1375 end;
1376 end;
1377 end;
1378 end;
1379 end;
1380 {$ENDIF}
1382 procedure r_Map_CalcSkyParallax (cx, cy, vw, vh, sw, sh, mw, mh: LongInt; out x, y, w, h: LongInt);
1383 const
1384 factor = 120; (* size ratio between view and sky (120%) *)
1385 limit = 100; (* max speed for parallax *)
1386 var
1387 msw, msh, mvw, mvh, svw, svh: LongInt;
1388 begin
1389 msw := vw * factor div 100;
1390 msh := vh * factor div 100;
1391 r_Common_CalcAspect(sw, sh, msw, msh, (sw / sh) <= (msw / msh), w, h);
1393 (* calc x parallax or sky center on speed limit *)
1394 mvw := MAX(1, mw - vw);
1395 svw := w - vw;
1396 if 100 * svw div mvw <= limit then
1397 x := -cx * svw div mvw
1398 else
1399 x := -svw div 2;
1401 (* calc y parallax or sky center on speed limit *)
1402 mvh := MAX(1, mh - vh);
1403 svh := h - vh;
1404 if 100 * svh div mvh <= limit then
1405 y := -cy * svh div mvh
1406 else
1407 y := -svh div 2;
1409 (* handle out of map bounds *)
1410 if x > 0 then x := 0;
1411 if y > 0 then y := 0;
1412 if x < -svw then x := -svw;
1413 if y < -svh then y := -svh;
1414 end;
1416 procedure r_Map_DrawScreenEffect (x, y, w, h, level: Integer; r, g, b: Byte);
1417 var i: Integer;
1418 begin
1419 if level > 0 then
1420 begin
1421 case level of
1422 0..14: i := 0;
1423 15..34: i := 1;
1424 35..54: i := 2;
1425 55..74: i := 3;
1426 75..94: i := 4;
1427 else i := 5
1428 end;
1429 r_Draw_FillRect(x, y, x + w, y + h, r, g, b, i * 50)
1430 end;
1431 end;
1433 procedure r_Map_DrawScreenEffects (x, y, w, h: Integer; p: TPlayer);
1434 begin
1435 if p <> nil then
1436 begin
1437 r_Map_DrawScreenEffect(x, y, w, h, p.pain, 255, 0, 0);
1438 r_Map_DrawScreenEffect(x, y, w, h, p.pickup, 150, 200, 150);
1439 if (p.FMegaRulez[MR_INVUL] >= gTime) and (p.SpawnInvul < gTime) then
1440 begin
1441 if ((p.FMegaRulez[MR_INVUL] - gTime) > 2100) or not ODD((p.FMegaRulez[MR_INVUL] - gTime) div 300) then
1442 r_Draw_InvertRect(x, y, x + w, y + h, 191, 191, 191, 255);
1443 end;
1444 if p.FMegaRulez[MR_SUIT] >= gTime then
1445 begin
1446 if ((p.FMegaRulez[MR_SUIT] - gTime) > 2100) or not ODD((p.FMegaRulez[MR_SUIT] - gTime) div 300) then
1447 r_Draw_FillRect(x, y, x + w, y + h, 0, 96, 0, 55);
1448 end;
1449 if (p.Berserk >= 0) and (p.Berserk >= gTime) and (gFlash = 2) then
1450 begin
1451 r_Draw_FillRect(x, y, x + w, y + h, 255, 0, 0, 55);
1452 end;
1453 end;
1454 end;
1456 procedure r_Map_DrawIndicator (p: TPlayer; color: TRGB; cx, cy, cw, ch: Integer);
1457 var a, ax, ay, fx, fy, xx, yy: Integer;
1458 begin
1459 if (p <> nil) and p.Alive and (p.Spectator = false) then
1460 begin
1461 r_Common_GetPlayerPos(p, fx, fy);
1462 case gPlayerIndicatorStyle of
1463 0:
1464 if IndicatorTexture <> nil then
1465 begin
1466 ax := IndicatorTexture.width div 2;
1467 ay := IndicatorTexture.height div 2;
1468 if (p.obj.x + p.obj.rect.x) < cx then
1469 begin
1470 a := 90;
1471 xx := fx + p.obj.rect.x + p.obj.rect.width;
1472 yy := fy + p.obj.rect.y + (p.obj.rect.height - IndicatorTexture.width) div 2;
1473 end
1474 else if (p.obj.x + p.obj.rect.x + p.obj.rect.width) > (cx + cw) then
1475 begin
1476 a := 270;
1477 xx := fx + p.obj.rect.x - IndicatorTexture.height;
1478 yy := fy + p.obj.rect.y - (p.obj.rect.height - IndicatorTexture.width) div 2;
1479 end
1480 else if (p.obj.y - IndicatorTexture.height) < cy then
1481 begin
1482 a := 180;
1483 xx := fx + p.obj.rect.x + (p.obj.rect.width - IndicatorTexture.width) div 2;
1484 yy := fy + p.obj.rect.y + p.obj.rect.height;
1485 end
1486 else
1487 begin
1488 a := 0;
1489 xx := fx + p.obj.rect.x + (p.obj.rect.width - IndicatorTexture.width) div 2;
1490 yy := fy - IndicatorTexture.height;
1491 end;
1492 xx := MIN(MAX(xx, cx), cx + cw - IndicatorTexture.width);
1493 yy := MIN(MAX(yy, cy), cy + ch - IndicatorTexture.height);
1494 r_Draw_TextureRepeatRotate(IndicatorTexture, xx, yy, IndicatorTexture.width, IndicatorTexture.height, false, color.r, color.g, color.b, 255, false, ax, ay, a);
1495 end;
1496 1:
1497 begin
1498 xx := fx + p.obj.rect.x + p.obj.rect.width div 2;
1499 yy := fy;
1500 r_Common_DrawText(p.Name, xx, yy, color.r, color.g, color.b, 255, stdfont, TBasePoint.BP_DOWN);
1501 end;
1502 end;
1503 end;
1504 end;
1506 procedure r_Map_DrawPlayerIndicators (player: TPlayer; cx, cy, cw, ch: Integer);
1507 var i: Integer; p: TPlayer;
1508 begin
1509 case gPlayerIndicator of
1510 1:
1511 if player <> nil then
1512 begin
1513 r_Map_DrawIndicator(player, _RGB(255, 255, 255), cx, cy, cw, ch);
1514 end;
1515 2:
1516 if gPlayers <> nil then
1517 begin
1518 for i := 0 to HIGH(gPlayers) do
1519 begin
1520 p := gPlayers[i];
1521 if p <> nil then
1522 begin
1523 if (player <> nil) and (p = player) then
1524 begin
1525 r_Map_DrawIndicator(p, _RGB(255, 255, 255), cx, cy, cw, ch);
1526 end
1527 else if (player = nil) or ((p.Team = player.Team) and (p.Team <> TEAM_NONE)) then
1528 begin
1529 case gPlayerIndicatorStyle of
1530 0: r_Map_DrawIndicator(p, p.GetColor(), cx, cy, cw, ch);
1531 1: r_Map_DrawIndicator(p, _RGB(192, 192, 192), cx, cy, cw, ch);
1532 end;
1533 end;
1534 end;
1535 end;
1536 end;
1537 end;
1538 end;
1540 function r_Map_GetDrawableGridMask (): Integer;
1541 var mask: Integer;
1542 begin
1543 mask := 0;
1544 if g_rlayer_back then mask := mask or GridTagBack;
1545 if g_rlayer_step then mask := mask or GridTagStep;
1546 if g_rlayer_wall then mask := mask or GridTagWall;
1547 if g_rlayer_door then mask := mask or GridTagDoor;
1548 if g_rlayer_acid1 then mask := mask or GridTagAcid1;
1549 if g_rlayer_acid2 then mask := mask or GridTagAcid2;
1550 if g_rlayer_water then mask := mask or GridTagWater;
1551 if g_rlayer_fore then mask := mask or GridTagFore;
1552 result := mask;
1553 end;
1555 procedure r_Map_DrawGame (xx, yy, ww, hh: Integer; player: TPlayer);
1556 (* xx/yy/ww/hh are in map units *)
1557 var iter: TPanelGrid.Iter; p: PPanel;
1558 begin
1559 if UseAccel then
1560 begin
1561 plist.Clear;
1562 iter := mapGrid.ForEachInAABB(xx, yy, ww, hh, r_Map_GetDrawableGridMask());
1563 for p in iter do
1564 if ((p^.tag and GridTagDoor) <> 0) = p^.door then
1565 plist.Insert(p^);
1566 iter.Release;
1567 end;
1569 r_Map_DrawPanelType(PANEL_BACK);
1570 r_Map_DrawPanelType(PANEL_STEP);
1571 r_Map_DrawItems(xx, yy, ww, hh, false);
1572 r_Map_DrawShots(xx, yy, ww, hh);
1573 {$IFDEF ENABLE_SHELLS}
1574 r_Map_DrawShells(xx, yy, ww, hh);
1575 {$ENDIF}
1576 r_Map_DrawPlayers(xx, yy, ww, hh, player);
1577 {$IFDEF ENABLE_GIBS}
1578 r_Map_DrawGibs(xx, yy, ww, hh);
1579 {$ENDIF}
1580 {$IFDEF ENABLE_CORPSES}
1581 r_Map_DrawCorpses(xx, yy, ww, hh);
1582 {$ENDIF}
1583 r_Map_DrawPanelType(PANEL_WALL);
1584 r_Map_DrawMonsters(xx, yy, ww, hh);
1585 r_Map_DrawItems(xx, yy, ww, hh, true);
1586 r_Map_DrawPanelType(PANEL_CLOSEDOOR);
1587 {$IFDEF ENABLE_GFX}
1588 r_Map_DrawParticles(xx, yy, ww, hh);
1589 r_Map_DrawGFX(xx, yy, ww, hh);
1590 {$ENDIF}
1591 r_Map_DrawFlags(xx, yy, ww, hh);
1592 r_Map_DrawPanelType(PANEL_ACID1);
1593 r_Map_DrawPanelType(PANEL_ACID2);
1594 r_Map_DrawPanelType(PANEL_WATER);
1595 r_Map_DrawPanelType(PANEL_FORE);
1596 end;
1598 procedure r_Map_DrawScaled (w, h, camx, camy: Integer; player: TPlayer; out acx, acy, acw, ach, axx, ayy, aww, ahh: Integer);
1599 (* w/h/camx/camy are in map units (scaled) *)
1600 const limit = 32767;
1601 var cx, cy, cw, ch, xx, yy, ww, hh{, ml, mt, mr, mb}: Integer; sx, sy, sw, sh: LongInt;
1602 begin
1603 (* camera rect *)
1604 cx := camx - w div 2;
1605 cy := camy - h div 2;
1606 cw := w;
1607 ch := h;
1609 (* camera bounds *)
1610 if g_dbg_ignore_bounds = false then
1611 begin
1612 if w > gMapInfo.Width then
1613 cx := gMapInfo.Width div 2 - w div 2
1614 else if cx + cw > gMapInfo.Width then
1615 cx := gMapInfo.Width - cw
1616 else if cx < 0 then
1617 cx := 0;
1619 if h > gMapInfo.Height then
1620 cy := gMapInfo.Height div 2 - h div 2
1621 else if cy + ch > gMapInfo.Height then
1622 cy := gMapInfo.Height - ch
1623 else if cy < 0 then
1624 cy := 0;
1625 end;
1627 acx := cx;
1628 acy := cy;
1629 acw := cw;
1630 ach := ch;
1632 (* map bounds *)
1633 xx := cx;
1634 yy := cy;
1635 ww := cw;
1636 hh := ch;
1637 if xx + ww > gMapInfo.Width then
1638 xx := gMapInfo.Width - ww;
1639 if yy + hh > gMapInfo.Height then
1640 yy := gMapInfo.Height - hh;
1641 if xx < 0 then
1642 xx := 0;
1643 if yy < 0 then
1644 yy := 0;
1645 axx := xx;
1646 ayy := yy;
1647 aww := ww;
1648 ahh := hh;
1651 (* view bounds *)
1652 ml := x; mt := y; mr := x + w; mb := y + h;
1653 if FillOutsizeArea and (DebugCameraScale = 1.0) then
1654 begin
1655 ml := MAX(cx + ml, 0) - cx;
1656 mt := MAX(cy + mt, 0) - cy;
1657 mr := MIN(cx + mr, gMapInfo.Width - 1) - cx;
1658 mb := MIN(cy + mb, gMapInfo.Height - 1) - cy;
1659 end;
1660 r_Draw_SetRect(ml, mt, mr, mb);
1663 if DebugCameraScale <> 1.0 then
1664 begin
1665 glTranslatef(cw div 2, ch div 2, 0);
1666 glScalef(DebugCameraScale, DebugCameraScale, 1);
1667 glTranslatef(-w div 2, -h div 2, 0);
1668 end;
1670 if gDrawBackGround and (SkyTexture <> nil) then
1671 begin
1672 r_Map_CalcSkyParallax(cx, cy, w, h, SkyTexture.width, SkyTexture.height, gMapInfo.Width, gMapInfo.Height, sx, sy, sw, sh);
1673 r_Draw_Texture(SkyTexture, sx, sy, sw, sh, false, 255, 255, 255, 255, false);
1674 end;
1676 glTranslatef(-cx, -cy, 0);
1677 r_Map_DrawGame(xx, yy, ww, hh, player);
1678 if FillOutsizeArea and (DebugCameraScale = 1.0) then
1679 begin
1680 (* top *) r_Draw_FillRect(0 - limit, 0 - limit, gMapInfo.Width + limit, 0, 0, 0, 0, 255);
1681 (* left *) r_Draw_FillRect(0 - limit, 0, 0, gMapInfo.Height + limit, 0, 0, 0, 255);
1682 (* right *) r_Draw_FillRect(gMapInfo.Width, 0, gMapInfo.Width + limit, gMapInfo.Height + limit, 0, 0, 0, 255);
1683 (* bottom *) r_Draw_FillRect(0 - limit, gMapInfo.Height, gMapInfo.Width + limit, gMapInfo.Height + limit, 0, 0, 0, 255);
1684 end;
1685 glTranslatef(cx, cy, 0);
1686 end;
1688 procedure r_Map_Draw (x, y, w, h, camx, camy: Integer; player: TPlayer; out acx, acy: Integer);
1689 var cx, cy, cw, ch, xx, yy, ww, hh, ml, mt, mr, mb, mcx, mcy: Integer; l, t, r, b: Integer;
1690 begin
1691 glPushMatrix;
1692 r_Draw_GetRect(l, t, r, b);
1693 glTranslatef(x, y, 0);
1694 glScalef(g_dbg_scale, g_dbg_scale, 0);
1696 r_Draw_SetRect(x, y, x + w, y + h);
1697 r_Map_DrawScaled(Round(w / g_dbg_scale), Round(h / g_dbg_scale), camx, camy, player, cx, cy, cw, ch, xx, yy, ww, hh);
1698 acx := cx;
1699 acy := cy;
1700 r_Draw_SetRect(x, y, x + w, y + h);
1702 if DebugCameraScale <> 1.0 then
1703 begin
1704 r_Draw_Rect(0, 0, cw, ch, 0, 255, 0, 255);
1705 r_Draw_Rect(-cx + xx, -cy + yy, -cx + xx + ww, -cy + yy + hh, 255, 0, 0, 255);
1706 end;
1708 if gGameSettings.GameMode <> GM_SINGLE then
1709 begin
1710 glTranslatef(-cx, -cy, 0);
1711 r_Map_DrawPlayerIndicators(player, cx, cy, cw, ch);
1712 end;
1714 //glTranslatef(-x, -y, 0);
1715 r_Draw_SetRect(l, t, r, b);
1716 glPopMatrix;
1718 r_Map_DrawScreenEffects(x, y, w, h, player);
1719 end;
1721 procedure r_Map_Reset;
1722 begin
1723 {$IFDEF ENABLE_GFX}
1724 r_Map_ResetGFX;
1725 {$ENDIF}
1726 end;
1728 procedure r_Map_Update;
1729 var i, count, tick: LongInt;
1730 begin
1731 tick := gTime div GAME_TICK;
1732 for i := 0 to ITEM_LAST do
1733 g_Anim_GetFrameByTime(ItemAnim[i].anim, tick, count, Items[i].frame);
1734 r_Map_UpdateGFX(tick);
1735 g_Anim_GetFrameByTime(FlagAnim, tick, count, FlagFrame);
1736 end;
1738 procedure r_Map_GetSpectatorLimits (out x0, y0, x1, y1: Integer);
1739 var w, h: Integer;
1740 begin
1741 w := Round(gScreenWidth / g_dbg_scale);
1742 if gMapInfo.Width > w then
1743 begin
1744 x0 := w div 2;
1745 x1 := gMapInfo.Width - w div 2 - 1;
1746 end
1747 else
1748 begin
1749 x0 := gMapInfo.Width div 2;
1750 x1 := gMapInfo.Width div 2;
1751 end;
1753 h := Round(gScreenHeight / g_dbg_scale);
1754 if gMapInfo.Height > h then
1755 begin
1756 y0 := h div 2;
1757 y1 := gMapInfo.Height - h div 2 - 1;
1758 end
1759 else
1760 begin
1761 y0 := gMapInfo.Height div 2;
1762 y1 := gMapInfo.Height div 2;
1763 end;
1764 end;
1766 initialization
1767 conRegVar('r_sq_draw', @UseAccel, 'accelerated spatial queries in rendering', 'accelerated rendering');
1768 conRegVar('r_debug_camera_scale', @DebugCameraScale, 0.0001, 1000.0, '', '');
1769 conRegVar('r_gl_fill_outside', @FillOutsizeArea, '', '');
1770 conRegVar('d_frames', @DebugFrames, '', '');
1771 conRegVar('d_health', @DebugHealth, '', '');
1772 UseAccel := true;
1773 DebugCameraScale := 1.0;
1774 FillOutsizeArea := true;
1775 DebugFrames := false;
1776 DebugHealth := false;
1777 end.