DEADSOFTWARE

d95d3a475ff26184f36d504676683503269f8157
[d2df-sdl.git] / src / game / renders / opengl / r_loadscreen.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_loadscreen;
18 interface
20 procedure r_LoadScreen_Initialize;
21 procedure r_LoadScreen_Finalize;
23 procedure r_LoadScreen_Load;
24 procedure r_LoadScreen_Free;
26 procedure r_LoadScreen_Clear;
27 procedure r_LoadScreen_Set (const text: AnsiString; maxval: Integer);
28 procedure r_LoadScreen_Step (incval: Integer);
29 procedure r_LoadScreen_Draw (force: Boolean);
31 implementation
33 uses
34 {$I ../../../nogl/noGLuses.inc}
35 {$IFDEF ENABLE_SYSTEM}
36 g_system,
37 {$ENDIF}
38 SysUtils, Classes, Math,
39 e_log, utils, g_language, g_options, g_console, g_game,
40 r_draw, r_textures, r_fonts, r_common, r_console
41 ;
43 var
44 FPSTime: LongWord = 0;
45 r_loadscreen_fps: WORD = 0;
46 BarL, BarM, BarR, BarF: TGLTexture;
47 LoadingScreen: array of record
48 msg: AnsiString;
49 val, maxval: Integer;
50 end = nil;
52 procedure r_LoadScreen_Initialize;
53 begin
54 end;
56 procedure r_LoadScreen_Finalize;
57 begin
58 end;
60 procedure r_LoadScreen_Load;
61 begin
62 BarL := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/LLEFT', [TGLHints.txNoRepeat]);
63 BarM := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/LMIDDLE', []);
64 BarR := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/LRIGHT', [TGLHints.txNoRepeat]);
65 BarF := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/LMARKER', []);
66 end;
68 procedure r_LoadScreen_Free;
69 begin
70 r_Common_FreeAndNil(BarL);
71 r_Common_FreeAndNil(BarM);
72 r_Common_FreeAndNil(BarR);
73 r_Common_FreeAndNil(BarF);
74 end;
76 procedure r_LoadScreen_DrawLoadingBar (x0, x1, y, val, maxval: Integer);
77 var l, t, r, b, minw, reqw, midw, fillw, curw, x: Integer;
78 begin
79 if (BarL <> nil) and (BarM <> nil) and (BarR <> nil) and (BarF <> nil) and (maxval > 0) then
80 begin
81 minw := BarL.width + BarM.width + BarR.width;
82 reqw := x1 - x0;
83 if reqw >= minw then
84 begin
85 midw := (reqw - BarL.width - BarR.width) div BarM.width * BarM.width;
86 x := x0 - (reqw - (BarL.width + midw + BarR.width)) div 2;
87 fillw := midw + 2;
88 curw := MIN(val * fillw div maxval, fillw);
89 r_Draw_TextureRepeat(BarL, x, y, BarL.width, BarL.height, false, 255, 255, 255, 255, false);
90 r_Draw_TextureRepeat(BarM, x + BarL.width, y, midw, BarM.height, false, 255, 255, 255, 255, false);
91 r_Draw_TextureRepeat(BarR, x + BarL.width + midw, y, BarR.width, BarR.height, false, 255, 255, 255, 255, false);
92 if curw > 0 then
93 begin
94 r_Draw_GetRect(l, t, r, b);
95 r_Draw_SetRect(x + BarL.width - 1, y, x + BarL.width - 1 + curw - 1, y + BarF.height - 1);
96 r_Draw_TextureRepeat(BarF, x + BarL.width - 1, y, curw, BarF.height, false, 255, 255, 255, 255, false);
97 r_Draw_SetRect(l, t, r, b);
98 end;
99 end;
100 end;
101 end;
103 procedure r_LoadScreen_Clear;
104 begin
105 LoadingScreen := nil;
106 end;
108 procedure r_LoadScreen_Set (const text: String; maxval: Integer);
109 var i: Integer;
110 begin
111 if LoadingScreen = nil then i := 0 else i := Length(LoadingScreen);
112 SetLength(LoadingScreen, i + 1);
113 LoadingScreen[i].msg := text;
114 LoadingScreen[i].val := 0;
115 LoadingScreen[i].maxval := MAX(0, maxval);
116 end;
118 procedure r_LoadScreen_Step (incval: Integer);
119 var i: Integer;
120 begin
121 if LoadingScreen <> nil then
122 begin
123 i := HIGH(LoadingScreen);
124 INC(LoadingScreen[i].val, MAX(0, incval));
125 end;
126 end;
128 procedure r_LoadScreen_Draw (force: Boolean);
129 const LOADING_INTERLINE = 20;
130 var xx, yy, hh, i, n: Integer; s: AnsiString; time, delay: LongWord;
131 begin
132 time := GetTickCount64();
133 if r_loadscreen_fps <= 0 then delay := 1000 div GAME_TICK else delay := 1000 div r_loadscreen_fps;
134 if force or (time - FPSTime >= delay) then
135 begin
136 FPSTime := time;
138 xx := gScreenWidth div 3;
139 yy := gScreenHeight div 3;
140 hh := gScreenHeight - yy - 96;
141 r_Draw_Setup(gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight);
142 glClearColor(0.0, 0.0, 0.0, 0.0);
143 glClear(GL_COLOR_BUFFER_BIT);
144 r_Common_DrawBackground(GameWad + ':TEXTURES/INTER');
145 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
146 if menufont <> nil then
147 begin
148 r_Common_DrawText(_lc[I_MENU_LOADING], gScreenWidth div 2, yy - 32, 255, 255, 255, 255, menufont, TBasePoint.BP_DOWN);
149 end;
150 if (smallfont <> nil) and (LoadingScreen <> nil) then
151 begin
152 n := hh div LOADING_INTERLINE - 1;
153 for i := MAX(0, Length(LoadingScreen) - n) to HIGH(LoadingScreen) do
154 begin
155 if LoadingScreen[i].maxval > 1 then
156 s := LoadingScreen[i].msg + ' ' + IntToStr(LoadingScreen[i].val) + '/' + IntToStr(LoadingScreen[i].maxval)
157 else
158 s := LoadingScreen[i].msg;
159 r_Common_DrawText(s, xx, yy, 255, 0, 0, 255, smallfont, TBasePoint.BP_LEFTUP);
160 INC(yy, LOADING_INTERLINE);
161 end;
162 end;
163 if (BarF <> nil) and (LoadingScreen <> nil) then
164 begin
165 i := HIGH(LoadingScreen);
166 if LoadingScreen[i].maxval > 1 then
167 r_LoadScreen_DrawLoadingBar(64, gScreenWidth - 64, gScreenHeight - 64, LoadingScreen[i].val, LoadingScreen[i].maxval);
168 end;
169 if stdfont <> nil then
170 begin
171 r_Console_Draw(true);
172 end;
173 sys_Repaint;
174 end;
175 end;
177 initialization
178 conRegVar('r_loadscreen_fps', @r_loadscreen_fps, '', '');
179 r_loadscreen_fps := 0; // auto
180 end.