DEADSOFTWARE

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