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, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
24 function SDLMain (): Integer;
25 function GetTimer (): Int64;
26 procedure ResetTimer ();
27 procedure PushExitEvent ();
28 function ProcessMessage (): Boolean;
29 procedure ReDrawWindow ();
30 procedure SwapBuffers ();
31 procedure Sleep (ms
: LongWord
);
32 function GetDisplayModes (dbpp
: LongWord
; var selres
: LongWord
): SSArray
;
33 function g_Window_SetDisplay (preserveGL
: Boolean=false): Boolean;
34 function g_Window_SetSize (w
, h
: Word; fullscreen
: Boolean): Boolean;
35 procedure g_SetVSync (vsync
: Boolean);
37 procedure ProcessLoading (forceUpdate
: Boolean=false);
39 // returns `true` if quit event was received
40 function g_ProcessMessages (): Boolean;
44 gwin_dump_extensions
: Boolean = false;
45 gwin_has_stencil
: Boolean = false;
46 gwin_k8_enable_light_experiments
: Boolean = false;
47 g_dbg_aimline_on
: Boolean = false;
53 {$IFDEF WINDOWS}Windows
,{$ENDIF}
54 {$INCLUDE ../nogl/noGLuses.inc}
55 {$IFDEF ENABLE_HOLMES}
56 g_holmes
, sdlcarcass
, fui_ctls
,
58 SysUtils
, Classes
, MAPDEF
,
59 SDL2
, e_graphics
, e_log
, e_texture
, g_main
,
60 g_console
, e_input
, g_options
, g_game
,
61 g_basic
, g_textures
, e_sound
, g_sound
, g_menu
, ENet
, g_net
,
62 g_map
, g_gfx
, g_monsters
, xprofiler
,
67 ProgressUpdateMSecs
= 1;//100;
70 h_Wnd
: PSDL_Window
= nil;
71 h_GL
: TSDL_GLContext
= nil;
72 Time
, Time_Delta
, Time_Old
: Int64;
74 {$IF not DEFINED(HEADLESS)}
76 wasFullscreen
: Boolean = true; // so we need to recreate the window
78 wNeedTimeReset
: Boolean = false;
79 wMinimized
: Boolean = false;
80 wMaximized
: Boolean = false;
81 wLoadingProgress
: Boolean = false;
82 wLoadingQuit
: Boolean = false;
84 ticksOverflow
: Int64 = -1;
85 lastTicks
: Uint32
= 0; // to detect overflow
89 procedure KillGLWindow (preserveGL
: Boolean);
91 {$IFDEF ENABLE_HOLMES}
92 if (h_GL
<> nil) and (not preserveGL
) then begin if (assigned(oglDeinitCB
)) then oglDeinitCB(); end;
94 if (h_Wnd
<> nil) then SDL_DestroyWindow(h_Wnd
);
95 if (h_GL
<> nil) and (not preserveGL
) then
106 SDL_GL_DeleteContext(h_GL
);
109 if (not preserveGL
) then h_GL
:= nil;
113 function g_Window_SetDisplay (preserveGL
: Boolean = false): Boolean;
114 {$IF not DEFINED(HEADLESS)}
116 mode
, cmode
: TSDL_DisplayMode
;
117 wFlags
: LongWord
= 0;
121 {$IF not DEFINED(HEADLESS)}
124 e_WriteLog('Setting display mode...', TMsgType
.Notify
);
126 wFlags
:= SDL_WINDOW_OPENGL
{or SDL_WINDOW_RESIZABLE};
127 if gFullscreen
then wFlags
:= wFlags
{or SDL_WINDOW_FULLSCREEN} else wFlags
:= wFlags
or SDL_WINDOW_RESIZABLE
;
128 if (not gFullscreen
) and (not preserveGL
) and gWinMaximized
then wFlags
:= wFlags
or SDL_WINDOW_MAXIMIZED
else gWinMaximized
:= false;
132 mode
.w
:= gScreenWidth
;
133 mode
.h
:= gScreenHeight
;
135 mode
.refresh_rate
:= 0;
136 mode
.driverdata
:= nil;
137 if (SDL_GetClosestDisplayMode(0, @mode
, @cmode
) = nil) then
139 e_WriteLog('SDL: cannot find display mode for '+IntToStr(gScreenWidth
), TMsgType
.Notify
);
141 gScreenHeight
:= 600;
145 e_WriteLog('SDL: found display mode for '+IntToStr(gScreenWidth
)+'x'+IntToStr(gScreenHeight
)+': '+IntToStr(cmode
.w
)+'x'+IntToStr(cmode
.h
), TMsgType
.Notify
);
146 gScreenWidth
:= cmode
.w
;
147 gScreenHeight
:= cmode
.h
;
151 if (preserveGL
) and (h_Wnd
<> nil) and (not gFullscreen
) and (not wasFullscreen
) then
153 //SDL_SetWindowMaximumSize(h_Wnd, gScreenWidth, gScreenHeight);
154 //SDL_SetWindowDisplayMode(h_Wnd, @cmode);
155 if (wMaximized
) then SDL_RestoreWindow(h_Wnd
);
157 gWinMaximized
:= false;
158 SDL_SetWindowSize(h_Wnd
, gScreenWidth
, gScreenHeight
);
159 //SDL_SetWindowFullscreen(h_Wnd, SDL_WINDOW_FULLSCREEN);
160 //SDL_SetWindowFullscreen(h_Wnd, 0);
164 KillGLWindow(preserveGL
);
165 h_Wnd
:= SDL_CreateWindow(PChar(wTitle
), gWinRealPosX
, gWinRealPosY
, gScreenWidth
, gScreenHeight
, wFlags
);
167 SDL_SetWindowFullscreen(h_Wnd
, SDL_WINDOW_FULLSCREEN
);
168 if (h_Wnd
= nil) then exit
;
170 wasFullscreen
:= gFullscreen
;
172 SDL_GL_MakeCurrent(h_Wnd
, h_GL
);
173 SDL_ShowCursor(SDL_DISABLE
);
174 if (h_GL
<> nil) then g_SetVSync(gVSync
);
175 if (gFullscreen
) then
179 SDL_GetWindowSize(h_Wnd
, @nw
, @nh
);
180 if (nw
> 128) and (nh
> 128) then
182 e_WriteLog('SDL: fullscreen window got size '+IntToStr(nw
)+'x'+IntToStr(nh
)+': '+IntToStr(gScreenWidth
)+'x'+IntToStr(gScreenHeight
), TMsgType
.Notify
);
188 e_WriteLog('SDL: fullscreen window got invalid size: '+IntToStr(nw
)+'x'+IntToStr(nh
), TMsgType
.Notify
);
192 {$IFDEF ENABLE_HOLMES}
193 fuiScrWdt
:= gScreenWidth
;
194 fuiScrHgt
:= gScreenHeight
;
195 if (h_GL
<> nil) and (not preserveGL
) then begin if (assigned(oglInitCB
)) then oglInitCB(); end;
203 function GetDisplayModes (dbpp
: LongWord
; var selres
: LongWord
): SSArray
;
205 mode
: TSDL_DisplayMode
;
206 res
, i
, k
, n
, pw
, ph
: Integer;
208 SetLength(result
, 0);
209 {$IFDEF HEADLESS}exit
;{$ENDIF}
211 n
:= SDL_GetNumDisplayModes(0);
215 res
:= SDL_GetDisplayMode(0, i
, @mode
);
216 if res
< 0 then continue
;
217 if SDL_BITSPERPIXEL(mode
.format
) = gBPP
then continue
;
218 if (mode
.w
= pw
) and (mode
.h
= ph
) then continue
;
219 if (mode
.w
= gScreenWidth
) and (mode
.h
= gScreenHeight
) then
222 SetLength(result
, k
);
223 result
[k
-1] := IntToStr(mode
.w
) + 'x' + IntToStr(mode
.h
);
224 pw
:= mode
.w
; ph
:= mode
.h
227 e_WriteLog('SDL: Got ' + IntToStr(k
) + ' resolutions.', TMsgType
.Notify
);
231 procedure Sleep (ms
: LongWord
);
237 procedure ChangeWindowSize ();
239 e_LogWritefln(' ChangeWindowSize: (ws=%dx%d) (ss=%dx%d)', [gWinSizeX
, gWinSizeY
, gScreenWidth
, gScreenHeight
]);
240 gWinSizeX
:= gScreenWidth
;
241 gWinSizeY
:= gScreenHeight
;
242 {$IF not DEFINED(HEADLESS)}
243 {$IFDEF ENABLE_HOLMES}
244 fuiScrWdt
:= gScreenWidth
;
245 fuiScrHgt
:= gScreenHeight
;
247 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
248 g_Game_SetupScreenSize();
250 g_Game_ClearLoading();
255 function g_Window_SetSize (w
, h
: Word; fullscreen
: Boolean): Boolean;
256 {$IF not DEFINED(HEADLESS)}
262 {$IF not DEFINED(HEADLESS)}
265 if (gScreenWidth
<> w
) or (gScreenHeight
<> h
) then
273 if (gFullscreen
<> fullscreen
) then
277 gFullscreen
:= fullscreen
;
283 g_Window_SetDisplay(preserve
);
290 function WindowEventHandler (constref ev
: TSDL_WindowEvent
): Boolean;
292 wActivate
, wDeactivate
: Boolean;
296 wDeactivate
:= false;
299 SDL_WINDOWEVENT_MOVED
:
301 if not (gFullscreen
or gWinMaximized
) then
303 gWinRealPosX
:= ev
.data1
;
304 gWinRealPosY
:= ev
.data2
;
308 SDL_WINDOWEVENT_MINIMIZED
:
311 if not wMinimized
then
313 e_ResizeWindow(0, 0);
315 if g_debug_WinMsgs
then
317 g_Console_Add('Now minimized');
318 e_WriteLog('[DEBUG] WinMsgs: Now minimized', TMsgType
.Notify
);
324 SDL_WINDOWEVENT_RESIZED
:
326 e_LogWritefln('Resize: (os=%dx%d) (ns=%dx%d)', [gScreenWidth
, gScreenHeight
, Integer(ev
.data1
), Integer(ev
.data2
)]);
327 {if (gFullscreen) then
329 e_LogWriteln(' fullscreen fix applied.');
330 if (gScreenWidth <> ev.data1) or (gScreenHeight <> ev.data2) then
332 SDL_SetWindowSize(h_Wnd, gScreenWidth, gScreenHeight);
337 gScreenWidth
:= ev
.data1
;
338 gScreenHeight
:= ev
.data2
;
342 if g_debug_WinMsgs
then
344 g_Console_Add('Resized to ' + IntToStr(ev
.data1
) + 'x' + IntToStr(ev
.data2
));
345 e_WriteLog('[DEBUG] WinMsgs: Resized to ' + IntToStr(ev
.data1
) + 'x' + IntToStr(ev
.data2
), TMsgType
.Notify
);
349 SDL_WINDOWEVENT_EXPOSED
:
352 SDL_WINDOWEVENT_MAXIMIZED
:
357 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
361 if (not gWinMaximized
) and (not gFullscreen
) then
363 gWinMaximized
:= true;
364 if g_debug_WinMsgs
then
366 g_Console_Add('Now maximized');
367 e_WriteLog('[DEBUG] WinMsgs: Now maximized', TMsgType
.Notify
);
372 SDL_WINDOWEVENT_RESTORED
:
377 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
381 gWinMaximized
:= false;
382 if g_debug_WinMsgs
then
384 g_Console_Add('Now restored');
385 e_WriteLog('[DEBUG] WinMsgs: Now restored', TMsgType
.Notify
);
389 SDL_WINDOWEVENT_FOCUS_GAINED
:
392 //e_WriteLog('window gained focus!', MSG_NOTIFY);
395 SDL_WINDOWEVENT_FOCUS_LOST
:
399 //e_WriteLog('window lost focus!', MSG_NOTIFY);
407 e_WriteLog('deactivating window', TMsgType
.Notify
);
408 e_EnableInput
:= false;
409 e_ClearInputBuffer();
411 if gMuteWhenInactive
then
413 //e_WriteLog('deactivating sounds', MSG_NOTIFY);
414 e_MuteChannels(true);
417 if g_debug_WinMsgs
then
419 g_Console_Add('Now inactive');
420 e_WriteLog('[DEBUG] WinMsgs: Now inactive', TMsgType
.Notify
);
425 {$IFDEF ENABLE_HOLMES}
426 if assigned(winBlurCB
) then winBlurCB();
430 else if wActivate
then
432 if not gWinActive
then
434 //e_WriteLog('activating window', MSG_NOTIFY);
435 e_EnableInput
:= true;
437 if gMuteWhenInactive
then
439 //e_WriteLog('activating sounds', MSG_NOTIFY);
440 e_MuteChannels(false);
443 if g_debug_WinMsgs
then
445 g_Console_Add('Now active');
446 e_WriteLog('[DEBUG] WinMsgs: Now active', TMsgType
.Notify
);
451 {$IFDEF ENABLE_HOLMES}
452 if assigned(winFocusCB
) then winFocusCB();
459 function EventHandler (var ev
: TSDL_Event
): Boolean;
469 result
:= WindowEventHandler(ev
.window
);
473 if (gExit
<> EXIT_QUIT
) then
475 if not wLoadingProgress
then
482 wLoadingQuit
:= true;
488 SDL_KEYDOWN
, SDL_KEYUP
:
490 key
:= ev
.key
.keysym
.scancode
;
491 if key
= SDL_SCANCODE_AC_BACK
then
492 key
:= SDL_SCANCODE_ESCAPE
;
493 down
:= (ev
.type_
= SDL_KEYDOWN
);
494 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
495 if fuiOnSDLEvent(ev
) then
497 // event eaten, but...
498 if not down
then e_KeyUpDown(key
, false);
502 e_KeyUpDown(key
, down
);
503 if down
then KeyPress(key
);
506 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
507 SDL_MOUSEBUTTONDOWN
, SDL_MOUSEBUTTONUP
, SDL_MOUSEWHEEL
, SDL_MOUSEMOTION
:
513 Utf8ToUnicode(@uc
, PChar(ev
.text.text), 1);
515 if (keychr
> 127) then keychr
:= Word(wchar2win(WideChar(keychr
)));
516 if (keychr
> 0) and (keychr
<= 255) then CharPress(AnsiChar(keychr
));
519 SDL_FINGERMOTION
, SDL_FINGERDOWN
, SDL_FINGERUP
:
520 g_Touch_HandleEvent(ev
.tfinger
);
522 // other key presses and joysticks are handled in e_input
527 procedure SwapBuffers ();
529 {$IF not DEFINED(HEADLESS)}
530 SDL_GL_SwapWindow(h_Wnd
);
535 function CreateGLWindow (Title
: PChar
): Boolean;
539 gWinSizeX
:= gScreenWidth
;
540 gWinSizeY
:= gScreenHeight
;
542 {$IF not DEFINED(HEADLESS)}
545 e_WriteLog('Creating window', TMsgType
.Notify
);
547 if not g_Window_SetDisplay() then
550 e_WriteLog('Window creation error (resolution not supported?)', TMsgType
.Fatal
);
554 {$IF not DEFINED(HEADLESS)}
555 h_GL
:= SDL_GL_CreateContext(h_Wnd
);
556 if (h_GL
= nil) then exit
;
557 {$IFDEF ENABLE_HOLMES}
558 fuiScrWdt
:= gScreenWidth
;
559 fuiScrHgt
:= gScreenHeight
;
561 SDL_GL_MakeCurrent(h_Wnd
, h_GL
);
563 if nanoGL_Init() = 0 then
566 e_WriteLog('nanoGL initialization error', TMsgType
.Fatal
);
573 {$IFDEF ENABLE_HOLMES}
574 if (assigned(oglInitCB
)) then oglInitCB();
576 if (h_GL
<> nil) then g_SetVSync(gVSync
);
579 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
587 // windoze sux; in headless mode `GetTickCount()` (and SDL) returns shit
588 function GetTimer (): Int64;
592 QueryPerformanceFrequency(F
);
593 QueryPerformanceCounter(C
);
594 result
:= Round(C
/F
*1000{000});
597 function GetTimer (): Int64;
603 if (ticksOverflow
= -1) then
610 if (lastTicks
> t
) then
612 // overflow, increment overflow ;-)
613 ticksOverflow
:= ticksOverflow
+(Int64($ffffffff)+Int64(1));
614 tt
:= (Int64($ffffffff)+Int64(1))+Int64(t
);
615 t
:= Uint32(tt
-lastTicks
);
619 result
:= ticksOverflow
+Int64(t
);
624 procedure ResetTimer ();
626 wNeedTimeReset
:= true;
630 procedure PushExitEvent ();
634 ev
.type_
:= SDL_QUITEV
;
640 prevLoadingUpdateTime
: UInt64
= 0;
642 procedure ProcessLoading (forceUpdate
: Boolean=false);
648 FillChar(ev
, sizeof(ev
), 0);
649 wLoadingProgress
:= true;
651 while (SDL_PollEvent(@ev
) > 0) do
654 if (ev
.type_
= SDL_QUITEV
) then break
;
658 if (ev
.type_
= SDL_QUITEV
) or (gExit
= EXIT_QUIT
) then
660 wLoadingProgress
:= false;
664 if not wMinimized
then
668 prevLoadingUpdateTime
:= getTimeMilli();
672 stt
:= getTimeMilli();
673 if (stt
< prevLoadingUpdateTime
) or (stt
-prevLoadingUpdateTime
>= ProgressUpdateMSecs
) then
675 prevLoadingUpdateTime
:= stt
;
682 if g_Texture_Get('INTER', ID
) then
684 e_DrawSize(ID
, 0, 0, 0, false, false, gScreenWidth
, gScreenHeight
);
685 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
689 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
699 if NetMode
= NET_SERVER
then
705 if (NetMode
= NET_CLIENT
) and (NetState
<> NET_STATE_AUTH
) then g_Net_Client_UpdateWhileLoading();
708 wLoadingProgress
:= false;
712 function g_ProcessMessages (): Boolean;
717 FillChar(ev
, SizeOf(ev
), 0);
718 while (SDL_PollEvent(@ev
) > 0) do
720 result
:= EventHandler(ev
);
721 if (ev
.type_
= SDL_QUITEV
) then exit
;
727 function ProcessMessage (): Boolean;
731 result
:= g_ProcessMessages();
734 Time_Delta
:= Time
-Time_Old
;
738 if wNeedTimeReset
then
741 wNeedTimeReset
:= false;
744 g_Map_ProfilersBegin();
745 g_Mons_ProfilersBegin();
747 t
:= Time_Delta
div 28;
753 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
754 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
760 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
761 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
764 g_Map_ProfilersEnd();
765 g_Mons_ProfilersEnd();
773 if (gExit
= EXIT_QUIT
) then
779 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ
782 Time_Old
:= Time
-(Time_Delta
mod 28);
783 if (not wMinimized
) then
791 Sleep(1); // release time slice, so we won't eat 100% CPU
798 procedure ReDrawWindow ();
804 procedure g_SetVSync (vsync
: Boolean);
805 {$IF not DEFINED(HEADLESS)}
810 {$IF not DEFINED(HEADLESS)}
811 if vsync
then v
:= 1 else v
:= 0;
812 if (SDL_GL_SetSwapInterval(v
) <> 0) then
814 e_WriteLog('oops; can''t change vsync option, restart required', TMsgType
.Warning
);
818 if vsync
then e_WriteLog('VSync: ON', TMsgType
.Notify
) else e_WriteLog('VSync: OFF', TMsgType
.Notify
);
824 procedure InitOpenGL ();
826 {$IF not DEFINED(HEADLESS)}
828 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION
, 1);
829 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION
, 1);
830 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK
, SDL_GL_CONTEXT_PROFILE_ES
);
832 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION
, 2);
833 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION
, 1);
834 SDL_GL_SetAttribute(SDL_GL_RED_SIZE
, 8);
835 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE
, 8);
836 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE
, 8);
837 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE
, 16);
838 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER
, 1);
839 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE
, 8); // lights; it is enough to have 1-bit stencil buffer for lighting, but...
845 function glHasExtension (const name
: AnsiString
): Boolean;
850 extName
: ShortString
;
853 if (Length(name
) = 0) then exit
;
854 exts
:= glGetString(GL_EXTENSIONS
);
855 if (exts
= nil) then exit
;
856 while (exts
[0] <> #0) and (exts
[0] = ' ') do Inc(exts
);
857 while (exts
[0] <> #0) do
859 if gwin_dump_extensions
then
862 while (exts
[i
] <> #0) and (exts
[i
] <> ' ') do Inc(i
);
865 e_WriteLog('FUUUUUUUUUUUUU', TMsgType
.Warning
);
869 Move(exts
^, extName
[1], i
);
870 extName
[0] := Char(i
);
871 e_WriteLog(Format('EXT: %s', [extName
]), TMsgType
.Notify
);
875 for i
:= 0 to length(name
)-1 do
877 if (exts
[i
] = #0) then begin found
:= false; break
; end;
878 if (exts
[i
] <> name
[i
+1]) then begin found
:= false; break
; end;
880 if found
and ((exts
[Length(name
)] = #0) or (exts
[Length(name
)] = ' ')) then begin result
:= true; exit
; end;
881 while (exts
[0] <> #0) and (exts
[0] <> ' ') do Inc(exts
);
882 while (exts
[0] <> #0) and (exts
[0] = ' ') do Inc(exts
);
887 function SDLMain (): Integer;
890 {$IF not DEFINED(HEADLESS)}
899 e_NoGraphics
:= true;
901 {$IFDEF ENABLE_HOLMES}
902 if (not g_holmes_imfunctional
) then
905 uiContext
.font
:= 'win14';
911 while (idx
<= ParamCount
) do
913 arg
:= ParamStr(idx
);
915 if arg
= '--opengl-dump-exts' then gwin_dump_extensions
:= true;
916 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
917 if arg
= '--jah' then g_profile_history_size
:= 100;
918 if arg
= '--no-particles' then gpart_dbg_enabled
:= false;
919 if arg
= '--no-los' then gmon_dbg_los_enabled
:= false;
921 if arg
= '--profile-render' then g_profile_frame_draw
:= true;
922 if arg
= '--profile-coldet' then g_profile_collision
:= true;
923 if arg
= '--profile-los' then g_profile_los
:= true;
925 if arg
= '--no-part-phys' then gpart_dbg_phys_enabled
:= false;
926 if arg
= '--no-part-physics' then gpart_dbg_phys_enabled
:= false;
927 if arg
= '--no-particles-phys' then gpart_dbg_phys_enabled
:= false;
928 if arg
= '--no-particles-physics' then gpart_dbg_phys_enabled
:= false;
929 if arg
= '--no-particle-phys' then gpart_dbg_phys_enabled
:= false;
930 if arg
= '--no-particle-physics' then gpart_dbg_phys_enabled
:= false;
932 {.$IF DEFINED(D2F_DEBUG)}
933 if arg
= '--aimline' then g_dbg_aimline_on
:= true;
936 {$IFDEF ENABLE_HOLMES}
937 if arg
= '--holmes' then begin g_holmes_enabled
:= true; g_Game_SetDebugMode(); end;
939 if (arg
= '--holmes-ui-scale') or (arg
= '-holmes-ui-scale') then
941 if (idx
<= ParamCount
) then
943 if not conParseFloat(fuiRenderScale
, ParamStr(idx
)) then fuiRenderScale
:= 1.0;
948 if (arg
= '--holmes-font') or (arg
= '-holmes-font') then
950 if (idx
<= ParamCount
) then
953 val(ParamStr(idx
), itmp
, valres
);
955 if (valres
= 0) and (not g_holmes_imfunctional
) then
958 8: uiContext
.font
:= 'win8';
959 14: uiContext
.font
:= 'win14';
960 16: uiContext
.font
:= 'win16';
973 if (arg
= '--game-scale') or (arg
= '-game-scale') then
975 if (idx
<= ParamCount
) then
977 if not conParseFloat(g_dbg_scale
, ParamStr(idx
)) then g_dbg_scale
:= 1.0;
982 if (arg
= '--write-mapdef') or (arg
= '-write-mapdef') then
984 mdfo
:= createDiskFile('mapdef.txt');
985 mdfo
.WriteBuffer(defaultMapDef
[1], Length(defaultMapDef
));
991 e_WriteLog('Initializing OpenGL', TMsgType
.Notify
);
994 e_WriteLog('Creating GL window', TMsgType
.Notify
);
995 if not CreateGLWindow(PChar(Format('Doom 2D: Forever %s', [GAME_VERSION
]))) then
998 e_WriteLog('Unable to create GL window: ' + SDL_GetError(), TMsgType
.Fatal
);
1002 {EnumDisplayModes();}
1005 //gwin_k8_enable_light_experiments := false;
1006 gwin_has_stencil
:= false;
1007 glLegacyNPOT
:= false;
1008 gwin_dump_extensions
:= false;
1010 SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE
, @ltmp
);
1011 e_LogWritefln('stencil buffer size: %s', [ltmp
]);
1012 gwin_has_stencil
:= (ltmp
> 0);
1014 if not glHasExtension('GL_ARB_texture_non_power_of_two') then
1016 e_WriteLog('NPOT textures: NO', TMsgType
.Warning
);
1017 glLegacyNPOT
:= true;
1021 e_WriteLog('NPOT textures: YES', TMsgType
.Notify
);
1022 glLegacyNPOT
:= false;
1024 gwin_dump_extensions
:= false;
1028 Time_Old
:= GetTimer();
1031 if (ParamCount
> 0) then g_Game_Process_Params();
1034 if (not gGameOn
) and gAskLanguage
then g_Menu_AskLanguage();
1036 e_WriteLog('Entering the main loop', TMsgType
.Notify
);
1039 while not ProcessMessage() do begin end;
1042 KillGLWindow(false);