Merge branch 'main' into devtools
This commit is contained in:
@@ -33,8 +33,10 @@ ContentLUT::ContentLUT(const Content* content, size_t blocksCount, size_t itemsC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentLUT* ContentLUT::create(const fs::path& filename,
|
std::shared_ptr<ContentLUT> ContentLUT::create(
|
||||||
const Content* content) {
|
const fs::path& filename,
|
||||||
|
const Content* content
|
||||||
|
) {
|
||||||
auto root = files::read_json(filename);
|
auto root = files::read_json(filename);
|
||||||
auto blocklist = root->list("blocks");
|
auto blocklist = root->list("blocks");
|
||||||
auto itemlist = root->list("items");
|
auto itemlist = root->list("items");
|
||||||
@@ -47,7 +49,7 @@ ContentLUT* ContentLUT::create(const fs::path& filename,
|
|||||||
? std::max(itemlist->size(), indices->countItemDefs())
|
? std::max(itemlist->size(), indices->countItemDefs())
|
||||||
: indices->countItemDefs();
|
: indices->countItemDefs();
|
||||||
|
|
||||||
auto lut = std::make_unique<ContentLUT>(content, blocks_c, items_c);
|
auto lut = std::make_shared<ContentLUT>(content, blocks_c, items_c);
|
||||||
|
|
||||||
if (blocklist) {
|
if (blocklist) {
|
||||||
for (size_t i = 0; i < blocklist->size(); i++) {
|
for (size_t i = 0; i < blocklist->size(); i++) {
|
||||||
@@ -74,7 +76,7 @@ ContentLUT* ContentLUT::create(const fs::path& filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (lut->hasContentReorder() || lut->hasMissingContent()) {
|
if (lut->hasContentReorder() || lut->hasMissingContent()) {
|
||||||
return lut.release();
|
return lut;
|
||||||
} else {
|
} else {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static ContentLUT* create(
|
static std::shared_ptr<ContentLUT> create(
|
||||||
const fs::path& filename,
|
const fs::path& filename,
|
||||||
const Content* content
|
const Content* content
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using namespace debug;
|
using namespace debug;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
namespace debug {
|
namespace debug {
|
||||||
|
|||||||
@@ -74,7 +74,8 @@ void langs::loadLocalesInfo(const fs::path& resdir, std::string& fallback) {
|
|||||||
|
|
||||||
auto langs = root->map("langs");
|
auto langs = root->map("langs");
|
||||||
if (langs) {
|
if (langs) {
|
||||||
std::cout << "locales ";
|
auto logline = logger.info();
|
||||||
|
logline << "locales ";
|
||||||
for (auto& entry : langs->values) {
|
for (auto& entry : langs->values) {
|
||||||
auto langInfo = entry.second;
|
auto langInfo = entry.second;
|
||||||
|
|
||||||
@@ -84,10 +85,10 @@ void langs::loadLocalesInfo(const fs::path& resdir, std::string& fallback) {
|
|||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std::cout << "[" << entry.first << " (" << name << ")] ";
|
logline << "[" << entry.first << " (" << name << ")] ";
|
||||||
langs::locales_info[entry.first] = LocaleInfo {entry.first, name};
|
langs::locales_info[entry.first] = LocaleInfo {entry.first, name};
|
||||||
}
|
}
|
||||||
std::cout << "added" << std::endl;
|
logline << "added";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,17 +98,17 @@ std::string langs::locale_by_envlocale(const std::string& envlocale, const fs::p
|
|||||||
loadLocalesInfo(resdir, fallback);
|
loadLocalesInfo(resdir, fallback);
|
||||||
}
|
}
|
||||||
if (locales_info.find(envlocale) != locales_info.end()) {
|
if (locales_info.find(envlocale) != locales_info.end()) {
|
||||||
std::cout << "locale " << envlocale << " is automatically selected" << std::endl;
|
logger.info() << "locale " << envlocale << " is automatically selected";
|
||||||
return envlocale;
|
return envlocale;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (const auto& loc : locales_info) {
|
for (const auto& loc : locales_info) {
|
||||||
if (loc.first.find(envlocale.substr(0, 2)) != std::string::npos) {
|
if (loc.first.find(envlocale.substr(0, 2)) != std::string::npos) {
|
||||||
std::cout << "locale " << loc.first << " is automatically selected" << std::endl;
|
logger.info() << "locale " << loc.first << " is automatically selected";
|
||||||
return loc.first;
|
return loc.first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "locale " << fallback << " is automatically selected" << std::endl;
|
logger.info() << "locale " << fallback << " is automatically selected";
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
static debug::Logger logger("level-screen");
|
static debug::Logger logger("level-screen");
|
||||||
|
|
||||||
LevelScreen::LevelScreen(Engine* engine, Level* level)
|
LevelScreen::LevelScreen(Engine* engine, std::unique_ptr<Level> level)
|
||||||
: Screen(engine), postProcessing(std::make_unique<PostProcessing>())
|
: Screen(engine), postProcessing(std::make_unique<PostProcessing>())
|
||||||
{
|
{
|
||||||
auto& settings = engine->getSettings();
|
auto& settings = engine->getSettings();
|
||||||
@@ -32,7 +32,7 @@ LevelScreen::LevelScreen(Engine* engine, Level* level)
|
|||||||
auto menu = engine->getGUI()->getMenu();
|
auto menu = engine->getGUI()->getMenu();
|
||||||
menu->reset();
|
menu->reset();
|
||||||
|
|
||||||
controller = std::make_unique<LevelController>(settings, level);
|
controller = std::make_unique<LevelController>(settings, std::move(level));
|
||||||
frontend = std::make_unique<LevelFrontend>(controller.get(), assets);
|
frontend = std::make_unique<LevelFrontend>(controller.get(), assets);
|
||||||
|
|
||||||
worldRenderer = std::make_unique<WorldRenderer>(engine, frontend.get(), controller->getPlayer());
|
worldRenderer = std::make_unique<WorldRenderer>(engine, frontend.get(), controller->getPlayer());
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class LevelScreen : public Screen {
|
|||||||
void updateHotkeys();
|
void updateHotkeys();
|
||||||
void initializeContent();
|
void initializeContent();
|
||||||
public:
|
public:
|
||||||
LevelScreen(Engine* engine, Level* level);
|
LevelScreen(Engine* engine, std::unique_ptr<Level> level);
|
||||||
~LevelScreen();
|
~LevelScreen();
|
||||||
|
|
||||||
void update(float delta) override;
|
void update(float delta) override;
|
||||||
|
|||||||
@@ -28,4 +28,4 @@ public:
|
|||||||
void solve();
|
void solve();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* LIGHTING_LIGHTSOLVER_HPP_ */
|
#endif // LIGHTING_LIGHTSOLVER_HPP_
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "Lighting.hpp"
|
#include "Lighting.hpp"
|
||||||
#include "LightSolver.hpp"
|
#include "LightSolver.hpp"
|
||||||
#include "Lightmap.hpp"
|
#include "Lightmap.hpp"
|
||||||
@@ -9,9 +7,10 @@
|
|||||||
#include "../voxels/voxel.hpp"
|
#include "../voxels/voxel.hpp"
|
||||||
#include "../voxels/Block.hpp"
|
#include "../voxels/Block.hpp"
|
||||||
#include "../constants.hpp"
|
#include "../constants.hpp"
|
||||||
#include "../typedefs.hpp"
|
|
||||||
#include "../util/timeutil.hpp"
|
#include "../util/timeutil.hpp"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
Lighting::Lighting(const Content* content, Chunks* chunks)
|
Lighting::Lighting(const Content* content, Chunks* chunks)
|
||||||
: content(content), chunks(chunks) {
|
: content(content), chunks(chunks) {
|
||||||
auto indices = content->getIndices();
|
auto indices = content->getIndices();
|
||||||
|
|||||||
@@ -87,4 +87,4 @@ public:
|
|||||||
static std::unique_ptr<light_t[]> decode(const ubyte* buffer);
|
static std::unique_ptr<light_t[]> decode(const ubyte* buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* LIGHTING_LIGHTMAP_HPP_ */
|
#endif // LIGHTING_LIGHTMAP_HPP_
|
||||||
|
|||||||
@@ -31,4 +31,4 @@ public:
|
|||||||
void update(int64_t maxDuration);
|
void update(int64_t maxDuration);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* VOXELS_CHUNKSCONTROLLER_HPP_ */
|
#endif // VOXELS_CHUNKSCONTROLLER_HPP_
|
||||||
|
|||||||
@@ -110,8 +110,8 @@ static void loadWorld(Engine* engine, fs::path folder) {
|
|||||||
auto& packs = engine->getContentPacks();
|
auto& packs = engine->getContentPacks();
|
||||||
auto& settings = engine->getSettings();
|
auto& settings = engine->getSettings();
|
||||||
|
|
||||||
Level* level = World::load(folder, settings, content, packs);
|
auto level = World::load(folder, settings, content, packs);
|
||||||
engine->setScreen(std::make_shared<LevelScreen>(engine, level));
|
engine->setScreen(std::make_shared<LevelScreen>(engine, std::move(level)));
|
||||||
} catch (const world_load_error& error) {
|
} catch (const world_load_error& error) {
|
||||||
guiutil::alert(
|
guiutil::alert(
|
||||||
engine->getGUI(), langs::get(L"Error")+L": "+
|
engine->getGUI(), langs::get(L"Error")+L": "+
|
||||||
@@ -197,13 +197,13 @@ void EngineController::createWorld(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Level* level = World::create(
|
auto level = World::create(
|
||||||
name, generatorID, folder, seed,
|
name, generatorID, folder, seed,
|
||||||
engine->getSettings(),
|
engine->getSettings(),
|
||||||
engine->getContent(),
|
engine->getContent(),
|
||||||
engine->getContentPacks()
|
engine->getContentPacks()
|
||||||
);
|
);
|
||||||
engine->setScreen(std::make_shared<LevelScreen>(engine, level));
|
engine->setScreen(std::make_shared<LevelScreen>(engine, std::move(level)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EngineController::reopenWorld(World* world) {
|
void EngineController::reopenWorld(World* world) {
|
||||||
|
|||||||
@@ -10,11 +10,11 @@
|
|||||||
|
|
||||||
static debug::Logger logger("level-control");
|
static debug::Logger logger("level-control");
|
||||||
|
|
||||||
LevelController::LevelController(EngineSettings& settings, Level* level)
|
LevelController::LevelController(EngineSettings& settings, std::unique_ptr<Level> level)
|
||||||
: settings(settings), level(level),
|
: settings(settings), level(std::move(level)),
|
||||||
blocks(std::make_unique<BlocksController>(level, settings.chunks.padding.get())),
|
blocks(std::make_unique<BlocksController>(this->level.get(), settings.chunks.padding.get())),
|
||||||
chunks(std::make_unique<ChunksController>(level, settings.chunks.padding.get())),
|
chunks(std::make_unique<ChunksController>(this->level.get(), settings.chunks.padding.get())),
|
||||||
player(std::make_unique<PlayerController>(level, settings, blocks.get())) {
|
player(std::make_unique<PlayerController>(this->level.get(), settings, blocks.get())) {
|
||||||
|
|
||||||
scripting::on_world_load(this);
|
scripting::on_world_load(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class LevelController {
|
|||||||
std::unique_ptr<ChunksController> chunks;
|
std::unique_ptr<ChunksController> chunks;
|
||||||
std::unique_ptr<PlayerController> player;
|
std::unique_ptr<PlayerController> player;
|
||||||
public:
|
public:
|
||||||
LevelController(EngineSettings& settings, Level* level);
|
LevelController(EngineSettings& settings, std::unique_ptr<Level> level);
|
||||||
|
|
||||||
/// @param delta time elapsed since the last update
|
/// @param delta time elapsed since the last update
|
||||||
/// @param input is user input allowed to be handled
|
/// @param input is user input allowed to be handled
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ const float RUN_ZOOM = 1.1f;
|
|||||||
const float C_ZOOM = 0.1f;
|
const float C_ZOOM = 0.1f;
|
||||||
const float CROUCH_SHIFT_Y = -0.2f;
|
const float CROUCH_SHIFT_Y = -0.2f;
|
||||||
|
|
||||||
|
|
||||||
CameraControl::CameraControl(std::shared_ptr<Player> player, const CameraSettings& settings)
|
CameraControl::CameraControl(std::shared_ptr<Player> player, const CameraSettings& settings)
|
||||||
: player(player),
|
: player(player),
|
||||||
camera(player->camera),
|
camera(player->camera),
|
||||||
@@ -136,7 +135,7 @@ void CameraControl::switchCamera() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraControl::update(PlayerInput& input, float delta, Chunks* chunks) {
|
void CameraControl::update(const PlayerInput& input, float delta, Chunks* chunks) {
|
||||||
offset = glm::vec3(0.0f, 0.7f, 0.0f);
|
offset = glm::vec3(0.0f, 0.7f, 0.0f);
|
||||||
|
|
||||||
if (settings.shaking.get() && !input.cheat) {
|
if (settings.shaking.get() && !input.cheat) {
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
#ifndef PLAYER_CONTROL_HPP_
|
#ifndef PLAYER_CONTROL_HPP_
|
||||||
#define PLAYER_CONTROL_HPP_
|
#define PLAYER_CONTROL_HPP_
|
||||||
|
|
||||||
|
#include "../settings.hpp"
|
||||||
|
#include "../objects/Player.hpp"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include "../settings.hpp"
|
|
||||||
#include "../objects/Player.hpp"
|
|
||||||
|
|
||||||
class Camera;
|
class Camera;
|
||||||
class Level;
|
class Level;
|
||||||
class Block;
|
class Block;
|
||||||
@@ -38,7 +38,7 @@ class CameraControl {
|
|||||||
public:
|
public:
|
||||||
CameraControl(std::shared_ptr<Player> player, const CameraSettings& settings);
|
CameraControl(std::shared_ptr<Player> player, const CameraSettings& settings);
|
||||||
void updateMouse(PlayerInput& input);
|
void updateMouse(PlayerInput& input);
|
||||||
void update(PlayerInput& input, float delta, Chunks* chunks);
|
void update(const PlayerInput& input, float delta, Chunks* chunks);
|
||||||
void refresh();
|
void refresh();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ using on_block_interaction = std::function<void(
|
|||||||
class PlayerController {
|
class PlayerController {
|
||||||
Level* level;
|
Level* level;
|
||||||
std::shared_ptr<Player> player;
|
std::shared_ptr<Player> player;
|
||||||
PlayerInput input;
|
PlayerInput input {};
|
||||||
CameraControl camControl;
|
CameraControl camControl;
|
||||||
BlocksController* blocksController;
|
BlocksController* blocksController;
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ static bool processCallback(
|
|||||||
try {
|
try {
|
||||||
return state->eval(*env, src, file) != 0;
|
return state->eval(*env, src, file) != 0;
|
||||||
} catch (lua::luaerror& err) {
|
} catch (lua::luaerror& err) {
|
||||||
std::cerr << err.what() << std::endl;
|
logger.error() << err.what();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace scripting {
|
namespace scripting {
|
||||||
using common_func = std::function<dynamic::Value(const std::vector<dynamic::Value>&)>;
|
using common_func = std::function<dynamic::Value(const std::vector<dynamic::Value>&)>;
|
||||||
|
|
||||||
|
|||||||
+7
-4
@@ -12,8 +12,11 @@
|
|||||||
#include "../items/Inventory.hpp"
|
#include "../items/Inventory.hpp"
|
||||||
#include "../items/Inventories.hpp"
|
#include "../items/Inventories.hpp"
|
||||||
|
|
||||||
Level::Level(World* world, const Content* content, EngineSettings& settings)
|
Level::Level(
|
||||||
: world(world),
|
std::unique_ptr<World> world,
|
||||||
|
const Content* content,
|
||||||
|
EngineSettings& settings
|
||||||
|
) : world(std::move(world)),
|
||||||
content(content),
|
content(content),
|
||||||
chunksStorage(std::make_unique<ChunksStorage>(this)),
|
chunksStorage(std::make_unique<ChunksStorage>(this)),
|
||||||
physics(std::make_unique<PhysicsSolver>(glm::vec3(0, -22.6f, 0))),
|
physics(std::make_unique<PhysicsSolver>(glm::vec3(0, -22.6f, 0))),
|
||||||
@@ -21,7 +24,7 @@ Level::Level(World* world, const Content* content, EngineSettings& settings)
|
|||||||
settings(settings)
|
settings(settings)
|
||||||
{
|
{
|
||||||
auto inv = std::make_shared<Inventory>(
|
auto inv = std::make_shared<Inventory>(
|
||||||
world->getNextInventoryId(), DEF_PLAYER_INVENTORY_SIZE
|
this->world->getNextInventoryId(), DEF_PLAYER_INVENTORY_SIZE
|
||||||
);
|
);
|
||||||
auto player = spawnObject<Player>(
|
auto player = spawnObject<Player>(
|
||||||
glm::vec3(0, DEF_PLAYER_Y, 0), DEF_PLAYER_SPEED, inv
|
glm::vec3(0, DEF_PLAYER_Y, 0), DEF_PLAYER_SPEED, inv
|
||||||
@@ -32,7 +35,7 @@ Level::Level(World* world, const Content* content, EngineSettings& settings)
|
|||||||
settings.chunks.padding.get()
|
settings.chunks.padding.get()
|
||||||
) * 2;
|
) * 2;
|
||||||
chunks = std::make_unique<Chunks>(
|
chunks = std::make_unique<Chunks>(
|
||||||
matrixSize, matrixSize, 0, 0, world->wfile.get(), events.get(), content
|
matrixSize, matrixSize, 0, 0, this->world->wfile.get(), events.get(), content
|
||||||
);
|
);
|
||||||
lighting = std::make_unique<Lighting>(content, chunks.get());
|
lighting = std::make_unique<Lighting>(content, chunks.get());
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -38,7 +38,11 @@ public:
|
|||||||
|
|
||||||
const EngineSettings& settings;
|
const EngineSettings& settings;
|
||||||
|
|
||||||
Level(World* world, const Content* content, EngineSettings& settings);
|
Level(
|
||||||
|
std::unique_ptr<World> world,
|
||||||
|
const Content* content,
|
||||||
|
EngineSettings& settings
|
||||||
|
);
|
||||||
~Level();
|
~Level();
|
||||||
|
|
||||||
void loadMatrix(int32_t x, int32_t z, uint32_t radius);
|
void loadMatrix(int32_t x, int32_t z, uint32_t radius);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ enum lvl_event_type {
|
|||||||
EVT_CHUNK_HIDDEN,
|
EVT_CHUNK_HIDDEN,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::function<void(lvl_event_type, Chunk*)> chunk_event_func;
|
using chunk_event_func = std::function<void(lvl_event_type, Chunk*)>;
|
||||||
|
|
||||||
class LevelEvents {
|
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;
|
||||||
|
|||||||
+28
-19
@@ -1,8 +1,10 @@
|
|||||||
#include "World.hpp"
|
#include "World.hpp"
|
||||||
|
|
||||||
#include "Level.hpp"
|
#include "Level.hpp"
|
||||||
|
|
||||||
#include "../content/Content.hpp"
|
#include "../content/Content.hpp"
|
||||||
#include "../content/ContentLUT.hpp"
|
#include "../content/ContentLUT.hpp"
|
||||||
|
#include "../debug/Logger.hpp"
|
||||||
#include "../files/WorldFiles.hpp"
|
#include "../files/WorldFiles.hpp"
|
||||||
#include "../items/Inventories.hpp"
|
#include "../items/Inventories.hpp"
|
||||||
#include "../objects/Player.hpp"
|
#include "../objects/Player.hpp"
|
||||||
@@ -13,9 +15,10 @@
|
|||||||
#include "../world/WorldGenerators.hpp"
|
#include "../world/WorldGenerators.hpp"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <iostream>
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
static debug::Logger logger("world");
|
||||||
|
|
||||||
world_load_error::world_load_error(std::string message)
|
world_load_error::world_load_error(std::string message)
|
||||||
: std::runtime_error(message) {
|
: std::runtime_error(message) {
|
||||||
}
|
}
|
||||||
@@ -65,18 +68,18 @@ void World::write(Level* level) {
|
|||||||
|
|
||||||
wfile->write(this, content);
|
wfile->write(this, content);
|
||||||
auto playerFile = dynamic::Map();
|
auto playerFile = dynamic::Map();
|
||||||
{
|
|
||||||
auto& players = playerFile.putList("players");
|
auto& players = playerFile.putList("players");
|
||||||
for (auto object : level->objects) {
|
for (auto object : level->objects) {
|
||||||
if (std::shared_ptr<Player> player = std::dynamic_pointer_cast<Player>(object)) {
|
if (auto player = std::dynamic_pointer_cast<Player>(object)) {
|
||||||
players.put(player->serialize());
|
players.put(player->serialize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
files::write_json(wfile->getPlayerFile(), &playerFile);
|
files::write_json(wfile->getPlayerFile(), &playerFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
Level* World::create(std::string name,
|
std::unique_ptr<Level> World::create(
|
||||||
|
std::string name,
|
||||||
std::string generator,
|
std::string generator,
|
||||||
fs::path directory,
|
fs::path directory,
|
||||||
uint64_t seed,
|
uint64_t seed,
|
||||||
@@ -84,15 +87,18 @@ Level* World::create(std::string name,
|
|||||||
const Content* content,
|
const Content* content,
|
||||||
const std::vector<ContentPack>& packs
|
const std::vector<ContentPack>& packs
|
||||||
) {
|
) {
|
||||||
auto world = new World(name, generator, directory, seed, settings, content, packs);
|
auto world = std::make_unique<World>(
|
||||||
auto level = new Level(world, content, settings);
|
name, generator, directory, seed, settings, content, packs
|
||||||
return level;
|
);
|
||||||
|
return std::make_unique<Level>(std::move(world), content, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
Level* World::load(fs::path directory,
|
std::unique_ptr<Level> World::load(
|
||||||
|
fs::path directory,
|
||||||
EngineSettings& settings,
|
EngineSettings& settings,
|
||||||
const Content* content,
|
const Content* content,
|
||||||
const std::vector<ContentPack>& packs) {
|
const std::vector<ContentPack>& packs
|
||||||
|
) {
|
||||||
auto world = std::make_unique<World>(
|
auto world = std::make_unique<World>(
|
||||||
".", WorldGenerators::getDefaultGeneratorID(), directory, 0, settings, content, packs
|
".", WorldGenerators::getDefaultGeneratorID(), directory, 0, settings, content, packs
|
||||||
);
|
);
|
||||||
@@ -102,18 +108,22 @@ Level* World::load(fs::path directory,
|
|||||||
throw world_load_error("could not to find world.json");
|
throw world_load_error("could not to find world.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto level = new Level(world.get(), content, settings);
|
auto level = std::make_unique<Level>(std::move(world), content, settings);
|
||||||
{
|
{
|
||||||
fs::path file = wfile->getPlayerFile();
|
fs::path file = wfile->getPlayerFile();
|
||||||
if (!fs::is_regular_file(file)) {
|
if (!fs::is_regular_file(file)) {
|
||||||
std::cerr << "warning: player.json does not exists" << std::endl;
|
logger.warning() << "player.json does not exists";
|
||||||
} else {
|
} else {
|
||||||
auto playerFile = files::read_json(file);
|
auto playerFile = files::read_json(file);
|
||||||
if (playerFile->has("players")) {
|
if (playerFile->has("players")) {
|
||||||
level->objects.clear();
|
level->objects.clear();
|
||||||
auto players = playerFile->list("players");
|
auto players = playerFile->list("players");
|
||||||
for (size_t i = 0; i < players->size(); i++) {
|
for (size_t i = 0; i < players->size(); i++) {
|
||||||
auto player = level->spawnObject<Player>(glm::vec3(0, DEF_PLAYER_Y, 0), DEF_PLAYER_SPEED, level->inventories->create(DEF_PLAYER_INVENTORY_SIZE));
|
auto player = level->spawnObject<Player>(
|
||||||
|
glm::vec3(0, DEF_PLAYER_Y, 0),
|
||||||
|
DEF_PLAYER_SPEED,
|
||||||
|
level->inventories->create(DEF_PLAYER_INVENTORY_SIZE)
|
||||||
|
);
|
||||||
player->deserialize(players->map(i));
|
player->deserialize(players->map(i));
|
||||||
level->inventories->store(player->getInventory());
|
level->inventories->store(player->getInventory());
|
||||||
}
|
}
|
||||||
@@ -128,8 +138,10 @@ Level* World::load(fs::path directory,
|
|||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentLUT* World::checkIndices(const fs::path& directory,
|
std::shared_ptr<ContentLUT> World::checkIndices(
|
||||||
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)) {
|
if (fs::is_regular_file(indicesFile)) {
|
||||||
return ContentLUT::create(indicesFile, content);
|
return ContentLUT::create(indicesFile, content);
|
||||||
@@ -178,10 +190,9 @@ void World::deserialize(dynamic::Map* root) {
|
|||||||
generator = root->get("generator", generator);
|
generator = root->get("generator", generator);
|
||||||
seed = root->get("seed", seed);
|
seed = root->get("seed", seed);
|
||||||
|
|
||||||
if(generator == "") {
|
if (generator == "") {
|
||||||
generator = WorldGenerators::getDefaultGeneratorID();
|
generator = WorldGenerators::getDefaultGeneratorID();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto verobj = root->map("version");
|
auto verobj = root->map("version");
|
||||||
if (verobj) {
|
if (verobj) {
|
||||||
int major=0, minor=-1;
|
int major=0, minor=-1;
|
||||||
@@ -189,14 +200,12 @@ void World::deserialize(dynamic::Map* root) {
|
|||||||
verobj->num("minor", minor);
|
verobj->num("minor", minor);
|
||||||
std::cout << "world version: " << major << "." << minor << std::endl;
|
std::cout << "world version: " << major << "." << minor << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto timeobj = root->map("time");
|
auto timeobj = root->map("time");
|
||||||
if (timeobj) {
|
if (timeobj) {
|
||||||
timeobj->num("day-time", daytime);
|
timeobj->num("day-time", daytime);
|
||||||
timeobj->num("day-time-speed", daytimeSpeed);
|
timeobj->num("day-time-speed", daytimeSpeed);
|
||||||
timeobj->num("total-time", totalTime);
|
timeobj->num("total-time", totalTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
nextInventoryId = root->get("next-inventory-id", 2);
|
nextInventoryId = root->get("next-inventory-id", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-7
@@ -12,13 +12,10 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
class Content;
|
class Content;
|
||||||
class WorldFiles;
|
class WorldFiles;
|
||||||
class Chunks;
|
|
||||||
class Level;
|
class Level;
|
||||||
class Player;
|
|
||||||
class ContentLUT;
|
class ContentLUT;
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
@@ -75,7 +72,9 @@ public:
|
|||||||
/// @param directory world directory
|
/// @param directory world directory
|
||||||
/// @param content current Content instance
|
/// @param content current Content instance
|
||||||
/// @return ContentLUT if world convert required else nullptr
|
/// @return ContentLUT if world convert required else nullptr
|
||||||
static ContentLUT* checkIndices(const fs::path& directory, const Content* content);
|
static std::shared_ptr<ContentLUT> checkIndices(
|
||||||
|
const fs::path& directory, const Content* content
|
||||||
|
);
|
||||||
|
|
||||||
/// @brief Create new world
|
/// @brief Create new world
|
||||||
/// @param name internal world name
|
/// @param name internal world name
|
||||||
@@ -87,7 +86,7 @@ public:
|
|||||||
/// with all world content-packs applied
|
/// with all world content-packs applied
|
||||||
/// @param packs vector of all world content-packs
|
/// @param packs vector of all world content-packs
|
||||||
/// @return Level instance containing World instance
|
/// @return Level instance containing World instance
|
||||||
static Level* create(
|
static std::unique_ptr<Level> create(
|
||||||
std::string name,
|
std::string name,
|
||||||
std::string generator,
|
std::string generator,
|
||||||
fs::path directory,
|
fs::path directory,
|
||||||
@@ -105,7 +104,7 @@ public:
|
|||||||
/// @param packs vector of all world content-packs
|
/// @param packs vector of all world content-packs
|
||||||
/// @return Level instance containing World instance
|
/// @return Level instance containing World instance
|
||||||
/// @throws world_load_error on world.json load error
|
/// @throws world_load_error on world.json load error
|
||||||
static Level* load(
|
static std::unique_ptr<Level> load(
|
||||||
fs::path directory,
|
fs::path directory,
|
||||||
EngineSettings& settings,
|
EngineSettings& settings,
|
||||||
const Content* content,
|
const Content* content,
|
||||||
@@ -148,4 +147,4 @@ public:
|
|||||||
void deserialize(dynamic::Map *src) override;
|
void deserialize(dynamic::Map *src) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* WORLD_WORLD_HPP_ */
|
#endif // WORLD_WORLD_HPP_
|
||||||
|
|||||||
Reference in New Issue
Block a user