game2006/server/gameserver/mapinstance.h
aozhiwei 737f7a056a 1
2024-03-28 19:35:50 +08:00

100 lines
3.4 KiB
C++

#pragma once
#include "DetourNavMesh.h"
#include "DetourNavMeshQuery.h"
const int MAX_POLYS = 256;
namespace mc
{
class ColliderNode;
};
struct HouseInfo
{
std::shared_ptr<mc::ColliderNode> node;
std::vector<float> verts;
};
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_; };
dtNavMesh* GetNavMesh() { return navmesh_; };
dtNavMeshQuery* GetNavMeshQuery() { return navmesh_query_.get(); };
int FindStraightPath(const glm::vec3& start,
const glm::vec3& end,
std::vector<MovePathPoint>& paths);
bool FindRandomPointAroundCircle(const glm::vec3& center_pos,
float max_radius,
glm::vec3& random_pt);
bool RandPoint(const glm::vec3& center, float range, glm::vec3& out_point);
bool Raycast(const glm::vec3& start, const glm::vec3& end,
glm::vec3& hit_point, bool& hit_result,
unsigned short includeFlags,
unsigned short excludeFlags);
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,
unsigned short exclude_flags);
bool FindNearestPoint(const glm::vec3& center, float radius, glm::vec3& nearestPt);
bool FindConnectableNearestPoint(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);
bool GetNearestGrass(const glm::vec3& center, glm::vec3& out_pt);
void AdjustOnLandPoint(glm::vec3& point);
bool IsConnectablePoly(dtPolyRef poly_ref);
bool IsValidPos(const glm::vec3& point);
unsigned short GetMoveIncludeFlags();
unsigned short GetMoveExcludeFlags();
unsigned short GetBulletIncludeFlags();
unsigned short GetBulletExcludeFlags();
private:
void LoadHouse();
void MarkMapAreaPolys();
void MarkConnectablePolys();
private:
dtNavMesh* navmesh_ = nullptr;
std::shared_ptr<dtNavMeshQuery> navmesh_query_;
float hit_normal_[3];
float hit_pos_[3];
dtPolyRef polys_[MAX_POLYS];
std::vector<int> poly_ext_datas_;
std::vector<glm::vec3> grass_pos_hash_;
std::list<HouseInfo> houses_;
std::vector<std::shared_ptr<mc::ColliderNode>> things_;
std::set<dtPolyRef> connectable_polys_;
std::string map_tpl_name_;
const mt::Map* map_meta_ = nullptr;
std::shared_ptr<MapService> map_service_;
std::shared_ptr<GridService> grid_service_;
};