Minimized region files reopen
This commit is contained in:
+25
-12
@@ -3,22 +3,27 @@
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include "glm/gtx/hash.hpp"
|
||||
|
||||
#include "files.h"
|
||||
#include "../typedefs.h"
|
||||
#include "../settings.h"
|
||||
|
||||
const uint REGION_LAYER_VOXELS = 0;
|
||||
const uint REGION_LAYER_LIGHTS = 1;
|
||||
const uint REGION_SIZE_BIT = 5;
|
||||
const uint REGION_SIZE = (1 << (REGION_SIZE_BIT));
|
||||
const uint REGION_CHUNKS_COUNT = ((REGION_SIZE) * (REGION_SIZE));
|
||||
const uint REGION_FORMAT_VERSION = 1;
|
||||
const uint WORLD_FORMAT_VERSION = 1;
|
||||
const uint MAX_OPEN_REGION_FILES = 16;
|
||||
|
||||
#define REGION_FORMAT_MAGIC ".VOXREG"
|
||||
#define WORLD_FORMAT_MAGIC ".VOXWLD"
|
||||
|
||||
@@ -47,7 +52,10 @@ public:
|
||||
uint32_t* getSizes() const;
|
||||
};
|
||||
|
||||
typedef std::unordered_map<glm::ivec2, WorldRegion*> regionsmap;
|
||||
class WorldFiles {
|
||||
std::unordered_map<glm::ivec3, std::unique_ptr<files::rafile>> openRegFiles;
|
||||
|
||||
void writeWorldInfo(const World* world);
|
||||
std::filesystem::path getLightsFolder() const;
|
||||
std::filesystem::path getRegionFilename(int x, int y) const;
|
||||
@@ -56,11 +64,11 @@ class WorldFiles {
|
||||
std::filesystem::path getIndicesFile() const;
|
||||
std::filesystem::path getPacksFile() const;
|
||||
|
||||
WorldRegion* getRegion(std::unordered_map<glm::ivec2, WorldRegion*>& regions,
|
||||
WorldRegion* getRegion(regionsmap& regions,
|
||||
int x, int z);
|
||||
|
||||
WorldRegion* getOrCreateRegion(
|
||||
std::unordered_map<glm::ivec2, WorldRegion*>& regions,
|
||||
regionsmap& regions,
|
||||
int x, int z);
|
||||
|
||||
/* Compress buffer with extrle
|
||||
@@ -77,21 +85,25 @@ class WorldFiles {
|
||||
ubyte* decompress(const ubyte* src, size_t srclen, size_t dstlen);
|
||||
|
||||
ubyte* readChunkData(int x, int y,
|
||||
uint32_t& length,
|
||||
std::filesystem::path file);
|
||||
uint32_t& length,
|
||||
std::filesystem::path folder,
|
||||
int layer);
|
||||
|
||||
void writeRegions(std::unordered_map<glm::ivec2, WorldRegion*>& regions,
|
||||
const std::filesystem::path& folder);
|
||||
void writeRegions(regionsmap& regions,
|
||||
const std::filesystem::path& folder, int layer);
|
||||
|
||||
ubyte* getData(std::unordered_map<glm::ivec2, WorldRegion*>& regions,
|
||||
ubyte* getData(regionsmap& regions,
|
||||
const std::filesystem::path& folder,
|
||||
int x, int z);
|
||||
int x, int z, int layer);
|
||||
|
||||
files::rafile* getRegFile(glm::ivec3 coord,
|
||||
const std::filesystem::path& folder);
|
||||
public:
|
||||
static bool parseRegionFilename(const std::string& name, int& x, int& y);
|
||||
std::filesystem::path getRegionsFolder() const;
|
||||
|
||||
std::unordered_map<glm::ivec2, WorldRegion*> regions;
|
||||
std::unordered_map<glm::ivec2, WorldRegion*> lights;
|
||||
regionsmap regions;
|
||||
regionsmap lights;
|
||||
std::filesystem::path directory;
|
||||
ubyte* compressionBuffer;
|
||||
bool generatorTestMode;
|
||||
@@ -111,7 +123,8 @@ public:
|
||||
|
||||
void writeRegion(int x, int y,
|
||||
WorldRegion* entry,
|
||||
std::filesystem::path file);
|
||||
std::filesystem::path file,
|
||||
int layer);
|
||||
void writePlayer(Player* player);
|
||||
/* @param world world info to save (nullable) */
|
||||
void write(const World* world, const Content* content);
|
||||
|
||||
Reference in New Issue
Block a user