DEADSOFTWARE

0b67e2d0b1561f92ed89ef24fb9b63ac7cca6944
[d2df-sdl.git] / src / game / renders / opengl / r_render.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_render;
18 interface
20 uses
21 {$IFDEF ENABLE_MENU}
22 g_gui,
23 {$ENDIF}
24 g_base // TRectWH
25 ;
27 (* render startup *)
28 procedure r_Render_Initialize;
29 procedure r_Render_Finalize;
31 (* load globally used textures *)
32 procedure r_Render_Load;
33 procedure r_Render_Free;
35 (* load map specific textures *)
36 procedure r_Render_LoadTextures;
37 procedure r_Render_FreeTextures;
39 procedure r_Render_Update;
40 procedure r_Render_Draw;
42 procedure r_Render_Resize (w, h: Integer);
43 procedure r_Render_Apply;
45 function r_Render_WriteScreenShot (filename: String): Boolean;
47 {$IFDEF ENABLE_GIBS}
48 function r_Render_GetGibRect (m, id: Integer): TRectWH;
49 {$ENDIF}
51 {$IFDEF ENABLE_GFX}
52 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
53 {$ENDIF}
55 {$IFDEF ENABLE_TOUCH}
56 // touch screen button location and size
57 procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
58 {$ENDIF}
60 {$IFDEF ENABLE_MENU}
61 procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
62 procedure r_Render_GetLogoSize (out w, h: Integer);
63 procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
64 procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
65 {$ENDIF}
67 procedure r_Render_DrawLoading (force: Boolean); // !!! remove it
69 implementation
71 uses
72 {$IFDEF USE_GLES1}
73 GLES11,
74 {$ELSE}
75 GL, GLEXT,
76 {$ENDIF}
77 {$IFDEF ENABLE_MENU}
78 r_gui,
79 {$ENDIF}
80 {$IFDEF ENABLE_SYSTEM}
81 g_system,
82 {$ENDIF}
83 SysUtils, Classes, Math,
84 g_basic,
85 e_log, utils, wadreader, mapdef,
86 g_game, g_map, g_panel, g_options, g_console, g_player, g_weapons, g_language, g_triggers, g_monsters,
87 g_net, g_netmaster,
88 r_draw, r_textures, r_fonts, r_common, r_console, r_map
89 ;
91 var
92 BackgroundTexture: THereTexture;
94 hud, hudbg: TGLTexture;
95 hudhp: array [Boolean] of TGLTexture;
96 hudap: TGLTexture;
97 hudwp: array [0..WP_LAST] of TGLTexture;
98 hudkey: array [0..2] of TGLTexture;
99 hudair: TGLTexture;
100 hudjet: TGLTexture;
101 hudrflag, hudrflags, hudrflagd: TGLTexture;
102 hudbflag, hudbflags, hudbflagd: TGLTexture;
104 procedure r_Render_LoadTextures;
105 begin
106 r_Map_LoadTextures;
107 end;
109 procedure r_Render_FreeTextures;
110 begin
111 r_Map_FreeTextures;
112 end;
114 procedure r_Render_Load;
115 const
116 WeapName: array [0..WP_LAST] of AnsiString = ('KASTET', 'SAW', 'PISTOL', 'SHOTGUN1', 'SHOTGUN2', 'MGUN', 'RLAUNCHER', 'PGUN', 'BFG', 'SPULEMET', 'FLAMETHROWER');
117 var
118 i: Integer;
119 begin
120 r_Common_Load;
121 BackgroundTexture := DEFAULT(THereTexture);
122 hud := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/HUD');
123 hudbg := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/HUDBG');
124 hudhp[false] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/MED2');
125 hudhp[true] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/BMED');
126 hudap := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/ARMORHUD');
127 for i := 0 to WP_LAST do
128 hudwp[i] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/' + WeapName[i]);
129 hudkey[0] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYR');
130 hudkey[1] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYG');
131 hudkey[2] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYB');
132 hudair := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/AIRBAR');
133 hudjet := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/JETBAR');
134 hudrflag := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_BASE');
135 hudrflags := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_STOLEN');
136 hudrflagd := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_DROP');
137 hudbflag := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_BASE');
138 hudbflags := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_STOLEN');
139 hudbflagd := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_DROP');
140 r_Console_Load;
141 r_Map_Load;
142 {$IFDEF ENABLE_MENU}
143 r_GUI_Load;
144 {$ENDIF}
145 end;
147 procedure r_Render_Free;
148 var i: Integer;
149 begin
150 {$IFDEF ENABLE_MENU}
151 r_GUI_Free;
152 {$ENDIF}
153 r_Map_Free;
154 r_Console_Free;
155 hudbflagd.Free;
156 hudbflags.Free;
157 hudbflag.Free;
158 hudrflagd.Free;
159 hudrflags.Free;
160 hudrflag.Free;
161 hudjet.Free;
162 hudair.Free;
163 hudkey[0].Free;
164 hudkey[1].Free;
165 hudkey[2].Free;
166 for i := 0 to WP_LAST do
167 begin
168 if hudwp[i] <> nil then
169 hudwp[i].Free;
170 hudwp[i] := nil;
171 end;
172 hudap.Free;
173 hudhp[true].Free;
174 hudhp[false].Free;
175 hudbg.Free;
176 hud.Free;
177 r_Common_FreeThis(BackgroundTexture);
178 r_Common_Free;
179 end;
181 {$IFDEF ENABLE_SYSTEM}
182 function GetInfo (): TGLDisplayInfo;
183 var info: TGLDisplayInfo;
184 begin
185 info := Default(TGLDisplayInfo);
186 info.w := Max(1, gRC_Width);
187 info.h := Max(1, gRC_Height);
188 info.bpp := Max(1, gBPP);
189 info.fullscreen := gRC_FullScreen;
190 info.maximized := gRC_Maximized;
191 info.major := 1;
192 info.minor := 1;
193 info.profile := TGLProfile.Compat;
194 result := info;
195 end;
196 {$ENDIF}
198 procedure r_Render_Initialize;
199 begin
200 {$IFDEF ENABLE_SYSTEM}
201 if sys_SetDisplayModeGL(GetInfo()) = False then
202 raise Exception.Create('Failed to set videomode on startup.');
203 sys_EnableVSync(gVSync);
204 {$ENDIF}
205 r_Textures_Initialize;
206 r_Console_Initialize;
207 r_Map_Initialize;
208 end;
210 procedure r_Render_Finalize;
211 begin
212 r_Map_Finalize;
213 r_Console_Finalize;
214 r_Textures_Finalize;
215 end;
217 procedure r_Render_Update;
218 begin
219 r_Console_Update;
220 r_Map_Update;
221 end;
223 procedure r_Render_DrawHUD (x, y: Integer; p: TPlayer);
224 var t: TGLTexture; s: AnsiString;
225 begin
226 ASSERT(p <> nil);
228 // hud area is 196 x 240 pixels
229 r_Common_DrawTexture(hud, x, y, hud.width, hud.height, TBasePoint.BP_LEFTUP);
230 r_Common_DrawText(p.name, x + 98, y + 16, 255, 0, 0, 255, smallfont, TBasePoint.BP_CENTER);
232 t := hudhp[R_BERSERK in p.FRulez];
233 r_Common_DrawTexture(t, x + 51, y + 61, t.width, t.height, TBasePoint.BP_CENTER);
234 r_Common_DrawTexture(hudap, x + 50, y + 85, hudap.width, hudap.height, TBasePoint.BP_CENTER);
236 r_Common_DrawText(IntToStr(MAX(0, p.health)), x + 174, y + 56, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
237 r_Common_DrawText(IntToStr(MAX(0, p.armor)), x + 174, y + 84, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
239 case p.CurrWeap of
240 WEAPON_KASTET, WEAPON_SAW: s := '--';
241 else s := IntToStr(p.GetAmmoByWeapon(p.CurrWeap));
242 end;
243 r_Common_DrawText(s, x + 174, y + 174, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
245 if p.CurrWeap <= WP_LAST then
246 begin
247 t := hudwp[p.CurrWeap];
248 r_Common_DrawTexture(t, x + 18, y + 160, t.width, t.height, TBasePoint.BP_LEFTUP);
249 end;
251 if R_KEY_RED in p.FRulez then
252 r_Common_DrawTexture(hudkey[0], x + 76, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
253 if R_KEY_GREEN in p.FRulez then
254 r_Common_DrawTexture(hudkey[1], x + 93, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
255 if R_KEY_BLUE in p.FRulez then
256 r_Common_DrawTexture(hudkey[2], x + 110, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
258 if p.JetFuel > 0 then
259 begin
260 r_Common_DrawTexture(hudair, x, y + 116, hudair.width, hudair.height, TBasePoint.BP_LEFTUP);
261 if p.air > 0 then
262 r_Draw_FillRect(x + 14, y + 116 + 4, x + 14 + 168 * p.air div AIR_MAX, y + 116 + 4 + 4, 0, 0, 196, 255);
263 r_Common_DrawTexture(hudjet, x, y + 126, hudjet.width, hudjet.height, TBasePoint.BP_LEFTUP);
264 r_Draw_FillRect(x + 14, y + 126 + 4, x + 14 + 168 * p.JetFuel div JET_MAX, y + 126 + 4 + 4, 208, 0, 0, 255);
265 end
266 else
267 begin
268 r_Common_DrawTexture(hudair, x, y + 124, hudair.width, hudair.height, TBasePoint.BP_LEFTUP);
269 if p.air > 0 then
270 r_Draw_FillRect(x + 14, y + 124 + 4, x + 14 + 168 * p.air div AIR_MAX, y + 124 + 4 + 4, 0, 0, 196, 255);
271 end;
272 end;
274 procedure r_Render_DrawHUDArea (x, y, w, h: Integer; p: TPlayer);
275 var s: AnsiString;
276 begin
277 r_Common_DrawTexture(hudbg, x, y, w, h, TBasePoint.BP_LEFTUP);
279 if p <> nil then
280 begin
281 r_Render_DrawHUD(x + w - 196 + 2, y, p);
282 if p.Spectator then
283 begin
284 r_Common_DrawText(_lc[I_PLAYER_SPECT], x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
285 r_Common_DrawText(_lc[I_PLAYER_SPECT2], x + 4, y + 258, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
286 r_Common_DrawText(_lc[I_PLAYER_SPECT1], x + 4, y + 274, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
287 if p.NoRespawn then
288 r_Common_DrawText(_lc[I_PLAYER_SPECT1S], x + 4, y + 290, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
289 end;
290 end;
292 if gShowPing and g_Game_IsClient then
293 begin
294 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
295 r_Common_DrawText(s, x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
296 end;
297 end;
299 procedure r_Render_DrawStatsView (x, y, w, h: Integer; p: TPlayer);
300 var fw, i, maxFrags, top, totalPlayers: Integer; sign: Char; stat: TPlayerStatArray; f: TGLTexture;
301 begin
302 ASSERT(p <> nil);
304 if gShowScore and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
305 begin
306 (* RED TEAM GOALS *)
307 fw := 0;
308 if gGameSettings.GameMode = GM_CTF then
309 begin
310 case gFlags[FLAG_RED].State of
311 FLAG_STATE_CAPTURED: f := hudrflags;
312 FLAG_STATE_DROPPED: f := hudrflagd;
313 otherwise f := hudrflag;
314 end;
315 if f <> nil then
316 begin
317 fw := f.width + 8; (* + space *)
318 r_Common_DrawTexture(f, x + w - 16, y + 240 - 72 - 4, f.width, f.height, TBasePoint.BP_RIGHTUP);
319 end;
320 end;
321 r_Common_DrawText(IntToStr(gTeamStat[TEAM_RED].Score), x + w - 16 - fw, y + 240 - 72 - 4, TEAMCOLOR[TEAM_RED].R, TEAMCOLOR[TEAM_RED].G, TEAMCOLOR[TEAM_RED].B, 255, menufont, TBasePoint.BP_RIGHTUP);
323 (* BLUE TEAM GOALS *)
324 fw := 0;
325 if gGameSettings.GameMode = GM_CTF then
326 begin
327 case gFlags[FLAG_BLUE].State of
328 FLAG_STATE_CAPTURED: f := hudbflags;
329 FLAG_STATE_DROPPED: f := hudbflagd;
330 otherwise f := hudbflag;
331 end;
332 if f <> nil then
333 begin
334 fw := f.width + 8; (* + space *)
335 r_Common_DrawTexture(f, x + w - 16, y + 240 - 32 - 4, f.width, f.height, TBasePoint.BP_RIGHTUP);
336 end;
337 end;
338 r_Common_DrawText(IntToStr(gTeamStat[TEAM_BLUE].Score), x + w - 16 - fw, y + 240 - 32 - 4, TEAMCOLOR[TEAM_BLUE].R, TEAMCOLOR[TEAM_BLUE].G, TEAMCOLOR[TEAM_BLUE].B, 255, menufont, TBasePoint.BP_RIGHTUP);
339 end;
341 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
342 begin
343 if gShowStat then
344 begin
345 r_Common_DrawText(IntToStr(p.Frags), x + w - 16, y, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHTUP);
347 top := 1;
348 maxFrags := 0;
349 totalPlayers := 0;
350 stat := g_Player_GetStats();
351 if stat <> nil then
352 begin
353 totalPlayers := Length(stat);
354 for i := 0 to High(stat) do
355 begin
356 if stat[i].Name <> p.Name then
357 begin
358 maxFrags := MAX(maxFrags, stat[i].Frags);
359 if stat[i].Frags > p.Frags then
360 top := top + 1;
361 end;
362 end;
363 end;
364 if p.Frags >= maxFrags then sign := '+' else sign := '-';
365 r_Common_DrawText(IntToStr(top) + ' / ' + IntToStr(totalPlayers) + ' ' + sign + IntToStr(ABS(p.Frags - maxFrags)), x + w - 16, y + 32, 255, 0, 0, 255, smallfont, TBasePoint.BP_RIGHTUP);
366 end;
368 if gLMSRespawn > LMS_RESPAWN_NONE then
369 begin
370 r_Common_DrawText(_lc[I_GAME_WARMUP], x + w - 16 - 64, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_RIGHTDOWN);
371 r_Common_DrawText(': ' + IntToStr((gLMSRespawnTime - gTime) div 1000), x + w - 16 - 64, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_LEFTDOWN);
372 end
373 else if gShowLives and (gGameSettings.MaxLives > 0) then
374 begin
375 r_Common_DrawText(IntToStr(p.Lives), x + w - 16, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_RIGHTDOWN);
376 end;
377 end;
378 end;
380 procedure r_Render_DrawView (x, y, w, h: Integer; p: TPlayer);
381 var l, t, r, b, xx, yy: Integer;
382 begin
383 r_Draw_GetRect(l, t, r, b);
384 r_Draw_SetRect(x, y, x + w, y + h);
386 r_Common_GetCameraPos(p, true, xx, yy);
387 if p <> nil then
388 begin
389 r_Map_Draw(x, y, w, h, xx, yy, p);
390 r_Render_DrawStatsView(x, y, w, h, p);
391 if p.Spectator and p.NoRespawn then
392 r_Common_DrawText(_lc[I_PLAYER_SPECT4], x div 2 + w div 2, y div 2 + h div 2, 255, 255, 255, 255, stdfont, TBasePoint.BP_CENTER);
393 end
394 else
395 begin
396 r_Map_Draw(x, y, w, h, xx, yy, nil);
397 end;
399 r_Draw_SetRect(l, t, r, b);
400 end;
402 procedure r_Render_DrawMapView (x, y, w, h, camx, camy: Integer);
403 var l, t, r, b: Integer;
404 begin
405 r_Draw_GetRect(l, t, r, b);
406 r_Draw_SetRect(x, y, x + w, y + h);
407 r_Map_Draw(x, y, w, h, camx, camy, nil);
408 r_Draw_SetRect(l, t, r, b);
409 end;
411 procedure r_Render_DrawPlayerView (x, y, w, h: Integer; p: TPlayer);
412 var l, t, r, b: Integer;
413 begin
414 r_Draw_GetRect(l, t, r, b);
415 r_Draw_SetRect(x, y, x + w, y + h);
416 r_Render_DrawView(x, y, w - 196, h, p);
417 r_Render_DrawHUDArea(x + w - 196, y, 196, h, p);
418 r_Draw_SetRect(l, t, r, b);
419 end;
421 procedure r_Render_DrawBackgroundImage (img: TGLTexture);
422 var fw, w, h: LongInt;
423 begin
424 if img <> nil then
425 begin
426 img := BackgroundTexture.id;
427 if img.width = img.height then fw := img.width * 4 div 3 else fw := img.width; // fix aspect 4:3
428 r_Common_CalcAspect(fw, img.height, gScreenWidth, gScreenHeight, false, w, h);
429 r_Draw_Texture(img, gScreenWidth div 2 - w div 2, 0, w, h, false, 255, 255, 255, 255, false);
430 end
431 end;
433 procedure r_Render_DrawBackground (const name: AnsiString);
434 begin
435 if r_Common_LoadThis(name, BackgroundTexture) then
436 r_Render_DrawBackgroundImage(BackgroundTexture.id)
437 end;
439 procedure r_Render_DrawServerList (var SL: TNetServerList; var ST: TNetServerTable);
440 var ip: AnsiString; ww, hh, cw, ch, mw, mh, motdh, scrx, scry, i, mx, y: Integer; msg: SSArray; Srv: TNetServer;
441 begin
442 scrx := gScreenWidth div 2;
443 scry := gScreenHeight div 2;
445 r_Draw_GetTextSize(_lc[I_NET_SLIST], menufont, ww, hh);
446 r_Common_DrawText(_lc[I_NET_SLIST], gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
448 r_Draw_GetTextSize('W', stdfont, cw, ch);
449 motdh := gScreenHeight - 49 - ch * b_Text_LineCount(slMOTD);
451 r_Draw_FillRect(16, 64, gScreenWidth - 16, motdh, 64, 64, 64, 145);
452 r_Draw_Rect(16, 64, gScreenWidth - 16, motdh, 255, 127, 0, 255);
454 r_Common_DrawText(_lc[I_NET_SLIST_HELP], gScreenWidth div 2, gScreenHeight - 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
456 if slMOTD <> '' then
457 begin
458 r_Draw_FillRect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 64, 64, 64, 110);
459 r_Draw_Rect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 255, 127, 0, 255);
460 r_Common_DrawFormatText(slMOTD, 20, motdh + 3 + ch * i, 255, stdfont, TBasePoint.BP_LEFTUP);
461 end;
463 if not slReadUrgent and (slUrgent <> '') then
464 begin
465 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
466 r_Draw_FillRect(scrx - 256, scry - 60, scrx + 256, scry + 60, 64, 64, 64, 127);
467 r_Draw_Rect(scrx - 256, scry - 60, scrx + 256, scry + 60, 255, 127, 0, 255);
468 r_Draw_FillRect(scrx - 256, scry - 40, scrx + 256, scry - 40, 255, 127, 0, 255);
469 r_Common_DrawText(_lc[I_NET_SLIST_URGENT], scrx, scry - 58, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
470 r_Common_DrawFormatText(slUrgent, scrx - 253, scry - 38 + ch * i, 255, stdfont, TBasePoint.BP_LEFTUP);
471 r_Common_DrawText(_lc[I_NET_SLIST_URGENT_CONT], scrx, scry + 41, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
472 r_Draw_FillRect(scrx - 256, scry + 40, scrx + 256, scry + 40, 255, 127, 0, 255);
473 end
474 else if SL = nil then
475 begin
476 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
477 r_Draw_Rect(scrx - 192, scry - 10, scrx + 192, scry + 11, 255, 127, 0, 255);
478 r_Common_DrawText(slWaitStr, scrx, scry, 255, 255, 255, 255, stdfont, TBasePoint.BP_CENTER);
479 end
480 else
481 begin
482 y := 90;
483 if slSelection < Length(ST) then
484 begin
485 sy := y + 42 * slSelection - 4;
486 Srv := GetServerFromTable(slSelection, SL, ST);
487 ip := _lc[I_NET_ADDRESS] + ' ' + Srv.IP + ':' + IntToStr(Srv.Port);
488 ip := ip + ' ' + _lc[I_NET_SERVER_PASSWORD] + ' ';
489 if Srv.Password then ip := ip + _lc[I_MENU_YES] else ip := ip +_lc[I_MENU_NO];
490 end;
492 mw := gScreenWidth - 188;
493 mx := 16 + mw;
495 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy + 40, 64, 64, 64, 255);
496 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy, 205, 205, 205, 255);
497 r_Draw_FillRect(16 + 1, sy + 41, gScreenWidth - 16 - 1, sy + 41, 255, 255, 255, 255);
499 r_Draw_FillRect(16, 85, gScreenWidth - 16, 85, 255, 127, 0, 255);
500 r_Draw_FillRect(16, motdh - 20, gScreenWidth - 16, motdh - 20, 255, 127, 0, 255);
502 r_Draw_FillRect(mx - 70, 64, mx - 70, motdh, 255, 127, 0, 255);
503 r_Draw_FillRect(mx, 64, mx, motdh - 20, 255, 127, 0, 255);
504 r_Draw_FillRect(mx + 52, 64, mx + 52, motdh - 20, 255, 127, 0, 255);
505 r_Draw_FillRect(mx + 104, 64, mx + 104, motdh - 20, 255, 127, 0, 255);
507 r_Common_DrawText('NAME/MAP', 18, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
508 r_Common_DrawText('PING', mx - 68, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
509 r_Common_DrawText('MODE', mx + 2, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
510 r_Common_DrawText('PLRS', mx + 54, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
511 r_Common_DrawText('VER', mx + 106, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
513 for i := 0 to High(ST) do
514 begin
515 Srv := GetServerFromTable(i, SL, ST);
516 r_Common_DrawText(Srv.Name, 18, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
517 r_Common_DrawText(Srv.Map, 18, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
519 if Srv.Ping = 0 then
520 r_Common_DrawText('<1' + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
521 else if (Srv.Ping >= 0) and (Srv.Ping <= 999) then
522 r_Common_DrawText(IntToStr(Srv.Ping) + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
523 else
524 r_Common_DrawText(_lc[I_NET_SLIST_NO_ACCESS], mx - 68, y, 255, 0, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
525 if Length(ST[I].Indices) > 1 then
526 r_Common_DrawText('<' + IntToStr(Length(ST[I].Indices)) + '>', mx - 68, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
528 r_Common_DrawText(g_Game_ModeToText(Srv.GameMode), mx + 2, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
530 r_Common_DrawText(IntToStr(Srv.Players) + '/' + IntToStr(Srv.MaxPlayers), mx + 54, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
531 r_Common_DrawText(IntToStr(Srv.LocalPl) + '+' + IntToStr(Srv.Bots), mx + 54, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
533 r_Common_DrawText(IntToStr(Srv.Protocol), mx + 106, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
535 y := y + 42;
536 end;
538 r_Common_DrawText(ip, 20, motdh - 20 + 3, 205, 205, 205, 255, stdfont, TBasePoint.BP_LEFTUP);
539 r_Common_DrawText(IntToStr(Length(ST)) + _lc[I_NET_SLIST_SERVERS], gScreenWidth - 48, motdh - 20 + 3, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
540 end;
541 end;
543 procedure r_Render_DrawStatsColumns (constref cs: TEndCustomGameStat; x, y, w: Integer; endview: Boolean);
544 var i, cw, ch, yy, team, players, w1, w2, w3, w4, tw: Integer; r, g, b, rr, gg, bb: Byte; s: AnsiString;
545 begin
546 r_Draw_GetTextSize('W', stdfont, cw, ch);
547 w4 := cw * 6; (* deaths width *)
548 w3 := cw * 8; (* frags width *)
549 w2 := cw * 12; (* ping/loss width *)
550 w1 := w - w2 - w3 - w4; (* name width *)
551 tw := w1 - cw * 2 - w2; (* team goals *)
552 if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
553 yy := y;
554 if cs.GameMode in [GM_TDM, GM_CTF] then
555 begin
556 for team := TEAM_RED to TEAM_BLUE do
557 begin
558 case team of
559 TEAM_RED:
560 begin
561 s := _lc[I_GAME_TEAM_RED];
562 r := 255; g := 0; b := 0;
563 end;
564 TEAM_BLUE:
565 begin
566 s := _lc[I_GAME_TEAM_BLUE];
567 r := 0; g := 0; b := 255;
568 end;
569 end;
570 r_Common_DrawText(s, x, yy, r, g, b, 255, stdfont, TBasePoint.BP_LEFTUP);
571 r_Common_DrawText(IntToStr(cs.TeamStat[team].Score), x + tw, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
572 if endview = false then
573 r_Common_DrawText(_lc[I_GAME_PING], x + w1, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
574 r_Common_DrawText(_lc[I_GAME_FRAGS], x + w1 + w2, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
575 r_Common_DrawText(_lc[I_GAME_DEATHS], x + w1 + w2 + w3, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
576 INC(yy, ch);
578 INC(yy, ch div 4);
579 r_Draw_FillRect(x, yy, x + w - 1, yy, r, g, b, 255);
580 INC(yy, ch div 4);
582 for i := 0 to players - 1 do
583 begin
584 if cs.PlayerStat[i].Team = team then
585 begin
586 rr := r; gg := g; bb := b;
587 if cs.PlayerStat[i].Spectator then
588 begin
589 rr := r div 2; gg := g div 2; bb := b div 2;
590 end;
592 // Player name
593 if gShowPIDs then s := Format('[%5d] %s', [cs.PlayerStat[i].UID, cs.PlayerStat[i].Name]) else s := cs.PlayerStat[i].Name;
594 if (gPlayers[cs.PlayerStat[i].Num] <> nil) and (gPlayers[cs.PlayerStat[i].Num].FReady) then s := s + ' *';
595 r_Common_DrawText(s, x, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_LEFTUP);
596 if endview = false then
597 begin
598 // Player ping/loss
599 s := Format(_lc[I_GAME_PING_MS], [cs.PlayerStat[i].Ping, cs.PlayerStat[i].Loss]);
600 r_Common_DrawText(s, x + w1, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
601 end;
602 // Player frags
603 s := IntToStr(cs.PlayerStat[i].Frags);
604 r_Common_DrawText(s, x + w1 + w2, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
605 // Player deaths
606 s := IntToStr(cs.PlayerStat[i].Deaths);
607 r_Common_DrawText(s, x + w1 + w2 + w3, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
609 INC(yy, ch);
610 end;
611 end;
612 INC(yy, ch);
613 end;
614 end
615 else if cs.GameMode in [GM_DM, GM_COOP] then
616 begin
617 r_Common_DrawText(_lc[I_GAME_PLAYER_NAME], x, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
618 if endview = false then
619 r_Common_DrawText(_lc[I_GAME_PING], x + w1, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
620 r_Common_DrawText(_lc[I_GAME_FRAGS], x + w1 + w2, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
621 r_Common_DrawText(_lc[I_GAME_DEATHS], x + w1 + w2 + w3, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
622 INC(yy, ch + ch div 2);
623 for i := 0 to players - 1 do
624 begin
625 // rr := 255; gg := 127; bb := 0;
626 rr := 255; gg := 255; bb := 255;
627 if cs.PlayerStat[i].Spectator then
628 begin
629 rr := rr div 2; gg := gg div 2; bb := bb div 2;
630 end;
632 // Player color
633 r_Draw_Rect(x, yy, x + 16 - 1, yy + 16 - 1, 192, 192, 192, 255);
634 r_Draw_FillRect(x + 1, yy + 1, x + 16 - 1, yy + 16 - 1, cs.PlayerStat[i].Color.R, cs.PlayerStat[i].Color.G, cs.PlayerStat[i].Color.B, 255);
635 // Player name
636 if gShowPIDs then s := Format('[%5d] %s', [cs.PlayerStat[i].UID, cs.PlayerStat[i].Name]) else s := cs.PlayerStat[i].Name;
637 if (gPlayers[cs.PlayerStat[i].Num] <> nil) and (gPlayers[cs.PlayerStat[i].Num].FReady) then s := s + ' *';
638 r_Common_DrawText(s, x + 16 + 8, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_LEFTUP);
639 if endview = false then
640 begin
641 // Player ping/loss
642 s := Format(_lc[I_GAME_PING_MS], [cs.PlayerStat[i].Ping, cs.PlayerStat[i].Loss]);
643 r_Common_DrawText(s, x + w1, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
644 end;
645 // Player frags
646 s := IntToStr(cs.PlayerStat[i].Frags);
647 r_Common_DrawText(s, x + w1 + w2, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
648 // Player deaths
649 s := IntToStr(cs.PlayerStat[i].Deaths);
650 r_Common_DrawText(s, x + w1 + w2 + w3, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
652 INC(yy, ch + ch div 2);
653 end;
654 end;
655 end;
657 procedure r_Render_DrawStatsWindow (x, y, w, h: Integer; cs: TEndCustomGameStat; endview: Boolean);
658 var xoff, yoff, cw, ch: Integer; s: AnsiString;
659 begin
660 xoff := 0; yoff := 8;
661 r_Draw_GetTextSize('W', stdfont, cw, ch);
662 r_Draw_FillRect(x, y, x + w - 1, y + h - 1, 64, 64, 64, 224);
663 r_Draw_Rect(x, y, x + w - 1, y + h - 1, 255, 127, 0, 255);
665 (* LINE 1 *)
667 if endview = false then
668 begin
669 case NetMode of
670 NET_SERVER: s := _lc[I_NET_SERVER];
671 NET_CLIENT: s := NetClientIP + ':' + IntToStr(NetClientPort);
672 otherwise s := '';
673 end;
674 r_Common_DrawText(s, x + 16, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
675 end;
677 case cs.GameMode of
678 GM_DM: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_DM] else s := _lc[I_GAME_LMS];
679 GM_TDM: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_TDM] else s := _lc[I_GAME_TLMS];
680 GM_CTF: s := _lc[I_GAME_CTF];
681 GM_COOP: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_COOP] else s := _lc[I_GAME_SURV];
682 otherwise s := 'GAME MODE ' + IntToStr(gGameSettings.GameMode);
683 end;
684 r_Common_DrawText(s, x + w div 2, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
686 if endview = false then
687 begin
688 s := r_Common_TimeToStr(cs.GameTime);
689 r_Common_DrawText(s, x + w - 16, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
690 end;
692 INC(yoff, ch + ch div 2);
694 (* LINE 2/3 *)
696 s := cs.Map;
697 if cs.MapName <> '' then
698 s := s + ' - ' + cs.MapName;
700 if endview = false then
701 begin
702 r_Common_DrawText(s, x + w div 2, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_UP);
703 INC(yoff, ch + ch div 2);
704 case cs.GameMode of
705 GM_DM, GM_TDM: s := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]);
706 GM_CTF: s := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.ScoreLimit]);
707 GM_COOP: s := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
708 otherwise s := '';
709 end;
710 r_Common_DrawText(s, x + 16, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_LEFTUP);
711 case cs.GameMode of
712 GM_DM, GM_TDM, GM_CTF: s := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
713 GM_COOP: s := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
714 otherwise s := '';
715 end;
716 r_Common_DrawText(s, x + w - 16, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_RIGHTUP);
717 INC(yoff, ch);
718 end
719 else
720 begin
721 xoff := MAX(Length(_lc[I_MENU_MAP]) + 1, Length(_lc[I_GAME_GAME_TIME]) + 1) * cw;
722 r_Common_DrawText(_lc[I_MENU_MAP], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
723 r_Common_DrawText(s, x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
724 INC(yoff, ch);
725 r_Common_DrawText(_lc[I_GAME_GAME_TIME], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
726 r_Common_DrawText(r_Common_TimeToStr(cs.GameTime), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
727 INC(yoff, ch);
728 end;
730 INC(yoff, ch);
732 (* LINE 4/5 *)
734 if endview and (cs.GameMode = GM_COOP) then
735 begin
736 xoff := MAX(Length(_lc[I_GAME_MONSTERS]) + 1, Length(_lc[I_GAME_SECRETS]) + 1) * cw;
737 r_Common_DrawText(_lc[I_GAME_MONSTERS], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
738 r_Common_DrawText(IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
739 INC(yoff, ch);
740 r_Common_DrawText(_lc[I_GAME_SECRETS], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
741 r_Common_DrawText(IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
742 INC(yoff, ch);
743 INC(yoff, ch);
744 end;
746 (* LINE 6/7 *)
748 if endview and (cs.GameMode = GM_COOP) and gLastMap then
749 begin
750 xoff := MAX(Length(_lc[I_GAME_MONSTERS_TOTAL]) + 1, Length(_lc[I_GAME_SECRETS_TOTAL]) + 1) * cw;
751 r_Common_DrawText(_lc[I_GAME_MONSTERS_TOTAL], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
752 r_Common_DrawText(IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
753 INC(yoff, ch);
754 r_Common_DrawText(_lc[I_GAME_SECRETS_TOTAL], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
755 r_Common_DrawText(IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
756 INC(yoff, ch);
757 INC(yoff, ch);
758 end;
760 (* LINE *)
762 if endview and (cs.GameMode in [GM_TDM, GM_CTF]) then
763 begin
764 if cs.TeamStat[TEAM_RED].Score > cs.TeamStat[TEAM_BLUE].Score then s := _lc[I_GAME_WIN_RED]
765 else if cs.TeamStat[TEAM_BLUE].Score > cs.TeamStat[TEAM_RED].Score then s := _lc[I_GAME_WIN_BLUE]
766 else s := _lc[I_GAME_WIN_DRAW];
767 r_Common_DrawText(s, x + w div 2, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
768 INC(yoff, ch);
769 INC(yoff, ch);
770 end;
772 (* LINE n *)
774 r_Render_DrawStatsColumns(cs, x + 16, y + yoff, w - 16 - 16, endview);
775 end;
777 function r_Render_StatsHeight (players: Integer): Integer;
778 var cw, ch: Integer;
779 begin
780 ASSERT(players >= 0);
781 r_Draw_GetTextSize('W', stdfont, cw, ch);
782 case gGameSettings.GameMode of
783 GM_TDM, GM_CTF: result := 32 + ch * (11 + players);
784 otherwise result := 40 + ch * 5 + (ch + 8) * players;
785 end;
786 end;
788 procedure r_Render_DrawStats;
789 var x, y, w, h, players: Integer; cs: TEndCustomGameStat;
790 begin
791 cs.PlayerStat := g_Player_GetStats();
792 SortGameStat(cs.PlayerStat);
793 cs.TeamStat := gTeamStat;
794 cs.GameTime := gTime;
795 cs.GameMode := gGameSettings.GameMode;
796 cs.Map := g_ExtractWadNameNoPath(gMapInfo.Map) + ':' + g_ExtractFileName(gMapInfo.Map);
797 cs.MapName := gMapInfo.Name;
798 if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
799 w := gScreenWidth - (gScreenWidth div 5);
800 h := r_Render_StatsHeight(players);
801 x := (gScreenWidth div 2) - (w div 2);
802 y := (gScreenHeight div 2) - (h div 2);
803 r_Render_DrawStatsWindow(x, y, w, h, cs, false);
804 end;
806 procedure r_Render_DrawCustomStats;
807 var cw, ch, s: AnsiString;
808 begin
809 if gStatsOff then
810 begin
811 r_Common_DrawText(_lc[I_MENU_INTER_NOTICE_TAB], gScreenWidth div 2, 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
812 end
813 else
814 begin
815 case gGameSettings.GameMode of
816 GM_COOP: if gMissionFailed then s := _lc[I_MENU_INTER_MISSION_FAIL] else s := _lc[I_MENU_INTER_LEVEL_COMPLETE];
817 otherwise s := _lc[I_MENU_INTER_ROUND_OVER];
818 end;
819 r_Common_DrawText(s, gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
821 if gChatShow = false then
822 begin
823 if g_Game_IsClient then s := _lc[I_MENU_INTER_NOTICE_MAP] else s := _lc[I_MENU_INTER_NOTICE_SPACE];
824 r_Common_DrawText(s, gScreenWidth div 2, gScreenHeight - 4, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
825 if g_Game_IsNet then
826 begin
827 s := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
828 r_Common_DrawText(s, gScreenWidth div 2, gScreenHeight - 16 - 4, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
829 end;
830 end;
832 r_Render_DrawStatsWindow(32, 64, gScreenWidth - 32 * 2, gScreenHeight - 64 * 2, CustomStat, true);
833 end;
834 end;
836 procedure r_Render_DrawValueOf (a, b, x, y: Integer; f: TGLFont);
837 var wa, wb, ch: Integer; sa, sb: AnsiString;
838 begin
839 sa := IntToStr(a);
840 sb := IntToStr(b);
841 r_Draw_GetTextSize(sa, f, wa, ch);
842 r_Draw_GetTextSize(sa + ' / ', f, wb, ch);
843 r_Common_DrawText(sa, x, y, 255, 0, 0, 255, f, TBasePoint.BP_LEFTUP);
844 r_Common_DrawText(' / ', x + wa, y, 255, 255, 255, 255, f, TBasePoint.BP_LEFTUP);
845 r_Common_DrawText(sb, x + wb, y, 255, 0, 0, 255, f, TBasePoint.BP_LEFTUP);
846 end;
848 procedure r_Render_DrawSinglStatsPlayer (player, x, y, w1: Integer);
849 var time, kpm: Single;
850 begin
851 r_Common_DrawText(_lc[I_MENU_INTER_KILLS], x, y, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
852 r_Render_DrawValueOf(SingleStat.PlayerStat[player].Kills, gTotalMonsters, x + w1, y, MenuFont);
853 r_Common_DrawText(_lc[I_MENU_INTER_KPM], x, y + 32, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
854 time := SingleStat.GameTime / 1000;
855 kpm := SingleStat.PlayerStat[player].Kills;
856 if time > 0 then kpm := kpm / time * 60;
857 r_Common_DrawText(Format('%.1f', [kpm]), x + w1, y + 32, 255, 0, 0, 255, menufont, TBasePoint.BP_LEFTUP);
858 r_Common_DrawText(_lc[I_MENU_INTER_SECRETS], x, y + 64, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
859 r_Render_DrawValueOf(SingleStat.PlayerStat[player].Secrets, SingleStat.TotalSecrets, x + w1, y + 64, MenuFont);
860 end;
862 procedure r_Render_DrawSingleStats;
863 var xx, wa, wb, ww, ch: Integer; s: AnsiString;
864 begin
865 r_Common_DrawText(_lc[I_MENU_INTER_LEVEL_COMPLETE], gScreenWidth div 2, 32, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
867 r_Draw_GetTextSize(_lc[I_MENU_INTER_KPM] + ' ', menufont, wa, ch);
868 r_Draw_GetTextSize(' 9999.9', menufont, wb, ch);
869 ww := wa + wb;
870 xx := gScreenWidth div 2 - ww div 2;
872 s := r_Common_TimeToStr(SingleStat.GameTime);
873 r_Common_DrawText(_lc[I_MENU_INTER_TIME], xx, 80, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
874 r_Common_DrawText(s, xx + wa, 80, 255, 0, 0, 255, menufont, TBasePoint.BP_LEFTUP);
876 if SingleStat.TwoPlayers then
877 begin
878 r_Common_DrawText(_lc[I_MENU_PLAYER_1], gScreenWidth div 2, 128, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
879 r_Render_DrawSinglStatsPlayer(0, xx, 176, wa);
880 r_Common_DrawText(_lc[I_MENU_PLAYER_2], gScreenWidth div 2, 288, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
881 r_Render_DrawSinglStatsPlayer(1, xx, 336, wa);
882 end
883 else
884 begin
885 r_Render_DrawSinglStatsPlayer(0, xx, 128, wa);
886 end;
887 end;
889 procedure r_Render_DrawSpectHud;
890 var xoff: Integer; s: AnsiString;
892 procedure AddText (s1, s2: AnsiString);
893 var w1, w2, ww, ch: Integer;
894 begin
895 r_Draw_GetTextSize(s1, stdfont, w1, ch);
896 r_Draw_GetTextSize(s2, stdfont, w2, ch);
897 ww := MAX(w1, w2);
898 r_Common_DrawText(s1, xoff + ww div 2, gScreenHeight - ch, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
899 r_Common_DrawText(s2, xoff + ww div 2, gScreenHeight - ch, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
900 xoff := xoff + ww + 16;
901 end;
903 begin
904 xoff := 0;
905 case gSpectMode of
906 SPECT_STATS: s := 'MODE: Stats';
907 SPECT_MAPVIEW: s := 'MODE: Observe Map';
908 SPECT_PLAYERS: s := 'MODE: Watch Players';
909 otherwise s := 'MODE: ' + IntToStr(gSpectMode);
910 end;
911 AddText(s, '< jump >');
912 if gSpectMode = SPECT_STATS then
913 AddText('Autoview', '< fire >');
914 if gSpectMode = SPECT_MAPVIEW then
915 AddText('[-] Step ' + IntToStr(gSpectStep) + ' [+]', '<prev weap> <next weap>');
916 if gSpectMode = SPECT_PLAYERS then
917 begin
918 AddText('Player 1', '<left/right>');
919 if gSpectViewTwo then
920 AddText('Player 2', '<prev w/next w>');
921 AddText('2x View', '<up/down>');
922 end;
923 end;
925 function GetActivePlayer_ByID (id: Integer): TPlayer;
926 var i, len: Integer; p: TPlayer;
927 begin
928 p := nil;
929 if (id >= 0) and (gPlayers <> nil) then
930 begin
931 i := 0; len := Length(gPlayers);
932 while (i < len) and ((IsActivePlayer(gPlayers[i]) = false) or (gPlayers[i].UID <> id)) do INC(i);
933 if i < len then p := gPlayers[i];
934 end;
935 result := p;
936 end;
938 procedure r_Render_DrawMinimap (x, y: Integer; alpha: Byte);
939 const scale = 16;
941 function IsMinimapPanel (const p: TPanel): Boolean;
942 begin
943 result := (p <> nil) and p.Enabled;
944 if result then
945 begin
946 case p.PanelType of
947 PANEL_WALL, PANEL_WATER, PANEL_ACID1, PANEL_ACID2,
948 PANEL_STEP, PANEL_OPENDOOR, PANEL_CLOSEDOOR,
949 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
950 result := true;
951 otherwise
952 result := false;
953 end;
954 end;
955 end;
957 procedure DrawObject (xx, yy, ww, hh: Integer; r, g, b: Byte);
958 var x0, y0, x1, y1: Integer;
959 begin
960 x0 := x + xx div scale;
961 y0 := y + yy div scale;
962 x1 := x + (xx + ww - 1) div scale;
963 y1 := y + (yy + hh - 1) div scale;
964 r_Draw_FillRect(x0, y0, x1, y1, r, g, b, alpha);
965 end;
967 procedure DrawPanels (const a: TPanelArray);
968 var i: Integer; p: TPanel; c: TRGB;
969 begin
970 if a <> nil then
971 begin
972 for i := 0 to HIGH(a) do
973 begin
974 p := a[i];
975 if IsMinimapPanel(p) then
976 begin
977 case p.PanelType of
978 PANEL_WALL: c := _RGB(208, 208, 208);
979 PANEL_OPENDOOR: c := _RGB(160, 160, 160);
980 PANEL_CLOSEDOOR: c := _RGB(160, 160, 160);
981 PANEL_STEP: c := _RGB(128, 128, 128);
982 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
983 case p.LiftType of
984 LIFTTYPE_UP: c := _RGB(116, 72, 36);
985 LIFTTYPE_DOWN: c := _RGB(116, 124, 96);
986 LIFTTYPE_LEFT: c := _RGB(116, 200, 80);
987 LIFTTYPE_RIGHT: c := _RGB(116, 252, 140);
988 otherwise c := _RGB(255, 0, 0);
989 end;
990 PANEL_WATER: c := _RGB(0, 0, 192);
991 PANEL_ACID1: c := _RGB(0, 176, 0);
992 PANEL_ACID2: c := _RGB(176, 0, 0);
993 otherwise c := _RGB(255, 0, 0);
994 end;
995 DrawObject(p.x, p.y, p.width, p.height, c.r, c.g, c.b);
996 end;
997 end;
998 end;
999 end;
1001 procedure DrawPlayers;
1002 var i: Integer; p: TPlayer; c: TRGB;
1003 begin
1004 if gPlayers <> nil then
1005 begin
1006 for i := 0 to HIGH(gPlayers) do
1007 begin
1008 p := gPlayers[i];
1009 if p.Alive then
1010 begin
1011 case p.Team of
1012 TEAM_RED: c := _RGB(255, 0, 0);
1013 TEAM_BLUE: c := _RGB(0, 0, 255);
1014 otherwise c := _RGB(255, 128, 0);
1015 end;
1016 DrawObject(p.obj.x, p.obj.y, p.obj.rect.width, p.obj.rect.height, c.r, c.g, c.b);
1017 end;
1018 end;
1019 end;
1020 end;
1022 function DrawMonster (m: TMonster): Boolean;
1023 begin
1024 result := false; // don't stop
1025 if m.alive then
1026 DrawObject(m.obj.x, m.obj.y, m.obj.rect.width, m.obj.rect.height, 255, 255, 0);
1027 end;
1029 begin
1030 r_Draw_FillRect(x, y, (x + gMapInfo.Width - 1) div scale, (y + gMapInfo.Height - 1) div scale, 0, 0, 0, alpha);
1031 DrawPanels(gSteps);
1032 DrawPanels(gLifts);
1033 DrawPanels(gWater);
1034 DrawPanels(gAcid1);
1035 DrawPanels(gAcid2);
1036 DrawPanels(gWalls);
1037 g_Mons_ForEach(DrawMonster);
1038 DrawPlayers;
1039 end;
1041 procedure r_Render_Draw;
1042 var p1, p2: TPlayer;
1043 begin
1044 if gExit = EXIT_QUIT then
1045 exit;
1047 r_Draw_Setup(gScreenWidth, gScreenHeight);
1049 glClearColor(0.0, 0.0, 0.0, 0.0);
1050 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
1052 glColor4ub(255, 255, 255, 255);
1053 glEnable(GL_SCISSOR_TEST);
1054 r_Draw_SetRect(0, 0, gScreenWidth, gScreenHeight);
1056 //e_LogWritefln('r_render_draw: %sx%s', [gScreenWidth, gScreenHeight]);
1058 p1 := nil;
1059 p2 := nil;
1060 if gGameOn or (gState = STATE_FOLD) then
1061 begin
1062 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
1063 begin
1064 if gRevertPlayers then
1065 begin
1066 p1 := gPlayer2;
1067 p2 := gPlayer1;
1068 end
1069 else
1070 begin
1071 p1 := gPlayer1;
1072 p2 := gPlayer2;
1073 end;
1074 end
1075 else if gPlayer1 <> nil then
1076 begin
1077 p1 := gPlayer1;
1078 end
1079 else if gPlayer2 <> nil then
1080 begin
1081 p1 := gPlayer2;
1082 end;
1083 if (gSpectMode = SPECT_PLAYERS) and (gPlayers <> nil) then
1084 begin
1085 p1 := GetActivePlayer_ByID(gSpectPID1);
1086 if p1 = nil then
1087 p1 := GetActivePlayer_ByID(GetActivePlayerID_Next());
1088 if gSpectViewTwo then
1089 begin
1090 p2 := GetActivePlayer_ByID(gSpectPID2);
1091 if p2 = nil then
1092 p2 := GetActivePlayer_ByID(GetActivePlayerID_Next());
1093 end;
1094 end;
1095 end;
1097 if gGameOn or ((gState in [STATE_FOLD]) and (EndingGameCounter < 255)) then
1098 begin
1099 // TODO setup player hear point
1101 if gSpectMode = SPECT_MAPVIEW then
1102 begin
1103 r_Render_DrawMapView(0, 0, gScreenWidth, gScreenHeight, gSpectX + gScreenWidth div 2, gSpectY + gScreenHeight div 2);
1104 end
1105 else if (p1 <> nil) and (p2 <> nil) then
1106 begin
1107 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight div 2 - 2, p1);
1108 r_Render_DrawPlayerView(0, gScreenHeight div 2 + 2, gScreenWidth, gScreenHeight div 2, p2);
1109 end
1110 else if p1 <> nil then
1111 begin
1112 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, p1);
1113 end
1114 else if p2 <> nil then
1115 begin
1116 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, p2);
1117 end;
1119 if gShowMap then
1120 r_Render_DrawMiniMap(0, 0, 160);
1122 // TODO draw holmes inspector
1124 if MessageText <> '' then
1125 r_Common_DrawFormatText(MessageText, (gScreenWidth - 196) div 2, gScreenHeight div 2, 255, menufont, TBasePoint.BP_CENTER);
1127 if IsDrawStat or (gSpectMode = SPECT_STATS) then
1128 r_Render_DrawStats;
1130 if gSpectHUD and (gChatShow = false) and (gSpectMode <> SPECT_NONE) and (gSpectAuto = false) then
1131 r_Render_DrawSpectHud;
1132 end;
1134 if gPauseMain and gGameOn {$IFDEF ENABLE_MENU}and (g_ActiveWindow = nil){$ENDIF} then
1135 begin
1136 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1137 r_Common_DrawText(_lc[I_MENU_PAUSE], gScreenWidth div 2, gScreenHeight div 2, 255, 255, 255, 255, menufont, TBasePoint.BP_CENTER);
1138 end;
1140 if not gGameOn then
1141 begin
1142 case gState of
1143 STATE_NONE: (* do nothing *) ;
1144 STATE_MENU: r_Render_DrawBackground(GameWad + ':TEXTURES/TITLE');
1145 STATE_FOLD:
1146 begin
1147 if EndingGameCounter > 0 then
1148 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
1149 end;
1150 STATE_INTERCUSTOM:
1151 begin
1152 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1153 if EndPicPath <> '' then
1154 r_Render_DrawBackground(EndPicPath)
1155 else
1156 r_Render_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC])
1157 else
1158 r_Render_DrawBackground(GameWad + ':TEXTURES/INTER');
1160 r_Render_DrawCustomStats;
1162 {$IFDEF ENABLE_MENU}
1163 if g_ActiveWindow <> nil then
1164 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1165 {$ENDIF}
1166 end;
1167 STATE_INTERSINGLE, STATE_INTERTEXT, STATE_INTERPIC:
1168 begin
1169 if EndingGameCounter > 0 then
1170 begin
1171 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
1172 end
1173 else
1174 begin
1175 r_Render_DrawBackground(GameWad + ':TEXTURES/INTER');
1176 r_Render_DrawSingleStats;
1177 {$IFDEF ENABLE_MENU}
1178 if g_ActiveWindow <> nil then
1179 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1180 {$ENDIF}
1181 end;
1182 end;
1183 STATE_ENDPIC:
1184 begin
1185 if EndPicPath <> '' then
1186 r_Render_DrawBackground(EndPicPath)
1187 else
1188 r_Render_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC]);
1189 {$IFDEF ENABLE_MENU}
1190 if g_ActiveWindow <> nil then
1191 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1192 {$ENDIF}
1193 end;
1194 STATE_SLIST:
1195 begin
1196 r_Render_DrawBackground(GameWad + ':TEXTURES/TITLE');
1197 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1198 r_Render_DrawServerList(slCurrent, slTable);
1199 end;
1200 end;
1201 end;
1203 {$IFDEF ENABLE_MENU}
1204 if g_ActiveWindow <> nil then
1205 begin
1206 if gGameOn then
1207 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1208 r_GUI_Draw_Window(g_ActiveWindow);
1209 end;
1210 {$ENDIF}
1212 r_Console_Draw(false);
1214 // TODO draw holmes interface
1216 glFlush();
1217 glFinish();
1218 sys_Repaint;
1219 end;
1221 procedure r_Render_Resize (w, h: Integer);
1222 begin
1223 gWinSizeX := w;
1224 gWinSizeY := h;
1225 gRC_Width := w;
1226 gRC_Height := h;
1227 gScreenWidth := w;
1228 gScreenHeight := h;
1229 end;
1231 procedure r_Render_Apply;
1232 begin
1233 {$IFDEF ENABLE_SYSTEM}
1234 if sys_SetDisplayModeGL(GetInfo()) then
1235 e_LogWriteln('resolution changed')
1236 else
1237 e_LogWriteln('resolution not changed');
1238 sys_EnableVSync(gVSync)
1239 {$ENDIF}
1240 end;
1242 function r_Render_WriteScreenShot (filename: String): Boolean;
1243 begin
1244 Result := False;
1245 end;
1247 {$IFDEF ENABLE_GIBS}
1248 function r_Render_GetGibRect (m, id: Integer): TRectWH;
1249 begin
1250 result := r_Map_GetGibSize(m, id);
1251 end;
1252 {$ENDIF}
1254 {$IFDEF ENABLE_GFX}
1255 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
1256 begin
1257 r_Map_NewGFX(AnimType, X, Y);
1258 end;
1259 {$ENDIF}
1261 {$IFDEF ENABLE_TOUCH}
1262 procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
1263 begin
1264 founded := False;
1265 end;
1266 {$ENDIF}
1268 {$IFDEF ENABLE_MENU}
1269 procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
1270 begin
1271 r_GUI_GetSize(ctrl, w, h);
1272 end;
1274 procedure r_Render_GetLogoSize (out w, h: Integer);
1275 begin
1276 r_GUI_GetLogoSize(w, h);
1277 end;
1279 procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
1280 begin
1281 r_GUI_GetMaxFontSize(BigFont, w, h);
1282 end;
1284 procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
1285 begin
1286 r_GUI_GetStringSize(BigFont, str, w, h);
1287 end;
1288 {$ENDIF}
1290 procedure r_Render_DrawLoading (force: Boolean);
1291 begin
1292 // TODO draw loading screen
1293 end;
1295 end.