DEADSOFTWARE

gl: draw screen message
[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 (* render startup *)
28 procedure r_Render_Initialize;
29 procedure r_Render_Finalize;
31 (* load globally used textures *)
32 procedure r_Render_Load;
33 procedure r_Render_Free;
35 (* load map specific textures *)
36 procedure r_Render_LoadTextures;
37 procedure r_Render_FreeTextures;
39 procedure r_Render_Update;
40 procedure r_Render_Draw;
42 procedure r_Render_Resize (w, h: Integer);
43 procedure r_Render_Apply;
45 function r_Render_WriteScreenShot (filename: String): Boolean;
47 {$IFDEF ENABLE_GIBS}
48 function r_Render_GetGibRect (m, id: Integer): TRectWH;
49 {$ENDIF}
51 {$IFDEF ENABLE_GFX}
52 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
53 {$ENDIF}
55 {$IFDEF ENABLE_TOUCH}
56 // touch screen button location and size
57 procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
58 {$ENDIF}
60 {$IFDEF ENABLE_MENU}
61 procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
62 procedure r_Render_GetLogoSize (out w, h: Integer);
63 procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
64 procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
65 {$ENDIF}
67 procedure r_Render_DrawLoading (force: Boolean); // !!! remove it
69 implementation
71 uses
72 {$IFDEF USE_GLES1}
73 GLES11,
74 {$ELSE}
75 GL, GLEXT,
76 {$ENDIF}
77 {$IFDEF ENABLE_MENU}
78 r_gui,
79 {$ENDIF}
80 {$IFDEF ENABLE_SYSTEM}
81 g_system,
82 {$ENDIF}
83 SysUtils, Classes, Math,
84 g_basic,
85 e_log, utils, wadreader,
86 g_game, g_map, g_options, g_console, g_player, g_weapons, g_language, g_triggers,
87 g_net, g_netmaster,
88 r_draw, r_textures, r_fonts, r_common, r_console, r_map
89 ;
91 type
92 TBasePoint = (
93 BP_LEFTUP, BP_UP, BP_RIGHTUP,
94 BP_LEFT, BP_CENTER, BP_RIGHT,
95 BP_LEFTDOWN, BP_DOWN, BP_RIGHTDOWN
96 );
98 var
99 BackgroundTexture: THereTexture;
101 hud, hudbg: TGLTexture;
102 hudhp: array [Boolean] of TGLTexture;
103 hudap: TGLTexture;
104 hudwp: array [0..WP_LAST] of TGLTexture;
105 hudkey: array [0..2] of TGLTexture;
106 hudair: TGLTexture;
107 hudjet: TGLTexture;
108 hudrflag, hudrflags, hudrflagd: TGLTexture;
109 hudbflag, hudbflags, hudbflagd: TGLTexture;
111 procedure r_Render_LoadTextures;
112 begin
113 r_Map_LoadTextures;
114 end;
116 procedure r_Render_FreeTextures;
117 begin
118 r_Map_FreeTextures;
119 end;
121 procedure r_Render_Load;
122 const
123 WeapName: array [0..WP_LAST] of AnsiString = ('KASTET', 'SAW', 'PISTOL', 'SHOTGUN1', 'SHOTGUN2', 'MGUN', 'RLAUNCHER', 'PGUN', 'BFG', 'SPULEMET', 'FLAMETHROWER');
124 var
125 i: Integer;
126 begin
127 r_Common_Load;
128 BackgroundTexture := DEFAULT(THereTexture);
129 hud := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/HUD');
130 hudbg := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/HUDBG');
131 hudhp[false] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/MED2');
132 hudhp[true] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/BMED');
133 hudap := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/ARMORHUD');
134 for i := 0 to WP_LAST do
135 hudwp[i] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/' + WeapName[i]);
136 hudkey[0] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYR');
137 hudkey[1] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYG');
138 hudkey[2] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYB');
139 hudair := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/AIRBAR');
140 hudjet := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/JETBAR');
141 hudrflag := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_BASE');
142 hudrflags := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_STOLEN');
143 hudrflagd := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_DROP');
144 hudbflag := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_BASE');
145 hudbflags := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_STOLEN');
146 hudbflagd := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_DROP');
147 r_Console_Load;
148 r_Map_Load;
149 {$IFDEF ENABLE_MENU}
150 r_GUI_Load;
151 {$ENDIF}
152 end;
154 procedure r_Render_Free;
155 var i: Integer;
156 begin
157 {$IFDEF ENABLE_MENU}
158 r_GUI_Free;
159 {$ENDIF}
160 r_Map_Free;
161 r_Console_Free;
162 hudbflagd.Free;
163 hudbflags.Free;
164 hudbflag.Free;
165 hudrflagd.Free;
166 hudrflags.Free;
167 hudrflag.Free;
168 hudjet.Free;
169 hudair.Free;
170 hudkey[0].Free;
171 hudkey[1].Free;
172 hudkey[2].Free;
173 for i := 0 to WP_LAST do
174 begin
175 if hudwp[i] <> nil then
176 hudwp[i].Free;
177 hudwp[i] := nil;
178 end;
179 hudap.Free;
180 hudhp[true].Free;
181 hudhp[false].Free;
182 hudbg.Free;
183 hud.Free;
184 r_Common_FreeThis(BackgroundTexture);
185 r_Common_Free;
186 end;
188 {$IFDEF ENABLE_SYSTEM}
189 function GetInfo (): TGLDisplayInfo;
190 var info: TGLDisplayInfo;
191 begin
192 info := Default(TGLDisplayInfo);
193 info.w := Max(1, gRC_Width);
194 info.h := Max(1, gRC_Height);
195 info.bpp := Max(1, gBPP);
196 info.fullscreen := gRC_FullScreen;
197 info.maximized := gRC_Maximized;
198 info.major := 1;
199 info.minor := 1;
200 info.profile := TGLProfile.Compat;
201 result := info;
202 end;
203 {$ENDIF}
205 procedure r_Render_Initialize;
206 begin
207 {$IFDEF ENABLE_SYSTEM}
208 if sys_SetDisplayModeGL(GetInfo()) = False then
209 raise Exception.Create('Failed to set videomode on startup.');
210 sys_EnableVSync(gVSync);
211 {$ENDIF}
212 r_Textures_Initialize;
213 r_Console_Initialize;
214 r_Map_Initialize;
215 end;
217 procedure r_Render_Finalize;
218 begin
219 r_Map_Finalize;
220 r_Console_Finalize;
221 r_Textures_Finalize;
222 end;
224 procedure r_Render_Update;
225 begin
226 r_Console_Update;
227 r_Map_Update;
228 end;
230 procedure r_Render_GetBasePoint (x, y, w, h: Integer; p: TBasePoint; out xx, yy: Integer);
231 begin
232 case p of
233 TBasePoint.BP_LEFTUP, TBasePoint.BP_LEFT, TBasePoint.BP_LEFTDOWN: xx := x;
234 TBasePoint.BP_UP, TBasePoint.BP_CENTER, TBasePoint.BP_DOWN: xx := x - w div 2;
235 TBasePoint.BP_RIGHTUP, TBasePoint.BP_RIGHT, TBasePoint.BP_RIGHTDOWN: xx := x - w;
236 end;
237 case p of
238 TBasePoint.BP_LEFTUP, TBasePoint.BP_UP, TBasePoint.BP_RIGHTUP: yy := y;
239 TBasePoint.BP_LEFT, TBasePoint.BP_CENTER, TBasePoint.BP_RIGHT: yy := y - h div 2;
240 TBasePoint.BP_LEFTDOWN, TBasePoint.BP_DOWN, TBasePoint.BP_RIGHTDOWN: yy := y - h;
241 end;
242 end;
244 procedure r_Render_DrawText (const text: AnsiString; x, y: Integer; r, g, b, a: Byte; f: TGLFont; p: TBasePoint);
245 var xx, yy, w, h: Integer;
246 begin
247 xx := x; yy := y;
248 if p <> TBasePoint.BP_LEFTUP then
249 begin
250 r_Draw_GetTextSize(text, f, w, h);
251 r_Render_GetBasePoint(x, y, w, h, p, xx, yy);
252 end;
253 r_Draw_Text(text, xx, yy, r, g, b, a, f);
254 end;
256 procedure r_Render_DrawTexture (img: TGLTexture; x, y, w, h: Integer; p: TBasePoint);
257 begin
258 r_Render_GetBasePoint(x, y, w, h, p, x, y);
259 r_Draw_TextureRepeat(img, x, y, w, h, false, 255, 255, 255, 255, false);
260 end;
262 procedure r_Render_GetFormatTextSize (const text: AnsiString; f: TGLFont; out w, h: Integer);
263 var i, cw, ch, cln, curw, curh, maxw, maxh: Integer;
264 begin
265 curw := 0; curh := 0; maxw := 0; maxh := 0;
266 r_Draw_GetTextSize('W', f, cw, cln);
267 for i := 1 to Length(text) do
268 begin
269 case text[i] of
270 #10:
271 begin
272 maxw := MAX(maxw, curw);
273 curh := curh + cln;
274 curw := 0;
275 end;
276 #1, #2, #3, #4, #18, #19, #20, #21:
277 begin
278 // skip color modifiers
279 end;
280 otherwise
281 begin
282 r_Draw_GetTextSize(text[i], f, cw, ch);
283 maxh := MAX(maxh, curh + ch);
284 curw := curw + cw;
285 end;
286 end;
287 end;
288 w := MAX(maxw, curw);
289 h := MAX(maxh, curh);
290 end;
292 procedure r_Render_DrawFormatText (const text: AnsiString; x, y: Integer; a: Byte; f: TGLFont; p: TBasePoint);
293 const
294 colors: array [boolean, 0..5] of TRGB = (
295 ((R:$00; G:$00; B:$00), (R:$FF; G:$00; B:$00), (R:$00; G:$FF; B:$00), (R:$FF; G:$FF; B:$00), (R:$00; G:$00; B:$FF), (R:$FF; G:$FF; B:$FF)),
296 ((R:$00; G:$00; B:$00), (R:$7F; G:$00; B:$00), (R:$00; G:$7F; B:$00), (R:$FF; G:$7F; B:$00), (R:$00; G:$00; B:$7F), (R:$7F; G:$7F; B:$7F))
297 );
298 var
299 i, xx, yy, cx, cy, w, h, cw, ch, cln, color: Integer; dark: Boolean;
300 begin
301 xx := x; yy := y;
302 if p <> TBasePoint.BP_LEFTUP then
303 begin
304 r_Render_GetFormatTextSize(text, f, w, h);
305 r_Render_GetBasePoint(x, y, w, h, p, xx, yy);
306 end;
307 cx := xx; cy := yy; color := 5; dark := false;
308 r_Draw_GetTextSize('W', f, cw, cln);
309 for i := 1 to Length(text) do
310 begin
311 case text[i] of
312 #10:
313 begin
314 cx := xx;
315 INC(cy, cln);
316 end;
317 #1: color := 0;
318 #2: color := 5;
319 #3: dark := true;
320 #4: dark := false;
321 #18: color := 1;
322 #19: color := 2;
323 #20: color := 4;
324 #21: color := 3;
325 otherwise
326 begin
327 r_Draw_GetTextSize(text[i], f, cw, ch);
328 r_Draw_Text(text[i], cx, cy, colors[dark, color].R, colors[dark, color].G, colors[dark, color].B, a, f);
329 INC(cx, cw);
330 end;
331 end;
332 end;
333 end;
335 procedure r_Render_DrawHUD (x, y: Integer; p: TPlayer);
336 var t: TGLTexture; s: AnsiString;
337 begin
338 ASSERT(p <> nil);
340 // hud area is 196 x 240 pixels
341 r_Render_DrawTexture(hud, x, y, hud.width, hud.height, TBasePoint.BP_LEFTUP);
342 r_Render_DrawText(p.name, x + 98, y + 16, 255, 0, 0, 255, smallfont, TBasePoint.BP_CENTER);
344 t := hudhp[R_BERSERK in p.FRulez];
345 r_Render_DrawTexture(t, x + 51, y + 61, t.width, t.height, TBasePoint.BP_CENTER);
346 r_Render_DrawTexture(hudap, x + 50, y + 85, hudap.width, hudap.height, TBasePoint.BP_CENTER);
348 r_Render_DrawText(IntToStr(MAX(0, p.health)), x + 174, y + 56, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
349 r_Render_DrawText(IntToStr(MAX(0, p.armor)), x + 174, y + 84, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
351 case p.CurrWeap of
352 WEAPON_KASTET, WEAPON_SAW: s := '--';
353 else s := IntToStr(p.GetAmmoByWeapon(p.CurrWeap));
354 end;
355 r_Render_DrawText(s, x + 174, y + 174, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
357 if p.CurrWeap <= WP_LAST then
358 begin
359 t := hudwp[p.CurrWeap];
360 r_Render_DrawTexture(t, x + 18, y + 160, t.width, t.height, TBasePoint.BP_LEFTUP);
361 end;
363 if R_KEY_RED in p.FRulez then
364 r_Render_DrawTexture(hudkey[0], x + 76, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
365 if R_KEY_GREEN in p.FRulez then
366 r_Render_DrawTexture(hudkey[1], x + 93, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
367 if R_KEY_BLUE in p.FRulez then
368 r_Render_DrawTexture(hudkey[2], x + 110, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
370 if p.JetFuel > 0 then
371 begin
372 r_Render_DrawTexture(hudair, x, y + 116, hudair.width, hudair.height, TBasePoint.BP_LEFTUP);
373 if p.air > 0 then
374 r_Draw_FillRect(x + 14, y + 116 + 4, x + 14 + 168 * p.air div AIR_MAX, y + 116 + 4 + 4, 0, 0, 196, 255);
375 r_Render_DrawTexture(hudjet, x, y + 126, hudjet.width, hudjet.height, TBasePoint.BP_LEFTUP);
376 r_Draw_FillRect(x + 14, y + 126 + 4, x + 14 + 168 * p.JetFuel div JET_MAX, y + 126 + 4 + 4, 208, 0, 0, 255);
377 end
378 else
379 begin
380 r_Render_DrawTexture(hudair, x, y + 124, hudair.width, hudair.height, TBasePoint.BP_LEFTUP);
381 if p.air > 0 then
382 r_Draw_FillRect(x + 14, y + 124 + 4, x + 14 + 168 * p.air div AIR_MAX, y + 124 + 4 + 4, 0, 0, 196, 255);
383 end;
384 end;
386 procedure r_Render_DrawHUDArea (x, y, w, h: Integer; p: TPlayer);
387 var s: AnsiString;
388 begin
389 r_Render_DrawTexture(hudbg, x, y, w, h, TBasePoint.BP_LEFTUP);
391 if p <> nil then
392 begin
393 r_Render_DrawHUD(x + w - 196 + 2, y, p);
394 if p.Spectator then
395 begin
396 r_Render_DrawText(_lc[I_PLAYER_SPECT], x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
397 r_Render_DrawText(_lc[I_PLAYER_SPECT2], x + 4, y + 258, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
398 r_Render_DrawText(_lc[I_PLAYER_SPECT1], x + 4, y + 274, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
399 if p.NoRespawn then
400 r_Render_DrawText(_lc[I_PLAYER_SPECT1S], x + 4, y + 290, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
401 end;
402 end;
404 if gShowPing and g_Game_IsClient then
405 begin
406 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
407 r_Render_DrawText(s, x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
408 end;
409 end;
411 procedure r_Render_DrawStatsView (x, y, w, h: Integer; p: TPlayer);
412 var fw, i, maxFrags, top, totalPlayers: Integer; sign: Char; stat: TPlayerStatArray; f: TGLTexture;
413 begin
414 ASSERT(p <> nil);
416 if gShowScore and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
417 begin
418 (* RED TEAM GOALS *)
419 fw := 0;
420 if gGameSettings.GameMode = GM_CTF then
421 begin
422 case gFlags[FLAG_RED].State of
423 FLAG_STATE_CAPTURED: f := hudrflags;
424 FLAG_STATE_DROPPED: f := hudrflagd;
425 otherwise f := hudrflag;
426 end;
427 if f <> nil then
428 begin
429 fw := f.width + 8; (* + space *)
430 r_Render_DrawTexture(f, x + w - 16, y + 240 - 72 - 4, f.width, f.height, TBasePoint.BP_RIGHTUP);
431 end;
432 end;
433 r_Render_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);
435 (* BLUE TEAM GOALS *)
436 fw := 0;
437 if gGameSettings.GameMode = GM_CTF then
438 begin
439 case gFlags[FLAG_BLUE].State of
440 FLAG_STATE_CAPTURED: f := hudbflags;
441 FLAG_STATE_DROPPED: f := hudbflagd;
442 otherwise f := hudbflag;
443 end;
444 if f <> nil then
445 begin
446 fw := f.width + 8; (* + space *)
447 r_Render_DrawTexture(f, x + w - 16, y + 240 - 32 - 4, f.width, f.height, TBasePoint.BP_RIGHTUP);
448 end;
449 end;
450 r_Render_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);
451 end;
453 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
454 begin
455 if gShowStat then
456 begin
457 r_Render_DrawText(IntToStr(p.Frags), x + w - 16, y, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHTUP);
459 top := 1;
460 maxFrags := 0;
461 totalPlayers := 0;
462 stat := g_Player_GetStats();
463 if stat <> nil then
464 begin
465 totalPlayers := Length(stat);
466 for i := 0 to High(stat) do
467 begin
468 if stat[i].Name <> p.Name then
469 begin
470 maxFrags := MAX(maxFrags, stat[i].Frags);
471 if stat[i].Frags > p.Frags then
472 top := top + 1;
473 end;
474 end;
475 end;
476 if p.Frags >= maxFrags then sign := '+' else sign := '-';
477 r_Render_DrawText(IntToStr(top) + ' / ' + IntToStr(totalPlayers) + ' ' + sign + IntToStr(ABS(p.Frags - maxFrags)), x + w - 16, y + 32, 255, 0, 0, 255, smallfont, TBasePoint.BP_RIGHTUP);
478 end;
480 if gLMSRespawn > LMS_RESPAWN_NONE then
481 begin
482 r_Render_DrawText(_lc[I_GAME_WARMUP], x + w - 16 - 64, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_RIGHTDOWN);
483 r_Render_DrawText(': ' + IntToStr((gLMSRespawnTime - gTime) div 1000), x + w - 16 - 64, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_LEFTDOWN);
484 end
485 else if gShowLives and (gGameSettings.MaxLives > 0) then
486 begin
487 r_Render_DrawText(IntToStr(p.Lives), x + w - 16, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_RIGHTDOWN);
488 end;
489 end;
490 end;
492 procedure r_Render_DrawView (x, y, w, h: Integer; p: TPlayer);
493 var l, t, r, b: Integer;
494 begin
495 r_Draw_GetRect(l, t, r, b);
496 r_Draw_SetRect(x, y, x + w, y + h);
498 if p <> nil then
499 begin
500 r_Map_Draw(x, y, w, h, p.obj.x + PLAYER_RECT_CX, p.obj.y + PLAYER_RECT_CY, p);
501 r_Render_DrawStatsView(x, y, w, h, p);
502 if p.Spectator and p.NoRespawn then
503 r_Render_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);
504 end
505 else
506 begin
507 r_Map_Draw(x, y, w, h, 0, 0, nil);
508 end;
510 r_Draw_SetRect(l, t, r, b);
511 end;
513 procedure r_Render_DrawMapView (x, y, w, h, camx, camy: Integer);
514 var l, t, r, b: Integer;
515 begin
516 r_Draw_GetRect(l, t, r, b);
517 r_Draw_SetRect(x, y, x + w, y + h);
518 r_Map_Draw(x, y, w, h, camx, camy, nil);
519 r_Draw_SetRect(l, t, r, b);
520 end;
522 procedure r_Render_DrawPlayerView (x, y, w, h: Integer; p: TPlayer);
523 var l, t, r, b: Integer;
524 begin
525 r_Draw_GetRect(l, t, r, b);
526 r_Draw_SetRect(x, y, x + w, y + h);
527 r_Render_DrawView(x, y, w - 196, h, p);
528 r_Render_DrawHUDArea(x + w - 196, y, 196, h, p);
529 r_Draw_SetRect(l, t, r, b);
530 end;
532 procedure r_Render_DrawBackgroundImage (img: TGLTexture);
533 var fw, w, h: LongInt;
534 begin
535 if img <> nil then
536 begin
537 img := BackgroundTexture.id;
538 if img.width = img.height then fw := img.width * 4 div 3 else fw := img.width; // fix aspect 4:3
539 r_Common_CalcAspect(fw, img.height, gScreenWidth, gScreenHeight, false, w, h);
540 r_Draw_Texture(img, gScreenWidth div 2 - w div 2, 0, w, h, false, 255, 255, 255, 255, false);
541 end
542 end;
544 procedure r_Render_DrawBackground (const name: AnsiString);
545 begin
546 if r_Common_LoadThis(name, BackgroundTexture) then
547 r_Render_DrawBackgroundImage(BackgroundTexture.id)
548 end;
550 procedure r_Render_DrawServerList (var SL: TNetServerList; var ST: TNetServerTable);
551 var ip: AnsiString; ww, hh, cw, ch, mw, mh, motdh, scrx, scry, i, mx, y: Integer; msg: SSArray; Srv: TNetServer;
552 begin
553 scrx := gScreenWidth div 2;
554 scry := gScreenHeight div 2;
556 r_Draw_GetTextSize(_lc[I_NET_SLIST], menufont, ww, hh);
557 r_Render_DrawText(_lc[I_NET_SLIST], gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
559 r_Draw_GetTextSize('W', stdfont, cw, ch);
560 motdh := gScreenHeight - 49 - ch * b_Text_LineCount(slMOTD);
562 r_Draw_FillRect(16, 64, gScreenWidth - 16, motdh, 64, 64, 64, 145);
563 r_Draw_Rect(16, 64, gScreenWidth - 16, motdh, 255, 127, 0, 255);
565 r_Render_DrawText(_lc[I_NET_SLIST_HELP], gScreenWidth div 2, gScreenHeight - 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
567 if slMOTD <> '' then
568 begin
569 r_Draw_FillRect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 64, 64, 64, 110);
570 r_Draw_Rect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 255, 127, 0, 255);
571 r_Render_DrawFormatText(slMOTD, 20, motdh + 3 + ch * i, 255, stdfont, TBasePoint.BP_LEFTUP);
572 end;
574 if not slReadUrgent and (slUrgent <> '') then
575 begin
576 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
577 r_Draw_FillRect(scrx - 256, scry - 60, scrx + 256, scry + 60, 64, 64, 64, 127);
578 r_Draw_Rect(scrx - 256, scry - 60, scrx + 256, scry + 60, 255, 127, 0, 255);
579 r_Draw_FillRect(scrx - 256, scry - 40, scrx + 256, scry - 40, 255, 127, 0, 255);
580 r_Render_DrawText(_lc[I_NET_SLIST_URGENT], scrx, scry - 58, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
581 r_Render_DrawFormatText(slUrgent, scrx - 253, scry - 38 + ch * i, 255, stdfont, TBasePoint.BP_LEFTUP);
582 r_Render_DrawText(_lc[I_NET_SLIST_URGENT_CONT], scrx, scry + 41, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
583 r_Draw_FillRect(scrx - 256, scry + 40, scrx + 256, scry + 40, 255, 127, 0, 255);
584 end
585 else if SL = nil then
586 begin
587 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
588 r_Draw_Rect(scrx - 192, scry - 10, scrx + 192, scry + 11, 255, 127, 0, 255);
589 r_Render_DrawText(slWaitStr, scrx, scry, 255, 255, 255, 255, stdfont, TBasePoint.BP_CENTER);
590 end
591 else
592 begin
593 y := 90;
594 if slSelection < Length(ST) then
595 begin
596 sy := y + 42 * slSelection - 4;
597 Srv := GetServerFromTable(slSelection, SL, ST);
598 ip := _lc[I_NET_ADDRESS] + ' ' + Srv.IP + ':' + IntToStr(Srv.Port);
599 ip := ip + ' ' + _lc[I_NET_SERVER_PASSWORD] + ' ';
600 if Srv.Password then ip := ip + _lc[I_MENU_YES] else ip := ip +_lc[I_MENU_NO];
601 end;
603 mw := gScreenWidth - 188;
604 mx := 16 + mw;
606 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy + 40, 64, 64, 64, 255);
607 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy, 205, 205, 205, 255);
608 r_Draw_FillRect(16 + 1, sy + 41, gScreenWidth - 16 - 1, sy + 41, 255, 255, 255, 255);
610 r_Draw_FillRect(16, 85, gScreenWidth - 16, 85, 255, 127, 0, 255);
611 r_Draw_FillRect(16, motdh - 20, gScreenWidth - 16, motdh - 20, 255, 127, 0, 255);
613 r_Draw_FillRect(mx - 70, 64, mx - 70, motdh, 255, 127, 0, 255);
614 r_Draw_FillRect(mx, 64, mx, motdh - 20, 255, 127, 0, 255);
615 r_Draw_FillRect(mx + 52, 64, mx + 52, motdh - 20, 255, 127, 0, 255);
616 r_Draw_FillRect(mx + 104, 64, mx + 104, motdh - 20, 255, 127, 0, 255);
618 r_Render_DrawText('NAME/MAP', 18, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
619 r_Render_DrawText('PING', mx - 68, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
620 r_Render_DrawText('MODE', mx + 2, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
621 r_Render_DrawText('PLRS', mx + 54, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
622 r_Render_DrawText('VER', mx + 106, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
624 for i := 0 to High(ST) do
625 begin
626 Srv := GetServerFromTable(i, SL, ST);
627 r_Render_DrawText(Srv.Name, 18, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
628 r_Render_DrawText(Srv.Map, 18, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
630 if Srv.Ping = 0 then
631 r_Render_DrawText('<1' + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
632 else if (Srv.Ping >= 0) and (Srv.Ping <= 999) then
633 r_Render_DrawText(IntToStr(Srv.Ping) + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
634 else
635 r_Render_DrawText(_lc[I_NET_SLIST_NO_ACCESS], mx - 68, y, 255, 0, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
636 if Length(ST[I].Indices) > 1 then
637 r_Render_DrawText('<' + IntToStr(Length(ST[I].Indices)) + '>', mx - 68, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
639 r_Render_DrawText(g_Game_ModeToText(Srv.GameMode), mx + 2, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
641 r_Render_DrawText(IntToStr(Srv.Players) + '/' + IntToStr(Srv.MaxPlayers), mx + 54, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
642 r_Render_DrawText(IntToStr(Srv.LocalPl) + '+' + IntToStr(Srv.Bots), mx + 54, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
644 r_Render_DrawText(IntToStr(Srv.Protocol), mx + 106, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
646 y := y + 42;
647 end;
649 r_Render_DrawText(ip, 20, motdh - 20 + 3, 205, 205, 205, 255, stdfont, TBasePoint.BP_LEFTUP);
650 r_Render_DrawText(IntToStr(Length(ST)) + _lc[I_NET_SLIST_SERVERS], gScreenWidth - 48, motdh - 20 + 3, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
651 end;
652 end;
654 function r_Render_TimeToStr (t: LongWord): AnsiString;
655 var h, m, s: Integer;
656 begin
657 h := t div 1000 div 3600;
658 m := t div 1000 div 60 mod 60;
659 s := t div 1000 mod 60;
660 result := Format('%d:%.2d:%.2d', [h, m, s]);
661 end;
663 procedure r_Render_DrawStatsColumns (constref cs: TEndCustomGameStat; x, y, w: Integer; endview: Boolean);
664 var i, cw, ch, yy, team, players, w1, w2, w3, w4, tw: Integer; r, g, b, rr, gg, bb: Byte; s: AnsiString;
665 begin
666 r_Draw_GetTextSize('W', stdfont, cw, ch);
667 w4 := cw * 6; (* deaths width *)
668 w3 := cw * 8; (* frags width *)
669 w2 := cw * 12; (* ping/loss width *)
670 w1 := w - w2 - w3 - w4; (* name width *)
671 tw := w1 - cw * 2 - w2; (* team goals *)
672 if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
673 yy := y;
674 if cs.GameMode in [GM_TDM, GM_CTF] then
675 begin
676 for team := TEAM_RED to TEAM_BLUE do
677 begin
678 case team of
679 TEAM_RED:
680 begin
681 s := _lc[I_GAME_TEAM_RED];
682 r := 255; g := 0; b := 0;
683 end;
684 TEAM_BLUE:
685 begin
686 s := _lc[I_GAME_TEAM_BLUE];
687 r := 0; g := 0; b := 255;
688 end;
689 end;
690 r_Render_DrawText(s, x, yy, r, g, b, 255, stdfont, TBasePoint.BP_LEFTUP);
691 r_Render_DrawText(IntToStr(cs.TeamStat[team].Score), x + tw, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
692 if endview = false then
693 r_Render_DrawText(_lc[I_GAME_PING], x + w1, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
694 r_Render_DrawText(_lc[I_GAME_FRAGS], x + w1 + w2, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
695 r_Render_DrawText(_lc[I_GAME_DEATHS], x + w1 + w2 + w3, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
696 INC(yy, ch);
698 INC(yy, ch div 4);
699 r_Draw_FillRect(x, yy, x + w - 1, yy, r, g, b, 255);
700 INC(yy, ch div 4);
702 for i := 0 to players - 1 do
703 begin
704 if cs.PlayerStat[i].Team = team then
705 begin
706 rr := r; gg := g; bb := b;
707 if cs.PlayerStat[i].Spectator then
708 begin
709 rr := r div 2; gg := g div 2; bb := b div 2;
710 end;
712 // Player name
713 if gShowPIDs then s := Format('[%5d] %s', [cs.PlayerStat[i].UID, cs.PlayerStat[i].Name]) else s := cs.PlayerStat[i].Name;
714 if (gPlayers[cs.PlayerStat[i].Num] <> nil) and (gPlayers[cs.PlayerStat[i].Num].FReady) then s := s + ' *';
715 r_Render_DrawText(s, x, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_LEFTUP);
716 if endview = false then
717 begin
718 // Player ping/loss
719 s := Format(_lc[I_GAME_PING_MS], [cs.PlayerStat[i].Ping, cs.PlayerStat[i].Loss]);
720 r_Render_DrawText(s, x + w1, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
721 end;
722 // Player frags
723 s := IntToStr(cs.PlayerStat[i].Frags);
724 r_Render_DrawText(s, x + w1 + w2, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
725 // Player deaths
726 s := IntToStr(cs.PlayerStat[i].Deaths);
727 r_Render_DrawText(s, x + w1 + w2 + w3, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
729 INC(yy, ch);
730 end;
731 end;
732 INC(yy, ch);
733 end;
734 end
735 else if cs.GameMode in [GM_DM, GM_COOP] then
736 begin
737 r_Render_DrawText(_lc[I_GAME_PLAYER_NAME], x, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
738 if endview = false then
739 r_Render_DrawText(_lc[I_GAME_PING], x + w1, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
740 r_Render_DrawText(_lc[I_GAME_FRAGS], x + w1 + w2, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
741 r_Render_DrawText(_lc[I_GAME_DEATHS], x + w1 + w2 + w3, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
742 INC(yy, ch + ch div 2);
743 for i := 0 to players - 1 do
744 begin
745 // rr := 255; gg := 127; bb := 0;
746 rr := 255; gg := 255; bb := 255;
747 if cs.PlayerStat[i].Spectator then
748 begin
749 rr := rr div 2; gg := gg div 2; bb := bb div 2;
750 end;
752 // Player color
753 r_Draw_Rect(x, yy, x + 16 - 1, yy + 16 - 1, 192, 192, 192, 255);
754 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);
755 // Player name
756 if gShowPIDs then s := Format('[%5d] %s', [cs.PlayerStat[i].UID, cs.PlayerStat[i].Name]) else s := cs.PlayerStat[i].Name;
757 if (gPlayers[cs.PlayerStat[i].Num] <> nil) and (gPlayers[cs.PlayerStat[i].Num].FReady) then s := s + ' *';
758 r_Render_DrawText(s, x + 16 + 8, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_LEFTUP);
759 if endview = false then
760 begin
761 // Player ping/loss
762 s := Format(_lc[I_GAME_PING_MS], [cs.PlayerStat[i].Ping, cs.PlayerStat[i].Loss]);
763 r_Render_DrawText(s, x + w1, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
764 end;
765 // Player frags
766 s := IntToStr(cs.PlayerStat[i].Frags);
767 r_Render_DrawText(s, x + w1 + w2, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
768 // Player deaths
769 s := IntToStr(cs.PlayerStat[i].Deaths);
770 r_Render_DrawText(s, x + w1 + w2 + w3, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
772 INC(yy, ch + ch div 2);
773 end;
774 end;
775 end;
777 procedure r_Render_DrawStatsWindow (x, y, w, h: Integer; cs: TEndCustomGameStat; endview: Boolean);
778 var xoff, yoff, cw, ch: Integer; s: AnsiString;
779 begin
780 xoff := 0; yoff := 8;
781 r_Draw_GetTextSize('W', stdfont, cw, ch);
782 r_Draw_FillRect(x, y, x + w - 1, y + h - 1, 64, 64, 64, 224);
783 r_Draw_Rect(x, y, x + w - 1, y + h - 1, 255, 127, 0, 255);
785 (* LINE 1 *)
787 if endview = false then
788 begin
789 case NetMode of
790 NET_SERVER: s := _lc[I_NET_SERVER];
791 NET_CLIENT: s := NetClientIP + ':' + IntToStr(NetClientPort);
792 otherwise s := '';
793 end;
794 r_Render_DrawText(s, x + 16, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
795 end;
797 case cs.GameMode of
798 GM_DM: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_DM] else s := _lc[I_GAME_LMS];
799 GM_TDM: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_TDM] else s := _lc[I_GAME_TLMS];
800 GM_CTF: s := _lc[I_GAME_CTF];
801 GM_COOP: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_COOP] else s := _lc[I_GAME_SURV];
802 otherwise s := 'GAME MODE ' + IntToStr(gGameSettings.GameMode);
803 end;
804 r_Render_DrawText(s, x + w div 2, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
806 if endview = false then
807 begin
808 s := r_Render_TimeToStr(cs.GameTime);
809 r_Render_DrawText(s, x + w - 16, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
810 end;
812 INC(yoff, ch + ch div 2);
814 (* LINE 2/3 *)
816 s := cs.Map;
817 if cs.MapName <> '' then
818 s := s + ' - ' + cs.MapName;
820 if endview = false then
821 begin
822 r_Render_DrawText(s, x + w div 2, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_UP);
823 INC(yoff, ch + ch div 2);
824 case cs.GameMode of
825 GM_DM, GM_TDM: s := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]);
826 GM_CTF: s := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.ScoreLimit]);
827 GM_COOP: s := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
828 otherwise s := '';
829 end;
830 r_Render_DrawText(s, x + 16, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_LEFTUP);
831 case cs.GameMode of
832 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]);
833 GM_COOP: s := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
834 otherwise s := '';
835 end;
836 r_Render_DrawText(s, x + w - 16, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_RIGHTUP);
837 INC(yoff, ch);
838 end
839 else
840 begin
841 xoff := MAX(Length(_lc[I_MENU_MAP]) + 1, Length(_lc[I_GAME_GAME_TIME]) + 1) * cw;
842 r_Render_DrawText(_lc[I_MENU_MAP], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
843 r_Render_DrawText(s, x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
844 INC(yoff, ch);
845 r_Render_DrawText(_lc[I_GAME_GAME_TIME], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
846 r_Render_DrawText(r_Render_TimeToStr(cs.GameTime), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
847 INC(yoff, ch);
848 end;
850 INC(yoff, ch);
852 (* LINE 4/5 *)
854 if endview and (cs.GameMode = GM_COOP) then
855 begin
856 xoff := MAX(Length(_lc[I_GAME_MONSTERS]) + 1, Length(_lc[I_GAME_SECRETS]) + 1) * cw;
857 r_Render_DrawText(_lc[I_GAME_MONSTERS], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
858 r_Render_DrawText(IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
859 INC(yoff, ch);
860 r_Render_DrawText(_lc[I_GAME_SECRETS], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
861 r_Render_DrawText(IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
862 INC(yoff, ch);
863 INC(yoff, ch);
864 end;
866 (* LINE 6/7 *)
868 if endview and (cs.GameMode = GM_COOP) and gLastMap then
869 begin
870 xoff := MAX(Length(_lc[I_GAME_MONSTERS_TOTAL]) + 1, Length(_lc[I_GAME_SECRETS_TOTAL]) + 1) * cw;
871 r_Render_DrawText(_lc[I_GAME_MONSTERS_TOTAL], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
872 r_Render_DrawText(IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
873 INC(yoff, ch);
874 r_Render_DrawText(_lc[I_GAME_SECRETS_TOTAL], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
875 r_Render_DrawText(IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
876 INC(yoff, ch);
877 INC(yoff, ch);
878 end;
880 (* LINE *)
882 if endview and (cs.GameMode in [GM_TDM, GM_CTF]) then
883 begin
884 if cs.TeamStat[TEAM_RED].Score > cs.TeamStat[TEAM_BLUE].Score then s := _lc[I_GAME_WIN_RED]
885 else if cs.TeamStat[TEAM_BLUE].Score > cs.TeamStat[TEAM_RED].Score then s := _lc[I_GAME_WIN_BLUE]
886 else s := _lc[I_GAME_WIN_DRAW];
887 r_Render_DrawText(s, x + w div 2, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
888 INC(yoff, ch);
889 INC(yoff, ch);
890 end;
892 (* LINE n *)
894 r_Render_DrawStatsColumns(cs, x + 16, y + yoff, w - 16 - 16, endview);
895 end;
897 function r_Render_StatsHeight (players: Integer): Integer;
898 var cw, ch: Integer;
899 begin
900 ASSERT(players >= 0);
901 r_Draw_GetTextSize('W', stdfont, cw, ch);
902 case gGameSettings.GameMode of
903 GM_TDM, GM_CTF: result := 32 + ch * (11 + players);
904 otherwise result := 40 + ch * 5 + (ch + 8) * players;
905 end;
906 end;
908 procedure r_Render_DrawStats;
909 var x, y, w, h, players: Integer; cs: TEndCustomGameStat;
910 begin
911 cs.PlayerStat := g_Player_GetStats();
912 SortGameStat(cs.PlayerStat);
913 cs.TeamStat := gTeamStat;
914 cs.GameTime := gTime;
915 cs.GameMode := gGameSettings.GameMode;
916 cs.Map := g_ExtractWadNameNoPath(gMapInfo.Map) + ':' + g_ExtractFileName(gMapInfo.Map);
917 cs.MapName := gMapInfo.Name;
918 if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
919 w := gScreenWidth - (gScreenWidth div 5);
920 h := r_Render_StatsHeight(players);
921 x := (gScreenWidth div 2) - (w div 2);
922 y := (gScreenHeight div 2) - (h div 2);
923 r_Render_DrawStatsWindow(x, y, w, h, cs, false);
924 end;
926 procedure r_Render_DrawCustomStats;
927 var cw, ch, s: AnsiString;
928 begin
929 if gStatsOff then
930 begin
931 r_Render_DrawText(_lc[I_MENU_INTER_NOTICE_TAB], gScreenWidth div 2, 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
932 end
933 else
934 begin
935 case gGameSettings.GameMode of
936 GM_COOP: if gMissionFailed then s := _lc[I_MENU_INTER_MISSION_FAIL] else s := _lc[I_MENU_INTER_LEVEL_COMPLETE];
937 otherwise s := _lc[I_MENU_INTER_ROUND_OVER];
938 end;
939 r_Render_DrawText(s, gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
941 if gChatShow = false then
942 begin
943 if g_Game_IsClient then s := _lc[I_MENU_INTER_NOTICE_MAP] else s := _lc[I_MENU_INTER_NOTICE_SPACE];
944 r_Render_DrawText(s, gScreenWidth div 2, gScreenHeight - 4, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
945 if g_Game_IsNet then
946 begin
947 s := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
948 r_Render_DrawText(s, gScreenWidth div 2, gScreenHeight - 16 - 4, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
949 end;
950 end;
952 r_Render_DrawStatsWindow(32, 64, gScreenWidth - 32 * 2, gScreenHeight - 64 * 2, CustomStat, true);
953 end;
954 end;
956 procedure r_Render_DrawValueOf (a, b, x, y: Integer; f: TGLFont);
957 var wa, wb, ch: Integer; sa, sb: AnsiString;
958 begin
959 sa := IntToStr(a);
960 sb := IntToStr(b);
961 r_Draw_GetTextSize(sa, f, wa, ch);
962 r_Draw_GetTextSize(sa + ' / ', f, wb, ch);
963 r_Render_DrawText(sa, x, y, 255, 0, 0, 255, f, TBasePoint.BP_LEFTUP);
964 r_Render_DrawText(' / ', x + wa, y, 255, 255, 255, 255, f, TBasePoint.BP_LEFTUP);
965 r_Render_DrawText(sb, x + wb, y, 255, 0, 0, 255, f, TBasePoint.BP_LEFTUP);
966 end;
968 procedure r_Render_DrawSinglStatsPlayer (player, x, y, w1: Integer);
969 var time, kpm: Single;
970 begin
971 r_Render_DrawText(_lc[I_MENU_INTER_KILLS], x, y, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
972 r_Render_DrawValueOf(SingleStat.PlayerStat[player].Kills, gTotalMonsters, x + w1, y, MenuFont);
973 r_Render_DrawText(_lc[I_MENU_INTER_KPM], x, y + 32, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
974 time := SingleStat.GameTime / 1000;
975 kpm := SingleStat.PlayerStat[player].Kills;
976 if time > 0 then kpm := kpm / time * 60;
977 r_Render_DrawText(Format('%.1f', [kpm]), x + w1, y + 32, 255, 0, 0, 255, menufont, TBasePoint.BP_LEFTUP);
978 r_Render_DrawText(_lc[I_MENU_INTER_SECRETS], x, y + 64, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
979 r_Render_DrawValueOf(SingleStat.PlayerStat[player].Secrets, SingleStat.TotalSecrets, x + w1, y + 64, MenuFont);
980 end;
982 procedure r_Render_DrawSingleStats;
983 var xx, wa, wb, ww, ch: Integer; s: AnsiString;
984 begin
985 r_Render_DrawText(_lc[I_MENU_INTER_LEVEL_COMPLETE], gScreenWidth div 2, 32, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
987 r_Draw_GetTextSize(_lc[I_MENU_INTER_KPM] + ' ', menufont, wa, ch);
988 r_Draw_GetTextSize(' 9999.9', menufont, wb, ch);
989 ww := wa + wb;
990 xx := gScreenWidth div 2 - ww div 2;
992 s := r_Render_TimeToStr(SingleStat.GameTime);
993 r_Render_DrawText(_lc[I_MENU_INTER_TIME], xx, 80, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
994 r_Render_DrawText(s, xx + wa, 80, 255, 0, 0, 255, menufont, TBasePoint.BP_LEFTUP);
996 if SingleStat.TwoPlayers then
997 begin
998 r_Render_DrawText(_lc[I_MENU_PLAYER_1], gScreenWidth div 2, 128, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
999 r_Render_DrawSinglStatsPlayer(0, xx, 176, wa);
1000 r_Render_DrawText(_lc[I_MENU_PLAYER_2], gScreenWidth div 2, 288, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
1001 r_Render_DrawSinglStatsPlayer(1, xx, 336, wa);
1002 end
1003 else
1004 begin
1005 r_Render_DrawSinglStatsPlayer(0, xx, 128, wa);
1006 end;
1007 end;
1009 procedure r_Render_DrawSpectHud;
1010 var xoff: Integer; s: AnsiString;
1012 procedure AddText (s1, s2: AnsiString);
1013 var w1, w2, ww, ch: Integer;
1014 begin
1015 r_Draw_GetTextSize(s1, stdfont, w1, ch);
1016 r_Draw_GetTextSize(s2, stdfont, w2, ch);
1017 ww := MAX(w1, w2);
1018 r_Render_DrawText(s1, xoff + ww div 2, gScreenHeight - ch, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
1019 r_Render_DrawText(s2, xoff + ww div 2, gScreenHeight - ch, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
1020 xoff := xoff + ww + 16;
1021 end;
1023 begin
1024 xoff := 0;
1025 case gSpectMode of
1026 SPECT_STATS: s := 'MODE: Stats';
1027 SPECT_MAPVIEW: s := 'MODE: Observe Map';
1028 SPECT_PLAYERS: s := 'MODE: Watch Players';
1029 otherwise s := 'MODE: ' + IntToStr(gSpectMode);
1030 end;
1031 AddText(s, '< jump >');
1032 if gSpectMode = SPECT_STATS then
1033 AddText('Autoview', '< fire >');
1034 if gSpectMode = SPECT_MAPVIEW then
1035 AddText('[-] Step ' + IntToStr(gSpectStep) + ' [+]', '<prev weap> <next weap>');
1036 if gSpectMode = SPECT_PLAYERS then
1037 begin
1038 AddText('Player 1', '<left/right>');
1039 if gSpectViewTwo then
1040 AddText('Player 2', '<prev w/next w>');
1041 AddText('2x View', '<up/down>');
1042 end;
1043 end;
1045 function GetActivePlayer_ByID (id: Integer): TPlayer;
1046 var i, len: Integer; p: TPlayer;
1047 begin
1048 p := nil;
1049 if (id >= 0) and (gPlayers <> nil) then
1050 begin
1051 i := 0; len := Length(gPlayers);
1052 while (i < len) and ((IsActivePlayer(gPlayers[i]) = false) or (gPlayers[i].UID <> id)) do INC(i);
1053 if i < len then p := gPlayers[i];
1054 end;
1055 result := p;
1056 end;
1058 procedure r_Render_Draw;
1059 var p1, p2: TPlayer;
1060 begin
1061 if gExit = EXIT_QUIT then
1062 exit;
1064 r_Draw_Setup(gScreenWidth, gScreenHeight);
1066 glClearColor(0.0, 0.0, 0.0, 0.0);
1067 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
1069 glColor4ub(255, 255, 255, 255);
1070 glEnable(GL_SCISSOR_TEST);
1071 r_Draw_SetRect(0, 0, gScreenWidth, gScreenHeight);
1073 //e_LogWritefln('r_render_draw: %sx%s', [gScreenWidth, gScreenHeight]);
1075 p1 := nil;
1076 p2 := nil;
1077 if gGameOn or (gState = STATE_FOLD) then
1078 begin
1079 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
1080 begin
1081 if gRevertPlayers then
1082 begin
1083 p1 := gPlayer2;
1084 p2 := gPlayer1;
1085 end
1086 else
1087 begin
1088 p1 := gPlayer1;
1089 p2 := gPlayer2;
1090 end;
1091 end
1092 else if gPlayer1 <> nil then
1093 begin
1094 p1 := gPlayer1;
1095 end
1096 else if gPlayer2 <> nil then
1097 begin
1098 p1 := gPlayer2;
1099 end;
1100 if (gSpectMode = SPECT_PLAYERS) and (gPlayers <> nil) then
1101 begin
1102 p1 := GetActivePlayer_ByID(gSpectPID1);
1103 if p1 = nil then
1104 p1 := GetActivePlayer_ByID(GetActivePlayerID_Next());
1105 if gSpectViewTwo then
1106 begin
1107 p2 := GetActivePlayer_ByID(gSpectPID2);
1108 if p2 = nil then
1109 p2 := GetActivePlayer_ByID(GetActivePlayerID_Next());
1110 end;
1111 end;
1112 end;
1114 if gGameOn or ((gState in [STATE_FOLD]) and (EndingGameCounter < 255)) then
1115 begin
1116 // TODO setup player hear point
1118 if gSpectMode = SPECT_MAPVIEW then
1119 begin
1120 r_Render_DrawMapView(0, 0, gScreenWidth, gScreenHeight, gSpectX + gScreenWidth div 2, gSpectY + gScreenHeight div 2);
1121 end
1122 else if (p1 <> nil) and (p2 <> nil) then
1123 begin
1124 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight div 2 - 2, p1);
1125 r_Render_DrawPlayerView(0, gScreenHeight div 2 + 2, gScreenWidth, gScreenHeight div 2, p2);
1126 end
1127 else if p1 <> nil then
1128 begin
1129 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, p1);
1130 end
1131 else if p2 <> nil then
1132 begin
1133 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, p2);
1134 end;
1136 // TODO draw holmes inspector
1138 if MessageText <> '' then
1139 r_Render_DrawFormatText(MessageText, (gScreenWidth - 196) div 2, gScreenHeight div 2, 255, menufont, TBasePoint.BP_CENTER);
1141 if IsDrawStat or (gSpectMode = SPECT_STATS) then
1142 r_Render_DrawStats;
1144 if gSpectHUD and (gChatShow = false) and (gSpectMode <> SPECT_NONE) and (gSpectAuto = false) then
1145 r_Render_DrawSpectHud;
1146 end;
1148 if gPauseMain and gGameOn {$IFDEF ENABLE_MENU}and (g_ActiveWindow = nil){$ENDIF} then
1149 begin
1150 // TODO draw pause screen
1151 end;
1153 if not gGameOn then
1154 begin
1155 case gState of
1156 STATE_NONE: (* do nothing *) ;
1157 STATE_MENU: r_Render_DrawBackground(GameWad + ':TEXTURES/TITLE');
1158 STATE_FOLD:
1159 begin
1160 if EndingGameCounter > 0 then
1161 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
1162 end;
1163 STATE_INTERCUSTOM:
1164 begin
1165 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1166 if EndPicPath <> '' then
1167 r_Render_DrawBackground(EndPicPath)
1168 else
1169 r_Render_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC])
1170 else
1171 r_Render_DrawBackground(GameWad + ':TEXTURES/INTER');
1173 r_Render_DrawCustomStats;
1175 {$IFDEF ENABLE_MENU}
1176 if g_ActiveWindow <> nil then
1177 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1178 {$ENDIF}
1179 end;
1180 STATE_INTERSINGLE, STATE_INTERTEXT, STATE_INTERPIC:
1181 begin
1182 if EndingGameCounter > 0 then
1183 begin
1184 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
1185 end
1186 else
1187 begin
1188 r_Render_DrawBackground(GameWad + ':TEXTURES/INTER');
1189 r_Render_DrawSingleStats;
1190 {$IFDEF ENABLE_MENU}
1191 if g_ActiveWindow <> nil then
1192 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1193 {$ENDIF}
1194 end;
1195 end;
1196 STATE_ENDPIC:
1197 begin
1198 if EndPicPath <> '' then
1199 r_Render_DrawBackground(EndPicPath)
1200 else
1201 r_Render_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC]);
1202 {$IFDEF ENABLE_MENU}
1203 if g_ActiveWindow <> nil then
1204 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1205 {$ENDIF}
1206 end;
1207 STATE_SLIST:
1208 begin
1209 r_Render_DrawBackground(GameWad + ':TEXTURES/TITLE');
1210 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1211 r_Render_DrawServerList(slCurrent, slTable);
1212 end;
1213 end;
1214 end;
1216 {$IFDEF ENABLE_MENU}
1217 if g_ActiveWindow <> nil then
1218 begin
1219 if gGameOn then
1220 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1221 r_GUI_Draw_Window(g_ActiveWindow);
1222 end;
1223 {$ENDIF}
1225 r_Console_Draw(false);
1227 // TODO draw holmes interface
1229 glFlush();
1230 glFinish();
1231 sys_Repaint;
1232 end;
1234 procedure r_Render_Resize (w, h: Integer);
1235 begin
1236 gWinSizeX := w;
1237 gWinSizeY := h;
1238 gRC_Width := w;
1239 gRC_Height := h;
1240 gScreenWidth := w;
1241 gScreenHeight := h;
1242 end;
1244 procedure r_Render_Apply;
1245 begin
1246 {$IFDEF ENABLE_SYSTEM}
1247 if sys_SetDisplayModeGL(GetInfo()) then
1248 e_LogWriteln('resolution changed')
1249 else
1250 e_LogWriteln('resolution not changed');
1251 sys_EnableVSync(gVSync)
1252 {$ENDIF}
1253 end;
1255 function r_Render_WriteScreenShot (filename: String): Boolean;
1256 begin
1257 Result := False;
1258 end;
1260 {$IFDEF ENABLE_GIBS}
1261 function r_Render_GetGibRect (m, id: Integer): TRectWH;
1262 begin
1263 result := r_Map_GetGibSize(m, id);
1264 end;
1265 {$ENDIF}
1267 {$IFDEF ENABLE_GFX}
1268 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
1269 begin
1270 r_Map_NewGFX(AnimType, X, Y);
1271 end;
1272 {$ENDIF}
1274 {$IFDEF ENABLE_TOUCH}
1275 procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
1276 begin
1277 founded := False;
1278 end;
1279 {$ENDIF}
1281 {$IFDEF ENABLE_MENU}
1282 procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
1283 begin
1284 r_GUI_GetSize(ctrl, w, h);
1285 end;
1287 procedure r_Render_GetLogoSize (out w, h: Integer);
1288 begin
1289 r_GUI_GetLogoSize(w, h);
1290 end;
1292 procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
1293 begin
1294 r_GUI_GetMaxFontSize(BigFont, w, h);
1295 end;
1297 procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
1298 begin
1299 r_GUI_GetStringSize(BigFont, str, w, h);
1300 end;
1301 {$ENDIF}
1303 procedure r_Render_DrawLoading (force: Boolean);
1304 begin
1305 // TODO draw loading screen
1306 end;
1308 end.