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_textures in 'g_textures.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_gui in 'renders/opengl/r_gui.pas',
209 {$FATAL render driver not selected}
214 fmod in '../lib/FMOD/fmod.pas',
215 fmoderrors in '../lib/FMOD/fmoderrors.pas',
216 fmodpresets in '../lib/FMOD/fmodpresets.pas',
217 fmodtypes in '../lib/FMOD/fmodtypes.pas',
219 xprofiler in '../shared/xprofiler.pas',
220 binheap in '../shared/binheap.pas',
221 hashtable in '../shared/hashtable.pas',
222 fhashdb in '../shared/fhashdb.pas',
223 idpool in '../shared/idpool.pas',
224 xparser in '../shared/xparser.pas',
225 xdynrec in '../shared/xdynrec.pas',
226 exoma in '../shared/exoma.pas',
227 envvars in '../shared/envvars.pas',
228 g_panel in 'g_panel.pas',
229 g_language in 'g_language.pas',
231 {$IFDEF ENABLE_HOLMES}
232 g_holmes in 'g_holmes.pas',
234 sdlcarcass in '../flexui/sdlcarcass.pas',
235 //sdlstandalone in '../flexui/sdlstandalone.pas',
237 fui_wadread in '../flexui/fui_wadread.pas',
238 fui_common in '../flexui/fui_common.pas',
239 fui_gfx_gl in '../flexui/fui_gfx_gl.pas',
240 fui_events in '../flexui/fui_events.pas',
241 fui_style in '../flexui/fui_style.pas',
242 fui_flexlay in '../flexui/fui_flexlay.pas',
243 fui_ctls in '../flexui/fui_ctls.pas',
253 autoexecScript = 'autoexec.cfg';
256 noct: Boolean = False;
257 binPath: AnsiString = '';
258 forceBinDir: Boolean = False;
259 {$IFDEF USE_SDLMIXER}
260 UseNativeMusic: Boolean;
268 // remember old mobj positions, prepare for update
270 // server: receive client commands for new frame
271 // client: receive game state changes from server
272 if (NetMode = NET_SERVER) then g_Net_Host_Update()
273 else if (NetMode = NET_CLIENT) then g_Net_Client_Update();
275 {$IFDEF ENABLE_RENDER}
279 // server: send any accumulated outgoing data to clients
280 if NetMode = NET_SERVER then g_Net_Flush();
283 function ProcessMessage (): Boolean;
287 Time, Time_Delta: Int64;
290 {$IFDEF ENABLE_SYSTEM}
291 Result := sys_HandleInput();
296 Time := GetTickCount64();
297 Time_Delta := Time-Time_Old;
301 if wNeedTimeReset then
305 wNeedTimeReset := false;
308 g_Map_ProfilersBegin();
309 g_Mons_ProfilersBegin();
311 t := Time_Delta div 28;
319 g_Map_ProfilersEnd();
320 g_Mons_ProfilersEnd();
322 if (gExit = EXIT_QUIT) then
328 // Время предыдущего обновления
330 Time_Old := Time - (Time_Delta mod 28);
332 // don't wait if VSync is on, GL already probably waits enough
334 flag := (Time - Frame >= gFrameTime) or gVSync;
338 if gPause or (not gLerpActors) or (gState = STATE_FOLD) then
341 gLerpFactor := nmin(1.0, (Time - Time_Old) / 28.0);
342 {$IFDEF ENABLE_RENDER}
345 {$IFDEF ENABLE_SYSTEM}
356 procedure DebugOptions;
361 {$IFDEF ENABLE_HOLMES}
367 while (idx <= ParamCount) do
369 arg := ParamStr(idx);
371 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
372 if arg = '--jah' then g_profile_history_size := 100;
373 if arg = '--no-los' then gmon_dbg_los_enabled := false;
375 if arg = '--profile-render' then g_profile_frame_draw := true;
376 if arg = '--profile-coldet' then g_profile_collision := true;
377 if arg = '--profile-los' then g_profile_los := true;
380 if arg = '--no-particles' then gpart_dbg_enabled := false;
381 if arg = '--no-part-phys' then gpart_dbg_phys_enabled := false;
382 if arg = '--no-part-physics' then gpart_dbg_phys_enabled := false;
383 if arg = '--no-particles-phys' then gpart_dbg_phys_enabled := false;
384 if arg = '--no-particles-physics' then gpart_dbg_phys_enabled := false;
385 if arg = '--no-particle-phys' then gpart_dbg_phys_enabled := false;
386 if arg = '--no-particle-physics' then gpart_dbg_phys_enabled := false;
389 if arg = '--debug-input' then g_dbg_input := True;
391 {.$IF DEFINED(D2F_DEBUG)}
392 if arg = '--aimline' then g_dbg_aimline_on := true;
395 {$IFDEF ENABLE_HOLMES}
396 if arg = '--holmes' then begin g_holmes_enabled := true; g_Game_SetDebugMode(); end;
398 if (arg = '--holmes-ui-scale') or (arg = '-holmes-ui-scale') then
400 if (idx <= ParamCount) then
402 if not conParseFloat(fuiRenderScale, ParamStr(idx)) then fuiRenderScale := 1.0;
407 if (arg = '--holmes-font') or (arg = '-holmes-font') then
409 if (idx <= ParamCount) then
412 val(ParamStr(idx), itmp, valres);
413 if (valres = 0) and (not g_holmes_imfunctional) then
416 8: uiContext.font := 'win8';
417 14: uiContext.font := 'win14';
418 16: uiContext.font := 'win16';
426 if (arg = '--game-scale') or (arg = '-game-scale') then
428 if (idx <= ParamCount) then
430 if not conParseFloat(g_dbg_scale, ParamStr(idx)) then g_dbg_scale := 1.0;
435 if (arg = '--write-mapdef') or (arg = '-write-mapdef') then
437 mdfo := createDiskFile('mapdef.txt');
438 mdfo.WriteBuffer(defaultMapDef[1], Length(defaultMapDef));
443 if (arg = '--pixel-scale') or (arg = '-pixel-scale') then
445 if (idx <= ParamCount) then
447 if not conParseFloat(r_pixel_scale, ParamStr(idx)) then r_pixel_scale := 1.0;
454 function GetBinaryPath (): AnsiString;
459 result := ExtractFilePath(ParamStr(0));
461 // it may be a symlink; do some guesswork here
462 sl := fpReadLink(ExtractFileName(ParamStr(0)));
463 if (sl = ParamStr(0)) then
465 // use current directory, as we don't have anything better
470 result := fixSlashes(result);
471 if (length(result) > 0) and (result[length(result)] <> '/') then
472 result := result + '/';
475 procedure PrintDirs (msg: AnsiString; dirs: SSArray);
478 e_LogWriteln(msg + ':');
480 e_LogWriteln(' ' + dir);
484 function NSStringToAnsiString (s: NSString): AnsiString;
488 for i := 0 to s.length - 1 do
489 result := result + AnsiChar(s.characterAtIndex(i));
492 function GetBundlePath (): AnsiString;
493 var pathRef: CFURLRef; pathCFStr: CFStringRef; pathStr: ShortString;
495 pathRef := CFBundleCopyBundleURL(CFBundleGetMainBundle());
496 pathCFStr := CFURLCopyFileSystemPath(pathRef, kCFURLPOSIXPathStyle);
497 CFStringGetPascalString(pathCFStr, @pathStr, 255, CFStringGetSystemEncoding());
499 CFRelease(pathCFStr);
505 var i: Integer; rwdir, rodir: AnsiString; rwdirs, rodirs: SSArray;
507 procedure AddDir (var dirs: SSArray; append: AnsiString);
509 SetLength(dirs, Length(dirs) + 1);
510 dirs[High(dirs)] := ExpandFileName(append)
513 function IsSep (ch: Char): Boolean;
516 result := (ch = '/') or (ch = '\');
518 result := (ch = '/');
522 function OptimizePath (dir: AnsiString): AnsiString;
523 var i, len: Integer; s: AnsiString;
525 i := 1; len := Length(dir); s := '';
528 if IsSep(dir[i]) then
530 s := s + DirectorySeparator;
532 while (i <= len) and IsSep(dir[i]) do Inc(i);
533 if (i <= len) and (dir[i] = '.') then
535 if (i = len) or IsSep(dir[i + 1]) then
539 else if (i + 1 <= len) and (dir[i + 1] = '.') then
541 if (i + 1 = len) or IsSep(dir[i + 2]) then
558 procedure OptimizeDirs (var dirs: SSArray);
559 var i, j, k: Integer;
561 for i := 0 to High(dirs) do
562 dirs[i] := OptimizePath(dirs[i]);
570 if dirs[j] = dirs[i] then
572 for k := j + 1 to High(dirs) do
573 dirs[k - 1] := dirs[k];
575 SetLength(dirs, High(dirs))
586 procedure AddDef (var dirs: SSArray; base: SSArray; append: AnsiString);
589 if Length(dirs) = 0 then
591 AddDir(dirs, e_CatPath(s, append));
595 function GetDefaultRODirs (): SSArray;
596 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
597 var home: AnsiString;
600 var appdata: AnsiString;
603 var bundle, s: AnsiString; dirArr: NSArray; i: Integer;
608 bundle := GetBundlePath();
609 if ExtractFileExt(bundle) <> '.app' then
610 AddDir(result, binpath);
612 AddDir(result, binPath);
614 if forceBinDir = false then
617 AddDir(result, SDL_GetBasePath());
618 AddDir(result, SDL_GetPrefPath('', 'doom2df'));
621 appdata := GetEnvironmentVariable('APPDATA') + '\doom2df';
622 if appdata <> '' then
623 AddDir(result, appdata);
625 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
626 AddDir(result, '/usr/share/doom2df');
627 AddDir(result, '/usr/local/share/doom2df');
628 home := GetEnvironmentVariable('HOME');
630 AddDir(result, e_CatPath(home, '.doom2df'));
633 bundle := GetBundlePath();
635 AddDir(result, e_CatPath(bundle, 'Contents/Resources'));
636 dirArr := NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true);
637 for i := 0 to dirArr.count - 1 do
639 s := NSStringToAnsiString(dirArr.objectAtIndex(i));
640 AddDir(result, e_CatPath(s, 'Doom 2D Forever'))
643 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
644 AddDir(result, SDL_AndroidGetInternalStoragePath());
645 if SDL_AndroidGetExternalStorageState() <> 0 then
646 AddDir(result, SDL_AndroidGetExternalStoragePath());
651 function GetDefaultRWDirs (): SSArray;
652 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
653 var home: AnsiString;
656 var appdata: AnsiString;
659 var bundle, s: AnsiString; dirArr: NSArray; i: Integer;
664 bundle := GetBundlePath();
665 if ExtractFileExt(bundle) <> '.app' then
666 AddDir(result, binPath);
668 AddDir(result, binPath);
670 if forceBinDir = false then
673 AddDir(result, SDL_GetPrefPath('', 'doom2df'));
676 appdata := GetEnvironmentVariable('APPDATA') + '\doom2df';
677 if appdata <> '' then
678 AddDir(result, appdata);
680 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
681 home := GetEnvironmentVariable('HOME');
683 AddDir(result, e_CatPath(home, '.doom2df'));
686 dirArr := NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true);
687 for i := 0 to dirArr.count - 1 do
689 s := NSStringToAnsiString(dirArr.objectAtIndex(i));
690 AddDir(result, e_CatPath(s, 'Doom 2D Forever'))
693 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
694 if SDL_AndroidGetExternalStorageState() <> 0 then
695 AddDir(result, SDL_AndroidGetExternalStoragePath());
701 forceBinDir := false;
702 binPath := GetBinaryPath();
705 while i < ParamCount do
708 '--like-windoze': forceBinDir := true;
712 rwdir := ParamStr(i);
714 AddDir(LogDirs, e_CatPath(rwdir, ''));
715 AddDir(SaveDirs, e_CatPath(rwdir, 'data'));
716 AddDir(CacheDirs, e_CatPath(rwdir, 'data/cache'));
717 AddDir(ConfigDirs, e_CatPath(rwdir, ''));
718 AddDir(MapDownloadDirs, e_CatPath(rwdir, 'maps/downloads'));
719 AddDir(WadDownloadDirs, e_CatPath(rwdir, 'wads/downloads'));
720 AddDir(ScreenshotDirs, e_CatPath(rwdir, 'screenshots'));
721 AddDir(StatsDirs, e_CatPath(rwdir, 'stats'));
723 AddDir(DataDirs, e_CatPath(rwdir, 'data'));
724 AddDir(ModelDirs, e_CatPath(rwdir, 'data/models'));
725 AddDir(MegawadDirs, e_CatPath(rwdir, 'maps/megawads'));
726 AddDir(MapDirs, e_CatPath(rwdir, 'maps'));
727 AddDir(WadDirs, e_CatPath(rwdir, 'wads'));
732 rodir := ParamStr(i);
734 AddDir(DataDirs, e_CatPath(rodir, 'data'));
735 AddDir(ModelDirs, e_CatPath(rodir, 'data/models'));
736 AddDir(MegawadDirs, e_CatPath(rodir, 'maps/megawads'));
737 AddDir(MapDirs, e_CatPath(rodir, 'maps'));
738 AddDir(WadDirs, e_CatPath(rodir, 'wads'));
743 GameWADName := ParamStr(i);
748 gConfigScript := ParamStr(i);
754 // prefer bin dir if it writable and contains game.wad
755 if forceBinDir = false then
757 if findDiskWad(binPath + 'data' + '/' + GameWADName) <> '' then
758 if e_CanCreateFilesAt(binPath) then
763 rodirs := GetDefaultRODirs();
764 AddDef(DataDirs, rodirs, 'data');
765 AddDef(ModelDirs, rodirs, 'data/models');
766 AddDef(MegawadDirs, rodirs, 'maps/megawads');
767 AddDef(MapDirs, rodirs, 'maps');
768 AddDef(WadDirs, rodirs, 'wads');
771 rwdirs := GetDefaultRWDirs();
772 AddDef(LogDirs, rwdirs, '');
773 AddDef(SaveDirs, rwdirs, 'data');
774 AddDef(CacheDirs, rwdirs, 'data/cache');
775 AddDef(ConfigDirs, rwdirs, '');
776 AddDef(MapDownloadDirs, rwdirs, 'maps/downloads');
777 AddDef(WadDownloadDirs, rwdirs, 'wads/downloads');
778 AddDef(ScreenshotDirs, rwdirs, 'screenshots');
779 AddDef(StatsDirs, rwdirs, 'stats');
781 for i := 0 to High(MapDirs) do
782 AddDir(AllMapDirs, MapDirs[i]);
783 for i := 0 to High(MegawadDirs) do
784 AddDir(AllMapDirs, MegawadDirs[i]);
785 OptimizeDirs(AllMapDirs);
787 // HACK: ensure the screenshots folder also has a stats subfolder in it
788 rwdir := e_GetWriteableDir(ScreenshotDirs, false);
789 if rwdir <> '' then CreateDir(rwdir + '/stats');
792 procedure EntryParams;
796 while i <= ParamCount do
799 '--gdb': noct := true;
800 '--log', '--con-stdout': conbufDumpToStdOut := true;
801 '--safe-log': e_SetSafeSlowLog(true);
803 if i + 1 <= ParamCount then
806 LogFileName := ParamStr(i)
808 '--no-fbo': glRenderToFBO := false;
815 var rwdir: AnsiString;
817 if LogFileName = '' then
819 rwdir := e_GetWriteableDir(LogDirs, false);
823 LogFileName := e_CatPath(rwdir, 'Doom2DF_H.log');
825 LogFileName := e_CatPath(rwdir, 'Doom2DF.log');
829 if LogFileName <> '' then
830 e_InitLog(LogFileName, TWriteMode.WM_NEWFILE);
836 e_WriteLog('Doom 2D: Forever version ' + GAME_VERSION + ' proto ' + IntToStr(NET_PROTOCOL_VER), TMsgType.Notify);
837 e_WriteLog('Build arch: ' + g_GetBuildArch(), TMsgType.Notify);
838 e_WriteLog('Build date: ' + GAME_BUILDDATE + ' ' + GAME_BUILDTIME, TMsgType.Notify);
839 e_WriteLog('Build hash: ' + g_GetBuildHash(), TMsgType.Notify);
840 e_WriteLog('Build by: ' + g_GetBuilderName(), TMsgType.Notify);
842 e_LogWritefln('Force bin dir: %s', [forceBinDir], TMsgType.Notify);
843 e_LogWritefln('BINARY PATH: [%s]', [binPath], TMsgType.Notify);
845 PrintDirs('DataDirs', DataDirs);
846 PrintDirs('ModelDirs', ModelDirs);
847 PrintDirs('MegawadDirs', MegawadDirs);
848 PrintDirs('MapDirs', MapDirs);
849 PrintDirs('WadDirs', WadDirs);
851 PrintDirs('LogDirs', LogDirs);
852 PrintDirs('SaveDirs', SaveDirs);
853 PrintDirs('CacheDirs', CacheDirs);
854 PrintDirs('ConfigDirs', ConfigDirs);
855 PrintDirs('ScreenshotDirs', ScreenshotDirs);
856 PrintDirs('StatsDirs', StatsDirs);
857 PrintDirs('MapDownloadDirs', MapDownloadDirs);
858 PrintDirs('WadDownloadDirs', WadDownloadDirs);
861 {$IFDEF USE_SDLMIXER}
862 NoSound := False; // hope env has set SDL_AUDIODRIVER to dummy
864 NoSound := True; // FMOD backend will sort it out
870 GameWAD := e_FindWad(DataDirs, GameWADName);
873 e_WriteLog('WAD ' + GameWADName + ' not found in data directories.', TMsgType.Fatal);
874 {$IF DEFINED(USE_SDL2) AND NOT DEFINED(HEADLESS)}
875 if forceBinDir = false then
876 SDL_ShowSimpleMessageBox(
877 SDL_MESSAGEBOX_ERROR,
879 PChar('WAD ' + GameWADName + ' not found in data directories.'),
888 {$IFDEF ENABLE_HOLMES}
889 procedure InitHolmes;
890 var flexloaded: Boolean;
893 if not fuiAddWad('flexui.wad') then
895 if not fuiAddWad('./data/flexui.wad') then fuiAddWad('./flexui.wad');
898 fuiGfxLoadFont('win8', 'flexui/fonts/win8.fuifont');
899 fuiGfxLoadFont('win14', 'flexui/fonts/win14.fuifont');
900 fuiGfxLoadFont('win16', 'flexui/fonts/win16.fuifont');
901 fuiGfxLoadFont('dos8', 'flexui/fonts/dos8.fuifont');
902 fuiGfxLoadFont('msx6', 'flexui/fonts/msx6.fuifont');
903 except on e: Exception do
905 writeln('ERROR loading FlexUI fonts');
918 e_LogWriteln('FlexUI: loading stylesheet...');
919 uiLoadStyles('flexui/widgets.wgs');
920 except on e: TParserException do
922 writeln('ERROR at (', e.tokLine, ',', e.tokCol, '): ', e.message);
933 g_holmes_imfunctional := not flexloaded;
934 if not g_holmes_imfunctional then
937 uiContext.font := 'win14';
939 if assigned(oglInitCB) then oglInitCB;
942 procedure FreeHolmes;
944 if assigned(oglDeinitCB) then
950 {$IFDEF USE_SDLMIXER}
951 var timiditycfg: AnsiString;
952 var oldcwd, newcwd: RawByteString;
955 if NoSound = false then
957 e_WriteLog('Initializing sound system', TMsgType.Notify);
958 {$IFDEF USE_SDLMIXER}
960 if UseNativeMusic then
961 SetEnvVar('SDL_NATIVE_MUSIC', '1');
962 timiditycfg := GetEnvironmentVariable('TIMIDITY_CFG');
963 if timiditycfg = '' then
965 timiditycfg := 'timidity.cfg';
966 if e_FindResource(ConfigDirs, timiditycfg) OR e_FindResource(DataDirs, timiditycfg) then
968 timiditycfg := ExpandFileName(timiditycfg);
969 newcwd := ExtractFileDir(timiditycfg);
970 SetEnvVar('TIMIDITY_CFG', timiditycfg);
975 e_LogWritefln('TIMIDITY_CFG = "%s"', [timiditycfg]);
976 e_LogWritefln('SDL_NATIVE_MUSIC = "%s"', [GetEnvironmentVariable('SDL_NATIVE_MUSIC')]);
978 e_InitSoundSystem(NoSound);
979 {$IFDEF USE_SDLMIXER}
980 if e_TimidityDecoder and (newcwd <> '') then
982 (* HACK: Set CWD to load GUS patches relatively to cfg file. *)
983 (* CWD not restored after sound init because timidity *)
984 (* store relative pathes internally and load patches *)
985 (* later. I hope game never relies on CWD. *)
989 e_logwritefln('WARNING: USED TIMIDITY CONFIG HACK, CWD SWITCHED "%s" -> "%s"', [oldcwd, newcwd]);
995 procedure ScreenResize (w, h: Integer);
997 {$IFDEF ENABLE_RENDER}
998 r_Render_Resize(w, h);
999 {$IFDEF ENABLE_HOLMES}
1004 (* This will fix menu reset on keyboard showing *)
1005 {$IFDEF ENABLE_MENU}
1009 //g_Game_ClearLoading;
1010 {$IFDEF ENABLE_HOLMES}
1011 if assigned(oglInitCB) then oglInitCB;
1024 {$IFDEF ENABLE_SYSTEM}
1026 sys_CharPress := @CharPress; (* install hook *)
1027 sys_ScreenResize := @ScreenResize; (* install hook *)
1029 g_Options_SetDefault;
1030 g_Options_SetDefaultVideo;
1031 g_Console_Initialize;
1032 // TODO move load configs here
1033 g_Language_Set(gLanguage);
1034 {$IFDEF ENABLE_RENDER}
1035 r_Render_Initialize;
1039 // TODO init serverlist
1040 {$IFDEF ENABLE_HOLMES}
1043 {$IFDEF ENABLE_RENDER}
1044 g_PlayerModel_LoadAll;
1047 g_PlayerModel_LoadFake('doomer', 'doomer.wad');
1050 {$IFDEF ENABLE_MENU}
1053 g_Game_Process_Params;
1054 // TODO reload GAME textures
1055 g_Console_Init; // welcome message
1056 {$IFDEF ENABLE_MENU}
1057 if (not gGameOn) and gAskLanguage then
1060 Time_Old := GetTickCount64();
1061 while not ProcessMessage() do begin end;
1062 g_Console_WriteGameConfig;
1063 {$IFDEF ENABLE_MENU}
1067 {$IFDEF ENABLE_RENDER}
1070 {$IFDEF ENABLE_HOLMES}
1073 g_Net_Slist_ShutdownAll;
1074 g_Net_DeinitLowLevel;
1075 (* g_Touch_Finalize; *)
1076 {$IFDEF ENABLE_RENDER}
1079 {$IFDEF ENABLE_SYSTEM}
1083 e_ReleaseSoundSystem;
1085 e_WriteLog('Shutdown with no errors.', TMsgType.Notify)
1088 procedure InitCVars;
1090 {$IFDEF USE_SDLMIXER}
1091 conRegVar('sdl_native_music', @UseNativeMusic, 'use native midi music output when possible', 'use native midi');
1093 UseNativeMusic := true; (* OSX have a good midi support, so why not? *)
1095 UseNativeMusic := false;
1100 procedure EntryPoint;
1102 SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]); //k8: fuck off, that's why
1107 conbufDumpToStdOut := true;
1114 except on e: Exception do
1115 e_WriteStackTrace(e.message)
1117 e_WriteStackTrace('FATAL ERROR')
1123 function SDL_main (argc: CInt; argv: PPChar): CInt; cdecl;
1126 System.argc := argc;
1127 System.argv := argv;
1133 function JNI_OnLoad (vm: PJavaVM; reserved: pointer): JInt; cdecl;
1135 result:= JNI_VERSION_1_6;
1138 procedure JNI_OnUnload(vm: PJavaVM; reserved: pointer); cdecl;
1142 // DONT REMOVE JNI FUNCTIONS. SPECIAL HANDLING BY FPC.
1143 exports SDL_main name 'SDL_main';
1144 exports JNI_OnLoad name 'JNI_OnLoad';
1145 exports JNI_OnUnload name 'JNI_Unload';