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}
16 {$IFDEF ANDROID}library{$ELSE}program{$ENDIF} Doom2DF;
35 mempool in '../shared/mempool.pas',
36 conbuf in '../shared/conbuf.pas',
37 geom in '../shared/geom.pas',
40 {$IFDEF USE_MINIUPNPC}
41 miniupnpc in '../lib/miniupnpc/miniupnpc.pas',
45 SDL in '../lib/sdl/sdl.pas',
47 SDL_mixer in '../lib/sdl/sdl_mixer.pas',
51 SDL2 in '../lib/sdl2/sdl2.pas',
53 SDL2_mixer in '../lib/sdl2/SDL2_mixer.pas',
58 SDL2 in '../lib/sdl2/sdl2.pas',
59 SDL2_mixer in '../lib/sdl2/SDL2_mixer.pas',
64 AL in '../lib/openal/al.pas',
65 e_soundfile in '../engine/e_soundfile.pas',
66 {$IF DEFINED(USE_SDL) OR DEFINED(USE_SDL2)}
67 e_soundfile_wav in '../engine/e_soundfile_wav.pas',
70 vorbis in '../lib/vorbis/vorbis.pas',
71 e_soundfile_vorbis in '../engine/e_soundfile_vorbis.pas',
73 {$IFDEF USE_FLUIDSYNTH}
74 fluidsynth in '../lib/fluidsynth/fluidsynth.pas',
75 e_soundfile_fluid in '../engine/e_soundfile_fluid.pas',
78 modplug in '../lib/modplug/modplug.pas',
79 e_soundfile_modplug in '../engine/e_soundfile_modplug.pas',
82 xmp in '../lib/xmp/xmp.pas',
83 e_soundfile_xmp in '../engine/e_soundfile_xmp.pas',
86 gme in '../lib/gme/gme.pas',
87 e_soundfile_gme in '../engine/e_soundfile_gme.pas',
90 mpg123 in '../lib/mpg123/mpg123.pas',
91 e_soundfile_mp3 in '../engine/e_soundfile_mp3.pas',
94 opus in '../lib/opus/opus.pas',
95 e_soundfile_opus in '../engine/e_soundfile_opus.pas',
97 {$IF DEFINED(USE_VORBIS) OR DEFINED(USE_OPUS)}
98 ogg in '../lib/vorbis/ogg.pas', // this has to come last because link order
102 ENet in '../lib/enet/enet.pp',
103 e_input in '../engine/e_input.pas',
104 e_log in '../engine/e_log.pas',
105 e_sound in '../engine/e_sound.pas',
106 e_msg in '../engine/e_msg.pas',
107 e_res in '../engine/e_res.pas',
108 utils in '../shared/utils.pas',
109 xstreams in '../shared/xstreams.pas',
110 sfs in '../sfs/sfs.pas',
111 sfsPlainFS in '../sfs/sfsPlainFS.pas',
112 sfsZipFS in '../sfs/sfsZipFS.pas',
113 wadreader in '../shared/wadreader.pas',
114 MAPDEF in '../shared/MAPDEF.pas',
115 CONFIG in '../shared/CONFIG.pas',
116 g_base in 'g_base.pas',
117 g_basic in 'g_basic.pas',
118 g_console in 'g_console.pas',
119 g_net in 'g_net.pas',
120 g_netmsg in 'g_netmsg.pas',
121 g_nethandler in 'g_nethandler.pas',
122 g_netmaster in 'g_netmaster.pas',
123 g_res_downloader in 'g_res_downloader.pas',
124 g_grid in 'g_grid.pas',
125 g_game in 'g_game.pas',
127 g_gfx in 'g_gfx.pas',
130 g_gibs in 'g_gibs.pas',
132 {$IFDEF ENABLE_SHELLS}
133 g_shells in 'g_shells.pas',
135 {$IFDEF ENABLE_CORPSES}
136 g_corpses in 'g_corpses.pas',
138 g_items in 'g_items.pas',
139 g_map in 'g_map.pas',
140 g_monsters in 'g_monsters.pas',
141 g_options in 'g_options.pas',
142 g_phys in 'g_phys.pas',
143 g_player in 'g_player.pas',
144 g_playermodel in 'g_playermodel.pas',
145 g_saveload in 'g_saveload.pas',
146 g_sound in 'g_sound.pas',
147 g_animations in 'g_animations.pas',
148 g_triggers in 'g_triggers.pas',
149 g_weapons in 'g_weapons.pas',
150 g_window in 'g_window.pas',
152 {$IFDEF ENABLE_SYSTEM}
154 g_system in 'stub/g_system.pas',
157 g_system in 'sdl/g_system.pas',
160 g_system in 'sdl2/g_system.pas',
165 g_gui in 'g_gui.pas',
166 g_menu in 'g_menu.pas',
169 {$IFDEF ENABLE_RENDER}
170 {$IF DEFINED(USE_OPENGL) OR DEFINED(USE_GLES1) OR DEFINED(USE_GLSTUB)}
171 {$I ../shared/vampimg.inc}
172 r_animations in 'opengl/r_animations.pas',
173 r_console in 'opengl/r_console.pas',
174 r_game in 'opengl/r_game.pas',
176 r_gfx in 'opengl/r_gfx.pas',
178 r_graphics in 'opengl/r_graphics.pas',
179 r_items in 'opengl/r_items.pas',
180 r_map in 'opengl/r_map.pas',
181 r_monsters in 'opengl/r_monsters.pas',
182 r_netmaster in 'opengl/r_netmaster.pas',
183 r_player in 'opengl/r_player.pas',
184 r_playermodel in 'opengl/r_playermodel.pas',
185 r_render in 'opengl/r_render.pas',
186 r_texture in 'opengl/r_texture.pas',
187 r_textures in 'opengl/r_textures.pas',
188 r_weapons in 'opengl/r_weapons.pas',
189 r_window in 'opengl/r_window.pas',
190 {$IFDEF ENABLE_TOUCH}
191 r_touch in 'opengl/r_touch.pas',
194 r_gui in 'opengl/r_gui.pas',
196 {$ELSEIF DEFINED(USE_STUBRENDER)}
197 r_render in 'renders/stub/r_render.pas',
198 {$ELSEIF DEFINED(USE_NEWGL)}
199 {$I ../shared/vampimg.inc}
200 r_render in 'renders/opengl/r_render.pas',
201 r_atlas in 'renders/opengl/r_atlas.pas',
202 r_textures in 'renders/opengl/r_textures.pas',
203 r_draw in 'renders/opengl/r_draw.pas',
204 r_map in 'renders/opengl/r_map.pas',
205 r_fonts in 'renders/opengl/r_fonts.pas',
206 r_common in 'renders/opengl/r_common.pas',
207 r_console in 'renders/opengl/r_console.pas',
208 r_gui in 'renders/opengl/r_gui.pas',
209 r_loadscreen in 'renders/opengl/r_loadscreen.pas',
211 {$FATAL render driver not selected}
216 fmod in '../lib/FMOD/fmod.pas',
217 fmoderrors in '../lib/FMOD/fmoderrors.pas',
218 fmodpresets in '../lib/FMOD/fmodpresets.pas',
219 fmodtypes in '../lib/FMOD/fmodtypes.pas',
221 xprofiler in '../shared/xprofiler.pas',
222 binheap in '../shared/binheap.pas',
223 hashtable in '../shared/hashtable.pas',
224 fhashdb in '../shared/fhashdb.pas',
225 idpool in '../shared/idpool.pas',
226 xparser in '../shared/xparser.pas',
227 xdynrec in '../shared/xdynrec.pas',
228 exoma in '../shared/exoma.pas',
229 envvars in '../shared/envvars.pas',
230 g_panel in 'g_panel.pas',
231 g_language in 'g_language.pas',
233 {$IFDEF ENABLE_HOLMES}
234 g_holmes in 'g_holmes.pas',
236 sdlcarcass in '../flexui/sdlcarcass.pas',
237 //sdlstandalone in '../flexui/sdlstandalone.pas',
239 fui_wadread in '../flexui/fui_wadread.pas',
240 fui_common in '../flexui/fui_common.pas',
241 fui_gfx_gl in '../flexui/fui_gfx_gl.pas',
242 fui_events in '../flexui/fui_events.pas',
243 fui_style in '../flexui/fui_style.pas',
244 fui_flexlay in '../flexui/fui_flexlay.pas',
245 fui_ctls in '../flexui/fui_ctls.pas',
255 autoexecScript = 'autoexec.cfg';
258 noct: Boolean = False;
259 binPath: AnsiString = '';
260 forceBinDir: Boolean = False;
261 {$IFDEF USE_SDLMIXER}
262 UseNativeMusic: Boolean;
270 // remember old mobj positions, prepare for update
272 // server: receive client commands for new frame
273 // client: receive game state changes from server
274 if (NetMode = NET_SERVER) then g_Net_Host_Update()
275 else if (NetMode = NET_CLIENT) then g_Net_Client_Update();
277 {$IFDEF ENABLE_RENDER}
281 // server: send any accumulated outgoing data to clients
282 if NetMode = NET_SERVER then g_Net_Flush();
285 function ProcessMessage (): Boolean;
289 Time, Time_Delta: Int64;
292 {$IFDEF ENABLE_SYSTEM}
293 Result := sys_HandleInput();
298 Time := GetTickCount64();
299 Time_Delta := Time-Time_Old;
303 if wNeedTimeReset then
307 wNeedTimeReset := false;
310 g_Map_ProfilersBegin();
311 g_Mons_ProfilersBegin();
313 t := Time_Delta div 28;
321 g_Map_ProfilersEnd();
322 g_Mons_ProfilersEnd();
324 if (gExit = EXIT_QUIT) then
330 // Время предыдущего обновления
332 Time_Old := Time - (Time_Delta mod 28);
334 // don't wait if VSync is on, GL already probably waits enough
336 flag := (Time - Frame >= gFrameTime) or gVSync;
340 if gPause or (not gLerpActors) or (gState = STATE_FOLD) then
343 gLerpFactor := nmin(1.0, (Time - Time_Old) / 28.0);
344 {$IFDEF ENABLE_RENDER}
355 procedure DebugOptions;
360 {$IFDEF ENABLE_HOLMES}
366 while (idx <= ParamCount) do
368 arg := ParamStr(idx);
370 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
371 if arg = '--jah' then g_profile_history_size := 100;
372 if arg = '--no-los' then gmon_dbg_los_enabled := false;
374 if arg = '--profile-render' then g_profile_frame_draw := true;
375 if arg = '--profile-coldet' then g_profile_collision := true;
376 if arg = '--profile-los' then g_profile_los := true;
379 if arg = '--no-particles' then gpart_dbg_enabled := false;
380 if arg = '--no-part-phys' then gpart_dbg_phys_enabled := false;
381 if arg = '--no-part-physics' then gpart_dbg_phys_enabled := false;
382 if arg = '--no-particles-phys' then gpart_dbg_phys_enabled := false;
383 if arg = '--no-particles-physics' then gpart_dbg_phys_enabled := false;
384 if arg = '--no-particle-phys' then gpart_dbg_phys_enabled := false;
385 if arg = '--no-particle-physics' then gpart_dbg_phys_enabled := false;
388 if arg = '--debug-input' then g_dbg_input := True;
390 {.$IF DEFINED(D2F_DEBUG)}
391 if arg = '--aimline' then g_dbg_aimline_on := true;
394 {$IFDEF ENABLE_HOLMES}
395 if arg = '--holmes' then begin g_holmes_enabled := true; g_Game_SetDebugMode(); end;
397 if (arg = '--holmes-ui-scale') or (arg = '-holmes-ui-scale') then
399 if (idx <= ParamCount) then
401 if not conParseFloat(fuiRenderScale, ParamStr(idx)) then fuiRenderScale := 1.0;
406 if (arg = '--holmes-font') or (arg = '-holmes-font') then
408 if (idx <= ParamCount) then
411 val(ParamStr(idx), itmp, valres);
412 if (valres = 0) and (not g_holmes_imfunctional) then
415 8: uiContext.font := 'win8';
416 14: uiContext.font := 'win14';
417 16: uiContext.font := 'win16';
425 if (arg = '--game-scale') or (arg = '-game-scale') then
427 if (idx <= ParamCount) then
429 if not conParseFloat(g_dbg_scale, ParamStr(idx)) then g_dbg_scale := 1.0;
434 if (arg = '--write-mapdef') or (arg = '-write-mapdef') then
436 mdfo := createDiskFile('mapdef.txt');
437 mdfo.WriteBuffer(defaultMapDef[1], Length(defaultMapDef));
442 if (arg = '--pixel-scale') or (arg = '-pixel-scale') then
444 if (idx <= ParamCount) then
446 if not conParseFloat(r_pixel_scale, ParamStr(idx)) then r_pixel_scale := 1.0;
453 function GetBinaryPath (): AnsiString;
458 result := ExtractFilePath(ParamStr(0));
460 // it may be a symlink; do some guesswork here
461 sl := fpReadLink(ExtractFileName(ParamStr(0)));
462 if (sl = ParamStr(0)) then
464 // use current directory, as we don't have anything better
469 result := fixSlashes(result);
470 if (length(result) > 0) and (result[length(result)] <> '/') then
471 result := result + '/';
474 procedure PrintDirs (msg: AnsiString; dirs: SSArray);
477 e_LogWriteln(msg + ':');
479 e_LogWriteln(' ' + dir);
483 function NSStringToAnsiString (s: NSString): AnsiString;
487 for i := 0 to s.length - 1 do
488 result := result + AnsiChar(s.characterAtIndex(i));
491 function GetBundlePath (): AnsiString;
492 var pathRef: CFURLRef; pathCFStr: CFStringRef; pathStr: ShortString;
494 pathRef := CFBundleCopyBundleURL(CFBundleGetMainBundle());
495 pathCFStr := CFURLCopyFileSystemPath(pathRef, kCFURLPOSIXPathStyle);
496 CFStringGetPascalString(pathCFStr, @pathStr, 255, CFStringGetSystemEncoding());
498 CFRelease(pathCFStr);
504 var i: Integer; rwdir, rodir: AnsiString; rwdirs, rodirs: SSArray;
506 procedure AddDir (var dirs: SSArray; append: AnsiString);
508 SetLength(dirs, Length(dirs) + 1);
509 dirs[High(dirs)] := ExpandFileName(append)
512 function IsSep (ch: Char): Boolean;
515 result := (ch = '/') or (ch = '\');
517 result := (ch = '/');
521 function OptimizePath (dir: AnsiString): AnsiString;
522 var i, len: Integer; s: AnsiString;
524 i := 1; len := Length(dir); s := '';
527 if IsSep(dir[i]) then
529 s := s + DirectorySeparator;
531 while (i <= len) and IsSep(dir[i]) do Inc(i);
532 if (i <= len) and (dir[i] = '.') then
534 if (i = len) or IsSep(dir[i + 1]) then
538 else if (i + 1 <= len) and (dir[i + 1] = '.') then
540 if (i + 1 = len) or IsSep(dir[i + 2]) then
557 procedure OptimizeDirs (var dirs: SSArray);
558 var i, j, k: Integer;
560 for i := 0 to High(dirs) do
561 dirs[i] := OptimizePath(dirs[i]);
569 if dirs[j] = dirs[i] then
571 for k := j + 1 to High(dirs) do
572 dirs[k - 1] := dirs[k];
574 SetLength(dirs, High(dirs))
585 procedure AddDef (var dirs: SSArray; base: SSArray; append: AnsiString);
588 if Length(dirs) = 0 then
590 AddDir(dirs, e_CatPath(s, append));
594 function GetDefaultRODirs (): SSArray;
595 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
596 var home: AnsiString;
599 var appdata: AnsiString;
602 var bundle, s: AnsiString; dirArr: NSArray; i: Integer;
607 bundle := GetBundlePath();
608 if ExtractFileExt(bundle) <> '.app' then
609 AddDir(result, binpath);
611 AddDir(result, binPath);
613 if forceBinDir = false then
616 AddDir(result, SDL_GetBasePath());
617 AddDir(result, SDL_GetPrefPath('', 'doom2df'));
620 appdata := GetEnvironmentVariable('APPDATA') + '\doom2df';
621 if appdata <> '' then
622 AddDir(result, appdata);
624 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
625 AddDir(result, '/usr/share/doom2df');
626 AddDir(result, '/usr/local/share/doom2df');
627 home := GetEnvironmentVariable('HOME');
629 AddDir(result, e_CatPath(home, '.doom2df'));
632 bundle := GetBundlePath();
634 AddDir(result, e_CatPath(bundle, 'Contents/Resources'));
635 dirArr := NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true);
636 for i := 0 to dirArr.count - 1 do
638 s := NSStringToAnsiString(dirArr.objectAtIndex(i));
639 AddDir(result, e_CatPath(s, 'Doom 2D Forever'))
642 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
643 AddDir(result, SDL_AndroidGetInternalStoragePath());
644 if SDL_AndroidGetExternalStorageState() <> 0 then
645 AddDir(result, SDL_AndroidGetExternalStoragePath());
650 function GetDefaultRWDirs (): SSArray;
651 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
652 var home: AnsiString;
655 var appdata: AnsiString;
658 var bundle, s: AnsiString; dirArr: NSArray; i: Integer;
663 bundle := GetBundlePath();
664 if ExtractFileExt(bundle) <> '.app' then
665 AddDir(result, binPath);
667 AddDir(result, binPath);
669 if forceBinDir = false then
672 AddDir(result, SDL_GetPrefPath('', 'doom2df'));
675 appdata := GetEnvironmentVariable('APPDATA') + '\doom2df';
676 if appdata <> '' then
677 AddDir(result, appdata);
679 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
680 home := GetEnvironmentVariable('HOME');
682 AddDir(result, e_CatPath(home, '.doom2df'));
685 dirArr := NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true);
686 for i := 0 to dirArr.count - 1 do
688 s := NSStringToAnsiString(dirArr.objectAtIndex(i));
689 AddDir(result, e_CatPath(s, 'Doom 2D Forever'))
692 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
693 if SDL_AndroidGetExternalStorageState() <> 0 then
694 AddDir(result, SDL_AndroidGetExternalStoragePath());
700 forceBinDir := false;
701 binPath := GetBinaryPath();
704 while i < ParamCount do
707 '--like-windoze': forceBinDir := true;
711 rwdir := ParamStr(i);
713 AddDir(LogDirs, e_CatPath(rwdir, ''));
714 AddDir(SaveDirs, e_CatPath(rwdir, 'data'));
715 AddDir(CacheDirs, e_CatPath(rwdir, 'data/cache'));
716 AddDir(ConfigDirs, e_CatPath(rwdir, ''));
717 AddDir(MapDownloadDirs, e_CatPath(rwdir, 'maps/downloads'));
718 AddDir(WadDownloadDirs, e_CatPath(rwdir, 'wads/downloads'));
719 AddDir(ScreenshotDirs, e_CatPath(rwdir, 'screenshots'));
720 AddDir(StatsDirs, e_CatPath(rwdir, 'stats'));
722 AddDir(DataDirs, e_CatPath(rwdir, 'data'));
723 AddDir(ModelDirs, e_CatPath(rwdir, 'data/models'));
724 AddDir(MegawadDirs, e_CatPath(rwdir, 'maps/megawads'));
725 AddDir(MapDirs, e_CatPath(rwdir, 'maps'));
726 AddDir(WadDirs, e_CatPath(rwdir, 'wads'));
731 rodir := ParamStr(i);
733 AddDir(DataDirs, e_CatPath(rodir, 'data'));
734 AddDir(ModelDirs, e_CatPath(rodir, 'data/models'));
735 AddDir(MegawadDirs, e_CatPath(rodir, 'maps/megawads'));
736 AddDir(MapDirs, e_CatPath(rodir, 'maps'));
737 AddDir(WadDirs, e_CatPath(rodir, 'wads'));
742 GameWADName := ParamStr(i);
747 gConfigScript := ParamStr(i);
753 // prefer bin dir if it writable and contains game.wad
754 if forceBinDir = false then
756 if findDiskWad(binPath + 'data' + '/' + GameWADName) <> '' then
757 if e_CanCreateFilesAt(binPath) then
762 rodirs := GetDefaultRODirs();
763 AddDef(DataDirs, rodirs, 'data');
764 AddDef(ModelDirs, rodirs, 'data/models');
765 AddDef(MegawadDirs, rodirs, 'maps/megawads');
766 AddDef(MapDirs, rodirs, 'maps');
767 AddDef(WadDirs, rodirs, 'wads');
770 rwdirs := GetDefaultRWDirs();
771 AddDef(LogDirs, rwdirs, '');
772 AddDef(SaveDirs, rwdirs, 'data');
773 AddDef(CacheDirs, rwdirs, 'data/cache');
774 AddDef(ConfigDirs, rwdirs, '');
775 AddDef(MapDownloadDirs, rwdirs, 'maps/downloads');
776 AddDef(WadDownloadDirs, rwdirs, 'wads/downloads');
777 AddDef(ScreenshotDirs, rwdirs, 'screenshots');
778 AddDef(StatsDirs, rwdirs, 'stats');
780 for i := 0 to High(MapDirs) do
781 AddDir(AllMapDirs, MapDirs[i]);
782 for i := 0 to High(MegawadDirs) do
783 AddDir(AllMapDirs, MegawadDirs[i]);
784 OptimizeDirs(AllMapDirs);
786 // HACK: ensure the screenshots folder also has a stats subfolder in it
787 rwdir := e_GetWriteableDir(ScreenshotDirs, false);
788 if rwdir <> '' then CreateDir(rwdir + '/stats');
791 procedure EntryParams;
795 while i <= ParamCount do
798 '--gdb': noct := true;
799 '--log', '--con-stdout': conbufDumpToStdOut := true;
800 '--safe-log': e_SetSafeSlowLog(true);
802 if i + 1 <= ParamCount then
805 LogFileName := ParamStr(i)
807 '--no-fbo': glRenderToFBO := false;
814 var rwdir: AnsiString;
816 if LogFileName = '' then
818 rwdir := e_GetWriteableDir(LogDirs, false);
822 LogFileName := e_CatPath(rwdir, 'Doom2DF_H.log');
824 LogFileName := e_CatPath(rwdir, 'Doom2DF.log');
828 if LogFileName <> '' then
829 e_InitLog(LogFileName, TWriteMode.WM_NEWFILE);
835 e_WriteLog('Doom 2D: Forever version ' + GAME_VERSION + ' proto ' + IntToStr(NET_PROTOCOL_VER), TMsgType.Notify);
836 e_WriteLog('Build arch: ' + g_GetBuildArch(), TMsgType.Notify);
837 e_WriteLog('Build date: ' + GAME_BUILDDATE + ' ' + GAME_BUILDTIME, TMsgType.Notify);
838 e_WriteLog('Build hash: ' + g_GetBuildHash(), TMsgType.Notify);
839 e_WriteLog('Build by: ' + g_GetBuilderName(), TMsgType.Notify);
841 e_LogWritefln('Force bin dir: %s', [forceBinDir], TMsgType.Notify);
842 e_LogWritefln('BINARY PATH: [%s]', [binPath], TMsgType.Notify);
844 PrintDirs('DataDirs', DataDirs);
845 PrintDirs('ModelDirs', ModelDirs);
846 PrintDirs('MegawadDirs', MegawadDirs);
847 PrintDirs('MapDirs', MapDirs);
848 PrintDirs('WadDirs', WadDirs);
850 PrintDirs('LogDirs', LogDirs);
851 PrintDirs('SaveDirs', SaveDirs);
852 PrintDirs('CacheDirs', CacheDirs);
853 PrintDirs('ConfigDirs', ConfigDirs);
854 PrintDirs('ScreenshotDirs', ScreenshotDirs);
855 PrintDirs('StatsDirs', StatsDirs);
856 PrintDirs('MapDownloadDirs', MapDownloadDirs);
857 PrintDirs('WadDownloadDirs', WadDownloadDirs);
860 {$IFDEF USE_SDLMIXER}
861 NoSound := False; // hope env has set SDL_AUDIODRIVER to dummy
863 NoSound := True; // FMOD backend will sort it out
869 GameWAD := e_FindWad(DataDirs, GameWADName);
872 e_WriteLog('WAD ' + GameWADName + ' not found in data directories.', TMsgType.Fatal);
873 {$IF DEFINED(USE_SDL2) AND NOT DEFINED(HEADLESS)}
874 if forceBinDir = false then
875 SDL_ShowSimpleMessageBox(
876 SDL_MESSAGEBOX_ERROR,
878 PChar('WAD ' + GameWADName + ' not found in data directories.'),
887 {$IFDEF ENABLE_HOLMES}
888 procedure InitHolmes;
889 var flexloaded: Boolean;
892 if not fuiAddWad('flexui.wad') then
894 if not fuiAddWad('./data/flexui.wad') then fuiAddWad('./flexui.wad');
897 fuiGfxLoadFont('win8', 'flexui/fonts/win8.fuifont');
898 fuiGfxLoadFont('win14', 'flexui/fonts/win14.fuifont');
899 fuiGfxLoadFont('win16', 'flexui/fonts/win16.fuifont');
900 fuiGfxLoadFont('dos8', 'flexui/fonts/dos8.fuifont');
901 fuiGfxLoadFont('msx6', 'flexui/fonts/msx6.fuifont');
902 except on e: Exception do
904 writeln('ERROR loading FlexUI fonts');
917 e_LogWriteln('FlexUI: loading stylesheet...');
918 uiLoadStyles('flexui/widgets.wgs');
919 except on e: TParserException do
921 writeln('ERROR at (', e.tokLine, ',', e.tokCol, '): ', e.message);
932 g_holmes_imfunctional := not flexloaded;
933 if not g_holmes_imfunctional then
936 uiContext.font := 'win14';
938 if assigned(oglInitCB) then oglInitCB;
941 procedure FreeHolmes;
943 if assigned(oglDeinitCB) then
949 {$IFDEF USE_SDLMIXER}
950 var timiditycfg: AnsiString;
951 var oldcwd, newcwd: RawByteString;
954 if NoSound = false then
956 e_WriteLog('Initializing sound system', TMsgType.Notify);
957 {$IFDEF USE_SDLMIXER}
959 if UseNativeMusic then
960 SetEnvVar('SDL_NATIVE_MUSIC', '1');
961 timiditycfg := GetEnvironmentVariable('TIMIDITY_CFG');
962 if timiditycfg = '' then
964 timiditycfg := 'timidity.cfg';
965 if e_FindResource(ConfigDirs, timiditycfg) OR e_FindResource(DataDirs, timiditycfg) then
967 timiditycfg := ExpandFileName(timiditycfg);
968 newcwd := ExtractFileDir(timiditycfg);
969 SetEnvVar('TIMIDITY_CFG', timiditycfg);
974 e_LogWritefln('TIMIDITY_CFG = "%s"', [timiditycfg]);
975 e_LogWritefln('SDL_NATIVE_MUSIC = "%s"', [GetEnvironmentVariable('SDL_NATIVE_MUSIC')]);
977 e_InitSoundSystem(NoSound);
978 {$IFDEF USE_SDLMIXER}
979 if e_TimidityDecoder and (newcwd <> '') then
981 (* HACK: Set CWD to load GUS patches relatively to cfg file. *)
982 (* CWD not restored after sound init because timidity *)
983 (* store relative pathes internally and load patches *)
984 (* later. I hope game never relies on CWD. *)
988 e_logwritefln('WARNING: USED TIMIDITY CONFIG HACK, CWD SWITCHED "%s" -> "%s"', [oldcwd, newcwd]);
994 procedure ScreenResize (w, h: Integer);
996 {$IFDEF ENABLE_RENDER}
997 r_Render_Resize(w, h);
998 {$IFDEF ENABLE_HOLMES}
1003 (* This will fix menu reset on keyboard showing *)
1004 {$IFDEF ENABLE_MENU}
1008 //g_Game_ClearLoading;
1009 {$IFDEF ENABLE_HOLMES}
1010 if assigned(oglInitCB) then oglInitCB;
1015 procedure ProcessLoading;
1016 var update: Boolean;
1018 {$IFDEF ENABLE_SYSTEM}
1019 update := sys_HandleInput() = False;
1026 // TODO: At the moment, I left here only host network processing, because the client code must
1027 // handle network events on its own. Otherwise separate network cases that use different calls to
1028 // enet_host_service() WILL lose their packets (for example, resource downloading). So they have
1029 // to handle everything by themselves. But in general, this MUST be removed completely, since
1030 // updating the window should never affect the network. Use single enet_host_service(), period.
1031 if NetMode = NET_SERVER then g_Net_Host_Update();
1043 {$IFDEF ENABLE_SYSTEM}
1045 sys_CharPress := @CharPress; (* install hook *)
1046 sys_ScreenResize := @ScreenResize; (* install hook *)
1048 g_Options_SetDefault;
1049 g_Options_SetDefaultVideo;
1050 g_Console_Initialize;
1051 // TODO move load configs here
1052 g_Language_Set(gLanguage);
1053 {$IFDEF ENABLE_RENDER}
1054 r_Render_Initialize;
1058 // TODO init serverlist
1059 {$IFDEF ENABLE_RENDER}
1060 r_Render_SetProcessLoadingCallback(@ProcessLoading);
1062 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION]), 0, False);
1063 g_Game_SetLoadingText('', 0, False);
1064 {$IFDEF ENABLE_HOLMES}
1067 {$IFDEF ENABLE_RENDER}
1068 g_PlayerModel_LoadAll;
1071 g_PlayerModel_LoadFake('doomer', 'doomer.wad');
1074 {$IFDEF ENABLE_MENU}
1077 g_Game_Process_Params;
1078 // TODO reload GAME textures
1079 g_Console_Init; // welcome message
1080 {$IFDEF ENABLE_MENU}
1081 if (not gGameOn) and gAskLanguage then
1084 Time_Old := GetTickCount64();
1085 while not ProcessMessage() do begin end;
1086 {$IFDEF ENABLE_RENDER}
1087 r_Render_SetProcessLoadingCallback(nil);
1089 g_Console_WriteGameConfig;
1090 {$IFDEF ENABLE_MENU}
1094 {$IFDEF ENABLE_RENDER}
1097 {$IFDEF ENABLE_HOLMES}
1100 g_Net_Slist_ShutdownAll;
1101 g_Net_DeinitLowLevel;
1102 (* g_Touch_Finalize; *)
1103 {$IFDEF ENABLE_RENDER}
1106 {$IFDEF ENABLE_SYSTEM}
1110 e_ReleaseSoundSystem;
1112 e_WriteLog('Shutdown with no errors.', TMsgType.Notify)
1115 procedure InitCVars;
1117 {$IFDEF USE_SDLMIXER}
1118 conRegVar('sdl_native_music', @UseNativeMusic, 'use native midi music output when possible', 'use native midi');
1120 UseNativeMusic := true; (* OSX have a good midi support, so why not? *)
1122 UseNativeMusic := false;
1127 procedure EntryPoint;
1129 SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]); //k8: fuck off, that's why
1134 conbufDumpToStdOut := true;
1141 except on e: Exception do
1142 e_WriteStackTrace(e.message)
1144 e_WriteStackTrace('FATAL ERROR')
1150 function SDL_main (argc: CInt; argv: PPChar): CInt; cdecl;
1153 System.argc := argc;
1154 System.argv := argv;
1160 function JNI_OnLoad (vm: PJavaVM; reserved: pointer): JInt; cdecl;
1162 result:= JNI_VERSION_1_6;
1165 procedure JNI_OnUnload(vm: PJavaVM; reserved: pointer); cdecl;
1169 // DONT REMOVE JNI FUNCTIONS. SPECIAL HANDLING BY FPC.
1170 exports SDL_main name 'SDL_main';
1171 exports JNI_OnLoad name 'JNI_OnLoad';
1172 exports JNI_OnUnload name 'JNI_Unload';