Options Logic Cleanup (#71)

* Output/Logging Overhaul
* Added StandardOut class
* Renamed LOGX macros to LOG_X
* Removed LogMsg macros in favor of LOG_X
* Added console window for debug Windows builds

* Options Refactor
* Moved options loading code from AppPlatform classes to Options class
* Added AppPlatform::singleton()
* Minecraft::m_options is now only accessible via Minecraft::getOptions() (as it should be)
* Making this work with SDL2 next

* Options Cleanup for SDL2

* Added AppPlatform::hasFileSystemAccess()
* Options won't try to load if hasFileSystemAccess returns false. Emscripten build will be happy.

---------

Co-authored-by: Brent Da Mage <BrentDaMage@users.noreply.github.com>
This commit is contained in:
Brent
2023-09-04 04:11:36 -05:00
committed by GitHub
parent cd4c469571
commit 2e55f99a54
25 changed files with 355 additions and 275 deletions

View File

@@ -382,12 +382,12 @@ void Gui::handleClick(int clickID, int mouseX, int mouseY)
void Gui::handleKeyPressed(int keyCode)
{
if (m_pMinecraft->m_options.isKey(KM_INVENTORY, keyCode))
if (m_pMinecraft->getOptions()->isKey(KM_INVENTORY, keyCode))
{
m_pMinecraft->setScreen(new IngameBlockSelectionScreen);
return;
}
if (m_pMinecraft->m_options.isKey(KM_SLOT_R, keyCode))
if (m_pMinecraft->getOptions()->isKey(KM_SLOT_R, keyCode))
{
int* slot = &m_pMinecraft->m_pLocalPlayer->m_pInventory->m_SelectedHotbarSlot;
@@ -402,7 +402,7 @@ void Gui::handleKeyPressed(int keyCode)
return;
}
if (m_pMinecraft->m_options.isKey(KM_SLOT_L, keyCode))
if (m_pMinecraft->getOptions()->isKey(KM_SLOT_L, keyCode))
{
int* slot = &m_pMinecraft->m_pLocalPlayer->m_pInventory->m_SelectedHotbarSlot;
@@ -412,12 +412,12 @@ void Gui::handleKeyPressed(int keyCode)
return;
}
if (m_pMinecraft->m_options.isKey(KM_CHAT_CMD, keyCode) || m_pMinecraft->m_options.isKey(KM_CHAT, keyCode))
if (m_pMinecraft->getOptions()->isKey(KM_CHAT_CMD, keyCode) || m_pMinecraft->getOptions()->isKey(KM_CHAT, keyCode))
{
if (m_pMinecraft->m_pScreen)
return;
m_pMinecraft->setScreen(new ChatScreen(m_pMinecraft->m_options.isKey(KM_CHAT_CMD, keyCode)));
m_pMinecraft->setScreen(new ChatScreen(m_pMinecraft->getOptions()->isKey(KM_CHAT_CMD, keyCode)));
return;
}
}

View File

@@ -70,7 +70,7 @@ bool Screen::isInGameScreen()
void Screen::keyPressed(int key)
{
if (m_pMinecraft->m_options.isKey(KM_MENU_CANCEL, key))
if (m_pMinecraft->getOptions()->isKey(KM_MENU_CANCEL, key))
{
m_pMinecraft->setScreen(nullptr);
}
@@ -78,19 +78,19 @@ void Screen::keyPressed(int key)
if (m_buttonTabList.size())
{
#ifndef ENH_HIGHLIGHT_BY_HOVER
if (m_pMinecraft->m_options.isKey(MENU_NEXT, key))
if (m_pMinecraft->getOptions()->isKey(MENU_NEXT, key))
{
m_tabButtonIndex++;
if (m_tabButtonIndex == int(m_buttonTabList.size()))
m_tabButtonIndex = 0;
}
if (m_pMinecraft->m_options.isKey(MENU_PREVIOUS, key))
if (m_pMinecraft->getOptions()->isKey(MENU_PREVIOUS, key))
{
m_tabButtonIndex--;
if (m_tabButtonIndex == -1)
m_tabButtonIndex = int(m_buttonTabList.size() - 1);
}
if (m_pMinecraft->m_options.isKey(MENU_OK, key))
if (m_pMinecraft->getOptions()->isKey(MENU_OK, key))
{
if (m_buttonTabList[m_tabButtonIndex]->m_bEnabled)
{

View File

@@ -60,7 +60,7 @@ void ChatScreen::render(int mouseX, int mouseY, float f)
void ChatScreen::keyPressed(int keyCode)
{
if (m_pMinecraft->m_options.isKey(KM_MENU_OK, keyCode))
if (m_pMinecraft->getOptions()->isKey(KM_MENU_OK, keyCode))
sendMessageAndExit();
Screen::keyPressed(keyCode);

View File

@@ -65,7 +65,7 @@ static std::string ViewDistanceStr(int dist)
void OptionsScreen::UpdateTexts()
{
Options& o = m_pMinecraft->m_options;
Options& o = *(m_pMinecraft->getOptions());
m_AOButton.m_text = "Smooth lighting: " + BoolOptionStr(o.m_bAmbientOcclusion);
m_invertYButton.m_text = "Invert Y-axis: " + BoolOptionStr(o.m_bInvertMouse);
@@ -159,16 +159,13 @@ void OptionsScreen::render(int a, int b, float c)
void OptionsScreen::removed()
{
#ifdef ORIGINAL_CODE // Reloading options will reload the options.txt we introduced. Don't do this
m_pMinecraft->reloadOptions();
#endif
}
#ifndef ORIGINAL_CODE
void OptionsScreen::buttonClicked(Button* pButton)
{
Options& o = m_pMinecraft->m_options;
Options& o = *(m_pMinecraft->getOptions());
bool* pOption = nullptr;
switch (pButton->m_buttonId)

View File

@@ -59,7 +59,7 @@ bool SelectWorldScreen::isInGameScreen()
void SelectWorldScreen::keyPressed(int code)
{
#ifndef ORIGINAL_CODE
if (m_pMinecraft->m_options.getKey(KM_MENU_OK) == code)
if (m_pMinecraft->getOptions()->getKey(KM_MENU_OK) == code)
m_pWorldSelectionList->selectItem(m_pWorldSelectionList->getItemAtPosition(m_width / 2, m_height / 2), false);
m_btnUnknown.field_36 = true;
@@ -67,10 +67,10 @@ void SelectWorldScreen::keyPressed(int code)
if (m_btnUnknown.field_36)
{
if (m_pMinecraft->m_options.getKey(KM_LEFT) == code)
if (m_pMinecraft->getOptions()->getKey(KM_LEFT) == code)
m_pWorldSelectionList->stepLeft();
if (m_pMinecraft->m_options.getKey(KM_RIGHT) == code)
if (m_pMinecraft->getOptions()->getKey(KM_RIGHT) == code)
m_pWorldSelectionList->stepRight();
}

View File

@@ -84,12 +84,12 @@ void GameRenderer::unZoomRegion()
void GameRenderer::setupCamera(float f, int i)
{
field_8 = float(256 >> m_pMinecraft->m_options.m_iViewDistance);
field_8 = float(256 >> m_pMinecraft->getOptions()->m_iViewDistance);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (m_pMinecraft->m_options.m_bAnaglyphs)
if (m_pMinecraft->getOptions()->m_bAnaglyphs)
{
glTranslatef(float(1 - 2 * i) * 0.07f, 0.0f, 0.0f);
}
@@ -106,13 +106,13 @@ void GameRenderer::setupCamera(float f, int i)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if (m_pMinecraft->m_options.m_bAnaglyphs)
if (m_pMinecraft->getOptions()->m_bAnaglyphs)
{
glTranslatef(float(2 * i - 1) * 0.1f, 0.0f, 0.0f);
}
bobHurt(f);
if (m_pMinecraft->m_options.m_bViewBobbing)
if (m_pMinecraft->getOptions()->m_bViewBobbing)
bobView(f);
moveCameraToPlayer(f);
@@ -130,10 +130,10 @@ void GameRenderer::moveCameraToPlayer(float f)
glRotatef(field_5C + f * (field_58 - field_5C), 0.0f, 0.0f, 1.0f);
if (m_pMinecraft->m_options.m_bThirdPerson)
if (m_pMinecraft->getOptions()->m_bThirdPerson)
{
float v11 = field_30 + (field_2C - field_30) * f;
if (m_pMinecraft->m_options.field_241)
if (m_pMinecraft->getOptions()->field_241)
{
glTranslatef(0.0f, 0.0f, -v11);
glRotatef(field_38 + (field_34 - field_38) * f, 1.0f, 0.0f, 0.0f);
@@ -185,7 +185,7 @@ void GameRenderer::moveCameraToPlayer(float f)
glTranslatef(0.0f, 0.0f, -0.1f);
}
if (!m_pMinecraft->m_options.field_241)
if (!m_pMinecraft->getOptions()->field_241)
{
glRotatef(pMob->field_60 + f * (pMob->m_pitch - pMob->field_60), 1.0f, 0.0f, 0.0f);
glRotatef(pMob->field_5C + f * (pMob->m_yaw - pMob->field_5C) + 180.0f, 0.0f, 1.0f, 0.0f);
@@ -256,7 +256,7 @@ void GameRenderer::setupClearColor(float f)
Level* pLevel = pMC->m_pLevel;
Mob* pMob = pMC->m_pMobPersp;
float x1 = 1.0f - powf(1.0f / float(4 - pMC->m_options.m_iViewDistance), 0.25f);
float x1 = 1.0f - powf(1.0f / float(4 - pMC->getOptions()->m_iViewDistance), 0.25f);
Vec3 skyColor = pLevel->getSkyColor(pMob, f), fogColor = pLevel->getFogColor(f);
@@ -287,7 +287,7 @@ void GameRenderer::setupClearColor(float f)
field_64 *= x2;
field_68 *= x2;
if (pMC->m_options.m_bAnaglyphs)
if (pMC->getOptions()->m_bAnaglyphs)
{
float r = (field_60 * 30.0f + field_64 * 59.0f + field_68 * 11.0f) / 100.0f;
float g = (field_60 * 30.0f + field_64 * 70.0f) / 100.0f;
@@ -407,7 +407,7 @@ void GameRenderer::renderLevel(float f)
fCamPos.y = pMob->field_98.y + (pMob->m_pos.y - pMob->field_98.y) * f;
fCamPos.z = pMob->field_98.z + (pMob->m_pos.z - pMob->field_98.z) * f;
bool bAnaglyph = m_pMinecraft->m_options.m_bAnaglyphs;
bool bAnaglyph = m_pMinecraft->getOptions()->m_bAnaglyphs;
LevelRenderer* pLR = m_pMinecraft->m_pLevelRenderer;
ParticleEngine* pPE = m_pMinecraft->m_pParticleEngine;
@@ -431,7 +431,7 @@ void GameRenderer::renderLevel(float f)
saveMatrices();
/*
if (m_pMinecraft->m_options.m_iViewDistance <= 1)
if (m_pMinecraft->getOptions()->m_iViewDistance <= 1)
{
#ifndef ORIGINAL_CODE
// @NOTE: For whatever reason, Minecraft doesn't enable GL_FOG right away.
@@ -446,7 +446,7 @@ void GameRenderer::renderLevel(float f)
glEnable(GL_FOG);
setupFog(1);
if (m_pMinecraft->m_options.m_bAmbientOcclusion)
if (m_pMinecraft->getOptions()->m_bAmbientOcclusion)
glShadeModel(GL_SMOOTH);
Frustum& frust = Frustum::frustum;
@@ -537,7 +537,7 @@ void GameRenderer::render(float f)
#ifndef ENH_DISABLE_TURN_ACCEL
float multPitch = -1.0f;
float mult1 = 2.0f * (0.2f + pMC->m_options.field_8 * 0.6f);
float mult1 = 2.0f * (0.2f + pMC->getOptions()->field_8 * 0.6f);
mult1 = mult1 * mult1 * mult1;
float xd = 4.0f * mult1 * pMC->field_D20;
@@ -552,10 +552,10 @@ void GameRenderer::render(float f)
if (diff_field_84 > 3.0f)
diff_field_84 = 3.0f;
if (pMC->m_options.m_bInvertMouse)
if (pMC->getOptions()->m_bInvertMouse)
multPitch = 1.0f;
if (!pMC->m_options.field_240)
if (!pMC->getOptions()->field_240)
{
// @TODO: untangle this code
float v17 = xd + m_rotZ;
@@ -580,7 +580,7 @@ void GameRenderer::render(float f)
}
#else
float multPitch = -1.0f;
if (pMC->m_options.m_bInvertMouse)
if (pMC->getOptions()->m_bInvertMouse)
multPitch = 1.0f;
float diff_field_84 = 1.0f;
@@ -601,7 +601,7 @@ void GameRenderer::render(float f)
if (t_keepPic < 0)
{
renderLevel(f);
if (m_pMinecraft->m_options.m_bDontRenderGui)
if (m_pMinecraft->getOptions()->m_bDontRenderGui)
{
if (!m_pMinecraft->m_pScreen)
return;
@@ -638,7 +638,7 @@ void GameRenderer::render(float f)
debugText << "ReMinecraftPE " << m_pMinecraft->getVersionString();
debugText << "\n" << m_shownFPS << " fps, " << m_shownChunkUpdates << " chunk updates";
if (m_pMinecraft->m_options.m_bDebugText)
if (m_pMinecraft->getOptions()->m_bDebugText)
{
if (m_pMinecraft->m_pLocalPlayer)
{
@@ -701,7 +701,7 @@ void GameRenderer::tick()
}
float bright = m_pMinecraft->m_pLevel->getBrightness(Mth::floor(pMob->m_pos.x), Mth::floor(pMob->m_pos.y), Mth::floor(pMob->m_pos.z));
float x3 = float(3 - m_pMinecraft->m_options.m_iViewDistance);
float x3 = float(3 - m_pMinecraft->getOptions()->m_iViewDistance);
field_C++;
@@ -718,27 +718,27 @@ void GameRenderer::renderItemInHand(float f, int i)
{
glLoadIdentity();
if (m_pMinecraft->m_options.m_bAnaglyphs)
if (m_pMinecraft->getOptions()->m_bAnaglyphs)
glTranslatef(float(2 * i - 1) * 0.1f, 0.0f, 0.0f);
glPushMatrix();
bobHurt(f);
if (m_pMinecraft->m_options.m_bViewBobbing)
if (m_pMinecraft->getOptions()->m_bViewBobbing)
bobView(f);
if (!m_pMinecraft->m_options.m_bThirdPerson && !m_pMinecraft->m_options.m_bDontRenderGui)
if (!m_pMinecraft->getOptions()->m_bThirdPerson && !m_pMinecraft->getOptions()->m_bDontRenderGui)
m_pItemInHandRenderer->render(f);
glPopMatrix();
if (!m_pMinecraft->m_options.m_bThirdPerson)
if (!m_pMinecraft->getOptions()->m_bThirdPerson)
{
m_pItemInHandRenderer->renderScreenEffect(f);
bobHurt(f);
}
if (m_pMinecraft->m_options.m_bViewBobbing)
if (m_pMinecraft->getOptions()->m_bViewBobbing)
bobView(f);
}

View File

@@ -327,7 +327,7 @@ void ItemInHandRenderer::renderScreenEffect(float f)
renderFire(f);
}
if (m_pMinecraft->m_pLocalPlayer->isInWall() && !m_pMinecraft->m_options.m_bFlyCheat)
if (m_pMinecraft->m_pLocalPlayer->isInWall() && !m_pMinecraft->getOptions()->m_bFlyCheat)
{
int fx = Mth::floor(m_pMinecraft->m_pLocalPlayer->m_pos.x);
int fy = Mth::floor(m_pMinecraft->m_pLocalPlayer->m_pos.y);

View File

@@ -132,10 +132,10 @@ void LevelRenderer::allChanged()
LeafTile* pLeaves = (LeafTile*)Tile::leaves;
pLeaves->m_bTransparent = m_pMinecraft->m_options.m_bFancyGraphics;
pLeaves->m_bTransparent = m_pMinecraft->getOptions()->m_bFancyGraphics;
pLeaves->m_TextureFrame = !pLeaves->m_bTransparent + pLeaves->field_74;
field_BC = m_pMinecraft->m_options.m_iViewDistance;
field_BC = m_pMinecraft->getOptions()->m_iViewDistance;
int x1 = 64 << (3 - field_BC);
if (x1 >= 400)
@@ -491,7 +491,7 @@ void LevelRenderer::render(Mob* pMob, int a, float b)
field_88.push_back(pChunk);
}
if (m_pMinecraft->m_options.m_iViewDistance != field_BC)
if (m_pMinecraft->getOptions()->m_iViewDistance != field_BC)
allChanged();
if (!a)
@@ -519,7 +519,7 @@ void LevelRenderer::render(Mob* pMob, int a, float b)
// @TODO: Fix goto hell
// @NOTE: Field_B8 doesn't appear to be used??
if (field_B8 && !a && !m_pMinecraft->m_options.m_bAnaglyphs)
if (field_B8 && !a && !m_pMinecraft->getOptions()->m_bAnaglyphs)
{
checkQueryResults(0, 16);
@@ -1089,7 +1089,7 @@ void LevelRenderer::renderEntities(Vec3 pos, Culler* culler, float f)
Mob* mob = m_pMinecraft->m_pMobPersp;
EntityRenderDispatcher::getInstance()->prepare(m_pLevel, m_pMinecraft->m_pTextures, m_pMinecraft->m_pFont, mob, &m_pMinecraft->m_options, f);
EntityRenderDispatcher::getInstance()->prepare(m_pLevel, m_pMinecraft->m_pTextures, m_pMinecraft->m_pFont, mob, m_pMinecraft->getOptions(), f);
field_18 = 0;
field_1C = 0;
@@ -1111,7 +1111,7 @@ void LevelRenderer::renderEntities(Vec3 pos, Culler* culler, float f)
if (!culler->isVisible(pEnt->m_hitbox))
continue;
if (m_pMinecraft->m_pMobPersp == pEnt && !m_pMinecraft->m_options.m_bThirdPerson)
if (m_pMinecraft->m_pMobPersp == pEnt && !m_pMinecraft->getOptions()->m_bThirdPerson)
continue;
if (m_pLevel->hasChunkAt(Mth::floor(pEnt->m_pos.x), Mth::floor(pEnt->m_pos.y), Mth::floor(pEnt->m_pos.z)))
@@ -1127,8 +1127,8 @@ extern int t_keepPic;
void LevelRenderer::takePicture(TripodCamera* pCamera, Entity* pOwner)
{
Mob* pOldMob = m_pMinecraft->m_pMobPersp;
bool bOldDontRenderGui = m_pMinecraft->m_options.m_bDontRenderGui;
bool bOldThirdPerson = m_pMinecraft->m_options.m_bThirdPerson;
bool bOldDontRenderGui = m_pMinecraft->getOptions()->m_bDontRenderGui;
bool bOldThirdPerson = m_pMinecraft->getOptions()->m_bThirdPerson;
#ifdef ENH_CAMERA_NO_PARTICLES
extern bool g_bDisableParticles;
@@ -1136,12 +1136,12 @@ void LevelRenderer::takePicture(TripodCamera* pCamera, Entity* pOwner)
#endif
m_pMinecraft->m_pMobPersp = pCamera;
m_pMinecraft->m_options.m_bDontRenderGui = true;
m_pMinecraft->m_options.m_bThirdPerson = false; // really from the perspective of the camera
m_pMinecraft->getOptions()->m_bDontRenderGui = true;
m_pMinecraft->getOptions()->m_bThirdPerson = false; // really from the perspective of the camera
m_pMinecraft->m_pGameRenderer->render(0.0f);
m_pMinecraft->m_pMobPersp = pOldMob;
m_pMinecraft->m_options.m_bDontRenderGui = bOldDontRenderGui;
m_pMinecraft->m_options.m_bThirdPerson = bOldThirdPerson;
m_pMinecraft->getOptions()->m_bDontRenderGui = bOldDontRenderGui;
m_pMinecraft->getOptions()->m_bThirdPerson = bOldThirdPerson;
#ifdef ENH_CAMERA_NO_PARTICLES
g_bDisableParticles = false;
@@ -1229,7 +1229,7 @@ void LevelRenderer::renderSky(float f)
glDisable(GL_TEXTURE_2D);
Vec3 skyColor = m_pLevel->getSkyColor(m_pMinecraft->m_pMobPersp, f);
if (m_pMinecraft->m_options.m_bAnaglyphs)
if (m_pMinecraft->getOptions()->m_bAnaglyphs)
{
skyColor.x = (((skyColor.x * 30.0f) + (skyColor.y * 59.0f)) + (skyColor.z * 11.0f)) / 100.0f;
skyColor.y = ((skyColor.x * 30.0f) + (skyColor.y * 70.0f)) / 100.0f;