DEADSOFTWARE

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