DEADSOFTWARE

gl: implement texture filtering
[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: 6; y: 7; 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_DrawAim (p: TPlayer);
988 var x0, y0, x1, y1, a, len: Integer;
989 begin
990 ASSERT(p <> nil);
991 r_Common_GetPlayerPos(p, x0, y0);
992 x0 := x0 + WEAPONPOINT[p.Direction].X + IfThen(p.Direction = TDirection.D_LEFT, 7, -7);
993 y0 := y0 + WEAPONPOINT[p.Direction].Y;
994 a := p.Angle_;
995 len := 1024;
996 case p.CurrWeap of
997 WEAPON_KASTET: len := 12;
998 WEAPON_SAW: len := 24;
999 WEAPON_PISTOL, WEAPON_SHOTGUN1, WEAPON_SHOTGUN2, WEAPON_CHAINGUN,
1000 WEAPON_ROCKETLAUNCHER, WEAPON_SUPERPULEMET, WEAPON_FLAMETHROWER:
1001 begin
1002 if a = ANGLE_RIGHTUP then DEC(a, 2);
1003 if a = ANGLE_RIGHTDOWN then INC(a, 4);
1004 if a = ANGLE_LEFTUP then INC(a, 2);
1005 if a = ANGLE_LEFTDOWN then DEC(a, 4);
1006 end;
1007 WEAPON_PLASMA:
1008 begin
1009 if a = ANGLE_RIGHTUP then DEC(a, 1);
1010 if a = ANGLE_RIGHTDOWN then INC(a, 3);
1011 if a = ANGLE_LEFTUP then INC(a, 1);
1012 if a = ANGLE_LEFTDOWN then DEC(a, 3);
1013 end;
1014 WEAPON_BFG:
1015 begin
1016 if a = ANGLE_RIGHTUP then DEC(a, 1);
1017 if a = ANGLE_RIGHTDOWN then INC(a, 2);
1018 if a = ANGLE_LEFTUP then INC(a, 1);
1019 if a = ANGLE_LEFTDOWN then DEC(a, 2);
1020 end;
1021 end;
1022 x1 := x0 + Trunc(Cos(-DegToRad(a)) * len);
1023 y1 := y0 + Trunc(Sin(-DegToRad(a)) * len);
1024 r_Draw_Line(x0, y0, x1, y1, 255, 0, 0, 158);
1025 end;
1027 procedure r_Map_DrawPlayer (p, drawed: TPlayer);
1028 var x, y, ax, ay, w, h: Integer; b, flip: Boolean; t: TGLMultiTexture; tex: TGLTexture; alpha: Byte; count, frame: LongInt;
1029 begin
1030 if p.alive then
1031 begin
1032 r_Common_GetPlayerPos(p, x, y);
1034 (* punch effect *)
1035 if p.PunchTime <= gTime then
1036 begin
1037 g_Anim_GetFrameByTime(PunchAnim, (gTime - p.PunchTime) DIV GAME_TICK, count, frame);
1038 if count < 1 then
1039 begin
1040 b := R_BERSERK in p.FRulez;
1041 if p.FKeys[KEY_DOWN].pressed then
1042 t := PunchTextures[b, 2]
1043 else if p.FKeys[KEY_UP].pressed then
1044 t := PunchTextures[b, 1]
1045 else
1046 t := PunchTextures[b, 0];
1047 if t <> nil then
1048 begin
1049 flip := p.Direction = TDirection.D_LEFT;
1050 ax := IfThen(flip, 15 - p.Obj.Rect.X, p.Obj.Rect.X - 15); // ???
1051 ay := p.Obj.Rect.Y - 11;
1052 tex := t.GetTexture(frame);
1053 r_Draw_TextureRepeat(tex, x + ax, y + ay, tex.width, tex.height, flip, 255, 255, 255, 255, false)
1054 end;
1055 end;
1056 end;
1058 (* invulnerability effect *)
1059 if (InvulPenta <> nil) and (p.FMegaRulez[MR_INVUL] > gTime) and ((p <> drawed) or (p.SpawnInvul >= gTime)) then
1060 begin
1061 w := InvulPenta.width;
1062 h := InvulPenta.height;
1063 ax := p.Obj.Rect.X + (p.Obj.Rect.Width div 2) - (w div 2); // + IfThen(flip, +4, -2) // ???
1064 ay := p.Obj.Rect.Y + (p.Obj.Rect.Height div 2) - (h div 2) - 7; // ???
1065 r_Draw_Texture(InvulPenta, x + ax, y + ay, w, h, false, 255, 255, 255, 255, false);
1066 end;
1068 (* invisibility effect *)
1069 alpha := 255;
1070 if p.FMegaRulez[MR_INVIS] > gTime then
1071 begin
1072 if (drawed <> nil) and ((p = drawed) or ((p.Team = drawed.Team) and (gGameSettings.GameMode <> GM_DM))) then
1073 begin
1074 if (p.FMegaRulez[MR_INVIS] - gTime > 2100) or not ODD((p.FMegaRulez[MR_INVIS] - gTime) div 300) then
1075 alpha := 55;
1076 end
1077 else
1078 alpha := 1; // ???
1079 end;
1081 r_Map_DrawPlayerModel(p.Model, x, y, alpha);
1082 end;
1084 if DebugFrames then
1085 begin
1086 r_Draw_Rect(
1087 x + p.obj.rect.x, // p.obj.x + p.obj.rect.x,
1088 y + p.obj.rect.y, // p.obj.y + p.obj.rect.y,
1089 x + p.obj.rect.x + p.obj.rect.width, // p.obj.x + p.obj.rect.x + p.obj.rect.width,
1090 y + p.obj.rect.y + p.obj.rect.height, // p.obj.y + p.obj.rect.y + p.obj.rect.height,
1091 0, 255, 0, 255
1092 );
1093 end;
1095 if DebugHealth and p.alive then
1096 begin
1097 r_Common_DrawText(
1098 IntToStr(p.health) + '/' + IntToStr(p.armor),
1099 x + p.obj.rect.x + p.obj.rect.width div 2,
1100 y - 24,
1101 255, 255, 255, 255,
1102 stdfont,
1103 TBasePoint.BP_DOWN
1104 );
1105 end;
1107 if (gChatBubble > 0) and p.FKeys[KEY_CHAT].Pressed and (p.Ghost = false) then
1108 if (p.FMegaRulez[MR_INVIS] <= gTime) or ((drawed <> nil) and ((p = drawed) or (p.Team = drawed.Team) and (gGameSettings.GameMode <> GM_DM))) then
1109 r_Map_DrawTalkBubble(p);
1111 if gAimLine and p.alive and ((p = gPlayer1) or (p = gPlayer2)) then
1112 r_Map_DrawAim(p);
1113 end;
1115 procedure r_Map_DrawPlayers (x, y, w, h: Integer; player: TPlayer);
1116 var i: Integer;
1117 begin
1118 if gPlayers <> nil then
1119 for i := 0 to High(gPlayers) do
1120 if gPlayers[i] <> nil then
1121 r_Map_DrawPlayer(gPlayers[i], player);
1122 end;
1124 {$IFDEF ENABLE_GIBS}
1125 function r_Map_GetGibSize (m, i: Integer): TRectWH;
1126 begin
1127 result := Models[m].gibs.rect[i];
1128 end;
1130 procedure r_Map_DrawGibs (x, y, w, h: Integer);
1131 var i, xx, yy, m, id, rx, ry, ra: Integer; p: PObj; t: TGLTexture;
1132 begin
1133 if gGibs <> nil then
1134 begin
1135 (* hack: prevent visual disappearance *)
1136 x := x - MAXGIBW;
1137 y := y - MAXGIBH;
1138 w := w + MAXGIBW*2;
1139 h := h + MAXGIBH*2;
1140 for i := 0 to High(gGibs) do
1141 begin
1142 if gGibs[i].alive then
1143 begin
1144 p := @gGibs[i].Obj;
1145 if g_Obj_Collide(x, y, w, h, p) then
1146 begin
1147 r_Common_GetObjectPos(p^, xx, yy);
1148 id := gGibs[i].GibID;
1149 m := gGibs[i].ModelID;
1150 t := Models[m].gibs.base[id];
1151 if t <> nil then
1152 begin
1153 rx := p.Rect.X + p.Rect.Width div 2;
1154 ry := p.Rect.Y + p.Rect.Height div 2;
1155 ra := gGibs[i].RAngle;
1156 r_Draw_TextureRepeatRotate(t, xx, yy, t.width, t.height, false, 255, 255, 255, 255, false, rx, ry, ra);
1157 t := Models[m].gibs.mask[id];
1158 if t <> nil then
1159 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);
1160 // 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);
1161 end;
1162 end;
1163 end;
1164 end;
1165 end;
1166 end;
1167 {$ENDIF}
1169 {$IFDEF ENABLE_CORPSES}
1170 procedure r_Map_DrawCorpses (x, y, w, h: Integer);
1171 var i, xx, yy: Integer; p: TCorpse;
1172 begin
1173 if gCorpses <> nil then
1174 begin
1175 for i := 0 to High(gCorpses) do
1176 begin
1177 p := gCorpses[i];
1178 if (p <> nil) and (p.state <> CORPSE_STATE_REMOVEME) and (p.model <> nil) then
1179 begin
1180 r_Common_GetObjectPos(p.obj, xx, yy);
1181 r_Map_DrawPlayerModel(p.model, xx, yy, 255);
1182 end;
1183 end;
1184 end;
1185 end;
1186 {$ENDIF}
1188 {$IFDEF ENABLE_GFX}
1189 function r_Map_GetGFXID (): Integer;
1190 var i: Integer;
1191 begin
1192 i := 0;
1193 if gfxlist <> nil then
1194 begin
1195 while (i < Length(gfxlist)) and (gfxlist[i].typ > 0) do
1196 Inc(i);
1197 if i >= Length(gfxlist) then
1198 SetLength(gfxlist, Length(gfxlist) + 1)
1199 end
1200 else
1201 SetLength(gfxlist, 1);
1202 gfxlist[i].typ := R_GFX_NONE;
1203 result := i
1204 end;
1206 procedure r_Map_NewGFX (typ, x, y: Integer);
1207 var i: Integer;
1208 begin
1209 if gpart_dbg_enabled and (typ > 0) and (typ <= R_GFX_LAST) then
1210 begin
1211 i := r_Map_GetGFXID();
1212 if i >= 0 then
1213 begin
1214 gfxlist[i].typ := typ;
1215 gfxlist[i].x := x;
1216 gfxlist[i].y := y;
1217 gfxlist[i].oldX := x;
1218 gfxlist[i].oldY := y;
1219 gfxlist[i].anim := GFXAnim[typ].anim;
1220 gfxlist[i].time := gTime DIV GAME_TICK;
1221 gfxlist[i].frame := 0;
1222 INC(gfxlist[i].anim.delay, Random(GFXAnim[typ].rdelay));
1223 end;
1224 end;
1225 end;
1227 procedure r_Map_ResetGFX;
1228 begin
1229 SetLength(gfxlist, 0);
1230 end;
1232 procedure r_Map_UpdateGFX (tick: LongWord);
1233 var i: Integer; count: LongInt;
1234 begin
1235 if gfxlist <> nil then
1236 begin
1237 for i := 0 to High(gfxlist) do
1238 begin
1239 if (gfxlist[i].typ > 0) and (tick >= gfxlist[i].time) then
1240 begin
1241 g_Anim_GetFrameByTime(gfxlist[i].anim, tick - gfxlist[i].time, count, gfxlist[i].frame);
1242 if count < 1 then
1243 begin
1244 gfxlist[i].oldX := gfxlist[i].x;
1245 gfxlist[i].oldY := gfxlist[i].y;
1246 case gfxlist[i].typ of
1247 R_GFX_FLAME, R_GFX_SMOKE:
1248 begin
1249 if Random(3) = 0 then
1250 gfxlist[i].x := gfxlist[i].x - 1 + Random(3);
1251 if Random(2) = 0 then
1252 gfxlist[i].y := gfxlist[i].y - Random(2);
1253 end;
1254 end;
1255 end
1256 else
1257 gfxlist[i].typ := R_GFX_NONE;
1258 end;
1259 end;
1260 end;
1261 end;
1263 procedure r_Map_DrawGFX (x, y, w, h: Integer);
1264 var i, fx, fy, typ: Integer; t: TGLMultiTexture; tex: TGLTexture;
1265 begin
1266 if gfxlist <> nil then
1267 begin
1268 for i := 0 to High(gfxlist) do
1269 begin
1270 if gfxlist[i].typ > 0 then
1271 begin
1272 typ := gfxlist[i].typ;
1273 t := GFXTextures[typ];
1274 if t <> nil then
1275 begin
1276 fx := nlerp(gfxlist[i].oldX, gfxlist[i].x, gLerpFactor);
1277 fy := nlerp(gfxlist[i].oldY, gfxlist[i].y, gLerpFactor);
1278 tex := t.GetTexture(gfxlist[i].frame);
1279 r_Draw_TextureRepeat(tex, fx, fy, tex.width, tex.height, false, 255, 255, 255, 255 - GFXAnim[typ].alpha, false);
1280 end;
1281 end;
1282 end;
1283 end;
1284 end;
1286 procedure r_Map_DrawParticles (x, y, w, h: Integer);
1287 var i, fx, fy: Integer; factor: Single;
1288 begin
1289 if gpart_dbg_enabled and (Particles <> nil) then
1290 begin
1291 r_Draw_EnableTexture2D(false);
1292 factor := r_pixel_scale * g_dbg_scale;
1293 if factor < 0.6 then
1294 glPointSize(1)
1295 else if factor > 1.3 then
1296 glPointSize(factor + 1)
1297 else
1298 glPointSize(2);
1299 glDisable(GL_POINT_SMOOTH);
1300 glEnable(GL_BLEND);
1301 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1303 r_Draw_SetColor(255, 255, 255, 255);
1304 glBegin(GL_POINTS);
1305 for i := 0 to High(Particles) do
1306 begin
1307 if Particles[i].alive then
1308 begin
1309 fx := nlerp(Particles[i].oldX, Particles[i].x, gLerpFactor);
1310 fy := nlerp(Particles[i].oldY, Particles[i].y, gLerpFactor);
1311 glColor4ub(Particles[i].red, Particles[i].green, Particles[i].blue, Particles[i].alpha);
1312 glVertex2i(fx, fy);
1313 end;
1314 end;
1315 glEnd;
1316 r_Draw_SetColor(0, 0, 0, 255);
1318 glDisable(GL_BLEND);
1319 end;
1320 end;
1321 {$ENDIF}
1323 procedure r_Map_DrawShots (x, y, w, h: Integer);
1324 var i, a, xx, yy, pX, pY, typ: Integer; count, frame: LongInt; t: TGLMultiTexture; tex: TGLTexture;
1325 begin
1326 if Shots <> nil then
1327 begin
1328 for i := 0 to High(Shots) do
1329 begin
1330 typ := Shots[i].ShotType;
1331 if typ <> 0 then
1332 begin
1333 t := ShotTextures[typ];
1334 if t <> nil then
1335 begin
1336 a := 0;
1337 case typ of
1338 WEAPON_ROCKETLAUNCHER, WEAPON_BARON_FIRE, WEAPON_MANCUB_FIRE, WEAPON_SKEL_FIRE:
1339 a := -GetAngle2(Shots[i].Obj.Vel.X, Shots[i].Obj.Vel.Y)
1340 end;
1341 r_Common_GetObjectPos(Shots[i].Obj, xx, yy);
1342 pX := Shots[i].Obj.Rect.Width div 2;
1343 pY := Shots[i].Obj.Rect.Height div 2;
1344 g_Anim_GetFrameByTime(ShotAnim[typ].anim, (gTime - Shots[i].time) DIV GAME_TICK, count, frame);
1345 tex := t.GetTexture(frame);
1346 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);
1347 if DebugFrames then
1348 begin
1349 r_Draw_Rect(
1350 xx + Shots[i].obj.rect.x, // Shots[i].obj.x + Shots[i].obj.rect.x,
1351 yy + Shots[i].obj.rect.y, // Shots[i].obj.y + Shots[i].obj.rect.y,
1352 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,
1353 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,
1354 0, 255, 0, 255
1355 );
1356 end;
1357 end;
1358 end;
1359 end;
1360 end;
1361 end;
1363 procedure r_Map_DrawFlags (x, y, w, h: Integer);
1364 var i, dx, xx, yy: Integer; flip: Boolean; t: TGLMultiTexture; tex: TGLTexture;
1365 begin
1366 if gGameSettings.GameMode = GM_CTF then
1367 begin
1368 for i := FLAG_RED to FLAG_BLUE do
1369 begin
1370 if not (gFlags[i].state in [FLAG_STATE_NONE, FLAG_STATE_CAPTURED]) then
1371 begin
1372 r_Common_GetObjectPos(gFlags[i].Obj, xx, yy);
1373 flip := gFlags[i].Direction = TDirection.D_LEFT;
1374 if flip then dx := -1 else dx := +1;
1375 t := FlagTextures[i];
1376 tex := t.GetTexture(FlagFrame);
1377 r_Draw_TextureRepeat(tex, xx + dx, yy + 1, tex.width, tex.height, flip, 255, 255, 255, 255, false);
1378 if DebugFrames then
1379 begin
1380 r_Draw_Rect(
1381 xx + gFlags[i].obj.rect.x, // gFlags[i].obj.x + gFlags[i].obj.rect.x,
1382 yy + gFlags[i].obj.rect.y, // gFlags[i].obj.y + gFlags[i].obj.rect.y,
1383 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,
1384 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,
1385 0, 255, 0, 255
1386 );
1387 end;
1388 end;
1389 end;
1390 end;
1391 end;
1393 {$IFDEF ENABLE_SHELLS}
1394 procedure r_Map_DrawShells (x, y, w, h: Integer);
1395 var i, xx, yy, typ: Integer; t: TGLTexture; p: PObj;
1396 begin
1397 if gShells <> nil then
1398 begin
1399 for i := 0 to High(gShells) do
1400 begin
1401 if gShells[i].alive then
1402 begin
1403 typ := gShells[i].SType;
1404 if typ <= SHELL_LAST then
1405 begin
1406 p := @gShells[i].Obj;
1407 if g_Obj_Collide(x, y, w, h, p) then
1408 begin
1409 t := ShellTextures[typ];
1410 if t <> nil then
1411 begin
1412 r_Common_GetObjectPos(p^, xx, yy);
1413 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);
1414 end;
1415 end;
1416 end;
1417 end;
1418 end;
1419 end;
1420 end;
1421 {$ENDIF}
1423 procedure r_Map_CalcSkyParallax (cx, cy, vw, vh, sw, sh, mw, mh: LongInt; out x, y, w, h: LongInt);
1424 const
1425 factor = 120; (* size ratio between view and sky (120%) *)
1426 limit = 100; (* max speed for parallax *)
1427 var
1428 msw, msh, mvw, mvh, svw, svh: LongInt;
1429 begin
1430 msw := vw * factor div 100;
1431 msh := vh * factor div 100;
1432 r_Common_CalcAspect(sw, sh, msw, msh, (sw / sh) <= (msw / msh), w, h);
1434 (* calc x parallax or sky center on speed limit *)
1435 mvw := MAX(1, mw - vw);
1436 svw := w - vw;
1437 if 100 * svw div mvw <= limit then
1438 x := -cx * svw div mvw
1439 else
1440 x := -svw div 2;
1442 (* calc y parallax or sky center on speed limit *)
1443 mvh := MAX(1, mh - vh);
1444 svh := h - vh;
1445 if 100 * svh div mvh <= limit then
1446 y := -cy * svh div mvh
1447 else
1448 y := -svh div 2;
1450 (* handle out of map bounds *)
1451 if x > 0 then x := 0;
1452 if y > 0 then y := 0;
1453 if x < -svw then x := -svw;
1454 if y < -svh then y := -svh;
1455 end;
1457 procedure r_Map_DrawScreenEffect (x, y, w, h, level: Integer; r, g, b: Byte);
1458 var i: Integer;
1459 begin
1460 if level > 0 then
1461 begin
1462 case level of
1463 0..14: i := 0;
1464 15..34: i := 1;
1465 35..54: i := 2;
1466 55..74: i := 3;
1467 75..94: i := 4;
1468 else i := 5
1469 end;
1470 r_Draw_FillRect(x, y, x + w, y + h, r, g, b, i * 50)
1471 end;
1472 end;
1474 procedure r_Map_DrawScreenEffects (x, y, w, h: Integer; p: TPlayer);
1475 begin
1476 if p <> nil then
1477 begin
1478 r_Map_DrawScreenEffect(x, y, w, h, p.pain, 255, 0, 0);
1479 r_Map_DrawScreenEffect(x, y, w, h, p.pickup, 150, 200, 150);
1480 if (p.FMegaRulez[MR_INVUL] >= gTime) and (p.SpawnInvul < gTime) then
1481 begin
1482 if ((p.FMegaRulez[MR_INVUL] - gTime) > 2100) or not ODD((p.FMegaRulez[MR_INVUL] - gTime) div 300) then
1483 r_Draw_InvertRect(x, y, x + w, y + h, 191, 191, 191, 255);
1484 end;
1485 if p.FMegaRulez[MR_SUIT] >= gTime then
1486 begin
1487 if ((p.FMegaRulez[MR_SUIT] - gTime) > 2100) or not ODD((p.FMegaRulez[MR_SUIT] - gTime) div 300) then
1488 r_Draw_FillRect(x, y, x + w, y + h, 0, 96, 0, 55);
1489 end;
1490 if (p.Berserk >= 0) and (p.Berserk >= gTime) and (gFlash = 2) then
1491 begin
1492 r_Draw_FillRect(x, y, x + w, y + h, 255, 0, 0, 55);
1493 end;
1494 end;
1495 end;
1497 procedure r_Map_DrawIndicator (p: TPlayer; color: TRGB; cx, cy, cw, ch: Integer);
1498 var a, ax, ay, fx, fy, xx, yy: Integer;
1499 begin
1500 if (p <> nil) and p.Alive and (p.Spectator = false) then
1501 begin
1502 r_Common_GetPlayerPos(p, fx, fy);
1503 case gPlayerIndicatorStyle of
1504 0:
1505 if IndicatorTexture <> nil then
1506 begin
1507 ax := IndicatorTexture.width div 2;
1508 ay := IndicatorTexture.height div 2;
1509 if (p.obj.x + p.obj.rect.x) < cx then
1510 begin
1511 a := 90;
1512 xx := fx + p.obj.rect.x + p.obj.rect.width;
1513 yy := fy + p.obj.rect.y + (p.obj.rect.height - IndicatorTexture.width) div 2;
1514 end
1515 else if (p.obj.x + p.obj.rect.x + p.obj.rect.width) > (cx + cw) then
1516 begin
1517 a := 270;
1518 xx := fx + p.obj.rect.x - IndicatorTexture.height;
1519 yy := fy + p.obj.rect.y - (p.obj.rect.height - IndicatorTexture.width) div 2;
1520 end
1521 else if (p.obj.y - IndicatorTexture.height) < cy then
1522 begin
1523 a := 180;
1524 xx := fx + p.obj.rect.x + (p.obj.rect.width - IndicatorTexture.width) div 2;
1525 yy := fy + p.obj.rect.y + p.obj.rect.height;
1526 end
1527 else
1528 begin
1529 a := 0;
1530 xx := fx + p.obj.rect.x + (p.obj.rect.width - IndicatorTexture.width) div 2;
1531 yy := fy - IndicatorTexture.height;
1532 end;
1533 xx := MIN(MAX(xx, cx), cx + cw - IndicatorTexture.width);
1534 yy := MIN(MAX(yy, cy), cy + ch - IndicatorTexture.height);
1535 r_Draw_TextureRepeatRotate(IndicatorTexture, xx, yy, IndicatorTexture.width, IndicatorTexture.height, false, color.r, color.g, color.b, 255, false, ax, ay, a);
1536 end;
1537 1:
1538 begin
1539 xx := fx + p.obj.rect.x + p.obj.rect.width div 2;
1540 yy := fy;
1541 r_Common_DrawText(p.Name, xx, yy, color.r, color.g, color.b, 255, stdfont, TBasePoint.BP_DOWN);
1542 end;
1543 end;
1544 end;
1545 end;
1547 procedure r_Map_DrawPlayerIndicators (player: TPlayer; cx, cy, cw, ch: Integer);
1548 var i: Integer; p: TPlayer;
1549 begin
1550 case gPlayerIndicator of
1551 1:
1552 if player <> nil then
1553 begin
1554 r_Map_DrawIndicator(player, _RGB(255, 255, 255), cx, cy, cw, ch);
1555 end;
1556 2:
1557 if gPlayers <> nil then
1558 begin
1559 for i := 0 to HIGH(gPlayers) do
1560 begin
1561 p := gPlayers[i];
1562 if p <> nil then
1563 begin
1564 if (player <> nil) and (p = player) then
1565 begin
1566 r_Map_DrawIndicator(p, _RGB(255, 255, 255), cx, cy, cw, ch);
1567 end
1568 else if (player = nil) or ((p.Team = player.Team) and (p.Team <> TEAM_NONE)) then
1569 begin
1570 case gPlayerIndicatorStyle of
1571 0: r_Map_DrawIndicator(p, p.GetColor(), cx, cy, cw, ch);
1572 1: r_Map_DrawIndicator(p, _RGB(192, 192, 192), cx, cy, cw, ch);
1573 end;
1574 end;
1575 end;
1576 end;
1577 end;
1578 end;
1579 end;
1581 function r_Map_GetDrawableGridMask (): Integer;
1582 var mask: Integer;
1583 begin
1584 mask := 0;
1585 if g_rlayer_back then mask := mask or GridTagBack;
1586 if g_rlayer_step then mask := mask or GridTagStep;
1587 if g_rlayer_wall then mask := mask or GridTagWall;
1588 if g_rlayer_door then mask := mask or GridTagDoor;
1589 if g_rlayer_acid1 then mask := mask or GridTagAcid1;
1590 if g_rlayer_acid2 then mask := mask or GridTagAcid2;
1591 if g_rlayer_water then mask := mask or GridTagWater;
1592 if g_rlayer_fore then mask := mask or GridTagFore;
1593 result := mask;
1594 end;
1596 procedure r_Map_DrawGame (xx, yy, ww, hh: Integer; player: TPlayer);
1597 (* xx/yy/ww/hh are in map units *)
1598 var iter: TPanelGrid.Iter; p: PPanel;
1599 begin
1600 if UseAccel then
1601 begin
1602 plist.Clear;
1603 iter := mapGrid.ForEachInAABB(xx, yy, ww, hh, r_Map_GetDrawableGridMask());
1604 for p in iter do
1605 if ((p^.tag and GridTagDoor) <> 0) = p^.door then
1606 plist.Insert(p^);
1607 iter.Release;
1608 end;
1610 r_Map_DrawPanelType(PANEL_BACK);
1611 r_Map_DrawPanelType(PANEL_STEP);
1612 r_Map_DrawItems(xx, yy, ww, hh, false);
1613 r_Map_DrawShots(xx, yy, ww, hh);
1614 {$IFDEF ENABLE_SHELLS}
1615 r_Map_DrawShells(xx, yy, ww, hh);
1616 {$ENDIF}
1617 r_Map_DrawPlayers(xx, yy, ww, hh, player);
1618 {$IFDEF ENABLE_GIBS}
1619 r_Map_DrawGibs(xx, yy, ww, hh);
1620 {$ENDIF}
1621 {$IFDEF ENABLE_CORPSES}
1622 r_Map_DrawCorpses(xx, yy, ww, hh);
1623 {$ENDIF}
1624 r_Map_DrawPanelType(PANEL_WALL);
1625 r_Map_DrawMonsters(xx, yy, ww, hh);
1626 r_Map_DrawItems(xx, yy, ww, hh, true);
1627 r_Map_DrawPanelType(PANEL_CLOSEDOOR);
1628 {$IFDEF ENABLE_GFX}
1629 r_Map_DrawParticles(xx, yy, ww, hh);
1630 r_Map_DrawGFX(xx, yy, ww, hh);
1631 {$ENDIF}
1632 r_Map_DrawFlags(xx, yy, ww, hh);
1633 r_Map_DrawPanelType(PANEL_ACID1);
1634 r_Map_DrawPanelType(PANEL_ACID2);
1635 r_Map_DrawPanelType(PANEL_WATER);
1636 r_Map_DrawPanelType(PANEL_FORE);
1637 end;
1639 procedure r_Map_DrawScaled (w, h, camx, camy: Integer; player: TPlayer; out acx, acy, acw, ach, axx, ayy, aww, ahh: Integer);
1640 (* w/h/camx/camy are in map units (scaled) *)
1641 const limit = 32767;
1642 var cx, cy, cw, ch, xx, yy, ww, hh{, ml, mt, mr, mb}: Integer; sx, sy, sw, sh: LongInt;
1643 begin
1644 (* camera rect *)
1645 cx := camx - w div 2;
1646 cy := camy - h div 2;
1647 cw := w;
1648 ch := h;
1650 (* camera bounds *)
1651 if g_dbg_ignore_bounds = false then
1652 begin
1653 if w > gMapInfo.Width then
1654 cx := gMapInfo.Width div 2 - w div 2
1655 else if cx + cw > gMapInfo.Width then
1656 cx := gMapInfo.Width - cw
1657 else if cx < 0 then
1658 cx := 0;
1660 if h > gMapInfo.Height then
1661 cy := gMapInfo.Height div 2 - h div 2
1662 else if cy + ch > gMapInfo.Height then
1663 cy := gMapInfo.Height - ch
1664 else if cy < 0 then
1665 cy := 0;
1666 end;
1668 acx := cx;
1669 acy := cy;
1670 acw := cw;
1671 ach := ch;
1673 (* map bounds *)
1674 xx := cx;
1675 yy := cy;
1676 ww := cw;
1677 hh := ch;
1678 if xx + ww > gMapInfo.Width then
1679 xx := gMapInfo.Width - ww;
1680 if yy + hh > gMapInfo.Height then
1681 yy := gMapInfo.Height - hh;
1682 if xx < 0 then
1683 xx := 0;
1684 if yy < 0 then
1685 yy := 0;
1686 axx := xx;
1687 ayy := yy;
1688 aww := ww;
1689 ahh := hh;
1692 (* view bounds *)
1693 ml := x; mt := y; mr := x + w; mb := y + h;
1694 if FillOutsizeArea and (DebugCameraScale = 1.0) then
1695 begin
1696 ml := MAX(cx + ml, 0) - cx;
1697 mt := MAX(cy + mt, 0) - cy;
1698 mr := MIN(cx + mr, gMapInfo.Width - 1) - cx;
1699 mb := MIN(cy + mb, gMapInfo.Height - 1) - cy;
1700 end;
1701 r_Draw_SetRect(ml, mt, mr, mb);
1704 if DebugCameraScale <> 1.0 then
1705 begin
1706 glTranslatef(cw div 2, ch div 2, 0);
1707 glScalef(DebugCameraScale, DebugCameraScale, 1);
1708 glTranslatef(-w div 2, -h div 2, 0);
1709 end;
1711 if gDrawBackGround and (SkyTexture <> nil) then
1712 begin
1713 r_Map_CalcSkyParallax(cx, cy, w, h, SkyTexture.width, SkyTexture.height, gMapInfo.Width, gMapInfo.Height, sx, sy, sw, sh);
1714 r_Draw_SetFilter(SkyTexture, gTextureFilter);
1715 r_Draw_Texture(SkyTexture, sx, sy, sw, sh, false, 255, 255, 255, 255, false);
1716 end;
1718 glTranslatef(-cx, -cy, 0);
1719 r_Map_DrawGame(xx, yy, ww, hh, player);
1720 if FillOutsizeArea and (DebugCameraScale = 1.0) then
1721 begin
1722 (* top *) r_Draw_FillRect(0 - limit, 0 - limit, gMapInfo.Width + limit, 0, 0, 0, 0, 255);
1723 (* left *) r_Draw_FillRect(0 - limit, 0, 0, gMapInfo.Height + limit, 0, 0, 0, 255);
1724 (* right *) r_Draw_FillRect(gMapInfo.Width, 0, gMapInfo.Width + limit, gMapInfo.Height + limit, 0, 0, 0, 255);
1725 (* bottom *) r_Draw_FillRect(0 - limit, gMapInfo.Height, gMapInfo.Width + limit, gMapInfo.Height + limit, 0, 0, 0, 255);
1726 end;
1727 glTranslatef(cx, cy, 0);
1728 end;
1730 procedure r_Map_Draw (x, y, w, h, camx, camy: Integer; player: TPlayer; out acx, acy: Integer);
1731 var cx, cy, cw, ch, xx, yy, ww, hh, ml, mt, mr, mb, mcx, mcy: Integer; l, t, r, b: Integer;
1732 begin
1733 glPushMatrix;
1734 r_Draw_GetRect(l, t, r, b);
1735 glTranslatef(x, y, 0);
1736 glScalef(g_dbg_scale, g_dbg_scale, 0);
1738 r_Draw_SetRect(x, y, x + w, y + h);
1739 r_Map_DrawScaled(Round(w / g_dbg_scale), Round(h / g_dbg_scale), camx, camy, player, cx, cy, cw, ch, xx, yy, ww, hh);
1740 acx := cx;
1741 acy := cy;
1742 r_Draw_SetRect(x, y, x + w, y + h);
1744 if DebugCameraScale <> 1.0 then
1745 begin
1746 r_Draw_Rect(0, 0, cw, ch, 0, 255, 0, 255);
1747 r_Draw_Rect(-cx + xx, -cy + yy, -cx + xx + ww, -cy + yy + hh, 255, 0, 0, 255);
1748 end;
1750 if gGameSettings.GameMode <> GM_SINGLE then
1751 begin
1752 glTranslatef(-cx, -cy, 0);
1753 r_Map_DrawPlayerIndicators(player, cx, cy, cw, ch);
1754 end;
1756 //glTranslatef(-x, -y, 0);
1757 r_Draw_SetRect(l, t, r, b);
1758 glPopMatrix;
1760 r_Map_DrawScreenEffects(x, y, w, h, player);
1761 end;
1763 procedure r_Map_Reset;
1764 begin
1765 {$IFDEF ENABLE_GFX}
1766 r_Map_ResetGFX;
1767 {$ENDIF}
1768 end;
1770 procedure r_Map_Update;
1771 var i, count, tick: LongInt;
1772 begin
1773 tick := gTime div GAME_TICK;
1774 for i := 0 to ITEM_LAST do
1775 g_Anim_GetFrameByTime(ItemAnim[i].anim, tick, count, Items[i].frame);
1776 r_Map_UpdateGFX(tick);
1777 g_Anim_GetFrameByTime(FlagAnim, tick, count, FlagFrame);
1778 end;
1780 procedure r_Map_GetSpectatorLimits (out x0, y0, x1, y1: Integer);
1781 var w, h: Integer;
1782 begin
1783 w := Round(gScreenWidth / g_dbg_scale);
1784 if gMapInfo.Width > w then
1785 begin
1786 x0 := w div 2;
1787 x1 := gMapInfo.Width - w div 2 - 1;
1788 end
1789 else
1790 begin
1791 x0 := gMapInfo.Width div 2;
1792 x1 := gMapInfo.Width div 2;
1793 end;
1795 h := Round(gScreenHeight / g_dbg_scale);
1796 if gMapInfo.Height > h then
1797 begin
1798 y0 := h div 2;
1799 y1 := gMapInfo.Height - h div 2 - 1;
1800 end
1801 else
1802 begin
1803 y0 := gMapInfo.Height div 2;
1804 y1 := gMapInfo.Height div 2;
1805 end;
1806 end;
1808 initialization
1809 conRegVar('r_sq_draw', @UseAccel, 'accelerated spatial queries in rendering', 'accelerated rendering');
1810 conRegVar('r_debug_camera_scale', @DebugCameraScale, 0.0001, 1000.0, '', '');
1811 conRegVar('r_gl_fill_outside', @FillOutsizeArea, '', '');
1812 conRegVar('d_frames', @DebugFrames, '', '');
1813 conRegVar('d_health', @DebugHealth, '', '');
1814 UseAccel := true;
1815 DebugCameraScale := 1.0;
1816 FillOutsizeArea := true;
1817 DebugFrames := false;
1818 DebugHealth := false;
1819 end.