DEADSOFTWARE

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