DEADSOFTWARE

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