4e84b5d53eb9823a4b5234c44a38cbbc99ca9077
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_has_stencil
: Boolean = false;
29 gwin_k8_enable_light_experiments
: Boolean = false;
30 g_dbg_aimline_on
: Boolean = false;
31 g_dbg_input
: Boolean = False;
36 {$IFDEF WINDOWS}Windows
,{$ENDIF}
37 {$IFDEF ENABLE_HOLMES}
38 g_holmes
, sdlcarcass
, fui_ctls
,
40 SysUtils
, Classes
, MAPDEF
, Math
,
41 r_window
, e_log
, g_main
,
42 g_console
, r_console
, e_input
, g_options
, g_game
,
43 g_basic
, g_textures
, e_sound
, g_sound
, g_menu
, ENet
, g_net
,
44 g_map
, g_gfx
, g_monsters
, xprofiler
,
45 g_touch
, g_gui
, g_system
, g_netmaster
;
48 Time
, Time_Delta
, Time_Old
: Int64;
51 wNeedTimeReset
: Boolean = false;
52 wLoadingQuit
: Boolean = false;
54 procedure ResetTimer ();
56 wNeedTimeReset
:= true;
59 procedure ProcessLoading (forceUpdate
: Boolean=false);
61 if sys_HandleInput() = True then
65 r_Window_DrawLoading(forceUpdate
);
70 if NetMode
= NET_SERVER
then
72 else if (NetMode
= NET_CLIENT
) and (NetState
<> NET_STATE_AUTH
) then
73 g_Net_Client_UpdateWhileLoading();
77 function ProcessMessage (): Boolean;
81 result
:= sys_HandleInput();
83 Time
:= sys_GetTicks();
84 Time_Delta
:= Time
-Time_Old
;
88 if wNeedTimeReset
then
92 wNeedTimeReset
:= false;
95 g_Map_ProfilersBegin();
96 g_Mons_ProfilersBegin();
98 t
:= Time_Delta
div 28;
106 g_Map_ProfilersEnd();
107 g_Mons_ProfilersEnd();
115 if (gExit
= EXIT_QUIT
) then
121 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ
123 Time_Old
:= Time
- (Time_Delta
mod 28);
125 // don't wait if VSync is on, GL already probably waits enough
127 flag
:= (Time
- Frame
>= gFrameTime
) or gVSync
;
131 if gPause
or (not gLerpActors
) or (gState
= STATE_FOLD
) then
134 gLerpFactor
:= nmin(1.0, (Time
- Time_Old
) / 28.0);
145 function SDLMain (): Integer;
150 {$IFDEF ENABLE_HOLMES}
157 while (idx
<= ParamCount
) do
159 arg
:= ParamStr(idx
);
161 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
162 if arg
= '--jah' then g_profile_history_size
:= 100;
163 if arg
= '--no-particles' then gpart_dbg_enabled
:= false;
164 if arg
= '--no-los' then gmon_dbg_los_enabled
:= false;
166 if arg
= '--profile-render' then g_profile_frame_draw
:= true;
167 if arg
= '--profile-coldet' then g_profile_collision
:= true;
168 if arg
= '--profile-los' then g_profile_los
:= true;
170 if arg
= '--no-part-phys' then gpart_dbg_phys_enabled
:= false;
171 if arg
= '--no-part-physics' then gpart_dbg_phys_enabled
:= false;
172 if arg
= '--no-particles-phys' then gpart_dbg_phys_enabled
:= false;
173 if arg
= '--no-particles-physics' then gpart_dbg_phys_enabled
:= false;
174 if arg
= '--no-particle-phys' then gpart_dbg_phys_enabled
:= false;
175 if arg
= '--no-particle-physics' then gpart_dbg_phys_enabled
:= false;
177 if arg
= '--debug-input' then g_dbg_input
:= True;
179 {.$IF DEFINED(D2F_DEBUG)}
180 if arg
= '--aimline' then g_dbg_aimline_on
:= true;
183 {$IFDEF ENABLE_HOLMES}
184 if arg
= '--holmes' then begin g_holmes_enabled
:= true; g_Game_SetDebugMode(); end;
186 if (arg
= '--holmes-ui-scale') or (arg
= '-holmes-ui-scale') then
188 if (idx
<= ParamCount
) then
190 if not conParseFloat(fuiRenderScale
, ParamStr(idx
)) then fuiRenderScale
:= 1.0;
195 if (arg
= '--holmes-font') or (arg
= '-holmes-font') then
197 if (idx
<= ParamCount
) then
200 val(ParamStr(idx
), itmp
, valres
);
202 if (valres
= 0) and (not g_holmes_imfunctional
) then
205 8: uiContext
.font
:= 'win8';
206 14: uiContext
.font
:= 'win14';
207 16: uiContext
.font
:= 'win16';
220 if (arg
= '--game-scale') or (arg
= '-game-scale') then
222 if (idx
<= ParamCount
) then
224 if not conParseFloat(g_dbg_scale
, ParamStr(idx
)) then g_dbg_scale
:= 1.0;
229 if (arg
= '--write-mapdef') or (arg
= '-write-mapdef') then
231 mdfo
:= createDiskFile('mapdef.txt');
232 mdfo
.WriteBuffer(defaultMapDef
[1], Length(defaultMapDef
));
237 if (arg
= '--pixel-scale') or (arg
= '-pixel-scale') then
239 if (idx
<= ParamCount
) then
241 if not conParseFloat(r_pixel_scale
, ParamStr(idx
)) then r_pixel_scale
:= 1.0;
250 Time_Old
:= sys_GetTicks();
252 g_Net_InitLowLevel();
255 if (ParamCount
> 0) then g_Game_Process_Params();
259 if (not gGameOn
) and gAskLanguage
then g_Menu_AskLanguage();
262 e_WriteLog('Entering the main loop', TMsgType
.Notify
);
265 while not ProcessMessage() do begin end;
267 g_Net_Slist_ShutdownAll();
271 g_Net_DeinitLowLevel();
277 conRegVar('d_input', @g_dbg_input
, '', '')