DEADSOFTWARE

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