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',
126 g_gfx in 'g_gfx.pas',
127 g_items in 'g_items.pas',
128 g_map in 'g_map.pas',
129 g_monsters in 'g_monsters.pas',
130 g_options in 'g_options.pas',
131 g_phys in 'g_phys.pas',
132 g_player in 'g_player.pas',
133 g_playermodel in 'g_playermodel.pas',
134 g_saveload in 'g_saveload.pas',
135 g_sound in 'g_sound.pas',
136 g_textures in 'g_textures.pas',
137 g_triggers in 'g_triggers.pas',
138 g_weapons in 'g_weapons.pas',
139 g_window in 'g_window.pas',
142 g_system in 'stub/g_system.pas',
143 g_touch in 'stub/g_touch.pas',
146 g_system in 'sdl/g_system.pas',
147 g_touch in 'sdl/g_touch.pas',
150 g_system in 'sdl2/g_system.pas',
151 g_touch in 'sdl2/g_touch.pas',
156 {$I ../shared/vampimg.inc}
157 r_animations in 'opengl/r_animations.pas',
158 r_console in 'opengl/r_console.pas',
159 r_game in 'opengl/r_game.pas',
160 r_gfx in 'opengl/r_gfx.pas',
161 r_graphics in 'opengl/r_graphics.pas',
162 r_items in 'opengl/r_items.pas',
163 r_map in 'opengl/r_map.pas',
164 r_monsters in 'opengl/r_monsters.pas',
165 r_netmaster in 'opengl/r_netmaster.pas',
166 r_player in 'opengl/r_player.pas',
167 r_playermodel in 'opengl/r_playermodel.pas',
168 r_render in 'opengl/r_render.pas',
169 r_texture in 'opengl/r_texture.pas',
170 r_textures in 'opengl/r_textures.pas',
171 r_weapons in 'opengl/r_weapons.pas',
172 r_window in 'opengl/r_window.pas',
174 g_gui in 'g_gui.pas',
175 g_menu in 'g_menu.pas',
180 fmod in '../lib/FMOD/fmod.pas',
181 fmoderrors in '../lib/FMOD/fmoderrors.pas',
182 fmodpresets in '../lib/FMOD/fmodpresets.pas',
183 fmodtypes in '../lib/FMOD/fmodtypes.pas',
185 xprofiler in '../shared/xprofiler.pas',
186 binheap in '../shared/binheap.pas',
187 hashtable in '../shared/hashtable.pas',
188 fhashdb in '../shared/fhashdb.pas',
189 idpool in '../shared/idpool.pas',
190 xparser in '../shared/xparser.pas',
191 xdynrec in '../shared/xdynrec.pas',
192 exoma in '../shared/exoma.pas',
193 envvars in '../shared/envvars.pas',
194 g_panel in 'g_panel.pas',
195 g_language in 'g_language.pas',
197 {$IFDEF ENABLE_HOLMES}
198 g_holmes in 'g_holmes.pas',
200 sdlcarcass in '../flexui/sdlcarcass.pas',
201 //sdlstandalone in '../flexui/sdlstandalone.pas',
203 fui_wadread in '../flexui/fui_wadread.pas',
204 fui_common in '../flexui/fui_common.pas',
205 fui_gfx_gl in '../flexui/fui_gfx_gl.pas',
206 fui_events in '../flexui/fui_events.pas',
207 fui_style in '../flexui/fui_style.pas',
208 fui_flexlay in '../flexui/fui_flexlay.pas',
209 fui_ctls in '../flexui/fui_ctls.pas',
219 autoexecScript = 'autoexec.cfg';
222 noct: Boolean = False;
223 binPath: AnsiString = '';
224 forceBinDir: Boolean = False;
225 {$IFDEF USE_SDLMIXER}
226 UseNativeMusic: Boolean;
234 // remember old mobj positions, prepare for update
236 // server: receive client commands for new frame
237 // client: receive game state changes from server
238 if (NetMode = NET_SERVER) then g_Net_Host_Update()
239 else if (NetMode = NET_CLIENT) then g_Net_Client_Update();
245 // server: send any accumulated outgoing data to clients
246 if NetMode = NET_SERVER then g_Net_Flush();
249 function ProcessMessage (): Boolean;
253 Time, Time_Delta: Int64;
259 Result := sys_HandleInput();
262 Time := GetTickCount64();
263 Time_Delta := Time-Time_Old;
267 if wNeedTimeReset then
271 wNeedTimeReset := false;
274 g_Map_ProfilersBegin();
275 g_Mons_ProfilersBegin();
277 t := Time_Delta div 28;
285 g_Map_ProfilersEnd();
286 g_Mons_ProfilersEnd();
288 if (gExit = EXIT_QUIT) then
294 // Время предыдущего обновления
296 Time_Old := Time - (Time_Delta mod 28);
298 // don't wait if VSync is on, GL already probably waits enough
300 flag := (Time - Frame >= gFrameTime) or gVSync;
304 if gPause or (not gLerpActors) or (gState = STATE_FOLD) then
307 gLerpFactor := nmin(1.0, (Time - Time_Old) / 28.0);
320 procedure DebugOptions;
325 {$IFDEF ENABLE_HOLMES}
331 while (idx <= ParamCount) do
333 arg := ParamStr(idx);
335 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
336 if arg = '--jah' then g_profile_history_size := 100;
337 if arg = '--no-particles' then gpart_dbg_enabled := false;
338 if arg = '--no-los' then gmon_dbg_los_enabled := false;
340 if arg = '--profile-render' then g_profile_frame_draw := true;
341 if arg = '--profile-coldet' then g_profile_collision := true;
342 if arg = '--profile-los' then g_profile_los := true;
344 if arg = '--no-part-phys' then gpart_dbg_phys_enabled := false;
345 if arg = '--no-part-physics' then gpart_dbg_phys_enabled := false;
346 if arg = '--no-particles-phys' then gpart_dbg_phys_enabled := false;
347 if arg = '--no-particles-physics' then gpart_dbg_phys_enabled := false;
348 if arg = '--no-particle-phys' then gpart_dbg_phys_enabled := false;
349 if arg = '--no-particle-physics' then gpart_dbg_phys_enabled := false;
351 if arg = '--debug-input' then g_dbg_input := True;
353 {.$IF DEFINED(D2F_DEBUG)}
354 if arg = '--aimline' then g_dbg_aimline_on := true;
357 {$IFDEF ENABLE_HOLMES}
358 if arg = '--holmes' then begin g_holmes_enabled := true; g_Game_SetDebugMode(); end;
360 if (arg = '--holmes-ui-scale') or (arg = '-holmes-ui-scale') then
362 if (idx <= ParamCount) then
364 if not conParseFloat(fuiRenderScale, ParamStr(idx)) then fuiRenderScale := 1.0;
369 if (arg = '--holmes-font') or (arg = '-holmes-font') then
371 if (idx <= ParamCount) then
374 val(ParamStr(idx), itmp, valres);
376 if (valres = 0) and (not g_holmes_imfunctional) then
379 8: uiContext.font := 'win8';
380 14: uiContext.font := 'win14';
381 16: uiContext.font := 'win16';
394 if (arg = '--game-scale') or (arg = '-game-scale') then
396 if (idx <= ParamCount) then
398 if not conParseFloat(g_dbg_scale, ParamStr(idx)) then g_dbg_scale := 1.0;
403 if (arg = '--write-mapdef') or (arg = '-write-mapdef') then
405 mdfo := createDiskFile('mapdef.txt');
406 mdfo.WriteBuffer(defaultMapDef[1], Length(defaultMapDef));
411 if (arg = '--pixel-scale') or (arg = '-pixel-scale') then
413 if (idx <= ParamCount) then
415 if not conParseFloat(r_pixel_scale, ParamStr(idx)) then r_pixel_scale := 1.0;
422 function GetBinaryPath (): AnsiString;
427 result := ExtractFilePath(ParamStr(0));
429 // it may be a symlink; do some guesswork here
430 sl := fpReadLink(ExtractFileName(ParamStr(0)));
431 if (sl = ParamStr(0)) then
433 // use current directory, as we don't have anything better
438 result := fixSlashes(result);
439 if (length(result) > 0) and (result[length(result)] <> '/') then
440 result := result + '/';
443 procedure PrintDirs (msg: AnsiString; dirs: SSArray);
446 e_LogWriteln(msg + ':');
448 e_LogWriteln(' ' + dir);
452 function NSStringToAnsiString (s: NSString): AnsiString;
456 for i := 0 to s.length - 1 do
457 result := result + AnsiChar(s.characterAtIndex(i));
460 function GetBundlePath (): AnsiString;
461 var pathRef: CFURLRef; pathCFStr: CFStringRef; pathStr: ShortString;
463 pathRef := CFBundleCopyBundleURL(CFBundleGetMainBundle());
464 pathCFStr := CFURLCopyFileSystemPath(pathRef, kCFURLPOSIXPathStyle);
465 CFStringGetPascalString(pathCFStr, @pathStr, 255, CFStringGetSystemEncoding());
467 CFRelease(pathCFStr);
473 var i: Integer; rwdir, rodir: AnsiString; rwdirs, rodirs: SSArray;
475 procedure AddDir (var dirs: SSArray; append: AnsiString);
477 SetLength(dirs, Length(dirs) + 1);
478 dirs[High(dirs)] := ExpandFileName(append)
481 function IsSep (ch: Char): Boolean;
484 result := (ch = '/') or (ch = '\');
486 result := (ch = '/');
490 function OptimizePath (dir: AnsiString): AnsiString;
491 var i, len: Integer; s: AnsiString;
493 i := 1; len := Length(dir); s := '';
496 if IsSep(dir[i]) then
498 s := s + DirectorySeparator;
500 while (i <= len) and IsSep(dir[i]) do Inc(i);
501 if (i <= len) and (dir[i] = '.') then
503 if (i = len) or IsSep(dir[i + 1]) then
507 else if (i + 1 <= len) and (dir[i + 1] = '.') then
509 if (i + 1 = len) or IsSep(dir[i + 2]) then
526 procedure OptimizeDirs (var dirs: SSArray);
527 var i, j, k: Integer;
529 for i := 0 to High(dirs) do
530 dirs[i] := OptimizePath(dirs[i]);
538 if dirs[j] = dirs[i] then
540 for k := j + 1 to High(dirs) do
541 dirs[k - 1] := dirs[k];
543 SetLength(dirs, High(dirs))
554 procedure AddDef (var dirs: SSArray; base: SSArray; append: AnsiString);
557 if Length(dirs) = 0 then
559 AddDir(dirs, e_CatPath(s, append));
563 function GetDefaultRODirs (): SSArray;
564 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
565 var home: AnsiString;
568 var appdata: AnsiString;
571 var bundle, s: AnsiString; dirArr: NSArray; i: Integer;
576 bundle := GetBundlePath();
577 if ExtractFileExt(bundle) <> '.app' then
578 AddDir(result, binpath);
580 AddDir(result, binPath);
582 if forceBinDir = false then
585 AddDir(result, SDL_GetBasePath());
586 AddDir(result, SDL_GetPrefPath('', 'doom2df'));
589 appdata := GetEnvironmentVariable('APPDATA') + '\doom2df';
590 if appdata <> '' then
591 AddDir(result, appdata);
593 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
594 AddDir(result, '/usr/share/doom2df');
595 AddDir(result, '/usr/local/share/doom2df');
596 home := GetEnvironmentVariable('HOME');
598 AddDir(result, e_CatPath(home, '.doom2df'));
601 bundle := GetBundlePath();
603 AddDir(result, e_CatPath(bundle, 'Contents/Resources'));
604 dirArr := NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true);
605 for i := 0 to dirArr.count - 1 do
607 s := NSStringToAnsiString(dirArr.objectAtIndex(i));
608 AddDir(result, e_CatPath(s, 'Doom 2D Forever'))
611 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
612 AddDir(result, SDL_AndroidGetInternalStoragePath());
613 if SDL_AndroidGetExternalStorageState() <> 0 then
614 AddDir(result, SDL_AndroidGetExternalStoragePath());
619 function GetDefaultRWDirs (): SSArray;
620 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
621 var home: AnsiString;
624 var appdata: AnsiString;
627 var bundle, s: AnsiString; dirArr: NSArray; i: Integer;
632 bundle := GetBundlePath();
633 if ExtractFileExt(bundle) <> '.app' then
634 AddDir(result, binPath);
636 AddDir(result, binPath);
638 if forceBinDir = false then
641 AddDir(result, SDL_GetPrefPath('', 'doom2df'));
644 appdata := GetEnvironmentVariable('APPDATA') + '\doom2df';
645 if appdata <> '' then
646 AddDir(result, appdata);
648 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
649 home := GetEnvironmentVariable('HOME');
651 AddDir(result, e_CatPath(home, '.doom2df'));
654 dirArr := NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true);
655 for i := 0 to dirArr.count - 1 do
657 s := NSStringToAnsiString(dirArr.objectAtIndex(i));
658 AddDir(result, e_CatPath(s, 'Doom 2D Forever'))
661 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
662 if SDL_AndroidGetExternalStorageState() <> 0 then
663 AddDir(result, SDL_AndroidGetExternalStoragePath());
669 forceBinDir := false;
670 binPath := GetBinaryPath();
673 while i < ParamCount do
676 '--like-windoze': forceBinDir := true;
680 rwdir := ParamStr(i);
682 AddDir(LogDirs, e_CatPath(rwdir, ''));
683 AddDir(SaveDirs, e_CatPath(rwdir, 'data'));
684 AddDir(CacheDirs, e_CatPath(rwdir, 'data/cache'));
685 AddDir(ConfigDirs, e_CatPath(rwdir, ''));
686 AddDir(MapDownloadDirs, e_CatPath(rwdir, 'maps/downloads'));
687 AddDir(WadDownloadDirs, e_CatPath(rwdir, 'wads/downloads'));
688 AddDir(ScreenshotDirs, e_CatPath(rwdir, 'screenshots'));
689 AddDir(StatsDirs, e_CatPath(rwdir, 'stats'));
691 AddDir(DataDirs, e_CatPath(rwdir, 'data'));
692 AddDir(ModelDirs, e_CatPath(rwdir, 'data/models'));
693 AddDir(MegawadDirs, e_CatPath(rwdir, 'maps/megawads'));
694 AddDir(MapDirs, e_CatPath(rwdir, 'maps'));
695 AddDir(WadDirs, e_CatPath(rwdir, 'wads'));
700 rodir := ParamStr(i);
702 AddDir(DataDirs, e_CatPath(rodir, 'data'));
703 AddDir(ModelDirs, e_CatPath(rodir, 'data/models'));
704 AddDir(MegawadDirs, e_CatPath(rodir, 'maps/megawads'));
705 AddDir(MapDirs, e_CatPath(rodir, 'maps'));
706 AddDir(WadDirs, e_CatPath(rodir, 'wads'));
711 GameWADName := ParamStr(i);
716 gConfigScript := ParamStr(i);
722 // prefer bin dir if it writable and contains game.wad
723 if forceBinDir = false then
725 if findDiskWad(binPath + 'data' + '/' + GameWADName) <> '' then
726 if e_CanCreateFilesAt(binPath) then
731 rodirs := GetDefaultRODirs();
732 AddDef(DataDirs, rodirs, 'data');
733 AddDef(ModelDirs, rodirs, 'data/models');
734 AddDef(MegawadDirs, rodirs, 'maps/megawads');
735 AddDef(MapDirs, rodirs, 'maps');
736 AddDef(WadDirs, rodirs, 'wads');
739 rwdirs := GetDefaultRWDirs();
740 AddDef(LogDirs, rwdirs, '');
741 AddDef(SaveDirs, rwdirs, 'data');
742 AddDef(CacheDirs, rwdirs, 'data/cache');
743 AddDef(ConfigDirs, rwdirs, '');
744 AddDef(MapDownloadDirs, rwdirs, 'maps/downloads');
745 AddDef(WadDownloadDirs, rwdirs, 'wads/downloads');
746 AddDef(ScreenshotDirs, rwdirs, 'screenshots');
747 AddDef(StatsDirs, rwdirs, 'stats');
749 for i := 0 to High(MapDirs) do
750 AddDir(AllMapDirs, MapDirs[i]);
751 for i := 0 to High(MegawadDirs) do
752 AddDir(AllMapDirs, MegawadDirs[i]);
753 OptimizeDirs(AllMapDirs);
755 // HACK: ensure the screenshots folder also has a stats subfolder in it
756 rwdir := e_GetWriteableDir(ScreenshotDirs, false);
757 if rwdir <> '' then CreateDir(rwdir + '/stats');
760 procedure EntryParams;
764 while i <= ParamCount do
767 '--gdb': noct := true;
768 '--log', '--con-stdout': conbufDumpToStdOut := true;
769 '--safe-log': e_SetSafeSlowLog(true);
771 if i + 1 <= ParamCount then
774 LogFileName := ParamStr(i)
776 '--no-fbo': glRenderToFBO := false;
783 var rwdir: AnsiString;
785 if LogFileName = '' then
787 rwdir := e_GetWriteableDir(LogDirs, false);
791 LogFileName := e_CatPath(rwdir, 'Doom2DF_H.log');
793 LogFileName := e_CatPath(rwdir, 'Doom2DF.log');
797 if LogFileName <> '' then
798 e_InitLog(LogFileName, TWriteMode.WM_NEWFILE);
804 e_WriteLog('Doom 2D: Forever version ' + GAME_VERSION + ' proto ' + IntToStr(NET_PROTOCOL_VER), TMsgType.Notify);
805 e_WriteLog('Build arch: ' + g_GetBuildArch(), TMsgType.Notify);
806 e_WriteLog('Build date: ' + GAME_BUILDDATE + ' ' + GAME_BUILDTIME, TMsgType.Notify);
807 e_WriteLog('Build hash: ' + g_GetBuildHash(), TMsgType.Notify);
808 e_WriteLog('Build by: ' + g_GetBuilderName(), TMsgType.Notify);
810 e_LogWritefln('Force bin dir: %s', [forceBinDir], TMsgType.Notify);
811 e_LogWritefln('BINARY PATH: [%s]', [binPath], TMsgType.Notify);
813 PrintDirs('DataDirs', DataDirs);
814 PrintDirs('ModelDirs', ModelDirs);
815 PrintDirs('MegawadDirs', MegawadDirs);
816 PrintDirs('MapDirs', MapDirs);
817 PrintDirs('WadDirs', WadDirs);
819 PrintDirs('LogDirs', LogDirs);
820 PrintDirs('SaveDirs', SaveDirs);
821 PrintDirs('CacheDirs', CacheDirs);
822 PrintDirs('ConfigDirs', ConfigDirs);
823 PrintDirs('ScreenshotDirs', ScreenshotDirs);
824 PrintDirs('StatsDirs', StatsDirs);
825 PrintDirs('MapDownloadDirs', MapDownloadDirs);
826 PrintDirs('WadDownloadDirs', WadDownloadDirs);
829 {$IFDEF USE_SDLMIXER}
830 NoSound := False; // hope env has set SDL_AUDIODRIVER to dummy
832 NoSound := True; // FMOD backend will sort it out
838 GameWAD := e_FindWad(DataDirs, GameWADName);
841 e_WriteLog('WAD ' + GameWADName + ' not found in data directories.', TMsgType.Fatal);
842 {$IF DEFINED(USE_SDL2) AND NOT DEFINED(HEADLESS)}
843 if forceBinDir = false then
844 SDL_ShowSimpleMessageBox(
845 SDL_MESSAGEBOX_ERROR,
847 PChar('WAD ' + GameWADName + ' not found in data directories.'),
856 {$IFDEF ENABLE_HOLMES}
857 procedure InitHolmes;
858 var flexloaded: Boolean;
861 if not fuiAddWad('flexui.wad') then
863 if not fuiAddWad('./data/flexui.wad') then fuiAddWad('./flexui.wad');
866 fuiGfxLoadFont('win8', 'flexui/fonts/win8.fuifont');
867 fuiGfxLoadFont('win14', 'flexui/fonts/win14.fuifont');
868 fuiGfxLoadFont('win16', 'flexui/fonts/win16.fuifont');
869 fuiGfxLoadFont('dos8', 'flexui/fonts/dos8.fuifont');
870 fuiGfxLoadFont('msx6', 'flexui/fonts/msx6.fuifont');
871 except on e: Exception do
873 writeln('ERROR loading FlexUI fonts');
886 e_LogWriteln('FlexUI: loading stylesheet...');
887 uiLoadStyles('flexui/widgets.wgs');
888 except on e: TParserException do
890 writeln('ERROR at (', e.tokLine, ',', e.tokCol, '): ', e.message);
901 g_holmes_imfunctional := not flexloaded;
902 if not g_holmes_imfunctional then
905 uiContext.font := 'win14';
907 if assigned(oglInitCB) then oglInitCB;
910 procedure FreeHolmes;
912 if assigned(oglDeinitCB) then
918 {$IFDEF USE_SDLMIXER}
919 var timiditycfg: AnsiString;
920 var oldcwd, newcwd: RawByteString;
923 if NoSound = false then
925 e_WriteLog('Initializing sound system', TMsgType.Notify);
926 {$IFDEF USE_SDLMIXER}
928 if UseNativeMusic then
929 SetEnvVar('SDL_NATIVE_MUSIC', '1');
930 timiditycfg := GetEnvironmentVariable('TIMIDITY_CFG');
931 if timiditycfg = '' then
933 timiditycfg := 'timidity.cfg';
934 if e_FindResource(ConfigDirs, timiditycfg) OR e_FindResource(DataDirs, timiditycfg) then
936 timiditycfg := ExpandFileName(timiditycfg);
937 newcwd := ExtractFileDir(timiditycfg);
938 SetEnvVar('TIMIDITY_CFG', timiditycfg);
943 e_LogWritefln('TIMIDITY_CFG = "%s"', [timiditycfg]);
944 e_LogWritefln('SDL_NATIVE_MUSIC = "%s"', [GetEnvironmentVariable('SDL_NATIVE_MUSIC')]);
946 e_InitSoundSystem(NoSound);
947 {$IFDEF USE_SDLMIXER}
948 if e_TimidityDecoder and (newcwd <> '') then
950 (* HACK: Set CWD to load GUS patches relatively to cfg file. *)
951 (* CWD not restored after sound init because timidity *)
952 (* store relative pathes internally and load patches *)
953 (* later. I hope game never relies on CWD. *)
957 e_logwritefln('WARNING: USED TIMIDITY CONFIG HACK, CWD SWITCHED "%s" -> "%s"', [oldcwd, newcwd]);
963 procedure ScreenResize (w, h: Integer);
966 r_Render_Resize(w, h);
967 {$IFDEF ENABLE_HOLMES}
972 (* This will fix menu reset on keyboard showing *)
977 //g_Game_ClearLoading;
978 {$IFDEF ENABLE_HOLMES}
979 if assigned(oglInitCB) then oglInitCB;
994 sys_CharPress := @CharPress; (* install hook *)
995 sys_ScreenResize := @ScreenResize; (* install hook *)
997 g_Options_SetDefault;
998 g_Options_SetDefaultVideo;
999 g_Console_Initialize;
1000 // TODO move load configs here
1001 g_Language_Set(gLanguage);
1003 r_Render_Initialize;
1008 // TODO init serverlist
1009 {$IFDEF ENABLE_HOLMES}
1013 g_PlayerModel_LoadFake('doomer', 'doomer.wad');
1015 g_PlayerModel_LoadAll;
1019 {$IFDEF ENABLE_MENU}
1023 g_Game_Process_Params;
1024 // TODO reload GAME textures
1025 g_Console_Init; // welcome message
1026 {$IFDEF ENABLE_MENU}
1027 if (not gGameOn) and gAskLanguage then
1030 Time_Old := GetTickCount64();
1031 while not ProcessMessage() do begin end;
1032 g_Console_WriteGameConfig;
1033 {$IFDEF ENABLE_MENU}
1040 {$IFDEF ENABLE_HOLMES}
1043 g_Net_Slist_ShutdownAll;
1044 g_Net_DeinitLowLevel;
1045 (* g_Touch_Finalize; *)
1051 e_ReleaseSoundSystem;
1053 e_WriteLog('Shutdown with no errors.', TMsgType.Notify)
1056 procedure InitCVars;
1058 {$IFDEF USE_SDLMIXER}
1059 conRegVar('sdl_native_music', @UseNativeMusic, 'use native midi music output when possible', 'use native midi');
1061 UseNativeMusic := true; (* OSX have a good midi support, so why not? *)
1063 UseNativeMusic := false;
1068 procedure EntryPoint;
1070 SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]); //k8: fuck off, that's why
1075 conbufDumpToStdOut := true;
1082 except on e: Exception do
1083 e_WriteStackTrace(e.message)
1085 e_WriteStackTrace('FATAL ERROR')
1091 function SDL_main (argc: CInt; argv: PPChar): CInt; cdecl;
1094 System.argc := argc;
1095 System.argv := argv;
1101 function JNI_OnLoad (vm: PJavaVM; reserved: pointer): JInt; cdecl;
1103 result:= JNI_VERSION_1_6;
1106 procedure JNI_OnUnload(vm: PJavaVM; reserved: pointer); cdecl;
1110 // DONT REMOVE JNI FUNCTIONS. SPECIAL HANDLING BY FPC.
1111 exports SDL_main name 'SDL_main';
1112 exports JNI_OnLoad name 'JNI_OnLoad';
1113 exports JNI_OnUnload name 'JNI_Unload';