Refactor, world.bin file, BinaryWriter, BinaryReader

This commit is contained in:
MihailRis
2023-11-16 19:32:44 +03:00
parent 9bc236b71a
commit 6cd775c27d
14 changed files with 378 additions and 126 deletions
+16 -5
View File
@@ -17,6 +17,9 @@
#define REGION_SIZE (1 << (REGION_SIZE_BIT))
#define REGION_VOL ((REGION_SIZE) * (REGION_SIZE))
#define REGION_FORMAT_VERSION 1
#define REGION_FORMAT_MAGIC ".VOXREG"
#define WORLD_FORMAT_MAGIC ".VOXWLD"
#define WORLD_FORMAT_VERSION 1
class Player;
class Chunk;
@@ -27,27 +30,35 @@ struct WorldRegion {
bool unsaved;
};
struct WorldInfo {
std::string name;
std::filesystem::path directory;
uint64_t seed;
};
class WorldFiles {
void writeWorldInfo(const WorldInfo& info);
std::filesystem::path getRegionFile(int x, int y) const;
std::filesystem::path getPlayerFile() const;
std::filesystem::path getWorldFile() const;
public:
std::unordered_map<glm::ivec2, WorldRegion> regions;
std::filesystem::path directory;
ubyte* compressionBuffer;
bool generatorTestMode;
WorldFiles(std::filesystem::path directory, size_t mainBufferCapacity, bool generatorTestMode);
WorldFiles(std::filesystem::path directory, bool generatorTestMode);
~WorldFiles();
void put(Chunk* chunk);
bool readWorldInfo(WorldInfo& info);
bool readPlayer(Player* player);
ubyte* readChunkData(int x, int y, uint32_t& length);
ubyte* getChunk(int x, int y);
void writeRegion(int x, int y, WorldRegion& entry);
void writePlayer(Player* player);
void write();
std::filesystem::path getRegionFile(int x, int y);
std::filesystem::path getPlayerFile();
void write(const WorldInfo info);
};
#endif /* FILES_WORLDFILES_H_ */