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_gui in 'g_gui.pas',
128 g_items in 'g_items.pas',
129 g_map in 'g_map.pas',
130 g_menu in 'g_menu.pas',
131 g_monsters in 'g_monsters.pas',
132 g_options in 'g_options.pas',
133 g_phys in 'g_phys.pas',
134 g_player in 'g_player.pas',
135 g_playermodel in 'g_playermodel.pas',
136 g_saveload in 'g_saveload.pas',
137 g_sound in 'g_sound.pas',
138 g_textures in 'g_textures.pas',
139 g_triggers in 'g_triggers.pas',
140 g_weapons in 'g_weapons.pas',
141 g_window in 'g_window.pas',
143 g_system in 'stub/g_system.pas',
144 g_touch in 'stub/g_touch.pas',
147 g_system in 'sdl/g_system.pas',
148 g_touch in 'sdl/g_touch.pas',
151 g_system in 'sdl2/g_system.pas',
152 g_touch in 'sdl2/g_touch.pas',
155 r_console in 'opengl/r_console.pas',
156 r_game in 'opengl/r_game.pas',
157 r_gfx in 'opengl/r_gfx.pas',
158 r_graphics in 'opengl/r_graphics.pas',
159 r_items in 'opengl/r_items.pas',
160 r_map in 'opengl/r_map.pas',
161 r_monsters in 'opengl/r_monsters.pas',
162 r_netmaster in 'opengl/r_netmaster.pas',
163 r_panel in 'opengl/r_panel.pas',
164 r_player in 'opengl/r_player.pas',
165 r_playermodel in 'opengl/r_playermodel.pas',
166 r_texture in 'opengl/r_texture.pas',
167 r_weapons in 'opengl/r_weapons.pas',
168 r_window in 'opengl/r_window.pas',
169 r_render in 'opengl/r_render.pas',
172 fmod in '../lib/FMOD/fmod.pas',
173 fmoderrors in '../lib/FMOD/fmoderrors.pas',
174 fmodpresets in '../lib/FMOD/fmodpresets.pas',
175 fmodtypes in '../lib/FMOD/fmodtypes.pas',
177 xprofiler in '../shared/xprofiler.pas',
178 binheap in '../shared/binheap.pas',
179 hashtable in '../shared/hashtable.pas',
180 fhashdb in '../shared/fhashdb.pas',
181 idpool in '../shared/idpool.pas',
182 xparser in '../shared/xparser.pas',
183 xdynrec in '../shared/xdynrec.pas',
184 exoma in '../shared/exoma.pas',
185 envvars in '../shared/envvars.pas',
186 g_panel in 'g_panel.pas',
187 g_language in 'g_language.pas',
189 {$IFDEF ENABLE_HOLMES}
190 g_holmes in 'g_holmes.pas',
192 sdlcarcass in '../flexui/sdlcarcass.pas',
193 //sdlstandalone in '../flexui/sdlstandalone.pas',
195 fui_wadread in '../flexui/fui_wadread.pas',
196 fui_common in '../flexui/fui_common.pas',
197 fui_gfx_gl in '../flexui/fui_gfx_gl.pas',
198 fui_events in '../flexui/fui_events.pas',
199 fui_style in '../flexui/fui_style.pas',
200 fui_flexlay in '../flexui/fui_flexlay.pas',
201 fui_ctls in '../flexui/fui_ctls.pas',
203 {$I ../shared/vampimg.inc}
212 autoexecScript = 'autoexec.cfg';
215 noct: Boolean = False;
216 binPath: AnsiString = '';
217 forceBinDir: Boolean = False;
218 {$IFDEF USE_SDLMIXER}
219 UseNativeMusic: Boolean;
222 wLoadingQuit: Boolean = false;
223 Time, Time_Delta, Time_Old: Int64;
225 flag: Boolean = false;
231 // remember old mobj positions, prepare for update
233 // server: receive client commands for new frame
234 // client: receive game state changes from server
235 if (NetMode = NET_SERVER) then g_Net_Host_Update()
236 else if (NetMode = NET_CLIENT) then g_Net_Client_Update();
239 // server: send any accumulated outgoing data to clients
240 if NetMode = NET_SERVER then g_Net_Flush();
243 function ProcessMessage (): Boolean;
247 result := sys_HandleInput();
249 Time := sys_GetTicks();
250 Time_Delta := Time-Time_Old;
254 if wNeedTimeReset then
258 wNeedTimeReset := false;
261 g_Map_ProfilersBegin();
262 g_Mons_ProfilersBegin();
264 t := Time_Delta div 28;
272 g_Map_ProfilersEnd();
273 g_Mons_ProfilersEnd();
281 if (gExit = EXIT_QUIT) then
287 // Время предыдущего обновления
289 Time_Old := Time - (Time_Delta mod 28);
291 // don't wait if VSync is on, GL already probably waits enough
293 flag := (Time - Frame >= gFrameTime) or gVSync;
297 if gPause or (not gLerpActors) or (gState = STATE_FOLD) then
300 gLerpFactor := nmin(1.0, (Time - Time_Old) / 28.0);
311 procedure DebugOptions;
316 {$IFDEF ENABLE_HOLMES}
322 while (idx <= ParamCount) do
324 arg := ParamStr(idx);
326 //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
327 if arg = '--jah' then g_profile_history_size := 100;
328 if arg = '--no-particles' then gpart_dbg_enabled := false;
329 if arg = '--no-los' then gmon_dbg_los_enabled := false;
331 if arg = '--profile-render' then g_profile_frame_draw := true;
332 if arg = '--profile-coldet' then g_profile_collision := true;
333 if arg = '--profile-los' then g_profile_los := true;
335 if arg = '--no-part-phys' then gpart_dbg_phys_enabled := false;
336 if arg = '--no-part-physics' then gpart_dbg_phys_enabled := false;
337 if arg = '--no-particles-phys' then gpart_dbg_phys_enabled := false;
338 if arg = '--no-particles-physics' then gpart_dbg_phys_enabled := false;
339 if arg = '--no-particle-phys' then gpart_dbg_phys_enabled := false;
340 if arg = '--no-particle-physics' then gpart_dbg_phys_enabled := false;
342 if arg = '--debug-input' then g_dbg_input := True;
344 {.$IF DEFINED(D2F_DEBUG)}
345 if arg = '--aimline' then g_dbg_aimline_on := true;
348 {$IFDEF ENABLE_HOLMES}
349 if arg = '--holmes' then begin g_holmes_enabled := true; g_Game_SetDebugMode(); end;
351 if (arg = '--holmes-ui-scale') or (arg = '-holmes-ui-scale') then
353 if (idx <= ParamCount) then
355 if not conParseFloat(fuiRenderScale, ParamStr(idx)) then fuiRenderScale := 1.0;
360 if (arg = '--holmes-font') or (arg = '-holmes-font') then
362 if (idx <= ParamCount) then
365 val(ParamStr(idx), itmp, valres);
367 if (valres = 0) and (not g_holmes_imfunctional) then
370 8: uiContext.font := 'win8';
371 14: uiContext.font := 'win14';
372 16: uiContext.font := 'win16';
385 if (arg = '--game-scale') or (arg = '-game-scale') then
387 if (idx <= ParamCount) then
389 if not conParseFloat(g_dbg_scale, ParamStr(idx)) then g_dbg_scale := 1.0;
394 if (arg = '--write-mapdef') or (arg = '-write-mapdef') then
396 mdfo := createDiskFile('mapdef.txt');
397 mdfo.WriteBuffer(defaultMapDef[1], Length(defaultMapDef));
402 if (arg = '--pixel-scale') or (arg = '-pixel-scale') then
404 if (idx <= ParamCount) then
406 if not conParseFloat(r_pixel_scale, ParamStr(idx)) then r_pixel_scale := 1.0;
413 function GetBinaryPath (): AnsiString;
418 result := ExtractFilePath(ParamStr(0));
420 // it may be a symlink; do some guesswork here
421 sl := fpReadLink(ExtractFileName(ParamStr(0)));
422 if (sl = ParamStr(0)) then
424 // use current directory, as we don't have anything better
429 result := fixSlashes(result);
430 if (length(result) > 0) and (result[length(result)] <> '/') then
431 result := result + '/';
434 procedure PrintDirs (msg: AnsiString; dirs: SSArray);
437 e_LogWriteln(msg + ':');
439 e_LogWriteln(' ' + dir);
443 function NSStringToAnsiString (s: NSString): AnsiString;
447 for i := 0 to s.length - 1 do
448 result := result + AnsiChar(s.characterAtIndex(i));
451 function GetBundlePath (): AnsiString;
452 var pathRef: CFURLRef; pathCFStr: CFStringRef; pathStr: ShortString;
454 pathRef := CFBundleCopyBundleURL(CFBundleGetMainBundle());
455 pathCFStr := CFURLCopyFileSystemPath(pathRef, kCFURLPOSIXPathStyle);
456 CFStringGetPascalString(pathCFStr, @pathStr, 255, CFStringGetSystemEncoding());
458 CFRelease(pathCFStr);
464 var i: Integer; rwdir, rodir: AnsiString; rwdirs, rodirs: SSArray;
466 procedure AddDir (var dirs: SSArray; append: AnsiString);
468 SetLength(dirs, Length(dirs) + 1);
469 dirs[High(dirs)] := ExpandFileName(append)
472 function IsSep (ch: Char): Boolean;
475 result := (ch = '/') or (ch = '\');
477 result := (ch = '/');
481 function OptimizePath (dir: AnsiString): AnsiString;
482 var i, len: Integer; s: AnsiString;
484 i := 1; len := Length(dir); s := '';
487 if IsSep(dir[i]) then
489 s := s + DirectorySeparator;
491 while (i <= len) and IsSep(dir[i]) do Inc(i);
492 if (i <= len) and (dir[i] = '.') then
494 if (i = len) or IsSep(dir[i + 1]) then
498 else if (i + 1 <= len) and (dir[i + 1] = '.') then
500 if (i + 1 = len) or IsSep(dir[i + 2]) then
517 procedure OptimizeDirs (var dirs: SSArray);
518 var i, j, k: Integer;
520 for i := 0 to High(dirs) do
521 dirs[i] := OptimizePath(dirs[i]);
529 if dirs[j] = dirs[i] then
531 for k := j + 1 to High(dirs) do
532 dirs[k - 1] := dirs[k];
534 SetLength(dirs, High(dirs))
545 procedure AddDef (var dirs: SSArray; base: SSArray; append: AnsiString);
548 if Length(dirs) = 0 then
550 AddDir(dirs, e_CatPath(s, append));
554 function GetDefaultRODirs (): SSArray;
555 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
556 var home: AnsiString;
559 var appdata: AnsiString;
562 var bundle, s: AnsiString; dirArr: NSArray; i: Integer;
567 bundle := GetBundlePath();
568 if ExtractFileExt(bundle) <> '.app' then
569 AddDir(result, binpath);
571 AddDir(result, binPath);
573 if forceBinDir = false then
576 AddDir(result, SDL_GetBasePath());
577 AddDir(result, SDL_GetPrefPath('', 'doom2df'));
580 appdata := GetEnvironmentVariable('APPDATA') + '\doom2df';
581 if appdata <> '' then
582 AddDir(result, appdata);
584 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
585 AddDir(result, '/usr/share/doom2df');
586 AddDir(result, '/usr/local/share/doom2df');
587 home := GetEnvironmentVariable('HOME');
589 AddDir(result, e_CatPath(home, '.doom2df'));
592 bundle := GetBundlePath();
594 AddDir(result, e_CatPath(bundle, 'Contents/Resources'));
595 dirArr := NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true);
596 for i := 0 to dirArr.count - 1 do
598 s := NSStringToAnsiString(dirArr.objectAtIndex(i));
599 AddDir(result, e_CatPath(s, 'Doom 2D Forever'))
602 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
603 AddDir(result, SDL_AndroidGetInternalStoragePath());
604 if SDL_AndroidGetExternalStorageState() <> 0 then
605 AddDir(result, SDL_AndroidGetExternalStoragePath());
610 function GetDefaultRWDirs (): SSArray;
611 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
612 var home: AnsiString;
615 var appdata: AnsiString;
618 var bundle, s: AnsiString; dirArr: NSArray; i: Integer;
623 bundle := GetBundlePath();
624 if ExtractFileExt(bundle) <> '.app' then
625 AddDir(result, binPath);
627 AddDir(result, binPath);
629 if forceBinDir = false then
632 AddDir(result, SDL_GetPrefPath('', 'doom2df'));
635 appdata := GetEnvironmentVariable('APPDATA') + '\doom2df';
636 if appdata <> '' then
637 AddDir(result, appdata);
639 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
640 home := GetEnvironmentVariable('HOME');
642 AddDir(result, e_CatPath(home, '.doom2df'));
645 dirArr := NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true);
646 for i := 0 to dirArr.count - 1 do
648 s := NSStringToAnsiString(dirArr.objectAtIndex(i));
649 AddDir(result, e_CatPath(s, 'Doom 2D Forever'))
652 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
653 if SDL_AndroidGetExternalStorageState() <> 0 then
654 AddDir(result, SDL_AndroidGetExternalStoragePath());
660 forceBinDir := false;
661 binPath := GetBinaryPath();
664 while i < ParamCount do
667 '--like-windoze': forceBinDir := true;
671 rwdir := ParamStr(i);
673 AddDir(LogDirs, e_CatPath(rwdir, ''));
674 AddDir(SaveDirs, e_CatPath(rwdir, 'data'));
675 AddDir(CacheDirs, e_CatPath(rwdir, 'data/cache'));
676 AddDir(ConfigDirs, e_CatPath(rwdir, ''));
677 AddDir(MapDownloadDirs, e_CatPath(rwdir, 'maps/downloads'));
678 AddDir(WadDownloadDirs, e_CatPath(rwdir, 'wads/downloads'));
679 AddDir(ScreenshotDirs, e_CatPath(rwdir, 'screenshots'));
680 AddDir(StatsDirs, e_CatPath(rwdir, 'stats'));
682 AddDir(DataDirs, e_CatPath(rwdir, 'data'));
683 AddDir(ModelDirs, e_CatPath(rwdir, 'data/models'));
684 AddDir(MegawadDirs, e_CatPath(rwdir, 'maps/megawads'));
685 AddDir(MapDirs, e_CatPath(rwdir, 'maps'));
686 AddDir(WadDirs, e_CatPath(rwdir, 'wads'));
691 rodir := ParamStr(i);
693 AddDir(DataDirs, e_CatPath(rodir, 'data'));
694 AddDir(ModelDirs, e_CatPath(rodir, 'data/models'));
695 AddDir(MegawadDirs, e_CatPath(rodir, 'maps/megawads'));
696 AddDir(MapDirs, e_CatPath(rodir, 'maps'));
697 AddDir(WadDirs, e_CatPath(rodir, 'wads'));
702 GameWADName := ParamStr(i);
707 gConfigScript := ParamStr(i);
713 // prefer bin dir if it writable and contains game.wad
714 if forceBinDir = false then
716 if findDiskWad(binPath + 'data' + '/' + GameWADName) <> '' then
717 if e_CanCreateFilesAt(binPath) then
722 rodirs := GetDefaultRODirs();
723 AddDef(DataDirs, rodirs, 'data');
724 AddDef(ModelDirs, rodirs, 'data/models');
725 AddDef(MegawadDirs, rodirs, 'maps/megawads');
726 AddDef(MapDirs, rodirs, 'maps');
727 AddDef(WadDirs, rodirs, 'wads');
730 rwdirs := GetDefaultRWDirs();
731 AddDef(LogDirs, rwdirs, '');
732 AddDef(SaveDirs, rwdirs, 'data');
733 AddDef(CacheDirs, rwdirs, 'data/cache');
734 AddDef(ConfigDirs, rwdirs, '');
735 AddDef(MapDownloadDirs, rwdirs, 'maps/downloads');
736 AddDef(WadDownloadDirs, rwdirs, 'wads/downloads');
737 AddDef(ScreenshotDirs, rwdirs, 'screenshots');
738 AddDef(StatsDirs, rwdirs, 'stats');
740 for i := 0 to High(MapDirs) do
741 AddDir(AllMapDirs, MapDirs[i]);
742 for i := 0 to High(MegawadDirs) do
743 AddDir(AllMapDirs, MegawadDirs[i]);
744 OptimizeDirs(AllMapDirs);
746 // HACK: ensure the screenshots folder also has a stats subfolder in it
747 rwdir := e_GetWriteableDir(ScreenshotDirs, false);
748 if rwdir <> '' then CreateDir(rwdir + '/stats');
751 procedure EntryParams;
755 while i <= ParamCount do
758 '--gdb': noct := true;
759 '--log', '--con-stdout': conbufDumpToStdOut := true;
760 '--safe-log': e_SetSafeSlowLog(true);
762 if i + 1 <= ParamCount then
765 LogFileName := ParamStr(i)
767 '--no-fbo': glRenderToFBO := false;
774 var rwdir: AnsiString;
776 if LogFileName = '' then
778 rwdir := e_GetWriteableDir(LogDirs, false);
782 LogFileName := e_CatPath(rwdir, 'Doom2DF_H.log');
784 LogFileName := e_CatPath(rwdir, 'Doom2DF.log');
788 if LogFileName <> '' then
789 e_InitLog(LogFileName, TWriteMode.WM_NEWFILE);
795 e_WriteLog('Doom 2D: Forever version ' + GAME_VERSION + ' proto ' + IntToStr(NET_PROTOCOL_VER), TMsgType.Notify);
796 e_WriteLog('Build arch: ' + g_GetBuildArch(), TMsgType.Notify);
797 e_WriteLog('Build date: ' + GAME_BUILDDATE + ' ' + GAME_BUILDTIME, TMsgType.Notify);
798 e_WriteLog('Build hash: ' + g_GetBuildHash(), TMsgType.Notify);
799 e_WriteLog('Build by: ' + g_GetBuilderName(), TMsgType.Notify);
801 e_LogWritefln('Force bin dir: %s', [forceBinDir], TMsgType.Notify);
802 e_LogWritefln('BINARY PATH: [%s]', [binPath], TMsgType.Notify);
804 PrintDirs('DataDirs', DataDirs);
805 PrintDirs('ModelDirs', ModelDirs);
806 PrintDirs('MegawadDirs', MegawadDirs);
807 PrintDirs('MapDirs', MapDirs);
808 PrintDirs('WadDirs', WadDirs);
810 PrintDirs('LogDirs', LogDirs);
811 PrintDirs('SaveDirs', SaveDirs);
812 PrintDirs('CacheDirs', CacheDirs);
813 PrintDirs('ConfigDirs', ConfigDirs);
814 PrintDirs('ScreenshotDirs', ScreenshotDirs);
815 PrintDirs('StatsDirs', StatsDirs);
816 PrintDirs('MapDownloadDirs', MapDownloadDirs);
817 PrintDirs('WadDownloadDirs', WadDownloadDirs);
820 {$IFDEF USE_SDLMIXER}
821 NoSound := False; // hope env has set SDL_AUDIODRIVER to dummy
823 NoSound := True; // FMOD backend will sort it out
829 GameWAD := e_FindWad(DataDirs, GameWADName);
832 e_WriteLog('WAD ' + GameWADName + ' not found in data directories.', TMsgType.Fatal);
833 {$IF DEFINED(USE_SDL2) AND NOT DEFINED(HEADLESS)}
834 if forceBinDir = false then
835 SDL_ShowSimpleMessageBox(
836 SDL_MESSAGEBOX_ERROR,
838 PChar('WAD ' + GameWADName + ' not found in data directories.'),
847 {$IFDEF ENABLE_HOLMES}
848 procedure InitHolmes;
849 var flexloaded: Boolean;
852 if not fuiAddWad('flexui.wad') then
854 if not fuiAddWad('./data/flexui.wad') then fuiAddWad('./flexui.wad');
857 fuiGfxLoadFont('win8', 'flexui/fonts/win8.fuifont');
858 fuiGfxLoadFont('win14', 'flexui/fonts/win14.fuifont');
859 fuiGfxLoadFont('win16', 'flexui/fonts/win16.fuifont');
860 fuiGfxLoadFont('dos8', 'flexui/fonts/dos8.fuifont');
861 fuiGfxLoadFont('msx6', 'flexui/fonts/msx6.fuifont');
862 except on e: Exception do
864 writeln('ERROR loading FlexUI fonts');
877 e_LogWriteln('FlexUI: loading stylesheet...');
878 uiLoadStyles('flexui/widgets.wgs');
879 except on e: TParserException do
881 writeln('ERROR at (', e.tokLine, ',', e.tokCol, '): ', e.message);
892 g_holmes_imfunctional := not flexloaded;
893 if not g_holmes_imfunctional then
896 uiContext.font := 'win14';
898 if assigned(oglInitCB) then oglInitCB;
901 procedure FreeHolmes;
903 if assigned(oglDeinitCB) then
909 {$IFDEF USE_SDLMIXER}
910 var timiditycfg: AnsiString;
911 var oldcwd, newcwd: RawByteString;
914 if NoSound = false then
916 e_WriteLog('Initializing sound system', TMsgType.Notify);
917 {$IFDEF USE_SDLMIXER}
919 if UseNativeMusic then
920 SetEnvVar('SDL_NATIVE_MUSIC', '1');
921 timiditycfg := GetEnvironmentVariable('TIMIDITY_CFG');
922 if timiditycfg = '' then
924 timiditycfg := 'timidity.cfg';
925 if e_FindResource(ConfigDirs, timiditycfg) OR e_FindResource(DataDirs, timiditycfg) then
927 timiditycfg := ExpandFileName(timiditycfg);
928 newcwd := ExtractFileDir(timiditycfg);
929 SetEnvVar('TIMIDITY_CFG', timiditycfg);
934 e_LogWritefln('TIMIDITY_CFG = "%s"', [timiditycfg]);
935 e_LogWritefln('SDL_NATIVE_MUSIC = "%s"', [GetEnvironmentVariable('SDL_NATIVE_MUSIC')]);
937 e_InitSoundSystem(NoSound);
938 {$IFDEF USE_SDLMIXER}
939 if e_TimidityDecoder and (newcwd <> '') then
941 (* HACK: Set CWD to load GUS patches relatively to cfg file. *)
942 (* CWD not restored after sound init because timidity *)
943 (* store relative pathes internally and load patches *)
944 (* later. I hope game never relies on CWD. *)
948 e_logwritefln('WARNING: USED TIMIDITY CONFIG HACK, CWD SWITCHED "%s" -> "%s"', [oldcwd, newcwd]);
954 procedure ScreenResize (w, h: Integer);
956 r_Render_Resize(w, h);
957 {$IFDEF ENABLE_HOLMES}
961 g_Game_SetupScreenSize;
963 (* This will fix menu reset on keyboard showing *)
966 //g_Game_ClearLoading;
967 {$IFDEF ENABLE_HOLMES}
968 if assigned(oglInitCB) then oglInitCB;
981 sys_CharPress := @CharPress; (* install hook *)
982 sys_ScreenResize := @ScreenResize; (* install hook *)
983 g_Options_SetDefault;
984 g_Options_SetDefaultVideo;
985 g_Console_Initialize;
986 // TODO move load configs here
987 g_Language_Set(gLanguage);
992 // TODO init serverlist
993 {$IFDEF ENABLE_HOLMES}
1001 g_Game_Process_Params;
1002 // TODO reload GAME textures
1003 g_Console_Init; // welcome message
1005 if (not gGameOn) and gAskLanguage then
1008 Time_Old := sys_GetTicks();
1009 while not ProcessMessage() do begin end;
1010 g_Console_WriteGameConfig;
1015 {$IFDEF ENABLE_HOLMES}
1018 g_Net_Slist_ShutdownAll;
1019 g_Net_DeinitLowLevel;
1020 (* g_Touch_Finalize; *)
1024 e_ReleaseSoundSystem;
1026 e_WriteLog('Shutdown with no errors.', TMsgType.Notify)
1029 procedure InitCVars;
1031 {$IFDEF USE_SDLMIXER}
1032 conRegVar('sdl_native_music', @UseNativeMusic, 'use native midi music output when possible', 'use native midi');
1034 UseNativeMusic := true; (* OSX have a good midi support, so why not? *)
1036 UseNativeMusic := false;
1041 procedure EntryPoint;
1043 SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]); //k8: fuck off, that's why
1048 conbufDumpToStdOut := true;
1055 except on e: Exception do
1056 e_WriteStackTrace(e.message)
1058 e_WriteStackTrace('FATAL ERROR')
1064 function SDL_main (argc: CInt; argv: PPChar): CInt; cdecl;
1067 System.argc := argc;
1068 System.argv := argv;
1074 function JNI_OnLoad (vm: PJavaVM; reserved: pointer): JInt; cdecl;
1076 result:= JNI_VERSION_1_6;
1079 procedure JNI_OnUnload(vm: PJavaVM; reserved: pointer); cdecl;
1083 // DONT REMOVE JNI FUNCTIONS. SPECIAL HANDLING BY FPC.
1084 exports SDL_main name 'SDL_main';
1085 exports JNI_OnLoad name 'JNI_OnLoad';
1086 exports JNI_OnUnload name 'JNI_Unload';