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
,
68 ProgressUpdateMSecs
= 1;//100;
71 h_Wnd
: PSDL_Window
= nil;
72 h_GL
: TSDL_GLContext
= nil;
73 Time
, Time_Delta
, Time_Old
: Int64;
75 {$IF not DEFINED(HEADLESS)}
77 wasFullscreen
: Boolean = true; // so we need to recreate the window
79 wNeedTimeReset
: Boolean = false;
80 wMinimized
: Boolean = false;
81 wMaximized
: Boolean = false;
82 wLoadingProgress
: Boolean = false;
83 wLoadingQuit
: Boolean = false;
85 ticksOverflow
: Int64 = -1;
86 lastTicks
: Uint32
= 0; // to detect overflow
90 procedure KillGLWindow (preserveGL
: Boolean);
92 if (h_GL
<> nil) and (not preserveGL
) then begin if (assigned(oglDeinitCB
)) then oglDeinitCB(); end;
93 if (h_Wnd
<> nil) then SDL_DestroyWindow(h_Wnd
);
94 if (h_GL
<> nil) and (not preserveGL
) then
99 SDL_GL_DeleteContext(h_GL
);
102 if (not preserveGL
) then h_GL
:= nil;
106 function g_Window_SetDisplay (preserveGL
: Boolean = false): Boolean;
107 {$IF not DEFINED(HEADLESS)}
109 mode
, cmode
: TSDL_DisplayMode
;
110 wFlags
: LongWord = 0;
114 {$IF not DEFINED(HEADLESS)}
117 e_WriteLog('Setting display mode...', TMsgType
.Notify
);
119 wFlags
:= SDL_WINDOW_OPENGL
{or SDL_WINDOW_RESIZABLE};
120 if gFullscreen
then wFlags
:= wFlags
{or SDL_WINDOW_FULLSCREEN} else wFlags
:= wFlags
or SDL_WINDOW_RESIZABLE
;
121 if (not gFullscreen
) and (not preserveGL
) and gWinMaximized
then wFlags
:= wFlags
or SDL_WINDOW_MAXIMIZED
else gWinMaximized
:= false;
125 mode
.w
:= gScreenWidth
;
126 mode
.h
:= gScreenHeight
;
128 mode
.refresh_rate
:= 0;
129 mode
.driverdata
:= nil;
130 if (SDL_GetClosestDisplayMode(0, @mode
, @cmode
) = nil) then
132 e_WriteLog('SDL: cannot find display mode for '+IntToStr(gScreenWidth
), TMsgType
.Notify
);
134 gScreenHeight
:= 600;
138 e_WriteLog('SDL: found display mode for '+IntToStr(gScreenWidth
)+'x'+IntToStr(gScreenHeight
)+': '+IntToStr(cmode
.w
)+'x'+IntToStr(cmode
.h
), TMsgType
.Notify
);
139 gScreenWidth
:= cmode
.w
;
140 gScreenHeight
:= cmode
.h
;
144 if (preserveGL
) and (h_Wnd
<> nil) and (not gFullscreen
) and (not wasFullscreen
) then
146 //SDL_SetWindowMaximumSize(h_Wnd, gScreenWidth, gScreenHeight);
147 //SDL_SetWindowDisplayMode(h_Wnd, @cmode);
148 if (wMaximized
) then SDL_RestoreWindow(h_Wnd
);
150 gWinMaximized
:= false;
151 SDL_SetWindowSize(h_Wnd
, gScreenWidth
, gScreenHeight
);
152 //SDL_SetWindowFullscreen(h_Wnd, SDL_WINDOW_FULLSCREEN);
153 //SDL_SetWindowFullscreen(h_Wnd, 0);
157 KillGLWindow(preserveGL
);
158 h_Wnd
:= SDL_CreateWindow(PChar(wTitle
), gWinRealPosX
, gWinRealPosY
, gScreenWidth
, gScreenHeight
, wFlags
);
160 SDL_SetWindowFullscreen(h_Wnd
, SDL_WINDOW_FULLSCREEN
);
161 if (h_Wnd
= nil) then exit
;
163 wasFullscreen
:= gFullscreen
;
165 SDL_GL_MakeCurrent(h_Wnd
, h_GL
);
166 SDL_ShowCursor(SDL_DISABLE
);
167 if (h_GL
<> nil) then g_SetVSync(gVSync
);
168 if (gFullscreen
) then
172 SDL_GetWindowSize(h_Wnd
, @nw
, @nh
);
173 if (nw
> 128) and (nh
> 128) then
175 e_WriteLog('SDL: fullscreen window got size '+IntToStr(nw
)+'x'+IntToStr(nh
)+': '+IntToStr(gScreenWidth
)+'x'+IntToStr(gScreenHeight
), TMsgType
.Notify
);
181 e_WriteLog('SDL: fullscreen window got invalid size: '+IntToStr(nw
)+'x'+IntToStr(nh
), TMsgType
.Notify
);
184 fuiScrWdt
:= gScreenWidth
;
185 fuiScrHgt
:= gScreenHeight
;
186 if (h_GL
<> nil) and (not preserveGL
) then begin if (assigned(oglInitCB
)) then oglInitCB(); end;
193 function GetDisplayModes (dbpp
: LongWord; var selres
: LongWord): SSArray
;
195 mode
: TSDL_DisplayMode
;
196 res
, i
, k
, n
, pw
, ph
: Integer;
198 SetLength(result
, 0);
199 {$IFDEF HEADLESS}exit
;{$ENDIF}
201 n
:= SDL_GetNumDisplayModes(0);
205 res
:= SDL_GetDisplayMode(0, i
, @mode
);
206 if res
< 0 then continue
;
207 if SDL_BITSPERPIXEL(mode
.format
) = gBPP
then continue
;
208 if (mode
.w
= pw
) and (mode
.h
= ph
) then continue
;
209 if (mode
.w
= gScreenWidth
) and (mode
.h
= gScreenHeight
) then
212 SetLength(result
, k
);
213 result
[k
-1] := IntToStr(mode
.w
) + 'x' + IntToStr(mode
.h
);
214 pw
:= mode
.w
; ph
:= mode
.h
217 e_WriteLog('SDL: Got ' + IntToStr(k
) + ' resolutions.', TMsgType
.Notify
);
221 procedure Sleep (ms
: LongWord);
227 procedure ChangeWindowSize ();
229 e_LogWritefln(' ChangeWindowSize: (ws=%dx%d) (ss=%dx%d)', [gWinSizeX
, gWinSizeY
, gScreenWidth
, gScreenHeight
]);
230 gWinSizeX
:= gScreenWidth
;
231 gWinSizeY
:= gScreenHeight
;
232 {$IF not DEFINED(HEADLESS)}
233 fuiScrWdt
:= gScreenWidth
;
234 fuiScrHgt
:= gScreenHeight
;
235 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
236 g_Game_SetupScreenSize();
238 g_Game_ClearLoading();
243 function g_Window_SetSize (w
, h
: Word; fullscreen
: Boolean): Boolean;
244 {$IF not DEFINED(HEADLESS)}
250 {$IF not DEFINED(HEADLESS)}
253 if (gScreenWidth
<> w
) or (gScreenHeight
<> h
) then
261 if (gFullscreen
<> fullscreen
) then
265 gFullscreen
:= fullscreen
;
271 g_Window_SetDisplay(preserve
);
278 function WindowEventHandler (constref ev
: TSDL_WindowEvent
): Boolean;
280 wActivate
, wDeactivate
: Boolean;
284 wDeactivate
:= false;
287 SDL_WINDOWEVENT_MOVED
:
289 if not (gFullscreen
or gWinMaximized
) then
291 gWinRealPosX
:= ev
.data1
;
292 gWinRealPosY
:= ev
.data2
;
296 SDL_WINDOWEVENT_MINIMIZED
:
299 if not wMinimized
then
301 e_ResizeWindow(0, 0);
303 if g_debug_WinMsgs
then
305 g_Console_Add('Now minimized');
306 e_WriteLog('[DEBUG] WinMsgs: Now minimized', TMsgType
.Notify
);
312 SDL_WINDOWEVENT_RESIZED
:
314 e_LogWritefln('Resize: (os=%dx%d) (ns=%dx%d)', [gScreenWidth
, gScreenHeight
, Integer(ev
.data1
), Integer(ev
.data2
)]);
315 {if (gFullscreen) then
317 e_LogWriteln(' fullscreen fix applied.');
318 if (gScreenWidth <> ev.data1) or (gScreenHeight <> ev.data2) then
320 SDL_SetWindowSize(h_Wnd, gScreenWidth, gScreenHeight);
325 gScreenWidth
:= ev
.data1
;
326 gScreenHeight
:= ev
.data2
;
330 if g_debug_WinMsgs
then
332 g_Console_Add('Resized to ' + IntToStr(ev
.data1
) + 'x' + IntToStr(ev
.data2
));
333 e_WriteLog('[DEBUG] WinMsgs: Resized to ' + IntToStr(ev
.data1
) + 'x' + IntToStr(ev
.data2
), TMsgType
.Notify
);
337 SDL_WINDOWEVENT_EXPOSED
:
340 SDL_WINDOWEVENT_MAXIMIZED
:
345 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
349 if (not gWinMaximized
) and (not gFullscreen
) then
351 gWinMaximized
:= true;
352 if g_debug_WinMsgs
then
354 g_Console_Add('Now maximized');
355 e_WriteLog('[DEBUG] WinMsgs: Now maximized', TMsgType
.Notify
);
360 SDL_WINDOWEVENT_RESTORED
:
365 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
369 gWinMaximized
:= false;
370 if g_debug_WinMsgs
then
372 g_Console_Add('Now restored');
373 e_WriteLog('[DEBUG] WinMsgs: Now restored', TMsgType
.Notify
);
377 SDL_WINDOWEVENT_FOCUS_GAINED
:
380 //e_WriteLog('window gained focus!', MSG_NOTIFY);
383 SDL_WINDOWEVENT_FOCUS_LOST
:
387 //e_WriteLog('window lost focus!', MSG_NOTIFY);
395 e_WriteLog('deactivating window', TMsgType
.Notify
);
396 e_EnableInput
:= false;
397 e_ClearInputBuffer();
399 if gMuteWhenInactive
then
401 //e_WriteLog('deactivating sounds', MSG_NOTIFY);
402 e_MuteChannels(true);
405 if g_debug_WinMsgs
then
407 g_Console_Add('Now inactive');
408 e_WriteLog('[DEBUG] WinMsgs: Now inactive', TMsgType
.Notify
);
413 if assigned(winBlurCB
) then winBlurCB();
416 else if wActivate
then
418 if not gWinActive
then
420 //e_WriteLog('activating window', MSG_NOTIFY);
421 e_EnableInput
:= true;
423 if gMuteWhenInactive
then
425 //e_WriteLog('activating sounds', MSG_NOTIFY);
426 e_MuteChannels(false);
429 if g_debug_WinMsgs
then
431 g_Console_Add('Now active');
432 e_WriteLog('[DEBUG] WinMsgs: Now active', TMsgType
.Notify
);
436 if assigned(winFocusCB
) then winFocusCB();
442 function EventHandler (var ev
: TSDL_Event
): Boolean;
452 result
:= WindowEventHandler(ev
.window
);
456 if (gExit
<> EXIT_QUIT
) then
458 if not wLoadingProgress
then
465 wLoadingQuit
:= true;
471 SDL_KEYDOWN
, SDL_KEYUP
:
473 key
:= ev
.key
.keysym
.scancode
;
474 down
:= (ev
.type_
= SDL_KEYDOWN
);
475 {$IF not DEFINED(HEADLESS)}
476 if fuiOnSDLEvent(ev
) then
478 // event eaten, but...
479 if not down
then e_KeyUpDown(key
, false);
483 if down
then KeyPress(key
);
484 e_KeyUpDown(key
, down
);
487 {$IF not DEFINED(HEADLESS)}
488 SDL_MOUSEBUTTONDOWN
, SDL_MOUSEBUTTONUP
, SDL_MOUSEWHEEL
, SDL_MOUSEMOTION
:
494 Utf8ToUnicode(@uc
, PChar(ev
.text.text), 1);
496 if (keychr
> 127) then keychr
:= Word(wchar2win(WideChar(keychr
)));
497 if (keychr
> 0) and (keychr
<= 255) then CharPress(AnsiChar(keychr
));
500 // other key presses and joysticks are handled in e_input
505 procedure SwapBuffers ();
507 {$IF not DEFINED(HEADLESS)}
508 SDL_GL_SwapWindow(h_Wnd
);
513 function CreateGLWindow (Title
: PChar): Boolean;
517 gWinSizeX
:= gScreenWidth
;
518 gWinSizeY
:= gScreenHeight
;
520 {$IF not DEFINED(HEADLESS)}
523 e_WriteLog('Creating window', TMsgType
.Notify
);
525 if not g_Window_SetDisplay() then
528 e_WriteLog('Window creation error (resolution not supported?)', TMsgType
.Fatal
);
532 {$IF not DEFINED(HEADLESS)}
533 h_GL
:= SDL_GL_CreateContext(h_Wnd
);
534 if (h_GL
= nil) then exit
;
535 fuiScrWdt
:= gScreenWidth
;
536 fuiScrHgt
:= gScreenHeight
;
537 SDL_GL_MakeCurrent(h_Wnd
, h_GL
);
539 if nanoGL_Init() = 0 then
542 e_WriteLog('nanoGL initialization error', TMsgType
.Fatal
);
546 if (assigned(oglInitCB
)) then oglInitCB();
547 if (h_GL
<> nil) then g_SetVSync(gVSync
);
550 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
558 // windoze sux; in headless mode `GetTickCount()` (and SDL) returns shit
559 function GetTimer (): Int64;
563 QueryPerformanceFrequency(F
);
564 QueryPerformanceCounter(C
);
565 result
:= Round(C
/F
*1000{000});
568 function GetTimer (): Int64;
574 if (ticksOverflow
= -1) then
581 if (lastTicks
> t
) then
583 // overflow, increment overflow ;-)
584 ticksOverflow
:= ticksOverflow
+(Int64($ffffffff)+Int64(1));
585 tt
:= (Int64($ffffffff)+Int64(1))+Int64(t
);
586 t
:= Uint32(tt
-lastTicks
);
590 result
:= ticksOverflow
+Int64(t
);
595 procedure ResetTimer ();
597 wNeedTimeReset
:= true;
601 procedure PushExitEvent ();
605 ev
.type_
:= SDL_QUITEV
;
611 prevLoadingUpdateTime
: UInt64 = 0;
613 procedure ProcessLoading (forceUpdate
: Boolean=false);
619 FillChar(ev
, sizeof(ev
), 0);
620 wLoadingProgress
:= true;
622 while (SDL_PollEvent(@ev
) > 0) do
625 if (ev
.type_
= SDL_QUITEV
) then break
;
629 if (ev
.type_
= SDL_QUITEV
) or (gExit
= EXIT_QUIT
) then
631 wLoadingProgress
:= false;
635 if not wMinimized
then
639 prevLoadingUpdateTime
:= getTimeMilli();
643 stt
:= getTimeMilli();
644 if (stt
< prevLoadingUpdateTime
) or (stt
-prevLoadingUpdateTime
>= ProgressUpdateMSecs
) then
646 prevLoadingUpdateTime
:= stt
;
653 if g_Texture_Get('INTER', ID
) then
655 e_DrawSize(ID
, 0, 0, 0, false, false, gScreenWidth
, gScreenHeight
);
656 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
660 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
670 if NetMode
= NET_SERVER
then
676 if (NetMode
= NET_CLIENT
) and (NetState
<> NET_STATE_AUTH
) then g_Net_Client_UpdateWhileLoading();
679 wLoadingProgress
:= false;
683 function g_ProcessMessages (): Boolean;
688 FillChar(ev
, SizeOf(ev
), 0);
689 while (SDL_PollEvent(@ev
) > 0) do
691 result
:= EventHandler(ev
);
692 if (ev
.type_
= SDL_QUITEV
) then exit
;
698 function ProcessMessage (): Boolean;
702 result
:= g_ProcessMessages();
705 Time_Delta
:= Time
-Time_Old
;
709 if wNeedTimeReset
then
712 wNeedTimeReset
:= false;
715 g_Map_ProfilersBegin();
716 g_Mons_ProfilersBegin();
718 t
:= Time_Delta
div 28;
724 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
725 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
731 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
732 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
735 g_Map_ProfilersEnd();
736 g_Mons_ProfilersEnd();
744 if (gExit
= EXIT_QUIT
) then
750 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ
753 Time_Old
:= Time
-(Time_Delta
mod 28);
754 if (not wMinimized
) then
762 Sleep(1); // release time slice, so we won't eat 100% CPU
769 procedure ReDrawWindow ();
775 procedure g_SetVSync (vsync
: Boolean);
776 {$IF not DEFINED(HEADLESS)}
781 {$IF not DEFINED(HEADLESS)}
782 if vsync
then v
:= 1 else v
:= 0;
783 if (SDL_GL_SetSwapInterval(v
) <> 0) then
785 e_WriteLog('oops; can''t change vsync option, restart required', TMsgType
.Warning
);
789 if vsync
then e_WriteLog('VSync: ON', TMsgType
.Notify
) else e_WriteLog('VSync: OFF', TMsgType
.Notify
);
795 procedure InitOpenGL ();
797 {$IF not DEFINED(HEADLESS)}
799 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION
, 1);
800 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION
, 1);
801 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK
, SDL_GL_CONTEXT_PROFILE_ES
);
803 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION
, 2);
804 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION
, 1);
805 SDL_GL_SetAttribute(SDL_GL_RED_SIZE
, 8);
806 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE
, 8);
807 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE
, 8);
808 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE
, 16);
809 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER
, 1);
810 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE
, 8); // lights; it is enough to have 1-bit stencil buffer for lighting, but...
816 function glHasExtension (const name
: AnsiString): Boolean;
821 extName
: ShortString;
824 if (Length(name
) = 0) then exit
;
825 exts
:= glGetString(GL_EXTENSIONS
);
826 if (exts
= nil) then exit
;
827 while (exts
[0] <> #0) and (exts
[0] = ' ') do Inc(exts
);
828 while (exts
[0] <> #0) do
830 if gwin_dump_extensions
then
833 while (exts
[i
] <> #0) and (exts
[i
] <> ' ') do Inc(i
);
836 e_WriteLog('FUUUUUUUUUUUUU', TMsgType
.Warning
);
840 Move(exts
^, extName
[1], i
);
841 extName
[0] := Char(i
);
842 e_WriteLog(Format('EXT: %s', [extName
]), TMsgType
.Notify
);
846 for i
:= 0 to length(name
)-1 do
848 if (exts
[i
] = #0) then begin found
:= false; break
; end;
849 if (exts
[i
] <> name
[i
+1]) then begin found
:= false; break
; end;
851 if found
and ((exts
[Length(name
)] = #0) or (exts
[Length(name
)] = ' ')) then begin result
:= true; exit
; end;
852 while (exts
[0] <> #0) and (exts
[0] <> ' ') do Inc(exts
);
853 while (exts
[0] <> #0) and (exts
[0] = ' ') do Inc(exts
);
858 function SDLMain (): Integer;
861 {$IF not DEFINED(HEADLESS)}
870 e_NoGraphics
:= true;
872 if (not g_holmes_imfunctional
) then
875 uiContext
.font
:= 'win14';
880 while (idx
<= ParamCount
) do
882 arg
:= ParamStr(idx
);
884 if arg
= '--opengl-dump-exts' then gwin_dump_extensions
:= true;
885 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
886 if arg
= '--jah' then g_profile_history_size
:= 100;
887 if arg
= '--no-particles' then gpart_dbg_enabled
:= false;
888 if arg
= '--no-los' then gmon_dbg_los_enabled
:= false;
890 if arg
= '--profile-render' then g_profile_frame_draw
:= true;
891 if arg
= '--profile-coldet' then g_profile_collision
:= true;
892 if arg
= '--profile-los' then g_profile_los
:= true;
894 if arg
= '--no-part-phys' then gpart_dbg_phys_enabled
:= false;
895 if arg
= '--no-part-physics' then gpart_dbg_phys_enabled
:= false;
896 if arg
= '--no-particles-phys' then gpart_dbg_phys_enabled
:= false;
897 if arg
= '--no-particles-physics' then gpart_dbg_phys_enabled
:= false;
898 if arg
= '--no-particle-phys' then gpart_dbg_phys_enabled
:= false;
899 if arg
= '--no-particle-physics' then gpart_dbg_phys_enabled
:= false;
901 {.$IF DEFINED(D2F_DEBUG)}
902 if arg
= '--aimline' then g_dbg_aimline_on
:= true;
905 if arg
= '--holmes' then begin g_holmes_enabled
:= true; g_Game_SetDebugMode(); end;
907 if (arg
= '--holmes-ui-scale') or (arg
= '-holmes-ui-scale') then
909 if (idx
<= ParamCount
) then
911 if not conParseFloat(fuiRenderScale
, ParamStr(idx
)) then fuiRenderScale
:= 1.0;
916 if (arg
= '--holmes-font') or (arg
= '-holmes-font') then
918 if (idx
<= ParamCount
) then
921 val(ParamStr(idx
), itmp
, valres
);
923 if (valres
= 0) and (not g_holmes_imfunctional
) then
926 8: uiContext
.font
:= 'win8';
927 14: uiContext
.font
:= 'win14';
928 16: uiContext
.font
:= 'win16';
940 if (arg
= '--game-scale') or (arg
= '-game-scale') then
942 if (idx
<= ParamCount
) then
944 if not conParseFloat(g_dbg_scale
, ParamStr(idx
)) then g_dbg_scale
:= 1.0;
949 if (arg
= '--write-mapdef') or (arg
= '-write-mapdef') then
951 mdfo
:= createDiskFile('mapdef.txt');
952 mdfo
.WriteBuffer(defaultMapDef
[1], Length(defaultMapDef
));
958 e_WriteLog('Initializing OpenGL', TMsgType
.Notify
);
961 e_WriteLog('Creating GL window', TMsgType
.Notify
);
962 if not CreateGLWindow(PChar(Format('Doom 2D: Forever %s', [GAME_VERSION
]))) then
965 e_WriteLog('Unable to create GL window: ' + SDL_GetError(), TMsgType
.Fatal
);
969 {EnumDisplayModes();}
972 //gwin_k8_enable_light_experiments := false;
973 gwin_has_stencil
:= false;
974 glLegacyNPOT
:= false;
975 gwin_dump_extensions
:= false;
977 SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE
, @ltmp
);
978 e_LogWritefln('stencil buffer size: %s', [ltmp
]);
979 gwin_has_stencil
:= (ltmp
> 0);
981 if not glHasExtension('GL_ARB_texture_non_power_of_two') then
983 e_WriteLog('NPOT textures: NO', TMsgType
.Warning
);
984 glLegacyNPOT
:= true;
988 e_WriteLog('NPOT textures: YES', TMsgType
.Notify
);
989 glLegacyNPOT
:= false;
991 gwin_dump_extensions
:= false;
995 Time_Old
:= GetTimer();
998 if (ParamCount
> 0) then g_Game_Process_Params();
1001 if (not gGameOn
) and gAskLanguage
then g_Menu_AskLanguage();
1003 e_WriteLog('Entering the main loop', TMsgType
.Notify
);
1006 while not ProcessMessage() do begin end;
1009 KillGLWindow(false);