X-Git-Url: http://deadsoftware.ru/gitweb?p=d2df-sdl.git;a=blobdiff_plain;f=src%2Fgame%2Fg_main.pas;h=5c458d5159025a8f4b376bb425802b8986f1a877;hp=8142dd83c30f7c1fd14b4a28fe650aec0769415a;hb=59b0e5dfe65548c5fa24cc64136417c37b495573;hpb=027ace8eccb0dc4c1d5ff8796b238d5b1fbbcfed diff --git a/src/game/g_main.pas b/src/game/g_main.pas index 8142dd8..5c458d5 100644 --- a/src/game/g_main.pas +++ b/src/game/g_main.pas @@ -44,9 +44,12 @@ var CacheDirs: SSArray; ConfigDirs: SSArray; ScreenshotDirs: SSArray; + StatsDirs: SSArray; MapDownloadDirs: SSArray; WadDownloadDirs: SSArray; + GameWADName: string = 'GAME'; + implementation uses @@ -76,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} @@ -345,6 +351,7 @@ begin AddDir(MapDownloadDirs, e_CatPath(rwdir, 'maps/downloads')); AddDir(WadDownloadDirs, e_CatPath(rwdir, 'wads/downloads')); AddDir(ScreenshotDirs, e_CatPath(rwdir, 'screenshots')); + AddDir(StatsDirs, e_CatPath(rwdir, 'stats')); (* RO *) AddDir(DataDirs, e_CatPath(rwdir, 'data')); AddDir(ModelDirs, e_CatPath(rwdir, 'data/models')); @@ -363,6 +370,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; @@ -370,7 +387,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; @@ -392,6 +409,7 @@ begin AddDef(MapDownloadDirs, rwdirs, 'maps/downloads'); AddDef(WadDownloadDirs, rwdirs, 'wads/downloads'); AddDef(ScreenshotDirs, rwdirs, 'screenshots'); + AddDef(StatsDirs, rwdirs, 'stats'); for i := 0 to High(MapDirs) do AddDir(AllMapDirs, MapDirs[i]); @@ -411,12 +429,13 @@ begin {$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; procedure InitPrep; - {$IF DEFINED(ANDROID) AND DEFINED(USE_SDLMIXER)} - var timiditycfg: AnsiString; - {$ENDIF} var i: Integer; begin {$IFDEF HEADLESS} @@ -424,10 +443,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; @@ -453,57 +471,44 @@ begin PrintDirs('CacheDirs', CacheDirs); PrintDirs('ConfigDirs', ConfigDirs); PrintDirs('ScreenshotDirs', ScreenshotDirs); + PrintDirs('StatsDirs', StatsDirs); 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; e_InitInput; sys_Init; - s := CONFIG_FILENAME; - if e_FindResource(ConfigDirs, s) = true then - begin - g_Options_Read(s) - end - else - begin - g_Options_SetDefault; - g_Options_SetDefaultVideo - end; - if sys_SetDisplayMode(gScreenWidth, gScreenHeight, gBPP, gFullScreen) = False then + 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.'); - g_Console_SysInit; e_WriteLog(gLanguage, TMsgType.Notify); g_Language_Set(gLanguage); @@ -572,12 +577,16 @@ begin if assigned(oglDeinitCB) then oglDeinitCB; {$ENDIF} + g_Console_WriteGameConfig; sys_Final; end; procedure Init(); -var - NoSound: Boolean; + {$IFDEF USE_SDLMIXER} + var timiditycfg: AnsiString; + var oldcwd, newcwd: RawByteString; + {$ENDIF} + var NoSound: Boolean; begin Randomize; @@ -600,10 +609,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); @@ -631,7 +673,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; @@ -983,4 +1034,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.