Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Minecraft.Client/Common/App_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ enum eGameSetting
// PSVita
eGameSetting_PSVita_NetworkModeAdhoc,

// Add setting data version
eGameSetting_SettingDataVersion,


};

Expand Down
2 changes: 2 additions & 0 deletions Minecraft.Client/Common/App_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ typedef struct
// was 192
//unsigned char ucUnused[192-TUTORIAL_PROFILE_STORAGE_BYTES-sizeof(DWORD)-sizeof(char)-sizeof(char)-sizeof(char)-sizeof(char)-sizeof(LONG)-sizeof(LONG)-sizeof(DWORD)];
// 4J-PB - don't need to define the padded space, the union with ucReservedSpace will make the sizeof GAME_SETTINGS correct

unsigned int uiSettingDataVersion;
};

unsigned char ucReservedSpace[192];
Expand Down
81 changes: 76 additions & 5 deletions Minecraft.Client/Common/Consoles_App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ int CMinecraftApp::s_iHTMLFontSizesA[eHTMLSize_COUNT] =
#endif
};

// jvnpr -- update this anytime settingfixer needs to convert old settings to new settings!
const int currentSettingDataVersion = 2;

CMinecraftApp::CMinecraftApp()
{
Expand Down Expand Up @@ -792,10 +794,23 @@ static void Win64_LoadSettings(GAME_SETTINGS *gs)
if (fread(&temp, sizeof(GAME_SETTINGS), 1, f) == 1)
memcpy(gs, &temp, sizeof(GAME_SETTINGS));
fclose(f);
CMinecraftApp::SetSettingsFileLoaded(true);
}
}
#endif

bool CMinecraftApp::settingFileLoaded = false;

void CMinecraftApp::SetSettingsFileLoaded(bool loaded)
{
settingFileLoaded = loaded;
}

bool CMinecraftApp::GetSettingsFileLoaded()
{
return settingFileLoaded;
}

void CMinecraftApp::InitGameSettings()
{
for(int i=0;i<XUSER_MAX_COUNT;i++)
Expand Down Expand Up @@ -837,7 +852,7 @@ int CMinecraftApp::SetDefaultOptions(C_4JProfile::PROFILESETTINGS *pSettings,con
SetGameSettings(iPad,eGameSetting_SoundFXVolume,DEFAULT_VOLUME_LEVEL);
SetGameSettings(iPad,eGameSetting_RenderDistance,16);
SetGameSettings(iPad,eGameSetting_Gamma,50);
SetGameSettings(iPad,eGameSetting_FOV,0);
SetGameSettings(iPad,eGameSetting_FOV,40); //jvnpr -- 40 here is an FOV of 70 (FOV = eGameSetting_FOV - 30)

// 4J-PB - Don't reset the difficult level if we're in-game
if(Minecraft::GetInstance()->level==nullptr)
Expand Down Expand Up @@ -904,6 +919,8 @@ int CMinecraftApp::SetDefaultOptions(C_4JProfile::PROFILESETTINGS *pSettings,con
app.SetGameHostOption(eGameHostOption_NaturalRegeneration, 1 );
app.SetGameHostOption(eGameHostOption_DoDaylightCycle, 1 );

app.SetGameSettings(iPad, eGameSetting_SettingDataVersion, currentSettingDataVersion);

// 4J-PB - leave these in, or remove from everywhere they are referenced!
// Although probably best to leave in unless we split the profile settings into platform specific classes - having different meaning per platform for the same bitmask could get confusing
//#ifdef __PS3__
Expand Down Expand Up @@ -1362,6 +1379,7 @@ void CMinecraftApp::ApplyGameSettingsChanged(int iPad)

ActionGameSettings(iPad,eGameSetting_PS3_EULA_Read);

ActionGameSettings(iPad,eGameSetting_SettingDataVersion);
}

void CMinecraftApp::ActionGameSettings(int iPad,eGameSetting eVal)
Expand Down Expand Up @@ -1406,9 +1424,8 @@ void CMinecraftApp::ActionGameSettings(int iPad,eGameSetting eVal)
case eGameSetting_FOV:
if(iPad==ProfileManager.GetPrimaryPad())
{
float fovDeg = 70.0f + (float)GameSettingsA[iPad]->ucFov * 40.0f / 100.0f;
pMinecraft->gameRenderer->SetFovVal(fovDeg);
pMinecraft->options->set(Options::Option::FOV, (float)GameSettingsA[iPad]->ucFov / 100.0f);
float v = static_cast<float>(GameSettingsA[iPad]->ucFov);
pMinecraft->options->fov = (v / 40.0f) - 1; // map to range between -1 and 1.
}
break;
case eGameSetting_Difficulty:
Expand Down Expand Up @@ -1596,6 +1613,51 @@ void CMinecraftApp::ActionGameSettings(int iPad,eGameSetting eVal)
case eGameSetting_PSVita_NetworkModeAdhoc:
//nothing to do here
break;
case eGameSetting_SettingDataVersion:
break;
}
}

void CMinecraftApp::SettingFixer() // jvnpr -- used to convert settings data when necessary
{
int iPad = ProfileManager.GetPrimaryPad();

unsigned int version = GameSettingsA[iPad]->uiSettingDataVersion;

if (GetSettingsFileLoaded())
{
if (version != currentSettingDataVersion)
{
DebugPrintf("[SettingFixer]: Fixing Settings!\n");


if (version < 2) { // FOV changes
float newFov = GetGameSettings(iPad,eGameSetting_FOV) * 40.0f / 100.0f; // convert old setting of 0-100 to a new range of 0-40
if (newFov > 20) newFov = 20; // FOV setting of 90 with old system is equivalent to an FOV of 110 (maximum) with new system.
newFov *= 2; // map range of 0-20 to 0-40 so we can convert to a new equivalent FOV
newFov += 40; // offset so that our new FOV is within the range of 40-80. (we store as 0-80 instead of 30-110)

Minecraft* pMinecraft = Minecraft::GetInstance();
pMinecraft->options->fov = (newFov / 40.0f) - 1; // convert 0-80 to range of -1 to 1

SetGameSettings(iPad, eGameSetting_FOV, newFov);
}

GameSettingsA[iPad]->uiSettingDataVersion = currentSettingDataVersion;
GameSettingsA[iPad]->bSettingsChanged = true;
CheckGameSettingsChanged(true, iPad);

DebugPrintf("[SettingFixer]: Settings fixed and saved.\n");

}
else
{
DebugPrintf("[SettingFixer]: Nothing to do.\n");
}
}
else
{
DebugPrintf("[SettingFixer]: No settings file found, nothing to do.\n");
}
}

Expand Down Expand Up @@ -2306,7 +2368,14 @@ void CMinecraftApp::SetGameSettings(int iPad,eGameSetting eVal,unsigned char ucV
GameSettingsA[iPad]->bSettingsChanged=true;
}
break;
case eGameSetting_SettingDataVersion:

if (GameSettingsA[iPad]->uiSettingDataVersion != ucVal)
{
GameSettingsA[iPad]->uiSettingDataVersion = ucVal;
ActionGameSettings(iPad, eVal);
GameSettingsA[iPad]->bSettingsChanged = true;
}
}
}

Expand Down Expand Up @@ -2441,7 +2510,9 @@ unsigned char CMinecraftApp::GetGameSettings(int iPad,eGameSetting eVal)

case eGameSetting_PSVita_NetworkModeAdhoc:
return (GameSettingsA[iPad]->uiBitmaskValues&GAMESETTING_PSVITANETWORKMODEADHOC)>>17;


case eGameSetting_SettingDataVersion:
return GameSettingsA[iPad]->uiSettingDataVersion;
}
return 0;
}
Expand Down
5 changes: 5 additions & 0 deletions Minecraft.Client/Common/Consoles_App.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ class CMinecraftApp
#endif
virtual void SetRichPresenceContext(int iPad, int contextId) = 0;

// jvnpr -- SettingFixer & related checks
void SettingFixer();
static void SetSettingsFileLoaded(bool loaded);
static bool GetSettingsFileLoaded();
static bool settingFileLoaded;

void SetGameSettings(int iPad,eGameSetting eVal,unsigned char ucVal);
unsigned char GetGameSettings(int iPad,eGameSetting eVal);
Expand Down
30 changes: 15 additions & 15 deletions Minecraft.Client/Common/UI/UIScene_DebugOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "..\..\Minecraft.h"
#include "..\..\MinecraftServer.h"
#include "..\..\GameRenderer.h"
#include "..\..\Options.h"
#include "..\..\MultiPlayerLevel.h"
#include "ClientConnection.h"
#include "MultiPlayerLocalPlayer.h"
Expand All @@ -22,15 +23,14 @@ UIScene_DebugOverlay::UIScene_DebugOverlay(int iPad, void *initData, UILayer *pa
initialiseMovie();

const Minecraft *pMinecraft = Minecraft::GetInstance();
WCHAR tempString[256];
const int fovSliderVal = app.GetGameSettings(m_iPad, eGameSetting_FOV);
const int fovDeg = 70 + fovSliderVal * 40 / 100;
swprintf( tempString, 256, L"Set fov (%d)", fovDeg);
m_sliderFov.init(tempString,eControl_FOV,0,100,fovSliderVal);
WCHAR TempString[256];
const int displayFOV = 30 + app.GetGameSettings(m_iPad,eGameSetting_FOV);
swprintf(TempString, 256, L"Set fov (%d)", displayFOV);
m_sliderFov.init(TempString,eControl_FOV,0,80,app.GetGameSettings(m_iPad,eGameSetting_FOV));

const float currentTime = pMinecraft->level->getLevelData()->getGameTime() % 24000;
swprintf( tempString, 256, L"Set time (unsafe) (%d)", static_cast<int>(currentTime));
m_sliderTime.init(tempString,eControl_Time,0,240,currentTime/100);
swprintf(TempString, 256, L"Set time (unsafe) (%d)", static_cast<int>(currentTime));
m_sliderTime.init(TempString,eControl_Time,0,240,currentTime/100);

m_buttonRain.init(L"Toggle Rain",eControl_Rain);
m_buttonThunder.init(L"Toggle Thunder",eControl_Thunder);
Expand Down Expand Up @@ -274,17 +274,17 @@ void UIScene_DebugOverlay::handleSliderMove(F64 sliderId, F64 currentValue)
break;
case eControl_FOV:
{
Minecraft *pMinecraft = Minecraft::GetInstance();
int v = static_cast<int>(currentValue);
if (v < 0) v = 0;
if (v > 100) v = 100;
int fovDeg = 70 + v * 40 / 100;
pMinecraft->gameRenderer->SetFovVal(static_cast<float>(fovDeg));
app.SetGameSettings(m_iPad, eGameSetting_FOV, v);
if (v > 80) v = 80;
int displayFOV = v + 30; // convert 0-80 to 30-110

WCHAR tempString[256];
swprintf( tempString, 256, L"Set fov (%d)", fovDeg);
m_sliderFov.setLabel(tempString);
Minecraft* pMinecraft = Minecraft::GetInstance();
pMinecraft->options->fov = (v / 40.0f) - 1;

WCHAR TempString[256];
swprintf((WCHAR*)TempString, 256, L"FOV: %d", displayFOV);
m_sliderFov.setLabel(TempString);
}
break;
};
Expand Down
65 changes: 24 additions & 41 deletions Minecraft.Client/Common/UI/UIScene_SettingsGraphicsMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,6 @@
#include "..\..\Options.h"
#include "..\..\GameRenderer.h"

namespace
{
constexpr int FOV_MIN = 70;
constexpr int FOV_MAX = 110;
constexpr int FOV_SLIDER_MAX = 100;

int ClampFov(int value)
{
if (value < FOV_MIN) return FOV_MIN;
if (value > FOV_MAX) return FOV_MAX;
return value;
}

[[maybe_unused]]
int FovToSliderValue(float fov)
{
const int clampedFov = ClampFov(static_cast<int>(fov + 0.5f));
return ((clampedFov - FOV_MIN) * FOV_SLIDER_MAX) / (FOV_MAX - FOV_MIN);
}

int sliderValueToFov(int sliderValue)
{
if (sliderValue < 0) sliderValue = 0;
if (sliderValue > FOV_SLIDER_MAX) sliderValue = FOV_SLIDER_MAX;
return FOV_MIN + ((sliderValue * (FOV_MAX - FOV_MIN)) / FOV_SLIDER_MAX);
}
}

int UIScene_SettingsGraphicsMenu::LevelToDistance(int level)
{
static const int table[6] = {2,4,8,16,32,64};
Expand Down Expand Up @@ -72,11 +44,11 @@ UIScene_SettingsGraphicsMenu::UIScene_SettingsGraphicsMenu(int iPad, void *initD
swprintf( TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_GAMMA ),app.GetGameSettings(m_iPad,eGameSetting_Gamma));
m_sliderGamma.init(TempString,eControl_Gamma,0,100,app.GetGameSettings(m_iPad,eGameSetting_Gamma));

const int initialFovSlider = app.GetGameSettings(m_iPad, eGameSetting_FOV);
const int initialFovDeg = sliderValueToFov(initialFovSlider);
swprintf(TempString, 256, L"FOV: %d", initialFovDeg);
m_sliderFOV.init(TempString, eControl_FOV, 0, FOV_SLIDER_MAX, initialFovSlider);
// if FOV = 70, display "Default" instead; otherwise display true value.
if (static_cast<int>(30.0f + app.GetGameSettings(m_iPad, eGameSetting_FOV)) == 70) swprintf((WCHAR*)TempString, 256, L"FOV: Default");
else swprintf((WCHAR*)TempString, 256, L"FOV: %d", static_cast<int>(30.0f + app.GetGameSettings(m_iPad, eGameSetting_FOV)));
m_sliderFOV.init(TempString, eControl_FOV, 0, 80, app.GetGameSettings(m_iPad, eGameSetting_FOV));

swprintf( TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_INTERFACEOPACITY ),app.GetGameSettings(m_iPad,eGameSetting_InterfaceOpacity));
m_sliderInterfaceOpacity.init(TempString,eControl_InterfaceOpacity,0,100,app.GetGameSettings(m_iPad,eGameSetting_InterfaceOpacity));

Expand Down Expand Up @@ -217,14 +189,25 @@ void UIScene_SettingsGraphicsMenu::handleSliderMove(F64 sliderId, F64 currentVal

case eControl_FOV:
{
m_sliderFOV.handleSliderMove(value);
const Minecraft* pMinecraft = Minecraft::GetInstance();
const int fovValue = sliderValueToFov(value);
pMinecraft->gameRenderer->SetFovVal(static_cast<float>(fovValue));
app.SetGameSettings(m_iPad, eGameSetting_FOV, value);
WCHAR tempString[256];
swprintf(tempString, 256, L"FOV: %d", fovValue);
m_sliderFOV.setLabel(tempString);
// jvnpr -- code in Consoles_App.cpp should reflect the same calculations as here so that controller and mouse inputs work the same.
int v = static_cast<int>(currentValue);
m_sliderFOV.handleSliderMove(v);

if (v < 0) v = 0;
if (v > 80) v = 80;
int displayFOV = v + 30;

Minecraft* pMinecraft = Minecraft::GetInstance();
pMinecraft->options->fov = (v / 40.0f) - 1; // use FOV option framework instead of modifying hardcoded gameRenderer value

WCHAR TempString[256];

if (displayFOV == 70) swprintf((WCHAR*)TempString, 256, L"FOV: Default");
else swprintf((WCHAR*)TempString, 256, L"FOV: %d", static_cast<int>(30.0f + app.GetGameSettings(m_iPad, eGameSetting_FOV)));
m_sliderFOV.setLabel(TempString);

app.SetGameSettings(m_iPad, eGameSetting_FOV, v);

}
break;

Expand Down
1 change: 1 addition & 0 deletions Minecraft.Client/Windows64/Windows64_Minecraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,7 @@ static Minecraft* InitialiseMinecraftRuntime()
return nullptr;

app.InitGameSettings();
app.SettingFixer();
app.InitialiseTips();

return pMinecraft;
Expand Down