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 {$INCLUDE ../nogl/noGLuses.inc}
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
, g_netmaster
;
50 ProgressUpdateMSecs
= 35; //1;//100;
53 Time
, Time_Delta
, Time_Old
: Int64;
56 wNeedTimeReset
: Boolean = false;
57 wMinimized
: Boolean = false;
58 wLoadingQuit
: Boolean = false;
60 procedure ResetTimer ();
62 wNeedTimeReset
:= true;
67 prevLoadingUpdateTime
: UInt64 = 0;
70 procedure ProcessLoading (forceUpdate
: Boolean);
76 if sys_HandleInput() = True then
80 if not wMinimized
then
82 if not forceUpdate
then
84 stt
:= getTimeMilli();
85 forceUpdate
:= (stt
< prevLoadingUpdateTime
) or (stt
-prevLoadingUpdateTime
>= ProgressUpdateMSecs
);
90 e_SetRendertarget(True);
91 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
93 DrawMenuBackground('INTER');
94 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
98 e_SetRendertarget(False);
99 e_SetViewPort(0, 0, gWinSizeX
, gWinSizeY
);
100 e_BlitFramebuffer(gWinSizeX
, gWinSizeY
);
103 prevLoadingUpdateTime
:= getTimeMilli();
110 // TODO: At the moment, I left here only host network processing, because the client code must
111 // handle network events on its own. Otherwise separate network cases that use different calls to
112 // enet_host_service() WILL lose their packets (for example, resource downloading). So they have
113 // to handle everything by themselves. But in general, this MUST be removed completely, since
114 // updating the window should never affect the network. Use single enet_host_service(), period.
115 if NetMode
= NET_SERVER
116 then g_Net_Host_Update();
120 function ProcessMessage (): Boolean;
124 result
:= sys_HandleInput();
126 Time
:= sys_GetTicks();
127 Time_Delta
:= Time
-Time_Old
;
131 if wNeedTimeReset
then
135 wNeedTimeReset
:= false;
138 g_Map_ProfilersBegin();
139 g_Mons_ProfilersBegin();
141 t
:= Time_Delta
div 28;
149 g_Map_ProfilersEnd();
150 g_Mons_ProfilersEnd();
158 if (gExit
= EXIT_QUIT
) then
164 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ
166 Time_Old
:= Time
- (Time_Delta
mod 28);
168 // don't wait if VSync is on, GL already probably waits enough
170 flag
:= (Time
- Frame
>= gFrameTime
) or gVSync
;
174 if (not wMinimized
) then
176 if gPause
or (not gLerpActors
) or (gState
= STATE_FOLD
) then
179 gLerpFactor
:= nmin(1.0, (Time
- Time_Old
) / 28.0);
191 function GLExtensionList (): SSArray
;
197 s
:= glGetString(GL_EXTENSIONS
);
203 while (s
[i
] <> #0) and (s
[i
] = ' ') do Inc(i
);
204 while (s
[i
] <> #0) do
206 while (s
[i
] <> #0) and (s
[i
] <> ' ') do Inc(i
);
207 SetLength(result
, num
+1);
208 result
[num
] := Copy(s
, j
+1, i
-j
);
209 while (s
[i
] <> #0) and (s
[i
] = ' ') do Inc(i
);
216 function GLExtensionSupported (ext
: AnsiString): Boolean;
222 exts
:= GLExtensionList();
225 //writeln('<', e, '> : [', ext, '] = ', strEquCI1251(e, ext));
226 if (strEquCI1251(e
, ext
)) then begin result
:= true; exit
; end;
230 procedure PrintGLSupportedExtensions
;
232 e_LogWritefln('GL Vendor: %s', [glGetString(GL_VENDOR
)]);
233 e_LogWritefln('GL Renderer: %s', [glGetString(GL_RENDERER
)]);
234 e_LogWritefln('GL Version: %s', [glGetString(GL_VERSION
)]);
235 e_LogWritefln('GL Shaders: %s', [glGetString(GL_SHADING_LANGUAGE_VERSION
)]);
236 e_LogWritefln('GL Extensions: %s', [glGetString(GL_EXTENSIONS
)]);
239 function SDLMain (): Integer;
244 {$IFDEF ENABLE_HOLMES}
250 e_NoGraphics
:= true;
254 while (idx
<= ParamCount
) do
256 arg
:= ParamStr(idx
);
258 if arg
= '--jah' then g_profile_history_size
:= 100;
259 if arg
= '--no-particles' then gpart_dbg_enabled
:= false;
260 if arg
= '--no-los' then gmon_dbg_los_enabled
:= false;
262 if arg
= '--profile-render' then g_profile_frame_draw
:= true;
263 if arg
= '--profile-coldet' then g_profile_collision
:= true;
264 if arg
= '--profile-los' then g_profile_los
:= true;
266 if arg
= '--no-part-phys' then gpart_dbg_phys_enabled
:= false;
267 if arg
= '--no-part-physics' then gpart_dbg_phys_enabled
:= false;
268 if arg
= '--no-particles-phys' then gpart_dbg_phys_enabled
:= false;
269 if arg
= '--no-particles-physics' then gpart_dbg_phys_enabled
:= false;
270 if arg
= '--no-particle-phys' then gpart_dbg_phys_enabled
:= false;
271 if arg
= '--no-particle-physics' then gpart_dbg_phys_enabled
:= false;
273 if arg
= '--debug-input' then g_dbg_input
:= True;
275 {.$IF DEFINED(D2F_DEBUG)}
276 if arg
= '--aimline' then g_dbg_aimline_on
:= true;
279 {$IFDEF ENABLE_HOLMES}
280 if arg
= '--holmes' then begin g_holmes_enabled
:= true; g_Game_SetDebugMode(); end;
282 if (arg
= '--holmes-ui-scale') or (arg
= '-holmes-ui-scale') then
284 if (idx
<= ParamCount
) then
286 if not conParseFloat(fuiRenderScale
, ParamStr(idx
)) then fuiRenderScale
:= 1.0;
291 if (arg
= '--holmes-font') or (arg
= '-holmes-font') then
293 if (idx
<= ParamCount
) then
296 val(ParamStr(idx
), itmp
, valres
);
298 if (valres
= 0) and (not g_holmes_imfunctional
) then
301 8: uiContext
.font
:= 'win8';
302 14: uiContext
.font
:= 'win14';
303 16: uiContext
.font
:= 'win16';
316 if (arg
= '--game-scale') or (arg
= '-game-scale') then
318 if (idx
<= ParamCount
) then
320 if not conParseFloat(g_dbg_scale
, ParamStr(idx
)) then g_dbg_scale
:= 1.0;
325 if (arg
= '--write-mapdef') or (arg
= '-write-mapdef') then
327 mdfo
:= createDiskFile('mapdef.txt');
328 mdfo
.WriteBuffer(defaultMapDef
[1], Length(defaultMapDef
));
333 if (arg
= '--pixel-scale') or (arg
= '-pixel-scale') then
335 if (idx
<= ParamCount
) then
337 if not conParseFloat(r_pixel_scale
, ParamStr(idx
)) then r_pixel_scale
:= 1.0;
343 {$IFNDEF USE_SYSSTUB}
344 PrintGLSupportedExtensions
;
345 glLegacyNPOT
:= not (GLExtensionSupported('GL_ARB_texture_non_power_of_two') or GLExtensionSupported('GL_OES_texture_npot'));
347 glLegacyNPOT
:= False;
348 glRenderToFBO
:= False;
350 if glNPOTOverride
and glLegacyNPOT
then
352 glLegacyNPOT
:= true;
353 e_logWriteln('NPOT texture emulation: FORCED');
357 if (glLegacyNPOT
) then e_logWriteln('NPOT texture emulation: enabled')
358 else e_logWriteln('NPOT texture emulation: disabled');
362 Time_Old
:= sys_GetTicks();
364 g_Net_InitLowLevel();
367 if (ParamCount
> 0) then g_Game_Process_Params();
371 if (not gGameOn
) and gAskLanguage
then g_Menu_AskLanguage();
374 e_WriteLog('Entering the main loop', TMsgType
.Notify
);
377 while not ProcessMessage() do begin end;
379 g_Net_Slist_ShutdownAll();
383 g_Net_DeinitLowLevel();
389 conRegVar('d_input', @g_dbg_input
, '', '')