X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_options.pas;h=41f0e69ffa8633d35f53b3540e61bce94b167838;hb=9b4492224e2e59560931496e925333bdbe6f2b0e;hp=697656bffc0327903c8a970fdf125a55a82bf62c;hpb=24f025e51e5faa8c8f28f6ec6614335a5977303a;p=d2df-sdl.git diff --git a/src/game/g_options.pas b/src/game/g_options.pas index 697656b..41f0e69 100644 --- a/src/game/g_options.pas +++ b/src/game/g_options.pas @@ -18,29 +18,26 @@ unit g_options; interface uses - g_language, g_weapons; + g_language, g_weapons, utils; function GenPlayerName (n: Integer): String; -procedure g_Options_SetDefault(); +procedure g_Options_SetDefault; +procedure g_Options_SetDefaultVideo; procedure g_Options_Read(FileName: String); procedure g_Options_Write(FileName: String); -procedure g_Options_Write_Language(FileName: String); -procedure g_Options_Write_Video(FileName: String); procedure g_Options_Write_Gameplay_Custom(FileName: String); procedure g_Options_Write_Gameplay_Net(FileName: String); procedure g_Options_Write_Net_Server(FileName: String); procedure g_Options_Write_Net_Client(FileName: String); +procedure g_Options_Commands (p: SSArray); const DF_Default_Megawad_Start = 'megawads/DOOM2D.WAD:\MAP01'; var -// gGameControls: TControls; gScreenWidth: Word; gScreenHeight: Word; - gWinRealPosX: Integer; - gWinRealPosY: Integer; - gBPP: Byte; + gBPP: Integer; gFreq: Byte; gFullscreen: Boolean; gWinMaximized: Boolean; @@ -48,9 +45,9 @@ var glLegacyNPOT: Boolean; gTextureFilter: Boolean; gNoSound: Boolean; - gSoundLevel: Byte; - gMusicLevel: Byte; - gMaxSimSounds: Byte; + gSoundLevel: Integer; + gMusicLevel: Integer; + gMaxSimSounds: Integer; gMuteWhenInactive: Boolean; gAdvCorpses: Boolean; gAdvBlood: Boolean; @@ -91,14 +88,18 @@ var gSFSFastMode: Boolean; gDefaultMegawadStart: AnsiString; gBerserkAutoswitch: Boolean; + glNPOTOverride: Boolean = false; implementation uses {$INCLUDE ../nogl/noGLuses.inc} + {$IFDEF USE_SDL2} + SDL2, + {$ENDIF} e_log, e_input, g_console, g_window, g_sound, g_gfx, g_player, Math, g_map, g_net, g_netmaster, SysUtils, CONFIG, g_game, g_main, e_texture, - g_items, wadreader, e_graphics, g_touch, SDL2, envvars; + g_items, wadreader, e_graphics, g_touch, envvars, g_system; var machine: Integer; @@ -115,19 +116,28 @@ uses Result := Copy(Result, 1, 10) + ' ' + IntToStr(n) end; +{$IFDEF USE_SDL2} procedure g_Options_SetDefaultVideo; -var - target, closest, display: TSDL_DisplayMode; - percentage: Integer; + var display: TSDL_DisplayMode; + {$IFNDEF ANDROID} + var target, closest: TSDL_DisplayMode; percentage: Integer; + {$ENDIF} begin (* Display 0 = Primary display *) - SDL_GetDesktopDisplayMode(0, @display); - {$IF DEFINED(ANDROID)} + gScreenWidth := 640; + gScreenHeight := 480; + //gBPP := SDL_BITSPERPIXEL(dispaly.format); + gBPP := 32; + {$IFDEF ANDROID} + gFullScreen := True; (* rotation not allowed? *) + {$ELSE} + gFullScreen := False; + {$ENDIF} + if SDL_GetDesktopDisplayMode(0, @display) = 0 then + begin + {$IFDEF ANDROID} gScreenWidth := display.w; gScreenHeight := display.h; - //gBPP := SDL_BITSPERPIXEL(dispaly.format); - gBPP := 32; - gFullScreen := True; (* rotation not allowed? *) {$ELSE} (* Window must be smaller than display *) closest.w := display.w; @@ -152,12 +162,13 @@ begin gScreenWidth := closest.w; gScreenHeight := closest.h; //gBPP := SDL_BITSPERPIXEL(closest.format); (* Resolution list didn't work for some reason *) - gBPP := 32; - gFullScreen := False; {$ENDIF} + end + else + begin + e_LogWritefln('SDL: Failed to get desktop display mode: %s', [SDL_GetError]) + end; (* Must be positioned on primary display *) - gWinRealPosX := SDL_WINDOWPOS_CENTERED; - gWinRealPosY := SDL_WINDOWPOS_CENTERED; gWinMaximized := False; gVSync := True; gTextureFilter := True; @@ -165,6 +176,21 @@ begin e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight)); g_Console_ResetBinds; end; +{$ELSE} +procedure g_Options_SetDefaultVideo; +begin + gScreenWidth := 640; + gScreenHeight := 480; + gBPP := 32; + gFullScreen := False; + gWinMaximized := False; + gVSync := True; + gTextureFilter := True; + glLegacyNPOT := False; + e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight)); + g_Console_ResetBinds; +end; +{$ENDIF} procedure g_Options_SetDefault(); var @@ -226,7 +252,6 @@ begin gShowMessages := True; gRevertPlayers := False; gChatBubble := 4; - gPlayerIndicator := 1; gSFSDebug := False; gSFSFastMode := False; e_FastScreenshots := True; @@ -266,7 +291,7 @@ begin (* section MasterServer *) NetSlistIP := 'mpms.doom2d.org'; NetSlistPort := 25665; - g_Net_Slist_Set(NetSlistIP, NetSlistPort); + g_Net_Slist_Set(NetSlistIP, NetSlistPort, NetSlistList); (* section Server *) NetServerName := 'Unnamed Server'; @@ -339,31 +364,6 @@ begin config := TConfig.CreateFile(FileName); - section := 'Video'; - ReadInteger(gScreenWidth, 'ScreenWidth', 0); - ReadInteger(gScreenHeight, 'ScreenHeight', 0); - ReadInteger(gWinRealPosX, 'WinPosX', 60); - ReadInteger(gWinRealPosY, 'WinPosY', 60); - ReadBoolean(gFullScreen, 'Fullscreen'); - ReadBoolean(gWinMaximized, 'Maximized'); - ReadInteger(gBPP, 'BPP', 0); - ReadInteger(gFreq, 'Freq', 0); - ReadBoolean(gVSync, 'VSync'); - ReadBoolean(gTextureFilter, 'TextureFilter'); - ReadBoolean(glLegacyNPOT, 'LegacyCompatible'); - - section := 'Sound'; - ReadBoolean(gNoSound, 'NoSound'); - ReadInteger(gSoundLevel, 'SoundLevel', 0, 255); - ReadInteger(gMusicLevel, 'MusicLevel', 0, 255); - ReadInteger(gMaxSimSounds, 'MaxSimSounds', 2, 66); - ReadBoolean(gMuteWhenInactive, 'MuteInactive'); - ReadInteger(gAnnouncer, 'Announcer', ANNOUNCE_NONE, ANNOUNCE_ALL); - ReadBoolean(gSoundEffectsDF, 'SoundEffectsDF'); - ReadBoolean(gUseChatSounds, 'ChatSounds'); - ReadInteger(gsSDLSampleRate, 'SDLSampleRate', 11025, 96000); - ReadInteger(gsSDLBufferSize, 'SDLBufferSize', 64, 16384); - section := 'Player1'; with gPlayer1Settings do begin @@ -390,12 +390,6 @@ begin Team := TEAM_RED; end; - section := 'Joysticks'; - for i := 0 to e_MaxJoys - 1 do - begin - ReadInteger(e_JoystickDeadzones[i], 'Deadzone' + IntToStr(i)) - end; - section := 'Game'; ReadInteger(i, 'MaxParticles', 0, 50000); g_GFX_SetMax(i); ReadInteger(i, 'MaxShells', 0, 600); g_Shells_SetMax(i); @@ -419,18 +413,12 @@ begin ReadBoolean(gShowMessages, 'Messages'); ReadBoolean(gRevertPlayers, 'RevertPlayers'); ReadInteger(gChatBubble, 'ChatBubble', 0, 4); - ReadInteger(gPlayerIndicator, 'PlayerIndicator', 0, 2); ReadBoolean(gSFSDebug, 'SFSDebug'); wadoptDebug := gSFSDebug; ReadBoolean(gSFSFastMode, 'SFSFastMode'); wadoptFast := gSFSFastMode; ReadBoolean(e_FastScreenshots, 'FastScreenshots'); ReadString(gDefaultMegawadStart, 'DefaultMegawadStart'); ReadBoolean(gBerserkAutoswitch, 'BerserkAutoswitching'); i := Trunc(g_dbg_scale * 100); ReadInteger(i, 'Scale', 100); g_dbg_scale := i / 100; - ReadString(gLanguage, 'Language'); - if (gLanguage = LANGUAGE_RUSSIAN) or (gLanguage = LANGUAGE_ENGLISH) then - gAskLanguage := False - else - gLanguage := LANGUAGE_ENGLISH; section := 'GameplayCustom'; ReadString(gcMap, 'Map'); @@ -489,7 +477,8 @@ begin section := 'MasterServer'; ReadString(NetSlistIP, 'IP'); ReadInteger(NetSlistPort, 'Port', 0, 65535); - g_Net_Slist_Set(NetSlistIP, NetSlistPort); + ReadString(NetSlistList, 'List'); + g_Net_Slist_Set(NetSlistIP, NetSlistPort, NetSlistList); section := 'Server'; ReadString(NetServerName, 'Name'); @@ -517,36 +506,12 @@ begin end; procedure g_Options_Write(FileName: String); -var - config: TConfig; - i: Integer; + var config: TConfig; begin e_WriteLog('Writing config', TMsgType.Notify); config := TConfig.CreateFile(FileName); - config.WriteInt('Video', 'ScreenWidth', gScreenWidth); - config.WriteInt('Video', 'ScreenHeight', gScreenHeight); - config.WriteInt('Video', 'WinPosX', gWinRealPosX); - config.WriteInt('Video', 'WinPosY', gWinRealPosY); - config.WriteBool('Video', 'Fullscreen', gFullScreen); - config.WriteBool('Video', 'Maximized', gWinMaximized); - config.WriteInt('Video', 'BPP', gBPP); - config.WriteBool('Video', 'VSync', gVSync); - config.WriteBool('Video', 'TextureFilter', gTextureFilter); - config.WriteBool('Video', 'LegacyCompatible', glLegacyNPOT); - - config.WriteBool('Sound', 'NoSound', gNoSound); - config.WriteInt('Sound', 'SoundLevel', gSoundLevel); - config.WriteInt('Sound', 'MusicLevel', gMusicLevel); - config.WriteInt('Sound', 'MaxSimSounds', gMaxSimSounds); - config.WriteBool('Sound', 'MuteInactive', gMuteWhenInactive); - config.WriteInt('Sound', 'Announcer', gAnnouncer); - config.WriteBool('Sound', 'SoundEffectsDF', gSoundEffectsDF); - config.WriteBool('Sound', 'ChatSounds', gUseChatSounds); - config.WriteInt('Sound', 'SDLSampleRate', gsSDLSampleRate); - config.WriteInt('Sound', 'SDLBufferSize', gsSDLBufferSize); - with config, gPlayer1Settings do begin WriteStr('Player1', 'Name', Name); @@ -567,9 +532,6 @@ begin WriteInt('Player2', 'team', Team); end; - for i := 0 to e_MaxJoys-1 do - config.WriteInt('Joysticks', 'Deadzone' + IntToStr(i), e_JoystickDeadzones[i]); - with config do case gGibsCount of 0: config.WriteInt('Game', 'GibsCount', 0); @@ -593,7 +555,6 @@ begin config.WriteBool('Game', 'Messages', gShowMessages); config.WriteBool('Game', 'RevertPlayers', gRevertPlayers); config.WriteInt('Game', 'ChatBubble', gChatBubble); - config.WriteInt('Game', 'PlayerIndicator', gPlayerIndicator); config.WriteBool('Game', 'SFSDebug', gSFSDebug); config.WriteBool('Game', 'SFSFastMode', gSFSFastMode); config.WriteBool('Game', 'FastScreenshots', e_FastScreenshots); @@ -627,6 +588,7 @@ begin config.WriteStr('MasterServer', 'IP', NetSlistIP); config.WriteInt('MasterServer', 'Port', NetSlistPort); + config.WriteStr('MasterServer', 'List', NetSlistList); config.WriteStr ('Server', 'Name', NetServerName); config.WriteStr ('Server', 'Password', NetPassword); @@ -650,53 +612,6 @@ begin config.Free(); end; -procedure g_Options_Write_Language(FileName: String); -var - config: TConfig; -begin - e_WriteLog('Writing language config', TMsgType.Notify); - - config := TConfig.CreateFile(FileName); - config.WriteStr('Game', 'Language', gLanguage); - config.SaveFile(FileName); - config.Free(); -end; - -procedure g_Options_Write_Video(FileName: String); -var - config: TConfig; - sW, sH: Integer; -begin - e_WriteLog('Writing resolution to config', TMsgType.Notify); - - config := TConfig.CreateFile(FileName); - - if gWinMaximized and (not gFullscreen) then - begin - sW := gWinSizeX; - sH := gWinSizeY; - end - else - begin - sW := gScreenWidth; - sH := gScreenHeight; - end; - e_LogWritefln(' (ws=%dx%d) (ss=%dx%d)', [gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight]); - - config.WriteInt('Video', 'ScreenWidth', sW); - config.WriteInt('Video', 'ScreenHeight', sH); - config.WriteInt('Video', 'WinPosX', gWinRealPosX); - config.WriteInt('Video', 'WinPosY', gWinRealPosY); - config.WriteBool('Video', 'Fullscreen', gFullscreen); - config.WriteBool('Video', 'Maximized', gWinMaximized); - - config.WriteStr('Player1', 'Name', gPlayer1Settings.Name); - config.WriteStr('Player2', 'Name', gPlayer2Settings.Name); - - config.SaveFile(FileName); - config.Free(); -end; - procedure g_Options_Write_Gameplay_Custom(FileName: String); var config: TConfig; @@ -779,7 +694,76 @@ begin config.Free(); end; +procedure g_Options_Commands (p: SSArray); + var cmd: AnsiString; +begin + cmd := LowerCase(p[0]); + case cmd of + 'r_reset': + begin + sys_EnableVSync(gVSync); + gRC_Width := Max(1, gRC_Width); + gRC_Height := Max(1, gRC_Height); + gBPP := Max(1, gBPP); + if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen) = True then + e_LogWriteln('resolution changed') + else + e_LogWriteln('resolution not changed') + end; + 'g_language': + begin + if Length(p) = 2 then + begin + gAskLanguage := true; + gLanguage := LANGUAGE_ENGLISH; + case LowerCase(p[1]) of + 'english': + begin + gAskLanguage := false; + gLanguage := LANGUAGE_ENGLISH; + end; + 'russian': + begin + gAskLanguage := false; + gLanguage := LANGUAGE_RUSSIAN; + end; + 'ask': + begin + gAskLanguage := true; + gLanguage := LANGUAGE_ENGLISH; + end; + end; + g_Language_Set(gLanguage) + end + end + end; +end; + initialization Randomize; - machine := Random(10000) + machine := Random(10000); + + (* Video *) + conRegVar('r_width', @gRC_Width, '', ''); + conRegVar('r_height', @gRC_Height, '', ''); + conRegVar('r_fullscreen', @gRC_FullScreen, '', ''); + conRegVar('r_maximized', @gRC_Maximized, '', ''); + conRegVar('r_bpp', @gBPP, '', ''); + conRegVar('r_vsync', @gVSync, '', ''); + conRegVar('r_texfilter', @gTextureFilter, '', ''); + conRegVar('r_npot', @glNPOTOverride, '', ''); + + (* Sound *) + conRegVar('s_nosound', @gNoSound, '', ''); + conRegVar('s_soundvolume', @gSoundLevel, '', ''); + conRegVar('s_musicvolume', @gMusicLevel, '', ''); + conRegVar('s_maxsim', @gMaxSimSounds, '', ''); // e_sound_fmod/sdl? + conRegVar('s_muteinactive', @gMuteWhenInactive, '', ''); + conRegVar('s_announcer', @gAnnouncer, '', ''); + conRegVar('s_sfx', @gSoundEffectsDF, '', ''); + conRegVar('s_chatsounds', @gUseChatSounds, '', ''); + {$IFDEF USE_SDLMIXER} + conRegVar('sdl_mixer_samplerate', @gsSDLSampleRate, '', ''); + conRegVar('sdl_mixer_buffersize', @gsSDLBufferSize, '', ''); + {$ENDIF} end.