DEADSOFTWARE

d63137edc2aae8f48fd46c2441c9753e4f807a2c
[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 (* window background *)
477 r_Draw_Rect(16, 64, gScreenWidth - 16, motdh + 1, 255, 127, 0, 255);
478 r_Draw_FillRect(16 + 1, 64 + 1, gScreenWidth - 16 - 1, motdh, 64, 64, 64, 145);
480 r_Common_DrawText(_lc[I_NET_SLIST_HELP], gScreenWidth div 2, gScreenHeight - 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
482 if slMOTD <> '' then
483 begin
484 r_Draw_Rect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 255, 127, 0, 255);
485 r_Draw_FillRect(16 + 1, motdh + 1, gScreenWidth - 16 - 1, gScreenHeight - 44 - 1, 64, 64, 64, 145);
486 r_Common_DrawFormatText(slMOTD, 20, motdh + 3, 255, stdfont, TBasePoint.BP_LEFTUP);
487 end;
489 if not slReadUrgent and (slUrgent <> '') then
490 begin
491 r_Draw_Rect(scrx - 256, scry - 60, scrx + 256, scry + 60 + 1, 255, 127, 0, 255);
492 r_Draw_FillRect(scrx - 256 + 1, scry - 60 + 1, scrx + 256 - 1, scry + 60, 64, 64, 64, 127);
493 r_Draw_FillRect(scrx - 256, scry - 40, scrx + 256, scry - 40 + 1, 255, 127, 0, 255);
494 r_Draw_FillRect(scrx - 256, scry + 40, scrx + 256, scry + 40 + 1, 255, 127, 0, 255);
495 r_Common_DrawText(_lc[I_NET_SLIST_URGENT], scrx, scry - 58, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
496 r_Common_DrawText(_lc[I_NET_SLIST_URGENT_CONT], scrx, scry + 41, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
497 r_Common_DrawFormatText(slUrgent, scrx - 253, scry - 38, 255, stdfont, TBasePoint.BP_LEFTUP);
498 end
499 else if SL = nil then
500 begin
501 r_Draw_Rect(scrx - 192, scry - 10, scrx + 192, scry + 10, 255, 127, 0, 255);
502 r_Draw_FillRect(scrx - 192 + 1, scry - 10 + 1, scrx + 192 - 1, scry + 10 - 1, 64, 64, 64, 145);
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 (* current selection *)
521 r_Draw_FillRect(16 + 1, sy + 1, gScreenWidth - 16 - 1, sy + 1 + 40, 64, 64, 64, 255);
522 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy + 1, 255, 255, 255, 255);
523 r_Draw_FillRect(16 + 1, sy + 1 + 40, gScreenWidth - 16 - 1, sy + 1 + 40 + 1, 255, 255, 255, 255);
525 (* line separators for name/ping/mode.. & address/pasword *)
526 r_Draw_FillRect(16, 85, gScreenWidth - 16, 85 + 1, 255, 127, 0, 255);
527 r_Draw_FillRect(16, motdh - 20, gScreenWidth - 16, motdh - 20 + 1, 255, 127, 0, 255);
529 (* column separators for name/ping/mode/players/version *)
530 r_Draw_FillRect(mx - 70, 64 + 1, mx - 70 + 1, motdh, 255, 127, 0, 255);
531 r_Draw_FillRect(mx, 64 + 1, mx + 1, motdh - 20, 255, 127, 0, 255);
532 r_Draw_FillRect(mx + 52, 64 + 1, mx + 52 + 1, motdh - 20, 255, 127, 0, 255);
533 r_Draw_FillRect(mx + 104, 64 + 1, mx + 104 + 1, motdh - 20, 255, 127, 0, 255);
535 r_Common_DrawText('NAME/MAP', 18, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
536 r_Common_DrawText('PING', mx - 68, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
537 r_Common_DrawText('MODE', mx + 2, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
538 r_Common_DrawText('PLRS', mx + 54, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
539 r_Common_DrawText('VER', mx + 106, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
541 for i := 0 to High(ST) do
542 begin
543 Srv := GetServerFromTable(i, SL, ST);
544 r_Common_DrawText(Srv.Name, 18, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
545 r_Common_DrawText(Srv.Map, 18, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
547 if Srv.Ping = 0 then
548 r_Common_DrawText('<1' + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
549 else if (Srv.Ping >= 0) and (Srv.Ping <= 999) then
550 r_Common_DrawText(IntToStr(Srv.Ping) + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
551 else
552 r_Common_DrawText(_lc[I_NET_SLIST_NO_ACCESS], mx - 68, y, 255, 0, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
553 if Length(ST[I].Indices) > 1 then
554 r_Common_DrawText('<' + IntToStr(Length(ST[I].Indices)) + '>', mx - 68, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
556 r_Common_DrawText(g_Game_ModeToText(Srv.GameMode), mx + 2, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
558 r_Common_DrawText(IntToStr(Srv.Players) + '/' + IntToStr(Srv.MaxPlayers), mx + 54, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
559 r_Common_DrawText(IntToStr(Srv.LocalPl) + '+' + IntToStr(Srv.Bots), mx + 54, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
561 r_Common_DrawText(IntToStr(Srv.Protocol), mx + 106, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
563 y := y + 42;
564 end;
566 r_Common_DrawText(ip, 20, motdh - 20 + 3, 205, 205, 205, 255, stdfont, TBasePoint.BP_LEFTUP);
567 r_Common_DrawText(IntToStr(Length(ST)) + _lc[I_NET_SLIST_SERVERS], gScreenWidth - 48, motdh - 20 + 3, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
568 end;
569 end;
571 procedure r_Render_DrawStatsColumns (constref cs: TEndCustomGameStat; x, y, w: Integer; endview: Boolean);
572 var i, cw, ch, yy, team, players, w1, w2, w3, w4, tw: Integer; r, g, b, rr, gg, bb: Byte; s: AnsiString;
573 begin
574 r_Draw_GetTextSize('W', stdfont, cw, ch);
575 w4 := cw * 6; (* deaths width *)
576 w3 := cw * 8; (* frags width *)
577 w2 := cw * 12; (* ping/loss width *)
578 w1 := w - w2 - w3 - w4; (* name width *)
579 tw := w1 - cw * 2 - w2; (* team score *)
580 if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
581 yy := y;
582 if cs.GameMode in [GM_TDM, GM_CTF] then
583 begin
584 for team := TEAM_RED to TEAM_BLUE do
585 begin
586 case team of
587 TEAM_RED:
588 begin
589 s := _lc[I_GAME_TEAM_RED];
590 r := 255; g := 0; b := 0;
591 end;
592 TEAM_BLUE:
593 begin
594 s := _lc[I_GAME_TEAM_BLUE];
595 r := 0; g := 0; b := 255;
596 end;
597 end;
598 r_Common_DrawText(s, x, yy, r, g, b, 255, stdfont, TBasePoint.BP_LEFTUP);
599 r_Common_DrawText(IntToStr(cs.TeamStat[team].Score), x + tw, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
600 if endview = false then
601 r_Common_DrawText(_lc[I_GAME_PING], x + w1, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
602 r_Common_DrawText(_lc[I_GAME_FRAGS], x + w1 + w2, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
603 r_Common_DrawText(_lc[I_GAME_DEATHS], x + w1 + w2 + w3, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
604 INC(yy, ch);
606 INC(yy, ch div 4);
607 r_Draw_FillRect(x, yy, x + w, yy + 1, r, g, b, 255);
608 INC(yy, ch div 4);
610 for i := 0 to players - 1 do
611 begin
612 if cs.PlayerStat[i].Team = team then
613 begin
614 rr := r; gg := g; bb := b;
615 if cs.PlayerStat[i].Spectator then
616 begin
617 rr := r div 2; gg := g div 2; bb := b div 2;
618 end;
620 // Player name
621 if gShowPIDs then s := Format('[%5d] %s', [cs.PlayerStat[i].UID, cs.PlayerStat[i].Name]) else s := cs.PlayerStat[i].Name;
622 if (gPlayers[cs.PlayerStat[i].Num] <> nil) and (gPlayers[cs.PlayerStat[i].Num].FReady) then s := s + ' *';
623 r_Common_DrawText(s, x, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_LEFTUP);
624 if endview = false then
625 begin
626 // Player ping/loss
627 s := Format(_lc[I_GAME_PING_MS], [cs.PlayerStat[i].Ping, cs.PlayerStat[i].Loss]);
628 r_Common_DrawText(s, x + w1, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
629 end;
630 // Player frags
631 s := IntToStr(cs.PlayerStat[i].Frags);
632 r_Common_DrawText(s, x + w1 + w2, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
633 // Player deaths
634 s := IntToStr(cs.PlayerStat[i].Deaths);
635 r_Common_DrawText(s, x + w1 + w2 + w3, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
637 INC(yy, ch);
638 end;
639 end;
640 INC(yy, ch);
641 end;
642 end
643 else if cs.GameMode in [GM_DM, GM_COOP] then
644 begin
645 r_Common_DrawText(_lc[I_GAME_PLAYER_NAME], x, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
646 if endview = false then
647 r_Common_DrawText(_lc[I_GAME_PING], x + w1, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
648 r_Common_DrawText(_lc[I_GAME_FRAGS], x + w1 + w2, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
649 r_Common_DrawText(_lc[I_GAME_DEATHS], x + w1 + w2 + w3, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
650 INC(yy, ch + ch div 2);
651 for i := 0 to players - 1 do
652 begin
653 // rr := 255; gg := 127; bb := 0;
654 rr := 255; gg := 255; bb := 255;
655 if cs.PlayerStat[i].Spectator then
656 begin
657 rr := rr div 2; gg := gg div 2; bb := bb div 2;
658 end;
660 // Player color
661 r_Draw_Rect(x, yy, x + 16, yy + 16, 192, 192, 192, 255);
662 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);
663 // Player name
664 if gShowPIDs then s := Format('[%5d] %s', [cs.PlayerStat[i].UID, cs.PlayerStat[i].Name]) else s := cs.PlayerStat[i].Name;
665 if (gPlayers[cs.PlayerStat[i].Num] <> nil) and (gPlayers[cs.PlayerStat[i].Num].FReady) then s := s + ' *';
666 r_Common_DrawText(s, x + 16 + 8, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_LEFTUP);
667 if endview = false then
668 begin
669 // Player ping/loss
670 s := Format(_lc[I_GAME_PING_MS], [cs.PlayerStat[i].Ping, cs.PlayerStat[i].Loss]);
671 r_Common_DrawText(s, x + w1, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
672 end;
673 // Player frags
674 s := IntToStr(cs.PlayerStat[i].Frags);
675 r_Common_DrawText(s, x + w1 + w2, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
676 // Player deaths
677 s := IntToStr(cs.PlayerStat[i].Deaths);
678 r_Common_DrawText(s, x + w1 + w2 + w3, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
680 INC(yy, ch + ch div 2);
681 end;
682 end;
683 end;
685 procedure r_Render_DrawStatsWindow (x, y, w, h: Integer; cs: TEndCustomGameStat; endview: Boolean);
686 var xoff, yoff, cw, ch: Integer; s: AnsiString;
687 begin
688 xoff := 0; yoff := 8;
689 r_Draw_GetTextSize('W', stdfont, cw, ch);
690 r_Draw_Rect(x, y, x + w, y + h, 255, 127, 0, 255);
691 r_Draw_FillRect(x + 1, y + 1, x + w - 1, y + h - 1, 64, 64, 64, 224);
693 (* LINE 1 *)
695 if endview = false then
696 begin
697 case NetMode of
698 NET_SERVER: s := _lc[I_NET_SERVER];
699 NET_CLIENT: s := NetClientIP + ':' + IntToStr(NetClientPort);
700 otherwise s := '';
701 end;
702 r_Common_DrawText(s, x + 16, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
703 end;
705 case cs.GameMode of
706 GM_DM: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_DM] else s := _lc[I_GAME_LMS];
707 GM_TDM: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_TDM] else s := _lc[I_GAME_TLMS];
708 GM_CTF: s := _lc[I_GAME_CTF];
709 GM_COOP: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_COOP] else s := _lc[I_GAME_SURV];
710 otherwise s := 'GAME MODE ' + IntToStr(gGameSettings.GameMode);
711 end;
712 r_Common_DrawText(s, x + w div 2, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
714 if endview = false then
715 begin
716 s := r_Common_TimeToStr(cs.GameTime);
717 r_Common_DrawText(s, x + w - 16, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
718 end;
720 INC(yoff, ch + ch div 2);
722 (* LINE 2/3 *)
724 s := cs.Map;
725 if cs.MapName <> '' then
726 s := s + ' - ' + cs.MapName;
728 if endview = false then
729 begin
730 r_Common_DrawText(s, x + w div 2, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_UP);
731 INC(yoff, ch + ch div 2);
732 case cs.GameMode of
733 GM_DM, GM_TDM: s := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]);
734 GM_CTF: s := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.ScoreLimit]);
735 GM_COOP: s := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
736 otherwise s := '';
737 end;
738 r_Common_DrawText(s, x + 16, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_LEFTUP);
739 case cs.GameMode of
740 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]);
741 GM_COOP: s := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
742 otherwise s := '';
743 end;
744 r_Common_DrawText(s, x + w - 16, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_RIGHTUP);
745 INC(yoff, ch);
746 end
747 else
748 begin
749 xoff := MAX(Length(_lc[I_MENU_MAP]) + 1, Length(_lc[I_GAME_GAME_TIME]) + 1) * cw;
750 r_Common_DrawText(_lc[I_MENU_MAP], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
751 r_Common_DrawText(s, x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
752 INC(yoff, ch);
753 r_Common_DrawText(_lc[I_GAME_GAME_TIME], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
754 r_Common_DrawText(r_Common_TimeToStr(cs.GameTime), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
755 INC(yoff, ch);
756 end;
758 INC(yoff, ch);
760 (* LINE 4/5 *)
762 if endview and (cs.GameMode = GM_COOP) then
763 begin
764 xoff := MAX(Length(_lc[I_GAME_MONSTERS]) + 1, Length(_lc[I_GAME_SECRETS]) + 1) * cw;
765 r_Common_DrawText(_lc[I_GAME_MONSTERS], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
766 r_Common_DrawText(IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
767 INC(yoff, ch);
768 r_Common_DrawText(_lc[I_GAME_SECRETS], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
769 r_Common_DrawText(IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
770 INC(yoff, ch);
771 INC(yoff, ch);
772 end;
774 (* LINE 6/7 *)
776 if endview and (cs.GameMode = GM_COOP) and gLastMap then
777 begin
778 xoff := MAX(Length(_lc[I_GAME_MONSTERS_TOTAL]) + 1, Length(_lc[I_GAME_SECRETS_TOTAL]) + 1) * cw;
779 r_Common_DrawText(_lc[I_GAME_MONSTERS_TOTAL], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
780 r_Common_DrawText(IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
781 INC(yoff, ch);
782 r_Common_DrawText(_lc[I_GAME_SECRETS_TOTAL], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
783 r_Common_DrawText(IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
784 INC(yoff, ch);
785 INC(yoff, ch);
786 end;
788 (* LINE *)
790 if endview and (cs.GameMode in [GM_TDM, GM_CTF]) then
791 begin
792 if cs.TeamStat[TEAM_RED].Score > cs.TeamStat[TEAM_BLUE].Score then s := _lc[I_GAME_WIN_RED]
793 else if cs.TeamStat[TEAM_BLUE].Score > cs.TeamStat[TEAM_RED].Score then s := _lc[I_GAME_WIN_BLUE]
794 else s := _lc[I_GAME_WIN_DRAW];
795 r_Common_DrawText(s, x + w div 2, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
796 INC(yoff, ch);
797 INC(yoff, ch);
798 end;
800 (* LINE n *)
802 r_Render_DrawStatsColumns(cs, x + 16, y + yoff, w - 16 - 16, endview);
803 end;
805 function r_Render_StatsHeight (players: Integer): Integer;
806 var cw, ch: Integer;
807 begin
808 ASSERT(players >= 0);
809 r_Draw_GetTextSize('W', stdfont, cw, ch);
810 case gGameSettings.GameMode of
811 GM_TDM, GM_CTF: result := 32 + ch * (11 + players);
812 otherwise result := 40 + ch * 5 + (ch + 8) * players;
813 end;
814 end;
816 procedure r_Render_DrawStats;
817 var x, y, w, h, players: Integer; cs: TEndCustomGameStat;
818 begin
819 cs.PlayerStat := g_Player_GetStats();
820 SortGameStat(cs.PlayerStat);
821 cs.TeamStat := gTeamStat;
822 cs.GameTime := gTime;
823 cs.GameMode := gGameSettings.GameMode;
824 cs.Map := g_ExtractWadNameNoPath(gMapInfo.Map) + ':' + g_ExtractFileName(gMapInfo.Map);
825 cs.MapName := gMapInfo.Name;
826 if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
827 w := gScreenWidth - (gScreenWidth div 5);
828 h := r_Render_StatsHeight(players);
829 x := (gScreenWidth div 2) - (w div 2);
830 y := (gScreenHeight div 2) - (h div 2);
831 r_Render_DrawStatsWindow(x, y, w, h, cs, false);
832 end;
834 procedure r_Render_DrawCustomStats;
835 var cw, ch, s: AnsiString;
836 begin
837 if gStatsOff then
838 begin
839 r_Common_DrawText(_lc[I_MENU_INTER_NOTICE_TAB], gScreenWidth div 2, 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
840 end
841 else
842 begin
843 case gGameSettings.GameMode of
844 GM_COOP: if gMissionFailed then s := _lc[I_MENU_INTER_MISSION_FAIL] else s := _lc[I_MENU_INTER_LEVEL_COMPLETE];
845 otherwise s := _lc[I_MENU_INTER_ROUND_OVER];
846 end;
847 r_Common_DrawText(s, gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
849 if gChatShow = false then
850 begin
851 if g_Game_IsClient then s := _lc[I_MENU_INTER_NOTICE_MAP] else s := _lc[I_MENU_INTER_NOTICE_SPACE];
852 r_Common_DrawText(s, gScreenWidth div 2, gScreenHeight - 4, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
853 if g_Game_IsNet then
854 begin
855 s := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
856 r_Common_DrawText(s, gScreenWidth div 2, gScreenHeight - 16 - 4, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
857 end;
858 end;
860 r_Render_DrawStatsWindow(32, 64, gScreenWidth - 32 * 2, gScreenHeight - 64 * 2, CustomStat, true);
861 end;
862 end;
864 procedure r_Render_DrawValueOf (a, b, x, y: Integer; f: TGLFont);
865 var wa, wb, ch: Integer; sa, sb: AnsiString;
866 begin
867 sa := IntToStr(a);
868 sb := IntToStr(b);
869 r_Draw_GetTextSize(sa, f, wa, ch);
870 r_Draw_GetTextSize(sa + ' / ', f, wb, ch);
871 r_Common_DrawText(sa, x, y, 255, 0, 0, 255, f, TBasePoint.BP_LEFTUP);
872 r_Common_DrawText(' / ', x + wa, y, 255, 255, 255, 255, f, TBasePoint.BP_LEFTUP);
873 r_Common_DrawText(sb, x + wb, y, 255, 0, 0, 255, f, TBasePoint.BP_LEFTUP);
874 end;
876 procedure r_Render_DrawSinglStatsPlayer (player, x, y, w1: Integer);
877 var time, kpm: Single;
878 begin
879 r_Common_DrawText(_lc[I_MENU_INTER_KILLS], x, y, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
880 r_Render_DrawValueOf(SingleStat.PlayerStat[player].Kills, gTotalMonsters, x + w1, y, MenuFont);
881 r_Common_DrawText(_lc[I_MENU_INTER_KPM], x, y + 32, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
882 time := SingleStat.GameTime / 1000;
883 kpm := SingleStat.PlayerStat[player].Kills;
884 if time > 0 then kpm := kpm / time * 60;
885 r_Common_DrawText(Format('%.1f', [kpm]), x + w1, y + 32, 255, 0, 0, 255, menufont, TBasePoint.BP_LEFTUP);
886 r_Common_DrawText(_lc[I_MENU_INTER_SECRETS], x, y + 64, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
887 r_Render_DrawValueOf(SingleStat.PlayerStat[player].Secrets, SingleStat.TotalSecrets, x + w1, y + 64, MenuFont);
888 end;
890 procedure r_Render_DrawSingleStats;
891 var xx, wa, wb, ww, ch: Integer; s: AnsiString;
892 begin
893 r_Common_DrawText(_lc[I_MENU_INTER_LEVEL_COMPLETE], gScreenWidth div 2, 32, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
895 r_Draw_GetTextSize(_lc[I_MENU_INTER_KPM] + ' ', menufont, wa, ch);
896 r_Draw_GetTextSize(' 9999.9', menufont, wb, ch);
897 ww := wa + wb;
898 xx := gScreenWidth div 2 - ww div 2;
900 s := r_Common_TimeToStr(SingleStat.GameTime);
901 r_Common_DrawText(_lc[I_MENU_INTER_TIME], xx, 80, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
902 r_Common_DrawText(s, xx + wa, 80, 255, 0, 0, 255, menufont, TBasePoint.BP_LEFTUP);
904 if SingleStat.TwoPlayers then
905 begin
906 r_Common_DrawText(_lc[I_MENU_PLAYER_1], gScreenWidth div 2, 128, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
907 r_Render_DrawSinglStatsPlayer(0, xx, 176, wa);
908 r_Common_DrawText(_lc[I_MENU_PLAYER_2], gScreenWidth div 2, 288, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
909 r_Render_DrawSinglStatsPlayer(1, xx, 336, wa);
910 end
911 else
912 begin
913 r_Render_DrawSinglStatsPlayer(0, xx, 128, wa);
914 end;
915 end;
917 procedure r_Render_DrawSpectHud;
918 var xoff: Integer; s: AnsiString;
920 procedure AddText (s1, s2: AnsiString);
921 var w1, w2, ww, ch: Integer;
922 begin
923 r_Draw_GetTextSize(s1, stdfont, w1, ch);
924 r_Draw_GetTextSize(s2, stdfont, w2, ch);
925 ww := MAX(w1, w2);
926 r_Common_DrawText(s1, xoff + ww div 2, gScreenHeight - ch, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
927 r_Common_DrawText(s2, xoff + ww div 2, gScreenHeight - ch, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
928 xoff := xoff + ww + 16;
929 end;
931 begin
932 xoff := 0;
933 case gSpectMode of
934 SPECT_STATS: s := 'MODE: Stats';
935 SPECT_MAPVIEW: s := 'MODE: Observe Map';
936 SPECT_PLAYERS: s := 'MODE: Watch Players';
937 otherwise s := 'MODE: ' + IntToStr(gSpectMode);
938 end;
939 AddText(s, '< jump >');
940 if gSpectMode = SPECT_STATS then
941 AddText('Autoview', '< fire >');
942 if gSpectMode = SPECT_MAPVIEW then
943 AddText('[-] Step ' + IntToStr(gSpectStep) + ' [+]', '<prev weap> <next weap>');
944 if gSpectMode = SPECT_PLAYERS then
945 begin
946 AddText('Player 1', '<left/right>');
947 if gSpectViewTwo then
948 AddText('Player 2', '<prev w/next w>');
949 AddText('2x View', '<up/down>');
950 end;
951 end;
953 function GetActivePlayer_ByID (id: Integer): TPlayer;
954 var i, len: Integer; p: TPlayer;
955 begin
956 p := nil;
957 if (id >= 0) and (gPlayers <> nil) then
958 begin
959 i := 0; len := Length(gPlayers);
960 while (i < len) and ((IsActivePlayer(gPlayers[i]) = false) or (gPlayers[i].UID <> id)) do INC(i);
961 if i < len then p := gPlayers[i];
962 end;
963 result := p;
964 end;
966 procedure r_Render_DrawMinimap (x, y: Integer; alpha: Byte);
967 const scale = 16;
969 function IsMinimapPanel (const p: TPanel): Boolean;
970 begin
971 result := (p <> nil) and p.Enabled;
972 if result then
973 begin
974 case p.PanelType of
975 PANEL_WALL, PANEL_WATER, PANEL_ACID1, PANEL_ACID2,
976 PANEL_STEP, PANEL_OPENDOOR, PANEL_CLOSEDOOR,
977 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
978 result := true;
979 otherwise
980 result := false;
981 end;
982 end;
983 end;
985 procedure DrawObject (xx, yy, ww, hh: Integer; r, g, b: Byte);
986 var x0, y0, x1, y1: Integer;
987 begin
988 x0 := x + xx div scale;
989 y0 := y + yy div scale;
990 x1 := x + (xx + ww) div scale;
991 y1 := y + (yy + hh) div scale;
992 r_Draw_FillRect(x0, y0, x1, y1, r, g, b, alpha);
993 end;
995 procedure DrawPanels (const a: TPanelArray);
996 var i: Integer; p: TPanel; c: TRGB;
997 begin
998 if a <> nil then
999 begin
1000 for i := 0 to HIGH(a) do
1001 begin
1002 p := a[i];
1003 if IsMinimapPanel(p) then
1004 begin
1005 case p.PanelType of
1006 PANEL_WALL: c := _RGB(208, 208, 208);
1007 PANEL_OPENDOOR: c := _RGB(160, 160, 160);
1008 PANEL_CLOSEDOOR: c := _RGB(160, 160, 160);
1009 PANEL_STEP: c := _RGB(128, 128, 128);
1010 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
1011 case p.LiftType of
1012 LIFTTYPE_UP: c := _RGB(116, 72, 36);
1013 LIFTTYPE_DOWN: c := _RGB(116, 124, 96);
1014 LIFTTYPE_LEFT: c := _RGB(116, 200, 80);
1015 LIFTTYPE_RIGHT: c := _RGB(116, 252, 140);
1016 otherwise c := _RGB(255, 0, 0);
1017 end;
1018 PANEL_WATER: c := _RGB(0, 0, 192);
1019 PANEL_ACID1: c := _RGB(0, 176, 0);
1020 PANEL_ACID2: c := _RGB(176, 0, 0);
1021 otherwise c := _RGB(255, 0, 0);
1022 end;
1023 DrawObject(p.x, p.y, p.width, p.height, c.r, c.g, c.b);
1024 end;
1025 end;
1026 end;
1027 end;
1029 procedure DrawPlayers;
1030 var i: Integer; p: TPlayer; c: TRGB;
1031 begin
1032 if gPlayers <> nil then
1033 begin
1034 for i := 0 to HIGH(gPlayers) do
1035 begin
1036 p := gPlayers[i];
1037 if p.Alive then
1038 begin
1039 case p.Team of
1040 TEAM_RED: c := _RGB(255, 0, 0);
1041 TEAM_BLUE: c := _RGB(0, 0, 255);
1042 otherwise c := _RGB(255, 128, 0);
1043 end;
1044 DrawObject(p.obj.x, p.obj.y, p.obj.rect.width, p.obj.rect.height, c.r, c.g, c.b);
1045 end;
1046 end;
1047 end;
1048 end;
1050 function DrawMonster (m: TMonster): Boolean;
1051 begin
1052 result := false; // don't stop
1053 if m.alive then
1054 DrawObject(m.obj.x, m.obj.y, m.obj.rect.width, m.obj.rect.height, 255, 255, 0);
1055 end;
1057 begin
1058 r_Draw_FillRect(x, y, (x + gMapInfo.Width) div scale, (y + gMapInfo.Height) div scale, 0, 0, 0, alpha);
1059 DrawPanels(gSteps);
1060 DrawPanels(gLifts);
1061 DrawPanels(gWater);
1062 DrawPanels(gAcid1);
1063 DrawPanels(gAcid2);
1064 DrawPanels(gWalls);
1065 g_Mons_ForEach(DrawMonster);
1066 DrawPlayers;
1067 end;
1069 procedure r_Render_Draw;
1070 var p1, p2: TPlayer; time: LongWord; pw, ph: Integer;
1071 begin
1072 if gExit = EXIT_QUIT then
1073 exit;
1075 {$IFDEF ENABLE_SYSTEM}
1076 (* hack: if r_pixel_scale changed, reset menu and other things *)
1077 pw := Round(gWinSizeX / r_pixel_scale);
1078 ph := Round(gWinSizeY / r_pixel_scale);
1079 if (pw <> gScreenWidth) or (ph <> gScreenHeight) then
1080 if assigned(sys_ScreenResize) then
1081 sys_ScreenResize(gWinSizeX, gWinSizeY);
1082 {$ENDIF}
1084 INC(FPSCounter);
1085 time := GetTickCount64();
1086 if time - FPSTime >= 1000 then
1087 begin
1088 FPS := FPSCounter;
1089 FPSCounter := 0;
1090 FPSTime := time;
1091 end;
1093 r_Draw_Setup(gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight);
1095 glClearColor(0.0, 0.0, 0.0, 0.0);
1096 glClear(GL_COLOR_BUFFER_BIT);
1098 p1 := nil;
1099 p2 := nil;
1100 if gGameOn or (gState = STATE_FOLD) then
1101 begin
1102 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
1103 begin
1104 if gRevertPlayers then
1105 begin
1106 p1 := gPlayer2;
1107 p2 := gPlayer1;
1108 end
1109 else
1110 begin
1111 p1 := gPlayer1;
1112 p2 := gPlayer2;
1113 end;
1114 end
1115 else if gPlayer1 <> nil then
1116 begin
1117 p1 := gPlayer1;
1118 end
1119 else if gPlayer2 <> nil then
1120 begin
1121 p1 := gPlayer2;
1122 end;
1123 if (gSpectMode = SPECT_PLAYERS) and (gPlayers <> nil) then
1124 begin
1125 p1 := GetActivePlayer_ByID(gSpectPID1);
1126 if p1 = nil then
1127 p1 := GetActivePlayer_ByID(GetActivePlayerID_Next());
1128 if gSpectViewTwo then
1129 begin
1130 p2 := GetActivePlayer_ByID(gSpectPID2);
1131 if p2 = nil then
1132 p2 := GetActivePlayer_ByID(GetActivePlayerID_Next());
1133 end;
1134 end;
1135 end;
1137 if gGameOn or ((gState in [STATE_FOLD]) and (EndingGameCounter < 255)) then
1138 begin
1139 if gSpectMode = SPECT_MAPVIEW then
1140 begin
1141 r_Render_DrawMapView(0, 0, gScreenWidth, gScreenHeight, gSpectX + gScreenWidth div 2, gSpectY + gScreenHeight div 2);
1142 end
1143 else if (p1 <> nil) and (p2 <> nil) then
1144 begin
1145 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight div 2 - 2, p1);
1146 r_Render_DrawPlayerView(0, gScreenHeight div 2 + 2, gScreenWidth, gScreenHeight div 2, p2);
1147 end
1148 else if p1 <> nil then
1149 begin
1150 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, p1);
1151 end
1152 else if p2 <> nil then
1153 begin
1154 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, p2);
1155 end;
1157 if gShowMap then
1158 r_Render_DrawMiniMap(0, 0, 160);
1160 {$IFDEF ENABLE_HOLMES}
1161 r_Holmes_Draw;
1162 {$ENDIF}
1164 if MessageText <> '' then
1165 r_Common_DrawFormatText(MessageText, (gScreenWidth - 196) div 2, gScreenHeight div 2, 255, menufont, TBasePoint.BP_CENTER);
1167 if IsDrawStat or (gSpectMode = SPECT_STATS) then
1168 r_Render_DrawStats;
1170 if gSpectHUD and (gChatShow = false) and (gSpectMode <> SPECT_NONE) and (gSpectAuto = false) then
1171 r_Render_DrawSpectHud;
1172 end;
1174 if gPauseMain and gGameOn {$IFDEF ENABLE_MENU}and (g_ActiveWindow = nil){$ENDIF} then
1175 begin
1176 r_Draw_FillRect(0, 0, gScreenWidth, gScreenHeight, 0, 0, 0, 105);
1177 r_Common_DrawText(_lc[I_MENU_PAUSE], gScreenWidth div 2, gScreenHeight div 2, 255, 255, 255, 255, menufont, TBasePoint.BP_CENTER);
1178 end;
1180 if not gGameOn then
1181 begin
1182 // TODO F key handle
1183 case gState of
1184 STATE_NONE: (* do nothing *) ;
1185 STATE_MENU: r_Common_DrawBackground(GameWad + ':TEXTURES/TITLE');
1186 STATE_FOLD:
1187 begin
1188 if EndingGameCounter > 0 then
1189 r_Draw_FillRect(0, 0, gScreenWidth, gScreenHeight, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
1190 end;
1191 STATE_INTERCUSTOM:
1192 begin
1193 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1194 if EndPicPath <> '' then
1195 r_Common_DrawBackground(EndPicPath)
1196 else
1197 r_Common_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC])
1198 else
1199 r_Common_DrawBackground(GameWad + ':TEXTURES/INTER');
1201 r_Render_DrawCustomStats;
1203 {$IFDEF ENABLE_MENU}
1204 if g_ActiveWindow <> nil then
1205 r_Draw_FillRect(0, 0, gScreenWidth, gScreenHeight, 0, 0, 0, 105);
1206 {$ENDIF}
1207 end;
1208 STATE_INTERSINGLE, STATE_INTERTEXT, STATE_INTERPIC:
1209 begin
1210 if EndingGameCounter > 0 then
1211 begin
1212 r_Draw_FillRect(0, 0, gScreenWidth, gScreenHeight, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
1213 end
1214 else
1215 begin
1216 r_Common_DrawBackground(GameWad + ':TEXTURES/INTER');
1217 r_Render_DrawSingleStats;
1218 {$IFDEF ENABLE_MENU}
1219 if g_ActiveWindow <> nil then
1220 r_Draw_FillRect(0, 0, gScreenWidth, gScreenHeight, 0, 0, 0, 105);
1221 {$ENDIF}
1222 end;
1223 end;
1224 STATE_ENDPIC:
1225 begin
1226 if EndPicPath <> '' then
1227 r_Common_DrawBackground(EndPicPath)
1228 else
1229 r_Common_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC]);
1230 {$IFDEF ENABLE_MENU}
1231 if g_ActiveWindow <> nil then
1232 r_Draw_FillRect(0, 0, gScreenWidth, gScreenHeight, 0, 0, 0, 105);
1233 {$ENDIF}
1234 end;
1235 STATE_SLIST:
1236 begin
1237 r_Common_DrawBackground(GameWad + ':TEXTURES/TITLE');
1238 r_Draw_FillRect(0, 0, gScreenWidth, gScreenHeight, 0, 0, 0, 105);
1239 r_Render_DrawServerList(slCurrent, slTable);
1240 end;
1241 end;
1242 end;
1244 {$IFDEF ENABLE_MENU}
1245 if g_ActiveWindow <> nil then
1246 begin
1247 if gGameOn then
1248 r_Draw_FillRect(0, 0, gScreenWidth, gScreenHeight, 0, 0, 0, 105);
1249 r_GUI_Draw_Window(g_ActiveWindow);
1250 end;
1251 {$ENDIF}
1253 r_Console_Draw(false);
1255 // TODO g_debug_Sounds
1257 if gShowFPS then
1258 begin
1259 r_Common_DrawText('FPS: ' + IntToStr(FPS), 0, 0, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
1260 r_Common_DrawText('UPS: ' + IntToStr(UPS), 0, 16, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
1261 end;
1263 if gGameOn and gShowTime then
1264 begin
1265 r_Common_DrawText(r_Common_TimeToStr(gTime), gScreenWidth - 4, gScreenHeight - 1, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTDOWN);
1266 end;
1268 // TODO draw profilers
1270 {$IFDEF ENABLE_HOLMES}
1271 r_Holmes_DrawUI;
1272 {$ENDIF}
1274 {$IFDEF ENABLE_TOUCH}
1275 glScalef(1 / r_pixel_scale, 1 / r_pixel_scale, 0);
1276 r_Touch_Draw;
1277 {$ENDIF}
1279 sys_Repaint;
1280 end;
1282 procedure r_Render_Resize (w, h: Integer);
1283 begin
1284 gWinSizeX := w;
1285 gWinSizeY := h;
1286 gRC_Width := w;
1287 gRC_Height := h;
1288 gScreenWidth := Round(w / r_pixel_scale);
1289 gScreenHeight := Round(h / r_pixel_scale);
1290 end;
1292 procedure r_Render_Apply;
1293 begin
1294 {$IFDEF ENABLE_SYSTEM}
1295 if sys_SetDisplayModeGL(GetInfo()) then
1296 e_LogWriteln('resolution changed')
1297 else
1298 e_LogWriteln('resolution not changed');
1299 sys_EnableVSync(gVSync);
1300 {$ENDIF}
1301 {$IFDEF NOGL_INIT}
1302 nogl_Init;
1303 {$ENDIF}
1304 end;
1306 function r_Render_WriteScreenShot (filename: String): Boolean;
1307 begin
1308 // TODO write screenshot file
1309 Result := False;
1310 end;
1312 {$IFDEF ENABLE_GIBS}
1313 function r_Render_GetGibRect (m, id: Integer): TRectWH;
1314 begin
1315 result := r_Map_GetGibSize(m, id);
1316 end;
1317 {$ENDIF}
1319 {$IFDEF ENABLE_GFX}
1320 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
1321 begin
1322 r_Map_NewGFX(AnimType, X, Y);
1323 end;
1324 {$ENDIF}
1326 {$IFDEF ENABLE_TOUCH}
1327 procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
1328 begin
1329 r_Touch_GetKeyRect(key, x, y, w, h, founded)
1330 end;
1331 {$ENDIF}
1333 {$IFDEF ENABLE_MENU}
1334 procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
1335 begin
1336 r_GUI_GetSize(ctrl, w, h);
1337 end;
1339 procedure r_Render_GetLogoSize (out w, h: Integer);
1340 begin
1341 r_GUI_GetLogoSize(w, h);
1342 end;
1344 procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
1345 begin
1346 r_GUI_GetMaxFontSize(BigFont, w, h);
1347 end;
1349 procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
1350 begin
1351 r_GUI_GetStringSize(BigFont, str, w, h);
1352 end;
1353 {$ENDIF}
1355 procedure r_Render_SetProcessLoadingCallback (p: TProcedure);
1356 begin
1357 r_Common_ProcessLoadingCallback := p;
1358 end;
1360 procedure r_Render_ClearLoading;
1361 begin
1362 r_Common_ClearLoading;
1363 end;
1365 procedure r_Render_SetLoading (const text: String; maxval: Integer);
1366 begin
1367 r_Common_SetLoading(text, maxval);
1368 end;
1370 procedure r_Render_StepLoading (incval: Integer);
1371 begin
1372 r_Common_StepLoading(incval);
1373 end;
1375 procedure r_Render_DrawLoading (force: Boolean);
1376 begin
1377 r_Common_DrawLoading(force);
1378 end;
1380 {$IFDEF ENABLE_HOLMES}
1381 function pmsCurMapX (): Integer;
1382 begin
1383 result := r_holmes.pmsCurMapX();
1384 end;
1386 function pmsCurMapY (): Integer;
1387 begin
1388 result := r_holmes.pmsCurMapY();
1389 end;
1391 function r_Render_HolmesViewIsSet (): Boolean;
1392 begin
1393 result := vpSet;
1394 end;
1395 {$ENDIF}
1397 end.