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',
153 g_system in 'stub/g_system.pas',
156 g_system in 'sdl/g_system.pas',
159 g_system in 'sdl2/g_system.pas',
164 {$I ../shared/vampimg.inc}
165 r_animations in 'opengl/r_animations.pas',
166 r_console in 'opengl/r_console.pas',
167 r_game in 'opengl/r_game.pas',
169 r_gfx in 'opengl/r_gfx.pas',
171 r_graphics in 'opengl/r_graphics.pas',
172 r_items in 'opengl/r_items.pas',
173 r_map in 'opengl/r_map.pas',
174 r_monsters in 'opengl/r_monsters.pas',
175 r_netmaster in 'opengl/r_netmaster.pas',
176 r_player in 'opengl/r_player.pas',
177 r_playermodel in 'opengl/r_playermodel.pas',
178 r_render in 'opengl/r_render.pas',
179 r_texture in 'opengl/r_texture.pas',
180 r_textures in 'opengl/r_textures.pas',
181 r_weapons in 'opengl/r_weapons.pas',
182 r_window in 'opengl/r_window.pas',
183 {$IFDEF ENABLE_TOUCH}
184 r_touch in 'opengl/r_touch.pas',
187 g_gui in 'g_gui.pas',
188 g_menu in 'g_menu.pas',
193 fmod in '../lib/FMOD/fmod.pas',
194 fmoderrors in '../lib/FMOD/fmoderrors.pas',
195 fmodpresets in '../lib/FMOD/fmodpresets.pas',
196 fmodtypes in '../lib/FMOD/fmodtypes.pas',
198 xprofiler in '../shared/xprofiler.pas',
199 binheap in '../shared/binheap.pas',
200 hashtable in '../shared/hashtable.pas',
201 fhashdb in '../shared/fhashdb.pas',
202 idpool in '../shared/idpool.pas',
203 xparser in '../shared/xparser.pas',
204 xdynrec in '../shared/xdynrec.pas',
205 exoma in '../shared/exoma.pas',
206 envvars in '../shared/envvars.pas',
207 g_panel in 'g_panel.pas',
208 g_language in 'g_language.pas',
210 {$IFDEF ENABLE_HOLMES}
211 g_holmes in 'g_holmes.pas',
213 sdlcarcass in '../flexui/sdlcarcass.pas',
214 //sdlstandalone in '../flexui/sdlstandalone.pas',
216 fui_wadread in '../flexui/fui_wadread.pas',
217 fui_common in '../flexui/fui_common.pas',
218 fui_gfx_gl in '../flexui/fui_gfx_gl.pas',
219 fui_events in '../flexui/fui_events.pas',
220 fui_style in '../flexui/fui_style.pas',
221 fui_flexlay in '../flexui/fui_flexlay.pas',
222 fui_ctls in '../flexui/fui_ctls.pas',
232 autoexecScript = 'autoexec.cfg';
235 noct: Boolean = False;
236 binPath: AnsiString = '';
237 forceBinDir: Boolean = False;
238 {$IFDEF USE_SDLMIXER}
239 UseNativeMusic: Boolean;
247 // remember old mobj positions, prepare for update
249 // server: receive client commands for new frame
250 // client: receive game state changes from server
251 if (NetMode = NET_SERVER) then g_Net_Host_Update()
252 else if (NetMode = NET_CLIENT) then g_Net_Client_Update();
258 // server: send any accumulated outgoing data to clients
259 if NetMode = NET_SERVER then g_Net_Flush();
262 function ProcessMessage (): Boolean;
266 Time, Time_Delta: Int64;
272 Result := sys_HandleInput();
275 Time := GetTickCount64();
276 Time_Delta := Time-Time_Old;
280 if wNeedTimeReset then
284 wNeedTimeReset := false;
287 g_Map_ProfilersBegin();
288 g_Mons_ProfilersBegin();
290 t := Time_Delta div 28;
298 g_Map_ProfilersEnd();
299 g_Mons_ProfilersEnd();
301 if (gExit = EXIT_QUIT) then
307 // Время предыдущего обновления
309 Time_Old := Time - (Time_Delta mod 28);
311 // don't wait if VSync is on, GL already probably waits enough
313 flag := (Time - Frame >= gFrameTime) or gVSync;
317 if gPause or (not gLerpActors) or (gState = STATE_FOLD) then
320 gLerpFactor := nmin(1.0, (Time - Time_Old) / 28.0);
333 procedure DebugOptions;
338 {$IFDEF ENABLE_HOLMES}
344 while (idx <= ParamCount) do
346 arg := ParamStr(idx);
348 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
349 if arg = '--jah' then g_profile_history_size := 100;
350 if arg = '--no-los' then gmon_dbg_los_enabled := false;
352 if arg = '--profile-render' then g_profile_frame_draw := true;
353 if arg = '--profile-coldet' then g_profile_collision := true;
354 if arg = '--profile-los' then g_profile_los := true;
357 if arg = '--no-particles' then gpart_dbg_enabled := false;
358 if arg = '--no-part-phys' then gpart_dbg_phys_enabled := false;
359 if arg = '--no-part-physics' then gpart_dbg_phys_enabled := false;
360 if arg = '--no-particles-phys' then gpart_dbg_phys_enabled := false;
361 if arg = '--no-particles-physics' then gpart_dbg_phys_enabled := false;
362 if arg = '--no-particle-phys' then gpart_dbg_phys_enabled := false;
363 if arg = '--no-particle-physics' then gpart_dbg_phys_enabled := false;
366 if arg = '--debug-input' then g_dbg_input := True;
368 {.$IF DEFINED(D2F_DEBUG)}
369 if arg = '--aimline' then g_dbg_aimline_on := true;
372 {$IFDEF ENABLE_HOLMES}
373 if arg = '--holmes' then begin g_holmes_enabled := true; g_Game_SetDebugMode(); end;
375 if (arg = '--holmes-ui-scale') or (arg = '-holmes-ui-scale') then
377 if (idx <= ParamCount) then
379 if not conParseFloat(fuiRenderScale, ParamStr(idx)) then fuiRenderScale := 1.0;
384 if (arg = '--holmes-font') or (arg = '-holmes-font') then
386 if (idx <= ParamCount) then
389 val(ParamStr(idx), itmp, valres);
391 if (valres = 0) and (not g_holmes_imfunctional) then
394 8: uiContext.font := 'win8';
395 14: uiContext.font := 'win14';
396 16: uiContext.font := 'win16';
409 if (arg = '--game-scale') or (arg = '-game-scale') then
411 if (idx <= ParamCount) then
413 if not conParseFloat(g_dbg_scale, ParamStr(idx)) then g_dbg_scale := 1.0;
418 if (arg = '--write-mapdef') or (arg = '-write-mapdef') then
420 mdfo := createDiskFile('mapdef.txt');
421 mdfo.WriteBuffer(defaultMapDef[1], Length(defaultMapDef));
426 if (arg = '--pixel-scale') or (arg = '-pixel-scale') then
428 if (idx <= ParamCount) then
430 if not conParseFloat(r_pixel_scale, ParamStr(idx)) then r_pixel_scale := 1.0;
437 function GetBinaryPath (): AnsiString;
442 result := ExtractFilePath(ParamStr(0));
444 // it may be a symlink; do some guesswork here
445 sl := fpReadLink(ExtractFileName(ParamStr(0)));
446 if (sl = ParamStr(0)) then
448 // use current directory, as we don't have anything better
453 result := fixSlashes(result);
454 if (length(result) > 0) and (result[length(result)] <> '/') then
455 result := result + '/';
458 procedure PrintDirs (msg: AnsiString; dirs: SSArray);
461 e_LogWriteln(msg + ':');
463 e_LogWriteln(' ' + dir);
467 function NSStringToAnsiString (s: NSString): AnsiString;
471 for i := 0 to s.length - 1 do
472 result := result + AnsiChar(s.characterAtIndex(i));
475 function GetBundlePath (): AnsiString;
476 var pathRef: CFURLRef; pathCFStr: CFStringRef; pathStr: ShortString;
478 pathRef := CFBundleCopyBundleURL(CFBundleGetMainBundle());
479 pathCFStr := CFURLCopyFileSystemPath(pathRef, kCFURLPOSIXPathStyle);
480 CFStringGetPascalString(pathCFStr, @pathStr, 255, CFStringGetSystemEncoding());
482 CFRelease(pathCFStr);
488 var i: Integer; rwdir, rodir: AnsiString; rwdirs, rodirs: SSArray;
490 procedure AddDir (var dirs: SSArray; append: AnsiString);
492 SetLength(dirs, Length(dirs) + 1);
493 dirs[High(dirs)] := ExpandFileName(append)
496 function IsSep (ch: Char): Boolean;
499 result := (ch = '/') or (ch = '\');
501 result := (ch = '/');
505 function OptimizePath (dir: AnsiString): AnsiString;
506 var i, len: Integer; s: AnsiString;
508 i := 1; len := Length(dir); s := '';
511 if IsSep(dir[i]) then
513 s := s + DirectorySeparator;
515 while (i <= len) and IsSep(dir[i]) do Inc(i);
516 if (i <= len) and (dir[i] = '.') then
518 if (i = len) or IsSep(dir[i + 1]) then
522 else if (i + 1 <= len) and (dir[i + 1] = '.') then
524 if (i + 1 = len) or IsSep(dir[i + 2]) then
541 procedure OptimizeDirs (var dirs: SSArray);
542 var i, j, k: Integer;
544 for i := 0 to High(dirs) do
545 dirs[i] := OptimizePath(dirs[i]);
553 if dirs[j] = dirs[i] then
555 for k := j + 1 to High(dirs) do
556 dirs[k - 1] := dirs[k];
558 SetLength(dirs, High(dirs))
569 procedure AddDef (var dirs: SSArray; base: SSArray; append: AnsiString);
572 if Length(dirs) = 0 then
574 AddDir(dirs, e_CatPath(s, append));
578 function GetDefaultRODirs (): SSArray;
579 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
580 var home: AnsiString;
583 var appdata: AnsiString;
586 var bundle, s: AnsiString; dirArr: NSArray; i: Integer;
591 bundle := GetBundlePath();
592 if ExtractFileExt(bundle) <> '.app' then
593 AddDir(result, binpath);
595 AddDir(result, binPath);
597 if forceBinDir = false then
600 AddDir(result, SDL_GetBasePath());
601 AddDir(result, SDL_GetPrefPath('', 'doom2df'));
604 appdata := GetEnvironmentVariable('APPDATA') + '\doom2df';
605 if appdata <> '' then
606 AddDir(result, appdata);
608 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
609 AddDir(result, '/usr/share/doom2df');
610 AddDir(result, '/usr/local/share/doom2df');
611 home := GetEnvironmentVariable('HOME');
613 AddDir(result, e_CatPath(home, '.doom2df'));
616 bundle := GetBundlePath();
618 AddDir(result, e_CatPath(bundle, 'Contents/Resources'));
619 dirArr := NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true);
620 for i := 0 to dirArr.count - 1 do
622 s := NSStringToAnsiString(dirArr.objectAtIndex(i));
623 AddDir(result, e_CatPath(s, 'Doom 2D Forever'))
626 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
627 AddDir(result, SDL_AndroidGetInternalStoragePath());
628 if SDL_AndroidGetExternalStorageState() <> 0 then
629 AddDir(result, SDL_AndroidGetExternalStoragePath());
634 function GetDefaultRWDirs (): SSArray;
635 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
636 var home: AnsiString;
639 var appdata: AnsiString;
642 var bundle, s: AnsiString; dirArr: NSArray; i: Integer;
647 bundle := GetBundlePath();
648 if ExtractFileExt(bundle) <> '.app' then
649 AddDir(result, binPath);
651 AddDir(result, binPath);
653 if forceBinDir = false then
656 AddDir(result, SDL_GetPrefPath('', 'doom2df'));
659 appdata := GetEnvironmentVariable('APPDATA') + '\doom2df';
660 if appdata <> '' then
661 AddDir(result, appdata);
663 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
664 home := GetEnvironmentVariable('HOME');
666 AddDir(result, e_CatPath(home, '.doom2df'));
669 dirArr := NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true);
670 for i := 0 to dirArr.count - 1 do
672 s := NSStringToAnsiString(dirArr.objectAtIndex(i));
673 AddDir(result, e_CatPath(s, 'Doom 2D Forever'))
676 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
677 if SDL_AndroidGetExternalStorageState() <> 0 then
678 AddDir(result, SDL_AndroidGetExternalStoragePath());
684 forceBinDir := false;
685 binPath := GetBinaryPath();
688 while i < ParamCount do
691 '--like-windoze': forceBinDir := true;
695 rwdir := ParamStr(i);
697 AddDir(LogDirs, e_CatPath(rwdir, ''));
698 AddDir(SaveDirs, e_CatPath(rwdir, 'data'));
699 AddDir(CacheDirs, e_CatPath(rwdir, 'data/cache'));
700 AddDir(ConfigDirs, e_CatPath(rwdir, ''));
701 AddDir(MapDownloadDirs, e_CatPath(rwdir, 'maps/downloads'));
702 AddDir(WadDownloadDirs, e_CatPath(rwdir, 'wads/downloads'));
703 AddDir(ScreenshotDirs, e_CatPath(rwdir, 'screenshots'));
704 AddDir(StatsDirs, e_CatPath(rwdir, 'stats'));
706 AddDir(DataDirs, e_CatPath(rwdir, 'data'));
707 AddDir(ModelDirs, e_CatPath(rwdir, 'data/models'));
708 AddDir(MegawadDirs, e_CatPath(rwdir, 'maps/megawads'));
709 AddDir(MapDirs, e_CatPath(rwdir, 'maps'));
710 AddDir(WadDirs, e_CatPath(rwdir, 'wads'));
715 rodir := ParamStr(i);
717 AddDir(DataDirs, e_CatPath(rodir, 'data'));
718 AddDir(ModelDirs, e_CatPath(rodir, 'data/models'));
719 AddDir(MegawadDirs, e_CatPath(rodir, 'maps/megawads'));
720 AddDir(MapDirs, e_CatPath(rodir, 'maps'));
721 AddDir(WadDirs, e_CatPath(rodir, 'wads'));
726 GameWADName := ParamStr(i);
731 gConfigScript := ParamStr(i);
737 // prefer bin dir if it writable and contains game.wad
738 if forceBinDir = false then
740 if findDiskWad(binPath + 'data' + '/' + GameWADName) <> '' then
741 if e_CanCreateFilesAt(binPath) then
746 rodirs := GetDefaultRODirs();
747 AddDef(DataDirs, rodirs, 'data');
748 AddDef(ModelDirs, rodirs, 'data/models');
749 AddDef(MegawadDirs, rodirs, 'maps/megawads');
750 AddDef(MapDirs, rodirs, 'maps');
751 AddDef(WadDirs, rodirs, 'wads');
754 rwdirs := GetDefaultRWDirs();
755 AddDef(LogDirs, rwdirs, '');
756 AddDef(SaveDirs, rwdirs, 'data');
757 AddDef(CacheDirs, rwdirs, 'data/cache');
758 AddDef(ConfigDirs, rwdirs, '');
759 AddDef(MapDownloadDirs, rwdirs, 'maps/downloads');
760 AddDef(WadDownloadDirs, rwdirs, 'wads/downloads');
761 AddDef(ScreenshotDirs, rwdirs, 'screenshots');
762 AddDef(StatsDirs, rwdirs, 'stats');
764 for i := 0 to High(MapDirs) do
765 AddDir(AllMapDirs, MapDirs[i]);
766 for i := 0 to High(MegawadDirs) do
767 AddDir(AllMapDirs, MegawadDirs[i]);
768 OptimizeDirs(AllMapDirs);
770 // HACK: ensure the screenshots folder also has a stats subfolder in it
771 rwdir := e_GetWriteableDir(ScreenshotDirs, false);
772 if rwdir <> '' then CreateDir(rwdir + '/stats');
775 procedure EntryParams;
779 while i <= ParamCount do
782 '--gdb': noct := true;
783 '--log', '--con-stdout': conbufDumpToStdOut := true;
784 '--safe-log': e_SetSafeSlowLog(true);
786 if i + 1 <= ParamCount then
789 LogFileName := ParamStr(i)
791 '--no-fbo': glRenderToFBO := false;
798 var rwdir: AnsiString;
800 if LogFileName = '' then
802 rwdir := e_GetWriteableDir(LogDirs, false);
806 LogFileName := e_CatPath(rwdir, 'Doom2DF_H.log');
808 LogFileName := e_CatPath(rwdir, 'Doom2DF.log');
812 if LogFileName <> '' then
813 e_InitLog(LogFileName, TWriteMode.WM_NEWFILE);
819 e_WriteLog('Doom 2D: Forever version ' + GAME_VERSION + ' proto ' + IntToStr(NET_PROTOCOL_VER), TMsgType.Notify);
820 e_WriteLog('Build arch: ' + g_GetBuildArch(), TMsgType.Notify);
821 e_WriteLog('Build date: ' + GAME_BUILDDATE + ' ' + GAME_BUILDTIME, TMsgType.Notify);
822 e_WriteLog('Build hash: ' + g_GetBuildHash(), TMsgType.Notify);
823 e_WriteLog('Build by: ' + g_GetBuilderName(), TMsgType.Notify);
825 e_LogWritefln('Force bin dir: %s', [forceBinDir], TMsgType.Notify);
826 e_LogWritefln('BINARY PATH: [%s]', [binPath], TMsgType.Notify);
828 PrintDirs('DataDirs', DataDirs);
829 PrintDirs('ModelDirs', ModelDirs);
830 PrintDirs('MegawadDirs', MegawadDirs);
831 PrintDirs('MapDirs', MapDirs);
832 PrintDirs('WadDirs', WadDirs);
834 PrintDirs('LogDirs', LogDirs);
835 PrintDirs('SaveDirs', SaveDirs);
836 PrintDirs('CacheDirs', CacheDirs);
837 PrintDirs('ConfigDirs', ConfigDirs);
838 PrintDirs('ScreenshotDirs', ScreenshotDirs);
839 PrintDirs('StatsDirs', StatsDirs);
840 PrintDirs('MapDownloadDirs', MapDownloadDirs);
841 PrintDirs('WadDownloadDirs', WadDownloadDirs);
844 {$IFDEF USE_SDLMIXER}
845 NoSound := False; // hope env has set SDL_AUDIODRIVER to dummy
847 NoSound := True; // FMOD backend will sort it out
853 GameWAD := e_FindWad(DataDirs, GameWADName);
856 e_WriteLog('WAD ' + GameWADName + ' not found in data directories.', TMsgType.Fatal);
857 {$IF DEFINED(USE_SDL2) AND NOT DEFINED(HEADLESS)}
858 if forceBinDir = false then
859 SDL_ShowSimpleMessageBox(
860 SDL_MESSAGEBOX_ERROR,
862 PChar('WAD ' + GameWADName + ' not found in data directories.'),
871 {$IFDEF ENABLE_HOLMES}
872 procedure InitHolmes;
873 var flexloaded: Boolean;
876 if not fuiAddWad('flexui.wad') then
878 if not fuiAddWad('./data/flexui.wad') then fuiAddWad('./flexui.wad');
881 fuiGfxLoadFont('win8', 'flexui/fonts/win8.fuifont');
882 fuiGfxLoadFont('win14', 'flexui/fonts/win14.fuifont');
883 fuiGfxLoadFont('win16', 'flexui/fonts/win16.fuifont');
884 fuiGfxLoadFont('dos8', 'flexui/fonts/dos8.fuifont');
885 fuiGfxLoadFont('msx6', 'flexui/fonts/msx6.fuifont');
886 except on e: Exception do
888 writeln('ERROR loading FlexUI fonts');
901 e_LogWriteln('FlexUI: loading stylesheet...');
902 uiLoadStyles('flexui/widgets.wgs');
903 except on e: TParserException do
905 writeln('ERROR at (', e.tokLine, ',', e.tokCol, '): ', e.message);
916 g_holmes_imfunctional := not flexloaded;
917 if not g_holmes_imfunctional then
920 uiContext.font := 'win14';
922 if assigned(oglInitCB) then oglInitCB;
925 procedure FreeHolmes;
927 if assigned(oglDeinitCB) then
933 {$IFDEF USE_SDLMIXER}
934 var timiditycfg: AnsiString;
935 var oldcwd, newcwd: RawByteString;
938 if NoSound = false then
940 e_WriteLog('Initializing sound system', TMsgType.Notify);
941 {$IFDEF USE_SDLMIXER}
943 if UseNativeMusic then
944 SetEnvVar('SDL_NATIVE_MUSIC', '1');
945 timiditycfg := GetEnvironmentVariable('TIMIDITY_CFG');
946 if timiditycfg = '' then
948 timiditycfg := 'timidity.cfg';
949 if e_FindResource(ConfigDirs, timiditycfg) OR e_FindResource(DataDirs, timiditycfg) then
951 timiditycfg := ExpandFileName(timiditycfg);
952 newcwd := ExtractFileDir(timiditycfg);
953 SetEnvVar('TIMIDITY_CFG', timiditycfg);
958 e_LogWritefln('TIMIDITY_CFG = "%s"', [timiditycfg]);
959 e_LogWritefln('SDL_NATIVE_MUSIC = "%s"', [GetEnvironmentVariable('SDL_NATIVE_MUSIC')]);
961 e_InitSoundSystem(NoSound);
962 {$IFDEF USE_SDLMIXER}
963 if e_TimidityDecoder and (newcwd <> '') then
965 (* HACK: Set CWD to load GUS patches relatively to cfg file. *)
966 (* CWD not restored after sound init because timidity *)
967 (* store relative pathes internally and load patches *)
968 (* later. I hope game never relies on CWD. *)
972 e_logwritefln('WARNING: USED TIMIDITY CONFIG HACK, CWD SWITCHED "%s" -> "%s"', [oldcwd, newcwd]);
978 procedure ScreenResize (w, h: Integer);
981 r_Render_Resize(w, h);
982 {$IFDEF ENABLE_HOLMES}
987 (* This will fix menu reset on keyboard showing *)
992 //g_Game_ClearLoading;
993 {$IFDEF ENABLE_HOLMES}
994 if assigned(oglInitCB) then oglInitCB;
1009 sys_CharPress := @CharPress; (* install hook *)
1010 sys_ScreenResize := @ScreenResize; (* install hook *)
1012 g_Options_SetDefault;
1013 g_Options_SetDefaultVideo;
1014 g_Console_Initialize;
1015 // TODO move load configs here
1016 g_Language_Set(gLanguage);
1018 r_Render_Initialize;
1022 // TODO init serverlist
1023 {$IFDEF ENABLE_HOLMES}
1027 g_PlayerModel_LoadFake('doomer', 'doomer.wad');
1029 g_PlayerModel_LoadAll;
1033 {$IFDEF ENABLE_MENU}
1037 g_Game_Process_Params;
1038 // TODO reload GAME textures
1039 g_Console_Init; // welcome message
1040 {$IFDEF ENABLE_MENU}
1041 if (not gGameOn) and gAskLanguage then
1044 Time_Old := GetTickCount64();
1045 while not ProcessMessage() do begin end;
1046 g_Console_WriteGameConfig;
1047 {$IFDEF ENABLE_MENU}
1054 {$IFDEF ENABLE_HOLMES}
1057 g_Net_Slist_ShutdownAll;
1058 g_Net_DeinitLowLevel;
1059 (* g_Touch_Finalize; *)
1065 e_ReleaseSoundSystem;
1067 e_WriteLog('Shutdown with no errors.', TMsgType.Notify)
1070 procedure InitCVars;
1072 {$IFDEF USE_SDLMIXER}
1073 conRegVar('sdl_native_music', @UseNativeMusic, 'use native midi music output when possible', 'use native midi');
1075 UseNativeMusic := true; (* OSX have a good midi support, so why not? *)
1077 UseNativeMusic := false;
1082 procedure EntryPoint;
1084 SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]); //k8: fuck off, that's why
1089 conbufDumpToStdOut := true;
1096 except on e: Exception do
1097 e_WriteStackTrace(e.message)
1099 e_WriteStackTrace('FATAL ERROR')
1105 function SDL_main (argc: CInt; argv: PPChar): CInt; cdecl;
1108 System.argc := argc;
1109 System.argv := argv;
1115 function JNI_OnLoad (vm: PJavaVM; reserved: pointer): JInt; cdecl;
1117 result:= JNI_VERSION_1_6;
1120 procedure JNI_OnUnload(vm: PJavaVM; reserved: pointer); cdecl;
1124 // DONT REMOVE JNI FUNCTIONS. SPECIAL HANDLING BY FPC.
1125 exports SDL_main name 'SDL_main';
1126 exports JNI_OnLoad name 'JNI_OnLoad';
1127 exports JNI_OnUnload name 'JNI_Unload';