Add files via upload

This commit is contained in:
Onran
2024-02-23 17:12:00 +09:00
committed by GitHub
parent a5087cf221
commit 8130b0626f
17 changed files with 95 additions and 39 deletions
+1 -2
View File
@@ -6,7 +6,6 @@
#include "Level.h"
#include "../files/WorldFiles.h"
#include "../world/WorldTypes.h"
#include "../content/Content.h"
#include "../world/WorldGenerators.h"
#include "../content/ContentLUT.h"
@@ -116,7 +115,7 @@ void World::setName(const std::string& name) {
this->name = name;
}
void world::setGenerator(const std::string& generator) {
void World::setGenerator(const std::string& generator) {
this->generator = generator;
}
+5 -13
View File
@@ -3,34 +3,26 @@
#include "../voxels/FlatWorldGenerator.h"
#include "../content/Content.h"
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <function>
std::map<std::string, std::function> generators;
template <typename T>
void WorldGenerators::addGenerator(std::string id) {
using create_func = std::function<T*>(const Content*);
generators[id] = create_func
}
std::vector<std::string> WorldGenerators::getGeneratorsIDs() {
std::vector<std::string> ids;
for(std::map<std::string, std::function>::iterator it = generators.begin(); it != generators.end(); ++it) {
for(std::map<std::string, gen_constructor>::iterator it = generators.begin(); it != generators.end(); ++it) {
ids.push_back(it->first);
}
return ids;
}
std::string WorldGenerators::getDefaultWorldGeneratorID() {
std::string WorldGenerators::getDefaultGeneratorID() {
return "core:default";
}
WorldGenerator* WorldGenerators::createWorldGenerator(std::string id, const Content* content) {
for(std::map<std::string, std::function>::iterator it = generators.begin(); it != generators.end(); ++it) {
WorldGenerator* WorldGenerators::createGenerator(std::string id, const Content* content) {
for(std::map<std::string, gen_constructor>::iterator it = generators.begin(); it != generators.end(); ++it) {
if(id == it->first) {
return (WorldGenerator*) it->second(content);
}
+18 -3
View File
@@ -1,14 +1,20 @@
#ifndef WORLD_WORLDTYPES_H_
#define WORLD_WORLDTYPES_H_
#ifndef WORLD_WORLDGENERATORS_H_
#define WORLD_WORLDGENERATORS_H_
#include "../voxels/WorldGenerator.h"
#include "../content/Content.h"
#include <map>
#include <vector>
#include <string>
typedef WorldGenerator* (*gen_constructor) (const Content*);
class WorldGenerators {
static inline std::map<std::string, gen_constructor> generators = *(new std::map<std::string, gen_constructor>);
public:
template <typename T>
static void addGenerator(std::string id);
static std::vector<std::string> getGeneratorsIDs();
@@ -18,4 +24,13 @@ public:
static WorldGenerator* createGenerator(std::string id, const Content* content);
};
#endif /* WORLD_WORLDTYPES_H_ */
template <typename T>
void WorldGenerators::addGenerator(std::string id) {
generators[id] =
[] (const Content* content)
{
return (WorldGenerator*) new T(content);
};
}
#endif /* WORLD_WORLDGENERATORS_H_ */