Sky lights data saving (optimization)

This commit is contained in:
MihailRis
2023-12-06 16:15:44 +03:00
parent 6b423b441f
commit a102821076
12 changed files with 147 additions and 38 deletions
+18 -3
View File
@@ -12,6 +12,7 @@
#include "glm/gtx/hash.hpp"
#include "../typedefs.h"
#include "../settings.h"
const uint REGION_SIZE_BIT = 5;
const uint REGION_SIZE = (1 << (REGION_SIZE_BIT));
@@ -30,7 +31,7 @@ class World;
class WorldRegion {
ubyte** chunksData;
uint32_t* sizes;
bool unsaved = true;
bool unsaved = false;
public:
WorldRegion();
~WorldRegion();
@@ -49,7 +50,8 @@ public:
class WorldFiles {
void writeWorldInfo(const World* world);
std::filesystem::path getRegionsFolder() const;
std::filesystem::path getRegionFile(int x, int y) const;
std::filesystem::path getLightsFolder() const;
std::filesystem::path getRegionFilename(int x, int y) const;
std::filesystem::path getPlayerFile() const;
std::filesystem::path getWorldFile() const;
std::filesystem::path getIndicesFile() const;
@@ -64,6 +66,10 @@ class WorldFiles {
WorldRegion* getRegion(std::unordered_map<glm::ivec2, WorldRegion*>& regions,
int x, int z);
WorldRegion* getOrCreateRegion(
std::unordered_map<glm::ivec2, WorldRegion*>& regions,
int x, int z);
/* Compress buffer with extrle
@param src source buffer
@param srclen length of source buffer
@@ -80,18 +86,27 @@ class WorldFiles {
ubyte* readChunkData(int x, int y,
uint32_t& length,
std::filesystem::path file);
void writeRegions(std::unordered_map<glm::ivec2, WorldRegion*>& regions,
const std::filesystem::path& folder);
ubyte* getData(std::unordered_map<glm::ivec2, WorldRegion*>& regions,
const std::filesystem::path& folder,
int x, int z);
public:
std::unordered_map<glm::ivec2, WorldRegion*> regions;
std::unordered_map<glm::ivec2, WorldRegion*> lights;
std::filesystem::path directory;
ubyte* compressionBuffer;
bool generatorTestMode;
bool doWriteLights;
WorldFiles(std::filesystem::path directory, bool generatorTestMode);
WorldFiles(std::filesystem::path directory, const DebugSettings& settings);
~WorldFiles();
void put(Chunk* chunk);
ubyte* getChunk(int x, int y);
light_t* getLights(int x, int y);
bool readWorldInfo(World* world);
bool readPlayer(Player* player);