DEADSOFTWARE

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