Use ThreadWorkPool instead of thread_process_array in NavMap

This commit is contained in:
Adam Scott 2022-04-18 15:57:23 -04:00
parent 690fefe43e
commit 732102cbc5
2 changed files with 15 additions and 3 deletions

View File

@ -30,7 +30,6 @@
#include "nav_map.h" #include "nav_map.h"
#include "core/os/threaded_array_processor.h"
#include "nav_region.h" #include "nav_region.h"
#include "rvo_agent.h" #include "rvo_agent.h"
@ -674,7 +673,7 @@ void NavMap::compute_single_step(uint32_t index, RvoAgent **agent) {
void NavMap::step(real_t p_deltatime) { void NavMap::step(real_t p_deltatime) {
deltatime = p_deltatime; deltatime = p_deltatime;
if (controlled_agents.size() > 0) { if (controlled_agents.size() > 0) {
thread_process_array( step_work_pool.do_work(
controlled_agents.size(), controlled_agents.size(),
this, this,
&NavMap::compute_single_step, &NavMap::compute_single_step,
@ -719,3 +718,11 @@ void NavMap::clip_path(const std::vector<gd::NavigationPoly> &p_navigation_polys
} }
} }
} }
NavMap::NavMap() {
step_work_pool.init();
}
NavMap::~NavMap() {
step_work_pool.finish();
}

View File

@ -35,6 +35,7 @@
#include "core/math/math_defs.h" #include "core/math/math_defs.h"
#include "core/templates/map.h" #include "core/templates/map.h"
#include "core/templates/thread_work_pool.h"
#include "nav_utils.h" #include "nav_utils.h"
#include <KdTree.h> #include <KdTree.h>
@ -80,8 +81,12 @@ class NavMap : public NavRid {
/// Change the id each time the map is updated. /// Change the id each time the map is updated.
uint32_t map_update_id = 0; uint32_t map_update_id = 0;
/// Pooled threads for computing steps
ThreadWorkPool step_work_pool;
public: public:
NavMap() {} NavMap();
~NavMap();
void set_up(Vector3 p_up); void set_up(Vector3 p_up);
Vector3 get_up() const { Vector3 get_up() const {