X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_main.pas;h=ad97a79bb5c9182ebe9132632f113f606acb0cd1;hb=fbbc2cfe8253d61c8a5eb27d352df4103a59b7fb;hp=ab6e1d8498b9de28c655539f2bf4c985c8a1a8c7;hpb=939a343cdc93545211b37de24e9d406bf54dcaf0;p=d2df-sdl.git diff --git a/src/game/g_main.pas b/src/game/g_main.pas index ab6e1d8..ad97a79 100644 --- a/src/game/g_main.pas +++ b/src/game/g_main.pas @@ -79,6 +79,9 @@ var charbuff: packed array [0..15] of AnsiChar; binPath: AnsiString = ''; forceBinDir: Boolean; + {$IFDEF USE_SDLMIXER} + UseNativeMusic: Boolean; + {$ENDIF} function GetBinaryPath (): AnsiString; {$IFDEF LINUX} @@ -372,6 +375,11 @@ begin Inc(i); GameWADName := ParamStr(i); end; + '--config': + begin + Inc(i); + gConfigScript := ParamStr(i); + end; end; Inc(i) end; @@ -428,9 +436,6 @@ begin end; procedure InitPrep; - {$IF DEFINED(ANDROID) AND DEFINED(USE_SDLMIXER)} - var timiditycfg: AnsiString; - {$ENDIF} var i: Integer; begin {$IFDEF HEADLESS} @@ -448,6 +453,7 @@ begin 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 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); @@ -486,23 +492,12 @@ begin e_DeinitLog; Halt(1); end; - - {$IF DEFINED(ANDROID) AND DEFINED(USE_SDLMIXER)} - timiditycfg := 'timidity.cfg'; - if e_FindResource(ConfigDirs, timiditycfg) = true then - begin - timiditycfg := ExpandFileName(timiditycfg); - SetEnvVar('TIMIDITY_CFG', timiditycfg); - e_LogWritefln('Set TIMIDITY_CFG = "%s"', [timiditycfg]); - end; - {$ENDIF} end; procedure Main(); {$IFDEF ENABLE_HOLMES} var flexloaded: Boolean; {$ENDIF} - var s: AnsiString; begin InitPath; InitPrep; @@ -511,9 +506,6 @@ begin g_Options_SetDefault; g_Options_SetDefaultVideo; - s := CONFIG_FILENAME; - if e_FindResource(ConfigDirs, s) = true then - g_Options_Read(s); 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.'); @@ -591,8 +583,11 @@ begin end; procedure Init(); -var - NoSound: Boolean; + {$IFDEF USE_SDLMIXER} + var timiditycfg: AnsiString; + var oldcwd, newcwd: RawByteString; + {$ENDIF} + var NoSound: Boolean; begin Randomize; @@ -615,10 +610,43 @@ begin e_WriteLog('Input: No Joysticks.', TMsgType.Notify); *) - if (not gNoSound) then + if gNoSound = 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; e_WriteLog('Init game', TMsgType.Notify); @@ -646,7 +674,16 @@ end; 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 g_Game_Update(); + // server: send any accumulated outgoing data to clients + if NetMode = NET_SERVER then g_Net_Flush(); end; @@ -998,4 +1035,13 @@ begin end; end; +initialization +{$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.