DEADSOFTWARE

gl: draw fps
[d2df-sdl.git] / src / game / renders / opengl / r_render.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../../../shared/a_modes.inc}
16 unit r_render;
18 interface
20 uses
21 {$IFDEF ENABLE_MENU}
22 g_gui,
23 {$ENDIF}
24 g_base // TRectWH
25 ;
27 (* render startup *)
28 procedure r_Render_Initialize;
29 procedure r_Render_Finalize;
31 (* load globally used textures *)
32 procedure r_Render_Load;
33 procedure r_Render_Free;
35 (* load map specific textures *)
36 procedure r_Render_LoadTextures;
37 procedure r_Render_FreeTextures;
39 procedure r_Render_Update;
40 procedure r_Render_Draw;
42 procedure r_Render_Resize (w, h: Integer);
43 procedure r_Render_Apply;
45 function r_Render_WriteScreenShot (filename: String): Boolean;
47 {$IFDEF ENABLE_GIBS}
48 function r_Render_GetGibRect (m, id: Integer): TRectWH;
49 {$ENDIF}
51 {$IFDEF ENABLE_GFX}
52 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
53 {$ENDIF}
55 {$IFDEF ENABLE_TOUCH}
56 // touch screen button location and size
57 procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
58 {$ENDIF}
60 {$IFDEF ENABLE_MENU}
61 procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
62 procedure r_Render_GetLogoSize (out w, h: Integer);
63 procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
64 procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
65 {$ENDIF}
67 procedure r_Render_DrawLoading (force: Boolean); // !!! remove it
69 implementation
71 uses
72 {$IFDEF USE_GLES1}
73 GLES11,
74 {$ELSE}
75 GL, GLEXT,
76 {$ENDIF}
77 {$IFDEF ENABLE_MENU}
78 r_gui,
79 {$ENDIF}
80 {$IFDEF ENABLE_SYSTEM}
81 g_system,
82 {$ENDIF}
83 SysUtils, Classes, Math,
84 g_basic,
85 e_log, utils, wadreader, mapdef,
86 g_game, g_map, g_panel, g_options, g_console, g_player, g_weapons, g_language, g_triggers, g_monsters,
87 g_net, g_netmaster,
88 r_draw, r_textures, r_fonts, r_common, r_console, r_map
89 ;
91 var
92 BackgroundTexture: THereTexture;
94 hud, hudbg: TGLTexture;
95 hudhp: array [Boolean] of TGLTexture;
96 hudap: TGLTexture;
97 hudwp: array [0..WP_LAST] of TGLTexture;
98 hudkey: array [0..2] of TGLTexture;
99 hudair: TGLTexture;
100 hudjet: TGLTexture;
101 hudrflag, hudrflags, hudrflagd: TGLTexture;
102 hudbflag, hudbflags, hudbflagd: TGLTexture;
104 FPS, FPSCounter, FPSTime: LongWord;
106 procedure r_Render_LoadTextures;
107 begin
108 r_Map_LoadTextures;
109 end;
111 procedure r_Render_FreeTextures;
112 begin
113 r_Map_FreeTextures;
114 end;
116 procedure r_Render_Load;
117 const
118 WeapName: array [0..WP_LAST] of AnsiString = ('KASTET', 'SAW', 'PISTOL', 'SHOTGUN1', 'SHOTGUN2', 'MGUN', 'RLAUNCHER', 'PGUN', 'BFG', 'SPULEMET', 'FLAMETHROWER');
119 var
120 i: Integer;
121 begin
122 r_Common_Load;
123 BackgroundTexture := DEFAULT(THereTexture);
124 hud := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/HUD');
125 hudbg := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/HUDBG');
126 hudhp[false] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/MED2');
127 hudhp[true] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/BMED');
128 hudap := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/ARMORHUD');
129 for i := 0 to WP_LAST do
130 hudwp[i] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/' + WeapName[i]);
131 hudkey[0] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYR');
132 hudkey[1] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYG');
133 hudkey[2] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYB');
134 hudair := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/AIRBAR');
135 hudjet := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/JETBAR');
136 hudrflag := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_BASE');
137 hudrflags := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_STOLEN');
138 hudrflagd := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_DROP');
139 hudbflag := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_BASE');
140 hudbflags := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_STOLEN');
141 hudbflagd := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_DROP');
142 r_Console_Load;
143 r_Map_Load;
144 {$IFDEF ENABLE_MENU}
145 r_GUI_Load;
146 {$ENDIF}
147 end;
149 procedure r_Render_Free;
150 var i: Integer;
151 begin
152 {$IFDEF ENABLE_MENU}
153 r_GUI_Free;
154 {$ENDIF}
155 r_Map_Free;
156 r_Console_Free;
157 hudbflagd.Free;
158 hudbflags.Free;
159 hudbflag.Free;
160 hudrflagd.Free;
161 hudrflags.Free;
162 hudrflag.Free;
163 hudjet.Free;
164 hudair.Free;
165 hudkey[0].Free;
166 hudkey[1].Free;
167 hudkey[2].Free;
168 for i := 0 to WP_LAST do
169 begin
170 if hudwp[i] <> nil then
171 hudwp[i].Free;
172 hudwp[i] := nil;
173 end;
174 hudap.Free;
175 hudhp[true].Free;
176 hudhp[false].Free;
177 hudbg.Free;
178 hud.Free;
179 r_Common_FreeThis(BackgroundTexture);
180 r_Common_Free;
181 end;
183 {$IFDEF ENABLE_SYSTEM}
184 function GetInfo (): TGLDisplayInfo;
185 var info: TGLDisplayInfo;
186 begin
187 info := Default(TGLDisplayInfo);
188 info.w := Max(1, gRC_Width);
189 info.h := Max(1, gRC_Height);
190 info.bpp := Max(1, gBPP);
191 info.fullscreen := gRC_FullScreen;
192 info.maximized := gRC_Maximized;
193 info.major := 1;
194 info.minor := 1;
195 info.profile := TGLProfile.Compat;
196 result := info;
197 end;
198 {$ENDIF}
200 procedure r_Render_Initialize;
201 begin
202 {$IFDEF ENABLE_SYSTEM}
203 if sys_SetDisplayModeGL(GetInfo()) = False then
204 raise Exception.Create('Failed to set videomode on startup.');
205 sys_EnableVSync(gVSync);
206 {$ENDIF}
207 r_Textures_Initialize;
208 r_Console_Initialize;
209 r_Map_Initialize;
210 end;
212 procedure r_Render_Finalize;
213 begin
214 r_Map_Finalize;
215 r_Console_Finalize;
216 r_Textures_Finalize;
217 end;
219 procedure r_Render_Update;
220 begin
221 r_Console_Update;
222 r_Map_Update;
223 end;
225 procedure r_Render_DrawHUD (x, y: Integer; p: TPlayer);
226 var t: TGLTexture; s: AnsiString;
227 begin
228 ASSERT(p <> nil);
230 // hud area is 196 x 240 pixels
231 r_Common_DrawTexture(hud, x, y, hud.width, hud.height, TBasePoint.BP_LEFTUP);
232 r_Common_DrawText(p.name, x + 98, y + 16, 255, 0, 0, 255, smallfont, TBasePoint.BP_CENTER);
234 t := hudhp[R_BERSERK in p.FRulez];
235 r_Common_DrawTexture(t, x + 51, y + 61, t.width, t.height, TBasePoint.BP_CENTER);
236 r_Common_DrawTexture(hudap, x + 50, y + 85, hudap.width, hudap.height, TBasePoint.BP_CENTER);
238 r_Common_DrawText(IntToStr(MAX(0, p.health)), x + 174, y + 56, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
239 r_Common_DrawText(IntToStr(MAX(0, p.armor)), x + 174, y + 84, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
241 case p.CurrWeap of
242 WEAPON_KASTET, WEAPON_SAW: s := '--';
243 else s := IntToStr(p.GetAmmoByWeapon(p.CurrWeap));
244 end;
245 r_Common_DrawText(s, x + 174, y + 174, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
247 if p.CurrWeap <= WP_LAST then
248 begin
249 t := hudwp[p.CurrWeap];
250 r_Common_DrawTexture(t, x + 18, y + 160, t.width, t.height, TBasePoint.BP_LEFTUP);
251 end;
253 if R_KEY_RED in p.FRulez then
254 r_Common_DrawTexture(hudkey[0], x + 76, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
255 if R_KEY_GREEN in p.FRulez then
256 r_Common_DrawTexture(hudkey[1], x + 93, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
257 if R_KEY_BLUE in p.FRulez then
258 r_Common_DrawTexture(hudkey[2], x + 110, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
260 if p.JetFuel > 0 then
261 begin
262 r_Common_DrawTexture(hudair, x, y + 116, hudair.width, hudair.height, TBasePoint.BP_LEFTUP);
263 if p.air > 0 then
264 r_Draw_FillRect(x + 14, y + 116 + 4, x + 14 + 168 * p.air div AIR_MAX, y + 116 + 4 + 4, 0, 0, 196, 255);
265 r_Common_DrawTexture(hudjet, x, y + 126, hudjet.width, hudjet.height, TBasePoint.BP_LEFTUP);
266 r_Draw_FillRect(x + 14, y + 126 + 4, x + 14 + 168 * p.JetFuel div JET_MAX, y + 126 + 4 + 4, 208, 0, 0, 255);
267 end
268 else
269 begin
270 r_Common_DrawTexture(hudair, x, y + 124, hudair.width, hudair.height, TBasePoint.BP_LEFTUP);
271 if p.air > 0 then
272 r_Draw_FillRect(x + 14, y + 124 + 4, x + 14 + 168 * p.air div AIR_MAX, y + 124 + 4 + 4, 0, 0, 196, 255);
273 end;
274 end;
276 procedure r_Render_DrawHUDArea (x, y, w, h: Integer; p: TPlayer);
277 var s: AnsiString;
278 begin
279 r_Common_DrawTexture(hudbg, x, y, w, h, TBasePoint.BP_LEFTUP);
281 if p <> nil then
282 begin
283 r_Render_DrawHUD(x + w - 196 + 2, y, p);
284 if p.Spectator then
285 begin
286 r_Common_DrawText(_lc[I_PLAYER_SPECT], x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
287 r_Common_DrawText(_lc[I_PLAYER_SPECT2], x + 4, y + 258, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
288 r_Common_DrawText(_lc[I_PLAYER_SPECT1], x + 4, y + 274, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
289 if p.NoRespawn then
290 r_Common_DrawText(_lc[I_PLAYER_SPECT1S], x + 4, y + 290, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
291 end;
292 end;
294 if gShowPing and g_Game_IsClient then
295 begin
296 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
297 r_Common_DrawText(s, x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
298 end;
299 end;
301 procedure r_Render_DrawStatsView (x, y, w, h: Integer; p: TPlayer);
302 var fw, i, maxFrags, top, totalPlayers: Integer; sign: Char; stat: TPlayerStatArray; f: TGLTexture;
303 begin
304 ASSERT(p <> nil);
306 if gShowScore and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
307 begin
308 (* RED TEAM GOALS *)
309 fw := 0;
310 if gGameSettings.GameMode = GM_CTF then
311 begin
312 case gFlags[FLAG_RED].State of
313 FLAG_STATE_CAPTURED: f := hudrflags;
314 FLAG_STATE_DROPPED: f := hudrflagd;
315 otherwise f := hudrflag;
316 end;
317 if f <> nil then
318 begin
319 fw := f.width + 8; (* + space *)
320 r_Common_DrawTexture(f, x + w - 16, y + 240 - 72 - 4, f.width, f.height, TBasePoint.BP_RIGHTUP);
321 end;
322 end;
323 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);
325 (* BLUE TEAM GOALS *)
326 fw := 0;
327 if gGameSettings.GameMode = GM_CTF then
328 begin
329 case gFlags[FLAG_BLUE].State of
330 FLAG_STATE_CAPTURED: f := hudbflags;
331 FLAG_STATE_DROPPED: f := hudbflagd;
332 otherwise f := hudbflag;
333 end;
334 if f <> nil then
335 begin
336 fw := f.width + 8; (* + space *)
337 r_Common_DrawTexture(f, x + w - 16, y + 240 - 32 - 4, f.width, f.height, TBasePoint.BP_RIGHTUP);
338 end;
339 end;
340 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);
341 end;
343 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
344 begin
345 if gShowStat then
346 begin
347 r_Common_DrawText(IntToStr(p.Frags), x + w - 16, y, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHTUP);
349 top := 1;
350 maxFrags := 0;
351 totalPlayers := 0;
352 stat := g_Player_GetStats();
353 if stat <> nil then
354 begin
355 totalPlayers := Length(stat);
356 for i := 0 to High(stat) do
357 begin
358 if stat[i].Name <> p.Name then
359 begin
360 maxFrags := MAX(maxFrags, stat[i].Frags);
361 if stat[i].Frags > p.Frags then
362 top := top + 1;
363 end;
364 end;
365 end;
366 if p.Frags >= maxFrags then sign := '+' else sign := '-';
367 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);
368 end;
370 if gLMSRespawn > LMS_RESPAWN_NONE then
371 begin
372 r_Common_DrawText(_lc[I_GAME_WARMUP], x + w - 16 - 64, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_RIGHTDOWN);
373 r_Common_DrawText(': ' + IntToStr((gLMSRespawnTime - gTime) div 1000), x + w - 16 - 64, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_LEFTDOWN);
374 end
375 else if gShowLives and (gGameSettings.MaxLives > 0) then
376 begin
377 r_Common_DrawText(IntToStr(p.Lives), x + w - 16, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_RIGHTDOWN);
378 end;
379 end;
380 end;
382 procedure r_Render_DrawView (x, y, w, h: Integer; p: TPlayer);
383 var l, t, r, b, xx, yy: Integer;
384 begin
385 r_Draw_GetRect(l, t, r, b);
386 r_Draw_SetRect(x, y, x + w, y + h);
388 r_Common_GetCameraPos(p, true, xx, yy);
389 if p <> nil then
390 begin
391 r_Map_Draw(x, y, w, h, xx, yy, p);
392 r_Render_DrawStatsView(x, y, w, h, p);
393 if p.Spectator and p.NoRespawn then
394 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);
395 end
396 else
397 begin
398 r_Map_Draw(x, y, w, h, xx, yy, nil);
399 end;
401 r_Draw_SetRect(l, t, r, b);
402 end;
404 procedure r_Render_DrawMapView (x, y, w, h, camx, camy: Integer);
405 var l, t, r, b: Integer;
406 begin
407 r_Draw_GetRect(l, t, r, b);
408 r_Draw_SetRect(x, y, x + w, y + h);
409 r_Map_Draw(x, y, w, h, camx, camy, nil);
410 r_Draw_SetRect(l, t, r, b);
411 end;
413 procedure r_Render_DrawPlayerView (x, y, w, h: Integer; p: TPlayer);
414 var l, t, r, b: Integer;
415 begin
416 r_Draw_GetRect(l, t, r, b);
417 r_Draw_SetRect(x, y, x + w, y + h);
418 r_Render_DrawView(x, y, w - 196, h, p);
419 r_Render_DrawHUDArea(x + w - 196, y, 196, h, p);
420 r_Draw_SetRect(l, t, r, b);
421 end;
423 procedure r_Render_DrawBackgroundImage (img: TGLTexture);
424 var fw, w, h: LongInt;
425 begin
426 if img <> nil then
427 begin
428 img := BackgroundTexture.id;
429 if img.width = img.height then fw := img.width * 4 div 3 else fw := img.width; // fix aspect 4:3
430 r_Common_CalcAspect(fw, img.height, gScreenWidth, gScreenHeight, false, w, h);
431 r_Draw_Texture(img, gScreenWidth div 2 - w div 2, 0, w, h, false, 255, 255, 255, 255, false);
432 end
433 end;
435 procedure r_Render_DrawBackground (const name: AnsiString);
436 begin
437 if r_Common_LoadThis(name, BackgroundTexture) then
438 r_Render_DrawBackgroundImage(BackgroundTexture.id)
439 end;
441 procedure r_Render_DrawServerList (var SL: TNetServerList; var ST: TNetServerTable);
442 var ip: AnsiString; ww, hh, cw, ch, mw, mh, motdh, scrx, scry, i, mx, y: Integer; msg: SSArray; Srv: TNetServer;
443 begin
444 scrx := gScreenWidth div 2;
445 scry := gScreenHeight div 2;
447 r_Draw_GetTextSize(_lc[I_NET_SLIST], menufont, ww, hh);
448 r_Common_DrawText(_lc[I_NET_SLIST], gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
450 r_Draw_GetTextSize('W', stdfont, cw, ch);
451 motdh := gScreenHeight - 49 - ch * b_Text_LineCount(slMOTD);
453 r_Draw_FillRect(16, 64, gScreenWidth - 16, motdh, 64, 64, 64, 145);
454 r_Draw_Rect(16, 64, gScreenWidth - 16, motdh, 255, 127, 0, 255);
456 r_Common_DrawText(_lc[I_NET_SLIST_HELP], gScreenWidth div 2, gScreenHeight - 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
458 if slMOTD <> '' then
459 begin
460 r_Draw_FillRect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 64, 64, 64, 110);
461 r_Draw_Rect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 255, 127, 0, 255);
462 r_Common_DrawFormatText(slMOTD, 20, motdh + 3 + ch * i, 255, stdfont, TBasePoint.BP_LEFTUP);
463 end;
465 if not slReadUrgent and (slUrgent <> '') then
466 begin
467 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
468 r_Draw_FillRect(scrx - 256, scry - 60, scrx + 256, scry + 60, 64, 64, 64, 127);
469 r_Draw_Rect(scrx - 256, scry - 60, scrx + 256, scry + 60, 255, 127, 0, 255);
470 r_Draw_FillRect(scrx - 256, scry - 40, scrx + 256, scry - 40, 255, 127, 0, 255);
471 r_Common_DrawText(_lc[I_NET_SLIST_URGENT], scrx, scry - 58, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
472 r_Common_DrawFormatText(slUrgent, scrx - 253, scry - 38 + ch * i, 255, stdfont, TBasePoint.BP_LEFTUP);
473 r_Common_DrawText(_lc[I_NET_SLIST_URGENT_CONT], scrx, scry + 41, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
474 r_Draw_FillRect(scrx - 256, scry + 40, scrx + 256, scry + 40, 255, 127, 0, 255);
475 end
476 else if SL = nil then
477 begin
478 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
479 r_Draw_Rect(scrx - 192, scry - 10, scrx + 192, scry + 11, 255, 127, 0, 255);
480 r_Common_DrawText(slWaitStr, scrx, scry, 255, 255, 255, 255, stdfont, TBasePoint.BP_CENTER);
481 end
482 else
483 begin
484 y := 90;
485 if slSelection < Length(ST) then
486 begin
487 sy := y + 42 * slSelection - 4;
488 Srv := GetServerFromTable(slSelection, SL, ST);
489 ip := _lc[I_NET_ADDRESS] + ' ' + Srv.IP + ':' + IntToStr(Srv.Port);
490 ip := ip + ' ' + _lc[I_NET_SERVER_PASSWORD] + ' ';
491 if Srv.Password then ip := ip + _lc[I_MENU_YES] else ip := ip +_lc[I_MENU_NO];
492 end;
494 mw := gScreenWidth - 188;
495 mx := 16 + mw;
497 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy + 40, 64, 64, 64, 255);
498 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy, 205, 205, 205, 255);
499 r_Draw_FillRect(16 + 1, sy + 41, gScreenWidth - 16 - 1, sy + 41, 255, 255, 255, 255);
501 r_Draw_FillRect(16, 85, gScreenWidth - 16, 85, 255, 127, 0, 255);
502 r_Draw_FillRect(16, motdh - 20, gScreenWidth - 16, motdh - 20, 255, 127, 0, 255);
504 r_Draw_FillRect(mx - 70, 64, mx - 70, motdh, 255, 127, 0, 255);
505 r_Draw_FillRect(mx, 64, mx, motdh - 20, 255, 127, 0, 255);
506 r_Draw_FillRect(mx + 52, 64, mx + 52, motdh - 20, 255, 127, 0, 255);
507 r_Draw_FillRect(mx + 104, 64, mx + 104, motdh - 20, 255, 127, 0, 255);
509 r_Common_DrawText('NAME/MAP', 18, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
510 r_Common_DrawText('PING', mx - 68, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
511 r_Common_DrawText('MODE', mx + 2, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
512 r_Common_DrawText('PLRS', mx + 54, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
513 r_Common_DrawText('VER', mx + 106, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
515 for i := 0 to High(ST) do
516 begin
517 Srv := GetServerFromTable(i, SL, ST);
518 r_Common_DrawText(Srv.Name, 18, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
519 r_Common_DrawText(Srv.Map, 18, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
521 if Srv.Ping = 0 then
522 r_Common_DrawText('<1' + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
523 else if (Srv.Ping >= 0) and (Srv.Ping <= 999) then
524 r_Common_DrawText(IntToStr(Srv.Ping) + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
525 else
526 r_Common_DrawText(_lc[I_NET_SLIST_NO_ACCESS], mx - 68, y, 255, 0, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
527 if Length(ST[I].Indices) > 1 then
528 r_Common_DrawText('<' + IntToStr(Length(ST[I].Indices)) + '>', mx - 68, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
530 r_Common_DrawText(g_Game_ModeToText(Srv.GameMode), mx + 2, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
532 r_Common_DrawText(IntToStr(Srv.Players) + '/' + IntToStr(Srv.MaxPlayers), mx + 54, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
533 r_Common_DrawText(IntToStr(Srv.LocalPl) + '+' + IntToStr(Srv.Bots), mx + 54, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
535 r_Common_DrawText(IntToStr(Srv.Protocol), mx + 106, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
537 y := y + 42;
538 end;
540 r_Common_DrawText(ip, 20, motdh - 20 + 3, 205, 205, 205, 255, stdfont, TBasePoint.BP_LEFTUP);
541 r_Common_DrawText(IntToStr(Length(ST)) + _lc[I_NET_SLIST_SERVERS], gScreenWidth - 48, motdh - 20 + 3, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
542 end;
543 end;
545 procedure r_Render_DrawStatsColumns (constref cs: TEndCustomGameStat; x, y, w: Integer; endview: Boolean);
546 var i, cw, ch, yy, team, players, w1, w2, w3, w4, tw: Integer; r, g, b, rr, gg, bb: Byte; s: AnsiString;
547 begin
548 r_Draw_GetTextSize('W', stdfont, cw, ch);
549 w4 := cw * 6; (* deaths width *)
550 w3 := cw * 8; (* frags width *)
551 w2 := cw * 12; (* ping/loss width *)
552 w1 := w - w2 - w3 - w4; (* name width *)
553 tw := w1 - cw * 2 - w2; (* team goals *)
554 if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
555 yy := y;
556 if cs.GameMode in [GM_TDM, GM_CTF] then
557 begin
558 for team := TEAM_RED to TEAM_BLUE do
559 begin
560 case team of
561 TEAM_RED:
562 begin
563 s := _lc[I_GAME_TEAM_RED];
564 r := 255; g := 0; b := 0;
565 end;
566 TEAM_BLUE:
567 begin
568 s := _lc[I_GAME_TEAM_BLUE];
569 r := 0; g := 0; b := 255;
570 end;
571 end;
572 r_Common_DrawText(s, x, yy, r, g, b, 255, stdfont, TBasePoint.BP_LEFTUP);
573 r_Common_DrawText(IntToStr(cs.TeamStat[team].Score), x + tw, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
574 if endview = false then
575 r_Common_DrawText(_lc[I_GAME_PING], x + w1, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
576 r_Common_DrawText(_lc[I_GAME_FRAGS], x + w1 + w2, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
577 r_Common_DrawText(_lc[I_GAME_DEATHS], x + w1 + w2 + w3, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
578 INC(yy, ch);
580 INC(yy, ch div 4);
581 r_Draw_FillRect(x, yy, x + w - 1, yy, r, g, b, 255);
582 INC(yy, ch div 4);
584 for i := 0 to players - 1 do
585 begin
586 if cs.PlayerStat[i].Team = team then
587 begin
588 rr := r; gg := g; bb := b;
589 if cs.PlayerStat[i].Spectator then
590 begin
591 rr := r div 2; gg := g div 2; bb := b div 2;
592 end;
594 // Player name
595 if gShowPIDs then s := Format('[%5d] %s', [cs.PlayerStat[i].UID, cs.PlayerStat[i].Name]) else s := cs.PlayerStat[i].Name;
596 if (gPlayers[cs.PlayerStat[i].Num] <> nil) and (gPlayers[cs.PlayerStat[i].Num].FReady) then s := s + ' *';
597 r_Common_DrawText(s, x, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_LEFTUP);
598 if endview = false then
599 begin
600 // Player ping/loss
601 s := Format(_lc[I_GAME_PING_MS], [cs.PlayerStat[i].Ping, cs.PlayerStat[i].Loss]);
602 r_Common_DrawText(s, x + w1, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
603 end;
604 // Player frags
605 s := IntToStr(cs.PlayerStat[i].Frags);
606 r_Common_DrawText(s, x + w1 + w2, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
607 // Player deaths
608 s := IntToStr(cs.PlayerStat[i].Deaths);
609 r_Common_DrawText(s, x + w1 + w2 + w3, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
611 INC(yy, ch);
612 end;
613 end;
614 INC(yy, ch);
615 end;
616 end
617 else if cs.GameMode in [GM_DM, GM_COOP] then
618 begin
619 r_Common_DrawText(_lc[I_GAME_PLAYER_NAME], x, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
620 if endview = false then
621 r_Common_DrawText(_lc[I_GAME_PING], x + w1, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
622 r_Common_DrawText(_lc[I_GAME_FRAGS], x + w1 + w2, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
623 r_Common_DrawText(_lc[I_GAME_DEATHS], x + w1 + w2 + w3, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
624 INC(yy, ch + ch div 2);
625 for i := 0 to players - 1 do
626 begin
627 // rr := 255; gg := 127; bb := 0;
628 rr := 255; gg := 255; bb := 255;
629 if cs.PlayerStat[i].Spectator then
630 begin
631 rr := rr div 2; gg := gg div 2; bb := bb div 2;
632 end;
634 // Player color
635 r_Draw_Rect(x, yy, x + 16 - 1, yy + 16 - 1, 192, 192, 192, 255);
636 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);
637 // Player name
638 if gShowPIDs then s := Format('[%5d] %s', [cs.PlayerStat[i].UID, cs.PlayerStat[i].Name]) else s := cs.PlayerStat[i].Name;
639 if (gPlayers[cs.PlayerStat[i].Num] <> nil) and (gPlayers[cs.PlayerStat[i].Num].FReady) then s := s + ' *';
640 r_Common_DrawText(s, x + 16 + 8, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_LEFTUP);
641 if endview = false then
642 begin
643 // Player ping/loss
644 s := Format(_lc[I_GAME_PING_MS], [cs.PlayerStat[i].Ping, cs.PlayerStat[i].Loss]);
645 r_Common_DrawText(s, x + w1, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
646 end;
647 // Player frags
648 s := IntToStr(cs.PlayerStat[i].Frags);
649 r_Common_DrawText(s, x + w1 + w2, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
650 // Player deaths
651 s := IntToStr(cs.PlayerStat[i].Deaths);
652 r_Common_DrawText(s, x + w1 + w2 + w3, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
654 INC(yy, ch + ch div 2);
655 end;
656 end;
657 end;
659 procedure r_Render_DrawStatsWindow (x, y, w, h: Integer; cs: TEndCustomGameStat; endview: Boolean);
660 var xoff, yoff, cw, ch: Integer; s: AnsiString;
661 begin
662 xoff := 0; yoff := 8;
663 r_Draw_GetTextSize('W', stdfont, cw, ch);
664 r_Draw_FillRect(x, y, x + w - 1, y + h - 1, 64, 64, 64, 224);
665 r_Draw_Rect(x, y, x + w - 1, y + h - 1, 255, 127, 0, 255);
667 (* LINE 1 *)
669 if endview = false then
670 begin
671 case NetMode of
672 NET_SERVER: s := _lc[I_NET_SERVER];
673 NET_CLIENT: s := NetClientIP + ':' + IntToStr(NetClientPort);
674 otherwise s := '';
675 end;
676 r_Common_DrawText(s, x + 16, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
677 end;
679 case cs.GameMode of
680 GM_DM: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_DM] else s := _lc[I_GAME_LMS];
681 GM_TDM: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_TDM] else s := _lc[I_GAME_TLMS];
682 GM_CTF: s := _lc[I_GAME_CTF];
683 GM_COOP: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_COOP] else s := _lc[I_GAME_SURV];
684 otherwise s := 'GAME MODE ' + IntToStr(gGameSettings.GameMode);
685 end;
686 r_Common_DrawText(s, x + w div 2, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
688 if endview = false then
689 begin
690 s := r_Common_TimeToStr(cs.GameTime);
691 r_Common_DrawText(s, x + w - 16, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
692 end;
694 INC(yoff, ch + ch div 2);
696 (* LINE 2/3 *)
698 s := cs.Map;
699 if cs.MapName <> '' then
700 s := s + ' - ' + cs.MapName;
702 if endview = false then
703 begin
704 r_Common_DrawText(s, x + w div 2, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_UP);
705 INC(yoff, ch + ch div 2);
706 case cs.GameMode of
707 GM_DM, GM_TDM: s := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]);
708 GM_CTF: s := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.ScoreLimit]);
709 GM_COOP: s := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
710 otherwise s := '';
711 end;
712 r_Common_DrawText(s, x + 16, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_LEFTUP);
713 case cs.GameMode of
714 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]);
715 GM_COOP: s := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
716 otherwise s := '';
717 end;
718 r_Common_DrawText(s, x + w - 16, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_RIGHTUP);
719 INC(yoff, ch);
720 end
721 else
722 begin
723 xoff := MAX(Length(_lc[I_MENU_MAP]) + 1, Length(_lc[I_GAME_GAME_TIME]) + 1) * cw;
724 r_Common_DrawText(_lc[I_MENU_MAP], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
725 r_Common_DrawText(s, x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
726 INC(yoff, ch);
727 r_Common_DrawText(_lc[I_GAME_GAME_TIME], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
728 r_Common_DrawText(r_Common_TimeToStr(cs.GameTime), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
729 INC(yoff, ch);
730 end;
732 INC(yoff, ch);
734 (* LINE 4/5 *)
736 if endview and (cs.GameMode = GM_COOP) then
737 begin
738 xoff := MAX(Length(_lc[I_GAME_MONSTERS]) + 1, Length(_lc[I_GAME_SECRETS]) + 1) * cw;
739 r_Common_DrawText(_lc[I_GAME_MONSTERS], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
740 r_Common_DrawText(IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
741 INC(yoff, ch);
742 r_Common_DrawText(_lc[I_GAME_SECRETS], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
743 r_Common_DrawText(IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
744 INC(yoff, ch);
745 INC(yoff, ch);
746 end;
748 (* LINE 6/7 *)
750 if endview and (cs.GameMode = GM_COOP) and gLastMap then
751 begin
752 xoff := MAX(Length(_lc[I_GAME_MONSTERS_TOTAL]) + 1, Length(_lc[I_GAME_SECRETS_TOTAL]) + 1) * cw;
753 r_Common_DrawText(_lc[I_GAME_MONSTERS_TOTAL], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
754 r_Common_DrawText(IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
755 INC(yoff, ch);
756 r_Common_DrawText(_lc[I_GAME_SECRETS_TOTAL], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
757 r_Common_DrawText(IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
758 INC(yoff, ch);
759 INC(yoff, ch);
760 end;
762 (* LINE *)
764 if endview and (cs.GameMode in [GM_TDM, GM_CTF]) then
765 begin
766 if cs.TeamStat[TEAM_RED].Score > cs.TeamStat[TEAM_BLUE].Score then s := _lc[I_GAME_WIN_RED]
767 else if cs.TeamStat[TEAM_BLUE].Score > cs.TeamStat[TEAM_RED].Score then s := _lc[I_GAME_WIN_BLUE]
768 else s := _lc[I_GAME_WIN_DRAW];
769 r_Common_DrawText(s, x + w div 2, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
770 INC(yoff, ch);
771 INC(yoff, ch);
772 end;
774 (* LINE n *)
776 r_Render_DrawStatsColumns(cs, x + 16, y + yoff, w - 16 - 16, endview);
777 end;
779 function r_Render_StatsHeight (players: Integer): Integer;
780 var cw, ch: Integer;
781 begin
782 ASSERT(players >= 0);
783 r_Draw_GetTextSize('W', stdfont, cw, ch);
784 case gGameSettings.GameMode of
785 GM_TDM, GM_CTF: result := 32 + ch * (11 + players);
786 otherwise result := 40 + ch * 5 + (ch + 8) * players;
787 end;
788 end;
790 procedure r_Render_DrawStats;
791 var x, y, w, h, players: Integer; cs: TEndCustomGameStat;
792 begin
793 cs.PlayerStat := g_Player_GetStats();
794 SortGameStat(cs.PlayerStat);
795 cs.TeamStat := gTeamStat;
796 cs.GameTime := gTime;
797 cs.GameMode := gGameSettings.GameMode;
798 cs.Map := g_ExtractWadNameNoPath(gMapInfo.Map) + ':' + g_ExtractFileName(gMapInfo.Map);
799 cs.MapName := gMapInfo.Name;
800 if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
801 w := gScreenWidth - (gScreenWidth div 5);
802 h := r_Render_StatsHeight(players);
803 x := (gScreenWidth div 2) - (w div 2);
804 y := (gScreenHeight div 2) - (h div 2);
805 r_Render_DrawStatsWindow(x, y, w, h, cs, false);
806 end;
808 procedure r_Render_DrawCustomStats;
809 var cw, ch, s: AnsiString;
810 begin
811 if gStatsOff then
812 begin
813 r_Common_DrawText(_lc[I_MENU_INTER_NOTICE_TAB], gScreenWidth div 2, 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
814 end
815 else
816 begin
817 case gGameSettings.GameMode of
818 GM_COOP: if gMissionFailed then s := _lc[I_MENU_INTER_MISSION_FAIL] else s := _lc[I_MENU_INTER_LEVEL_COMPLETE];
819 otherwise s := _lc[I_MENU_INTER_ROUND_OVER];
820 end;
821 r_Common_DrawText(s, gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
823 if gChatShow = false then
824 begin
825 if g_Game_IsClient then s := _lc[I_MENU_INTER_NOTICE_MAP] else s := _lc[I_MENU_INTER_NOTICE_SPACE];
826 r_Common_DrawText(s, gScreenWidth div 2, gScreenHeight - 4, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
827 if g_Game_IsNet then
828 begin
829 s := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
830 r_Common_DrawText(s, gScreenWidth div 2, gScreenHeight - 16 - 4, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
831 end;
832 end;
834 r_Render_DrawStatsWindow(32, 64, gScreenWidth - 32 * 2, gScreenHeight - 64 * 2, CustomStat, true);
835 end;
836 end;
838 procedure r_Render_DrawValueOf (a, b, x, y: Integer; f: TGLFont);
839 var wa, wb, ch: Integer; sa, sb: AnsiString;
840 begin
841 sa := IntToStr(a);
842 sb := IntToStr(b);
843 r_Draw_GetTextSize(sa, f, wa, ch);
844 r_Draw_GetTextSize(sa + ' / ', f, wb, ch);
845 r_Common_DrawText(sa, x, y, 255, 0, 0, 255, f, TBasePoint.BP_LEFTUP);
846 r_Common_DrawText(' / ', x + wa, y, 255, 255, 255, 255, f, TBasePoint.BP_LEFTUP);
847 r_Common_DrawText(sb, x + wb, y, 255, 0, 0, 255, f, TBasePoint.BP_LEFTUP);
848 end;
850 procedure r_Render_DrawSinglStatsPlayer (player, x, y, w1: Integer);
851 var time, kpm: Single;
852 begin
853 r_Common_DrawText(_lc[I_MENU_INTER_KILLS], x, y, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
854 r_Render_DrawValueOf(SingleStat.PlayerStat[player].Kills, gTotalMonsters, x + w1, y, MenuFont);
855 r_Common_DrawText(_lc[I_MENU_INTER_KPM], x, y + 32, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
856 time := SingleStat.GameTime / 1000;
857 kpm := SingleStat.PlayerStat[player].Kills;
858 if time > 0 then kpm := kpm / time * 60;
859 r_Common_DrawText(Format('%.1f', [kpm]), x + w1, y + 32, 255, 0, 0, 255, menufont, TBasePoint.BP_LEFTUP);
860 r_Common_DrawText(_lc[I_MENU_INTER_SECRETS], x, y + 64, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
861 r_Render_DrawValueOf(SingleStat.PlayerStat[player].Secrets, SingleStat.TotalSecrets, x + w1, y + 64, MenuFont);
862 end;
864 procedure r_Render_DrawSingleStats;
865 var xx, wa, wb, ww, ch: Integer; s: AnsiString;
866 begin
867 r_Common_DrawText(_lc[I_MENU_INTER_LEVEL_COMPLETE], gScreenWidth div 2, 32, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
869 r_Draw_GetTextSize(_lc[I_MENU_INTER_KPM] + ' ', menufont, wa, ch);
870 r_Draw_GetTextSize(' 9999.9', menufont, wb, ch);
871 ww := wa + wb;
872 xx := gScreenWidth div 2 - ww div 2;
874 s := r_Common_TimeToStr(SingleStat.GameTime);
875 r_Common_DrawText(_lc[I_MENU_INTER_TIME], xx, 80, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
876 r_Common_DrawText(s, xx + wa, 80, 255, 0, 0, 255, menufont, TBasePoint.BP_LEFTUP);
878 if SingleStat.TwoPlayers then
879 begin
880 r_Common_DrawText(_lc[I_MENU_PLAYER_1], gScreenWidth div 2, 128, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
881 r_Render_DrawSinglStatsPlayer(0, xx, 176, wa);
882 r_Common_DrawText(_lc[I_MENU_PLAYER_2], gScreenWidth div 2, 288, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
883 r_Render_DrawSinglStatsPlayer(1, xx, 336, wa);
884 end
885 else
886 begin
887 r_Render_DrawSinglStatsPlayer(0, xx, 128, wa);
888 end;
889 end;
891 procedure r_Render_DrawSpectHud;
892 var xoff: Integer; s: AnsiString;
894 procedure AddText (s1, s2: AnsiString);
895 var w1, w2, ww, ch: Integer;
896 begin
897 r_Draw_GetTextSize(s1, stdfont, w1, ch);
898 r_Draw_GetTextSize(s2, stdfont, w2, ch);
899 ww := MAX(w1, w2);
900 r_Common_DrawText(s1, xoff + ww div 2, gScreenHeight - ch, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
901 r_Common_DrawText(s2, xoff + ww div 2, gScreenHeight - ch, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
902 xoff := xoff + ww + 16;
903 end;
905 begin
906 xoff := 0;
907 case gSpectMode of
908 SPECT_STATS: s := 'MODE: Stats';
909 SPECT_MAPVIEW: s := 'MODE: Observe Map';
910 SPECT_PLAYERS: s := 'MODE: Watch Players';
911 otherwise s := 'MODE: ' + IntToStr(gSpectMode);
912 end;
913 AddText(s, '< jump >');
914 if gSpectMode = SPECT_STATS then
915 AddText('Autoview', '< fire >');
916 if gSpectMode = SPECT_MAPVIEW then
917 AddText('[-] Step ' + IntToStr(gSpectStep) + ' [+]', '<prev weap> <next weap>');
918 if gSpectMode = SPECT_PLAYERS then
919 begin
920 AddText('Player 1', '<left/right>');
921 if gSpectViewTwo then
922 AddText('Player 2', '<prev w/next w>');
923 AddText('2x View', '<up/down>');
924 end;
925 end;
927 function GetActivePlayer_ByID (id: Integer): TPlayer;
928 var i, len: Integer; p: TPlayer;
929 begin
930 p := nil;
931 if (id >= 0) and (gPlayers <> nil) then
932 begin
933 i := 0; len := Length(gPlayers);
934 while (i < len) and ((IsActivePlayer(gPlayers[i]) = false) or (gPlayers[i].UID <> id)) do INC(i);
935 if i < len then p := gPlayers[i];
936 end;
937 result := p;
938 end;
940 procedure r_Render_DrawMinimap (x, y: Integer; alpha: Byte);
941 const scale = 16;
943 function IsMinimapPanel (const p: TPanel): Boolean;
944 begin
945 result := (p <> nil) and p.Enabled;
946 if result then
947 begin
948 case p.PanelType of
949 PANEL_WALL, PANEL_WATER, PANEL_ACID1, PANEL_ACID2,
950 PANEL_STEP, PANEL_OPENDOOR, PANEL_CLOSEDOOR,
951 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
952 result := true;
953 otherwise
954 result := false;
955 end;
956 end;
957 end;
959 procedure DrawObject (xx, yy, ww, hh: Integer; r, g, b: Byte);
960 var x0, y0, x1, y1: Integer;
961 begin
962 x0 := x + xx div scale;
963 y0 := y + yy div scale;
964 x1 := x + (xx + ww - 1) div scale;
965 y1 := y + (yy + hh - 1) div scale;
966 r_Draw_FillRect(x0, y0, x1, y1, r, g, b, alpha);
967 end;
969 procedure DrawPanels (const a: TPanelArray);
970 var i: Integer; p: TPanel; c: TRGB;
971 begin
972 if a <> nil then
973 begin
974 for i := 0 to HIGH(a) do
975 begin
976 p := a[i];
977 if IsMinimapPanel(p) then
978 begin
979 case p.PanelType of
980 PANEL_WALL: c := _RGB(208, 208, 208);
981 PANEL_OPENDOOR: c := _RGB(160, 160, 160);
982 PANEL_CLOSEDOOR: c := _RGB(160, 160, 160);
983 PANEL_STEP: c := _RGB(128, 128, 128);
984 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
985 case p.LiftType of
986 LIFTTYPE_UP: c := _RGB(116, 72, 36);
987 LIFTTYPE_DOWN: c := _RGB(116, 124, 96);
988 LIFTTYPE_LEFT: c := _RGB(116, 200, 80);
989 LIFTTYPE_RIGHT: c := _RGB(116, 252, 140);
990 otherwise c := _RGB(255, 0, 0);
991 end;
992 PANEL_WATER: c := _RGB(0, 0, 192);
993 PANEL_ACID1: c := _RGB(0, 176, 0);
994 PANEL_ACID2: c := _RGB(176, 0, 0);
995 otherwise c := _RGB(255, 0, 0);
996 end;
997 DrawObject(p.x, p.y, p.width, p.height, c.r, c.g, c.b);
998 end;
999 end;
1000 end;
1001 end;
1003 procedure DrawPlayers;
1004 var i: Integer; p: TPlayer; c: TRGB;
1005 begin
1006 if gPlayers <> nil then
1007 begin
1008 for i := 0 to HIGH(gPlayers) do
1009 begin
1010 p := gPlayers[i];
1011 if p.Alive then
1012 begin
1013 case p.Team of
1014 TEAM_RED: c := _RGB(255, 0, 0);
1015 TEAM_BLUE: c := _RGB(0, 0, 255);
1016 otherwise c := _RGB(255, 128, 0);
1017 end;
1018 DrawObject(p.obj.x, p.obj.y, p.obj.rect.width, p.obj.rect.height, c.r, c.g, c.b);
1019 end;
1020 end;
1021 end;
1022 end;
1024 function DrawMonster (m: TMonster): Boolean;
1025 begin
1026 result := false; // don't stop
1027 if m.alive then
1028 DrawObject(m.obj.x, m.obj.y, m.obj.rect.width, m.obj.rect.height, 255, 255, 0);
1029 end;
1031 begin
1032 r_Draw_FillRect(x, y, (x + gMapInfo.Width - 1) div scale, (y + gMapInfo.Height - 1) div scale, 0, 0, 0, alpha);
1033 DrawPanels(gSteps);
1034 DrawPanels(gLifts);
1035 DrawPanels(gWater);
1036 DrawPanels(gAcid1);
1037 DrawPanels(gAcid2);
1038 DrawPanels(gWalls);
1039 g_Mons_ForEach(DrawMonster);
1040 DrawPlayers;
1041 end;
1043 procedure r_Render_Draw;
1044 var p1, p2: TPlayer; time: LongWord;
1045 begin
1046 if gExit = EXIT_QUIT then
1047 exit;
1049 INC(FPSCounter);
1050 time := GetTickCount64();
1051 if time - FPSTime >= 1000 then
1052 begin
1053 FPS := FPSCounter;
1054 FPSCounter := 0;
1055 FPSTime := time;
1056 end;
1058 r_Draw_Setup(gScreenWidth, gScreenHeight);
1060 glClearColor(0.0, 0.0, 0.0, 0.0);
1061 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
1063 glColor4ub(255, 255, 255, 255);
1064 glEnable(GL_SCISSOR_TEST);
1065 r_Draw_SetRect(0, 0, gScreenWidth, gScreenHeight);
1067 //e_LogWritefln('r_render_draw: %sx%s', [gScreenWidth, gScreenHeight]);
1069 p1 := nil;
1070 p2 := nil;
1071 if gGameOn or (gState = STATE_FOLD) then
1072 begin
1073 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
1074 begin
1075 if gRevertPlayers then
1076 begin
1077 p1 := gPlayer2;
1078 p2 := gPlayer1;
1079 end
1080 else
1081 begin
1082 p1 := gPlayer1;
1083 p2 := gPlayer2;
1084 end;
1085 end
1086 else if gPlayer1 <> nil then
1087 begin
1088 p1 := gPlayer1;
1089 end
1090 else if gPlayer2 <> nil then
1091 begin
1092 p1 := gPlayer2;
1093 end;
1094 if (gSpectMode = SPECT_PLAYERS) and (gPlayers <> nil) then
1095 begin
1096 p1 := GetActivePlayer_ByID(gSpectPID1);
1097 if p1 = nil then
1098 p1 := GetActivePlayer_ByID(GetActivePlayerID_Next());
1099 if gSpectViewTwo then
1100 begin
1101 p2 := GetActivePlayer_ByID(gSpectPID2);
1102 if p2 = nil then
1103 p2 := GetActivePlayer_ByID(GetActivePlayerID_Next());
1104 end;
1105 end;
1106 end;
1108 if gGameOn or ((gState in [STATE_FOLD]) and (EndingGameCounter < 255)) then
1109 begin
1110 if gSpectMode = SPECT_MAPVIEW then
1111 begin
1112 r_Render_DrawMapView(0, 0, gScreenWidth, gScreenHeight, gSpectX + gScreenWidth div 2, gSpectY + gScreenHeight div 2);
1113 end
1114 else if (p1 <> nil) and (p2 <> nil) then
1115 begin
1116 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight div 2 - 2, p1);
1117 r_Render_DrawPlayerView(0, gScreenHeight div 2 + 2, gScreenWidth, gScreenHeight div 2, p2);
1118 end
1119 else if p1 <> nil then
1120 begin
1121 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, p1);
1122 end
1123 else if p2 <> nil then
1124 begin
1125 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, p2);
1126 end;
1128 if gShowMap then
1129 r_Render_DrawMiniMap(0, 0, 160);
1131 // TODO draw holmes inspector
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_Render_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_Render_DrawBackground(EndPicPath)
1165 else
1166 r_Render_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC])
1167 else
1168 r_Render_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_Render_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_Render_DrawBackground(EndPicPath)
1197 else
1198 r_Render_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_Render_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 // TODO gShowTime
1233 // TODO draw profilers
1235 // TODO draw holmes interface
1237 // TODO draw touch screen controls
1239 glFlush();
1240 glFinish();
1241 sys_Repaint;
1242 end;
1244 procedure r_Render_Resize (w, h: Integer);
1245 begin
1246 gWinSizeX := w;
1247 gWinSizeY := h;
1248 gRC_Width := w;
1249 gRC_Height := h;
1250 gScreenWidth := w;
1251 gScreenHeight := h;
1252 end;
1254 procedure r_Render_Apply;
1255 begin
1256 {$IFDEF ENABLE_SYSTEM}
1257 if sys_SetDisplayModeGL(GetInfo()) then
1258 e_LogWriteln('resolution changed')
1259 else
1260 e_LogWriteln('resolution not changed');
1261 sys_EnableVSync(gVSync)
1262 {$ENDIF}
1263 end;
1265 function r_Render_WriteScreenShot (filename: String): Boolean;
1266 begin
1267 // TODO write screenshot file
1268 Result := False;
1269 end;
1271 {$IFDEF ENABLE_GIBS}
1272 function r_Render_GetGibRect (m, id: Integer): TRectWH;
1273 begin
1274 result := r_Map_GetGibSize(m, id);
1275 end;
1276 {$ENDIF}
1278 {$IFDEF ENABLE_GFX}
1279 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
1280 begin
1281 r_Map_NewGFX(AnimType, X, Y);
1282 end;
1283 {$ENDIF}
1285 {$IFDEF ENABLE_TOUCH}
1286 procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
1287 begin
1288 // TODO implement touchscreen
1289 founded := False;
1290 end;
1291 {$ENDIF}
1293 {$IFDEF ENABLE_MENU}
1294 procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
1295 begin
1296 r_GUI_GetSize(ctrl, w, h);
1297 end;
1299 procedure r_Render_GetLogoSize (out w, h: Integer);
1300 begin
1301 r_GUI_GetLogoSize(w, h);
1302 end;
1304 procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
1305 begin
1306 r_GUI_GetMaxFontSize(BigFont, w, h);
1307 end;
1309 procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
1310 begin
1311 r_GUI_GetStringSize(BigFont, str, w, h);
1312 end;
1313 {$ENDIF}
1315 procedure r_Render_DrawLoading (force: Boolean);
1316 begin
1317 // TODO draw loading screen
1318 end;
1320 end.