game2006/server/gameserver/mapinstance.h
aozhiwei 640e2ebaaf 1
2023-02-09 20:18:33 +08:00

91 lines
2.7 KiB
C++

#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<float> verts;
};
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(const glm::vec3& start,
const glm::vec3& end,
std::vector<glm::vec3>& 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<dtPolyRef>& 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<dtPolyRef>& spec_polys);
void TraverseHouseList(std::function<void (HouseInfo*)> 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<int, Entity*> uniid_hash_;
std::vector<int> poly_ext_datas_;
std::list<HouseInfo> houses_;
std::vector<mc::ColliderNode*> things_;
std::string map_tpl_name_;
const mt::Map* map_meta_ = nullptr;
MapService* map_service_ = nullptr;
GridService* grid_service_ = nullptr;
};