* Add improved saving.

This commit is contained in:
iProgramInCpp
2023-08-02 13:53:35 +03:00
parent 6683422467
commit d363d8d298
6 changed files with 104 additions and 12 deletions

View File

@@ -10,6 +10,7 @@
#include "PauseScreen.hpp"
#include "StartMenuScreen.hpp"
#include "RenameMPLevelScreen.hpp"
#include "SavingWorldScreen.hpp"
#include "ServerSideNetworkHandler.hpp"
#include "ClientSideNetworkHandler.hpp"
@@ -299,7 +300,7 @@ void Minecraft::tickInput()
{
if (!field_D14->field_10)
{
field_DB0 = 1;
field_DB0 = true;
field_D14->updateEvents();
field_DB0 = false;
if (field_DB1)
@@ -839,16 +840,12 @@ void Minecraft::leaveGame(bool bCopyMap)
// @BUG: Deleting ServerSideNetworkHandler too late! This causes
// access to invalid memory in the destructor seeing as we already deleted the level.
delete m_pNetEventCallback;
// @NOTE: Saving only happens once every 50 ticks. Force it to happen when quitting.
if (m_pLevel)
{
m_pLevel->saveAllChunks();
m_pLevel->saveLevelData();
m_pLevel->savePlayerData();
}
#endif
#ifdef ENH_IMPROVED_SAVING
field_288 = true;
setScreen(new SavingWorldScreen(bCopyMap));
#else
if (m_pLevel)
{
LevelStorage* pStorage = m_pLevel->getLevelStorage();
@@ -857,6 +854,7 @@ void Minecraft::leaveGame(bool bCopyMap)
m_pLevel = nullptr;
}
#endif
#ifdef ORIGINAL_CODE
delete m_pNetEventCallback;
@@ -865,10 +863,12 @@ void Minecraft::leaveGame(bool bCopyMap)
m_pNetEventCallback = nullptr;
field_D9C = 0;
#ifndef ENH_IMPROVED_SAVING
if (bCopyMap)
setScreen(new RenameMPLevelScreen("_LastJoinedServer"));
else
setScreen(new StartMenuScreen);
#endif
}
void Minecraft::hostMultiplayer()

View File

@@ -0,0 +1,63 @@
#include "SavingWorldScreen.hpp"
#include "RenameMPLevelScreen.hpp"
#include "StartMenuScreen.hpp"
#ifdef ENH_IMPROVED_SAVING
SavingWorldScreen::SavingWorldScreen(bool bCopyMap)
{
m_bCopyMapAtEnd = bCopyMap;
m_timer = 0;
}
void SavingWorldScreen::render(int mouseX, int mouseY, float f)
{
renderDirtBackground(0);
int x_width = int(Minecraft::width * Gui::InvGuiScale);
int x_height = int(Minecraft::height * Gui::InvGuiScale);
int yPos = x_height / 2;
int width = m_pFont->width("Saving chunks");
m_pFont->drawShadow("Saving chunks", (x_width - width) / 2, yPos + 4, 0xFFFFFF);
}
void SavingWorldScreen::tick()
{
if (m_timer < 0)
return;
m_timer++;
if (m_timer >= 5)
{
m_timer = -1;
Level* pLevel = m_pMinecraft->m_pLevel;
if (pLevel)
{
pLevel->saveAllChunks();
pLevel->saveLevelData();
pLevel->savePlayerData();
LevelStorage* pStorage = pLevel->getLevelStorage();
SAFE_DELETE(pStorage);
SAFE_DELETE(pLevel);
m_pMinecraft->m_pLevel = nullptr;
}
m_pMinecraft->field_DB0 = true;
if (m_bCopyMapAtEnd)
m_pMinecraft->setScreen(new RenameMPLevelScreen("_LastJoinedServer"));
else
m_pMinecraft->setScreen(new StartMenuScreen);
m_pMinecraft->field_DB0 = false;
m_pMinecraft->field_288 = false;
}
}
#endif

View File

@@ -0,0 +1,20 @@
#pragma once
#include "Screen.hpp"
#ifdef ENH_IMPROVED_SAVING
class SavingWorldScreen : public Screen
{
public:
SavingWorldScreen(bool bCopyMap);
void render(int mouseX, int mouseY, float f) override;
void tick() override;
public:
bool m_bCopyMapAtEnd;
int m_timer = 0;
};
#endif