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 {$INCLUDE ../nogl/noGLuses.inc}
42 SysUtils
, Classes
, MAPDEF
, Math
,
43 e_graphics
, e_log
, e_texture
, g_main
,
44 g_console
, e_input
, g_options
, g_game
,
45 g_basic
, g_textures
, e_sound
, g_sound
, g_menu
, ENet
, g_net
,
46 g_map
, g_gfx
, g_monsters
, xprofiler
,
47 g_touch
, g_gui
, g_system
, g_netmaster
;
51 ProgressUpdateMSecs
= 35; //1;//100;
54 Time
, Time_Delta
, Time_Old
: Int64;
57 wNeedTimeReset
: Boolean = false;
58 wMinimized
: Boolean = false;
59 wLoadingQuit
: Boolean = false;
61 procedure ResetTimer ();
63 wNeedTimeReset
:= true;
68 prevLoadingUpdateTime
: UInt64 = 0;
71 procedure ProcessLoading (forceUpdate
: Boolean=false);
77 if sys_HandleInput() = True then
81 if not wMinimized
then
83 if not forceUpdate
then
85 stt
:= getTimeMilli();
86 forceUpdate
:= (stt
< prevLoadingUpdateTime
) or (stt
-prevLoadingUpdateTime
>= ProgressUpdateMSecs
);
91 e_SetRendertarget(True);
92 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
94 DrawMenuBackground('INTER');
95 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
99 e_SetRendertarget(False);
100 e_SetViewPort(0, 0, gWinSizeX
, gWinSizeY
);
101 e_BlitFramebuffer(gWinSizeX
, gWinSizeY
);
104 prevLoadingUpdateTime
:= getTimeMilli();
111 if NetMode
= NET_SERVER
then
117 if (NetMode
= NET_CLIENT
) and (NetState
<> NET_STATE_AUTH
) then g_Net_Client_UpdateWhileLoading();
122 function ProcessMessage (): Boolean;
126 result
:= sys_HandleInput();
128 Time
:= sys_GetTicks();
129 Time_Delta
:= Time
-Time_Old
;
133 if wNeedTimeReset
then
137 wNeedTimeReset
:= false;
140 g_Map_ProfilersBegin();
141 g_Mons_ProfilersBegin();
143 t
:= Time_Delta
div 28;
151 g_Map_ProfilersEnd();
152 g_Mons_ProfilersEnd();
160 if (gExit
= EXIT_QUIT
) then
166 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ
168 Time_Old
:= Time
- (Time_Delta
mod 28);
170 // don't wait if VSync is on, GL already probably waits enough
172 flag
:= (Time
- Frame
>= gFrameTime
) or gVSync
;
176 if (not wMinimized
) then
178 if gPause
or (not gLerpActors
) or (gState
= STATE_FOLD
) then
181 gLerpFactor
:= nmin(1.0, (Time
- Time_Old
) / 28.0);
193 function GLExtensionList (): SSArray
;
199 s
:= glGetString(GL_EXTENSIONS
);
205 while (s
[i
] <> #0) and (s
[i
] = ' ') do Inc(i
);
206 while (s
[i
] <> #0) do
208 while (s
[i
] <> #0) and (s
[i
] <> ' ') do Inc(i
);
209 SetLength(result
, num
+1);
210 result
[num
] := Copy(s
, j
+1, i
-j
);
211 while (s
[i
] <> #0) and (s
[i
] = ' ') do Inc(i
);
218 function GLExtensionSupported (ext
: AnsiString): Boolean;
224 exts
:= GLExtensionList();
227 //writeln('<', e, '> : [', ext, '] = ', strEquCI1251(e, ext));
228 if (strEquCI1251(e
, ext
)) then begin result
:= true; exit
; end;
232 procedure PrintGLSupportedExtensions
;
234 e_LogWritefln('GL Vendor: %s', [glGetString(GL_VENDOR
)]);
235 e_LogWritefln('GL Renderer: %s', [glGetString(GL_RENDERER
)]);
236 e_LogWritefln('GL Version: %s', [glGetString(GL_VERSION
)]);
237 e_LogWritefln('GL Shaders: %s', [glGetString(GL_SHADING_LANGUAGE_VERSION
)]);
238 e_LogWritefln('GL Extensions: %s', [glGetString(GL_EXTENSIONS
)]);
241 function SDLMain (): Integer;
246 {$IFDEF ENABLE_HOLMES}
252 e_NoGraphics
:= true;
256 while (idx
<= ParamCount
) do
258 arg
:= ParamStr(idx
);
260 if arg
= '--opengl-dump-exts' then gwin_dump_extensions
:= true;
261 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
262 if arg
= '--jah' then g_profile_history_size
:= 100;
263 if arg
= '--no-particles' then gpart_dbg_enabled
:= false;
264 if arg
= '--no-los' then gmon_dbg_los_enabled
:= false;
266 if arg
= '--profile-render' then g_profile_frame_draw
:= true;
267 if arg
= '--profile-coldet' then g_profile_collision
:= true;
268 if arg
= '--profile-los' then g_profile_los
:= true;
270 if arg
= '--no-part-phys' then gpart_dbg_phys_enabled
:= false;
271 if arg
= '--no-part-physics' then gpart_dbg_phys_enabled
:= false;
272 if arg
= '--no-particles-phys' then gpart_dbg_phys_enabled
:= false;
273 if arg
= '--no-particles-physics' then gpart_dbg_phys_enabled
:= false;
274 if arg
= '--no-particle-phys' then gpart_dbg_phys_enabled
:= false;
275 if arg
= '--no-particle-physics' then gpart_dbg_phys_enabled
:= false;
277 if arg
= '--debug-input' then g_dbg_input
:= True;
279 {.$IF DEFINED(D2F_DEBUG)}
280 if arg
= '--aimline' then g_dbg_aimline_on
:= true;
283 {$IFDEF ENABLE_HOLMES}
284 if arg
= '--holmes' then begin g_holmes_enabled
:= true; g_Game_SetDebugMode(); end;
286 if (arg
= '--holmes-ui-scale') or (arg
= '-holmes-ui-scale') then
288 if (idx
<= ParamCount
) then
290 if not conParseFloat(fuiRenderScale
, ParamStr(idx
)) then fuiRenderScale
:= 1.0;
295 if (arg
= '--holmes-font') or (arg
= '-holmes-font') then
297 if (idx
<= ParamCount
) then
300 val(ParamStr(idx
), itmp
, valres
);
302 if (valres
= 0) and (not g_holmes_imfunctional
) then
305 8: uiContext
.font
:= 'win8';
306 14: uiContext
.font
:= 'win14';
307 16: uiContext
.font
:= 'win16';
320 if (arg
= '--game-scale') or (arg
= '-game-scale') then
322 if (idx
<= ParamCount
) then
324 if not conParseFloat(g_dbg_scale
, ParamStr(idx
)) then g_dbg_scale
:= 1.0;
329 if (arg
= '--write-mapdef') or (arg
= '-write-mapdef') then
331 mdfo
:= createDiskFile('mapdef.txt');
332 mdfo
.WriteBuffer(defaultMapDef
[1], Length(defaultMapDef
));
337 if (arg
= '--pixel-scale') or (arg
= '-pixel-scale') then
339 if (idx
<= ParamCount
) then
341 if not conParseFloat(r_pixel_scale
, ParamStr(idx
)) then r_pixel_scale
:= 1.0;
347 {$IFNDEF USE_SYSSTUB}
348 PrintGLSupportedExtensions
;
349 glLegacyNPOT
:= not (GLExtensionSupported('GL_ARB_texture_non_power_of_two') or GLExtensionSupported('GL_OES_texture_npot'));
351 glLegacyNPOT
:= False;
352 glRenderToFBO
:= False;
354 if glNPOTOverride
and glLegacyNPOT
then
356 glLegacyNPOT
:= true;
357 e_logWriteln('NPOT texture emulation: FORCED');
361 if (glLegacyNPOT
) then e_logWriteln('NPOT texture emulation: enabled')
362 else e_logWriteln('NPOT texture emulation: disabled');
364 gwin_dump_extensions
:= false;
367 Time_Old
:= sys_GetTicks();
369 g_Net_InitLowLevel();
372 if (ParamCount
> 0) then g_Game_Process_Params();
376 if (not gGameOn
) and gAskLanguage
then g_Menu_AskLanguage();
379 e_WriteLog('Entering the main loop', TMsgType
.Notify
);
382 while not ProcessMessage() do begin end;
384 g_Net_Slist_ShutdownAll();
388 g_Net_DeinitLowLevel();
394 conRegVar('d_input', @g_dbg_input
, '', '')