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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 95 additions and 39 deletions

View File

@ -25,6 +25,9 @@ world.Seed=Зерне
world.Name=Назва
menu.Create World=Стварыць Свет
world.World generator=Генератар свету
world.generators.default=Звычайны
world.generators.flat=Плоскі
world.convert-request=Ёсць змены ў індэксах! Канвертаваць свет?
world.delete-confirm=Выдаліць свет незваротна?

View File

@ -4,6 +4,8 @@ world.convert-request=Content indices have changed! Convert world files?
error.pack-not-found=Could not to find pack
error.dependency-not-found=Dependency pack is not found
world.delete-confirm=Do you want to delete world forever?
world.generators.default=Default
world.generators.flat=Flat
# Bindings
movement.forward=Forward

View File

@ -23,6 +23,9 @@ menu.Seed=Siemen
menu.Name=Nimi
menu.Create World=Luo Maailma
world.World generator=Valon generaattori
world.generators.default=Äärimmäinen
world.generators.flat=Tasainen
world.convert-request=Indeksit vaihdettu! Lataa maailma uudeleen?
world.delete-confirm=Poistetaanko maailma ikuisesti?

View File

@ -22,6 +22,9 @@ world.Seed=Ziarno
world.Name=Nazwa
menu.Create World=Stwórz świat
world.World generator=Generator światła
world.generators.default=Ekstremalne
world.generators.flat=Mieszkanie
world.convert-request=Szykują się zmiany w indeksach! Przekształcić świat?
# Ustawienia

View File

@ -23,6 +23,10 @@ menu.Settings=Настройки
menu.Content=Контент
world.Seed=Зерно
world.Name=Название
world.World generator=Генератор мира
world.generators.default=Обычный
world.generators.flat=Плоский
menu.Create World=Создать Мир
world.convert-request=Есть изменения в индексах! Конвертировать мир?

View File

@ -22,6 +22,9 @@ world.Seed=Зерно
world.Name=Назва
menu.Create World=Створити Світ
world.World generator=Генератор світла
world.generators.default=Звичайні
world.generators.flat=Плоскі
world.convert-request=Є зміни в індексах! Конвертувати світ?
# Налаштування

View File

@ -7,6 +7,7 @@
#include <glm/glm.hpp>
#include <filesystem>
#include <unordered_set>
#include <functional>
#define GLEW_STATIC
#include "audio/Audio.h"
@ -44,6 +45,11 @@
namespace fs = std::filesystem;
void addWorldGenerators() {
WorldGenerators::addGenerator<DefaultWorldGenerator>("core:default");
WorldGenerators::addGenerator<FlatWorldGenerator>("core:flat");
}
Engine::Engine(EngineSettings& settings, EnginePaths* paths)
: settings(settings), paths(paths)
{
@ -86,11 +92,6 @@ Engine::Engine(EngineSettings& settings, EnginePaths* paths)
addWorldGenerators();
}
void addWorldGenerators() {
WorldGenerators::addWorldGenerator<DefaultWorldGenerator>("core:default");
WorldGenerators::addWorldGenerator<FlatWorldGenerator>("core:flat");
}
void Engine::updateTimers() {
frame++;
double currentTime = Window::time();

View File

@ -186,6 +186,18 @@ void create_languages_panel(Engine* engine) {
panel->add(guiutil::backButton(menu));
}
std::string translate_generator_id(std::string& id) {
int delimiterPosition = id.find(":");
std::string pack = id.substr(0, delimiterPosition);
std::string generator = id.substr(delimiterPosition + 1);
if(pack == "core") {
return util::wstr2str_utf8(langs::get(util::str2wstr_utf8(generator), L"world.generators"));
} else {
return id;
}
}
void create_world_generators_panel(Engine* engine) {
auto menu = engine->getGUI()->getMenu();
auto panel = create_page(engine, "world_generators", 400, 0.5f, 1);
@ -193,13 +205,30 @@ void create_world_generators_panel(Engine* engine) {
std::vector<std::string> generatorsIDs = WorldGenerators::getGeneratorsIDs();
std::sort(generatorsIDs.begin(), generatorsIDs.end());
for (std::string& type : generatorsIDs) {
const std::string& fullName = util::wstr2str_utf8(langs::get(util::str2wstr_utf8(type), L"world.generators"));
auto button = std::make_shared<Button>(
for (std::string& id : generatorsIDs) {
const std::string& fullName = translate_generator_id(id);
/*auto button = std::make_shared<Button>(
util::str2wstr_utf8(fullName),
vec4(10.f),
[=](GUI*) {
menus::generatorID = type;
menus::generatorID = id;
menu->back();
}
);*/
auto button = std::make_shared<RichButton>(vec2(80, 30));
auto idlabel = std::make_shared<Label>("["+id+"]");
idlabel->setColor(vec4(1, 1, 1, 0.5f));
idlabel->setSize(vec2(300, 25));
idlabel->setAlign(Align::right);
button->add(idlabel, vec2(80, 4));
button->add(std::make_shared<Label>(fullName), vec2(0, 8));
button->listenAction(
[=](GUI*) {
menus::generatorID = id;
menu->back();
}
);
@ -497,7 +526,7 @@ void create_new_world_panel(Engine* engine) {
engine->getContent(),
engine->getContentPacks()
);
menus::generatorID = WorldGenerators::getDefaultWorldGeneratorID();
menus::generatorID = WorldGenerators::getDefaultGeneratorID();
engine->setScreen(std::make_shared<LevelScreen>(engine, level));
}));
panel->add(guiutil::backButton(engine->getGUI()->getMenu()));
@ -684,7 +713,7 @@ void create_pause_panel(Engine* engine) {
}
void menus::create_menus(Engine* engine) {
menus::generatorID = WorldGenerators::getDefaultWorldGeneratorID();
menus::generatorID = WorldGenerators::getDefaultGeneratorID();
create_new_world_panel(engine);
create_settings_panel(engine);
create_controls_panel(engine);

View File

@ -27,7 +27,7 @@ ChunksController::ChunksController(Level* level, uint padding)
chunks(level->chunks),
lighting(level->lighting),
padding(padding),
generator(WorldGenerators::createWorldGenerator(level->getWorld()->getGenerator(), level->content)) {
generator(WorldGenerators::createGenerator(level->getWorld()->getGenerator(), level->content)) {
}
ChunksController::~ChunksController(){

View File

@ -1,5 +1,4 @@
#include "DefaultWorldGenerator.h"
#include "WorldGenerator.h"
#include "voxel.h"
#include "Chunk.h"
#include "Block.h"
@ -120,7 +119,7 @@ int generate_tree(fnl_state *noise,
return 0;
}
void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
void DefaultWorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
const int treesTile = 12;
fnl_state noise = fnlCreateState();
noise.noise_type = FNL_NOISE_OPENSIMPLEX2;

View File

@ -1,18 +1,18 @@
#ifndef VOXELS_WORLDGENERATOR_H_
#define VOXELS_WORLDGENERATOR_H_
#ifndef VOXELS_DEFAULTWORLDGENERATOR_H_
#define VOXELS_DEFAULTWORLDGENERATOR_H_
#include "../typedefs.h"
#include "../voxels/WorldGenerator.h"
#include <string>
struct voxel;
class Content;
class DefaultWorldGenerator : WorldGenerator {
public:
DefaultWorldGenerator(const Content* content) : WorldGenerator(content) {}
void generate(voxel* voxels, int x, int z, int seed) override;
void generate(voxel* voxels, int x, int z, int seed);
};
#endif /* VOXELS_WORLDGENERATOR_H_ */
#endif /* VOXELS_DEFAULTWORLDGENERATOR_H_ */

View File

@ -12,7 +12,7 @@ public:
FlatWorldGenerator(const Content* content) : WorldGenerator(content) {}
void generate(voxel* voxels, int x, int z, int seed) override;
void generate(voxel* voxels, int x, int z, int seed);
};
#endif /* VOXELS_FLATWORLDGENERATOR_H_ */

View File

@ -1,4 +1,7 @@
#include "WorldGenerator.h"
#include "voxel.h"
#include "Chunk.h"
#include "Block.h"
#include "../content/Content.h"

View File

@ -22,7 +22,7 @@ protected:
public:
WorldGenerator(const Content* content);
virtual void generate(voxel* voxels, int x, int z, int seed);
virtual void generate(voxel* voxels, int x, int z, int seed) = 0;
};
#endif /* VOXELS_WORLDGENERATOR_H_ */

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;
}

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);
}

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_ */