#pragma once #include #include #include #include #include #include "game/transform_node.hpp" #include "model.hpp" #include "utils/aabb.hpp" namespace assets { struct MapStaticObject { game::TransformNode node; AABB3 aabb; std::shared_ptr model; glm::vec3 color = glm::vec3(1.0f); }; struct ChunkSurfaceRange { size_t idx = 0; size_t first = 0; size_t count = 0; ChunkSurfaceRange(size_t idx, size_t first, size_t count) : idx(idx), first(first), count(count) {} }; struct Chunk { AABB3 aabb; std::vector surfaces; size_t first_obj = 0; size_t num_objs = 0; }; struct MapGraphNode { glm::vec3 position = glm::vec3(0.0f); size_t num_nbs = 0; size_t nbs = 0; }; struct MapGraph { std::vector nodes; std::vector nbs; }; class Map { public: Map() = default; static std::shared_ptr LoadFromFile(const std::string& filename); const std::shared_ptr& GetBaseModel() const { return basemodel_; } const std::vector& GetChunks() const { return chunks_; } const std::vector& GetStaticObjects() const { return objs_; } const MapGraph* GetGraph(const std::string& name) const; private: std::shared_ptr basemodel_; std::vector chunks_; std::vector objs_; std::map graphs_; friend class MapLoader; }; enum MapLoadingState { ML_INIT, ML_READ_MODELS, ML_LOAD_BASEMODEL, ML_LOAD_MODELS, ML_STRUCTS, ML_FINISHED, }; class MapLoader { public: MapLoader(const std::string& filename); bool Next(); int GetPercent() const; std::shared_ptr GetMap() const; private: void ReadModels(); void LoadBaseModel(); bool LoadNextModel(); void LoadStructs(); private: std::istringstream map_iss_; MapLoadingState state_ = ML_INIT; std::string basemodel_name_; std::vector model_names_; std::vector> models_; std::shared_ptr map_; }; } // namespace assets