1 (* Copyright (C) Doom 2D: Forever Developers
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.
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.
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/>.
15 {$INCLUDE ../../../shared/a_modes.inc}
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);
34 {$I ../../../nogl/noGLuses.inc}
35 {$IFDEF ENABLE_SYSTEM}
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
44 FPSTime
: LongWord = 0;
45 r_loadscreen_fps
: WORD = 0;
46 BarL
, BarM
, BarR
, BarF
: TGLTexture
;
47 LoadingScreen
: array of record
52 procedure r_LoadScreen_Initialize
;
56 procedure r_LoadScreen_Finalize
;
60 procedure r_LoadScreen_Load
;
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', []);
68 procedure r_LoadScreen_Free
;
70 r_Common_FreeAndNil(BarL
);
71 r_Common_FreeAndNil(BarM
);
72 r_Common_FreeAndNil(BarR
);
73 r_Common_FreeAndNil(BarF
);
76 procedure r_LoadScreen_DrawLoadingBar (x0
, x1
, y
, val
, maxval
: Integer);
77 var l
, t
, r
, b
, minw
, reqw
, midw
, fillw
, curw
, x
: Integer;
79 if (BarL
<> nil) and (BarM
<> nil) and (BarR
<> nil) and (BarF
<> nil) and (maxval
> 0) then
81 minw
:= BarL
.width
+ BarM
.width
+ BarR
.width
;
85 midw
:= (reqw
- BarL
.width
- BarR
.width
) div BarM
.width
* BarM
.width
;
86 x
:= x0
- (reqw
- (BarL
.width
+ midw
+ BarR
.width
)) div 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);
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
);
103 procedure r_LoadScreen_Clear
;
105 LoadingScreen
:= nil;
108 procedure r_LoadScreen_Set (const text: String; maxval
: Integer);
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
);
118 procedure r_LoadScreen_Step (incval
: Integer);
121 if LoadingScreen
<> nil then
123 i
:= HIGH(LoadingScreen
);
124 INC(LoadingScreen
[i
].val
, MAX(0, incval
));
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;
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
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
148 r_Common_DrawText(_lc
[I_MENU_LOADING
], gScreenWidth
div 2, yy
- 32, 255, 255, 255, 255, menufont
, TBasePoint
.BP_DOWN
);
150 if (smallfont
<> nil) and (LoadingScreen
<> nil) then
152 n
:= hh
div LOADING_INTERLINE
- 1;
153 for i
:= MAX(0, Length(LoadingScreen
) - n
) to HIGH(LoadingScreen
) do
155 if LoadingScreen
[i
].maxval
> 1 then
156 s
:= LoadingScreen
[i
].msg
+ ' ' + IntToStr(LoadingScreen
[i
].val
) + '/' + IntToStr(LoadingScreen
[i
].maxval
)
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
);
163 if (BarF
<> nil) and (LoadingScreen
<> nil) then
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
);
169 if stdfont
<> nil then
171 r_Console_Draw(true);
178 conRegVar('r_loadscreen_fps', @r_loadscreen_fps
, '', '');
179 r_loadscreen_fps
:= 0; // auto