DEADSOFTWARE

gl: apply r_resolution_scale without videomode reset
[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 type
28 TProcedure = procedure;
30 (* render startup *)
31 procedure r_Render_Initialize;
32 procedure r_Render_Finalize;
34 (* load globally used textures *)
35 procedure r_Render_Load;
36 procedure r_Render_Free;
38 (* load map specific textures *)
39 procedure r_Render_LoadTextures;
40 procedure r_Render_FreeTextures;
42 procedure r_Render_Update;
43 procedure r_Render_Draw;
45 procedure r_Render_Resize (w, h: Integer);
46 procedure r_Render_Apply;
48 function r_Render_WriteScreenShot (filename: String): Boolean;
50 {$IFDEF ENABLE_GIBS}
51 function r_Render_GetGibRect (m, id: Integer): TRectWH;
52 {$ENDIF}
54 {$IFDEF ENABLE_GFX}
55 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
56 {$ENDIF}
58 {$IFDEF ENABLE_TOUCH}
59 // touch screen button location and size
60 procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
61 {$ENDIF}
63 {$IFDEF ENABLE_MENU}
64 procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
65 procedure r_Render_GetLogoSize (out w, h: Integer);
66 procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
67 procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
68 {$ENDIF}
70 procedure r_Render_SetProcessLoadingCallback (p: TProcedure);
71 procedure r_Render_ClearLoading;
72 procedure r_Render_SetLoading (const text: String; maxval: Integer);
73 procedure r_Render_StepLoading (incval: Integer);
74 procedure r_Render_DrawLoading (force: Boolean);
76 {$IFDEF ENABLE_HOLMES}
77 function pmsCurMapX (): Integer;
78 function pmsCurMapY (): Integer;
79 function r_Render_HolmesViewIsSet (): Boolean;
80 {$ENDIF}
82 implementation
84 uses
85 {$I ../../../nogl/noGLuses.inc}
86 {$IFDEF ENABLE_MENU}
87 r_gui,
88 {$ENDIF}
89 {$IFDEF ENABLE_SYSTEM}
90 g_system,
91 {$ENDIF}
92 {$IFDEF ENABLE_TOUCH}
93 r_touch,
94 {$ENDIF}
95 {$IFDEF ENABLE_HOLMES}
96 r_holmes,
97 {$ENDIF}
98 SysUtils, Classes, Math,
99 g_basic,
100 e_log, utils, wadreader, mapdef,
101 g_game, g_map, g_panel, g_options, g_console, g_player, g_weapons, g_language, g_triggers, g_monsters,
102 g_net, g_netmaster,
103 r_draw, r_textures, r_fonts, r_common, r_console, r_map, r_loadscreen
106 var
107 hud, hudbg: TGLTexture;
108 hudhp: array [Boolean] of TGLTexture;
109 hudap: TGLTexture;
110 hudwp: array [0..WP_LAST] of TGLTexture;
111 hudkey: array [0..2] of TGLTexture;
112 hudair: TGLTexture;
113 hudjet: TGLTexture;
114 hudrflag, hudrflags, hudrflagd: TGLTexture;
115 hudbflag, hudbflags, hudbflagd: TGLTexture;
117 FPS, FPSCounter, FPSTime: LongWord;
119 procedure r_Render_LoadTextures;
120 begin
121 r_Map_LoadTextures;
122 end;
124 procedure r_Render_FreeTextures;
125 begin
126 r_Map_FreeTextures;
127 end;
129 procedure r_Render_Load;
130 const
131 WeapName: array [0..WP_LAST] of AnsiString = ('KASTET', 'SAW', 'PISTOL', 'SHOTGUN1', 'SHOTGUN2', 'MGUN', 'RLAUNCHER', 'PGUN', 'BFG', 'SPULEMET', 'FLAMETHROWER');
132 var
133 i: Integer;
134 begin
135 r_LoadScreen_Load;
136 r_Common_Load;
137 r_Common_SetLoading('HUD Textures', 5 + (WP_LAST + 1) + 11);
138 hud := r_Common_LoadTextureFromFile(GameWAD + ':TEXTURES/HUD', [TGLHints.txNoRepeat]);
139 hudbg := r_Common_LoadTextureFromFile(GameWAD + ':TEXTURES/HUDBG', []);
140 hudhp[false] := r_Common_LoadTextureFromFile(GameWAD + ':TEXTURES/MED2', [TGLHints.txNoRepeat]);
141 hudhp[true] := r_Common_LoadTextureFromFile(GameWAD + ':TEXTURES/BMED', [TGLHints.txNoRepeat]);
142 hudap := r_Common_LoadTextureFromFile(GameWAD + ':TEXTURES/ARMORHUD', [TGLHints.txNoRepeat]);
143 for i := 0 to WP_LAST do
144 hudwp[i] := r_Common_LoadTextureFromFile(GameWAD + ':TEXTURES/' + WeapName[i], [TGLHints.txNoRepeat]);
145 hudkey[0] := r_Common_LoadTextureFromFile(GameWAD + ':TEXTURES/KEYR', [TGLHints.txNoRepeat]);
146 hudkey[1] := r_Common_LoadTextureFromFile(GameWAD + ':TEXTURES/KEYG', [TGLHints.txNoRepeat]);
147 hudkey[2] := r_Common_LoadTextureFromFile(GameWAD + ':TEXTURES/KEYB', [TGLHints.txNoRepeat]);
148 hudair := r_Common_LoadTextureFromFile(GameWAD + ':TEXTURES/AIRBAR', [TGLHints.txNoRepeat]);
149 hudjet := r_Common_LoadTextureFromFile(GameWAD + ':TEXTURES/JETBAR', [TGLHints.txNoRepeat]);
150 hudrflag := r_Common_LoadTextureFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_BASE', [TGLHints.txNoRepeat]);
151 hudrflags := r_Common_LoadTextureFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_STOLEN', [TGLHints.txNoRepeat]);
152 hudrflagd := r_Common_LoadTextureFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_DROP', [TGLHints.txNoRepeat]);
153 hudbflag := r_Common_LoadTextureFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_BASE', [TGLHints.txNoRepeat]);
154 hudbflags := r_Common_LoadTextureFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_STOLEN', [TGLHints.txNoRepeat]);
155 hudbflagd := r_Common_LoadTextureFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_DROP', [TGLHints.txNoRepeat]);
156 r_Console_Load;
157 r_Map_Load;
158 {$IFDEF ENABLE_MENU}
159 r_GUI_Load;
160 {$ENDIF}
161 end;
163 procedure r_Render_Free;
164 var i: Integer;
165 begin
166 {$IFDEF ENABLE_MENU}
167 r_GUI_Free;
168 {$ENDIF}
169 r_Map_Free;
170 r_Console_Free;
171 r_Common_FreeAndNil(hudbflagd);
172 r_Common_FreeAndNil(hudbflags);
173 r_Common_FreeAndNil(hudbflag);
174 r_Common_FreeAndNil(hudrflagd);
175 r_Common_FreeAndNil(hudrflags);
176 r_Common_FreeAndNil(hudrflag);
177 r_Common_FreeAndNil(hudjet);
178 r_Common_FreeAndNil(hudair);
179 r_Common_FreeAndNil(hudkey[0]);
180 r_Common_FreeAndNil(hudkey[1]);
181 r_Common_FreeAndNil(hudkey[2]);
182 for i := 0 to WP_LAST do
183 r_Common_FreeAndNil(hudwp[i]);
184 r_Common_FreeAndNil(hudap);
185 r_Common_FreeAndNil(hudhp[true]);
186 r_Common_FreeAndNil(hudhp[false]);
187 r_Common_FreeAndNil(hudbg);
188 r_Common_FreeAndNil(hud);
189 r_Common_Free;
190 end;
192 {$IFDEF ENABLE_SYSTEM}
193 function GetInfo (): TGLDisplayInfo;
194 var info: TGLDisplayInfo;
195 begin
196 info := Default(TGLDisplayInfo);
197 info.w := Max(1, gRC_Width);
198 info.h := Max(1, gRC_Height);
199 info.bpp := Max(1, gBPP);
200 info.fullscreen := gRC_FullScreen;
201 info.maximized := gRC_Maximized;
202 info.major := 1;
203 info.minor := 1;
204 {$IFDEF USE_GLES1}
205 info.profile := TGLProfile.Common;
206 {$ELSE}
207 info.profile := TGLProfile.Compat;
208 {$ENDIF}
209 result := info;
210 end;
211 {$ENDIF}
213 procedure r_Render_LogGLInfo;
214 begin
215 e_LogWritefln('GL Vendor: %s', [glGetString(GL_VENDOR)]);
216 e_LogWritefln('GL Renderer: %s', [glGetString(GL_RENDERER)]);
217 e_LogWritefln('GL Version: %s', [glGetString(GL_VERSION)]);
218 e_LogWritefln('GL Shaders: %s', [glGetString(GL_SHADING_LANGUAGE_VERSION)]);
219 e_LogWritefln('GL Extensions: %s', [glGetString(GL_EXTENSIONS)]);
220 end;
222 procedure r_Render_Initialize;
223 begin
224 {$IFDEF ENABLE_SYSTEM}
225 if sys_SetDisplayModeGL(GetInfo()) = False then
226 raise Exception.Create('Failed to set videomode on startup.');
227 sys_EnableVSync(gVSync);
228 {$ENDIF}
229 {$IFDEF NOGL_INIT}
230 nogl_Init;
231 {$ENDIF}
232 r_Render_LogGLInfo;
233 r_LoadScreen_Initialize;
234 r_Textures_Initialize;
235 r_Console_Initialize;
236 r_Map_Initialize;
237 end;
239 procedure r_Render_Finalize;
240 begin
241 r_Map_Finalize;
242 r_Console_Finalize;
243 r_Textures_Finalize;
244 r_LoadScreen_Finalize;
245 {$IFDEF NOGL_INIT}
246 nogl_Quit;
247 {$ENDIF}
248 end;
250 procedure r_Render_Update;
251 begin
252 r_Console_Update;
253 r_Map_Update;
254 end;
256 procedure r_Render_DrawHUD (x, y: Integer; p: TPlayer);
257 var t: TGLTexture; s: AnsiString;
258 begin
259 ASSERT(p <> nil);
261 // hud area is 196 x 240 pixels
262 r_Common_DrawTexture(hud, x, y, hud.width, hud.height, TBasePoint.BP_LEFTUP);
263 r_Common_DrawText(p.name, x + 98, y + 16, 255, 0, 0, 255, smallfont, TBasePoint.BP_CENTER);
265 t := hudhp[R_BERSERK in p.FRulez];
266 r_Common_DrawTexture(t, x + 51, y + 61, t.width, t.height, TBasePoint.BP_CENTER);
267 r_Common_DrawTexture(hudap, x + 50, y + 85, hudap.width, hudap.height, TBasePoint.BP_CENTER);
269 r_Common_DrawText(IntToStr(MAX(0, p.health)), x + 174, y + 56, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
270 r_Common_DrawText(IntToStr(MAX(0, p.armor)), x + 174, y + 84, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
272 case p.CurrWeap of
273 WEAPON_KASTET, WEAPON_SAW: s := '--';
274 else s := IntToStr(p.GetAmmoByWeapon(p.CurrWeap));
275 end;
276 r_Common_DrawText(s, x + 174, y + 174, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
278 if p.CurrWeap <= WP_LAST then
279 begin
280 t := hudwp[p.CurrWeap];
281 r_Common_DrawTexture(t, x + 18, y + 160, t.width, t.height, TBasePoint.BP_LEFTUP);
282 end;
284 if R_KEY_RED in p.FRulez then
285 r_Common_DrawTexture(hudkey[0], x + 76, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
286 if R_KEY_GREEN in p.FRulez then
287 r_Common_DrawTexture(hudkey[1], x + 93, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
288 if R_KEY_BLUE in p.FRulez then
289 r_Common_DrawTexture(hudkey[2], x + 110, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
291 if p.JetFuel > 0 then
292 begin
293 r_Common_DrawTexture(hudair, x, y + 116, hudair.width, hudair.height, TBasePoint.BP_LEFTUP);
294 if p.air > 0 then
295 r_Draw_FillRect(x + 14, y + 116 + 4, x + 14 + 168 * p.air div AIR_MAX, y + 116 + 4 + 4, 0, 0, 196, 255);
296 r_Common_DrawTexture(hudjet, x, y + 126, hudjet.width, hudjet.height, TBasePoint.BP_LEFTUP);
297 r_Draw_FillRect(x + 14, y + 126 + 4, x + 14 + 168 * p.JetFuel div JET_MAX, y + 126 + 4 + 4, 208, 0, 0, 255);
298 end
299 else
300 begin
301 r_Common_DrawTexture(hudair, x, y + 124, hudair.width, hudair.height, TBasePoint.BP_LEFTUP);
302 if p.air > 0 then
303 r_Draw_FillRect(x + 14, y + 124 + 4, x + 14 + 168 * p.air div AIR_MAX, y + 124 + 4 + 4, 0, 0, 196, 255);
304 end;
305 end;
307 procedure r_Render_DrawHUDArea (x, y, w, h: Integer; p: TPlayer);
308 var s: AnsiString; oldy: Integer;
309 begin
310 r_Common_DrawTexture(hudbg, x, y, w, h, TBasePoint.BP_LEFTUP);
312 if p <> nil then
313 begin
314 oldy := y;
315 if h < 239 then y := y - 32; (* hack: hide nickname on 640x400 *)
316 r_Render_DrawHUD(x + w - 196 + 2, y, p);
317 if p.Spectator then
318 begin
319 r_Common_DrawText(_lc[I_PLAYER_SPECT], x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
320 r_Common_DrawText(_lc[I_PLAYER_SPECT2], x + 4, y + 258, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
321 r_Common_DrawText(_lc[I_PLAYER_SPECT1], x + 4, y + 274, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
322 if p.NoRespawn then
323 r_Common_DrawText(_lc[I_PLAYER_SPECT1S], x + 4, y + 290, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
324 end;
325 y := oldy;
326 end;
328 if gShowPing and g_Game_IsClient then
329 begin
330 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
331 r_Common_DrawText(s, x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
332 end;
333 end;
335 procedure r_Render_DrawStatsView (x, y, w, h: Integer; p: TPlayer);
336 var fw, i, maxFrags, top, totalPlayers: Integer; sign: Char; stat: TPlayerStatArray; f: TGLTexture;
337 begin
338 ASSERT(p <> nil);
340 if gShowScore and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
341 begin
342 (* RED TEAM SCORE *)
343 fw := 0;
344 if gGameSettings.GameMode = GM_CTF then
345 begin
346 case gFlags[FLAG_RED].State of
347 FLAG_STATE_CAPTURED: f := hudrflags;
348 FLAG_STATE_DROPPED: f := hudrflagd;
349 otherwise f := hudrflag;
350 end;
351 if f <> nil then
352 begin
353 fw := f.width + 8; (* + space *)
354 r_Common_DrawTexture(f, x + w - 16, y + 240 - 72 - 4, f.width, f.height, TBasePoint.BP_RIGHTUP);
355 end;
356 end;
357 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);
359 (* BLUE TEAM SCORE *)
360 fw := 0;
361 if gGameSettings.GameMode = GM_CTF then
362 begin
363 case gFlags[FLAG_BLUE].State of
364 FLAG_STATE_CAPTURED: f := hudbflags;
365 FLAG_STATE_DROPPED: f := hudbflagd;
366 otherwise f := hudbflag;
367 end;
368 if f <> nil then
369 begin
370 fw := f.width + 8; (* + space *)
371 r_Common_DrawTexture(f, x + w - 16, y + 240 - 32 - 4, f.width, f.height, TBasePoint.BP_RIGHTUP);
372 end;
373 end;
374 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);
375 end;
377 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
378 begin
379 if gShowStat then
380 begin
381 r_Common_DrawText(IntToStr(p.Frags), x + w - 16, y, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHTUP);
383 top := 1;
384 maxFrags := 0;
385 totalPlayers := 0;
386 stat := g_Player_GetStats();
387 if stat <> nil then
388 begin
389 totalPlayers := Length(stat);
390 for i := 0 to High(stat) do
391 begin
392 if stat[i].Name <> p.Name then
393 begin
394 maxFrags := MAX(maxFrags, stat[i].Frags);
395 if stat[i].Frags > p.Frags then
396 top := top + 1;
397 end;
398 end;
399 end;
400 if p.Frags >= maxFrags then sign := '+' else sign := '-';
401 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);
402 end;
404 if gLMSRespawn > LMS_RESPAWN_NONE then
405 begin
406 r_Common_DrawText(_lc[I_GAME_WARMUP], x + w - 16 - 64, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_RIGHTDOWN);
407 r_Common_DrawText(': ' + IntToStr((gLMSRespawnTime - gTime) div 1000), x + w - 16 - 64, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_LEFTDOWN);
408 end
409 else if gShowLives and (gGameSettings.MaxLives > 0) then
410 begin
411 r_Common_DrawText(IntToStr(p.Lives), x + w - 16, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_RIGHTDOWN);
412 end;
413 end;
414 end;
416 procedure r_Render_DrawView (x, y, w, h: Integer; p: TPlayer);
417 var l, t, r, b, xx, yy, cx, cy: Integer;
418 begin
419 r_Draw_GetRect(l, t, r, b);
420 r_Draw_SetRect(x, y, x + w, y + h);
422 r_Common_GetCameraPos(p, true, xx, yy);
423 if p <> nil then
424 begin
425 r_Map_Draw(x, y, w, h, xx, yy, p, cx, cy);
426 {$IFDEF ENABLE_HOLMES}
427 if p = gPlayer1 then
428 begin
429 r_Holmes_plrViewPos(cx, cy);
430 r_Holmes_plrViewSize(h, w);
431 end;
432 {$ENDIF}
433 r_Render_DrawStatsView(x, y, w, h, p);
434 if p.Spectator and p.NoRespawn then
435 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);
436 end
437 else
438 begin
439 r_Map_Draw(x, y, w, h, xx, yy, nil, cx, cy);
440 end;
442 r_Draw_SetRect(l, t, r, b);
443 end;
445 procedure r_Render_DrawMapView (x, y, w, h, camx, camy: Integer);
446 var l, t, r, b, cx, cy: Integer;
447 begin
448 r_Draw_GetRect(l, t, r, b);
449 r_Draw_SetRect(x, y, x + w, y + h);
450 r_Map_Draw(x, y, w, h, camx, camy, nil, cx, cy);
451 r_Draw_SetRect(l, t, r, b);
452 end;
454 procedure r_Render_DrawPlayerView (x, y, w, h: Integer; p: TPlayer);
455 var l, t, r, b: Integer;
456 begin
457 r_Draw_GetRect(l, t, r, b);
458 r_Draw_SetRect(x, y, x + w, y + h);
459 r_Render_DrawView(x, y, w - 196, h, p);
460 r_Render_DrawHUDArea(x + w - 196, y, 196, h, p);
461 r_Draw_SetRect(l, t, r, b);
462 end;
464 procedure r_Render_DrawServerList (var SL: TNetServerList; var ST: TNetServerTable);
465 var ip: AnsiString; ww, hh, cw, ch, mw, mh, motdh, scrx, scry, i, mx, y: Integer; msg: SSArray; Srv: TNetServer;
466 begin
467 scrx := gScreenWidth div 2;
468 scry := gScreenHeight div 2;
470 r_Draw_GetTextSize(_lc[I_NET_SLIST], menufont, ww, hh);
471 r_Common_DrawText(_lc[I_NET_SLIST], gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
473 r_Draw_GetTextSize('W', stdfont, cw, ch);
474 motdh := gScreenHeight - 49 - ch * b_Text_LineCount(slMOTD);
476 r_Draw_FillRect(16, 64, gScreenWidth - 16, motdh, 64, 64, 64, 145);
477 r_Draw_Rect(16, 64, gScreenWidth - 16, motdh, 255, 127, 0, 255);
479 r_Common_DrawText(_lc[I_NET_SLIST_HELP], gScreenWidth div 2, gScreenHeight - 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
481 if slMOTD <> '' then
482 begin
483 r_Draw_FillRect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 64, 64, 64, 110);
484 r_Draw_Rect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 255, 127, 0, 255);
485 r_Common_DrawFormatText(slMOTD, 20, motdh + 3, 255, stdfont, TBasePoint.BP_LEFTUP);
486 end;
488 if not slReadUrgent and (slUrgent <> '') then
489 begin
490 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
491 r_Draw_FillRect(scrx - 256, scry - 60, scrx + 256, scry + 60, 64, 64, 64, 127);
492 r_Draw_Rect(scrx - 256, scry - 60, scrx + 256, scry + 60, 255, 127, 0, 255);
493 r_Draw_FillRect(scrx - 256, scry - 40, scrx + 256, scry - 40, 255, 127, 0, 255);
494 r_Common_DrawText(_lc[I_NET_SLIST_URGENT], scrx, scry - 58, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
495 r_Common_DrawFormatText(slUrgent, scrx - 253, scry - 38, 255, stdfont, TBasePoint.BP_LEFTUP);
496 r_Common_DrawText(_lc[I_NET_SLIST_URGENT_CONT], scrx, scry + 41, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
497 r_Draw_FillRect(scrx - 256, scry + 40, scrx + 256, scry + 40, 255, 127, 0, 255);
498 end
499 else if SL = nil then
500 begin
501 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
502 r_Draw_Rect(scrx - 192, scry - 10, scrx + 192, scry + 11, 255, 127, 0, 255);
503 r_Common_DrawText(slWaitStr, scrx, scry, 255, 255, 255, 255, stdfont, TBasePoint.BP_CENTER);
504 end
505 else
506 begin
507 y := 90;
508 if slSelection < Length(ST) then
509 begin
510 sy := y + 42 * slSelection - 4;
511 Srv := GetServerFromTable(slSelection, SL, ST);
512 ip := _lc[I_NET_ADDRESS] + ' ' + Srv.IP + ':' + IntToStr(Srv.Port);
513 ip := ip + ' ' + _lc[I_NET_SERVER_PASSWORD] + ' ';
514 if Srv.Password then ip := ip + _lc[I_MENU_YES] else ip := ip +_lc[I_MENU_NO];
515 end;
517 mw := gScreenWidth - 188;
518 mx := 16 + mw;
520 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy + 40, 64, 64, 64, 255);
521 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy, 205, 205, 205, 255);
522 r_Draw_FillRect(16 + 1, sy + 41, gScreenWidth - 16 - 1, sy + 41, 255, 255, 255, 255);
524 r_Draw_FillRect(16, 85, gScreenWidth - 16, 85, 255, 127, 0, 255);
525 r_Draw_FillRect(16, motdh - 20, gScreenWidth - 16, motdh - 20, 255, 127, 0, 255);
527 r_Draw_FillRect(mx - 70, 64, mx - 70, motdh, 255, 127, 0, 255);
528 r_Draw_FillRect(mx, 64, mx, motdh - 20, 255, 127, 0, 255);
529 r_Draw_FillRect(mx + 52, 64, mx + 52, motdh - 20, 255, 127, 0, 255);
530 r_Draw_FillRect(mx + 104, 64, mx + 104, motdh - 20, 255, 127, 0, 255);
532 r_Common_DrawText('NAME/MAP', 18, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
533 r_Common_DrawText('PING', mx - 68, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
534 r_Common_DrawText('MODE', mx + 2, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
535 r_Common_DrawText('PLRS', mx + 54, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
536 r_Common_DrawText('VER', mx + 106, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
538 for i := 0 to High(ST) do
539 begin
540 Srv := GetServerFromTable(i, SL, ST);
541 r_Common_DrawText(Srv.Name, 18, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
542 r_Common_DrawText(Srv.Map, 18, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
544 if Srv.Ping = 0 then
545 r_Common_DrawText('<1' + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
546 else if (Srv.Ping >= 0) and (Srv.Ping <= 999) then
547 r_Common_DrawText(IntToStr(Srv.Ping) + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
548 else
549 r_Common_DrawText(_lc[I_NET_SLIST_NO_ACCESS], mx - 68, y, 255, 0, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
550 if Length(ST[I].Indices) > 1 then
551 r_Common_DrawText('<' + IntToStr(Length(ST[I].Indices)) + '>', mx - 68, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
553 r_Common_DrawText(g_Game_ModeToText(Srv.GameMode), mx + 2, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
555 r_Common_DrawText(IntToStr(Srv.Players) + '/' + IntToStr(Srv.MaxPlayers), mx + 54, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
556 r_Common_DrawText(IntToStr(Srv.LocalPl) + '+' + IntToStr(Srv.Bots), mx + 54, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
558 r_Common_DrawText(IntToStr(Srv.Protocol), mx + 106, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
560 y := y + 42;
561 end;
563 r_Common_DrawText(ip, 20, motdh - 20 + 3, 205, 205, 205, 255, stdfont, TBasePoint.BP_LEFTUP);
564 r_Common_DrawText(IntToStr(Length(ST)) + _lc[I_NET_SLIST_SERVERS], gScreenWidth - 48, motdh - 20 + 3, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
565 end;
566 end;
568 procedure r_Render_DrawStatsColumns (constref cs: TEndCustomGameStat; x, y, w: Integer; endview: Boolean);
569 var i, cw, ch, yy, team, players, w1, w2, w3, w4, tw: Integer; r, g, b, rr, gg, bb: Byte; s: AnsiString;
570 begin
571 r_Draw_GetTextSize('W', stdfont, cw, ch);
572 w4 := cw * 6; (* deaths width *)
573 w3 := cw * 8; (* frags width *)
574 w2 := cw * 12; (* ping/loss width *)
575 w1 := w - w2 - w3 - w4; (* name width *)
576 tw := w1 - cw * 2 - w2; (* team score *)
577 if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
578 yy := y;
579 if cs.GameMode in [GM_TDM, GM_CTF] then
580 begin
581 for team := TEAM_RED to TEAM_BLUE do
582 begin
583 case team of
584 TEAM_RED:
585 begin
586 s := _lc[I_GAME_TEAM_RED];
587 r := 255; g := 0; b := 0;
588 end;
589 TEAM_BLUE:
590 begin
591 s := _lc[I_GAME_TEAM_BLUE];
592 r := 0; g := 0; b := 255;
593 end;
594 end;
595 r_Common_DrawText(s, x, yy, r, g, b, 255, stdfont, TBasePoint.BP_LEFTUP);
596 r_Common_DrawText(IntToStr(cs.TeamStat[team].Score), x + tw, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
597 if endview = false then
598 r_Common_DrawText(_lc[I_GAME_PING], x + w1, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
599 r_Common_DrawText(_lc[I_GAME_FRAGS], x + w1 + w2, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
600 r_Common_DrawText(_lc[I_GAME_DEATHS], x + w1 + w2 + w3, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
601 INC(yy, ch);
603 INC(yy, ch div 4);
604 r_Draw_FillRect(x, yy, x + w - 1, yy, r, g, b, 255);
605 INC(yy, ch div 4);
607 for i := 0 to players - 1 do
608 begin
609 if cs.PlayerStat[i].Team = team then
610 begin
611 rr := r; gg := g; bb := b;
612 if cs.PlayerStat[i].Spectator then
613 begin
614 rr := r div 2; gg := g div 2; bb := b div 2;
615 end;
617 // Player name
618 if gShowPIDs then s := Format('[%5d] %s', [cs.PlayerStat[i].UID, cs.PlayerStat[i].Name]) else s := cs.PlayerStat[i].Name;
619 if (gPlayers[cs.PlayerStat[i].Num] <> nil) and (gPlayers[cs.PlayerStat[i].Num].FReady) then s := s + ' *';
620 r_Common_DrawText(s, x, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_LEFTUP);
621 if endview = false then
622 begin
623 // Player ping/loss
624 s := Format(_lc[I_GAME_PING_MS], [cs.PlayerStat[i].Ping, cs.PlayerStat[i].Loss]);
625 r_Common_DrawText(s, x + w1, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
626 end;
627 // Player frags
628 s := IntToStr(cs.PlayerStat[i].Frags);
629 r_Common_DrawText(s, x + w1 + w2, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
630 // Player deaths
631 s := IntToStr(cs.PlayerStat[i].Deaths);
632 r_Common_DrawText(s, x + w1 + w2 + w3, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
634 INC(yy, ch);
635 end;
636 end;
637 INC(yy, ch);
638 end;
639 end
640 else if cs.GameMode in [GM_DM, GM_COOP] then
641 begin
642 r_Common_DrawText(_lc[I_GAME_PLAYER_NAME], x, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
643 if endview = false then
644 r_Common_DrawText(_lc[I_GAME_PING], x + w1, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
645 r_Common_DrawText(_lc[I_GAME_FRAGS], x + w1 + w2, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
646 r_Common_DrawText(_lc[I_GAME_DEATHS], x + w1 + w2 + w3, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
647 INC(yy, ch + ch div 2);
648 for i := 0 to players - 1 do
649 begin
650 // rr := 255; gg := 127; bb := 0;
651 rr := 255; gg := 255; bb := 255;
652 if cs.PlayerStat[i].Spectator then
653 begin
654 rr := rr div 2; gg := gg div 2; bb := bb div 2;
655 end;
657 // Player color
658 r_Draw_Rect(x, yy, x + 16 - 1, yy + 16 - 1, 192, 192, 192, 255);
659 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);
660 // Player name
661 if gShowPIDs then s := Format('[%5d] %s', [cs.PlayerStat[i].UID, cs.PlayerStat[i].Name]) else s := cs.PlayerStat[i].Name;
662 if (gPlayers[cs.PlayerStat[i].Num] <> nil) and (gPlayers[cs.PlayerStat[i].Num].FReady) then s := s + ' *';
663 r_Common_DrawText(s, x + 16 + 8, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_LEFTUP);
664 if endview = false then
665 begin
666 // Player ping/loss
667 s := Format(_lc[I_GAME_PING_MS], [cs.PlayerStat[i].Ping, cs.PlayerStat[i].Loss]);
668 r_Common_DrawText(s, x + w1, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
669 end;
670 // Player frags
671 s := IntToStr(cs.PlayerStat[i].Frags);
672 r_Common_DrawText(s, x + w1 + w2, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
673 // Player deaths
674 s := IntToStr(cs.PlayerStat[i].Deaths);
675 r_Common_DrawText(s, x + w1 + w2 + w3, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
677 INC(yy, ch + ch div 2);
678 end;
679 end;
680 end;
682 procedure r_Render_DrawStatsWindow (x, y, w, h: Integer; cs: TEndCustomGameStat; endview: Boolean);
683 var xoff, yoff, cw, ch: Integer; s: AnsiString;
684 begin
685 xoff := 0; yoff := 8;
686 r_Draw_GetTextSize('W', stdfont, cw, ch);
687 r_Draw_FillRect(x, y, x + w - 1, y + h - 1, 64, 64, 64, 224);
688 r_Draw_Rect(x, y, x + w - 1, y + h - 1, 255, 127, 0, 255);
690 (* LINE 1 *)
692 if endview = false then
693 begin
694 case NetMode of
695 NET_SERVER: s := _lc[I_NET_SERVER];
696 NET_CLIENT: s := NetClientIP + ':' + IntToStr(NetClientPort);
697 otherwise s := '';
698 end;
699 r_Common_DrawText(s, x + 16, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
700 end;
702 case cs.GameMode of
703 GM_DM: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_DM] else s := _lc[I_GAME_LMS];
704 GM_TDM: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_TDM] else s := _lc[I_GAME_TLMS];
705 GM_CTF: s := _lc[I_GAME_CTF];
706 GM_COOP: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_COOP] else s := _lc[I_GAME_SURV];
707 otherwise s := 'GAME MODE ' + IntToStr(gGameSettings.GameMode);
708 end;
709 r_Common_DrawText(s, x + w div 2, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
711 if endview = false then
712 begin
713 s := r_Common_TimeToStr(cs.GameTime);
714 r_Common_DrawText(s, x + w - 16, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
715 end;
717 INC(yoff, ch + ch div 2);
719 (* LINE 2/3 *)
721 s := cs.Map;
722 if cs.MapName <> '' then
723 s := s + ' - ' + cs.MapName;
725 if endview = false then
726 begin
727 r_Common_DrawText(s, x + w div 2, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_UP);
728 INC(yoff, ch + ch div 2);
729 case cs.GameMode of
730 GM_DM, GM_TDM: s := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]);
731 GM_CTF: s := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.ScoreLimit]);
732 GM_COOP: s := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
733 otherwise s := '';
734 end;
735 r_Common_DrawText(s, x + 16, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_LEFTUP);
736 case cs.GameMode of
737 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]);
738 GM_COOP: s := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
739 otherwise s := '';
740 end;
741 r_Common_DrawText(s, x + w - 16, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_RIGHTUP);
742 INC(yoff, ch);
743 end
744 else
745 begin
746 xoff := MAX(Length(_lc[I_MENU_MAP]) + 1, Length(_lc[I_GAME_GAME_TIME]) + 1) * cw;
747 r_Common_DrawText(_lc[I_MENU_MAP], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
748 r_Common_DrawText(s, x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
749 INC(yoff, ch);
750 r_Common_DrawText(_lc[I_GAME_GAME_TIME], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
751 r_Common_DrawText(r_Common_TimeToStr(cs.GameTime), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
752 INC(yoff, ch);
753 end;
755 INC(yoff, ch);
757 (* LINE 4/5 *)
759 if endview and (cs.GameMode = GM_COOP) then
760 begin
761 xoff := MAX(Length(_lc[I_GAME_MONSTERS]) + 1, Length(_lc[I_GAME_SECRETS]) + 1) * cw;
762 r_Common_DrawText(_lc[I_GAME_MONSTERS], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
763 r_Common_DrawText(IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
764 INC(yoff, ch);
765 r_Common_DrawText(_lc[I_GAME_SECRETS], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
766 r_Common_DrawText(IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
767 INC(yoff, ch);
768 INC(yoff, ch);
769 end;
771 (* LINE 6/7 *)
773 if endview and (cs.GameMode = GM_COOP) and gLastMap then
774 begin
775 xoff := MAX(Length(_lc[I_GAME_MONSTERS_TOTAL]) + 1, Length(_lc[I_GAME_SECRETS_TOTAL]) + 1) * cw;
776 r_Common_DrawText(_lc[I_GAME_MONSTERS_TOTAL], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
777 r_Common_DrawText(IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
778 INC(yoff, ch);
779 r_Common_DrawText(_lc[I_GAME_SECRETS_TOTAL], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
780 r_Common_DrawText(IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
781 INC(yoff, ch);
782 INC(yoff, ch);
783 end;
785 (* LINE *)
787 if endview and (cs.GameMode in [GM_TDM, GM_CTF]) then
788 begin
789 if cs.TeamStat[TEAM_RED].Score > cs.TeamStat[TEAM_BLUE].Score then s := _lc[I_GAME_WIN_RED]
790 else if cs.TeamStat[TEAM_BLUE].Score > cs.TeamStat[TEAM_RED].Score then s := _lc[I_GAME_WIN_BLUE]
791 else s := _lc[I_GAME_WIN_DRAW];
792 r_Common_DrawText(s, x + w div 2, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
793 INC(yoff, ch);
794 INC(yoff, ch);
795 end;
797 (* LINE n *)
799 r_Render_DrawStatsColumns(cs, x + 16, y + yoff, w - 16 - 16, endview);
800 end;
802 function r_Render_StatsHeight (players: Integer): Integer;
803 var cw, ch: Integer;
804 begin
805 ASSERT(players >= 0);
806 r_Draw_GetTextSize('W', stdfont, cw, ch);
807 case gGameSettings.GameMode of
808 GM_TDM, GM_CTF: result := 32 + ch * (11 + players);
809 otherwise result := 40 + ch * 5 + (ch + 8) * players;
810 end;
811 end;
813 procedure r_Render_DrawStats;
814 var x, y, w, h, players: Integer; cs: TEndCustomGameStat;
815 begin
816 cs.PlayerStat := g_Player_GetStats();
817 SortGameStat(cs.PlayerStat);
818 cs.TeamStat := gTeamStat;
819 cs.GameTime := gTime;
820 cs.GameMode := gGameSettings.GameMode;
821 cs.Map := g_ExtractWadNameNoPath(gMapInfo.Map) + ':' + g_ExtractFileName(gMapInfo.Map);
822 cs.MapName := gMapInfo.Name;
823 if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
824 w := gScreenWidth - (gScreenWidth div 5);
825 h := r_Render_StatsHeight(players);
826 x := (gScreenWidth div 2) - (w div 2);
827 y := (gScreenHeight div 2) - (h div 2);
828 r_Render_DrawStatsWindow(x, y, w, h, cs, false);
829 end;
831 procedure r_Render_DrawCustomStats;
832 var cw, ch, s: AnsiString;
833 begin
834 if gStatsOff then
835 begin
836 r_Common_DrawText(_lc[I_MENU_INTER_NOTICE_TAB], gScreenWidth div 2, 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
837 end
838 else
839 begin
840 case gGameSettings.GameMode of
841 GM_COOP: if gMissionFailed then s := _lc[I_MENU_INTER_MISSION_FAIL] else s := _lc[I_MENU_INTER_LEVEL_COMPLETE];
842 otherwise s := _lc[I_MENU_INTER_ROUND_OVER];
843 end;
844 r_Common_DrawText(s, gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
846 if gChatShow = false then
847 begin
848 if g_Game_IsClient then s := _lc[I_MENU_INTER_NOTICE_MAP] else s := _lc[I_MENU_INTER_NOTICE_SPACE];
849 r_Common_DrawText(s, gScreenWidth div 2, gScreenHeight - 4, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
850 if g_Game_IsNet then
851 begin
852 s := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
853 r_Common_DrawText(s, gScreenWidth div 2, gScreenHeight - 16 - 4, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
854 end;
855 end;
857 r_Render_DrawStatsWindow(32, 64, gScreenWidth - 32 * 2, gScreenHeight - 64 * 2, CustomStat, true);
858 end;
859 end;
861 procedure r_Render_DrawValueOf (a, b, x, y: Integer; f: TGLFont);
862 var wa, wb, ch: Integer; sa, sb: AnsiString;
863 begin
864 sa := IntToStr(a);
865 sb := IntToStr(b);
866 r_Draw_GetTextSize(sa, f, wa, ch);
867 r_Draw_GetTextSize(sa + ' / ', f, wb, ch);
868 r_Common_DrawText(sa, x, y, 255, 0, 0, 255, f, TBasePoint.BP_LEFTUP);
869 r_Common_DrawText(' / ', x + wa, y, 255, 255, 255, 255, f, TBasePoint.BP_LEFTUP);
870 r_Common_DrawText(sb, x + wb, y, 255, 0, 0, 255, f, TBasePoint.BP_LEFTUP);
871 end;
873 procedure r_Render_DrawSinglStatsPlayer (player, x, y, w1: Integer);
874 var time, kpm: Single;
875 begin
876 r_Common_DrawText(_lc[I_MENU_INTER_KILLS], x, y, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
877 r_Render_DrawValueOf(SingleStat.PlayerStat[player].Kills, gTotalMonsters, x + w1, y, MenuFont);
878 r_Common_DrawText(_lc[I_MENU_INTER_KPM], x, y + 32, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
879 time := SingleStat.GameTime / 1000;
880 kpm := SingleStat.PlayerStat[player].Kills;
881 if time > 0 then kpm := kpm / time * 60;
882 r_Common_DrawText(Format('%.1f', [kpm]), x + w1, y + 32, 255, 0, 0, 255, menufont, TBasePoint.BP_LEFTUP);
883 r_Common_DrawText(_lc[I_MENU_INTER_SECRETS], x, y + 64, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
884 r_Render_DrawValueOf(SingleStat.PlayerStat[player].Secrets, SingleStat.TotalSecrets, x + w1, y + 64, MenuFont);
885 end;
887 procedure r_Render_DrawSingleStats;
888 var xx, wa, wb, ww, ch: Integer; s: AnsiString;
889 begin
890 r_Common_DrawText(_lc[I_MENU_INTER_LEVEL_COMPLETE], gScreenWidth div 2, 32, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
892 r_Draw_GetTextSize(_lc[I_MENU_INTER_KPM] + ' ', menufont, wa, ch);
893 r_Draw_GetTextSize(' 9999.9', menufont, wb, ch);
894 ww := wa + wb;
895 xx := gScreenWidth div 2 - ww div 2;
897 s := r_Common_TimeToStr(SingleStat.GameTime);
898 r_Common_DrawText(_lc[I_MENU_INTER_TIME], xx, 80, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
899 r_Common_DrawText(s, xx + wa, 80, 255, 0, 0, 255, menufont, TBasePoint.BP_LEFTUP);
901 if SingleStat.TwoPlayers then
902 begin
903 r_Common_DrawText(_lc[I_MENU_PLAYER_1], gScreenWidth div 2, 128, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
904 r_Render_DrawSinglStatsPlayer(0, xx, 176, wa);
905 r_Common_DrawText(_lc[I_MENU_PLAYER_2], gScreenWidth div 2, 288, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
906 r_Render_DrawSinglStatsPlayer(1, xx, 336, wa);
907 end
908 else
909 begin
910 r_Render_DrawSinglStatsPlayer(0, xx, 128, wa);
911 end;
912 end;
914 procedure r_Render_DrawSpectHud;
915 var xoff: Integer; s: AnsiString;
917 procedure AddText (s1, s2: AnsiString);
918 var w1, w2, ww, ch: Integer;
919 begin
920 r_Draw_GetTextSize(s1, stdfont, w1, ch);
921 r_Draw_GetTextSize(s2, stdfont, w2, ch);
922 ww := MAX(w1, w2);
923 r_Common_DrawText(s1, xoff + ww div 2, gScreenHeight - ch, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
924 r_Common_DrawText(s2, xoff + ww div 2, gScreenHeight - ch, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
925 xoff := xoff + ww + 16;
926 end;
928 begin
929 xoff := 0;
930 case gSpectMode of
931 SPECT_STATS: s := 'MODE: Stats';
932 SPECT_MAPVIEW: s := 'MODE: Observe Map';
933 SPECT_PLAYERS: s := 'MODE: Watch Players';
934 otherwise s := 'MODE: ' + IntToStr(gSpectMode);
935 end;
936 AddText(s, '< jump >');
937 if gSpectMode = SPECT_STATS then
938 AddText('Autoview', '< fire >');
939 if gSpectMode = SPECT_MAPVIEW then
940 AddText('[-] Step ' + IntToStr(gSpectStep) + ' [+]', '<prev weap> <next weap>');
941 if gSpectMode = SPECT_PLAYERS then
942 begin
943 AddText('Player 1', '<left/right>');
944 if gSpectViewTwo then
945 AddText('Player 2', '<prev w/next w>');
946 AddText('2x View', '<up/down>');
947 end;
948 end;
950 function GetActivePlayer_ByID (id: Integer): TPlayer;
951 var i, len: Integer; p: TPlayer;
952 begin
953 p := nil;
954 if (id >= 0) and (gPlayers <> nil) then
955 begin
956 i := 0; len := Length(gPlayers);
957 while (i < len) and ((IsActivePlayer(gPlayers[i]) = false) or (gPlayers[i].UID <> id)) do INC(i);
958 if i < len then p := gPlayers[i];
959 end;
960 result := p;
961 end;
963 procedure r_Render_DrawMinimap (x, y: Integer; alpha: Byte);
964 const scale = 16;
966 function IsMinimapPanel (const p: TPanel): Boolean;
967 begin
968 result := (p <> nil) and p.Enabled;
969 if result then
970 begin
971 case p.PanelType of
972 PANEL_WALL, PANEL_WATER, PANEL_ACID1, PANEL_ACID2,
973 PANEL_STEP, PANEL_OPENDOOR, PANEL_CLOSEDOOR,
974 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
975 result := true;
976 otherwise
977 result := false;
978 end;
979 end;
980 end;
982 procedure DrawObject (xx, yy, ww, hh: Integer; r, g, b: Byte);
983 var x0, y0, x1, y1: Integer;
984 begin
985 x0 := x + xx div scale;
986 y0 := y + yy div scale;
987 x1 := x + (xx + ww - 1) div scale;
988 y1 := y + (yy + hh - 1) div scale;
989 r_Draw_FillRect(x0, y0, x1, y1, r, g, b, alpha);
990 end;
992 procedure DrawPanels (const a: TPanelArray);
993 var i: Integer; p: TPanel; c: TRGB;
994 begin
995 if a <> nil then
996 begin
997 for i := 0 to HIGH(a) do
998 begin
999 p := a[i];
1000 if IsMinimapPanel(p) then
1001 begin
1002 case p.PanelType of
1003 PANEL_WALL: c := _RGB(208, 208, 208);
1004 PANEL_OPENDOOR: c := _RGB(160, 160, 160);
1005 PANEL_CLOSEDOOR: c := _RGB(160, 160, 160);
1006 PANEL_STEP: c := _RGB(128, 128, 128);
1007 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
1008 case p.LiftType of
1009 LIFTTYPE_UP: c := _RGB(116, 72, 36);
1010 LIFTTYPE_DOWN: c := _RGB(116, 124, 96);
1011 LIFTTYPE_LEFT: c := _RGB(116, 200, 80);
1012 LIFTTYPE_RIGHT: c := _RGB(116, 252, 140);
1013 otherwise c := _RGB(255, 0, 0);
1014 end;
1015 PANEL_WATER: c := _RGB(0, 0, 192);
1016 PANEL_ACID1: c := _RGB(0, 176, 0);
1017 PANEL_ACID2: c := _RGB(176, 0, 0);
1018 otherwise c := _RGB(255, 0, 0);
1019 end;
1020 DrawObject(p.x, p.y, p.width, p.height, c.r, c.g, c.b);
1021 end;
1022 end;
1023 end;
1024 end;
1026 procedure DrawPlayers;
1027 var i: Integer; p: TPlayer; c: TRGB;
1028 begin
1029 if gPlayers <> nil then
1030 begin
1031 for i := 0 to HIGH(gPlayers) do
1032 begin
1033 p := gPlayers[i];
1034 if p.Alive then
1035 begin
1036 case p.Team of
1037 TEAM_RED: c := _RGB(255, 0, 0);
1038 TEAM_BLUE: c := _RGB(0, 0, 255);
1039 otherwise c := _RGB(255, 128, 0);
1040 end;
1041 DrawObject(p.obj.x, p.obj.y, p.obj.rect.width, p.obj.rect.height, c.r, c.g, c.b);
1042 end;
1043 end;
1044 end;
1045 end;
1047 function DrawMonster (m: TMonster): Boolean;
1048 begin
1049 result := false; // don't stop
1050 if m.alive then
1051 DrawObject(m.obj.x, m.obj.y, m.obj.rect.width, m.obj.rect.height, 255, 255, 0);
1052 end;
1054 begin
1055 r_Draw_FillRect(x, y, (x + gMapInfo.Width - 1) div scale, (y + gMapInfo.Height - 1) div scale, 0, 0, 0, alpha);
1056 DrawPanels(gSteps);
1057 DrawPanels(gLifts);
1058 DrawPanels(gWater);
1059 DrawPanels(gAcid1);
1060 DrawPanels(gAcid2);
1061 DrawPanels(gWalls);
1062 g_Mons_ForEach(DrawMonster);
1063 DrawPlayers;
1064 end;
1066 procedure r_Render_Draw;
1067 var p1, p2: TPlayer; time: LongWord; pw, ph: Integer;
1068 begin
1069 if gExit = EXIT_QUIT then
1070 exit;
1072 {$IFDEF ENABLE_SYSTEM}
1073 (* hack: if r_pixel_scale changed, reset menu and other things *)
1074 pw := Round(gWinSizeX / r_pixel_scale);
1075 ph := Round(gWinSizeY / r_pixel_scale);
1076 if (pw <> gScreenWidth) or (ph <> gScreenHeight) then
1077 if assigned(sys_ScreenResize) then
1078 sys_ScreenResize(gWinSizeX, gWinSizeY);
1079 {$ENDIF}
1081 INC(FPSCounter);
1082 time := GetTickCount64();
1083 if time - FPSTime >= 1000 then
1084 begin
1085 FPS := FPSCounter;
1086 FPSCounter := 0;
1087 FPSTime := time;
1088 end;
1090 r_Draw_Setup(gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight);
1092 glClearColor(0.0, 0.0, 0.0, 0.0);
1093 glClear(GL_COLOR_BUFFER_BIT);
1095 p1 := nil;
1096 p2 := nil;
1097 if gGameOn or (gState = STATE_FOLD) then
1098 begin
1099 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
1100 begin
1101 if gRevertPlayers then
1102 begin
1103 p1 := gPlayer2;
1104 p2 := gPlayer1;
1105 end
1106 else
1107 begin
1108 p1 := gPlayer1;
1109 p2 := gPlayer2;
1110 end;
1111 end
1112 else if gPlayer1 <> nil then
1113 begin
1114 p1 := gPlayer1;
1115 end
1116 else if gPlayer2 <> nil then
1117 begin
1118 p1 := gPlayer2;
1119 end;
1120 if (gSpectMode = SPECT_PLAYERS) and (gPlayers <> nil) then
1121 begin
1122 p1 := GetActivePlayer_ByID(gSpectPID1);
1123 if p1 = nil then
1124 p1 := GetActivePlayer_ByID(GetActivePlayerID_Next());
1125 if gSpectViewTwo then
1126 begin
1127 p2 := GetActivePlayer_ByID(gSpectPID2);
1128 if p2 = nil then
1129 p2 := GetActivePlayer_ByID(GetActivePlayerID_Next());
1130 end;
1131 end;
1132 end;
1134 if gGameOn or ((gState in [STATE_FOLD]) and (EndingGameCounter < 255)) then
1135 begin
1136 if gSpectMode = SPECT_MAPVIEW then
1137 begin
1138 r_Render_DrawMapView(0, 0, gScreenWidth, gScreenHeight, gSpectX + gScreenWidth div 2, gSpectY + gScreenHeight div 2);
1139 end
1140 else if (p1 <> nil) and (p2 <> nil) then
1141 begin
1142 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight div 2 - 2, p1);
1143 r_Render_DrawPlayerView(0, gScreenHeight div 2 + 2, gScreenWidth, gScreenHeight div 2, p2);
1144 end
1145 else if p1 <> nil then
1146 begin
1147 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, p1);
1148 end
1149 else if p2 <> nil then
1150 begin
1151 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, p2);
1152 end;
1154 if gShowMap then
1155 r_Render_DrawMiniMap(0, 0, 160);
1157 {$IFDEF ENABLE_HOLMES}
1158 r_Holmes_Draw;
1159 {$ENDIF}
1161 if MessageText <> '' then
1162 r_Common_DrawFormatText(MessageText, (gScreenWidth - 196) div 2, gScreenHeight div 2, 255, menufont, TBasePoint.BP_CENTER);
1164 if IsDrawStat or (gSpectMode = SPECT_STATS) then
1165 r_Render_DrawStats;
1167 if gSpectHUD and (gChatShow = false) and (gSpectMode <> SPECT_NONE) and (gSpectAuto = false) then
1168 r_Render_DrawSpectHud;
1169 end;
1171 if gPauseMain and gGameOn {$IFDEF ENABLE_MENU}and (g_ActiveWindow = nil){$ENDIF} then
1172 begin
1173 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1174 r_Common_DrawText(_lc[I_MENU_PAUSE], gScreenWidth div 2, gScreenHeight div 2, 255, 255, 255, 255, menufont, TBasePoint.BP_CENTER);
1175 end;
1177 if not gGameOn then
1178 begin
1179 // TODO F key handle
1180 case gState of
1181 STATE_NONE: (* do nothing *) ;
1182 STATE_MENU: r_Common_DrawBackground(GameWad + ':TEXTURES/TITLE');
1183 STATE_FOLD:
1184 begin
1185 if EndingGameCounter > 0 then
1186 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
1187 end;
1188 STATE_INTERCUSTOM:
1189 begin
1190 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1191 if EndPicPath <> '' then
1192 r_Common_DrawBackground(EndPicPath)
1193 else
1194 r_Common_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC])
1195 else
1196 r_Common_DrawBackground(GameWad + ':TEXTURES/INTER');
1198 r_Render_DrawCustomStats;
1200 {$IFDEF ENABLE_MENU}
1201 if g_ActiveWindow <> nil then
1202 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1203 {$ENDIF}
1204 end;
1205 STATE_INTERSINGLE, STATE_INTERTEXT, STATE_INTERPIC:
1206 begin
1207 if EndingGameCounter > 0 then
1208 begin
1209 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
1210 end
1211 else
1212 begin
1213 r_Common_DrawBackground(GameWad + ':TEXTURES/INTER');
1214 r_Render_DrawSingleStats;
1215 {$IFDEF ENABLE_MENU}
1216 if g_ActiveWindow <> nil then
1217 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1218 {$ENDIF}
1219 end;
1220 end;
1221 STATE_ENDPIC:
1222 begin
1223 if EndPicPath <> '' then
1224 r_Common_DrawBackground(EndPicPath)
1225 else
1226 r_Common_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC]);
1227 {$IFDEF ENABLE_MENU}
1228 if g_ActiveWindow <> nil then
1229 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1230 {$ENDIF}
1231 end;
1232 STATE_SLIST:
1233 begin
1234 r_Common_DrawBackground(GameWad + ':TEXTURES/TITLE');
1235 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1236 r_Render_DrawServerList(slCurrent, slTable);
1237 end;
1238 end;
1239 end;
1241 {$IFDEF ENABLE_MENU}
1242 if g_ActiveWindow <> nil then
1243 begin
1244 if gGameOn then
1245 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1246 r_GUI_Draw_Window(g_ActiveWindow);
1247 end;
1248 {$ENDIF}
1250 r_Console_Draw(false);
1252 // TODO g_debug_Sounds
1254 if gShowFPS then
1255 begin
1256 r_Common_DrawText('FPS: ' + IntToStr(FPS), 0, 0, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
1257 r_Common_DrawText('UPS: ' + IntToStr(UPS), 0, 16, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
1258 end;
1260 if gGameOn and gShowTime then
1261 begin
1262 r_Common_DrawText(r_Common_TimeToStr(gTime), gScreenWidth - 4, gScreenHeight - 1, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTDOWN);
1263 end;
1265 // TODO draw profilers
1267 {$IFDEF ENABLE_HOLMES}
1268 r_Holmes_DrawUI;
1269 {$ENDIF}
1271 {$IFDEF ENABLE_TOUCH}
1272 glScalef(1 / r_pixel_scale, 1 / r_pixel_scale, 0);
1273 r_Touch_Draw;
1274 {$ENDIF}
1276 sys_Repaint;
1277 end;
1279 procedure r_Render_Resize (w, h: Integer);
1280 begin
1281 gWinSizeX := w;
1282 gWinSizeY := h;
1283 gRC_Width := w;
1284 gRC_Height := h;
1285 gScreenWidth := Round(w / r_pixel_scale);
1286 gScreenHeight := Round(h / r_pixel_scale);
1287 end;
1289 procedure r_Render_Apply;
1290 begin
1291 {$IFDEF ENABLE_SYSTEM}
1292 if sys_SetDisplayModeGL(GetInfo()) then
1293 e_LogWriteln('resolution changed')
1294 else
1295 e_LogWriteln('resolution not changed');
1296 sys_EnableVSync(gVSync);
1297 {$ENDIF}
1298 {$IFDEF NOGL_INIT}
1299 nogl_Init;
1300 {$ENDIF}
1301 end;
1303 function r_Render_WriteScreenShot (filename: String): Boolean;
1304 begin
1305 // TODO write screenshot file
1306 Result := False;
1307 end;
1309 {$IFDEF ENABLE_GIBS}
1310 function r_Render_GetGibRect (m, id: Integer): TRectWH;
1311 begin
1312 result := r_Map_GetGibSize(m, id);
1313 end;
1314 {$ENDIF}
1316 {$IFDEF ENABLE_GFX}
1317 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
1318 begin
1319 r_Map_NewGFX(AnimType, X, Y);
1320 end;
1321 {$ENDIF}
1323 {$IFDEF ENABLE_TOUCH}
1324 procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
1325 begin
1326 r_Touch_GetKeyRect(key, x, y, w, h, founded)
1327 end;
1328 {$ENDIF}
1330 {$IFDEF ENABLE_MENU}
1331 procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
1332 begin
1333 r_GUI_GetSize(ctrl, w, h);
1334 end;
1336 procedure r_Render_GetLogoSize (out w, h: Integer);
1337 begin
1338 r_GUI_GetLogoSize(w, h);
1339 end;
1341 procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
1342 begin
1343 r_GUI_GetMaxFontSize(BigFont, w, h);
1344 end;
1346 procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
1347 begin
1348 r_GUI_GetStringSize(BigFont, str, w, h);
1349 end;
1350 {$ENDIF}
1352 procedure r_Render_SetProcessLoadingCallback (p: TProcedure);
1353 begin
1354 r_Common_ProcessLoadingCallback := p;
1355 end;
1357 procedure r_Render_ClearLoading;
1358 begin
1359 r_Common_ClearLoading;
1360 end;
1362 procedure r_Render_SetLoading (const text: String; maxval: Integer);
1363 begin
1364 r_Common_SetLoading(text, maxval);
1365 end;
1367 procedure r_Render_StepLoading (incval: Integer);
1368 begin
1369 r_Common_StepLoading(incval);
1370 end;
1372 procedure r_Render_DrawLoading (force: Boolean);
1373 begin
1374 r_Common_DrawLoading(force);
1375 end;
1377 {$IFDEF ENABLE_HOLMES}
1378 function pmsCurMapX (): Integer;
1379 begin
1380 result := r_holmes.pmsCurMapX();
1381 end;
1383 function pmsCurMapY (): Integer;
1384 begin
1385 result := r_holmes.pmsCurMapY();
1386 end;
1388 function r_Render_HolmesViewIsSet (): Boolean;
1389 begin
1390 result := vpSet;
1391 end;
1392 {$ENDIF}
1394 end.