mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-09 21:11:50 +00:00
One step closer to multiplayer
This commit is contained in:
parent
9d9c9f5570
commit
0157213a56
26 changed files with 213 additions and 219 deletions
|
|
@ -3,16 +3,13 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
#include "../typedefs.h"
|
||||
#include "../settings.h"
|
||||
#include <list>
|
||||
#include "../interfaces/Object.h"
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
|
||||
class Content;
|
||||
class World;
|
||||
class Player;
|
||||
class Object;
|
||||
class Chunks;
|
||||
class Inventory;
|
||||
class Inventories;
|
||||
|
|
@ -21,21 +18,19 @@ class Lighting;
|
|||
class PhysicsSolver;
|
||||
class ChunksStorage;
|
||||
|
||||
/* A level, contains chunks and objects */
|
||||
class Level {
|
||||
private:
|
||||
int objCounter;
|
||||
public:
|
||||
std::unique_ptr<World> world;
|
||||
const Content* const content;
|
||||
std::list<std::shared_ptr<Object>> objects;
|
||||
std::shared_ptr<Player> player;
|
||||
Chunks* chunks;
|
||||
ChunksStorage* chunksStorage;
|
||||
std::vector<std::shared_ptr<Object>> objects;
|
||||
std::unique_ptr<Chunks> chunks;
|
||||
std::unique_ptr<ChunksStorage> chunksStorage;
|
||||
std::unique_ptr<Inventories> inventories;
|
||||
|
||||
PhysicsSolver* physics;
|
||||
Lighting* lighting;
|
||||
LevelEvents* events;
|
||||
std::unique_ptr<PhysicsSolver> physics;
|
||||
std::unique_ptr<Lighting> lighting;
|
||||
std::unique_ptr<LevelEvents> events;
|
||||
|
||||
const EngineSettings& settings;
|
||||
|
||||
|
|
@ -44,7 +39,7 @@ public:
|
|||
EngineSettings& settings);
|
||||
~Level();
|
||||
|
||||
void update();
|
||||
void loadMatrix(int32_t x, int32_t z, uint32_t radius);
|
||||
|
||||
World* getWorld();
|
||||
|
||||
|
|
@ -52,7 +47,24 @@ public:
|
|||
// @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);
|
||||
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...);
|
||||
|
||||
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>
|
||||
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");
|
||||
if (id >= objects.size()) return nullptr;
|
||||
std::shared_ptr<T> object = std::dynamic_pointer_cast<T>(objects[id]);
|
||||
return object;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* WORLD_LEVEL_H_ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue