format: reformat project
Signed-off-by: Vyacheslav Ivanov <islavaivanov76@gmail.com>
This commit is contained in:
+43
-42
@@ -1,33 +1,34 @@
|
||||
#include "Level.hpp"
|
||||
#include "World.hpp"
|
||||
#include "LevelEvents.hpp"
|
||||
#include "../settings.hpp"
|
||||
|
||||
#include "../content/Content.hpp"
|
||||
#include "../data/dynamic_util.hpp"
|
||||
#include "../items/Inventories.hpp"
|
||||
#include "../items/Inventory.hpp"
|
||||
#include "../lighting/Lighting.hpp"
|
||||
#include "../objects/Entities.hpp"
|
||||
#include "../objects/Player.hpp"
|
||||
#include "../physics/Hitbox.hpp"
|
||||
#include "../physics/PhysicsSolver.hpp"
|
||||
#include "../settings.hpp"
|
||||
#include "../voxels/Chunk.hpp"
|
||||
#include "../voxels/Chunks.hpp"
|
||||
#include "../voxels/ChunksStorage.hpp"
|
||||
#include "../physics/Hitbox.hpp"
|
||||
#include "../physics/PhysicsSolver.hpp"
|
||||
#include "../objects/Player.hpp"
|
||||
#include "../objects/Entities.hpp"
|
||||
#include "../items/Inventory.hpp"
|
||||
#include "../items/Inventories.hpp"
|
||||
#include "../window/Camera.hpp"
|
||||
#include "../data/dynamic_util.hpp"
|
||||
#include "LevelEvents.hpp"
|
||||
#include "World.hpp"
|
||||
|
||||
Level::Level(
|
||||
std::unique_ptr<World> worldPtr,
|
||||
const Content* content,
|
||||
EngineSettings& settings
|
||||
) : world(std::move(worldPtr)),
|
||||
content(content),
|
||||
chunksStorage(std::make_unique<ChunksStorage>(this)),
|
||||
physics(std::make_unique<PhysicsSolver>(glm::vec3(0, -22.6f, 0))),
|
||||
events(std::make_unique<LevelEvents>()),
|
||||
entities(std::make_unique<Entities>(this)),
|
||||
settings(settings)
|
||||
{
|
||||
)
|
||||
: world(std::move(worldPtr)),
|
||||
content(content),
|
||||
chunksStorage(std::make_unique<ChunksStorage>(this)),
|
||||
physics(std::make_unique<PhysicsSolver>(glm::vec3(0, -22.6f, 0))),
|
||||
events(std::make_unique<LevelEvents>()),
|
||||
entities(std::make_unique<Entities>(this)),
|
||||
settings(settings) {
|
||||
auto& cameraIndices = content->getIndices(ResourceType::CAMERA);
|
||||
for (size_t i = 0; i < cameraIndices.size(); i++) {
|
||||
auto camera = std::make_shared<Camera>();
|
||||
@@ -48,45 +49,45 @@ Level::Level(
|
||||
if (world->nextEntityId) {
|
||||
entities->setNextID(world->nextEntityId);
|
||||
}
|
||||
auto inv = std::make_shared<Inventory>(
|
||||
auto inv = std::make_shared<Inventory>(
|
||||
world->getNextInventoryId(), DEF_PLAYER_INVENTORY_SIZE
|
||||
);
|
||||
auto player = spawnObject<Player>(
|
||||
auto player = spawnObject<Player>(
|
||||
this, glm::vec3(0, DEF_PLAYER_Y, 0), DEF_PLAYER_SPEED, inv, 0
|
||||
);
|
||||
|
||||
uint matrixSize = (
|
||||
settings.chunks.loadDistance.get() +
|
||||
settings.chunks.padding.get()
|
||||
) * 2;
|
||||
uint matrixSize =
|
||||
(settings.chunks.loadDistance.get() + settings.chunks.padding.get()) *
|
||||
2;
|
||||
chunks = std::make_unique<Chunks>(
|
||||
matrixSize, matrixSize, 0, 0, world->wfile.get(), this
|
||||
);
|
||||
lighting = std::make_unique<Lighting>(content, chunks.get());
|
||||
matrixSize, matrixSize, 0, 0, world->wfile.get(), this
|
||||
);
|
||||
lighting = std::make_unique<Lighting>(content, chunks.get());
|
||||
|
||||
events->listen(EVT_CHUNK_HIDDEN, [this](lvl_event_type, Chunk* chunk) {
|
||||
this->chunksStorage->remove(chunk->x, chunk->z);
|
||||
});
|
||||
events->listen(EVT_CHUNK_HIDDEN, [this](lvl_event_type, Chunk* chunk) {
|
||||
this->chunksStorage->remove(chunk->x, chunk->z);
|
||||
});
|
||||
|
||||
inventories = std::make_unique<Inventories>(*this);
|
||||
inventories->store(player->getInventory());
|
||||
inventories = std::make_unique<Inventories>(*this);
|
||||
inventories->store(player->getInventory());
|
||||
}
|
||||
|
||||
Level::~Level(){
|
||||
for(auto obj : objects) {
|
||||
obj.reset();
|
||||
}
|
||||
Level::~Level() {
|
||||
for (auto obj : objects) {
|
||||
obj.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void Level::loadMatrix(int32_t x, int32_t z, uint32_t radius) {
|
||||
chunks->setCenter(x, z);
|
||||
chunks->setCenter(x, z);
|
||||
uint32_t diameter = std::min(
|
||||
radius*2LL,
|
||||
(settings.chunks.loadDistance.get() + settings.chunks.padding.get()) * 2LL
|
||||
radius * 2LL,
|
||||
(settings.chunks.loadDistance.get() + settings.chunks.padding.get()) *
|
||||
2LL
|
||||
);
|
||||
if (chunks->w != diameter) {
|
||||
chunks->resize(diameter, diameter);
|
||||
}
|
||||
if (chunks->w != diameter) {
|
||||
chunks->resize(diameter, diameter);
|
||||
}
|
||||
}
|
||||
|
||||
World* Level::getWorld() {
|
||||
|
||||
+20
-13
@@ -1,11 +1,11 @@
|
||||
#ifndef WORLD_LEVEL_HPP_
|
||||
#define WORLD_LEVEL_HPP_
|
||||
|
||||
#include "../interfaces/Object.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "../interfaces/Object.hpp"
|
||||
|
||||
inline constexpr float DEF_PLAYER_Y = 100.0f;
|
||||
inline constexpr float DEF_PLAYER_SPEED = 4.0f;
|
||||
inline constexpr int DEF_PLAYER_INVENTORY_SIZE = 40;
|
||||
@@ -36,42 +36,49 @@ public:
|
||||
std::unique_ptr<Lighting> lighting;
|
||||
std::unique_ptr<LevelEvents> events;
|
||||
std::unique_ptr<Entities> entities;
|
||||
std::vector<std::shared_ptr<Camera>> cameras; // move somewhere?
|
||||
std::vector<std::shared_ptr<Camera>> cameras; // move somewhere?
|
||||
|
||||
const EngineSettings& settings;
|
||||
|
||||
Level(
|
||||
std::unique_ptr<World> world,
|
||||
const Content* content,
|
||||
std::unique_ptr<World> world,
|
||||
const Content* content,
|
||||
EngineSettings& settings
|
||||
);
|
||||
~Level();
|
||||
|
||||
void loadMatrix(int32_t x, int32_t z, uint32_t radius);
|
||||
|
||||
|
||||
World* getWorld();
|
||||
|
||||
/// Spawns object of class T and returns pointer to it.
|
||||
/// @param T class that derives the Object class
|
||||
/// @param args pass arguments needed for T class constructor
|
||||
template<class T, typename... Args>
|
||||
template <class T, typename... Args>
|
||||
std::shared_ptr<T> spawnObject(Args&&... args) {
|
||||
static_assert(std::is_base_of<Object, T>::value, "T must be a derived of Object class");
|
||||
static_assert(
|
||||
std::is_base_of<Object, T>::value,
|
||||
"T must be a derived of Object class"
|
||||
);
|
||||
std::shared_ptr<T> tObj = std::make_shared<T>(args...);
|
||||
|
||||
std::shared_ptr<Object> obj = std::dynamic_pointer_cast<Object, T>(tObj);
|
||||
|
||||
std::shared_ptr<Object> obj =
|
||||
std::dynamic_pointer_cast<Object, T>(tObj);
|
||||
obj->objectUID = objects.size();
|
||||
objects.push_back(obj);
|
||||
obj->spawned();
|
||||
return tObj;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
std::shared_ptr<T> getObject(uint64_t id) {
|
||||
static_assert(std::is_base_of<Object, T>::value, "T must be a derived of Object class");
|
||||
static_assert(
|
||||
std::is_base_of<Object, T>::value,
|
||||
"T must be a derived of Object class"
|
||||
);
|
||||
if (id >= objects.size()) return nullptr;
|
||||
std::shared_ptr<T> object = std::dynamic_pointer_cast<T>(objects[id]);
|
||||
return object;
|
||||
return object;
|
||||
}
|
||||
|
||||
void onSave();
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
#include "LevelEvents.hpp"
|
||||
|
||||
#include "../voxels/Chunk.hpp"
|
||||
|
||||
using std::vector;
|
||||
|
||||
void LevelEvents::listen(lvl_event_type type, const chunk_event_func& func) {
|
||||
auto& callbacks = chunk_callbacks[type];
|
||||
callbacks.push_back(func);
|
||||
auto& callbacks = chunk_callbacks[type];
|
||||
callbacks.push_back(func);
|
||||
}
|
||||
|
||||
void LevelEvents::trigger(lvl_event_type type, Chunk* chunk) {
|
||||
const auto& callbacks = chunk_callbacks[type];
|
||||
for (const chunk_event_func& func : callbacks) {
|
||||
func(type, chunk);
|
||||
}
|
||||
const auto& callbacks = chunk_callbacks[type];
|
||||
for (const chunk_event_func& func : callbacks) {
|
||||
func(type, chunk);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#define WORLD_LEVEL_EVENTS_HPP_
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class Chunk;
|
||||
|
||||
@@ -14,10 +14,11 @@ enum lvl_event_type {
|
||||
using chunk_event_func = std::function<void(lvl_event_type, Chunk*)>;
|
||||
|
||||
class LevelEvents {
|
||||
std::unordered_map<lvl_event_type, std::vector<chunk_event_func>> chunk_callbacks;
|
||||
std::unordered_map<lvl_event_type, std::vector<chunk_event_func>>
|
||||
chunk_callbacks;
|
||||
public:
|
||||
void listen(lvl_event_type type, const chunk_event_func& func);
|
||||
void trigger(lvl_event_type type, Chunk* chunk);
|
||||
};
|
||||
|
||||
#endif // WORLD_LEVEL_EVENTS_HPP_
|
||||
#endif // WORLD_LEVEL_EVENTS_HPP_
|
||||
|
||||
+33
-30
@@ -1,49 +1,48 @@
|
||||
#include "World.hpp"
|
||||
|
||||
#include "Level.hpp"
|
||||
#include <glm/glm.hpp>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "../settings.hpp"
|
||||
#include "../content/Content.hpp"
|
||||
#include "../content/ContentLUT.hpp"
|
||||
#include "../debug/Logger.hpp"
|
||||
#include "../files/WorldFiles.hpp"
|
||||
#include "../items/Inventories.hpp"
|
||||
#include "../objects/Player.hpp"
|
||||
#include "../objects/Entities.hpp"
|
||||
#include "../objects/Player.hpp"
|
||||
#include "../settings.hpp"
|
||||
#include "../voxels/Chunk.hpp"
|
||||
#include "../voxels/Chunks.hpp"
|
||||
#include "../voxels/ChunksStorage.hpp"
|
||||
#include "../world/WorldGenerators.hpp"
|
||||
#include "Level.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <glm/glm.hpp>
|
||||
#include <utility>
|
||||
|
||||
static debug::Logger logger("world");
|
||||
const float DAYIME_SPECIFIC_SPEED = 1.0f/1440.0f; //1.0f/60.0f/24.0f;
|
||||
const float DAYIME_SPECIFIC_SPEED = 1.0f / 1440.0f; // 1.0f/60.0f/24.0f;
|
||||
|
||||
world_load_error::world_load_error(const std::string& message)
|
||||
: std::runtime_error(message) {
|
||||
}
|
||||
|
||||
World::World(
|
||||
std::string name,
|
||||
std::string name,
|
||||
std::string generator,
|
||||
const fs::path& directory,
|
||||
uint64_t seed,
|
||||
uint64_t seed,
|
||||
EngineSettings& settings,
|
||||
const Content* content,
|
||||
const std::vector<ContentPack>& packs
|
||||
) : name(std::move(name)),
|
||||
generator(std::move(generator)),
|
||||
seed(seed),
|
||||
content(content),
|
||||
packs(packs),
|
||||
wfile(std::make_unique<WorldFiles>(directory, settings.debug))
|
||||
{}
|
||||
)
|
||||
: name(std::move(name)),
|
||||
generator(std::move(generator)),
|
||||
seed(seed),
|
||||
content(content),
|
||||
packs(packs),
|
||||
wfile(std::make_unique<WorldFiles>(directory, settings.debug)) {
|
||||
}
|
||||
|
||||
World::~World(){
|
||||
World::~World() {
|
||||
}
|
||||
|
||||
void World::updateTimers(float delta) {
|
||||
@@ -74,7 +73,7 @@ void World::write(Level* level) {
|
||||
level->chunks->saveAll();
|
||||
nextEntityId = level->entities->peekNextID();
|
||||
wfile->write(this, content);
|
||||
|
||||
|
||||
auto playerFile = dynamic::Map();
|
||||
auto& players = playerFile.putList("players");
|
||||
for (const auto& object : level->objects) {
|
||||
@@ -92,7 +91,7 @@ std::unique_ptr<Level> World::create(
|
||||
const std::string& generator,
|
||||
const fs::path& directory,
|
||||
uint64_t seed,
|
||||
EngineSettings& settings,
|
||||
EngineSettings& settings,
|
||||
const Content* content,
|
||||
const std::vector<ContentPack>& packs
|
||||
) {
|
||||
@@ -109,7 +108,13 @@ std::unique_ptr<Level> World::load(
|
||||
const std::vector<ContentPack>& packs
|
||||
) {
|
||||
auto world = std::make_unique<World>(
|
||||
".", WorldGenerators::getDefaultGeneratorID(), directory, 0, settings, content, packs
|
||||
".",
|
||||
WorldGenerators::getDefaultGeneratorID(),
|
||||
directory,
|
||||
0,
|
||||
settings,
|
||||
content,
|
||||
packs
|
||||
);
|
||||
auto& wfile = world->wfile;
|
||||
|
||||
@@ -131,8 +136,8 @@ std::unique_ptr<Level> World::load(
|
||||
for (size_t i = 0; i < players->size(); i++) {
|
||||
auto player = level->spawnObject<Player>(
|
||||
level.get(),
|
||||
glm::vec3(0, DEF_PLAYER_Y, 0),
|
||||
DEF_PLAYER_SPEED,
|
||||
glm::vec3(0, DEF_PLAYER_Y, 0),
|
||||
DEF_PLAYER_SPEED,
|
||||
level->inventories->create(DEF_PLAYER_INVENTORY_SIZE),
|
||||
0
|
||||
);
|
||||
@@ -150,10 +155,9 @@ std::unique_ptr<Level> World::load(
|
||||
}
|
||||
|
||||
std::shared_ptr<ContentLUT> World::checkIndices(
|
||||
const fs::path& directory,
|
||||
const Content* content
|
||||
const fs::path& directory, const Content* content
|
||||
) {
|
||||
fs::path indicesFile = directory/fs::path("indices.json");
|
||||
fs::path indicesFile = directory / fs::path("indices.json");
|
||||
if (fs::is_regular_file(indicesFile)) {
|
||||
return ContentLUT::create(indicesFile, content);
|
||||
}
|
||||
@@ -170,8 +174,7 @@ void World::setGenerator(const std::string& generator) {
|
||||
|
||||
bool World::hasPack(const std::string& id) const {
|
||||
for (auto& pack : packs) {
|
||||
if (pack.id == id)
|
||||
return true;
|
||||
if (pack.id == id) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -205,7 +208,7 @@ void World::deserialize(dynamic::Map* root) {
|
||||
generator = WorldGenerators::getDefaultGeneratorID();
|
||||
}
|
||||
if (auto verobj = root->map("version")) {
|
||||
int major=0, minor=-1;
|
||||
int major = 0, minor = -1;
|
||||
verobj->num("major", major);
|
||||
verobj->num("minor", minor);
|
||||
logger.info() << "world version: " << major << "." << minor;
|
||||
@@ -232,7 +235,7 @@ std::unique_ptr<dynamic::Map> World::serialize() const {
|
||||
root->put("name", name);
|
||||
root->put("generator", generator);
|
||||
root->put("seed", static_cast<integer_t>(seed));
|
||||
|
||||
|
||||
auto& timeobj = root->putMap("time");
|
||||
timeobj.put("day-time", daytime);
|
||||
timeobj.put("day-time-speed", daytimeSpeed);
|
||||
|
||||
+26
-26
@@ -1,16 +1,16 @@
|
||||
#ifndef WORLD_WORLD_HPP_
|
||||
#define WORLD_WORLD_HPP_
|
||||
|
||||
#include "../typedefs.hpp"
|
||||
#include "../util/timeutil.hpp"
|
||||
#include "../data/dynamic.hpp"
|
||||
#include "../interfaces/Serializable.hpp"
|
||||
#include "../content/ContentPack.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <filesystem>
|
||||
|
||||
#include "../content/ContentPack.hpp"
|
||||
#include "../data/dynamic.hpp"
|
||||
#include "../interfaces/Serializable.hpp"
|
||||
#include "../typedefs.hpp"
|
||||
#include "../util/timeutil.hpp"
|
||||
|
||||
class Content;
|
||||
class WorldFiles;
|
||||
@@ -22,7 +22,7 @@ namespace fs = std::filesystem;
|
||||
|
||||
class world_load_error : public std::runtime_error {
|
||||
public:
|
||||
world_load_error(const std::string &message);
|
||||
world_load_error(const std::string& message);
|
||||
};
|
||||
|
||||
/// @brief holds all world data except the level (chunks and objects)
|
||||
@@ -39,27 +39,27 @@ class World : Serializable {
|
||||
public:
|
||||
std::unique_ptr<WorldFiles> wfile;
|
||||
|
||||
/// @brief Day/night loop timer in range 0..1 where
|
||||
/// @brief Day/night loop timer in range 0..1 where
|
||||
/// 0.0 - is midnight and
|
||||
/// 0.5 - is noon
|
||||
float daytime = timeutil::time_value(10, 00, 00);
|
||||
|
||||
// looking bad
|
||||
float daytimeSpeed = 1.0f;
|
||||
|
||||
|
||||
/// @brief total time passed in the world (not depending on daytimeSpeed)
|
||||
double totalTime = 0.0;
|
||||
|
||||
/// @brief will be replaced with weather in future
|
||||
/// @brief will be replaced with weather in future
|
||||
float fog = 0.0f;
|
||||
|
||||
entityid_t nextEntityId = 0;
|
||||
|
||||
World(
|
||||
std::string name,
|
||||
std::string name,
|
||||
std::string generator,
|
||||
const fs::path& directory,
|
||||
uint64_t seed,
|
||||
uint64_t seed,
|
||||
EngineSettings& settings,
|
||||
const Content* content,
|
||||
const std::vector<ContentPack>& packs
|
||||
@@ -70,14 +70,14 @@ public:
|
||||
/// @brief Update world day-time and total time
|
||||
/// @param delta delta-time
|
||||
void updateTimers(float delta);
|
||||
|
||||
|
||||
/// @brief Write all unsaved level data to the world directory
|
||||
void write(Level* level);
|
||||
|
||||
/// @brief Check world indices and generate ContentLUT if convert required
|
||||
/// @brief Check world indices and generate ContentLUT if convert required
|
||||
/// @param directory world directory
|
||||
/// @param content current Content instance
|
||||
/// @return ContentLUT if world convert required else nullptr
|
||||
/// @return ContentLUT if world convert required else nullptr
|
||||
static std::shared_ptr<ContentLUT> checkIndices(
|
||||
const fs::path& directory, const Content* content
|
||||
);
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
/// @param type of the world
|
||||
/// @param seed world generation seed
|
||||
/// @param settings current engine settings
|
||||
/// @param content current engine Content instance
|
||||
/// @param content current engine Content instance
|
||||
/// with all world content-packs applied
|
||||
/// @param packs vector of all world content-packs
|
||||
/// @return Level instance containing World instance
|
||||
@@ -96,16 +96,16 @@ public:
|
||||
const std::string& name,
|
||||
const std::string& generator,
|
||||
const fs::path& directory,
|
||||
uint64_t seed,
|
||||
EngineSettings& settings,
|
||||
uint64_t seed,
|
||||
EngineSettings& settings,
|
||||
const Content* content,
|
||||
const std::vector<ContentPack>& packs
|
||||
);
|
||||
|
||||
/// @brief Load an existing world
|
||||
/// @param directory root world directory
|
||||
/// @param directory root world directory
|
||||
/// @param settings current engine settings
|
||||
/// @param content current engine Content instance
|
||||
/// @param content current engine Content instance
|
||||
/// with all world content-packs applied
|
||||
/// @param packs vector of all world content-packs
|
||||
/// @return Level instance containing World instance
|
||||
@@ -121,7 +121,7 @@ public:
|
||||
void setSeed(uint64_t seed);
|
||||
void setGenerator(const std::string& generator);
|
||||
|
||||
/// @brief Check if world has content-pack installed
|
||||
/// @brief Check if world has content-pack installed
|
||||
/// @param id content-pack id
|
||||
bool hasPack(const std::string& id) const;
|
||||
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
|
||||
/// @brief Get vector of all content-packs installed in world
|
||||
const std::vector<ContentPack>& getPacks() const;
|
||||
|
||||
|
||||
/// @brief Get next inventory id and increment it's counter
|
||||
/// @return integer >= 1
|
||||
int64_t getNextInventoryId() {
|
||||
@@ -150,7 +150,7 @@ public:
|
||||
}
|
||||
|
||||
std::unique_ptr<dynamic::Map> serialize() const override;
|
||||
void deserialize(dynamic::Map *src) override;
|
||||
void deserialize(dynamic::Map* src) override;
|
||||
};
|
||||
|
||||
#endif // WORLD_WORLD_HPP_
|
||||
#endif // WORLD_WORLD_HPP_
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#include "WorldGenerators.hpp"
|
||||
#include "../voxels/WorldGenerator.hpp"
|
||||
#include "../voxels/FlatWorldGenerator.hpp"
|
||||
#include "../content/Content.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "../content/Content.hpp"
|
||||
#include "../voxels/FlatWorldGenerator.hpp"
|
||||
#include "../voxels/WorldGenerator.hpp"
|
||||
|
||||
std::vector<std::string> WorldGenerators::getGeneratorsIDs() {
|
||||
std::vector<std::string> ids;
|
||||
for (auto& entry : generators) {
|
||||
@@ -16,10 +18,12 @@ std::string WorldGenerators::getDefaultGeneratorID() {
|
||||
return "core:default";
|
||||
}
|
||||
|
||||
std::unique_ptr<WorldGenerator> WorldGenerators::createGenerator(const std::string& id, const Content* content) {
|
||||
std::unique_ptr<WorldGenerator> WorldGenerators::createGenerator(
|
||||
const std::string& id, const Content* content
|
||||
) {
|
||||
auto found = generators.find(id);
|
||||
if (found == generators.end()) {
|
||||
throw std::runtime_error("unknown generator id: "+id);
|
||||
throw std::runtime_error("unknown generator id: " + id);
|
||||
}
|
||||
return std::unique_ptr<WorldGenerator>(found->second(content));
|
||||
}
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
#ifndef WORLD_WORLDGENERATORS_HPP_
|
||||
#define WORLD_WORLDGENERATORS_HPP_
|
||||
|
||||
#include "../voxels/WorldGenerator.hpp"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../voxels/WorldGenerator.hpp"
|
||||
|
||||
class Content;
|
||||
|
||||
typedef WorldGenerator* (*gen_constructor) (const Content*);
|
||||
|
||||
typedef WorldGenerator* (*gen_constructor)(const Content*);
|
||||
|
||||
class WorldGenerators {
|
||||
static inline std::map<std::string, gen_constructor> generators;
|
||||
|
||||
public:
|
||||
template <typename T>
|
||||
static void addGenerator(std::string id);
|
||||
@@ -23,16 +22,14 @@ public:
|
||||
static std::string getDefaultGeneratorID();
|
||||
|
||||
static std::unique_ptr<WorldGenerator> createGenerator(
|
||||
const std::string &id, const Content *content
|
||||
const std::string& id, const Content* content
|
||||
);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void WorldGenerators::addGenerator(std::string id) {
|
||||
generators[id] =
|
||||
[] (const Content* content)
|
||||
{
|
||||
return (WorldGenerator*) new T(content);
|
||||
generators[id] = [](const Content* content) {
|
||||
return (WorldGenerator*)new T(content);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user