#pragma once #include "DetourNavMesh.h" #include "DetourNavMeshQuery.h" const int MAX_POLYS = 256; namespace mc { class ColliderNode; }; struct HouseInfo { mc::ColliderNode* node = nullptr; std::vector verts; }; class Entity; class Obstacle; class MapService; class GridService; class Room; struct RoomInitInfo; class MapInstance : public std::enable_shared_from_this { public: int map_id = 0; void Init(); void UnInit(); void AttachRoom(Room* room, RoomInitInfo& init_info); const mt::Map* GetMapMeta() { return map_meta_; }; std::vector& GetPolyExtDatas() { return poly_ext_datas_; }; Entity* GetEntityByUniId(int uniid); dtNavMesh* GetNavMesh() { return navmesh_; }; dtNavMeshQuery* GetNavMeshQuery() { return navmesh_query_; }; int FindStraightPath(const glm::vec3& start, const glm::vec3& end, std::vector& paths); int FindRandomPointAroundCircle(const glm::vec3& center_pos, float max_radius, glm::vec3& random_pt); bool Raycast(const glm::vec3& start, const glm::vec3& end, glm::vec3& hit_point, bool& hit_result); bool RaycastEx(const glm::vec3& start, const glm::vec3& end, glm::vec3& hit_point, bool& hit_result, int& same_polys_flags, std::vector& spec_polys); bool FindNearestPoint(const glm::vec3& center, float radius, glm::vec3& nearestPt); bool GetPosHeight(const Position& pos, float& out_height); dtPoly* GetPoly(glm::vec3 pos, int& poly_idx); void Scale(glm::vec3& v); void UnScale(glm::vec3& v); glm::vec3 UnScaleEx(const glm::vec3& v); void CheckTerrain(Creature* c, int same_poly_flags, const std::vector& spec_polys); void TraverseHouseList(std::function func); bool PtInHouse(const glm::vec3& pt, glm::vec3& nearest_pt); bool SceneRaycast(const glm::vec3& orig, const glm::vec3& dir, float max_distance, glm::vec3& hit_pos, float& ray_length); private: void CreateThings(); void LoadHouse(); int AllocUniid(); void MarkMapAreaPolys(); private: dtNavMesh* navmesh_ = nullptr; dtNavMeshQuery* navmesh_query_ = nullptr; float hit_normal_[3]; float hit_pos_[3]; dtPolyRef polys_[MAX_POLYS]; int current_uniid_ = 0; std::map uniid_hash_; std::vector poly_ext_datas_; std::list houses_; std::vector things_; std::string map_tpl_name_; const mt::Map* map_meta_ = nullptr; MapService* map_service_ = nullptr; GridService* grid_service_ = nullptr; };