game2006/server/gameserver/mapinstance.h
aozhiwei 97f9f3f760 1
2022-12-28 14:41:28 +08:00

63 lines
1.8 KiB
C++

#pragma once
#include "DetourNavMesh.h"
#include "DetourNavMeshQuery.h"
const int MAX_POLYS = 256;
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_; }
Entity* GetEntityByUniId(int uniid);
dtNavMesh* GetNavMesh() { return navmesh_; };
dtNavMeshQuery* GetNavMeshQuery() { return navmesh_query_; };
int FindStraightPath(int layer,
const a8::Vec3& start,
const a8::Vec3& end,
std::vector<a8::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);
void Scale(glm::vec3& v);
void UnScale(glm::vec3& v);
private:
void CreateThings();
int AllocUniid();
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::string map_tpl_name_;
const mt::Map* map_meta_ = nullptr;
MapService* map_service_ = nullptr;
GridService* grid_service_ = nullptr;
};