X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_main.pas;h=57fe927873118c68a20e3d96c9f19ded132465d1;hb=541bba4ec498539ae13827e2c821b1eb8bca7db8;hp=def9f2914d20b342539c8021c605dc93e39c353f;hpb=9b4492224e2e59560931496e925333bdbe6f2b0e;p=d2df-sdl.git diff --git a/src/game/g_main.pas b/src/game/g_main.pas index def9f29..57fe927 100644 --- a/src/game/g_main.pas +++ b/src/game/g_main.pas @@ -44,13 +44,15 @@ var CacheDirs: SSArray; ConfigDirs: SSArray; ScreenshotDirs: SSArray; + StatsDirs: SSArray; MapDownloadDirs: SSArray; WadDownloadDirs: SSArray; + GameWADName: string = 'GAME'; + implementation uses -{$INCLUDE ../nogl/noGLuses.inc} {$IFDEF ENABLE_HOLMES} g_holmes, sdlcarcass, fui_ctls, fui_wadread, fui_style, fui_gfx_gl, {$ENDIF} @@ -64,11 +66,11 @@ uses SDL2, {$ENDIF} wadreader, e_log, g_window, - e_graphics, e_input, g_game, g_console, g_gui, + r_graphics, e_input, g_game, g_console, g_gui, e_sound, g_options, g_sound, g_player, g_basic, g_weapons, SysUtils, g_triggers, MAPDEF, g_map, e_res, g_menu, g_language, g_net, g_touch, g_system, g_res_downloader, - conbuf, envvars, + conbuf, envvars, r_game, xparser; @@ -76,6 +78,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 +350,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 +369,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 +386,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 +408,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 +428,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 +442,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; @@ -435,6 +452,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); @@ -453,37 +471,32 @@ 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; @@ -492,11 +505,8 @@ 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(gScreenWidth, gScreenHeight, gBPP, gFullScreen) = False then + if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = False then raise Exception.Create('Failed to set videomode on startup.'); e_WriteLog(gLanguage, TMsgType.Notify); @@ -572,8 +582,11 @@ begin end; procedure Init(); -var - NoSound: Boolean; + {$IFDEF USE_SDLMIXER} + var timiditycfg: AnsiString; + var oldcwd, newcwd: RawByteString; + {$ENDIF} + var NoSound: Boolean; begin Randomize; @@ -596,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); @@ -627,13 +673,22 @@ 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; procedure Draw (); begin - g_Game_Draw(); + r_Game_Draw(); end; @@ -979,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.