game2006/server/gameserver/mapinstance.h
aozhiwei dc1b5a00e8 1
2023-01-31 14:26:36 +08:00

85 lines
2.3 KiB
C++

#pragma once
#include "DetourNavMesh.h"
#include "DetourNavMeshQuery.h"
const int MAX_POLYS = 256;
struct HeightInfo
{
int t = 0;
int h = 0;
};
struct GridInfo
{
bool is_perfect = false;
HeightInfo* layers = nullptr;
HeightInfo* details = nullptr;
};
class Entity;
class Obstacle;
class MapService;
class GridService;
class Room;
struct RoomInitInfo;
class MapInstance : public std::enable_shared_from_this<MapInstance>
{
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<int>& GetPolyExtDatas() { return poly_ext_datas_; };
Entity* GetEntityByUniId(int uniid);
dtNavMesh* GetNavMesh() { return navmesh_; };
dtNavMeshQuery* GetNavMeshQuery() { return navmesh_query_; };
int FindStraightPath(int layer,
const glm::vec3& start,
const glm::vec3& end,
std::vector<glm::vec3>& paths);
int FindRandomPointAroundCircle(int layer,
const glm::vec3& center_pos,
float max_radius,
glm::vec3& random_pt);
bool Raycast(int layer, const glm::vec3& start, const glm::vec3& end,
glm::vec3& hit_point, bool& hit_result);
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);
private:
void CreateThings();
int AllocUniid();
void MarkMapAreaPolys();
void LoadHeightData();
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<int, Entity*> uniid_hash_;
std::vector<int> poly_ext_datas_;
std::vector<HeightInfo> height_datas_;
std::string map_tpl_name_;
const mt::Map* map_meta_ = nullptr;
MapService* map_service_ = nullptr;
GridService* grid_service_ = nullptr;
};