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 SysUtils
, Classes
, MAPDEF
,
55 SDL2
, GL
, GLExt
, e_graphics
, e_log
, e_texture
, g_main
,
56 g_console
, e_input
, g_options
, g_game
,
57 g_basic
, g_textures
, e_sound
, g_sound
, g_menu
, ENet
, g_net
,
58 g_map
, g_gfx
, g_monsters
, g_holmes
, xprofiler
,
63 ProgressUpdateMSecs
= 1;//100;
66 h_Wnd
: PSDL_Window
= nil;
67 h_GL
: TSDL_GLContext
= nil;
68 Time
, Time_Delta
, Time_Old
: Int64;
70 {$IF not DEFINED(HEADLESS)}
72 wasFullscreen
: Boolean = true; // so we need to recreate the window
74 wNeedTimeReset
: Boolean = false;
75 wMinimized
: Boolean = false;
76 wMaximized
: Boolean = false;
77 wLoadingProgress
: Boolean = false;
78 wLoadingQuit
: Boolean = false;
80 ticksOverflow
: Int64 = -1;
81 lastTicks
: Uint32
= 0; // to detect overflow
85 procedure KillGLWindow (preserveGL
: Boolean);
87 if (h_GL
<> nil) and (not preserveGL
) then begin if (assigned(oglDeinitCB
)) then oglDeinitCB(); end;
88 if (h_Wnd
<> nil) then SDL_DestroyWindow(h_Wnd
);
89 if (h_GL
<> nil) and (not preserveGL
) then SDL_GL_DeleteContext(h_GL
);
91 if (not preserveGL
) then h_GL
:= nil;
95 function g_Window_SetDisplay (preserveGL
: Boolean = false): Boolean;
96 {$IF not DEFINED(HEADLESS)}
98 mode
, cmode
: TSDL_DisplayMode
;
103 {$IF not DEFINED(HEADLESS)}
106 e_WriteLog('Setting display mode...', TMsgType
.Notify
);
108 wFlags
:= SDL_WINDOW_OPENGL
{or SDL_WINDOW_RESIZABLE};
109 if gFullscreen
then wFlags
:= wFlags
{or SDL_WINDOW_FULLSCREEN} else wFlags
:= wFlags
or SDL_WINDOW_RESIZABLE
;
110 if (not gFullscreen
) and (not preserveGL
) and gWinMaximized
then wFlags
:= wFlags
or SDL_WINDOW_MAXIMIZED
else gWinMaximized
:= false;
114 mode
.w
:= gScreenWidth
;
115 mode
.h
:= gScreenHeight
;
117 mode
.refresh_rate
:= 0;
118 mode
.driverdata
:= nil;
119 if (SDL_GetClosestDisplayMode(0, @mode
, @cmode
) = nil) then
121 e_WriteLog('SDL: cannot find display mode for '+IntToStr(gScreenWidth
), TMsgType
.Notify
);
123 gScreenHeight
:= 600;
127 e_WriteLog('SDL: found display mode for '+IntToStr(gScreenWidth
)+'x'+IntToStr(gScreenHeight
)+': '+IntToStr(cmode
.w
)+'x'+IntToStr(cmode
.h
), TMsgType
.Notify
);
128 gScreenWidth
:= cmode
.w
;
129 gScreenHeight
:= cmode
.h
;
133 if (preserveGL
) and (h_Wnd
<> nil) and (not gFullscreen
) and (not wasFullscreen
) then
135 //SDL_SetWindowMaximumSize(h_Wnd, gScreenWidth, gScreenHeight);
136 //SDL_SetWindowDisplayMode(h_Wnd, @cmode);
137 if (wMaximized
) then SDL_RestoreWindow(h_Wnd
);
139 gWinMaximized
:= false;
140 SDL_SetWindowSize(h_Wnd
, gScreenWidth
, gScreenHeight
);
141 //SDL_SetWindowFullscreen(h_Wnd, SDL_WINDOW_FULLSCREEN);
142 //SDL_SetWindowFullscreen(h_Wnd, 0);
146 KillGLWindow(preserveGL
);
147 h_Wnd
:= SDL_CreateWindow(PChar(wTitle
), gWinRealPosX
, gWinRealPosY
, gScreenWidth
, gScreenHeight
, wFlags
);
149 SDL_SetWindowFullscreen(h_Wnd
, SDL_WINDOW_FULLSCREEN
);
150 if (h_Wnd
= nil) then exit
;
152 wasFullscreen
:= gFullscreen
;
154 SDL_GL_MakeCurrent(h_Wnd
, h_GL
);
155 SDL_ShowCursor(SDL_DISABLE
);
156 if (h_GL
<> nil) then g_SetVSync(gVSync
);
157 if (gFullscreen
) then
161 SDL_GetWindowSize(h_Wnd
, @nw
, @nh
);
162 if (nw
> 128) and (nh
> 128) then
164 e_WriteLog('SDL: fullscreen window got size '+IntToStr(nw
)+'x'+IntToStr(nh
)+': '+IntToStr(gScreenWidth
)+'x'+IntToStr(gScreenHeight
), TMsgType
.Notify
);
170 e_WriteLog('SDL: fullscreen window got invalid size: '+IntToStr(nw
)+'x'+IntToStr(nh
), TMsgType
.Notify
);
173 fuiScrWdt
:= gScreenWidth
;
174 fuiScrHgt
:= gScreenHeight
;
175 if (h_GL
<> nil) and (not preserveGL
) then begin if (assigned(oglInitCB
)) then oglInitCB(); end;
182 function GetDisplayModes (dbpp
: LongWord; var selres
: LongWord): SSArray
;
184 mode
: TSDL_DisplayMode
;
185 res
, i
, k
, n
, pw
, ph
: Integer;
187 SetLength(result
, 0);
188 {$IFDEF HEADLESS}exit
;{$ENDIF}
190 n
:= SDL_GetNumDisplayModes(0);
194 res
:= SDL_GetDisplayMode(0, i
, @mode
);
195 if res
< 0 then continue
;
196 if SDL_BITSPERPIXEL(mode
.format
) = gBPP
then continue
;
197 if (mode
.w
= pw
) and (mode
.h
= ph
) then continue
;
198 if (mode
.w
= gScreenWidth
) and (mode
.h
= gScreenHeight
) then
201 SetLength(result
, k
);
202 result
[k
-1] := IntToStr(mode
.w
) + 'x' + IntToStr(mode
.h
);
203 pw
:= mode
.w
; ph
:= mode
.h
206 e_WriteLog('SDL: Got ' + IntToStr(k
) + ' resolutions.', TMsgType
.Notify
);
210 procedure Sleep (ms
: LongWord);
216 procedure ChangeWindowSize ();
218 e_LogWritefln(' ChangeWindowSize: (ws=%dx%d) (ss=%dx%d)', [gWinSizeX
, gWinSizeY
, gScreenWidth
, gScreenHeight
]);
219 gWinSizeX
:= gScreenWidth
;
220 gWinSizeY
:= gScreenHeight
;
221 {$IF not DEFINED(HEADLESS)}
222 fuiScrWdt
:= gScreenWidth
;
223 fuiScrHgt
:= gScreenHeight
;
224 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
225 g_Game_SetupScreenSize();
227 g_Game_ClearLoading();
232 function g_Window_SetSize (w
, h
: Word; fullscreen
: Boolean): Boolean;
233 {$IF not DEFINED(HEADLESS)}
239 {$IF not DEFINED(HEADLESS)}
242 if (gScreenWidth
<> w
) or (gScreenHeight
<> h
) then
250 if (gFullscreen
<> fullscreen
) then
254 gFullscreen
:= fullscreen
;
260 g_Window_SetDisplay(preserve
);
267 function WindowEventHandler (constref ev
: TSDL_WindowEvent
): Boolean;
269 wActivate
, wDeactivate
: Boolean;
273 wDeactivate
:= false;
276 SDL_WINDOWEVENT_MOVED
:
278 if not (gFullscreen
or gWinMaximized
) then
280 gWinRealPosX
:= ev
.data1
;
281 gWinRealPosY
:= ev
.data2
;
285 SDL_WINDOWEVENT_MINIMIZED
:
288 if not wMinimized
then
290 e_ResizeWindow(0, 0);
292 if g_debug_WinMsgs
then
294 g_Console_Add('Now minimized');
295 e_WriteLog('[DEBUG] WinMsgs: Now minimized', TMsgType
.Notify
);
301 SDL_WINDOWEVENT_RESIZED
:
303 e_LogWritefln('Resize: (os=%dx%d) (ns=%dx%d)', [gScreenWidth
, gScreenHeight
, Integer(ev
.data1
), Integer(ev
.data2
)]);
304 {if (gFullscreen) then
306 e_LogWriteln(' fullscreen fix applied.');
307 if (gScreenWidth <> ev.data1) or (gScreenHeight <> ev.data2) then
309 SDL_SetWindowSize(h_Wnd, gScreenWidth, gScreenHeight);
314 gScreenWidth
:= ev
.data1
;
315 gScreenHeight
:= ev
.data2
;
319 if g_debug_WinMsgs
then
321 g_Console_Add('Resized to ' + IntToStr(ev
.data1
) + 'x' + IntToStr(ev
.data2
));
322 e_WriteLog('[DEBUG] WinMsgs: Resized to ' + IntToStr(ev
.data1
) + 'x' + IntToStr(ev
.data2
), TMsgType
.Notify
);
326 SDL_WINDOWEVENT_EXPOSED
:
329 SDL_WINDOWEVENT_MAXIMIZED
:
334 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
338 if (not gWinMaximized
) and (not gFullscreen
) then
340 gWinMaximized
:= true;
341 if g_debug_WinMsgs
then
343 g_Console_Add('Now maximized');
344 e_WriteLog('[DEBUG] WinMsgs: Now maximized', TMsgType
.Notify
);
349 SDL_WINDOWEVENT_RESTORED
:
354 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
358 gWinMaximized
:= false;
359 if g_debug_WinMsgs
then
361 g_Console_Add('Now restored');
362 e_WriteLog('[DEBUG] WinMsgs: Now restored', TMsgType
.Notify
);
366 SDL_WINDOWEVENT_FOCUS_GAINED
:
369 //e_WriteLog('window gained focus!', MSG_NOTIFY);
372 SDL_WINDOWEVENT_FOCUS_LOST
:
376 //e_WriteLog('window lost focus!', MSG_NOTIFY);
384 e_WriteLog('deactivating window', TMsgType
.Notify
);
385 e_EnableInput
:= false;
386 e_ClearInputBuffer();
388 if gMuteWhenInactive
then
390 //e_WriteLog('deactivating sounds', MSG_NOTIFY);
391 e_MuteChannels(true);
394 if g_debug_WinMsgs
then
396 g_Console_Add('Now inactive');
397 e_WriteLog('[DEBUG] WinMsgs: Now inactive', TMsgType
.Notify
);
402 if assigned(winBlurCB
) then winBlurCB();
405 else if wActivate
then
407 if not gWinActive
then
409 //e_WriteLog('activating window', MSG_NOTIFY);
410 e_EnableInput
:= true;
412 if gMuteWhenInactive
then
414 //e_WriteLog('activating sounds', MSG_NOTIFY);
415 e_MuteChannels(false);
418 if g_debug_WinMsgs
then
420 g_Console_Add('Now active');
421 e_WriteLog('[DEBUG] WinMsgs: Now active', TMsgType
.Notify
);
425 if assigned(winFocusCB
) then winFocusCB();
431 function EventHandler (var ev
: TSDL_Event
): Boolean;
441 result
:= WindowEventHandler(ev
.window
);
445 if (gExit
<> EXIT_QUIT
) then
447 if not wLoadingProgress
then
454 wLoadingQuit
:= true;
460 SDL_KEYDOWN
, SDL_KEYUP
:
462 key
:= ev
.key
.keysym
.scancode
;
463 down
:= (ev
.type_
= SDL_KEYDOWN
);
464 {$IF not DEFINED(HEADLESS)}
465 if fuiOnSDLEvent(ev
) then
467 // event eaten, but...
468 if not down
then e_KeyUpDown(key
, false);
472 if down
then KeyPress(key
);
473 e_KeyUpDown(key
, down
);
476 {$IF not DEFINED(HEADLESS)}
477 SDL_MOUSEBUTTONDOWN
, SDL_MOUSEBUTTONUP
, SDL_MOUSEWHEEL
, SDL_MOUSEMOTION
:
483 Utf8ToUnicode(@uc
, PChar(ev
.text.text), 1);
485 if (keychr
> 127) then keychr
:= Word(wchar2win(WideChar(keychr
)));
486 if (keychr
> 0) and (keychr
<= 255) then CharPress(AnsiChar(keychr
));
489 // other key presses and joysticks are handled in e_input
494 procedure SwapBuffers ();
496 {$IF not DEFINED(HEADLESS)}
497 SDL_GL_SwapWindow(h_Wnd
);
502 function CreateGLWindow (Title
: PChar): Boolean;
506 gWinSizeX
:= gScreenWidth
;
507 gWinSizeY
:= gScreenHeight
;
509 {$IF not DEFINED(HEADLESS)}
512 e_WriteLog('Creating window', TMsgType
.Notify
);
514 if not g_Window_SetDisplay() then
517 e_WriteLog('Window creation error (resolution not supported?)', TMsgType
.Fatal
);
521 {$IF not DEFINED(HEADLESS)}
522 h_GL
:= SDL_GL_CreateContext(h_Wnd
);
523 if (h_GL
= nil) then exit
;
524 fuiScrWdt
:= gScreenWidth
;
525 fuiScrHgt
:= gScreenHeight
;
526 if (assigned(oglInitCB
)) then oglInitCB();
527 SDL_GL_MakeCurrent(h_Wnd
, h_GL
);
528 if (h_GL
<> nil) then g_SetVSync(gVSync
);
531 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
539 // windoze sux; in headless mode `GetTickCount()` (and SDL) returns shit
540 function GetTimer (): Int64;
544 QueryPerformanceFrequency(F
);
545 QueryPerformanceCounter(C
);
546 result
:= Round(C
/F
*1000{000});
549 function GetTimer (): Int64;
555 if (ticksOverflow
= -1) then
562 if (lastTicks
> t
) then
564 // overflow, increment overflow ;-)
565 ticksOverflow
:= ticksOverflow
+(Int64($ffffffff)+Int64(1));
566 tt
:= (Int64($ffffffff)+Int64(1))+Int64(t
);
567 t
:= Uint32(tt
-lastTicks
);
571 result
:= ticksOverflow
+Int64(t
);
576 procedure ResetTimer ();
578 wNeedTimeReset
:= true;
582 procedure PushExitEvent ();
586 ev
.type_
:= SDL_QUITEV
;
592 prevLoadingUpdateTime
: UInt64 = 0;
594 procedure ProcessLoading (forceUpdate
: Boolean=false);
600 FillChar(ev
, sizeof(ev
), 0);
601 wLoadingProgress
:= true;
603 while (SDL_PollEvent(@ev
) > 0) do
606 if (ev
.type_
= SDL_QUITEV
) then break
;
610 if (ev
.type_
= SDL_QUITEV
) or (gExit
= EXIT_QUIT
) then
612 wLoadingProgress
:= false;
616 if not wMinimized
then
620 prevLoadingUpdateTime
:= getTimeMilli();
624 stt
:= getTimeMilli();
625 if (stt
< prevLoadingUpdateTime
) or (stt
-prevLoadingUpdateTime
>= ProgressUpdateMSecs
) then
627 prevLoadingUpdateTime
:= stt
;
634 if g_Texture_Get('INTER', ID
) then
636 e_DrawSize(ID
, 0, 0, 0, false, false, gScreenWidth
, gScreenHeight
);
637 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
641 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
651 if NetMode
= NET_SERVER
then
657 if (NetMode
= NET_CLIENT
) and (NetState
<> NET_STATE_AUTH
) then g_Net_Client_UpdateWhileLoading();
660 wLoadingProgress
:= false;
664 function g_ProcessMessages (): Boolean;
669 FillChar(ev
, SizeOf(ev
), 0);
670 while (SDL_PollEvent(@ev
) > 0) do
672 result
:= EventHandler(ev
);
673 if (ev
.type_
= SDL_QUITEV
) then exit
;
679 function ProcessMessage (): Boolean;
683 result
:= g_ProcessMessages();
686 Time_Delta
:= Time
-Time_Old
;
690 if wNeedTimeReset
then
693 wNeedTimeReset
:= false;
696 g_Map_ProfilersBegin();
697 g_Mons_ProfilersBegin();
699 t
:= Time_Delta
div 28;
705 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
706 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
712 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
713 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
716 g_Map_ProfilersEnd();
717 g_Mons_ProfilersEnd();
725 if (gExit
= EXIT_QUIT
) then
731 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ
734 Time_Old
:= Time
-(Time_Delta
mod 28);
735 if (not wMinimized
) then
743 Sleep(1); // release time slice, so we won't eat 100% CPU
750 procedure ReDrawWindow ();
756 procedure g_SetVSync (vsync
: Boolean);
757 {$IF not DEFINED(HEADLESS)}
762 {$IF not DEFINED(HEADLESS)}
763 if vsync
then v
:= 1 else v
:= 0;
764 if (SDL_GL_SetSwapInterval(v
) <> 0) then
766 e_WriteLog('oops; can''t change vsync option, restart required', TMsgType
.Warning
);
770 if vsync
then e_WriteLog('VSync: ON', TMsgType
.Notify
) else e_WriteLog('VSync: OFF', TMsgType
.Notify
);
776 procedure InitOpenGL ();
778 {$IF not DEFINED(HEADLESS)}
779 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION
, 2);
780 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION
, 1);
781 SDL_GL_SetAttribute(SDL_GL_RED_SIZE
, 8);
782 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE
, 8);
783 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE
, 8);
784 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE
, 16);
785 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER
, 1);
786 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE
, 8); // lights; it is enough to have 1-bit stencil buffer for lighting, but...
791 function glHasExtension (const name
: AnsiString): Boolean;
796 extName
: ShortString;
799 if (Length(name
) = 0) then exit
;
800 exts
:= glGetString(GL_EXTENSIONS
);
801 if (exts
= nil) then exit
;
802 while (exts
[0] <> #0) and (exts
[0] = ' ') do Inc(exts
);
803 while (exts
[0] <> #0) do
805 if gwin_dump_extensions
then
808 while (exts
[i
] <> #0) and (exts
[i
] <> ' ') do Inc(i
);
811 e_WriteLog('FUUUUUUUUUUUUU', TMsgType
.Warning
);
815 Move(exts
^, extName
[1], i
);
816 extName
[0] := Char(i
);
817 e_WriteLog(Format('EXT: %s', [extName
]), TMsgType
.Notify
);
821 for i
:= 0 to length(name
)-1 do
823 if (exts
[i
] = #0) then begin found
:= false; break
; end;
824 if (exts
[i
] <> name
[i
+1]) then begin found
:= false; break
; end;
826 if found
and ((exts
[Length(name
)] = #0) or (exts
[Length(name
)] = ' ')) then begin result
:= true; exit
; end;
827 while (exts
[0] <> #0) and (exts
[0] <> ' ') do Inc(exts
);
828 while (exts
[0] <> #0) and (exts
[0] = ' ') do Inc(exts
);
833 function SDLMain (): Integer;
836 {$IF not DEFINED(HEADLESS)}
845 e_NoGraphics
:= true;
847 if (not g_holmes_imfunctional
) then
850 uiContext
.font
:= 'win14';
855 while (idx
<= ParamCount
) do
857 arg
:= ParamStr(idx
);
859 if arg
= '--opengl-dump-exts' then gwin_dump_extensions
:= true;
860 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
861 if arg
= '--jah' then g_profile_history_size
:= 100;
862 if arg
= '--no-particles' then gpart_dbg_enabled
:= false;
863 if arg
= '--no-los' then gmon_dbg_los_enabled
:= false;
865 if arg
= '--profile-render' then g_profile_frame_draw
:= true;
866 if arg
= '--profile-coldet' then g_profile_collision
:= true;
867 if arg
= '--profile-los' then g_profile_los
:= true;
869 if arg
= '--no-part-phys' then gpart_dbg_phys_enabled
:= false;
870 if arg
= '--no-part-physics' then gpart_dbg_phys_enabled
:= false;
871 if arg
= '--no-particles-phys' then gpart_dbg_phys_enabled
:= false;
872 if arg
= '--no-particles-physics' then gpart_dbg_phys_enabled
:= false;
873 if arg
= '--no-particle-phys' then gpart_dbg_phys_enabled
:= false;
874 if arg
= '--no-particle-physics' then gpart_dbg_phys_enabled
:= false;
876 {.$IF DEFINED(D2F_DEBUG)}
877 if arg
= '--aimline' then g_dbg_aimline_on
:= true;
880 if arg
= '--holmes' then begin g_holmes_enabled
:= true; g_Game_SetDebugMode(); end;
882 if (arg
= '--holmes-ui-scale') or (arg
= '-holmes-ui-scale') then
884 if (idx
<= ParamCount
) then
886 if not conParseFloat(fuiRenderScale
, ParamStr(idx
)) then fuiRenderScale
:= 1.0;
891 if (arg
= '--holmes-font') or (arg
= '-holmes-font') then
893 if (idx
<= ParamCount
) then
896 val(ParamStr(idx
), itmp
, valres
);
898 if (valres
= 0) and (not g_holmes_imfunctional
) then
901 8: uiContext
.font
:= 'win8';
902 14: uiContext
.font
:= 'win14';
903 16: uiContext
.font
:= 'win16';
915 if (arg
= '--game-scale') or (arg
= '-game-scale') then
917 if (idx
<= ParamCount
) then
919 if not conParseFloat(g_dbg_scale
, ParamStr(idx
)) then g_dbg_scale
:= 1.0;
924 if (arg
= '--write-mapdef') or (arg
= '-write-mapdef') then
926 mdfo
:= createDiskFile('mapdef.txt');
927 mdfo
.WriteBuffer(defaultMapDef
[1], Length(defaultMapDef
));
933 e_WriteLog('Initializing OpenGL', TMsgType
.Notify
);
936 e_WriteLog('Creating GL window', TMsgType
.Notify
);
937 if not CreateGLWindow(PChar(Format('Doom 2D: Forever %s', [GAME_VERSION
]))) then
943 {EnumDisplayModes();}
946 //gwin_k8_enable_light_experiments := false;
947 gwin_has_stencil
:= false;
948 glLegacyNPOT
:= false;
949 gwin_dump_extensions
:= false;
951 SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE
, @ltmp
);
952 e_LogWritefln('stencil buffer size: %s', [ltmp
]);
953 gwin_has_stencil
:= (ltmp
> 0);
955 if not glHasExtension('GL_ARB_texture_non_power_of_two') then
957 e_WriteLog('NPOT textures: NO', TMsgType
.Warning
);
958 glLegacyNPOT
:= true;
962 e_WriteLog('NPOT textures: YES', TMsgType
.Notify
);
963 glLegacyNPOT
:= false;
965 gwin_dump_extensions
:= false;
969 Time_Old
:= GetTimer();
972 if (ParamCount
> 0) then g_Game_Process_Params();
975 if (not gGameOn
) and gAskLanguage
then g_Menu_AskLanguage();
977 e_WriteLog('Entering the main loop', TMsgType
.Notify
);
980 while not ProcessMessage() do begin end;