diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-06-29 17:51:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-29 17:51:22 +0200 |
commit | 916c37de09871be0f5578f2f23f700ecaa08f836 (patch) | |
tree | bbb54b367c30c4d17ec19fb0f5357c4343f64908 /modules | |
parent | 691c754a6c46b7557e5605f479e028447f923df6 (diff) | |
parent | 64c925cca6d5c54b0ef4dd0bcdd7a4357f4b86fb (diff) |
Merge pull request #50000 from reduz/improve-rid-owner-memory-usage
Improve RID_Owner memory usage
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdnavigation/gd_navigation_server.cpp | 15 | ||||
-rw-r--r-- | modules/gdnavigation/gd_navigation_server.h | 6 |
2 files changed, 9 insertions, 12 deletions
diff --git a/modules/gdnavigation/gd_navigation_server.cpp b/modules/gdnavigation/gd_navigation_server.cpp index d5e6e5e69f..929bbf9354 100644 --- a/modules/gdnavigation/gd_navigation_server.cpp +++ b/modules/gdnavigation/gd_navigation_server.cpp @@ -132,8 +132,8 @@ void GdNavigationServer::add_command(SetCommand *command) const { RID GdNavigationServer::map_create() const { GdNavigationServer *mut_this = const_cast<GdNavigationServer *>(this); MutexLock lock(mut_this->operations_mutex); - NavMap *space = memnew(NavMap); - RID rid = map_owner.make_rid(space); + RID rid = map_owner.make_rid(); + NavMap *space = map_owner.getornull(rid); space->set_self(rid); return rid; } @@ -242,8 +242,8 @@ RID GdNavigationServer::map_get_closest_point_owner(RID p_map, const Vector3 &p_ RID GdNavigationServer::region_create() const { GdNavigationServer *mut_this = const_cast<GdNavigationServer *>(this); MutexLock lock(mut_this->operations_mutex); - NavRegion *reg = memnew(NavRegion); - RID rid = region_owner.make_rid(reg); + RID rid = region_owner.make_rid(); + NavRegion *reg = region_owner.getornull(rid); reg->set_self(rid); return rid; } @@ -332,8 +332,8 @@ Vector3 GdNavigationServer::region_get_connection_pathway_end(RID p_region, int RID GdNavigationServer::agent_create() const { GdNavigationServer *mut_this = const_cast<GdNavigationServer *>(this); MutexLock lock(mut_this->operations_mutex); - RvoAgent *agent = memnew(RvoAgent()); - RID rid = agent_owner.make_rid(agent); + RID rid = agent_owner.make_rid(); + RvoAgent *agent = agent_owner.getornull(rid); agent->set_self(rid); return rid; } @@ -472,7 +472,6 @@ COMMAND_1(free, RID, p_object) { active_maps.remove(map_index); active_maps_update_id.remove(map_index); map_owner.free(p_object); - memdelete(map); } else if (region_owner.owns(p_object)) { NavRegion *region = region_owner.getornull(p_object); @@ -484,7 +483,6 @@ COMMAND_1(free, RID, p_object) { } region_owner.free(p_object); - memdelete(region); } else if (agent_owner.owns(p_object)) { RvoAgent *agent = agent_owner.getornull(p_object); @@ -496,7 +494,6 @@ COMMAND_1(free, RID, p_object) { } agent_owner.free(p_object); - memdelete(agent); } else { ERR_FAIL_COND("Invalid ID."); diff --git a/modules/gdnavigation/gd_navigation_server.h b/modules/gdnavigation/gd_navigation_server.h index 759d15e508..bc2fc855c4 100644 --- a/modules/gdnavigation/gd_navigation_server.h +++ b/modules/gdnavigation/gd_navigation_server.h @@ -75,9 +75,9 @@ class GdNavigationServer : public NavigationServer3D { std::vector<SetCommand *> commands; - mutable RID_PtrOwner<NavMap> map_owner; - mutable RID_PtrOwner<NavRegion> region_owner; - mutable RID_PtrOwner<RvoAgent> agent_owner; + mutable RID_Owner<NavMap> map_owner; + mutable RID_Owner<NavRegion> region_owner; + mutable RID_Owner<RvoAgent> agent_owner; bool active = true; LocalVector<NavMap *> active_maps; |