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}
59 SysUtils
, Classes
, MAPDEF
,
60 SDL2
, e_graphics
, e_log
, e_texture
, g_main
,
61 g_console
, e_input
, g_options
, g_game
,
62 g_basic
, g_textures
, e_sound
, g_sound
, g_menu
, ENet
, g_net
,
63 g_map
, g_gfx
, g_monsters
, g_holmes
, xprofiler
,
69 ProgressUpdateMSecs
= 1;//100;
72 h_Wnd
: PSDL_Window
= nil;
73 h_GL
: TSDL_GLContext
= nil;
74 Time
, Time_Delta
, Time_Old
: Int64;
76 {$IF not DEFINED(HEADLESS)}
78 wasFullscreen
: Boolean = true; // so we need to recreate the window
80 wNeedTimeReset
: Boolean = false;
81 wMinimized
: Boolean = false;
82 wMaximized
: Boolean = false;
83 wLoadingProgress
: Boolean = false;
84 wLoadingQuit
: Boolean = false;
86 ticksOverflow
: Int64 = -1;
87 lastTicks
: Uint32
= 0; // to detect overflow
91 procedure KillGLWindow (preserveGL
: Boolean);
93 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
100 SDL_GL_DeleteContext(h_GL
);
103 if (not preserveGL
) then h_GL
:= nil;
107 function g_Window_SetDisplay (preserveGL
: Boolean = false): Boolean;
108 {$IF not DEFINED(HEADLESS)}
110 mode
, cmode
: TSDL_DisplayMode
;
111 wFlags
: LongWord = 0;
115 {$IF not DEFINED(HEADLESS)}
118 e_WriteLog('Setting display mode...', TMsgType
.Notify
);
120 wFlags
:= SDL_WINDOW_OPENGL
{or SDL_WINDOW_RESIZABLE};
121 if gFullscreen
then wFlags
:= wFlags
{or SDL_WINDOW_FULLSCREEN} else wFlags
:= wFlags
or SDL_WINDOW_RESIZABLE
;
122 if (not gFullscreen
) and (not preserveGL
) and gWinMaximized
then wFlags
:= wFlags
or SDL_WINDOW_MAXIMIZED
else gWinMaximized
:= false;
126 mode
.w
:= gScreenWidth
;
127 mode
.h
:= gScreenHeight
;
129 mode
.refresh_rate
:= 0;
130 mode
.driverdata
:= nil;
131 if (SDL_GetClosestDisplayMode(0, @mode
, @cmode
) = nil) then
133 e_WriteLog('SDL: cannot find display mode for '+IntToStr(gScreenWidth
), TMsgType
.Notify
);
135 gScreenHeight
:= 600;
139 e_WriteLog('SDL: found display mode for '+IntToStr(gScreenWidth
)+'x'+IntToStr(gScreenHeight
)+': '+IntToStr(cmode
.w
)+'x'+IntToStr(cmode
.h
), TMsgType
.Notify
);
140 gScreenWidth
:= cmode
.w
;
141 gScreenHeight
:= cmode
.h
;
145 if (preserveGL
) and (h_Wnd
<> nil) and (not gFullscreen
) and (not wasFullscreen
) then
147 //SDL_SetWindowMaximumSize(h_Wnd, gScreenWidth, gScreenHeight);
148 //SDL_SetWindowDisplayMode(h_Wnd, @cmode);
149 if (wMaximized
) then SDL_RestoreWindow(h_Wnd
);
151 gWinMaximized
:= false;
152 SDL_SetWindowSize(h_Wnd
, gScreenWidth
, gScreenHeight
);
153 //SDL_SetWindowFullscreen(h_Wnd, SDL_WINDOW_FULLSCREEN);
154 //SDL_SetWindowFullscreen(h_Wnd, 0);
158 KillGLWindow(preserveGL
);
159 h_Wnd
:= SDL_CreateWindow(PChar(wTitle
), gWinRealPosX
, gWinRealPosY
, gScreenWidth
, gScreenHeight
, wFlags
);
161 SDL_SetWindowFullscreen(h_Wnd
, SDL_WINDOW_FULLSCREEN
);
162 if (h_Wnd
= nil) then exit
;
164 wasFullscreen
:= gFullscreen
;
166 SDL_GL_MakeCurrent(h_Wnd
, h_GL
);
167 SDL_ShowCursor(SDL_DISABLE
);
168 if (h_GL
<> nil) then g_SetVSync(gVSync
);
169 if (gFullscreen
) then
173 SDL_GetWindowSize(h_Wnd
, @nw
, @nh
);
174 if (nw
> 128) and (nh
> 128) then
176 e_WriteLog('SDL: fullscreen window got size '+IntToStr(nw
)+'x'+IntToStr(nh
)+': '+IntToStr(gScreenWidth
)+'x'+IntToStr(gScreenHeight
), TMsgType
.Notify
);
182 e_WriteLog('SDL: fullscreen window got invalid size: '+IntToStr(nw
)+'x'+IntToStr(nh
), TMsgType
.Notify
);
185 fuiScrWdt
:= gScreenWidth
;
186 fuiScrHgt
:= gScreenHeight
;
187 if (h_GL
<> nil) and (not preserveGL
) then begin if (assigned(oglInitCB
)) then oglInitCB(); end;
194 function GetDisplayModes (dbpp
: LongWord; var selres
: LongWord): SSArray
;
196 mode
: TSDL_DisplayMode
;
197 res
, i
, k
, n
, pw
, ph
: Integer;
199 SetLength(result
, 0);
200 {$IFDEF HEADLESS}exit
;{$ENDIF}
202 n
:= SDL_GetNumDisplayModes(0);
206 res
:= SDL_GetDisplayMode(0, i
, @mode
);
207 if res
< 0 then continue
;
208 if SDL_BITSPERPIXEL(mode
.format
) = gBPP
then continue
;
209 if (mode
.w
= pw
) and (mode
.h
= ph
) then continue
;
210 if (mode
.w
= gScreenWidth
) and (mode
.h
= gScreenHeight
) then
213 SetLength(result
, k
);
214 result
[k
-1] := IntToStr(mode
.w
) + 'x' + IntToStr(mode
.h
);
215 pw
:= mode
.w
; ph
:= mode
.h
218 e_WriteLog('SDL: Got ' + IntToStr(k
) + ' resolutions.', TMsgType
.Notify
);
222 procedure Sleep (ms
: LongWord);
228 procedure ChangeWindowSize ();
230 e_LogWritefln(' ChangeWindowSize: (ws=%dx%d) (ss=%dx%d)', [gWinSizeX
, gWinSizeY
, gScreenWidth
, gScreenHeight
]);
231 gWinSizeX
:= gScreenWidth
;
232 gWinSizeY
:= gScreenHeight
;
233 {$IF not DEFINED(HEADLESS)}
234 fuiScrWdt
:= gScreenWidth
;
235 fuiScrHgt
:= gScreenHeight
;
236 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
237 g_Game_SetupScreenSize();
239 g_Game_ClearLoading();
244 function g_Window_SetSize (w
, h
: Word; fullscreen
: Boolean): Boolean;
245 {$IF not DEFINED(HEADLESS)}
251 {$IF not DEFINED(HEADLESS)}
254 if (gScreenWidth
<> w
) or (gScreenHeight
<> h
) then
262 if (gFullscreen
<> fullscreen
) then
266 gFullscreen
:= fullscreen
;
272 g_Window_SetDisplay(preserve
);
279 function WindowEventHandler (constref ev
: TSDL_WindowEvent
): Boolean;
281 wActivate
, wDeactivate
: Boolean;
285 wDeactivate
:= false;
288 SDL_WINDOWEVENT_MOVED
:
290 if not (gFullscreen
or gWinMaximized
) then
292 gWinRealPosX
:= ev
.data1
;
293 gWinRealPosY
:= ev
.data2
;
297 SDL_WINDOWEVENT_MINIMIZED
:
300 if not wMinimized
then
302 e_ResizeWindow(0, 0);
304 if g_debug_WinMsgs
then
306 g_Console_Add('Now minimized');
307 e_WriteLog('[DEBUG] WinMsgs: Now minimized', TMsgType
.Notify
);
313 SDL_WINDOWEVENT_RESIZED
:
315 e_LogWritefln('Resize: (os=%dx%d) (ns=%dx%d)', [gScreenWidth
, gScreenHeight
, Integer(ev
.data1
), Integer(ev
.data2
)]);
316 {if (gFullscreen) then
318 e_LogWriteln(' fullscreen fix applied.');
319 if (gScreenWidth <> ev.data1) or (gScreenHeight <> ev.data2) then
321 SDL_SetWindowSize(h_Wnd, gScreenWidth, gScreenHeight);
326 gScreenWidth
:= ev
.data1
;
327 gScreenHeight
:= ev
.data2
;
331 if g_debug_WinMsgs
then
333 g_Console_Add('Resized to ' + IntToStr(ev
.data1
) + 'x' + IntToStr(ev
.data2
));
334 e_WriteLog('[DEBUG] WinMsgs: Resized to ' + IntToStr(ev
.data1
) + 'x' + IntToStr(ev
.data2
), TMsgType
.Notify
);
338 SDL_WINDOWEVENT_EXPOSED
:
341 SDL_WINDOWEVENT_MAXIMIZED
:
346 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
350 if (not gWinMaximized
) and (not gFullscreen
) then
352 gWinMaximized
:= true;
353 if g_debug_WinMsgs
then
355 g_Console_Add('Now maximized');
356 e_WriteLog('[DEBUG] WinMsgs: Now maximized', TMsgType
.Notify
);
361 SDL_WINDOWEVENT_RESTORED
:
366 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
370 gWinMaximized
:= false;
371 if g_debug_WinMsgs
then
373 g_Console_Add('Now restored');
374 e_WriteLog('[DEBUG] WinMsgs: Now restored', TMsgType
.Notify
);
378 SDL_WINDOWEVENT_FOCUS_GAINED
:
381 //e_WriteLog('window gained focus!', MSG_NOTIFY);
384 SDL_WINDOWEVENT_FOCUS_LOST
:
388 //e_WriteLog('window lost focus!', MSG_NOTIFY);
396 e_WriteLog('deactivating window', TMsgType
.Notify
);
397 e_EnableInput
:= false;
398 e_ClearInputBuffer();
400 if gMuteWhenInactive
then
402 //e_WriteLog('deactivating sounds', MSG_NOTIFY);
403 e_MuteChannels(true);
406 if g_debug_WinMsgs
then
408 g_Console_Add('Now inactive');
409 e_WriteLog('[DEBUG] WinMsgs: Now inactive', TMsgType
.Notify
);
414 if assigned(winBlurCB
) then winBlurCB();
417 else if wActivate
then
419 if not gWinActive
then
421 //e_WriteLog('activating window', MSG_NOTIFY);
422 e_EnableInput
:= true;
424 if gMuteWhenInactive
then
426 //e_WriteLog('activating sounds', MSG_NOTIFY);
427 e_MuteChannels(false);
430 if g_debug_WinMsgs
then
432 g_Console_Add('Now active');
433 e_WriteLog('[DEBUG] WinMsgs: Now active', TMsgType
.Notify
);
437 if assigned(winFocusCB
) then winFocusCB();
443 function EventHandler (var ev
: TSDL_Event
): Boolean;
453 result
:= WindowEventHandler(ev
.window
);
457 if (gExit
<> EXIT_QUIT
) then
459 if not wLoadingProgress
then
466 wLoadingQuit
:= true;
472 SDL_KEYDOWN
, SDL_KEYUP
:
474 key
:= ev
.key
.keysym
.scancode
;
475 if key
= SDL_SCANCODE_AC_BACK
then
476 key
:= SDL_SCANCODE_ESCAPE
;
477 down
:= (ev
.type_
= SDL_KEYDOWN
);
478 {$IF not DEFINED(HEADLESS)}
479 if fuiOnSDLEvent(ev
) then
481 // event eaten, but...
482 if not down
then e_KeyUpDown(key
, false);
486 e_KeyUpDown(key
, down
);
487 if down
then KeyPress(key
);
490 {$IF not DEFINED(HEADLESS)}
491 SDL_MOUSEBUTTONDOWN
, SDL_MOUSEBUTTONUP
, SDL_MOUSEWHEEL
, SDL_MOUSEMOTION
:
497 Utf8ToUnicode(@uc
, PChar(ev
.text.text), 1);
499 if (keychr
> 127) then keychr
:= Word(wchar2win(WideChar(keychr
)));
500 if (keychr
> 0) and (keychr
<= 255) then CharPress(AnsiChar(keychr
));
503 SDL_FINGERMOTION
, SDL_FINGERDOWN
, SDL_FINGERUP
:
504 g_Touch_HandleEvent(ev
.tfinger
);
506 // other key presses and joysticks are handled in e_input
511 procedure SwapBuffers ();
513 {$IF not DEFINED(HEADLESS)}
514 SDL_GL_SwapWindow(h_Wnd
);
519 function CreateGLWindow (Title
: PChar): Boolean;
523 gWinSizeX
:= gScreenWidth
;
524 gWinSizeY
:= gScreenHeight
;
526 {$IF not DEFINED(HEADLESS)}
529 e_WriteLog('Creating window', TMsgType
.Notify
);
531 if not g_Window_SetDisplay() then
534 e_WriteLog('Window creation error (resolution not supported?)', TMsgType
.Fatal
);
538 {$IF not DEFINED(HEADLESS)}
539 h_GL
:= SDL_GL_CreateContext(h_Wnd
);
540 if (h_GL
= nil) then exit
;
541 fuiScrWdt
:= gScreenWidth
;
542 fuiScrHgt
:= gScreenHeight
;
543 SDL_GL_MakeCurrent(h_Wnd
, h_GL
);
545 if nanoGL_Init() = 0 then
548 e_WriteLog('nanoGL initialization error', TMsgType
.Fatal
);
552 if (assigned(oglInitCB
)) then oglInitCB();
553 if (h_GL
<> nil) then g_SetVSync(gVSync
);
556 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
564 // windoze sux; in headless mode `GetTickCount()` (and SDL) returns shit
565 function GetTimer (): Int64;
569 QueryPerformanceFrequency(F
);
570 QueryPerformanceCounter(C
);
571 result
:= Round(C
/F
*1000{000});
574 function GetTimer (): Int64;
580 if (ticksOverflow
= -1) then
587 if (lastTicks
> t
) then
589 // overflow, increment overflow ;-)
590 ticksOverflow
:= ticksOverflow
+(Int64($ffffffff)+Int64(1));
591 tt
:= (Int64($ffffffff)+Int64(1))+Int64(t
);
592 t
:= Uint32(tt
-lastTicks
);
596 result
:= ticksOverflow
+Int64(t
);
601 procedure ResetTimer ();
603 wNeedTimeReset
:= true;
607 procedure PushExitEvent ();
611 ev
.type_
:= SDL_QUITEV
;
617 prevLoadingUpdateTime
: UInt64 = 0;
619 procedure ProcessLoading (forceUpdate
: Boolean=false);
625 FillChar(ev
, sizeof(ev
), 0);
626 wLoadingProgress
:= true;
628 while (SDL_PollEvent(@ev
) > 0) do
631 if (ev
.type_
= SDL_QUITEV
) then break
;
635 if (ev
.type_
= SDL_QUITEV
) or (gExit
= EXIT_QUIT
) then
637 wLoadingProgress
:= false;
641 if not wMinimized
then
645 prevLoadingUpdateTime
:= getTimeMilli();
649 stt
:= getTimeMilli();
650 if (stt
< prevLoadingUpdateTime
) or (stt
-prevLoadingUpdateTime
>= ProgressUpdateMSecs
) then
652 prevLoadingUpdateTime
:= stt
;
659 if g_Texture_Get('INTER', ID
) then
661 e_DrawSize(ID
, 0, 0, 0, false, false, gScreenWidth
, gScreenHeight
);
662 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
666 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
676 if NetMode
= NET_SERVER
then
682 if (NetMode
= NET_CLIENT
) and (NetState
<> NET_STATE_AUTH
) then g_Net_Client_UpdateWhileLoading();
685 wLoadingProgress
:= false;
689 function g_ProcessMessages (): Boolean;
694 FillChar(ev
, SizeOf(ev
), 0);
695 while (SDL_PollEvent(@ev
) > 0) do
697 result
:= EventHandler(ev
);
698 if (ev
.type_
= SDL_QUITEV
) then exit
;
704 function ProcessMessage (): Boolean;
708 result
:= g_ProcessMessages();
711 Time_Delta
:= Time
-Time_Old
;
715 if wNeedTimeReset
then
718 wNeedTimeReset
:= false;
721 g_Map_ProfilersBegin();
722 g_Mons_ProfilersBegin();
724 t
:= Time_Delta
div 28;
730 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
731 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
737 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
738 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
741 g_Map_ProfilersEnd();
742 g_Mons_ProfilersEnd();
750 if (gExit
= EXIT_QUIT
) then
756 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ
759 Time_Old
:= Time
-(Time_Delta
mod 28);
760 if (not wMinimized
) then
768 Sleep(1); // release time slice, so we won't eat 100% CPU
775 procedure ReDrawWindow ();
781 procedure g_SetVSync (vsync
: Boolean);
782 {$IF not DEFINED(HEADLESS)}
787 {$IF not DEFINED(HEADLESS)}
788 if vsync
then v
:= 1 else v
:= 0;
789 if (SDL_GL_SetSwapInterval(v
) <> 0) then
791 e_WriteLog('oops; can''t change vsync option, restart required', TMsgType
.Warning
);
795 if vsync
then e_WriteLog('VSync: ON', TMsgType
.Notify
) else e_WriteLog('VSync: OFF', TMsgType
.Notify
);
801 procedure InitOpenGL ();
803 {$IF not DEFINED(HEADLESS)}
805 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION
, 1);
806 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION
, 1);
807 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK
, SDL_GL_CONTEXT_PROFILE_ES
);
809 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION
, 2);
810 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION
, 1);
811 SDL_GL_SetAttribute(SDL_GL_RED_SIZE
, 8);
812 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE
, 8);
813 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE
, 8);
814 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE
, 16);
815 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER
, 1);
816 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE
, 8); // lights; it is enough to have 1-bit stencil buffer for lighting, but...
822 function glHasExtension (const name
: AnsiString): Boolean;
827 extName
: ShortString;
830 if (Length(name
) = 0) then exit
;
831 exts
:= glGetString(GL_EXTENSIONS
);
832 if (exts
= nil) then exit
;
833 while (exts
[0] <> #0) and (exts
[0] = ' ') do Inc(exts
);
834 while (exts
[0] <> #0) do
836 if gwin_dump_extensions
then
839 while (exts
[i
] <> #0) and (exts
[i
] <> ' ') do Inc(i
);
842 e_WriteLog('FUUUUUUUUUUUUU', TMsgType
.Warning
);
846 Move(exts
^, extName
[1], i
);
847 extName
[0] := Char(i
);
848 e_WriteLog(Format('EXT: %s', [extName
]), TMsgType
.Notify
);
852 for i
:= 0 to length(name
)-1 do
854 if (exts
[i
] = #0) then begin found
:= false; break
; end;
855 if (exts
[i
] <> name
[i
+1]) then begin found
:= false; break
; end;
857 if found
and ((exts
[Length(name
)] = #0) or (exts
[Length(name
)] = ' ')) then begin result
:= true; exit
; end;
858 while (exts
[0] <> #0) and (exts
[0] <> ' ') do Inc(exts
);
859 while (exts
[0] <> #0) and (exts
[0] = ' ') do Inc(exts
);
864 function SDLMain (): Integer;
867 {$IF not DEFINED(HEADLESS)}
876 e_NoGraphics
:= true;
878 if (not g_holmes_imfunctional
) then
881 uiContext
.font
:= 'win14';
886 while (idx
<= ParamCount
) do
888 arg
:= ParamStr(idx
);
890 if arg
= '--opengl-dump-exts' then gwin_dump_extensions
:= true;
891 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
892 if arg
= '--jah' then g_profile_history_size
:= 100;
893 if arg
= '--no-particles' then gpart_dbg_enabled
:= false;
894 if arg
= '--no-los' then gmon_dbg_los_enabled
:= false;
896 if arg
= '--profile-render' then g_profile_frame_draw
:= true;
897 if arg
= '--profile-coldet' then g_profile_collision
:= true;
898 if arg
= '--profile-los' then g_profile_los
:= true;
900 if arg
= '--no-part-phys' then gpart_dbg_phys_enabled
:= false;
901 if arg
= '--no-part-physics' then gpart_dbg_phys_enabled
:= false;
902 if arg
= '--no-particles-phys' then gpart_dbg_phys_enabled
:= false;
903 if arg
= '--no-particles-physics' then gpart_dbg_phys_enabled
:= false;
904 if arg
= '--no-particle-phys' then gpart_dbg_phys_enabled
:= false;
905 if arg
= '--no-particle-physics' then gpart_dbg_phys_enabled
:= false;
907 {.$IF DEFINED(D2F_DEBUG)}
908 if arg
= '--aimline' then g_dbg_aimline_on
:= true;
911 if arg
= '--holmes' then begin g_holmes_enabled
:= true; g_Game_SetDebugMode(); end;
913 if (arg
= '--holmes-ui-scale') or (arg
= '-holmes-ui-scale') then
915 if (idx
<= ParamCount
) then
917 if not conParseFloat(fuiRenderScale
, ParamStr(idx
)) then fuiRenderScale
:= 1.0;
922 if (arg
= '--holmes-font') or (arg
= '-holmes-font') then
924 if (idx
<= ParamCount
) then
927 val(ParamStr(idx
), itmp
, valres
);
929 if (valres
= 0) and (not g_holmes_imfunctional
) then
932 8: uiContext
.font
:= 'win8';
933 14: uiContext
.font
:= 'win14';
934 16: uiContext
.font
:= 'win16';
946 if (arg
= '--game-scale') or (arg
= '-game-scale') then
948 if (idx
<= ParamCount
) then
950 if not conParseFloat(g_dbg_scale
, ParamStr(idx
)) then g_dbg_scale
:= 1.0;
955 if (arg
= '--write-mapdef') or (arg
= '-write-mapdef') then
957 mdfo
:= createDiskFile('mapdef.txt');
958 mdfo
.WriteBuffer(defaultMapDef
[1], Length(defaultMapDef
));
964 e_WriteLog('Initializing OpenGL', TMsgType
.Notify
);
967 e_WriteLog('Creating GL window', TMsgType
.Notify
);
968 if not CreateGLWindow(PChar(Format('Doom 2D: Forever %s', [GAME_VERSION
]))) then
971 e_WriteLog('Unable to create GL window: ' + SDL_GetError(), TMsgType
.Fatal
);
975 {EnumDisplayModes();}
978 //gwin_k8_enable_light_experiments := false;
979 gwin_has_stencil
:= false;
980 glLegacyNPOT
:= false;
981 gwin_dump_extensions
:= false;
983 SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE
, @ltmp
);
984 e_LogWritefln('stencil buffer size: %s', [ltmp
]);
985 gwin_has_stencil
:= (ltmp
> 0);
987 if not glHasExtension('GL_ARB_texture_non_power_of_two') then
989 e_WriteLog('NPOT textures: NO', TMsgType
.Warning
);
990 glLegacyNPOT
:= true;
994 e_WriteLog('NPOT textures: YES', TMsgType
.Notify
);
995 glLegacyNPOT
:= false;
997 gwin_dump_extensions
:= false;
1001 Time_Old
:= GetTimer();
1004 if (ParamCount
> 0) then g_Game_Process_Params();
1007 if (not gGameOn
) and gAskLanguage
then g_Menu_AskLanguage();
1009 e_WriteLog('Entering the main loop', TMsgType
.Notify
);
1012 while not ProcessMessage() do begin end;
1015 KillGLWindow(false);