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 (gPlayer1
<> nil) then gPlayer1
.releaseAllWeaponSwitchKeys();
318 if (gPlayer2
<> nil) then gPlayer2
.releaseAllWeaponSwitchKeys();
319 if not wMinimized
then
321 e_ResizeWindow(0, 0);
323 if g_debug_WinMsgs
then
325 g_Console_Add('Now minimized');
326 e_WriteLog('[DEBUG] WinMsgs: Now minimized', TMsgType
.Notify
);
332 SDL_WINDOWEVENT_RESIZED
:
334 e_LogWritefln('Resize: (os=%dx%d) (ns=%dx%d)', [gScreenWidth
, gScreenHeight
, Integer(ev
.data1
), Integer(ev
.data2
)]);
335 {if (gFullscreen) then
337 e_LogWriteln(' fullscreen fix applied.');
338 if (gScreenWidth <> ev.data1) or (gScreenHeight <> ev.data2) then
340 SDL_SetWindowSize(h_Wnd, gScreenWidth, gScreenHeight);
345 gScreenWidth
:= ev
.data1
;
346 gScreenHeight
:= ev
.data2
;
348 ChangeWindowSize(false);
350 if g_debug_WinMsgs
then
352 g_Console_Add('Resized to ' + IntToStr(ev
.data1
) + 'x' + IntToStr(ev
.data2
));
353 e_WriteLog('[DEBUG] WinMsgs: Resized to ' + IntToStr(ev
.data1
) + 'x' + IntToStr(ev
.data2
), TMsgType
.Notify
);
357 SDL_WINDOWEVENT_EXPOSED
:
360 SDL_WINDOWEVENT_MAXIMIZED
:
365 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
369 if (not gWinMaximized
) and (not gFullscreen
) then
371 gWinMaximized
:= true;
372 if g_debug_WinMsgs
then
374 g_Console_Add('Now maximized');
375 e_WriteLog('[DEBUG] WinMsgs: Now maximized', TMsgType
.Notify
);
380 SDL_WINDOWEVENT_RESTORED
:
385 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
389 gWinMaximized
:= false;
390 if g_debug_WinMsgs
then
392 g_Console_Add('Now restored');
393 e_WriteLog('[DEBUG] WinMsgs: Now restored', TMsgType
.Notify
);
397 SDL_WINDOWEVENT_FOCUS_GAINED
:
400 //e_WriteLog('window gained focus!', MSG_NOTIFY);
403 SDL_WINDOWEVENT_FOCUS_LOST
:
407 if (gPlayer1
<> nil) then gPlayer1
.releaseAllWeaponSwitchKeys();
408 if (gPlayer2
<> nil) then gPlayer2
.releaseAllWeaponSwitchKeys();
409 //e_WriteLog('window lost focus!', MSG_NOTIFY);
417 e_WriteLog('deactivating window', TMsgType
.Notify
);
418 e_EnableInput
:= false;
419 e_ClearInputBuffer();
421 if gMuteWhenInactive
then
423 //e_WriteLog('deactivating sounds', MSG_NOTIFY);
424 e_MuteChannels(true);
427 if g_debug_WinMsgs
then
429 g_Console_Add('Now inactive');
430 e_WriteLog('[DEBUG] WinMsgs: Now inactive', TMsgType
.Notify
);
435 {$IFDEF ENABLE_HOLMES}
436 if assigned(winBlurCB
) then winBlurCB();
440 else if wActivate
then
442 if not gWinActive
then
444 //e_WriteLog('activating window', MSG_NOTIFY);
445 e_EnableInput
:= true;
447 if gMuteWhenInactive
then
449 //e_WriteLog('activating sounds', MSG_NOTIFY);
450 e_MuteChannels(false);
453 if g_debug_WinMsgs
then
455 g_Console_Add('Now active');
456 e_WriteLog('[DEBUG] WinMsgs: Now active', TMsgType
.Notify
);
461 {$IFDEF ENABLE_HOLMES}
462 if assigned(winFocusCB
) then winFocusCB();
469 function EventHandler (var ev
: TSDL_Event
): Boolean;
479 result
:= WindowEventHandler(ev
.window
);
483 if (gExit
<> EXIT_QUIT
) then
485 if not wLoadingProgress
then
492 wLoadingQuit
:= true;
498 SDL_KEYDOWN
, SDL_KEYUP
:
500 key
:= ev
.key
.keysym
.scancode
;
501 if key
= SDL_SCANCODE_AC_BACK
then
502 key
:= SDL_SCANCODE_ESCAPE
;
503 down
:= (ev
.type_
= SDL_KEYDOWN
);
504 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
505 if fuiOnSDLEvent(ev
) then
507 // event eaten, but...
508 if not down
then e_KeyUpDown(key
, false);
512 e_KeyUpDown(key
, down
);
513 if down
then KeyPress(key
);
516 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
517 SDL_MOUSEBUTTONDOWN
, SDL_MOUSEBUTTONUP
, SDL_MOUSEWHEEL
, SDL_MOUSEMOTION
:
523 Utf8ToUnicode(@uc
, PChar(ev
.text.text), 1);
525 if (keychr
> 127) then keychr
:= Word(wchar2win(WideChar(keychr
)));
526 if (keychr
> 0) and (keychr
<= 255) then CharPress(AnsiChar(keychr
));
529 SDL_FINGERMOTION
, SDL_FINGERDOWN
, SDL_FINGERUP
:
530 g_Touch_HandleEvent(ev
.tfinger
);
532 // other key presses and joysticks are handled in e_input
537 procedure SwapBuffers ();
539 {$IF not DEFINED(HEADLESS)}
540 SDL_GL_SwapWindow(h_Wnd
);
545 function CreateGLWindow (Title
: PChar
): Boolean;
549 gWinSizeX
:= gScreenWidth
;
550 gWinSizeY
:= gScreenHeight
;
552 {$IF not DEFINED(HEADLESS)}
555 e_WriteLog('Creating window', TMsgType
.Notify
);
557 if not g_Window_SetDisplay() then
560 e_WriteLog('Window creation error (resolution not supported?)', TMsgType
.Fatal
);
564 {$IF not DEFINED(HEADLESS)}
565 h_GL
:= SDL_GL_CreateContext(h_Wnd
);
566 if (h_GL
= nil) then exit
;
567 {$IFDEF ENABLE_HOLMES}
568 fuiScrWdt
:= gScreenWidth
;
569 fuiScrHgt
:= gScreenHeight
;
571 SDL_GL_MakeCurrent(h_Wnd
, h_GL
);
573 if nanoGL_Init() = 0 then
576 e_WriteLog('nanoGL initialization error', TMsgType
.Fatal
);
583 {$IFDEF ENABLE_HOLMES}
584 if (assigned(oglInitCB
)) then oglInitCB();
586 if (h_GL
<> nil) then g_SetVSync(gVSync
);
589 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
597 // windoze sux; in headless mode `GetTickCount()` (and SDL) returns shit
598 function GetTimer (): Int64;
602 QueryPerformanceFrequency(F
);
603 QueryPerformanceCounter(C
);
604 result
:= Round(C
/F
*1000{000});
607 function GetTimer (): Int64;
613 if (ticksOverflow
= -1) then
620 if (lastTicks
> t
) then
622 // overflow, increment overflow ;-)
623 ticksOverflow
:= ticksOverflow
+(Int64($ffffffff)+Int64(1));
624 tt
:= (Int64($ffffffff)+Int64(1))+Int64(t
);
625 t
:= Uint32(tt
-lastTicks
);
629 result
:= ticksOverflow
+Int64(t
);
634 procedure ResetTimer ();
636 wNeedTimeReset
:= true;
640 procedure PushExitEvent ();
644 ev
.type_
:= SDL_QUITEV
;
650 prevLoadingUpdateTime
: UInt64
= 0;
652 procedure ProcessLoading (forceUpdate
: Boolean=false);
658 FillChar(ev
, sizeof(ev
), 0);
659 wLoadingProgress
:= true;
661 while (SDL_PollEvent(@ev
) > 0) do
664 if (ev
.type_
= SDL_QUITEV
) then break
;
668 if (ev
.type_
= SDL_QUITEV
) or (gExit
= EXIT_QUIT
) then
670 wLoadingProgress
:= false;
674 if not wMinimized
then
678 prevLoadingUpdateTime
:= getTimeMilli();
682 stt
:= getTimeMilli();
683 if (stt
< prevLoadingUpdateTime
) or (stt
-prevLoadingUpdateTime
>= ProgressUpdateMSecs
) then
685 prevLoadingUpdateTime
:= stt
;
692 if g_Texture_Get('INTER', ID
) then
694 e_DrawSize(ID
, 0, 0, 0, false, false, gScreenWidth
, gScreenHeight
);
695 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
699 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
709 if NetMode
= NET_SERVER
then
715 if (NetMode
= NET_CLIENT
) and (NetState
<> NET_STATE_AUTH
) then g_Net_Client_UpdateWhileLoading();
718 wLoadingProgress
:= false;
722 function g_ProcessMessages (): Boolean;
727 FillChar(ev
, SizeOf(ev
), 0);
728 while (SDL_PollEvent(@ev
) > 0) do
730 result
:= EventHandler(ev
);
731 if (ev
.type_
= SDL_QUITEV
) then exit
;
737 function ProcessMessage (): Boolean;
741 result
:= g_ProcessMessages();
744 Time_Delta
:= Time
-Time_Old
;
748 if wNeedTimeReset
then
751 wNeedTimeReset
:= false;
754 g_Map_ProfilersBegin();
755 g_Mons_ProfilersBegin();
757 t
:= Time_Delta
div 28;
763 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
764 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
770 if (NetMode
= NET_SERVER
) then g_Net_Host_Update()
771 else if (NetMode
= NET_CLIENT
) then g_Net_Client_Update();
774 g_Map_ProfilersEnd();
775 g_Mons_ProfilersEnd();
783 if (gExit
= EXIT_QUIT
) then
789 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ
792 Time_Old
:= Time
-(Time_Delta
mod 28);
793 if (not wMinimized
) then
801 Sleep(1); // release time slice, so we won't eat 100% CPU
808 procedure ReDrawWindow ();
814 procedure g_SetVSync (vsync
: Boolean);
815 {$IF not DEFINED(HEADLESS)}
820 {$IF not DEFINED(HEADLESS)}
821 if vsync
then v
:= 1 else v
:= 0;
822 if (SDL_GL_SetSwapInterval(v
) <> 0) then
824 e_WriteLog('oops; can''t change vsync option, restart required', TMsgType
.Warning
);
828 if vsync
then e_WriteLog('VSync: ON', TMsgType
.Notify
) else e_WriteLog('VSync: OFF', TMsgType
.Notify
);
834 procedure InitOpenGL ();
836 {$IF not DEFINED(HEADLESS)}
838 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION
, 1);
839 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION
, 1);
840 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK
, SDL_GL_CONTEXT_PROFILE_ES
);
842 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION
, 2);
843 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION
, 1);
844 SDL_GL_SetAttribute(SDL_GL_RED_SIZE
, 8);
845 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE
, 8);
846 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE
, 8);
847 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE
, 16);
848 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER
, 1);
849 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE
, 8); // lights; it is enough to have 1-bit stencil buffer for lighting, but...
855 function glHasExtension (const name
: AnsiString
): Boolean;
860 extName
: ShortString
;
863 if (Length(name
) = 0) then exit
;
864 exts
:= glGetString(GL_EXTENSIONS
);
865 if (exts
= nil) then exit
;
866 while (exts
[0] <> #0) and (exts
[0] = ' ') do Inc(exts
);
867 while (exts
[0] <> #0) do
869 if gwin_dump_extensions
then
872 while (exts
[i
] <> #0) and (exts
[i
] <> ' ') do Inc(i
);
875 e_WriteLog('FUUUUUUUUUUUUU', TMsgType
.Warning
);
879 Move(exts
^, extName
[1], i
);
880 extName
[0] := Char(i
);
881 e_WriteLog(Format('EXT: %s', [extName
]), TMsgType
.Notify
);
885 for i
:= 0 to length(name
)-1 do
887 if (exts
[i
] = #0) then begin found
:= false; break
; end;
888 if (exts
[i
] <> name
[i
+1]) then begin found
:= false; break
; end;
890 if found
and ((exts
[Length(name
)] = #0) or (exts
[Length(name
)] = ' ')) then begin result
:= true; exit
; end;
891 while (exts
[0] <> #0) and (exts
[0] <> ' ') do Inc(exts
);
892 while (exts
[0] <> #0) and (exts
[0] = ' ') do Inc(exts
);
897 function SDLMain (): Integer;
900 {$IF not DEFINED(HEADLESS)}
905 {$IFDEF ENABLE_HOLMES}
911 e_NoGraphics
:= true;
913 {$IFDEF ENABLE_HOLMES}
914 if (not g_holmes_imfunctional
) then
917 uiContext
.font
:= 'win14';
923 while (idx
<= ParamCount
) do
925 arg
:= ParamStr(idx
);
927 if arg
= '--opengl-dump-exts' then gwin_dump_extensions
:= true;
928 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
929 if arg
= '--jah' then g_profile_history_size
:= 100;
930 if arg
= '--no-particles' then gpart_dbg_enabled
:= false;
931 if arg
= '--no-los' then gmon_dbg_los_enabled
:= false;
933 if arg
= '--profile-render' then g_profile_frame_draw
:= true;
934 if arg
= '--profile-coldet' then g_profile_collision
:= true;
935 if arg
= '--profile-los' then g_profile_los
:= true;
937 if arg
= '--no-part-phys' then gpart_dbg_phys_enabled
:= false;
938 if arg
= '--no-part-physics' then gpart_dbg_phys_enabled
:= false;
939 if arg
= '--no-particles-phys' then gpart_dbg_phys_enabled
:= false;
940 if arg
= '--no-particles-physics' then gpart_dbg_phys_enabled
:= false;
941 if arg
= '--no-particle-phys' then gpart_dbg_phys_enabled
:= false;
942 if arg
= '--no-particle-physics' then gpart_dbg_phys_enabled
:= false;
944 {.$IF DEFINED(D2F_DEBUG)}
945 if arg
= '--aimline' then g_dbg_aimline_on
:= true;
948 {$IFDEF ENABLE_HOLMES}
949 if arg
= '--holmes' then begin g_holmes_enabled
:= true; g_Game_SetDebugMode(); end;
951 if (arg
= '--holmes-ui-scale') or (arg
= '-holmes-ui-scale') then
953 if (idx
<= ParamCount
) then
955 if not conParseFloat(fuiRenderScale
, ParamStr(idx
)) then fuiRenderScale
:= 1.0;
960 if (arg
= '--holmes-font') or (arg
= '-holmes-font') then
962 if (idx
<= ParamCount
) then
965 val(ParamStr(idx
), itmp
, valres
);
967 if (valres
= 0) and (not g_holmes_imfunctional
) then
970 8: uiContext
.font
:= 'win8';
971 14: uiContext
.font
:= 'win14';
972 16: uiContext
.font
:= 'win16';
985 if (arg
= '--game-scale') or (arg
= '-game-scale') then
987 if (idx
<= ParamCount
) then
989 if not conParseFloat(g_dbg_scale
, ParamStr(idx
)) then g_dbg_scale
:= 1.0;
994 if (arg
= '--write-mapdef') or (arg
= '-write-mapdef') then
996 mdfo
:= createDiskFile('mapdef.txt');
997 mdfo
.WriteBuffer(defaultMapDef
[1], Length(defaultMapDef
));
1003 e_WriteLog('Initializing OpenGL', TMsgType
.Notify
);
1006 e_WriteLog('Creating GL window', TMsgType
.Notify
);
1007 if not CreateGLWindow(PChar(Format('Doom 2D: Forever %s', [GAME_VERSION
]))) then
1010 e_WriteLog('Unable to create GL window: ' + SDL_GetError(), TMsgType
.Fatal
);
1014 {EnumDisplayModes();}
1017 //gwin_k8_enable_light_experiments := false;
1018 gwin_has_stencil
:= false;
1019 glLegacyNPOT
:= false;
1020 gwin_dump_extensions
:= false;
1022 SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE
, @ltmp
);
1023 e_LogWritefln('stencil buffer size: %s', [ltmp
]);
1024 gwin_has_stencil
:= (ltmp
> 0);
1026 if glHasExtension('GL_ARB_texture_non_power_of_two') or
1027 glHasExtension('GL_OES_texture_npot') then
1029 e_WriteLog('NPOT textures: YES', TMsgType
.Notify
);
1030 glLegacyNPOT
:= false;
1034 e_WriteLog('NPOT textures: NO', TMsgType
.Warning
);
1035 glLegacyNPOT
:= true;
1037 gwin_dump_extensions
:= false;
1041 Time_Old
:= GetTimer();
1044 if (ParamCount
> 0) then g_Game_Process_Params();
1047 if (not gGameOn
) and gAskLanguage
then g_Menu_AskLanguage();
1049 e_WriteLog('Entering the main loop', TMsgType
.Notify
);
1052 while not ProcessMessage() do begin end;
1055 KillGLWindow(false);