World indices check

This commit is contained in:
MihailRis
2023-12-07 15:16:37 +03:00
parent 551b230b94
commit 636cb0c44c
12 changed files with 197 additions and 40 deletions
+37 -7
View File
@@ -6,6 +6,7 @@
#include "Level.h"
#include "../files/WorldFiles.h"
#include "../content/Content.h"
#include "../content/ContentIndexLUT.h"
#include "../voxels/Chunk.h"
#include "../voxels/Chunks.h"
#include "../voxels/ChunksStorage.h"
@@ -13,15 +14,22 @@
#include "../window/Camera.h"
using glm::vec3;
using std::unique_ptr;
using std::shared_ptr;
using std::string;
using std::filesystem::path;
namespace fs = std::filesystem;
world_load_error::world_load_error(string message) : std::runtime_error(message) {
}
World::World(string name,
path directory,
uint64_t seed,
EngineSettings& settings)
EngineSettings& settings,
const Content* content)
: settings(settings),
content(content),
name(name),
seed(seed) {
wfile = new WorldFiles(directory, settings.debug);
@@ -59,17 +67,39 @@ void World::write(Level* level) {
const float DEF_PLAYER_Y = 100.0f;
const float DEF_PLAYER_SPEED = 4.0f;
Level* World::create(EngineSettings& settings, const Content* content) {
Level* World::create(string name,
path directory,
uint64_t seed,
EngineSettings& settings,
const Content* content) {
World* world = new World(name, directory, seed, settings, content);
Player* player = new Player(vec3(0, DEF_PLAYER_Y, 0), DEF_PLAYER_SPEED);
return new Level(this, content, player, settings);
return new Level(world, content, player, settings);
}
Level* World::load(EngineSettings& settings, const Content* content) {
wfile->readWorldInfo(this);
Level* World::load(path directory,
EngineSettings& settings,
const Content* content) {
path indicesFile = directory/path("indices.json");
if (fs::is_regular_file(indicesFile)) {
auto lut = ContentIndexLUT::create(indicesFile, content);
if (lut) {
throw world_load_error("world indices conflict");
}
}
unique_ptr<World> world (new World(".", directory, 0, settings, content));
auto& wfile = world->wfile;
if (!wfile->readWorldInfo(world.get())) {
throw world_load_error("could not to find world.json");
}
Player* player = new Player(vec3(0, DEF_PLAYER_Y, 0), DEF_PLAYER_SPEED);
Level* level = new Level(this, content, player, settings);
Level* level = new Level(world.get(), content, player, settings);
wfile->readPlayer(player);
world.release();
return level;
}
+18 -3
View File
@@ -3,6 +3,7 @@
#include <string>
#include <filesystem>
#include <stdexcept>
#include "../typedefs.h"
#include "../settings.h"
#include "../util/timeutil.h"
@@ -13,8 +14,14 @@ class Chunks;
class Level;
class Player;
class world_load_error : public std::runtime_error {
public:
world_load_error(std::string message);
};
class World {
EngineSettings& settings;
const Content* const content;
public:
std::string name;
WorldFiles* wfile;
@@ -30,13 +37,21 @@ public:
World(std::string name,
std::filesystem::path directory,
uint64_t seed,
EngineSettings& settings);
EngineSettings& settings,
const Content* content);
~World();
void updateTimers(float delta);
void write(Level* level);
Level* create(EngineSettings& settings, const Content* content);
Level* load(EngineSettings& settings, const Content* content);
static Level* create(std::string name,
std::filesystem::path directory,
uint64_t seed,
EngineSettings& settings,
const Content* content);
static Level* load(std::filesystem::path directory,
EngineSettings& settings,
const Content* content);
};
#endif /* WORLD_WORLD_H_ */