* SavingWorldScreen: Only save what's necessary

This commit is contained in:
iProgramInCpp
2023-08-02 21:55:46 +03:00
parent a2df1b3095
commit e5f942c194
7 changed files with 49 additions and 3 deletions

View File

@@ -19,7 +19,7 @@ void SavingWorldScreen::render(int mouseX, int mouseY, float f)
int yPos = x_height / 2;
int width = m_pFont->width("Saving chunks");
m_pFont->drawShadow("Saving chunks", (x_width - width) / 2, yPos + 4, 0xFFFFFF);
m_pFont->drawShadow("Saving chunks", (x_width - width) / 2, yPos, 0xFFFFFF);
}
void SavingWorldScreen::tick()
@@ -36,7 +36,7 @@ void SavingWorldScreen::tick()
Level* pLevel = m_pMinecraft->m_pLevel;
if (pLevel)
{
pLevel->saveAllChunks();
pLevel->saveUnsavedChunks();
pLevel->saveLevelData();
pLevel->savePlayerData();

View File

@@ -179,6 +179,27 @@ void ChunkCache::saveAll()
m_pChunkStorage->saveAll(m_pLevel, chunksToSave);
}
void ChunkCache::saveUnsaved()
{
if (!m_pChunkStorage) return;
std::vector<LevelChunk*> chunksToSave;
for (int i = 0; i < C_MAX_CHUNKS_Z; i++)
{
for (int j = 0; j < C_MAX_CHUNKS_X; j++)
{
LevelChunk* pChunk = m_pLevel->getChunk(j, i);
if (!pChunk->m_bUnsaved)
continue;
chunksToSave.push_back(pChunk);
}
}
m_pChunkStorage->saveAll(m_pLevel, chunksToSave);
}
bool ChunkCache::shouldSave()
{
return true;

View File

@@ -27,6 +27,9 @@ public:
bool shouldSave() override;
void saveAll() override;
int tick() override;
#ifdef ENH_IMPROVED_SAVING
void saveUnsaved() override;
#endif
LevelChunk* load(int, int);
void save(LevelChunk*);

View File

@@ -9,11 +9,18 @@
#include "ChunkSource.hpp"
#include "Level.hpp"
ChunkSource::~ChunkSource()
{
}
void ChunkSource::saveAll()
{
}
ChunkSource::~ChunkSource()
#ifdef ENH_IMPROVED_SAVING
void ChunkSource::saveUnsaved()
{
}
#endif

View File

@@ -8,6 +8,7 @@
#pragma once
#include <string>
#include "GameMods.hpp"
class Level;
class LevelChunk;
@@ -23,5 +24,8 @@ public:
virtual bool shouldSave() = 0;
virtual void saveAll();
virtual std::string gatherStats() = 0;
#ifdef ENH_IMPROVED_SAVING
virtual void saveUnsaved();
#endif
};

View File

@@ -1095,6 +1095,13 @@ void Level::saveAllChunks()
m_pChunkSource->saveAll();
}
#ifdef ENH_IMPROVED_SAVING
void Level::saveUnsavedChunks()
{
m_pChunkSource->saveUnsaved();
}
#endif
void Level::setInitialSpawn()
{
field_A00 = true;

View File

@@ -161,6 +161,10 @@ public:
bool hasDirectSignal(int x, int y, int z);
bool hasNeighborSignal(int x, int y, int z);
#ifdef ENH_IMPROVED_SAVING
void saveUnsavedChunks();
#endif
public:
AABBVector m_aabbs;
uint8_t field_10 = 0;