General refactor

This commit is contained in:
MihailRis
2023-11-30 04:30:40 +03:00
parent de134dc2e5
commit 1d5037893c
27 changed files with 558 additions and 419 deletions
+13 -12
View File
@@ -12,6 +12,7 @@
#include "../voxels/Chunk.h"
#include "../typedefs.h"
#include "../maths/voxmaths.h"
#include "../world/World.h"
#include <cassert>
#include <iostream>
@@ -201,12 +202,12 @@ ubyte* WorldFiles::readChunkData(int x, int y, uint32_t& length){
return data;
}
void WorldFiles::write(const WorldInfo info, const Content* content) {
void WorldFiles::write(const World* world, const Content* content) {
path directory = getRegionsFolder();
if (!std::filesystem::is_directory(directory)) {
std::filesystem::create_directories(directory);
}
writeWorldInfo(info);
writeWorldInfo(world);
if (generatorTestMode)
return;
writeIndices(content->indices);
@@ -232,23 +233,23 @@ void WorldFiles::writeIndices(const ContentIndices* indices) {
}
}
void WorldFiles::writeWorldInfo(const WorldInfo& info) {
void WorldFiles::writeWorldInfo(const World* world) {
BinaryWriter out;
out.putCStr(WORLD_FORMAT_MAGIC);
out.put(WORLD_FORMAT_VERSION);
out.put(WORLD_SECTION_MAIN);
out.putInt64(info.seed);
out.put(info.name);
out.putInt64(world->seed);
out.put(world->name);
out.put(WORLD_SECTION_DAYNIGHT);
out.putFloat32(info.daytime);
out.putFloat32(info.daytimeSpeed);
out.putFloat32(world->daytime);
out.putFloat32(world->daytimeSpeed);
files::write_bytes(getWorldFile(), (const char*)out.data(), out.size());
}
bool WorldFiles::readWorldInfo(WorldInfo& info) {
bool WorldFiles::readWorldInfo(World* world) {
size_t length = 0;
ubyte* data = (ubyte*)files::read_bytes(getWorldFile(), length);
if (data == nullptr){
@@ -262,12 +263,12 @@ bool WorldFiles::readWorldInfo(WorldInfo& info) {
ubyte section = inp.get();
switch (section) {
case WORLD_SECTION_MAIN:
info.seed = inp.getInt64();
info.name = inp.getString();
world->seed = inp.getInt64();
world->name = inp.getString();
break;
case WORLD_SECTION_DAYNIGHT:
info.daytime = inp.getFloat32();
info.daytimeSpeed = inp.getFloat32();
world->daytime = inp.getFloat32();
world->daytimeSpeed = inp.getFloat32();
break;
}
}
+4 -11
View File
@@ -25,6 +25,7 @@ class Player;
class Chunk;
class Content;
class ContentIndices;
class World;
struct WorldRegion {
ubyte** chunksData;
@@ -32,16 +33,8 @@ struct WorldRegion {
bool unsaved;
};
struct WorldInfo {
std::string name;
std::filesystem::path directory;
uint64_t seed;
float daytime;
float daytimeSpeed;
};
class WorldFiles {
void writeWorldInfo(const WorldInfo& info);
void writeWorldInfo(const World* world);
std::filesystem::path getRegionsFolder() const;
std::filesystem::path getRegionFile(int x, int y) const;
std::filesystem::path getPlayerFile() const;
@@ -58,13 +51,13 @@ public:
void put(Chunk* chunk);
bool readWorldInfo(WorldInfo& info);
bool readWorldInfo(World* world);
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(const WorldInfo info, const Content* content);
void write(const World* world, const Content* content);
void writeIndices(const ContentIndices* indices);
};
+1
View File
@@ -30,6 +30,7 @@ toml::Wrapper create_wrapper(EngineSettings& settings) {
toml::Section& graphics = wrapper.add("graphics");
graphics.add("fog-curve", &settings.graphics.fogCurve);
graphics.add("backlight", &settings.graphics.backlight);
graphics.add("frustum-culling", &settings.graphics.frustumCulling);
toml::Section& debug = wrapper.add("debug");
debug.add("generator-test-mode", &settings.debug.generatorTestMode);