mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Merge pull request #105071 from smix8/map_changed
Make navigation maps emit map_changed directly
This commit is contained in:
commit
e1509d533e
6 changed files with 6 additions and 26 deletions
|
|
@ -293,13 +293,11 @@ COMMAND_2(map_set_active, RID, p_map, bool, p_active) {
|
||||||
if (p_active) {
|
if (p_active) {
|
||||||
if (!map_is_active(p_map)) {
|
if (!map_is_active(p_map)) {
|
||||||
active_maps.push_back(map);
|
active_maps.push_back(map);
|
||||||
active_maps_iteration_id.push_back(map->get_iteration_id());
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int map_index = active_maps.find(map);
|
int map_index = active_maps.find(map);
|
||||||
ERR_FAIL_COND(map_index < 0);
|
ERR_FAIL_COND(map_index < 0);
|
||||||
active_maps.remove_at(map_index);
|
active_maps.remove_at(map_index);
|
||||||
active_maps_iteration_id.remove_at(map_index);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1192,7 +1190,6 @@ COMMAND_1(free, RID, p_object) {
|
||||||
int map_index = active_maps.find(map);
|
int map_index = active_maps.find(map);
|
||||||
if (map_index >= 0) {
|
if (map_index >= 0) {
|
||||||
active_maps.remove_at(map_index);
|
active_maps.remove_at(map_index);
|
||||||
active_maps_iteration_id.remove_at(map_index);
|
|
||||||
}
|
}
|
||||||
map_owner.free(p_object);
|
map_owner.free(p_object);
|
||||||
|
|
||||||
|
|
@ -1290,8 +1287,6 @@ void GodotNavigationServer2D::physics_process(double p_delta_time) {
|
||||||
int _new_pm_edge_free_count = 0;
|
int _new_pm_edge_free_count = 0;
|
||||||
int _new_pm_obstacle_count = 0;
|
int _new_pm_obstacle_count = 0;
|
||||||
|
|
||||||
// In c++ we can't be sure that this is performed in the main thread
|
|
||||||
// even with mutable functions.
|
|
||||||
MutexLock lock(operations_mutex);
|
MutexLock lock(operations_mutex);
|
||||||
for (uint32_t i(0); i < active_maps.size(); i++) {
|
for (uint32_t i(0); i < active_maps.size(); i++) {
|
||||||
active_maps[i]->sync();
|
active_maps[i]->sync();
|
||||||
|
|
@ -1307,13 +1302,6 @@ void GodotNavigationServer2D::physics_process(double p_delta_time) {
|
||||||
_new_pm_edge_connection_count += active_maps[i]->get_pm_edge_connection_count();
|
_new_pm_edge_connection_count += active_maps[i]->get_pm_edge_connection_count();
|
||||||
_new_pm_edge_free_count += active_maps[i]->get_pm_edge_free_count();
|
_new_pm_edge_free_count += active_maps[i]->get_pm_edge_free_count();
|
||||||
_new_pm_obstacle_count += active_maps[i]->get_pm_obstacle_count();
|
_new_pm_obstacle_count += active_maps[i]->get_pm_obstacle_count();
|
||||||
|
|
||||||
// Emit a signal if a map changed.
|
|
||||||
const uint32_t new_map_iteration_id = active_maps[i]->get_iteration_id();
|
|
||||||
if (new_map_iteration_id != active_maps_iteration_id[i]) {
|
|
||||||
emit_signal(SNAME("map_changed"), active_maps[i]->get_self());
|
|
||||||
active_maps_iteration_id[i] = new_map_iteration_id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pm_region_count = _new_pm_region_count;
|
pm_region_count = _new_pm_region_count;
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,6 @@ class GodotNavigationServer2D : public NavigationServer2D {
|
||||||
|
|
||||||
bool active = true;
|
bool active = true;
|
||||||
LocalVector<NavMap2D *> active_maps;
|
LocalVector<NavMap2D *> active_maps;
|
||||||
LocalVector<uint32_t> active_maps_iteration_id;
|
|
||||||
|
|
||||||
#ifdef CLIPPER2_ENABLED
|
#ifdef CLIPPER2_ENABLED
|
||||||
NavMeshGenerator2D *navmesh_generator_2d = nullptr;
|
NavMeshGenerator2D *navmesh_generator_2d = nullptr;
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@
|
||||||
|
|
||||||
#include "core/config/project_settings.h"
|
#include "core/config/project_settings.h"
|
||||||
#include "core/object/worker_thread_pool.h"
|
#include "core/object/worker_thread_pool.h"
|
||||||
|
#include "servers/navigation_server_2d.h"
|
||||||
|
|
||||||
#include <Obstacle2d.h>
|
#include <Obstacle2d.h>
|
||||||
|
|
||||||
|
|
@ -418,6 +419,8 @@ void NavMap2D::sync() {
|
||||||
}
|
}
|
||||||
if (iteration_ready) {
|
if (iteration_ready) {
|
||||||
_sync_iteration();
|
_sync_iteration();
|
||||||
|
|
||||||
|
NavigationServer2D::get_singleton()->emit_signal(SNAME("map_changed"), get_self());
|
||||||
}
|
}
|
||||||
|
|
||||||
map_settings_dirty = false;
|
map_settings_dirty = false;
|
||||||
|
|
|
||||||
|
|
@ -120,13 +120,11 @@ COMMAND_2(map_set_active, RID, p_map, bool, p_active) {
|
||||||
if (p_active) {
|
if (p_active) {
|
||||||
if (!map_is_active(p_map)) {
|
if (!map_is_active(p_map)) {
|
||||||
active_maps.push_back(map);
|
active_maps.push_back(map);
|
||||||
active_maps_iteration_id.push_back(map->get_iteration_id());
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int map_index = active_maps.find(map);
|
int map_index = active_maps.find(map);
|
||||||
ERR_FAIL_COND(map_index < 0);
|
ERR_FAIL_COND(map_index < 0);
|
||||||
active_maps.remove_at(map_index);
|
active_maps.remove_at(map_index);
|
||||||
active_maps_iteration_id.remove_at(map_index);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1224,7 +1222,6 @@ COMMAND_1(free, RID, p_object) {
|
||||||
int map_index = active_maps.find(map);
|
int map_index = active_maps.find(map);
|
||||||
if (map_index >= 0) {
|
if (map_index >= 0) {
|
||||||
active_maps.remove_at(map_index);
|
active_maps.remove_at(map_index);
|
||||||
active_maps_iteration_id.remove_at(map_index);
|
|
||||||
}
|
}
|
||||||
map_owner.free(p_object);
|
map_owner.free(p_object);
|
||||||
|
|
||||||
|
|
@ -1371,8 +1368,6 @@ void GodotNavigationServer3D::physics_process(double p_delta_time) {
|
||||||
int _new_pm_edge_free_count = 0;
|
int _new_pm_edge_free_count = 0;
|
||||||
int _new_pm_obstacle_count = 0;
|
int _new_pm_obstacle_count = 0;
|
||||||
|
|
||||||
// In c++ we can't be sure that this is performed in the main thread
|
|
||||||
// even with mutable functions.
|
|
||||||
MutexLock lock(operations_mutex);
|
MutexLock lock(operations_mutex);
|
||||||
for (uint32_t i(0); i < active_maps.size(); i++) {
|
for (uint32_t i(0); i < active_maps.size(); i++) {
|
||||||
active_maps[i]->sync();
|
active_maps[i]->sync();
|
||||||
|
|
@ -1388,13 +1383,6 @@ void GodotNavigationServer3D::physics_process(double p_delta_time) {
|
||||||
_new_pm_edge_connection_count += active_maps[i]->get_pm_edge_connection_count();
|
_new_pm_edge_connection_count += active_maps[i]->get_pm_edge_connection_count();
|
||||||
_new_pm_edge_free_count += active_maps[i]->get_pm_edge_free_count();
|
_new_pm_edge_free_count += active_maps[i]->get_pm_edge_free_count();
|
||||||
_new_pm_obstacle_count += active_maps[i]->get_pm_obstacle_count();
|
_new_pm_obstacle_count += active_maps[i]->get_pm_obstacle_count();
|
||||||
|
|
||||||
// Emit a signal if a map changed.
|
|
||||||
const uint32_t new_map_iteration_id = active_maps[i]->get_iteration_id();
|
|
||||||
if (new_map_iteration_id != active_maps_iteration_id[i]) {
|
|
||||||
emit_signal(SNAME("map_changed"), active_maps[i]->get_self());
|
|
||||||
active_maps_iteration_id[i] = new_map_iteration_id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pm_region_count = _new_pm_region_count;
|
pm_region_count = _new_pm_region_count;
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,6 @@ class GodotNavigationServer3D : public NavigationServer3D {
|
||||||
|
|
||||||
bool active = true;
|
bool active = true;
|
||||||
LocalVector<NavMap3D *> active_maps;
|
LocalVector<NavMap3D *> active_maps;
|
||||||
LocalVector<uint32_t> active_maps_iteration_id;
|
|
||||||
|
|
||||||
NavMeshGenerator3D *navmesh_generator_3d = nullptr;
|
NavMeshGenerator3D *navmesh_generator_3d = nullptr;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@
|
||||||
|
|
||||||
#include "core/config/project_settings.h"
|
#include "core/config/project_settings.h"
|
||||||
#include "core/object/worker_thread_pool.h"
|
#include "core/object/worker_thread_pool.h"
|
||||||
|
#include "servers/navigation_server_3d.h"
|
||||||
|
|
||||||
#include <Obstacle2d.h>
|
#include <Obstacle2d.h>
|
||||||
|
|
||||||
|
|
@ -474,6 +475,8 @@ void NavMap3D::sync() {
|
||||||
}
|
}
|
||||||
if (iteration_ready) {
|
if (iteration_ready) {
|
||||||
_sync_iteration();
|
_sync_iteration();
|
||||||
|
|
||||||
|
NavigationServer3D::get_singleton()->emit_signal(SNAME("map_changed"), get_self());
|
||||||
}
|
}
|
||||||
|
|
||||||
map_settings_dirty = false;
|
map_settings_dirty = false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue