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, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 function PerformExecution (): Integer;
24 procedure ResetTimer ();
25 procedure ProcessLoading (forceUpdate
: Boolean = False);
28 gwin_has_stencil
: Boolean = false;
29 gwin_k8_enable_light_experiments
: Boolean = false;
30 g_dbg_aimline_on
: Boolean = false;
31 g_dbg_input
: Boolean = False;
36 {$IFDEF WINDOWS}Windows
,{$ENDIF}
37 {$IFDEF ENABLE_HOLMES}
38 g_holmes
, sdlcarcass
, fui_ctls
,
40 {$INCLUDE ../nogl/noGLuses.inc}
41 SysUtils
, Classes
, MAPDEF
, Math
,
42 e_graphics
, e_log
, e_texture
, g_main
,
43 g_console
, e_input
, g_options
, g_game
,
44 g_basic
, g_textures
, e_sound
, g_sound
, g_menu
, ENet
, g_net
,
45 g_map
, g_gfx
, g_monsters
, xprofiler
,
46 g_touch
, g_gui
, g_system
, g_netmaster
;
50 ProgressUpdateMSecs
= 35; //1;//100;
53 Time
, Time_Delta
, Time_Old
: Int64;
56 wNeedTimeReset
: Boolean = false;
57 wMinimized
: Boolean = false;
59 procedure ResetTimer ();
61 wNeedTimeReset
:= true;
66 prevLoadingUpdateTime
: UInt64
= 0;
69 procedure ProcessLoading (forceUpdate
: Boolean);
75 if sys_HandleEvents() then
79 if not wMinimized
then
81 if not forceUpdate
then
83 stt
:= getTimeMilli();
84 forceUpdate
:= (stt
< prevLoadingUpdateTime
) or (stt
-prevLoadingUpdateTime
>= ProgressUpdateMSecs
);
89 e_SetRendertarget(True);
90 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
92 DrawMenuBackground('INTER');
93 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
97 e_SetRendertarget(False);
98 e_SetViewPort(0, 0, gWinSizeX
, gWinSizeY
);
99 e_BlitFramebuffer(gWinSizeX
, gWinSizeY
);
102 prevLoadingUpdateTime
:= getTimeMilli();
109 // TODO: At the moment, I left here only host network processing, because the client code must
110 // handle network events on its own. Otherwise separate network cases that use different calls to
111 // enet_host_service() WILL lose their packets (for example, resource downloading). So they have
112 // to handle everything by themselves. But in general, this MUST be removed completely, since
113 // updating the window should never affect the network. Use single enet_host_service(), period.
114 if NetMode
= NET_SERVER
115 then g_Net_Host_Update();
119 function ProcessMessage (): Boolean;
123 // BEWARE: Short-circuit evaluation matters here!
124 Result
:= (gExit
= EXIT_QUIT
) or sys_HandleEvents();
132 Time
:= sys_GetTicks();
133 Time_Delta
:= Time
-Time_Old
;
137 if wNeedTimeReset
then
141 wNeedTimeReset
:= false;
144 g_Map_ProfilersBegin();
145 g_Mons_ProfilersBegin();
147 t
:= Time_Delta
div 28;
155 g_Map_ProfilersEnd();
156 g_Mons_ProfilersEnd();
158 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ
160 Time_Old
:= Time
- (Time_Delta
mod 28);
162 // don't wait if VSync is on, GL already probably waits enough
164 flag
:= (Time
- Frame
>= gFrameTime
) or gVSync
;
168 if (not wMinimized
) then
170 if gPause
or (not gLerpActors
) or (gState
= STATE_FOLD
) then
173 gLerpFactor
:= nmin(1.0, (Time
- Time_Old
) / 28.0);
185 function GLExtensionList (): SSArray
;
191 s
:= glGetString(GL_EXTENSIONS
);
197 while (s
[i
] <> #0) and (s
[i
] = ' ') do Inc(i
);
198 while (s
[i
] <> #0) do
200 while (s
[i
] <> #0) and (s
[i
] <> ' ') do Inc(i
);
201 SetLength(result
, num
+1);
202 result
[num
] := Copy(s
, j
+1, i
-j
);
203 while (s
[i
] <> #0) and (s
[i
] = ' ') do Inc(i
);
210 function GLExtensionSupported (ext
: AnsiString
): Boolean;
216 exts
:= GLExtensionList();
219 //writeln('<', e, '> : [', ext, '] = ', strEquCI1251(e, ext));
220 if (strEquCI1251(e
, ext
)) then begin result
:= true; exit
; end;
224 procedure PrintGLSupportedExtensions
;
226 e_LogWritefln('GL Vendor: %s', [glGetString(GL_VENDOR
)]);
227 e_LogWritefln('GL Renderer: %s', [glGetString(GL_RENDERER
)]);
228 e_LogWritefln('GL Version: %s', [glGetString(GL_VERSION
)]);
229 e_LogWritefln('GL Shaders: %s', [glGetString(GL_SHADING_LANGUAGE_VERSION
)]);
230 e_LogWritefln('GL Extensions: %s', [glGetString(GL_EXTENSIONS
)]);
233 function PerformExecution (): Integer;
238 {$IFDEF ENABLE_HOLMES}
244 e_NoGraphics
:= true;
248 while (idx
<= ParamCount
) do
250 arg
:= ParamStr(idx
);
252 if arg
= '--jah' then g_profile_history_size
:= 100;
253 if arg
= '--no-particles' then gpart_dbg_enabled
:= false;
254 if arg
= '--no-los' then gmon_dbg_los_enabled
:= false;
256 if arg
= '--profile-render' then g_profile_frame_draw
:= true;
257 if arg
= '--profile-coldet' then g_profile_collision
:= true;
258 if arg
= '--profile-los' then g_profile_los
:= true;
260 if arg
= '--no-part-phys' then gpart_dbg_phys_enabled
:= false;
261 if arg
= '--no-part-physics' then gpart_dbg_phys_enabled
:= false;
262 if arg
= '--no-particles-phys' then gpart_dbg_phys_enabled
:= false;
263 if arg
= '--no-particles-physics' then gpart_dbg_phys_enabled
:= false;
264 if arg
= '--no-particle-phys' then gpart_dbg_phys_enabled
:= false;
265 if arg
= '--no-particle-physics' then gpart_dbg_phys_enabled
:= false;
267 if arg
= '--debug-input' then g_dbg_input
:= True;
269 {.$IF DEFINED(D2F_DEBUG)}
270 if arg
= '--aimline' then g_dbg_aimline_on
:= true;
273 {$IFDEF ENABLE_HOLMES}
274 if arg
= '--holmes' then begin g_holmes_enabled
:= true; g_Game_SetDebugMode(); end;
276 if (arg
= '--holmes-ui-scale') or (arg
= '-holmes-ui-scale') then
278 if (idx
<= ParamCount
) then
280 if not conParseFloat(fuiRenderScale
, ParamStr(idx
)) then fuiRenderScale
:= 1.0;
285 if (arg
= '--holmes-font') or (arg
= '-holmes-font') then
287 if (idx
<= ParamCount
) then
290 val(ParamStr(idx
), itmp
, valres
);
292 if (valres
= 0) and (not g_holmes_imfunctional
) then
295 8: uiContext
.font
:= 'win8';
296 14: uiContext
.font
:= 'win14';
297 16: uiContext
.font
:= 'win16';
310 if (arg
= '--game-scale') or (arg
= '-game-scale') then
312 if (idx
<= ParamCount
) then
314 if not conParseFloat(g_dbg_scale
, ParamStr(idx
)) then g_dbg_scale
:= 1.0;
319 if (arg
= '--write-mapdef') or (arg
= '-write-mapdef') then
321 mdfo
:= createDiskFile('mapdef.txt');
322 mdfo
.WriteBuffer(defaultMapDef
[1], Length(defaultMapDef
));
327 if (arg
= '--pixel-scale') or (arg
= '-pixel-scale') then
329 if (idx
<= ParamCount
) then
331 if not conParseFloat(r_pixel_scale
, ParamStr(idx
)) then r_pixel_scale
:= 1.0;
337 {$IFNDEF USE_SYSSTUB}
338 PrintGLSupportedExtensions
;
339 glLegacyNPOT
:= not (GLExtensionSupported('GL_ARB_texture_non_power_of_two') or GLExtensionSupported('GL_OES_texture_npot'));
341 glLegacyNPOT
:= False;
342 glRenderToFBO
:= False;
344 if glNPOTOverride
and glLegacyNPOT
then
346 glLegacyNPOT
:= true;
347 e_logWriteln('NPOT texture emulation: FORCED');
351 if (glLegacyNPOT
) then e_logWriteln('NPOT texture emulation: enabled')
352 else e_logWriteln('NPOT texture emulation: disabled');
356 Time_Old
:= sys_GetTicks();
358 g_Net_InitLowLevel();
361 if (ParamCount
> 0) then g_Game_Process_Params();
365 if (not gGameOn
) and gAskLanguage
then g_Menu_AskLanguage();
368 e_WriteLog('Entering the main loop', TMsgType
.Notify
);
371 repeat until ProcessMessage();
373 g_Net_Slist_ShutdownAll();
377 g_Net_DeinitLowLevel();
383 conRegVar('d_input', @g_dbg_input
, '', '')