diff --git a/src/game/Doom2DF.lpr b/src/game/Doom2DF.lpr
index 452b7715fe53bfcbc551b6683674a8326cc74799..33a069dc79288ea61dd312f8b0742dd285afe121 100644 (file)
--- a/src/game/Doom2DF.lpr
+++ b/src/game/Doom2DF.lpr
uses
{$IFDEF ANDROID}
uses
{$IFDEF ANDROID}
- ctypes,
+ ctypes, jni,
{$ENDIF}
{$IFDEF UNIX}
cthreads, BaseUnix,
{$ENDIF}
{$IFDEF UNIX}
cthreads, BaseUnix,
g_res_downloader in 'g_res_downloader.pas',
g_grid in 'g_grid.pas',
g_game in 'g_game.pas',
g_res_downloader in 'g_res_downloader.pas',
g_grid in 'g_grid.pas',
g_game in 'g_game.pas',
- g_gfx in 'g_gfx.pas',
- g_gui in 'g_gui.pas',
+ {$IFDEF ENABLE_GFX}
+ g_gfx in 'g_gfx.pas',
+ {$ENDIF}
+ {$IFDEF ENABLE_GIBS}
+ g_gibs in 'g_gibs.pas',
+ {$ENDIF}
+ {$IFDEF ENABLE_SHELLS}
+ g_shells in 'g_shells.pas',
+ {$ENDIF}
+ {$IFDEF ENABLE_CORPSES}
+ g_corpses in 'g_corpses.pas',
+ {$ENDIF}
g_items in 'g_items.pas',
g_map in 'g_map.pas',
g_items in 'g_items.pas',
g_map in 'g_map.pas',
- g_menu in 'g_menu.pas',
g_monsters in 'g_monsters.pas',
g_options in 'g_options.pas',
g_phys in 'g_phys.pas',
g_monsters in 'g_monsters.pas',
g_options in 'g_options.pas',
g_phys in 'g_phys.pas',
g_playermodel in 'g_playermodel.pas',
g_saveload in 'g_saveload.pas',
g_sound in 'g_sound.pas',
g_playermodel in 'g_playermodel.pas',
g_saveload in 'g_saveload.pas',
g_sound in 'g_sound.pas',
- g_textures in 'g_textures.pas',
+ g_animations in 'g_animations.pas',
g_triggers in 'g_triggers.pas',
g_weapons in 'g_weapons.pas',
g_window in 'g_window.pas',
g_triggers in 'g_triggers.pas',
g_weapons in 'g_weapons.pas',
g_window in 'g_window.pas',
-{$IFDEF USE_SYSSTUB}
- g_system in 'stub/g_system.pas',
- g_touch in 'stub/g_touch.pas',
-{$ENDIF}
-{$IFDEF USE_SDL}
- g_system in 'sdl/g_system.pas',
- g_touch in 'sdl/g_touch.pas',
-{$ENDIF}
-{$IFDEF USE_SDL2}
- g_system in 'sdl2/g_system.pas',
- g_touch in 'sdl2/g_touch.pas',
-{$ENDIF}
- r_console in 'opengl/r_console.pas',
- r_game in 'opengl/r_game.pas',
- r_gfx in 'opengl/r_gfx.pas',
- r_graphics in 'opengl/r_graphics.pas',
- r_items in 'opengl/r_items.pas',
- r_map in 'opengl/r_map.pas',
- r_monsters in 'opengl/r_monsters.pas',
- r_netmaster in 'opengl/r_netmaster.pas',
- r_panel in 'opengl/r_panel.pas',
- r_player in 'opengl/r_player.pas',
- r_playermodel in 'opengl/r_playermodel.pas',
- r_texture in 'opengl/r_texture.pas',
- r_weapons in 'opengl/r_weapons.pas',
- r_window in 'opengl/r_window.pas',
+ {$IFDEF ENABLE_SYSTEM}
+ {$IFDEF USE_SYSSTUB}
+ g_system in 'stub/g_system.pas',
+ {$ENDIF}
+ {$IFDEF USE_SDL}
+ g_system in 'sdl/g_system.pas',
+ {$ENDIF}
+ {$IFDEF USE_SDL2}
+ g_system in 'sdl2/g_system.pas',
+ {$ENDIF}
+ {$ENDIF}
+
+ {$IFDEF ENABLE_MENU}
+ g_gui in 'g_gui.pas',
+ g_menu in 'g_menu.pas',
+ {$ENDIF}
+
+{$IFDEF ENABLE_RENDER}
+ {$IF DEFINED(USE_STUBRENDER)}
+ r_render in 'renders/stub/r_render.pas',
+ {$ELSEIF DEFINED(USE_OPENGL) OR DEFINED(USE_GLES1) OR DEFINED(USE_GLSTUB) OR DEFINED(USE_NEWGL)}
+ {$I ../shared/vampimg.inc}
+ r_render in 'renders/opengl/r_render.pas',
+ r_atlas in 'renders/opengl/r_atlas.pas',
+ r_textures in 'renders/opengl/r_textures.pas',
+ r_draw in 'renders/opengl/r_draw.pas',
+ r_map in 'renders/opengl/r_map.pas',
+ r_fonts in 'renders/opengl/r_fonts.pas',
+ r_common in 'renders/opengl/r_common.pas',
+ r_console in 'renders/opengl/r_console.pas',
+ {$IFDEF ENABLE_MENU}
+ r_gui in 'renders/opengl/r_gui.pas',
+ {$ENDIF}
+ r_loadscreen in 'renders/opengl/r_loadscreen.pas',
+ {$IFDEF ENABLE_TOUCH}
+ r_touch in 'renders/opengl/r_touch.pas',
+ {$ENDIF}
+ {$IFDEF ENABLE_HOLMES}
+ r_fui_gfx_gl in 'renders/opengl/r_fui_gfx_gl.pas',
+ r_holmes in 'renders/opengl/r_holmes.pas',
+ {$ENDIF}
+ {$ELSE}
+ {$FATAL render driver not selected}
+ {$ENDIF}
+{$ENDIF}
{$IFDEF USE_FMOD}
fmod in '../lib/FMOD/fmod.pas',
{$IFDEF USE_FMOD}
fmod in '../lib/FMOD/fmod.pas',
fui_wadread in '../flexui/fui_wadread.pas',
fui_common in '../flexui/fui_common.pas',
fui_wadread in '../flexui/fui_wadread.pas',
fui_common in '../flexui/fui_common.pas',
- fui_gfx_gl in '../flexui/fui_gfx_gl.pas',
+ fui_gfx in '../flexui/fui_gfx.pas',
fui_events in '../flexui/fui_events.pas',
fui_style in '../flexui/fui_style.pas',
fui_flexlay in '../flexui/fui_flexlay.pas',
fui_ctls in '../flexui/fui_ctls.pas',
{$ENDIF}
fui_events in '../flexui/fui_events.pas',
fui_style in '../flexui/fui_style.pas',
fui_flexlay in '../flexui/fui_flexlay.pas',
fui_ctls in '../flexui/fui_ctls.pas',
{$ENDIF}
- {$I ../shared/vampimg.inc}
- SysUtils;
+
+ SysUtils, Classes;
{$IFDEF WINDOWS}
{$R *.res}
{$ENDIF}
{$IFDEF WINDOWS}
{$R *.res}
{$ENDIF}
+ const
+ autoexecScript = 'autoexec.cfg';
+
var
noct: Boolean = False;
binPath: AnsiString = '';
forceBinDir: Boolean = False;
var
noct: Boolean = False;
binPath: AnsiString = '';
forceBinDir: Boolean = False;
+ {$IFDEF USE_SDLMIXER}
+ UseNativeMusic: Boolean;
+ {$ENDIF}
+
+ Time_Old: Int64;
+ NoSound: Boolean;
+
+procedure Update ();
+begin
+ // remember old mobj positions, prepare for update
+ g_Game_PreUpdate();
+ // server: receive client commands for new frame
+ // client: receive game state changes from server
+ if (NetMode = NET_SERVER) then g_Net_Host_Update()
+ else if (NetMode = NET_CLIENT) then g_Net_Client_Update();
+ // think
+{$IFDEF ENABLE_RENDER}
+ r_Render_Update;
+{$ENDIF}
+ g_Game_Update();
+ // server: send any accumulated outgoing data to clients
+ if NetMode = NET_SERVER then g_Net_Flush();
+end;
+
+function ProcessMessage (): Boolean;
+var
+ i, t: Integer;
+ flag: Boolean;
+ Time, Time_Delta: Int64;
+ Frame: Int64;
+begin
+ {$IFDEF ENABLE_SYSTEM}
+ Result := sys_HandleInput();
+ {$ELSE}
+ Result := False;
+ {$ENDIF}
+
+ Time := GetTickCount64();
+ Time_Delta := Time-Time_Old;
+
+ flag := false;
+
+ if wNeedTimeReset then
+ begin
+ Frame := 0;
+ Time_Delta := 28;
+ wNeedTimeReset := false;
+ end;
+
+ g_Map_ProfilersBegin();
+ g_Mons_ProfilersBegin();
+
+ t := Time_Delta div 28;
+ if (t > 0) then
+ begin
+ flag := true;
+ for i := 1 to t do
+ Update();
+ end;
+
+ g_Map_ProfilersEnd();
+ g_Mons_ProfilersEnd();
+
+ if (gExit = EXIT_QUIT) then
+ begin
+ result := true;
+ exit;
+ end;
+
+ // Время предыдущего обновления
+ if flag then
+ Time_Old := Time - (Time_Delta mod 28);
+
+ // don't wait if VSync is on, GL already probably waits enough
+ if gLerpActors then
+ flag := (Time - Frame >= gFrameTime) or gVSync;
+
+ if flag then
+ begin
+ if gPause or (not gLerpActors) or (gState = STATE_FOLD) then
+ gLerpFactor := 1.0
+ else
+ gLerpFactor := nmin(1.0, (Time - Time_Old) / 28.0);
+ {$IFDEF ENABLE_RENDER}
+ r_Render_Draw;
+ {$ENDIF}
+ Frame := Time
+ end
+ else
+ Sleep(1);
+
+ e_SoundUpdate();
+end;
+
+procedure DebugOptions;
+var
+ idx: Integer;
+ arg: AnsiString;
+ mdfo: TStream;
+ {$IFDEF ENABLE_HOLMES}
+ itmp: Integer;
+ valres: Word;
+ {$ENDIF}
+begin
+ idx := 1;
+ while (idx <= ParamCount) do
+ begin
+ arg := ParamStr(idx);
+ Inc(idx);
+ //if arg = '--twinkletwinkle' then gwin_k8_enable_light_experiments := true;
+ if arg = '--jah' then g_profile_history_size := 100;
+ if arg = '--no-los' then gmon_dbg_los_enabled := false;
+
+ if arg = '--profile-render' then g_profile_frame_draw := true;
+ if arg = '--profile-coldet' then g_profile_collision := true;
+ if arg = '--profile-los' then g_profile_los := true;
+
+ {$IFDEF ENABLE_GFX}
+ if arg = '--no-particles' then gpart_dbg_enabled := false;
+ if arg = '--no-part-phys' then gpart_dbg_phys_enabled := false;
+ if arg = '--no-part-physics' then gpart_dbg_phys_enabled := false;
+ if arg = '--no-particles-phys' then gpart_dbg_phys_enabled := false;
+ if arg = '--no-particles-physics' then gpart_dbg_phys_enabled := false;
+ if arg = '--no-particle-phys' then gpart_dbg_phys_enabled := false;
+ if arg = '--no-particle-physics' then gpart_dbg_phys_enabled := false;
+ {$ENDIF}
+
+ if arg = '--debug-input' then g_dbg_input := True;
+
+ {.$IF DEFINED(D2F_DEBUG)}
+ if arg = '--aimline' then g_dbg_aimline_on := true;
+ {.$ENDIF}
+
+{$IFDEF ENABLE_HOLMES}
+ if arg = '--holmes' then begin g_holmes_enabled := true; g_Game_SetDebugMode(); end;
+
+ if (arg = '--holmes-ui-scale') or (arg = '-holmes-ui-scale') then
+ begin
+ if (idx <= ParamCount) then
+ begin
+ if not conParseFloat(fuiRenderScale, ParamStr(idx)) then fuiRenderScale := 1.0;
+ Inc(idx);
+ end;
+ end;
+
+ if (arg = '--holmes-font') or (arg = '-holmes-font') then
+ begin
+ if (idx <= ParamCount) then
+ begin
+ itmp := 0;
+ val(ParamStr(idx), itmp, valres);
+ if (valres = 0) and (not g_holmes_imfunctional) then
+ begin
+ case itmp of
+ 8: uiContext.font := 'win8';
+ 14: uiContext.font := 'win14';
+ 16: uiContext.font := 'win16';
+ end;
+ end;
+ Inc(idx);
+ end;
+ end;
+{$ENDIF}
+
+ if (arg = '--game-scale') or (arg = '-game-scale') then
+ begin
+ if (idx <= ParamCount) then
+ begin
+ if not conParseFloat(g_dbg_scale, ParamStr(idx)) then g_dbg_scale := 1.0;
+ Inc(idx);
+ end;
+ end;
+
+ if (arg = '--write-mapdef') or (arg = '-write-mapdef') then
+ begin
+ mdfo := createDiskFile('mapdef.txt');
+ mdfo.WriteBuffer(defaultMapDef[1], Length(defaultMapDef));
+ mdfo.Free();
+ Halt(0);
+ end;
+
+ if (arg = '--pixel-scale') or (arg = '-pixel-scale') then
+ begin
+ if (idx <= ParamCount) then
+ begin
+ if not conParseFloat(r_pixel_scale, ParamStr(idx)) then r_pixel_scale := 1.0;
+ Inc(idx);
+ end;
+ end;
+ end;
+end;
function GetBinaryPath (): AnsiString;
{$IFDEF LINUX}
function GetBinaryPath (): AnsiString;
{$IFDEF LINUX}
AddDir(AllMapDirs, MegawadDirs[i]);
OptimizeDirs(AllMapDirs);
AddDir(AllMapDirs, MegawadDirs[i]);
OptimizeDirs(AllMapDirs);
- if LogFileName = '' then
- begin
- rwdir := e_GetWriteableDir(LogDirs, false);
- if rwdir <> '' then
- begin
- {$IFDEF HEADLESS}
- LogFileName := e_CatPath(rwdir, 'Doom2DF_H.log');
- {$ELSE}
- LogFileName := e_CatPath(rwdir, 'Doom2DF.log');
- {$ENDIF}
- end
- end;
-
// HACK: ensure the screenshots folder also has a stats subfolder in it
rwdir := e_GetWriteableDir(ScreenshotDirs, false);
if rwdir <> '' then CreateDir(rwdir + '/stats');
end;
// HACK: ensure the screenshots folder also has a stats subfolder in it
rwdir := e_GetWriteableDir(ScreenshotDirs, false);
if rwdir <> '' then CreateDir(rwdir + '/stats');
end;
-procedure InitPrep;
- var i: Integer;
-begin
- {$IFDEF HEADLESS}
- conbufDumpToStdOut := true;
- {$ENDIF}
- for i := 1 to ParamCount do
+ procedure EntryParams;
+ var i: Integer;
begin
begin
- case ParamStr(i) of
- '--con-stdout': conbufDumpToStdOut := true;
- '--no-fbo': glRenderToFBO := false;
+ i := 1;
+ while i <= ParamCount do
+ begin
+ case ParamStr(i) of
+ '--gdb': noct := true;
+ '--log', '--con-stdout': conbufDumpToStdOut := true;
+ '--safe-log': e_SetSafeSlowLog(true);
+ '--log-file':
+ if i + 1 <= ParamCount then
+ begin
+ Inc(i);
+ LogFileName := ParamStr(i)
+ end;
+ '--no-fbo': glRenderToFBO := false;
+ end;
+ Inc(i)
end
end;
end
end;
- if LogFileName <> '' then
- e_InitLog(LogFileName, TWriteMode.WM_NEWFILE);
- e_InitWritelnDriver();
- e_WriteLog('Doom 2D: Forever version ' + GAME_VERSION + ' proto ' + IntToStr(NET_PROTOCOL_VER), TMsgType.Notify);
- e_WriteLog('Build date: ' + GAME_BUILDDATE + ' ' + GAME_BUILDTIME, TMsgType.Notify);
- e_WriteLog('Build hash: ' + g_GetBuildHash(), TMsgType.Notify);
- e_WriteLog('Build by: ' + g_GetBuilderName(), TMsgType.Notify);
-
- e_LogWritefln('Force bin dir: %s', [forceBinDir], TMsgType.Notify);
- e_LogWritefln('BINARY PATH: [%s]', [binPath], TMsgType.Notify);
-
- PrintDirs('DataDirs', DataDirs);
- PrintDirs('ModelDirs', ModelDirs);
- PrintDirs('MegawadDirs', MegawadDirs);
- PrintDirs('MapDirs', MapDirs);
- PrintDirs('WadDirs', WadDirs);
-
- PrintDirs('LogDirs', LogDirs);
- PrintDirs('SaveDirs', SaveDirs);
- PrintDirs('CacheDirs', CacheDirs);
- PrintDirs('ConfigDirs', ConfigDirs);
- PrintDirs('ScreenshotDirs', ScreenshotDirs);
- PrintDirs('StatsDirs', StatsDirs);
- PrintDirs('MapDownloadDirs', MapDownloadDirs);
- PrintDirs('WadDownloadDirs', WadDownloadDirs);
-
- GameWAD := e_FindWad(DataDirs, GameWADName);
- if GameWad = '' then
+ procedure InitLog;
+ var rwdir: AnsiString;
begin
begin
- e_WriteLog('WAD ' + GameWADName + ' not found in data directories.', TMsgType.Fatal);
- {$IF DEFINED(USE_SDL2) AND NOT DEFINED(HEADLESS)}
- if forceBinDir = false then
- SDL_ShowSimpleMessageBox(
- SDL_MESSAGEBOX_ERROR,
- 'Doom 2D Forever',
- PChar('WAD ' + GameWADName + ' not found in data directories.'),
- nil
- );
- {$ENDIF}
- e_DeinitLog;
- Halt(1);
+ if LogFileName = '' then
+ begin
+ rwdir := e_GetWriteableDir(LogDirs, false);
+ if rwdir <> '' then
+ begin
+ {$IFDEF HEADLESS}
+ LogFileName := e_CatPath(rwdir, 'Doom2DF_H.log');
+ {$ELSE}
+ LogFileName := e_CatPath(rwdir, 'Doom2DF.log');
+ {$ENDIF}
+ end
+ end;
+ if LogFileName <> '' then
+ e_InitLog(LogFileName, TWriteMode.WM_NEWFILE);
+ e_InitWritelnDriver
end;
end;
-end;
-procedure Main;
-{$IFDEF ENABLE_HOLMES}
- var flexloaded: Boolean;
-{$ENDIF}
-begin
- InitPath;
- InitPrep;
- e_InitInput;
- sys_Init;
+ procedure InitPrep;
+ begin
+ e_WriteLog('Doom 2D: Forever version ' + GAME_VERSION + ' proto ' + IntToStr(NET_PROTOCOL_VER), TMsgType.Notify);
+ e_WriteLog('Build arch: ' + g_GetBuildArch(), TMsgType.Notify);
+ e_WriteLog('Build date: ' + GAME_BUILDDATE + ' ' + GAME_BUILDTIME, TMsgType.Notify);
+ e_WriteLog('Build hash: ' + g_GetBuildHash(), TMsgType.Notify);
+ e_WriteLog('Build by: ' + g_GetBuilderName(), TMsgType.Notify);
- sys_CharPress := @CharPress;
+ e_LogWritefln('Force bin dir: %s', [forceBinDir], TMsgType.Notify);
+ e_LogWritefln('BINARY PATH: [%s]', [binPath], TMsgType.Notify);
- g_Options_SetDefault;
- g_Options_SetDefaultVideo;
- g_Console_SysInit;
- if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = False then
- raise Exception.Create('Failed to set videomode on startup.');
+ PrintDirs('DataDirs', DataDirs);
+ PrintDirs('ModelDirs', ModelDirs);
+ PrintDirs('MegawadDirs', MegawadDirs);
+ PrintDirs('MapDirs', MapDirs);
+ PrintDirs('WadDirs', WadDirs);
- e_WriteLog(gLanguage, TMsgType.Notify);
- g_Language_Set(gLanguage);
+ PrintDirs('LogDirs', LogDirs);
+ PrintDirs('SaveDirs', SaveDirs);
+ PrintDirs('CacheDirs', CacheDirs);
+ PrintDirs('ConfigDirs', ConfigDirs);
+ PrintDirs('ScreenshotDirs', ScreenshotDirs);
+ PrintDirs('StatsDirs', StatsDirs);
+ PrintDirs('MapDownloadDirs', MapDownloadDirs);
+ PrintDirs('WadDownloadDirs', WadDownloadDirs);
-{$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
- flexloaded := true;
- if not fuiAddWad('flexui.wad') then
- begin
- if not fuiAddWad('./data/flexui.wad') then fuiAddWad('./flexui.wad');
- end;
- try
- fuiGfxLoadFont('win8', 'flexui/fonts/win8.fuifont');
- fuiGfxLoadFont('win14', 'flexui/fonts/win14.fuifont');
- fuiGfxLoadFont('win16', 'flexui/fonts/win16.fuifont');
- fuiGfxLoadFont('dos8', 'flexui/fonts/dos8.fuifont');
- fuiGfxLoadFont('msx6', 'flexui/fonts/msx6.fuifont');
- except on e: Exception do
- begin
- writeln('ERROR loading FlexUI fonts');
- flexloaded := false;
- //raise;
- end;
- else
+ {$IFDEF HEADLESS}
+ {$IFDEF USE_SDLMIXER}
+ NoSound := False; // hope env has set SDL_AUDIODRIVER to dummy
+ {$ELSE}
+ NoSound := True; // FMOD backend will sort it out
+ {$ENDIF}
+ {$ELSE}
+ NoSound := False;
+ {$ENDIF}
+
+ GameWAD := e_FindWad(DataDirs, GameWADName);
+ if GameWad = '' then
begin
begin
- flexloaded := false;
- //raise;
- end;
+ e_WriteLog('WAD ' + GameWADName + ' not found in data directories.', TMsgType.Fatal);
+ {$IF DEFINED(USE_SDL2) AND NOT DEFINED(HEADLESS)}
+ if forceBinDir = false then
+ SDL_ShowSimpleMessageBox(
+ SDL_MESSAGEBOX_ERROR,
+ 'Doom 2D Forever',
+ PChar('WAD ' + GameWADName + ' not found in data directories.'),
+ nil
+ );
+ {$ENDIF}
+ e_DeinitLog;
+ Halt(1);
+ end
end;
end;
- if (flexloaded) then
+
+{$IFDEF ENABLE_HOLMES}
+ procedure InitHolmes;
+ var flexloaded: Boolean;
begin
begin
+ flexloaded := true;
+ if not fuiAddWad('flexui.wad') then
+ begin
+ if not fuiAddWad('./data/flexui.wad') then fuiAddWad('./flexui.wad');
+ end;
try
try
- e_LogWriteln('FlexUI: loading stylesheet...');
- uiLoadStyles('flexui/widgets.wgs');
- except on e: TParserException do
+ gxGfxLoadFont('win8', 'flexui/fonts/win8.fuifont');
+ gxGfxLoadFont('win14', 'flexui/fonts/win14.fuifont');
+ gxGfxLoadFont('win16', 'flexui/fonts/win16.fuifont');
+ gxGfxLoadFont('dos8', 'flexui/fonts/dos8.fuifont');
+ gxGfxLoadFont('msx6', 'flexui/fonts/msx6.fuifont');
+ except on e: Exception do
begin
begin
- writeln('ERROR at (', e.tokLine, ',', e.tokCol, '): ', e.message);
- //raise;
+ writeln('ERROR loading FlexUI fonts');
flexloaded := false;
flexloaded := false;
+ //raise;
end;
else
begin
end;
else
begin
- //raise;
flexloaded := false;
flexloaded := false;
+ //raise;
end;
end;
end;
end;
+ if flexloaded then
+ begin
+ try
+ e_LogWriteln('FlexUI: loading stylesheet...');
+ uiLoadStyles('flexui/widgets.wgs');
+ except on e: TParserException do
+ begin
+ writeln('ERROR at (', e.tokLine, ',', e.tokCol, '): ', e.message);
+ //raise;
+ flexloaded := false;
+ end;
+ else
+ begin
+ //raise;
+ flexloaded := false;
+ end;
+ end;
+ end;
+ g_holmes_imfunctional := not flexloaded;
+ if not g_holmes_imfunctional then
+ begin
+ uiInitialize();
+ uiContext.font := 'win14';
+ end;
+ if assigned(oglInitCB) then oglInitCB;
end;
end;
- g_holmes_imfunctional := not flexloaded;
- if (not g_holmes_imfunctional) then
+ procedure FreeHolmes;
begin
begin
- uiInitialize();
- uiContext.font := 'win14';
+ if assigned(oglDeinitCB) then
+ oglDeinitCB
end;
end;
-
- if assigned(oglInitCB) then oglInitCB;
{$ENDIF}
{$ENDIF}
- //g_Res_CreateDatabases(true); // it will be done before connecting to the server for the first time
-
- e_WriteLog('Entering SDLMain', TMsgType.Notify);
+ procedure InitSound;
+ {$IFDEF USE_SDLMIXER}
+ var timiditycfg: AnsiString;
+ var oldcwd, newcwd: RawByteString;
+ {$ENDIF}
+ begin
+ if NoSound = false then
+ begin
+ e_WriteLog('Initializing sound system', TMsgType.Notify);
+ {$IFDEF USE_SDLMIXER}
+ newcwd := '';
+ if UseNativeMusic then
+ SetEnvVar('SDL_NATIVE_MUSIC', '1');
+ timiditycfg := GetEnvironmentVariable('TIMIDITY_CFG');
+ if timiditycfg = '' then
+ begin
+ timiditycfg := 'timidity.cfg';
+ if e_FindResource(ConfigDirs, timiditycfg) OR e_FindResource(DataDirs, timiditycfg) then
+ begin
+ timiditycfg := ExpandFileName(timiditycfg);
+ newcwd := ExtractFileDir(timiditycfg);
+ SetEnvVar('TIMIDITY_CFG', timiditycfg);
+ end
+ else
+ timiditycfg := '';
+ end;
+ e_LogWritefln('TIMIDITY_CFG = "%s"', [timiditycfg]);
+ e_LogWritefln('SDL_NATIVE_MUSIC = "%s"', [GetEnvironmentVariable('SDL_NATIVE_MUSIC')]);
+ {$ENDIF}
+ e_InitSoundSystem(NoSound);
+ {$IFDEF USE_SDLMIXER}
+ if e_TimidityDecoder and (newcwd <> '') then
+ begin
+ (* HACK: Set CWD to load GUS patches relatively to cfg file. *)
+ (* CWD not restored after sound init because timidity *)
+ (* store relative pathes internally and load patches *)
+ (* later. I hope game never relies on CWD. *)
+ oldcwd := '';
+ GetDir(0, oldcwd);
+ ChDir(newcwd);
+ e_logwritefln('WARNING: USED TIMIDITY CONFIG HACK, CWD SWITCHED "%s" -> "%s"', [oldcwd, newcwd]);
+ end;
+ {$ENDIF}
+ end;
+ end;
- {$WARNINGS OFF}
- SDLMain();
- {$WARNINGS ON}
+ procedure ScreenResize (w, h: Integer);
+ begin
+ {$IFDEF ENABLE_RENDER}
+ r_Render_Resize(w, h);
+ {$IFDEF ENABLE_HOLMES}
+ fuiScrWdt := w;
+ fuiScrHgt := h;
+ {$ENDIF}
+ {$IFNDEF ANDROID}
+ (* This will fix menu reset on keyboard showing *)
+ {$IFDEF ENABLE_MENU}
+ g_Menu_Reset;
+ {$ENDIF}
+ {$ENDIF}
+ //g_Game_ClearLoading;
+ {$IFDEF ENABLE_HOLMES}
+ if assigned(oglInitCB) then oglInitCB;
+ {$ENDIF}
+ {$ENDIF}
+ end;
- {$IFDEF ENABLE_HOLMES}
- if assigned(oglDeinitCB) then oglDeinitCB;
- {$ENDIF}
+ procedure ProcessLoading;
+ var update: Boolean;
+ begin
+ {$IFDEF ENABLE_SYSTEM}
+ update := sys_HandleInput() = False;
+ {$ELSE}
+ update := True;
+ {$ENDIF}
+ if update then
+ begin
+ e_SoundUpdate;
+ // TODO: At the moment, I left here only host network processing, because the client code must
+ // handle network events on its own. Otherwise separate network cases that use different calls to
+ // enet_host_service() WILL lose their packets (for example, resource downloading). So they have
+ // to handle everything by themselves. But in general, this MUST be removed completely, since
+ // updating the window should never affect the network. Use single enet_host_service(), period.
+ if NetMode = NET_SERVER then g_Net_Host_Update();
+ end
+ end;
- g_Console_WriteGameConfig;
- sys_Final;
-end;
+ procedure Startup;
+ begin
+ Randomize;
+ InitPath;
+ InitLog;
+ InitPrep;
+ e_Input_Initialize;
+ InitSound;
+ {$IFDEF ENABLE_SYSTEM}
+ sys_Init;
+ sys_CharPress := @CharPress; (* install hook *)
+ sys_ScreenResize := @ScreenResize; (* install hook *)
+ {$ENDIF}
+ g_Options_SetDefault;
+ g_Options_SetDefaultVideo;
+ g_Console_Initialize;
+ // TODO move load configs here
+ g_Language_Set(gLanguage);
+ {$IFDEF ENABLE_RENDER}
+ r_Render_Initialize;
+ {$ENDIF}
+ DebugOptions;
+ g_Net_InitLowLevel;
+ // TODO init serverlist
+ {$IFDEF ENABLE_RENDER}
+ r_Render_SetProcessLoadingCallback(@ProcessLoading);
+ {$ENDIF}
+ g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION]), 0, False);
+ g_Game_SetLoadingText('', 0, False);
+ {$IFDEF ENABLE_HOLMES}
+ InitHolmes;
+ {$ENDIF}
+ {$IFDEF ENABLE_RENDER}
+ g_PlayerModel_LoadAll;
+ r_Render_Load;
+ {$ELSE}
+ g_PlayerModel_LoadFake('doomer', 'doomer.wad');
+ {$ENDIF}
+ g_Game_Init;
+ {$IFDEF ENABLE_MENU}
+ g_Menu_Init;
+ {$ENDIF}
+ g_Game_Process_Params;
+ // TODO reload GAME textures
+ g_Console_Init; // welcome message
+ {$IFDEF ENABLE_MENU}
+ if (not gGameOn) and gAskLanguage then
+ g_Menu_AskLanguage;
+ {$ENDIF}
+ Time_Old := GetTickCount64();
+ while not ProcessMessage() do begin end;
+ {$IFDEF ENABLE_RENDER}
+ r_Render_SetProcessLoadingCallback(nil);
+ {$ENDIF}
+ g_Console_WriteGameConfig;
+ {$IFDEF ENABLE_MENU}
+ g_GUI_Destroy;
+ g_Menu_Free;
+ {$ENDIF}
+ {$IFDEF ENABLE_RENDER}
+ r_Render_Free;
+ {$ENDIF}
+ {$IFDEF ENABLE_HOLMES}
+ FreeHolmes;
+ {$ENDIF}
+ g_Net_Slist_ShutdownAll;
+ g_Net_DeinitLowLevel;
+ (* g_Touch_Finalize; *)
+ {$IFDEF ENABLE_RENDER}
+ r_Render_Finalize;
+ {$ENDIF}
+ {$IFDEF ENABLE_SYSTEM}
+ sys_Final;
+ {$ENDIF}
+ g_Console_Finalize;
+ e_ReleaseSoundSystem;
+ e_Input_Finalize;
+ e_WriteLog('Shutdown with no errors.', TMsgType.Notify)
+ end;
+ procedure InitCVars;
+ begin
+ {$IFDEF USE_SDLMIXER}
+ conRegVar('sdl_native_music', @UseNativeMusic, 'use native midi music output when possible', 'use native midi');
+ {$IFDEF DARWIN}
+ UseNativeMusic := true; (* OSX have a good midi support, so why not? *)
+ {$ELSE}
+ UseNativeMusic := false;
+ {$ENDIF}
+ {$ENDIF}
+ end;
-procedure EntryParams;
- var f: Integer;
-begin
- f := 1;
- while f <= ParamCount do
+ procedure EntryPoint;
begin
begin
- case ParamStr(f) of
- '--gdb': noct := true;
- '--log': conbufDumpToStdOut := true;
- '--safe-log': e_SetSafeSlowLog(true);
- '--log-file':
- if f + 1 <= ParamCount then
- begin
- Inc(f);
- LogFileName := ParamStr(f)
- end
+ SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]); //k8: fuck off, that's why
+ InitCVars;
+ EntryParams;
+ e_Log_Initialize;
+ {$IFDEF HEADLESS}
+ conbufDumpToStdOut := true;
+ {$ENDIF}
+ if noct then
+ Startup
+ else
+ try
+ Startup
+ except on e: Exception do
+ e_WriteStackTrace(e.message)
+ else
+ e_WriteStackTrace('FATAL ERROR')
end;
end;
- Inc(f)
- end
-end;
-
-procedure EntryPoint;
-begin
- SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]); //k8: fuck off, that's why
- EntryParams;
- if noct then
- Main
- else
- try
- Main;
- e_WriteLog('Shutdown with no errors.', TMsgType.Notify)
- except on e: Exception do
- e_WriteStackTrace(e.message)
- else
- e_WriteStackTrace('FATAL ERROR')
+ e_Log_Finalize
end;
end;
- e_DeinitLog;
-end;
-
{$IFDEF ANDROID}
function SDL_main (argc: CInt; argv: PPChar): CInt; cdecl;
begin
{$IFDEF ANDROID}
function SDL_main (argc: CInt; argv: PPChar): CInt; cdecl;
begin
result := 0
end;
result := 0
end;
- exports SDL_main;
+ function JNI_OnLoad (vm: PJavaVM; reserved: pointer): JInt; cdecl;
+ begin
+ result:= JNI_VERSION_1_6;
+ end;
+
+ procedure JNI_OnUnload(vm: PJavaVM; reserved: pointer); cdecl;
+ begin
+ end;
+
+ // DONT REMOVE JNI FUNCTIONS. SPECIAL HANDLING BY FPC.
+ exports SDL_main name 'SDL_main';
+ exports JNI_OnLoad name 'JNI_OnLoad';
+ exports JNI_OnUnload name 'JNI_Unload';
{$ELSE}
begin
EntryPoint
{$ELSE}
begin
EntryPoint