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 (requested
: Boolean);
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();
249 {$IF DEFINED(ANDROID)}
250 (* This will fix menu reset on keyboard showing *)
256 g_Game_ClearLoading();
261 function g_Window_SetSize (w
, h
: Word; fullscreen
: Boolean): Boolean;
262 {$IF not DEFINED(HEADLESS)}
268 {$IF not DEFINED(HEADLESS)}
271 if (gScreenWidth
<> w
) or (gScreenHeight
<> h
) then
279 if (gFullscreen
<> fullscreen
) then
283 gFullscreen
:= fullscreen
;
289 g_Window_SetDisplay(preserve
);
290 ChangeWindowSize(true);
296 function WindowEventHandler (constref ev
: TSDL_WindowEvent
): Boolean;
298 wActivate
, wDeactivate
: Boolean;
302 wDeactivate
:= false;
305 SDL_WINDOWEVENT_MOVED
:
307 if not (gFullscreen
or gWinMaximized
) then
309 gWinRealPosX
:= ev
.data1
;
310 gWinRealPosY
:= ev
.data2
;
314 SDL_WINDOWEVENT_MINIMIZED
:
317 if not wMinimized
then
319 e_ResizeWindow(0, 0);
321 if g_debug_WinMsgs
then
323 g_Console_Add('Now minimized');
324 e_WriteLog('[DEBUG] WinMsgs: Now minimized', TMsgType
.Notify
);
330 SDL_WINDOWEVENT_RESIZED
:
332 e_LogWritefln('Resize: (os=%dx%d) (ns=%dx%d)', [gScreenWidth
, gScreenHeight
, Integer(ev
.data1
), Integer(ev
.data2
)]);
333 {if (gFullscreen) then
335 e_LogWriteln(' fullscreen fix applied.');
336 if (gScreenWidth <> ev.data1) or (gScreenHeight <> ev.data2) then
338 SDL_SetWindowSize(h_Wnd, gScreenWidth, gScreenHeight);
343 gScreenWidth
:= ev
.data1
;
344 gScreenHeight
:= ev
.data2
;
346 ChangeWindowSize(false);
348 if g_debug_WinMsgs
then
350 g_Console_Add('Resized to ' + IntToStr(ev
.data1
) + 'x' + IntToStr(ev
.data2
));
351 e_WriteLog('[DEBUG] WinMsgs: Resized to ' + IntToStr(ev
.data1
) + 'x' + IntToStr(ev
.data2
), TMsgType
.Notify
);
355 SDL_WINDOWEVENT_EXPOSED
:
358 SDL_WINDOWEVENT_MAXIMIZED
:
363 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
367 if (not gWinMaximized
) and (not gFullscreen
) then
369 gWinMaximized
:= true;
370 if g_debug_WinMsgs
then
372 g_Console_Add('Now maximized');
373 e_WriteLog('[DEBUG] WinMsgs: Now maximized', TMsgType
.Notify
);
378 SDL_WINDOWEVENT_RESTORED
:
383 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
387 gWinMaximized
:= false;
388 if g_debug_WinMsgs
then
390 g_Console_Add('Now restored');
391 e_WriteLog('[DEBUG] WinMsgs: Now restored', TMsgType
.Notify
);
395 SDL_WINDOWEVENT_FOCUS_GAINED
:
398 //e_WriteLog('window gained focus!', MSG_NOTIFY);
401 SDL_WINDOWEVENT_FOCUS_LOST
:
405 //e_WriteLog('window lost focus!', MSG_NOTIFY);
413 e_WriteLog('deactivating window', TMsgType
.Notify
);
414 e_EnableInput
:= false;
415 e_ClearInputBuffer();
417 if gMuteWhenInactive
then
419 //e_WriteLog('deactivating sounds', MSG_NOTIFY);
420 e_MuteChannels(true);
423 if g_debug_WinMsgs
then
425 g_Console_Add('Now inactive');
426 e_WriteLog('[DEBUG] WinMsgs: Now inactive', TMsgType
.Notify
);
431 {$IFDEF ENABLE_HOLMES}
432 if assigned(winBlurCB
) then winBlurCB();
436 else if wActivate
then
438 if not gWinActive
then
440 //e_WriteLog('activating window', MSG_NOTIFY);
441 e_EnableInput
:= true;
443 if gMuteWhenInactive
then
445 //e_WriteLog('activating sounds', MSG_NOTIFY);
446 e_MuteChannels(false);
449 if g_debug_WinMsgs
then
451 g_Console_Add('Now active');
452 e_WriteLog('[DEBUG] WinMsgs: Now active', TMsgType
.Notify
);
457 {$IFDEF ENABLE_HOLMES}
458 if assigned(winFocusCB
) then winFocusCB();
465 function EventHandler (var ev
: TSDL_Event
): Boolean;
475 result
:= WindowEventHandler(ev
.window
);
479 if (gExit
<> EXIT_QUIT
) then
481 if not wLoadingProgress
then
488 wLoadingQuit
:= true;
494 SDL_KEYDOWN
, SDL_KEYUP
:
496 key
:= ev
.key
.keysym
.scancode
;
497 if key
= SDL_SCANCODE_AC_BACK
then
498 key
:= SDL_SCANCODE_ESCAPE
;
499 down
:= (ev
.type_
= SDL_KEYDOWN
);
500 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
501 if fuiOnSDLEvent(ev
) then
503 // event eaten, but...
504 if not down
then e_KeyUpDown(key
, false);
508 e_KeyUpDown(key
, down
);
509 if down
then KeyPress(key
);
512 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
513 SDL_MOUSEBUTTONDOWN
, SDL_MOUSEBUTTONUP
, SDL_MOUSEWHEEL
, SDL_MOUSEMOTION
:
519 Utf8ToUnicode(@uc
, PChar(ev
.text.text), 1);
521 if (keychr
> 127) then keychr
:= Word(wchar2win(WideChar(keychr
)));
522 if (keychr
> 0) and (keychr
<= 255) then CharPress(AnsiChar(keychr
));
525 SDL_FINGERMOTION
, SDL_FINGERDOWN
, SDL_FINGERUP
:
526 g_Touch_HandleEvent(ev
.tfinger
);
528 // other key presses and joysticks are handled in e_input
533 procedure SwapBuffers ();
535 {$IF not DEFINED(HEADLESS)}
536 SDL_GL_SwapWindow(h_Wnd
);
541 function CreateGLWindow (Title
: PChar
): Boolean;
545 gWinSizeX
:= gScreenWidth
;
546 gWinSizeY
:= gScreenHeight
;
548 {$IF not DEFINED(HEADLESS)}
551 e_WriteLog('Creating window', TMsgType
.Notify
);
553 if not g_Window_SetDisplay() then
556 e_WriteLog('Window creation error (resolution not supported?)', TMsgType
.Fatal
);
560 {$IF not DEFINED(HEADLESS)}
561 h_GL
:= SDL_GL_CreateContext(h_Wnd
);
562 if (h_GL
= nil) then exit
;
563 {$IFDEF ENABLE_HOLMES}
564 fuiScrWdt
:= gScreenWidth
;
565 fuiScrHgt
:= gScreenHeight
;
567 SDL_GL_MakeCurrent(h_Wnd
, h_GL
);
569 if nanoGL_Init() = 0 then
572 e_WriteLog('nanoGL initialization error', TMsgType
.Fatal
);
579 {$IFDEF ENABLE_HOLMES}
580 if (assigned(oglInitCB
)) then oglInitCB();
582 if (h_GL
<> nil) then g_SetVSync(gVSync
);
585 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
593 // windoze sux; in headless mode `GetTickCount()` (and SDL) returns shit
594 function GetTimer (): Int64;
598 QueryPerformanceFrequency(F
);
599 QueryPerformanceCounter(C
);
600 result
:= Round(C
/F
*1000{000});
603 function GetTimer (): Int64;
609 if (ticksOverflow
= -1) then
616 if (lastTicks
> t
) then
618 // overflow, increment overflow ;-)
619 ticksOverflow
:= ticksOverflow
+(Int64($ffffffff)+Int64(1));
620 tt
:= (Int64($ffffffff)+Int64(1))+Int64(t
);
621 t
:= Uint32(tt
-lastTicks
);
625 result
:= ticksOverflow
+Int64(t
);
630 procedure ResetTimer ();
632 wNeedTimeReset
:= true;
636 procedure PushExitEvent ();
640 ev
.type_
:= SDL_QUITEV
;
646 prevLoadingUpdateTime
: UInt64
= 0;
648 procedure ProcessLoading (forceUpdate
: Boolean=false);
654 FillChar(ev
, sizeof(ev
), 0);
655 wLoadingProgress
:= true;
657 while (SDL_PollEvent(@ev
) > 0) do
660 if (ev
.type_
= SDL_QUITEV
) then break
;
664 if (ev
.type_
= SDL_QUITEV
) or (gExit
= EXIT_QUIT
) then
666 wLoadingProgress
:= false;
670 if not wMinimized
then
674 prevLoadingUpdateTime
:= getTimeMilli();
678 stt
:= getTimeMilli();
679 if (stt
< prevLoadingUpdateTime
) or (stt
-prevLoadingUpdateTime
>= ProgressUpdateMSecs
) then
681 prevLoadingUpdateTime
:= stt
;
688 if g_Texture_Get('INTER', ID
) then
690 e_DrawSize(ID
, 0, 0, 0, false, false, gScreenWidth
, gScreenHeight
);
691 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
695 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
705 if NetMode
= NET_SERVER
then
711 if (NetMode
= NET_CLIENT
) and (NetState
<> NET_STATE_AUTH
) then g_Net_Client_UpdateWhileLoading();
714 wLoadingProgress
:= false;
718 function g_ProcessMessages (): Boolean;
723 FillChar(ev
, SizeOf(ev
), 0);
724 while (SDL_PollEvent(@ev
) > 0) do
726 result
:= EventHandler(ev
);
727 if (ev
.type_
= SDL_QUITEV
) then exit
;
733 function ProcessMessage (): Boolean;
737 result
:= g_ProcessMessages();
740 Time_Delta
:= Time
-Time_Old
;
744 if wNeedTimeReset
then
747 wNeedTimeReset
:= false;
750 g_Map_ProfilersBegin();
751 g_Mons_ProfilersBegin();
753 t
:= Time_Delta
div 28;
759 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
760 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
766 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
767 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
770 g_Map_ProfilersEnd();
771 g_Mons_ProfilersEnd();
779 if (gExit
= EXIT_QUIT
) then
785 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ
788 Time_Old
:= Time
-(Time_Delta
mod 28);
789 if (not wMinimized
) then
797 Sleep(1); // release time slice, so we won't eat 100% CPU
804 procedure ReDrawWindow ();
810 procedure g_SetVSync (vsync
: Boolean);
811 {$IF not DEFINED(HEADLESS)}
816 {$IF not DEFINED(HEADLESS)}
817 if vsync
then v
:= 1 else v
:= 0;
818 if (SDL_GL_SetSwapInterval(v
) <> 0) then
820 e_WriteLog('oops; can''t change vsync option, restart required', TMsgType
.Warning
);
824 if vsync
then e_WriteLog('VSync: ON', TMsgType
.Notify
) else e_WriteLog('VSync: OFF', TMsgType
.Notify
);
830 procedure InitOpenGL ();
832 {$IF not DEFINED(HEADLESS)}
834 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION
, 1);
835 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION
, 1);
836 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK
, SDL_GL_CONTEXT_PROFILE_ES
);
838 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION
, 2);
839 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION
, 1);
840 SDL_GL_SetAttribute(SDL_GL_RED_SIZE
, 8);
841 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE
, 8);
842 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE
, 8);
843 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE
, 16);
844 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER
, 1);
845 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE
, 8); // lights; it is enough to have 1-bit stencil buffer for lighting, but...
851 function glHasExtension (const name
: AnsiString
): Boolean;
856 extName
: ShortString
;
859 if (Length(name
) = 0) then exit
;
860 exts
:= glGetString(GL_EXTENSIONS
);
861 if (exts
= nil) then exit
;
862 while (exts
[0] <> #0) and (exts
[0] = ' ') do Inc(exts
);
863 while (exts
[0] <> #0) do
865 if gwin_dump_extensions
then
868 while (exts
[i
] <> #0) and (exts
[i
] <> ' ') do Inc(i
);
871 e_WriteLog('FUUUUUUUUUUUUU', TMsgType
.Warning
);
875 Move(exts
^, extName
[1], i
);
876 extName
[0] := Char(i
);
877 e_WriteLog(Format('EXT: %s', [extName
]), TMsgType
.Notify
);
881 for i
:= 0 to length(name
)-1 do
883 if (exts
[i
] = #0) then begin found
:= false; break
; end;
884 if (exts
[i
] <> name
[i
+1]) then begin found
:= false; break
; end;
886 if found
and ((exts
[Length(name
)] = #0) or (exts
[Length(name
)] = ' ')) then begin result
:= true; exit
; end;
887 while (exts
[0] <> #0) and (exts
[0] <> ' ') do Inc(exts
);
888 while (exts
[0] <> #0) and (exts
[0] = ' ') do Inc(exts
);
893 function SDLMain (): Integer;
896 {$IF not DEFINED(HEADLESS)}
901 {$IFDEF ENABLE_HOLMES}
907 e_NoGraphics
:= true;
909 {$IFDEF ENABLE_HOLMES}
910 if (not g_holmes_imfunctional
) then
913 uiContext
.font
:= 'win14';
919 while (idx
<= ParamCount
) do
921 arg
:= ParamStr(idx
);
923 if arg
= '--opengl-dump-exts' then gwin_dump_extensions
:= true;
924 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
925 if arg
= '--jah' then g_profile_history_size
:= 100;
926 if arg
= '--no-particles' then gpart_dbg_enabled
:= false;
927 if arg
= '--no-los' then gmon_dbg_los_enabled
:= false;
929 if arg
= '--profile-render' then g_profile_frame_draw
:= true;
930 if arg
= '--profile-coldet' then g_profile_collision
:= true;
931 if arg
= '--profile-los' then g_profile_los
:= true;
933 if arg
= '--no-part-phys' then gpart_dbg_phys_enabled
:= false;
934 if arg
= '--no-part-physics' then gpart_dbg_phys_enabled
:= false;
935 if arg
= '--no-particles-phys' then gpart_dbg_phys_enabled
:= false;
936 if arg
= '--no-particles-physics' then gpart_dbg_phys_enabled
:= false;
937 if arg
= '--no-particle-phys' then gpart_dbg_phys_enabled
:= false;
938 if arg
= '--no-particle-physics' then gpart_dbg_phys_enabled
:= false;
940 {.$IF DEFINED(D2F_DEBUG)}
941 if arg
= '--aimline' then g_dbg_aimline_on
:= true;
944 {$IFDEF ENABLE_HOLMES}
945 if arg
= '--holmes' then begin g_holmes_enabled
:= true; g_Game_SetDebugMode(); end;
947 if (arg
= '--holmes-ui-scale') or (arg
= '-holmes-ui-scale') then
949 if (idx
<= ParamCount
) then
951 if not conParseFloat(fuiRenderScale
, ParamStr(idx
)) then fuiRenderScale
:= 1.0;
956 if (arg
= '--holmes-font') or (arg
= '-holmes-font') then
958 if (idx
<= ParamCount
) then
961 val(ParamStr(idx
), itmp
, valres
);
963 if (valres
= 0) and (not g_holmes_imfunctional
) then
966 8: uiContext
.font
:= 'win8';
967 14: uiContext
.font
:= 'win14';
968 16: uiContext
.font
:= 'win16';
981 if (arg
= '--game-scale') or (arg
= '-game-scale') then
983 if (idx
<= ParamCount
) then
985 if not conParseFloat(g_dbg_scale
, ParamStr(idx
)) then g_dbg_scale
:= 1.0;
990 if (arg
= '--write-mapdef') or (arg
= '-write-mapdef') then
992 mdfo
:= createDiskFile('mapdef.txt');
993 mdfo
.WriteBuffer(defaultMapDef
[1], Length(defaultMapDef
));
999 e_WriteLog('Initializing OpenGL', TMsgType
.Notify
);
1002 e_WriteLog('Creating GL window', TMsgType
.Notify
);
1003 if not CreateGLWindow(PChar(Format('Doom 2D: Forever %s', [GAME_VERSION
]))) then
1006 e_WriteLog('Unable to create GL window: ' + SDL_GetError(), TMsgType
.Fatal
);
1010 {EnumDisplayModes();}
1013 //gwin_k8_enable_light_experiments := false;
1014 gwin_has_stencil
:= false;
1015 glLegacyNPOT
:= false;
1016 gwin_dump_extensions
:= false;
1018 SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE
, @ltmp
);
1019 e_LogWritefln('stencil buffer size: %s', [ltmp
]);
1020 gwin_has_stencil
:= (ltmp
> 0);
1022 if glHasExtension('GL_ARB_texture_non_power_of_two') or
1023 glHasExtension('GL_OES_texture_npot') then
1025 e_WriteLog('NPOT textures: YES', TMsgType
.Notify
);
1026 glLegacyNPOT
:= false;
1030 e_WriteLog('NPOT textures: NO', TMsgType
.Warning
);
1031 glLegacyNPOT
:= true;
1033 gwin_dump_extensions
:= false;
1037 Time_Old
:= GetTimer();
1040 if (ParamCount
> 0) then g_Game_Process_Params();
1043 if (not gGameOn
) and gAskLanguage
then g_Menu_AskLanguage();
1045 e_WriteLog('Entering the main loop', TMsgType
.Notify
);
1048 while not ProcessMessage() do begin end;
1051 KillGLWindow(false);