DEADSOFTWARE

202500d6170fbe92ddd1416d47811ce01e071656
[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 {$IFDEF USE_GLES1}
86 GLES11,
87 {$ELSE}
88 GL, GLEXT,
89 {$ENDIF}
90 {$IFDEF ENABLE_MENU}
91 r_gui,
92 {$ENDIF}
93 {$IFDEF ENABLE_SYSTEM}
94 g_system,
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 info.profile := TGLProfile.Compat;
206 result := info;
207 end;
208 {$ENDIF}
210 procedure r_Render_Initialize;
211 begin
212 {$IFDEF ENABLE_SYSTEM}
213 if sys_SetDisplayModeGL(GetInfo()) = False then
214 raise Exception.Create('Failed to set videomode on startup.');
215 sys_EnableVSync(gVSync);
216 {$ENDIF}
217 r_LoadScreen_Initialize;
218 r_Textures_Initialize;
219 r_Console_Initialize;
220 r_Map_Initialize;
221 end;
223 procedure r_Render_Finalize;
224 begin
225 r_Map_Finalize;
226 r_Console_Finalize;
227 r_Textures_Finalize;
228 r_LoadScreen_Finalize;
229 end;
231 procedure r_Render_Update;
232 begin
233 r_Console_Update;
234 r_Map_Update;
235 end;
237 procedure r_Render_DrawHUD (x, y: Integer; p: TPlayer);
238 var t: TGLTexture; s: AnsiString;
239 begin
240 ASSERT(p <> nil);
242 // hud area is 196 x 240 pixels
243 r_Common_DrawTexture(hud, x, y, hud.width, hud.height, TBasePoint.BP_LEFTUP);
244 r_Common_DrawText(p.name, x + 98, y + 16, 255, 0, 0, 255, smallfont, TBasePoint.BP_CENTER);
246 t := hudhp[R_BERSERK in p.FRulez];
247 r_Common_DrawTexture(t, x + 51, y + 61, t.width, t.height, TBasePoint.BP_CENTER);
248 r_Common_DrawTexture(hudap, x + 50, y + 85, hudap.width, hudap.height, TBasePoint.BP_CENTER);
250 r_Common_DrawText(IntToStr(MAX(0, p.health)), x + 174, y + 56, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
251 r_Common_DrawText(IntToStr(MAX(0, p.armor)), x + 174, y + 84, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
253 case p.CurrWeap of
254 WEAPON_KASTET, WEAPON_SAW: s := '--';
255 else s := IntToStr(p.GetAmmoByWeapon(p.CurrWeap));
256 end;
257 r_Common_DrawText(s, x + 174, y + 174, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
259 if p.CurrWeap <= WP_LAST then
260 begin
261 t := hudwp[p.CurrWeap];
262 r_Common_DrawTexture(t, x + 18, y + 160, t.width, t.height, TBasePoint.BP_LEFTUP);
263 end;
265 if R_KEY_RED in p.FRulez then
266 r_Common_DrawTexture(hudkey[0], x + 76, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
267 if R_KEY_GREEN in p.FRulez then
268 r_Common_DrawTexture(hudkey[1], x + 93, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
269 if R_KEY_BLUE in p.FRulez then
270 r_Common_DrawTexture(hudkey[2], x + 110, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
272 if p.JetFuel > 0 then
273 begin
274 r_Common_DrawTexture(hudair, x, y + 116, hudair.width, hudair.height, TBasePoint.BP_LEFTUP);
275 if p.air > 0 then
276 r_Draw_FillRect(x + 14, y + 116 + 4, x + 14 + 168 * p.air div AIR_MAX, y + 116 + 4 + 4, 0, 0, 196, 255);
277 r_Common_DrawTexture(hudjet, x, y + 126, hudjet.width, hudjet.height, TBasePoint.BP_LEFTUP);
278 r_Draw_FillRect(x + 14, y + 126 + 4, x + 14 + 168 * p.JetFuel div JET_MAX, y + 126 + 4 + 4, 208, 0, 0, 255);
279 end
280 else
281 begin
282 r_Common_DrawTexture(hudair, x, y + 124, hudair.width, hudair.height, TBasePoint.BP_LEFTUP);
283 if p.air > 0 then
284 r_Draw_FillRect(x + 14, y + 124 + 4, x + 14 + 168 * p.air div AIR_MAX, y + 124 + 4 + 4, 0, 0, 196, 255);
285 end;
286 end;
288 procedure r_Render_DrawHUDArea (x, y, w, h: Integer; p: TPlayer);
289 var s: AnsiString; oldy: Integer;
290 begin
291 r_Common_DrawTexture(hudbg, x, y, w, h, TBasePoint.BP_LEFTUP);
293 if p <> nil then
294 begin
295 oldy := y;
296 if h < 239 then y := y - 32; (* hack: hide nickname on 640x400 *)
297 r_Render_DrawHUD(x + w - 196 + 2, y, p);
298 if p.Spectator then
299 begin
300 r_Common_DrawText(_lc[I_PLAYER_SPECT], x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
301 r_Common_DrawText(_lc[I_PLAYER_SPECT2], x + 4, y + 258, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
302 r_Common_DrawText(_lc[I_PLAYER_SPECT1], x + 4, y + 274, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
303 if p.NoRespawn then
304 r_Common_DrawText(_lc[I_PLAYER_SPECT1S], x + 4, y + 290, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
305 end;
306 y := oldy;
307 end;
309 if gShowPing and g_Game_IsClient then
310 begin
311 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
312 r_Common_DrawText(s, x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
313 end;
314 end;
316 procedure r_Render_DrawStatsView (x, y, w, h: Integer; p: TPlayer);
317 var fw, i, maxFrags, top, totalPlayers: Integer; sign: Char; stat: TPlayerStatArray; f: TGLTexture;
318 begin
319 ASSERT(p <> nil);
321 if gShowScore and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
322 begin
323 (* RED TEAM GOALS *)
324 fw := 0;
325 if gGameSettings.GameMode = GM_CTF then
326 begin
327 case gFlags[FLAG_RED].State of
328 FLAG_STATE_CAPTURED: f := hudrflags;
329 FLAG_STATE_DROPPED: f := hudrflagd;
330 otherwise f := hudrflag;
331 end;
332 if f <> nil then
333 begin
334 fw := f.width + 8; (* + space *)
335 r_Common_DrawTexture(f, x + w - 16, y + 240 - 72 - 4, f.width, f.height, TBasePoint.BP_RIGHTUP);
336 end;
337 end;
338 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);
340 (* BLUE TEAM GOALS *)
341 fw := 0;
342 if gGameSettings.GameMode = GM_CTF then
343 begin
344 case gFlags[FLAG_BLUE].State of
345 FLAG_STATE_CAPTURED: f := hudbflags;
346 FLAG_STATE_DROPPED: f := hudbflagd;
347 otherwise f := hudbflag;
348 end;
349 if f <> nil then
350 begin
351 fw := f.width + 8; (* + space *)
352 r_Common_DrawTexture(f, x + w - 16, y + 240 - 32 - 4, f.width, f.height, TBasePoint.BP_RIGHTUP);
353 end;
354 end;
355 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);
356 end;
358 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
359 begin
360 if gShowStat then
361 begin
362 r_Common_DrawText(IntToStr(p.Frags), x + w - 16, y, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHTUP);
364 top := 1;
365 maxFrags := 0;
366 totalPlayers := 0;
367 stat := g_Player_GetStats();
368 if stat <> nil then
369 begin
370 totalPlayers := Length(stat);
371 for i := 0 to High(stat) do
372 begin
373 if stat[i].Name <> p.Name then
374 begin
375 maxFrags := MAX(maxFrags, stat[i].Frags);
376 if stat[i].Frags > p.Frags then
377 top := top + 1;
378 end;
379 end;
380 end;
381 if p.Frags >= maxFrags then sign := '+' else sign := '-';
382 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);
383 end;
385 if gLMSRespawn > LMS_RESPAWN_NONE then
386 begin
387 r_Common_DrawText(_lc[I_GAME_WARMUP], x + w - 16 - 64, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_RIGHTDOWN);
388 r_Common_DrawText(': ' + IntToStr((gLMSRespawnTime - gTime) div 1000), x + w - 16 - 64, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_LEFTDOWN);
389 end
390 else if gShowLives and (gGameSettings.MaxLives > 0) then
391 begin
392 r_Common_DrawText(IntToStr(p.Lives), x + w - 16, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_RIGHTDOWN);
393 end;
394 end;
395 end;
397 procedure r_Render_DrawView (x, y, w, h: Integer; p: TPlayer);
398 var l, t, r, b, xx, yy, cx, cy: Integer;
399 begin
400 r_Draw_GetRect(l, t, r, b);
401 r_Draw_SetRect(x, y, x + w, y + h);
403 r_Common_GetCameraPos(p, true, xx, yy);
404 if p <> nil then
405 begin
406 r_Map_Draw(x, y, w, h, xx, yy, p, cx, cy);
407 {$IFDEF ENABLE_HOLMES}
408 if p = gPlayer1 then
409 begin
410 r_Holmes_plrViewPos(cx, cy);
411 r_Holmes_plrViewSize(h, w);
412 end;
413 {$ENDIF}
414 r_Render_DrawStatsView(x, y, w, h, p);
415 if p.Spectator and p.NoRespawn then
416 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);
417 end
418 else
419 begin
420 r_Map_Draw(x, y, w, h, xx, yy, nil, cx, cy);
421 end;
423 r_Draw_SetRect(l, t, r, b);
424 end;
426 procedure r_Render_DrawMapView (x, y, w, h, camx, camy: Integer);
427 var l, t, r, b, cx, cy: Integer;
428 begin
429 r_Draw_GetRect(l, t, r, b);
430 r_Draw_SetRect(x, y, x + w, y + h);
431 r_Map_Draw(x, y, w, h, camx, camy, nil, cx, cy);
432 r_Draw_SetRect(l, t, r, b);
433 end;
435 procedure r_Render_DrawPlayerView (x, y, w, h: Integer; p: TPlayer);
436 var l, t, r, b: Integer;
437 begin
438 r_Draw_GetRect(l, t, r, b);
439 r_Draw_SetRect(x, y, x + w, y + h);
440 r_Render_DrawView(x, y, w - 196, h, p);
441 r_Render_DrawHUDArea(x + w - 196, y, 196, h, p);
442 r_Draw_SetRect(l, t, r, b);
443 end;
445 procedure r_Render_DrawServerList (var SL: TNetServerList; var ST: TNetServerTable);
446 var ip: AnsiString; ww, hh, cw, ch, mw, mh, motdh, scrx, scry, i, mx, y: Integer; msg: SSArray; Srv: TNetServer;
447 begin
448 scrx := gScreenWidth div 2;
449 scry := gScreenHeight div 2;
451 r_Draw_GetTextSize(_lc[I_NET_SLIST], menufont, ww, hh);
452 r_Common_DrawText(_lc[I_NET_SLIST], gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
454 r_Draw_GetTextSize('W', stdfont, cw, ch);
455 motdh := gScreenHeight - 49 - ch * b_Text_LineCount(slMOTD);
457 r_Draw_FillRect(16, 64, gScreenWidth - 16, motdh, 64, 64, 64, 145);
458 r_Draw_Rect(16, 64, gScreenWidth - 16, motdh, 255, 127, 0, 255);
460 r_Common_DrawText(_lc[I_NET_SLIST_HELP], gScreenWidth div 2, gScreenHeight - 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
462 if slMOTD <> '' then
463 begin
464 r_Draw_FillRect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 64, 64, 64, 110);
465 r_Draw_Rect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 255, 127, 0, 255);
466 r_Common_DrawFormatText(slMOTD, 20, motdh + 3, 255, stdfont, TBasePoint.BP_LEFTUP);
467 end;
469 if not slReadUrgent and (slUrgent <> '') then
470 begin
471 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
472 r_Draw_FillRect(scrx - 256, scry - 60, scrx + 256, scry + 60, 64, 64, 64, 127);
473 r_Draw_Rect(scrx - 256, scry - 60, scrx + 256, scry + 60, 255, 127, 0, 255);
474 r_Draw_FillRect(scrx - 256, scry - 40, scrx + 256, scry - 40, 255, 127, 0, 255);
475 r_Common_DrawText(_lc[I_NET_SLIST_URGENT], scrx, scry - 58, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
476 r_Common_DrawFormatText(slUrgent, scrx - 253, scry - 38, 255, stdfont, TBasePoint.BP_LEFTUP);
477 r_Common_DrawText(_lc[I_NET_SLIST_URGENT_CONT], scrx, scry + 41, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
478 r_Draw_FillRect(scrx - 256, scry + 40, scrx + 256, scry + 40, 255, 127, 0, 255);
479 end
480 else if SL = nil then
481 begin
482 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
483 r_Draw_Rect(scrx - 192, scry - 10, scrx + 192, scry + 11, 255, 127, 0, 255);
484 r_Common_DrawText(slWaitStr, scrx, scry, 255, 255, 255, 255, stdfont, TBasePoint.BP_CENTER);
485 end
486 else
487 begin
488 y := 90;
489 if slSelection < Length(ST) then
490 begin
491 sy := y + 42 * slSelection - 4;
492 Srv := GetServerFromTable(slSelection, SL, ST);
493 ip := _lc[I_NET_ADDRESS] + ' ' + Srv.IP + ':' + IntToStr(Srv.Port);
494 ip := ip + ' ' + _lc[I_NET_SERVER_PASSWORD] + ' ';
495 if Srv.Password then ip := ip + _lc[I_MENU_YES] else ip := ip +_lc[I_MENU_NO];
496 end;
498 mw := gScreenWidth - 188;
499 mx := 16 + mw;
501 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy + 40, 64, 64, 64, 255);
502 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy, 205, 205, 205, 255);
503 r_Draw_FillRect(16 + 1, sy + 41, gScreenWidth - 16 - 1, sy + 41, 255, 255, 255, 255);
505 r_Draw_FillRect(16, 85, gScreenWidth - 16, 85, 255, 127, 0, 255);
506 r_Draw_FillRect(16, motdh - 20, gScreenWidth - 16, motdh - 20, 255, 127, 0, 255);
508 r_Draw_FillRect(mx - 70, 64, mx - 70, motdh, 255, 127, 0, 255);
509 r_Draw_FillRect(mx, 64, mx, motdh - 20, 255, 127, 0, 255);
510 r_Draw_FillRect(mx + 52, 64, mx + 52, motdh - 20, 255, 127, 0, 255);
511 r_Draw_FillRect(mx + 104, 64, mx + 104, motdh - 20, 255, 127, 0, 255);
513 r_Common_DrawText('NAME/MAP', 18, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
514 r_Common_DrawText('PING', mx - 68, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
515 r_Common_DrawText('MODE', mx + 2, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
516 r_Common_DrawText('PLRS', mx + 54, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
517 r_Common_DrawText('VER', mx + 106, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
519 for i := 0 to High(ST) do
520 begin
521 Srv := GetServerFromTable(i, SL, ST);
522 r_Common_DrawText(Srv.Name, 18, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
523 r_Common_DrawText(Srv.Map, 18, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
525 if Srv.Ping = 0 then
526 r_Common_DrawText('<1' + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
527 else if (Srv.Ping >= 0) and (Srv.Ping <= 999) then
528 r_Common_DrawText(IntToStr(Srv.Ping) + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
529 else
530 r_Common_DrawText(_lc[I_NET_SLIST_NO_ACCESS], mx - 68, y, 255, 0, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
531 if Length(ST[I].Indices) > 1 then
532 r_Common_DrawText('<' + IntToStr(Length(ST[I].Indices)) + '>', mx - 68, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
534 r_Common_DrawText(g_Game_ModeToText(Srv.GameMode), mx + 2, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
536 r_Common_DrawText(IntToStr(Srv.Players) + '/' + IntToStr(Srv.MaxPlayers), mx + 54, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
537 r_Common_DrawText(IntToStr(Srv.LocalPl) + '+' + IntToStr(Srv.Bots), mx + 54, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
539 r_Common_DrawText(IntToStr(Srv.Protocol), mx + 106, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
541 y := y + 42;
542 end;
544 r_Common_DrawText(ip, 20, motdh - 20 + 3, 205, 205, 205, 255, stdfont, TBasePoint.BP_LEFTUP);
545 r_Common_DrawText(IntToStr(Length(ST)) + _lc[I_NET_SLIST_SERVERS], gScreenWidth - 48, motdh - 20 + 3, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
546 end;
547 end;
549 procedure r_Render_DrawStatsColumns (constref cs: TEndCustomGameStat; x, y, w: Integer; endview: Boolean);
550 var i, cw, ch, yy, team, players, w1, w2, w3, w4, tw: Integer; r, g, b, rr, gg, bb: Byte; s: AnsiString;
551 begin
552 r_Draw_GetTextSize('W', stdfont, cw, ch);
553 w4 := cw * 6; (* deaths width *)
554 w3 := cw * 8; (* frags width *)
555 w2 := cw * 12; (* ping/loss width *)
556 w1 := w - w2 - w3 - w4; (* name width *)
557 tw := w1 - cw * 2 - w2; (* team goals *)
558 if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
559 yy := y;
560 if cs.GameMode in [GM_TDM, GM_CTF] then
561 begin
562 for team := TEAM_RED to TEAM_BLUE do
563 begin
564 case team of
565 TEAM_RED:
566 begin
567 s := _lc[I_GAME_TEAM_RED];
568 r := 255; g := 0; b := 0;
569 end;
570 TEAM_BLUE:
571 begin
572 s := _lc[I_GAME_TEAM_BLUE];
573 r := 0; g := 0; b := 255;
574 end;
575 end;
576 r_Common_DrawText(s, x, yy, r, g, b, 255, stdfont, TBasePoint.BP_LEFTUP);
577 r_Common_DrawText(IntToStr(cs.TeamStat[team].Score), x + tw, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
578 if endview = false then
579 r_Common_DrawText(_lc[I_GAME_PING], x + w1, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
580 r_Common_DrawText(_lc[I_GAME_FRAGS], x + w1 + w2, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
581 r_Common_DrawText(_lc[I_GAME_DEATHS], x + w1 + w2 + w3, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
582 INC(yy, ch);
584 INC(yy, ch div 4);
585 r_Draw_FillRect(x, yy, x + w - 1, yy, r, g, b, 255);
586 INC(yy, ch div 4);
588 for i := 0 to players - 1 do
589 begin
590 if cs.PlayerStat[i].Team = team then
591 begin
592 rr := r; gg := g; bb := b;
593 if cs.PlayerStat[i].Spectator then
594 begin
595 rr := r div 2; gg := g div 2; bb := b div 2;
596 end;
598 // Player name
599 if gShowPIDs then s := Format('[%5d] %s', [cs.PlayerStat[i].UID, cs.PlayerStat[i].Name]) else s := cs.PlayerStat[i].Name;
600 if (gPlayers[cs.PlayerStat[i].Num] <> nil) and (gPlayers[cs.PlayerStat[i].Num].FReady) then s := s + ' *';
601 r_Common_DrawText(s, x, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_LEFTUP);
602 if endview = false then
603 begin
604 // Player ping/loss
605 s := Format(_lc[I_GAME_PING_MS], [cs.PlayerStat[i].Ping, cs.PlayerStat[i].Loss]);
606 r_Common_DrawText(s, x + w1, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
607 end;
608 // Player frags
609 s := IntToStr(cs.PlayerStat[i].Frags);
610 r_Common_DrawText(s, x + w1 + w2, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
611 // Player deaths
612 s := IntToStr(cs.PlayerStat[i].Deaths);
613 r_Common_DrawText(s, x + w1 + w2 + w3, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
615 INC(yy, ch);
616 end;
617 end;
618 INC(yy, ch);
619 end;
620 end
621 else if cs.GameMode in [GM_DM, GM_COOP] then
622 begin
623 r_Common_DrawText(_lc[I_GAME_PLAYER_NAME], x, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
624 if endview = false then
625 r_Common_DrawText(_lc[I_GAME_PING], x + w1, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
626 r_Common_DrawText(_lc[I_GAME_FRAGS], x + w1 + w2, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
627 r_Common_DrawText(_lc[I_GAME_DEATHS], x + w1 + w2 + w3, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
628 INC(yy, ch + ch div 2);
629 for i := 0 to players - 1 do
630 begin
631 // rr := 255; gg := 127; bb := 0;
632 rr := 255; gg := 255; bb := 255;
633 if cs.PlayerStat[i].Spectator then
634 begin
635 rr := rr div 2; gg := gg div 2; bb := bb div 2;
636 end;
638 // Player color
639 r_Draw_Rect(x, yy, x + 16 - 1, yy + 16 - 1, 192, 192, 192, 255);
640 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);
641 // Player name
642 if gShowPIDs then s := Format('[%5d] %s', [cs.PlayerStat[i].UID, cs.PlayerStat[i].Name]) else s := cs.PlayerStat[i].Name;
643 if (gPlayers[cs.PlayerStat[i].Num] <> nil) and (gPlayers[cs.PlayerStat[i].Num].FReady) then s := s + ' *';
644 r_Common_DrawText(s, x + 16 + 8, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_LEFTUP);
645 if endview = false then
646 begin
647 // Player ping/loss
648 s := Format(_lc[I_GAME_PING_MS], [cs.PlayerStat[i].Ping, cs.PlayerStat[i].Loss]);
649 r_Common_DrawText(s, x + w1, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
650 end;
651 // Player frags
652 s := IntToStr(cs.PlayerStat[i].Frags);
653 r_Common_DrawText(s, x + w1 + w2, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
654 // Player deaths
655 s := IntToStr(cs.PlayerStat[i].Deaths);
656 r_Common_DrawText(s, x + w1 + w2 + w3, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
658 INC(yy, ch + ch div 2);
659 end;
660 end;
661 end;
663 procedure r_Render_DrawStatsWindow (x, y, w, h: Integer; cs: TEndCustomGameStat; endview: Boolean);
664 var xoff, yoff, cw, ch: Integer; s: AnsiString;
665 begin
666 xoff := 0; yoff := 8;
667 r_Draw_GetTextSize('W', stdfont, cw, ch);
668 r_Draw_FillRect(x, y, x + w - 1, y + h - 1, 64, 64, 64, 224);
669 r_Draw_Rect(x, y, x + w - 1, y + h - 1, 255, 127, 0, 255);
671 (* LINE 1 *)
673 if endview = false then
674 begin
675 case NetMode of
676 NET_SERVER: s := _lc[I_NET_SERVER];
677 NET_CLIENT: s := NetClientIP + ':' + IntToStr(NetClientPort);
678 otherwise s := '';
679 end;
680 r_Common_DrawText(s, x + 16, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
681 end;
683 case cs.GameMode of
684 GM_DM: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_DM] else s := _lc[I_GAME_LMS];
685 GM_TDM: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_TDM] else s := _lc[I_GAME_TLMS];
686 GM_CTF: s := _lc[I_GAME_CTF];
687 GM_COOP: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_COOP] else s := _lc[I_GAME_SURV];
688 otherwise s := 'GAME MODE ' + IntToStr(gGameSettings.GameMode);
689 end;
690 r_Common_DrawText(s, x + w div 2, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
692 if endview = false then
693 begin
694 s := r_Common_TimeToStr(cs.GameTime);
695 r_Common_DrawText(s, x + w - 16, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
696 end;
698 INC(yoff, ch + ch div 2);
700 (* LINE 2/3 *)
702 s := cs.Map;
703 if cs.MapName <> '' then
704 s := s + ' - ' + cs.MapName;
706 if endview = false then
707 begin
708 r_Common_DrawText(s, x + w div 2, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_UP);
709 INC(yoff, ch + ch div 2);
710 case cs.GameMode of
711 GM_DM, GM_TDM: s := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]);
712 GM_CTF: s := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.ScoreLimit]);
713 GM_COOP: s := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
714 otherwise s := '';
715 end;
716 r_Common_DrawText(s, x + 16, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_LEFTUP);
717 case cs.GameMode of
718 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]);
719 GM_COOP: s := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
720 otherwise s := '';
721 end;
722 r_Common_DrawText(s, x + w - 16, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_RIGHTUP);
723 INC(yoff, ch);
724 end
725 else
726 begin
727 xoff := MAX(Length(_lc[I_MENU_MAP]) + 1, Length(_lc[I_GAME_GAME_TIME]) + 1) * cw;
728 r_Common_DrawText(_lc[I_MENU_MAP], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
729 r_Common_DrawText(s, x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
730 INC(yoff, ch);
731 r_Common_DrawText(_lc[I_GAME_GAME_TIME], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
732 r_Common_DrawText(r_Common_TimeToStr(cs.GameTime), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
733 INC(yoff, ch);
734 end;
736 INC(yoff, ch);
738 (* LINE 4/5 *)
740 if endview and (cs.GameMode = GM_COOP) then
741 begin
742 xoff := MAX(Length(_lc[I_GAME_MONSTERS]) + 1, Length(_lc[I_GAME_SECRETS]) + 1) * cw;
743 r_Common_DrawText(_lc[I_GAME_MONSTERS], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
744 r_Common_DrawText(IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
745 INC(yoff, ch);
746 r_Common_DrawText(_lc[I_GAME_SECRETS], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
747 r_Common_DrawText(IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
748 INC(yoff, ch);
749 INC(yoff, ch);
750 end;
752 (* LINE 6/7 *)
754 if endview and (cs.GameMode = GM_COOP) and gLastMap then
755 begin
756 xoff := MAX(Length(_lc[I_GAME_MONSTERS_TOTAL]) + 1, Length(_lc[I_GAME_SECRETS_TOTAL]) + 1) * cw;
757 r_Common_DrawText(_lc[I_GAME_MONSTERS_TOTAL], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
758 r_Common_DrawText(IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
759 INC(yoff, ch);
760 r_Common_DrawText(_lc[I_GAME_SECRETS_TOTAL], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
761 r_Common_DrawText(IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
762 INC(yoff, ch);
763 INC(yoff, ch);
764 end;
766 (* LINE *)
768 if endview and (cs.GameMode in [GM_TDM, GM_CTF]) then
769 begin
770 if cs.TeamStat[TEAM_RED].Score > cs.TeamStat[TEAM_BLUE].Score then s := _lc[I_GAME_WIN_RED]
771 else if cs.TeamStat[TEAM_BLUE].Score > cs.TeamStat[TEAM_RED].Score then s := _lc[I_GAME_WIN_BLUE]
772 else s := _lc[I_GAME_WIN_DRAW];
773 r_Common_DrawText(s, x + w div 2, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
774 INC(yoff, ch);
775 INC(yoff, ch);
776 end;
778 (* LINE n *)
780 r_Render_DrawStatsColumns(cs, x + 16, y + yoff, w - 16 - 16, endview);
781 end;
783 function r_Render_StatsHeight (players: Integer): Integer;
784 var cw, ch: Integer;
785 begin
786 ASSERT(players >= 0);
787 r_Draw_GetTextSize('W', stdfont, cw, ch);
788 case gGameSettings.GameMode of
789 GM_TDM, GM_CTF: result := 32 + ch * (11 + players);
790 otherwise result := 40 + ch * 5 + (ch + 8) * players;
791 end;
792 end;
794 procedure r_Render_DrawStats;
795 var x, y, w, h, players: Integer; cs: TEndCustomGameStat;
796 begin
797 cs.PlayerStat := g_Player_GetStats();
798 SortGameStat(cs.PlayerStat);
799 cs.TeamStat := gTeamStat;
800 cs.GameTime := gTime;
801 cs.GameMode := gGameSettings.GameMode;
802 cs.Map := g_ExtractWadNameNoPath(gMapInfo.Map) + ':' + g_ExtractFileName(gMapInfo.Map);
803 cs.MapName := gMapInfo.Name;
804 if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
805 w := gScreenWidth - (gScreenWidth div 5);
806 h := r_Render_StatsHeight(players);
807 x := (gScreenWidth div 2) - (w div 2);
808 y := (gScreenHeight div 2) - (h div 2);
809 r_Render_DrawStatsWindow(x, y, w, h, cs, false);
810 end;
812 procedure r_Render_DrawCustomStats;
813 var cw, ch, s: AnsiString;
814 begin
815 if gStatsOff then
816 begin
817 r_Common_DrawText(_lc[I_MENU_INTER_NOTICE_TAB], gScreenWidth div 2, 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
818 end
819 else
820 begin
821 case gGameSettings.GameMode of
822 GM_COOP: if gMissionFailed then s := _lc[I_MENU_INTER_MISSION_FAIL] else s := _lc[I_MENU_INTER_LEVEL_COMPLETE];
823 otherwise s := _lc[I_MENU_INTER_ROUND_OVER];
824 end;
825 r_Common_DrawText(s, gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
827 if gChatShow = false then
828 begin
829 if g_Game_IsClient then s := _lc[I_MENU_INTER_NOTICE_MAP] else s := _lc[I_MENU_INTER_NOTICE_SPACE];
830 r_Common_DrawText(s, gScreenWidth div 2, gScreenHeight - 4, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
831 if g_Game_IsNet then
832 begin
833 s := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
834 r_Common_DrawText(s, gScreenWidth div 2, gScreenHeight - 16 - 4, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
835 end;
836 end;
838 r_Render_DrawStatsWindow(32, 64, gScreenWidth - 32 * 2, gScreenHeight - 64 * 2, CustomStat, true);
839 end;
840 end;
842 procedure r_Render_DrawValueOf (a, b, x, y: Integer; f: TGLFont);
843 var wa, wb, ch: Integer; sa, sb: AnsiString;
844 begin
845 sa := IntToStr(a);
846 sb := IntToStr(b);
847 r_Draw_GetTextSize(sa, f, wa, ch);
848 r_Draw_GetTextSize(sa + ' / ', f, wb, ch);
849 r_Common_DrawText(sa, x, y, 255, 0, 0, 255, f, TBasePoint.BP_LEFTUP);
850 r_Common_DrawText(' / ', x + wa, y, 255, 255, 255, 255, f, TBasePoint.BP_LEFTUP);
851 r_Common_DrawText(sb, x + wb, y, 255, 0, 0, 255, f, TBasePoint.BP_LEFTUP);
852 end;
854 procedure r_Render_DrawSinglStatsPlayer (player, x, y, w1: Integer);
855 var time, kpm: Single;
856 begin
857 r_Common_DrawText(_lc[I_MENU_INTER_KILLS], x, y, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
858 r_Render_DrawValueOf(SingleStat.PlayerStat[player].Kills, gTotalMonsters, x + w1, y, MenuFont);
859 r_Common_DrawText(_lc[I_MENU_INTER_KPM], x, y + 32, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
860 time := SingleStat.GameTime / 1000;
861 kpm := SingleStat.PlayerStat[player].Kills;
862 if time > 0 then kpm := kpm / time * 60;
863 r_Common_DrawText(Format('%.1f', [kpm]), x + w1, y + 32, 255, 0, 0, 255, menufont, TBasePoint.BP_LEFTUP);
864 r_Common_DrawText(_lc[I_MENU_INTER_SECRETS], x, y + 64, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
865 r_Render_DrawValueOf(SingleStat.PlayerStat[player].Secrets, SingleStat.TotalSecrets, x + w1, y + 64, MenuFont);
866 end;
868 procedure r_Render_DrawSingleStats;
869 var xx, wa, wb, ww, ch: Integer; s: AnsiString;
870 begin
871 r_Common_DrawText(_lc[I_MENU_INTER_LEVEL_COMPLETE], gScreenWidth div 2, 32, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
873 r_Draw_GetTextSize(_lc[I_MENU_INTER_KPM] + ' ', menufont, wa, ch);
874 r_Draw_GetTextSize(' 9999.9', menufont, wb, ch);
875 ww := wa + wb;
876 xx := gScreenWidth div 2 - ww div 2;
878 s := r_Common_TimeToStr(SingleStat.GameTime);
879 r_Common_DrawText(_lc[I_MENU_INTER_TIME], xx, 80, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
880 r_Common_DrawText(s, xx + wa, 80, 255, 0, 0, 255, menufont, TBasePoint.BP_LEFTUP);
882 if SingleStat.TwoPlayers then
883 begin
884 r_Common_DrawText(_lc[I_MENU_PLAYER_1], gScreenWidth div 2, 128, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
885 r_Render_DrawSinglStatsPlayer(0, xx, 176, wa);
886 r_Common_DrawText(_lc[I_MENU_PLAYER_2], gScreenWidth div 2, 288, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
887 r_Render_DrawSinglStatsPlayer(1, xx, 336, wa);
888 end
889 else
890 begin
891 r_Render_DrawSinglStatsPlayer(0, xx, 128, wa);
892 end;
893 end;
895 procedure r_Render_DrawSpectHud;
896 var xoff: Integer; s: AnsiString;
898 procedure AddText (s1, s2: AnsiString);
899 var w1, w2, ww, ch: Integer;
900 begin
901 r_Draw_GetTextSize(s1, stdfont, w1, ch);
902 r_Draw_GetTextSize(s2, stdfont, w2, ch);
903 ww := MAX(w1, w2);
904 r_Common_DrawText(s1, xoff + ww div 2, gScreenHeight - ch, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
905 r_Common_DrawText(s2, xoff + ww div 2, gScreenHeight - ch, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
906 xoff := xoff + ww + 16;
907 end;
909 begin
910 xoff := 0;
911 case gSpectMode of
912 SPECT_STATS: s := 'MODE: Stats';
913 SPECT_MAPVIEW: s := 'MODE: Observe Map';
914 SPECT_PLAYERS: s := 'MODE: Watch Players';
915 otherwise s := 'MODE: ' + IntToStr(gSpectMode);
916 end;
917 AddText(s, '< jump >');
918 if gSpectMode = SPECT_STATS then
919 AddText('Autoview', '< fire >');
920 if gSpectMode = SPECT_MAPVIEW then
921 AddText('[-] Step ' + IntToStr(gSpectStep) + ' [+]', '<prev weap> <next weap>');
922 if gSpectMode = SPECT_PLAYERS then
923 begin
924 AddText('Player 1', '<left/right>');
925 if gSpectViewTwo then
926 AddText('Player 2', '<prev w/next w>');
927 AddText('2x View', '<up/down>');
928 end;
929 end;
931 function GetActivePlayer_ByID (id: Integer): TPlayer;
932 var i, len: Integer; p: TPlayer;
933 begin
934 p := nil;
935 if (id >= 0) and (gPlayers <> nil) then
936 begin
937 i := 0; len := Length(gPlayers);
938 while (i < len) and ((IsActivePlayer(gPlayers[i]) = false) or (gPlayers[i].UID <> id)) do INC(i);
939 if i < len then p := gPlayers[i];
940 end;
941 result := p;
942 end;
944 procedure r_Render_DrawMinimap (x, y: Integer; alpha: Byte);
945 const scale = 16;
947 function IsMinimapPanel (const p: TPanel): Boolean;
948 begin
949 result := (p <> nil) and p.Enabled;
950 if result then
951 begin
952 case p.PanelType of
953 PANEL_WALL, PANEL_WATER, PANEL_ACID1, PANEL_ACID2,
954 PANEL_STEP, PANEL_OPENDOOR, PANEL_CLOSEDOOR,
955 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
956 result := true;
957 otherwise
958 result := false;
959 end;
960 end;
961 end;
963 procedure DrawObject (xx, yy, ww, hh: Integer; r, g, b: Byte);
964 var x0, y0, x1, y1: Integer;
965 begin
966 x0 := x + xx div scale;
967 y0 := y + yy div scale;
968 x1 := x + (xx + ww - 1) div scale;
969 y1 := y + (yy + hh - 1) div scale;
970 r_Draw_FillRect(x0, y0, x1, y1, r, g, b, alpha);
971 end;
973 procedure DrawPanels (const a: TPanelArray);
974 var i: Integer; p: TPanel; c: TRGB;
975 begin
976 if a <> nil then
977 begin
978 for i := 0 to HIGH(a) do
979 begin
980 p := a[i];
981 if IsMinimapPanel(p) then
982 begin
983 case p.PanelType of
984 PANEL_WALL: c := _RGB(208, 208, 208);
985 PANEL_OPENDOOR: c := _RGB(160, 160, 160);
986 PANEL_CLOSEDOOR: c := _RGB(160, 160, 160);
987 PANEL_STEP: c := _RGB(128, 128, 128);
988 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
989 case p.LiftType of
990 LIFTTYPE_UP: c := _RGB(116, 72, 36);
991 LIFTTYPE_DOWN: c := _RGB(116, 124, 96);
992 LIFTTYPE_LEFT: c := _RGB(116, 200, 80);
993 LIFTTYPE_RIGHT: c := _RGB(116, 252, 140);
994 otherwise c := _RGB(255, 0, 0);
995 end;
996 PANEL_WATER: c := _RGB(0, 0, 192);
997 PANEL_ACID1: c := _RGB(0, 176, 0);
998 PANEL_ACID2: c := _RGB(176, 0, 0);
999 otherwise c := _RGB(255, 0, 0);
1000 end;
1001 DrawObject(p.x, p.y, p.width, p.height, c.r, c.g, c.b);
1002 end;
1003 end;
1004 end;
1005 end;
1007 procedure DrawPlayers;
1008 var i: Integer; p: TPlayer; c: TRGB;
1009 begin
1010 if gPlayers <> nil then
1011 begin
1012 for i := 0 to HIGH(gPlayers) do
1013 begin
1014 p := gPlayers[i];
1015 if p.Alive then
1016 begin
1017 case p.Team of
1018 TEAM_RED: c := _RGB(255, 0, 0);
1019 TEAM_BLUE: c := _RGB(0, 0, 255);
1020 otherwise c := _RGB(255, 128, 0);
1021 end;
1022 DrawObject(p.obj.x, p.obj.y, p.obj.rect.width, p.obj.rect.height, c.r, c.g, c.b);
1023 end;
1024 end;
1025 end;
1026 end;
1028 function DrawMonster (m: TMonster): Boolean;
1029 begin
1030 result := false; // don't stop
1031 if m.alive then
1032 DrawObject(m.obj.x, m.obj.y, m.obj.rect.width, m.obj.rect.height, 255, 255, 0);
1033 end;
1035 begin
1036 r_Draw_FillRect(x, y, (x + gMapInfo.Width - 1) div scale, (y + gMapInfo.Height - 1) div scale, 0, 0, 0, alpha);
1037 DrawPanels(gSteps);
1038 DrawPanels(gLifts);
1039 DrawPanels(gWater);
1040 DrawPanels(gAcid1);
1041 DrawPanels(gAcid2);
1042 DrawPanels(gWalls);
1043 g_Mons_ForEach(DrawMonster);
1044 DrawPlayers;
1045 end;
1047 procedure r_Render_Draw;
1048 var p1, p2: TPlayer; time: LongWord;
1049 begin
1050 if gExit = EXIT_QUIT then
1051 exit;
1053 INC(FPSCounter);
1054 time := GetTickCount64();
1055 if time - FPSTime >= 1000 then
1056 begin
1057 FPS := FPSCounter;
1058 FPSCounter := 0;
1059 FPSTime := time;
1060 end;
1062 r_Draw_Setup(gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight);
1064 glClearColor(0.0, 0.0, 0.0, 0.0);
1065 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
1067 p1 := nil;
1068 p2 := nil;
1069 if gGameOn or (gState = STATE_FOLD) then
1070 begin
1071 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
1072 begin
1073 if gRevertPlayers then
1074 begin
1075 p1 := gPlayer2;
1076 p2 := gPlayer1;
1077 end
1078 else
1079 begin
1080 p1 := gPlayer1;
1081 p2 := gPlayer2;
1082 end;
1083 end
1084 else if gPlayer1 <> nil then
1085 begin
1086 p1 := gPlayer1;
1087 end
1088 else if gPlayer2 <> nil then
1089 begin
1090 p1 := gPlayer2;
1091 end;
1092 if (gSpectMode = SPECT_PLAYERS) and (gPlayers <> nil) then
1093 begin
1094 p1 := GetActivePlayer_ByID(gSpectPID1);
1095 if p1 = nil then
1096 p1 := GetActivePlayer_ByID(GetActivePlayerID_Next());
1097 if gSpectViewTwo then
1098 begin
1099 p2 := GetActivePlayer_ByID(gSpectPID2);
1100 if p2 = nil then
1101 p2 := GetActivePlayer_ByID(GetActivePlayerID_Next());
1102 end;
1103 end;
1104 end;
1106 if gGameOn or ((gState in [STATE_FOLD]) and (EndingGameCounter < 255)) then
1107 begin
1108 if gSpectMode = SPECT_MAPVIEW then
1109 begin
1110 r_Render_DrawMapView(0, 0, gScreenWidth, gScreenHeight, gSpectX + gScreenWidth div 2, gSpectY + gScreenHeight div 2);
1111 end
1112 else if (p1 <> nil) and (p2 <> nil) then
1113 begin
1114 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight div 2 - 2, p1);
1115 r_Render_DrawPlayerView(0, gScreenHeight div 2 + 2, gScreenWidth, gScreenHeight div 2, p2);
1116 end
1117 else if p1 <> nil then
1118 begin
1119 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, p1);
1120 end
1121 else if p2 <> nil then
1122 begin
1123 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, p2);
1124 end;
1126 if gShowMap then
1127 r_Render_DrawMiniMap(0, 0, 160);
1129 {$IFDEF ENABLE_HOLMES}
1130 r_Holmes_Draw;
1131 {$ENDIF}
1133 if MessageText <> '' then
1134 r_Common_DrawFormatText(MessageText, (gScreenWidth - 196) div 2, gScreenHeight div 2, 255, menufont, TBasePoint.BP_CENTER);
1136 if IsDrawStat or (gSpectMode = SPECT_STATS) then
1137 r_Render_DrawStats;
1139 if gSpectHUD and (gChatShow = false) and (gSpectMode <> SPECT_NONE) and (gSpectAuto = false) then
1140 r_Render_DrawSpectHud;
1141 end;
1143 if gPauseMain and gGameOn {$IFDEF ENABLE_MENU}and (g_ActiveWindow = nil){$ENDIF} then
1144 begin
1145 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1146 r_Common_DrawText(_lc[I_MENU_PAUSE], gScreenWidth div 2, gScreenHeight div 2, 255, 255, 255, 255, menufont, TBasePoint.BP_CENTER);
1147 end;
1149 if not gGameOn then
1150 begin
1151 // TODO F key handle
1152 case gState of
1153 STATE_NONE: (* do nothing *) ;
1154 STATE_MENU: r_Common_DrawBackground(GameWad + ':TEXTURES/TITLE');
1155 STATE_FOLD:
1156 begin
1157 if EndingGameCounter > 0 then
1158 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
1159 end;
1160 STATE_INTERCUSTOM:
1161 begin
1162 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1163 if EndPicPath <> '' then
1164 r_Common_DrawBackground(EndPicPath)
1165 else
1166 r_Common_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC])
1167 else
1168 r_Common_DrawBackground(GameWad + ':TEXTURES/INTER');
1170 r_Render_DrawCustomStats;
1172 {$IFDEF ENABLE_MENU}
1173 if g_ActiveWindow <> nil then
1174 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1175 {$ENDIF}
1176 end;
1177 STATE_INTERSINGLE, STATE_INTERTEXT, STATE_INTERPIC:
1178 begin
1179 if EndingGameCounter > 0 then
1180 begin
1181 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
1182 end
1183 else
1184 begin
1185 r_Common_DrawBackground(GameWad + ':TEXTURES/INTER');
1186 r_Render_DrawSingleStats;
1187 {$IFDEF ENABLE_MENU}
1188 if g_ActiveWindow <> nil then
1189 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1190 {$ENDIF}
1191 end;
1192 end;
1193 STATE_ENDPIC:
1194 begin
1195 if EndPicPath <> '' then
1196 r_Common_DrawBackground(EndPicPath)
1197 else
1198 r_Common_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC]);
1199 {$IFDEF ENABLE_MENU}
1200 if g_ActiveWindow <> nil then
1201 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1202 {$ENDIF}
1203 end;
1204 STATE_SLIST:
1205 begin
1206 r_Common_DrawBackground(GameWad + ':TEXTURES/TITLE');
1207 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1208 r_Render_DrawServerList(slCurrent, slTable);
1209 end;
1210 end;
1211 end;
1213 {$IFDEF ENABLE_MENU}
1214 if g_ActiveWindow <> nil then
1215 begin
1216 if gGameOn then
1217 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1218 r_GUI_Draw_Window(g_ActiveWindow);
1219 end;
1220 {$ENDIF}
1222 r_Console_Draw(false);
1224 // TODO g_debug_Sounds
1226 if gShowFPS then
1227 begin
1228 r_Common_DrawText('FPS: ' + IntToStr(FPS), 0, 0, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
1229 r_Common_DrawText('UPS: ' + IntToStr(UPS), 0, 16, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
1230 end;
1232 if gGameOn and gShowTime then
1233 begin
1234 r_Common_DrawText(r_Common_TimeToStr(gTime), gScreenWidth - 4, gScreenHeight - 1, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTDOWN);
1235 end;
1237 // TODO draw profilers
1239 {$IFDEF ENABLE_HOLMES}
1240 r_Holmes_DrawUI;
1241 {$ENDIF}
1243 // TODO draw touch screen controls
1245 sys_Repaint;
1246 end;
1248 procedure r_Render_Resize (w, h: Integer);
1249 begin
1250 gWinSizeX := w;
1251 gWinSizeY := h;
1252 gRC_Width := w;
1253 gRC_Height := h;
1254 gScreenWidth := Round(w / r_pixel_scale);
1255 gScreenHeight := Round(h / r_pixel_scale);
1256 end;
1258 procedure r_Render_Apply;
1259 begin
1260 {$IFDEF ENABLE_SYSTEM}
1261 if sys_SetDisplayModeGL(GetInfo()) then
1262 e_LogWriteln('resolution changed')
1263 else
1264 e_LogWriteln('resolution not changed');
1265 sys_EnableVSync(gVSync)
1266 {$ENDIF}
1267 end;
1269 function r_Render_WriteScreenShot (filename: String): Boolean;
1270 begin
1271 // TODO write screenshot file
1272 Result := False;
1273 end;
1275 {$IFDEF ENABLE_GIBS}
1276 function r_Render_GetGibRect (m, id: Integer): TRectWH;
1277 begin
1278 result := r_Map_GetGibSize(m, id);
1279 end;
1280 {$ENDIF}
1282 {$IFDEF ENABLE_GFX}
1283 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
1284 begin
1285 r_Map_NewGFX(AnimType, X, Y);
1286 end;
1287 {$ENDIF}
1289 {$IFDEF ENABLE_TOUCH}
1290 procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
1291 begin
1292 // TODO implement touchscreen
1293 founded := False;
1294 end;
1295 {$ENDIF}
1297 {$IFDEF ENABLE_MENU}
1298 procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
1299 begin
1300 r_GUI_GetSize(ctrl, w, h);
1301 end;
1303 procedure r_Render_GetLogoSize (out w, h: Integer);
1304 begin
1305 r_GUI_GetLogoSize(w, h);
1306 end;
1308 procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
1309 begin
1310 r_GUI_GetMaxFontSize(BigFont, w, h);
1311 end;
1313 procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
1314 begin
1315 r_GUI_GetStringSize(BigFont, str, w, h);
1316 end;
1317 {$ENDIF}
1319 procedure r_Render_SetProcessLoadingCallback (p: TProcedure);
1320 begin
1321 r_Common_ProcessLoadingCallback := p;
1322 end;
1324 procedure r_Render_ClearLoading;
1325 begin
1326 r_Common_ClearLoading;
1327 end;
1329 procedure r_Render_SetLoading (const text: String; maxval: Integer);
1330 begin
1331 r_Common_SetLoading(text, maxval);
1332 end;
1334 procedure r_Render_StepLoading (incval: Integer);
1335 begin
1336 r_Common_StepLoading(incval);
1337 end;
1339 procedure r_Render_DrawLoading (force: Boolean);
1340 begin
1341 r_Common_DrawLoading(force);
1342 end;
1344 {$IFDEF ENABLE_HOLMES}
1345 function pmsCurMapX (): Integer;
1346 begin
1347 result := r_holmes.pmsCurMapX();
1348 end;
1350 function pmsCurMapY (): Integer;
1351 begin
1352 result := r_holmes.pmsCurMapY();
1353 end;
1355 function r_Render_HolmesViewIsSet (): Boolean;
1356 begin
1357 result := vpSet;
1358 end;
1359 {$ENDIF}
1361 end.