This commit is contained in:
aozhiwei 2023-11-04 10:28:21 +08:00
parent 8c8f3ff397
commit 08e64375a8
5 changed files with 14 additions and 15 deletions

View File

@ -99,8 +99,8 @@ void MapInstance::Init()
if (map_meta_->map_height() < 1) {
A8_ABORT();
}
map_service_ = new MapService();
grid_service_ = new GridService();
map_service_ = std::make_shared<MapService>();
grid_service_ = std::make_shared<GridService>();
grid_service_->Init(map_meta_->map_width(),
map_meta_->map_height(),
mt::Param::s().map_cell_width);
@ -186,7 +186,7 @@ void MapInstance::Init()
fclose(fp);
}
}
navmesh_query_ = new dtNavMeshQuery();
navmesh_query_ = std::make_shared<dtNavMeshQuery>();
navmesh_query_->init(navmesh_, 1024);
MarkMapAreaPolys();
MarkConnectablePolys();
@ -201,15 +201,14 @@ void MapInstance::Init()
void MapInstance::UnInit()
{
delete navmesh_query_;
navmesh_query_ = nullptr;
dtFreeNavMesh(navmesh_);
navmesh_ = nullptr;
map_service_->UnInit();
grid_service_->UnInit();
A8_SAFE_DELETE(map_service_);
A8_SAFE_DELETE(grid_service_);
map_service_ = nullptr;
grid_service_ = nullptr;
}
void MapInstance::AttachRoom(Room* room, RoomInitInfo& init_info)

View File

@ -34,7 +34,7 @@ class MapInstance : public std::enable_shared_from_this<MapInstance>
std::vector<int>& GetPolyExtDatas() { return poly_ext_datas_; };
dtNavMesh* GetNavMesh() { return navmesh_; };
dtNavMeshQuery* GetNavMeshQuery() { return navmesh_query_; };
dtNavMeshQuery* GetNavMeshQuery() { return navmesh_query_.get(); };
int FindStraightPath(const glm::vec3& start,
const glm::vec3& end,
std::vector<glm::vec3>& paths);
@ -71,7 +71,7 @@ class MapInstance : public std::enable_shared_from_this<MapInstance>
private:
dtNavMesh* navmesh_ = nullptr;
dtNavMeshQuery* navmesh_query_ = nullptr;
std::shared_ptr<dtNavMeshQuery> navmesh_query_;
float hit_normal_[3];
float hit_pos_[3];
@ -87,6 +87,6 @@ class MapInstance : public std::enable_shared_from_this<MapInstance>
std::string map_tpl_name_;
const mt::Map* map_meta_ = nullptr;
MapService* map_service_ = nullptr;
GridService* grid_service_ = nullptr;
std::shared_ptr<MapService> map_service_;
std::shared_ptr<GridService> grid_service_;
};

View File

@ -134,7 +134,7 @@ void Room::Init()
CreateSpawnPoints();
CreateWorldObjects();
ShuaAndroid();
incubator_ = std::make_shared(Incubator>();
incubator_ = std::make_shared<Incubator>();
incubator_->room = this;
incubator_->Init();
sand_table_ = std::make_shared<SandTable>(this);

View File

@ -80,8 +80,8 @@ public:
Plane plane;
f8::Attacher timer_attacher;
a8::Attacher xtimer_attacher_;
GridService* grid_service = nullptr;
MapService* map_service = nullptr;
std::shared_ptr<GridService> grid_service;
std::shared_ptr<MapService> map_service;
std::shared_ptr<MapInstance> map_instance;
bool debug_trace = false;
bool added_to_over_room = false;

View File

@ -43,8 +43,8 @@ struct RoomInitInfo
const mt::Map* map_meta = nullptr;
std::string map_tpl_name;
GridService* grid_service = nullptr;
MapService* map_service = nullptr;
std::shared_ptr<GridService> grid_service;
std::shared_ptr<MapService> map_service;
std::shared_ptr<MapInstance> map_instance;
std::vector<const mt::MapTplThing*>* mini_room_spawn_points = nullptr;
std::vector<const mt::MapTplThing*>* normal_room_spawn_points = nullptr;