#ifndef WORLD_LEVEL_H_ #define WORLD_LEVEL_H_ #include "../settings.h" #include "../interfaces/Object.h" #include #include 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; class Player; class Chunks; class Inventory; class Inventories; class LevelEvents; class Lighting; class PhysicsSolver; class ChunksStorage; /// @brief A level, contains chunks and objects class Level { public: std::unique_ptr world; const Content* const content; std::vector> objects; std::unique_ptr chunks; std::unique_ptr chunksStorage; std::unique_ptr inventories; std::unique_ptr physics; std::unique_ptr lighting; std::unique_ptr events; const EngineSettings& settings; Level(World* world, const Content* content, EngineSettings& settings); ~Level(); 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 std::shared_ptr spawnObject(Args&&... args) { static_assert(std::is_base_of::value, "T must be a derived of Object class"); std::shared_ptr tObj = std::make_shared(args...); std::shared_ptr obj = std::dynamic_pointer_cast(tObj); obj->objectUID = objects.size(); objects.push_back(obj); obj->spawned(); return tObj; } template std::shared_ptr getObject(uint64_t id) { static_assert(std::is_base_of::value, "T must be a derived of Object class"); if (id >= objects.size()) return nullptr; std::shared_ptr object = std::dynamic_pointer_cast(objects[id]); return object; } }; #endif /* WORLD_LEVEL_H_ */