contentpack removal feature + refactor
This commit is contained in:
+9
-9
@@ -13,19 +13,20 @@
|
||||
#include "../items/Inventories.h"
|
||||
|
||||
Level::Level(World* world, const Content* content, EngineSettings& settings)
|
||||
: world(world),
|
||||
content(content),
|
||||
chunksStorage(std::make_unique<ChunksStorage>(this)),
|
||||
physics(std::make_unique<PhysicsSolver>(glm::vec3(0, -22.6f, 0))),
|
||||
events(std::make_unique<LevelEvents>()),
|
||||
settings(settings)
|
||||
: world(world),
|
||||
content(content),
|
||||
chunksStorage(std::make_unique<ChunksStorage>(this)),
|
||||
physics(std::make_unique<PhysicsSolver>(glm::vec3(0, -22.6f, 0))),
|
||||
events(std::make_unique<LevelEvents>()),
|
||||
settings(settings)
|
||||
{
|
||||
auto inv = std::make_shared<Inventory>(world->getNextInventoryId(), DEF_PLAYER_INVENTORY_SIZE);
|
||||
auto player = spawnObject<Player>(glm::vec3(0, DEF_PLAYER_Y, 0), DEF_PLAYER_SPEED, inv);
|
||||
|
||||
uint matrixSize = (settings.chunks.loadDistance + settings.chunks.padding) * 2;
|
||||
chunks = std::make_unique<Chunks>(matrixSize, matrixSize, 0, 0,
|
||||
world->wfile.get(), events.get(), content);
|
||||
chunks = std::make_unique<Chunks>(
|
||||
matrixSize, matrixSize, 0, 0, world->wfile.get(), events.get(), content
|
||||
);
|
||||
lighting = std::make_unique<Lighting>(content, chunks.get());
|
||||
|
||||
events->listen(EVT_CHUNK_HIDDEN, [this](lvl_event_type type, Chunk* chunk) {
|
||||
@@ -53,4 +54,3 @@ void Level::loadMatrix(int32_t x, int32_t z, uint32_t radius) {
|
||||
World* Level::getWorld() {
|
||||
return world.get();
|
||||
}
|
||||
|
||||
|
||||
+19
-21
@@ -1,15 +1,15 @@
|
||||
#ifndef WORLD_LEVEL_H_
|
||||
#define WORLD_LEVEL_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "../settings.h"
|
||||
#include "../interfaces/Object.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
const float DEF_PLAYER_Y = 100.0f;
|
||||
const float DEF_PLAYER_SPEED = 4.0f;
|
||||
const int DEF_PLAYER_INVENTORY_SIZE = 40;
|
||||
inline constexpr float DEF_PLAYER_Y = 100.0f;
|
||||
inline constexpr float DEF_PLAYER_SPEED = 4.0f;
|
||||
inline constexpr int DEF_PLAYER_INVENTORY_SIZE = 40;
|
||||
|
||||
class Content;
|
||||
class World;
|
||||
@@ -22,36 +22,34 @@ class Lighting;
|
||||
class PhysicsSolver;
|
||||
class ChunksStorage;
|
||||
|
||||
/* A level, contains chunks and objects */
|
||||
/// @brief A level, contains chunks and objects
|
||||
class Level {
|
||||
public:
|
||||
std::unique_ptr<World> world;
|
||||
const Content* const content;
|
||||
std::vector<std::shared_ptr<Object>> objects;
|
||||
std::unique_ptr<World> world;
|
||||
const Content* const content;
|
||||
std::vector<std::shared_ptr<Object>> objects;
|
||||
std::unique_ptr<Chunks> chunks;
|
||||
std::unique_ptr<ChunksStorage> chunksStorage;
|
||||
std::unique_ptr<Inventories> inventories;
|
||||
std::unique_ptr<Inventories> inventories;
|
||||
|
||||
std::unique_ptr<PhysicsSolver> physics;
|
||||
std::unique_ptr<Lighting> lighting;
|
||||
std::unique_ptr<LevelEvents> events;
|
||||
|
||||
const EngineSettings& settings;
|
||||
const EngineSettings& settings;
|
||||
|
||||
Level(World* world,
|
||||
const Content* content,
|
||||
EngineSettings& settings);
|
||||
~Level();
|
||||
Level(World* world, const Content* content, EngineSettings& settings);
|
||||
~Level();
|
||||
|
||||
void loadMatrix(int32_t x, int32_t z, uint32_t radius);
|
||||
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>
|
||||
std::shared_ptr<T> spawnObject(Args&&... args) {
|
||||
/// 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>
|
||||
std::shared_ptr<T> spawnObject(Args&&... args) {
|
||||
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...);
|
||||
|
||||
|
||||
+69
-80
@@ -27,7 +27,7 @@ public:
|
||||
world_load_error(std::string message);
|
||||
};
|
||||
|
||||
/* World - holds all world data except the level (chunks and objects) */
|
||||
/// @brief holds all world data except the level (chunks and objects)
|
||||
class World : Serializable {
|
||||
std::string name;
|
||||
std::string generator;
|
||||
@@ -40,116 +40,105 @@ class World : Serializable {
|
||||
public:
|
||||
std::unique_ptr<WorldFiles> wfile;
|
||||
|
||||
/**
|
||||
* Day/night loop timer in range 0..1
|
||||
* 0.0 - is midnight
|
||||
* 0.5 - is noon
|
||||
*/
|
||||
/// @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/60.0f/24.0f;
|
||||
|
||||
/// @brief total time passed in the world (not depending on daytimeSpeed)
|
||||
double totalTime = 0.0;
|
||||
|
||||
World(std::string name,
|
||||
std::string generator,
|
||||
fs::path directory,
|
||||
uint64_t seed,
|
||||
EngineSettings& settings,
|
||||
const Content* content,
|
||||
std::vector<ContentPack> packs);
|
||||
World(
|
||||
std::string name,
|
||||
std::string generator,
|
||||
fs::path directory,
|
||||
uint64_t seed,
|
||||
EngineSettings& settings,
|
||||
const Content* content,
|
||||
std::vector<ContentPack> packs
|
||||
);
|
||||
|
||||
~World();
|
||||
|
||||
/**
|
||||
* Update world day-time and total time
|
||||
* @param delta delta-time
|
||||
*/
|
||||
/// @brief Update world day-time and total time
|
||||
/// @param delta delta-time
|
||||
void updateTimers(float delta);
|
||||
|
||||
/**
|
||||
* Write all unsaved level data to the world directory
|
||||
*/
|
||||
/// @brief Write all unsaved level data to the world directory
|
||||
void write(Level* level);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
/// @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
|
||||
static ContentLUT* checkIndices(const fs::path& directory, const Content* content);
|
||||
|
||||
/**
|
||||
* Create new world
|
||||
* @param name internal world name
|
||||
* @param directory root world directory
|
||||
* @param type of the world
|
||||
* @param seed world generation seed
|
||||
* @param settings current engine settings
|
||||
* @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
|
||||
*/
|
||||
static Level* create(std::string name,
|
||||
std::string generator,
|
||||
fs::path directory,
|
||||
uint64_t seed,
|
||||
EngineSettings& settings,
|
||||
const Content* content,
|
||||
const std::vector<ContentPack>& packs);
|
||||
|
||||
/**
|
||||
* Load an existing world
|
||||
* @param directory root world directory
|
||||
* @param settings current engine settings
|
||||
* @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
|
||||
* @throws world_load_error on world.json load error
|
||||
*/
|
||||
static Level* load(fs::path directory,
|
||||
EngineSettings& settings,
|
||||
const Content* content,
|
||||
const std::vector<ContentPack>& packs);
|
||||
/// @brief Create new world
|
||||
/// @param name internal world name
|
||||
/// @param directory root world directory
|
||||
/// @param type of the world
|
||||
/// @param seed world generation seed
|
||||
/// @param settings current engine settings
|
||||
/// @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
|
||||
static Level* create(
|
||||
std::string name,
|
||||
std::string generator,
|
||||
fs::path directory,
|
||||
uint64_t seed,
|
||||
EngineSettings& settings,
|
||||
const Content* content,
|
||||
const std::vector<ContentPack>& packs
|
||||
);
|
||||
|
||||
/// @brief Load an existing world
|
||||
/// @param directory root world directory
|
||||
/// @param settings current engine settings
|
||||
/// @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
|
||||
/// @throws world_load_error on world.json load error
|
||||
static Level* load(
|
||||
fs::path directory,
|
||||
EngineSettings& settings,
|
||||
const Content* content,
|
||||
const std::vector<ContentPack>& packs
|
||||
);
|
||||
|
||||
void setName(const std::string& name);
|
||||
void setSeed(uint64_t seed);
|
||||
void setGenerator(const std::string& generator);
|
||||
|
||||
/**
|
||||
* Check if world has content-pack installed
|
||||
* @param id content-pack id
|
||||
*/
|
||||
/// @brief Check if world has content-pack installed
|
||||
/// @param id content-pack id
|
||||
bool hasPack(const std::string& id) const;
|
||||
|
||||
/**
|
||||
* Get internal world name (not the folder name)
|
||||
* @return name stored in world.json
|
||||
*/
|
||||
/// @brief Get internal world name (not the folder name)
|
||||
/// @return name stored in world.json
|
||||
std::string getName() const;
|
||||
|
||||
/** Get world generation seed */
|
||||
/// @brief Get world generation seed
|
||||
uint64_t getSeed() const;
|
||||
|
||||
/** Get world generator id */
|
||||
/// @brief Get world generator id
|
||||
std::string getGenerator() const;
|
||||
/**
|
||||
* Get vector of all content-packs installed in world
|
||||
*/
|
||||
|
||||
/// @brief Get vector of all content-packs installed in world
|
||||
const std::vector<ContentPack>& getPacks() const;
|
||||
|
||||
/**
|
||||
* Get next inventory id and increment it's counter
|
||||
* @return integer >= 1
|
||||
*/
|
||||
/// @brief Get next inventory id and increment it's counter
|
||||
/// @return integer >= 1
|
||||
int64_t getNextInventoryId() {
|
||||
return nextInventoryId++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current world Content instance
|
||||
*/
|
||||
/// @brief Get current world Content instance
|
||||
const Content* getContent() const {
|
||||
return content;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user