X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_main.pas;h=80b5e7ae6a4f1a58cfea5eb3af24e37be5c1cffd;hb=HEAD;hp=7a9785b6964cd331222219282a1f9b4310d4605f;hpb=76b68febf6f7d7a3f0a45e47b57606ac8f40a083;p=d2df-sdl.git diff --git a/src/game/g_main.pas b/src/game/g_main.pas index 7a9785b..80b5e7a 100644 --- a/src/game/g_main.pas +++ b/src/game/g_main.pas @@ -48,6 +48,9 @@ var MapDownloadDirs: SSArray; WadDownloadDirs: SSArray; + GameWADName: string = 'GAME'; + date: AnsiString; + implementation uses @@ -77,6 +80,9 @@ var charbuff: packed array [0..15] of AnsiChar; binPath: AnsiString = ''; forceBinDir: Boolean; + {$IFDEF USE_SDLMIXER} + UseNativeMusic: Boolean; + {$ENDIF} function GetBinaryPath (): AnsiString; {$IFDEF LINUX} @@ -339,8 +345,8 @@ begin Inc(i); rwdir := ParamStr(i); (* RW *) - AddDir(LogDirs, e_CatPath(rwdir, '')); - AddDir(SaveDirs, e_CatPath(rwdir, 'data')); + AddDir(LogDirs, e_CatPath(rwdir, 'logs')); + AddDir(SaveDirs, e_CatPath(rwdir, 'data/saves')); AddDir(CacheDirs, e_CatPath(rwdir, 'data/cache')); AddDir(ConfigDirs, e_CatPath(rwdir, '')); AddDir(MapDownloadDirs, e_CatPath(rwdir, 'maps/downloads')); @@ -365,6 +371,16 @@ begin AddDir(MapDirs, e_CatPath(rodir, 'maps')); AddDir(WadDirs, e_CatPath(rodir, 'wads')); end; + '--game-wad': + begin + Inc(i); + GameWADName := ParamStr(i); + end; + '--config': + begin + Inc(i); + gConfigScript := ParamStr(i); + end; end; Inc(i) end; @@ -372,7 +388,7 @@ begin // prefer bin dir if it writable and contains game.wad if forceBinDir = false then begin - if findDiskWad(binPath + 'data' + '/' + 'GAME') <> '' then + if findDiskWad(binPath + 'data' + '/' + GameWADName) <> '' then if e_CanCreateFilesAt(binPath) then forceBinDir := true end; @@ -387,8 +403,8 @@ begin (* RW *) rwdirs := GetDefaultRWDirs(); - AddDef(LogDirs, rwdirs, ''); - AddDef(SaveDirs, rwdirs, 'data'); + AddDef(LogDirs, rwdirs, 'logs'); + AddDef(SaveDirs, rwdirs, 'data/saves'); AddDef(CacheDirs, rwdirs, 'data/cache'); AddDef(ConfigDirs, rwdirs, ''); AddDef(MapDownloadDirs, rwdirs, 'maps/downloads'); @@ -407,10 +423,11 @@ begin rwdir := e_GetWriteableDir(LogDirs, false); if rwdir <> '' then begin + DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', Now()); {$IFDEF HEADLESS} - LogFileName := e_CatPath(rwdir, 'Doom2DF_H.log'); + LogFileName := e_CatPath(rwdir, 'dfserver-' + date + '.log'); {$ELSE} - LogFileName := e_CatPath(rwdir, 'Doom2DF.log'); + LogFileName := e_CatPath(rwdir, 'dfclient-' + date + '.log'); {$ENDIF} end end; @@ -421,9 +438,6 @@ begin end; procedure InitPrep; - {$IF DEFINED(ANDROID) AND DEFINED(USE_SDLMIXER)} - var timiditycfg: AnsiString; - {$ENDIF} var i: Integer; begin {$IFDEF HEADLESS} @@ -431,10 +445,9 @@ begin {$ENDIF} for i := 1 to ParamCount do begin - if (ParamStr(i) = '--con-stdout') then - begin - conbufDumpToStdOut := true; - break + case ParamStr(i) of + '--con-stdout': conbufDumpToStdOut := true; + '--no-fbo': glRenderToFBO := false; end end; @@ -442,6 +455,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); @@ -464,34 +478,28 @@ begin PrintDirs('MapDownloadDirs', MapDownloadDirs); PrintDirs('WadDownloadDirs', WadDownloadDirs); - GameWAD := e_FindWad(DataDirs, 'GAME'); + GameWAD := e_FindWad(DataDirs, GameWADName); if GameWad = '' then begin - e_WriteLog('GAME.WAD not installed?', TMsgType.Fatal); + 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', 'GAME.WAD not installed?', nil); + SDL_ShowSimpleMessageBox( + SDL_MESSAGEBOX_ERROR, + 'Doom 2D Forever', + PChar('WAD ' + GameWADName + ' not found in data directories.'), + nil + ); {$ENDIF} 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; @@ -500,9 +508,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.'); @@ -580,8 +585,11 @@ begin end; procedure Init(); -var - NoSound: Boolean; + {$IFDEF USE_SDLMIXER} + var timiditycfg: AnsiString; + var oldcwd, newcwd: RawByteString; + {$ENDIF} + var NoSound: Boolean; begin Randomize; @@ -604,10 +612,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); @@ -635,7 +676,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; @@ -747,15 +797,15 @@ begin // RAMBO if CheckCheat(I_GAME_CHEAT_WEAPONS) then begin - if gPlayer1 <> nil then gPlayer1.AllRulez(False); - if gPlayer2 <> nil then gPlayer2.AllRulez(False); + if gPlayer1 <> nil then gPlayer1.TankRamboCheats(False); + if gPlayer2 <> nil then gPlayer2.TankRamboCheats(False); goto Cheated; end; // TANK if CheckCheat(I_GAME_CHEAT_HEALTH) then begin - if gPlayer1 <> nil then gPlayer1.AllRulez(True); - if gPlayer2 <> nil then gPlayer2.AllRulez(True); + if gPlayer1 <> nil then gPlayer1.TankRamboCheats(True); + if gPlayer2 <> nil then gPlayer2.TankRamboCheats(True); goto Cheated; end; // IDDQD @@ -987,4 +1037,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.