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}
23 function SDLMain (): Integer;
24 procedure ResetTimer ();
25 procedure ProcessLoading (forceUpdate
: Boolean=false);
28 gwin_dump_extensions
: Boolean = false;
29 gwin_has_stencil
: Boolean = false;
30 gwin_k8_enable_light_experiments
: Boolean = false;
31 g_dbg_aimline_on
: Boolean = false;
32 g_dbg_input
: Boolean = False;
37 {$IFDEF WINDOWS}Windows
,{$ENDIF}
38 {$IFDEF ENABLE_HOLMES}
39 g_holmes
, sdlcarcass
, fui_ctls
,
41 SysUtils
, Classes
, MAPDEF
, Math
,
42 e_graphics
, e_log
, e_texture
, g_main
,
43 g_console
, e_input
, g_options
, g_game
,
44 g_basic
, g_textures
, e_sound
, g_sound
, g_menu
, ENet
, g_net
,
45 g_map
, g_gfx
, g_monsters
, xprofiler
,
46 g_touch
, g_gui
, g_system
;
50 ProgressUpdateMSecs
= 35; //1;//100;
53 Time
, Time_Delta
, Time_Old
: Int64;
55 wNeedTimeReset
: Boolean = false;
56 wMinimized
: Boolean = false;
57 wMaximized
: Boolean = false;
58 wLoadingProgress
: Boolean = false;
59 wLoadingQuit
: Boolean = false;
61 procedure ResetTimer ();
63 wNeedTimeReset
:= true;
68 prevLoadingUpdateTime
: UInt64 = 0;
71 procedure ProcessLoading (forceUpdate
: Boolean=false);
78 // FillChar(ev, sizeof(ev), 0);
79 wLoadingProgress
:= true;
81 // while (SDL_PollEvent(@ev) > 0) do
84 // if (ev.type_ = SDL_QUITEV) then break;
88 // if (ev.type_ = SDL_QUITEV) or (gExit = EXIT_QUIT) then
90 // wLoadingProgress := false;
95 if not wMinimized
then
97 if not forceUpdate
then
99 stt
:= getTimeMilli();
100 forceUpdate
:= (stt
< prevLoadingUpdateTime
) or (stt
-prevLoadingUpdateTime
>= ProgressUpdateMSecs
);
105 DrawMenuBackground('INTER');
106 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
109 g_Console_Draw(True);
111 prevLoadingUpdateTime
:= getTimeMilli();
118 if NetMode
= NET_SERVER
then
124 if (NetMode
= NET_CLIENT
) and (NetState
<> NET_STATE_AUTH
) then g_Net_Client_UpdateWhileLoading();
127 wLoadingProgress
:= false;
131 function ProcessMessage (): Boolean;
135 result
:= sys_HandleInput();
137 Time
:= sys_GetTicks();
138 Time_Delta
:= Time
-Time_Old
;
142 if wNeedTimeReset
then
145 wNeedTimeReset
:= false;
148 g_Map_ProfilersBegin();
149 g_Mons_ProfilersBegin();
151 t
:= Time_Delta
div 28;
157 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
158 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
164 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
165 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
168 if NetMode
= NET_SERVER
then g_Net_Flush();
170 g_Map_ProfilersEnd();
171 g_Mons_ProfilersEnd();
179 if (gExit
= EXIT_QUIT
) then
185 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ
188 Time_Old
:= Time
- (Time_Delta
mod 28);
189 if (not wMinimized
) then
197 sys_Delay(1) // release time slice, so we won't eat 100% CPU
203 function SDLMain (): Integer;
206 {$IF not DEFINED(HEADLESS)}
211 {$IFDEF ENABLE_HOLMES}
217 e_NoGraphics
:= true;
219 {$IFDEF ENABLE_HOLMES}
220 if (not g_holmes_imfunctional
) then
223 uiContext
.font
:= 'win14';
229 while (idx
<= ParamCount
) do
231 arg
:= ParamStr(idx
);
233 if arg
= '--opengl-dump-exts' then gwin_dump_extensions
:= true;
234 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
235 if arg
= '--jah' then g_profile_history_size
:= 100;
236 if arg
= '--no-particles' then gpart_dbg_enabled
:= false;
237 if arg
= '--no-los' then gmon_dbg_los_enabled
:= false;
239 if arg
= '--profile-render' then g_profile_frame_draw
:= true;
240 if arg
= '--profile-coldet' then g_profile_collision
:= true;
241 if arg
= '--profile-los' then g_profile_los
:= true;
243 if arg
= '--no-part-phys' then gpart_dbg_phys_enabled
:= false;
244 if arg
= '--no-part-physics' then gpart_dbg_phys_enabled
:= false;
245 if arg
= '--no-particles-phys' then gpart_dbg_phys_enabled
:= false;
246 if arg
= '--no-particles-physics' then gpart_dbg_phys_enabled
:= false;
247 if arg
= '--no-particle-phys' then gpart_dbg_phys_enabled
:= false;
248 if arg
= '--no-particle-physics' then gpart_dbg_phys_enabled
:= false;
250 if arg
= '--debug-input' then g_dbg_input
:= True;
252 {.$IF DEFINED(D2F_DEBUG)}
253 if arg
= '--aimline' then g_dbg_aimline_on
:= true;
256 {$IFDEF ENABLE_HOLMES}
257 if arg
= '--holmes' then begin g_holmes_enabled
:= true; g_Game_SetDebugMode(); end;
259 if (arg
= '--holmes-ui-scale') or (arg
= '-holmes-ui-scale') then
261 if (idx
<= ParamCount
) then
263 if not conParseFloat(fuiRenderScale
, ParamStr(idx
)) then fuiRenderScale
:= 1.0;
268 if (arg
= '--holmes-font') or (arg
= '-holmes-font') then
270 if (idx
<= ParamCount
) then
273 val(ParamStr(idx
), itmp
, valres
);
275 if (valres
= 0) and (not g_holmes_imfunctional
) then
278 8: uiContext
.font
:= 'win8';
279 14: uiContext
.font
:= 'win14';
280 16: uiContext
.font
:= 'win16';
293 if (arg
= '--game-scale') or (arg
= '-game-scale') then
295 if (idx
<= ParamCount
) then
297 if not conParseFloat(g_dbg_scale
, ParamStr(idx
)) then g_dbg_scale
:= 1.0;
302 if (arg
= '--write-mapdef') or (arg
= '-write-mapdef') then
304 mdfo
:= createDiskFile('mapdef.txt');
305 mdfo
.WriteBuffer(defaultMapDef
[1], Length(defaultMapDef
));
312 Time_Old
:= sys_GetTicks();
315 if (ParamCount
> 0) then g_Game_Process_Params();
319 if (not gGameOn
) and gAskLanguage
then g_Menu_AskLanguage();
322 e_WriteLog('Entering the main loop', TMsgType
.Notify
);
325 while not ProcessMessage() do begin end;
333 conRegVar('d_input', @g_dbg_input
, '', '')