1
This commit is contained in:
parent
9bc053e936
commit
646ec15f5a
@ -2,6 +2,7 @@
|
||||
|
||||
#include "behaviac/behaviac.h"
|
||||
#include "navigation.h"
|
||||
#include "navigation_handle.h"
|
||||
|
||||
namespace f8
|
||||
{
|
||||
@ -15,6 +16,16 @@ namespace f8
|
||||
|
||||
}
|
||||
|
||||
f8::NavigationHandle* Navigation::NewNavigation(std::string& unique_str)
|
||||
{
|
||||
if (HasNavigation(unique_str)) {
|
||||
abort();
|
||||
}
|
||||
f8::NavigationHandle* handle = new f8::NavigationHandle;
|
||||
navhandles_[unique_str] = handle;
|
||||
return handle;
|
||||
}
|
||||
|
||||
f8::NavigationHandle* Navigation::LoadNavigation(const std::string& res_path,
|
||||
const std::map<int, std::string>& params)
|
||||
{
|
||||
|
@ -13,6 +13,7 @@ namespace f8
|
||||
void Init();
|
||||
void UnInit();
|
||||
|
||||
f8::NavigationHandle* NewNavigation(std::string& unique_str);
|
||||
f8::NavigationHandle* LoadNavigation(const std::string& res_path,
|
||||
const std::map<int, std::string>& params);
|
||||
bool HasNavigation(const std::string& res_path);
|
||||
|
@ -4,22 +4,100 @@
|
||||
|
||||
namespace f8
|
||||
{
|
||||
int NavigationHandle::FindStraightPath(int layer, const a8::Vec3& start, const a8::Vec3& end,
|
||||
std::vector<a8::Vec3>& path_list)
|
||||
|
||||
int NavMeshLayer::FindStraightPath(const a8::Vec3& start, const a8::Vec3& end,
|
||||
std::vector<a8::Vec3>& path_list)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int NavigationHandle::FindRandomPointAroundCircle(int layer, const a8::Vec3& center_pos,
|
||||
std::vector<a8::Vec3>& points, int max_points, float max_radius)
|
||||
int NavMeshLayer::FindRandomPointAroundCircle(const a8::Vec3& center_pos,
|
||||
std::vector<a8::Vec3>& points,
|
||||
int max_points, float max_radius)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int NavigationHandle::Raycast(int layer, const a8::Vec3& start, const a8::Vec3& end,
|
||||
std::vector<a8::Vec3>& hit_points)
|
||||
int NavMeshLayer::Raycast(const a8::Vec3& start, const a8::Vec3& end,
|
||||
std::vector<a8::Vec3>& hit_points)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool NavMeshLayer::AddObstacle(a8::Vec3& pos, const float radius, const float height,
|
||||
ObstacleRef* obstacle_ref)
|
||||
{
|
||||
if (obstacle_ref) {
|
||||
*obstacle_ref = 0;
|
||||
}
|
||||
float p[3];
|
||||
p[0] = pos.x;
|
||||
p[1] = pos.y;
|
||||
p[2] = pos.z;
|
||||
dtStatus status = tile_cache_->addObstacle(p, radius, height, obstacle_ref);
|
||||
return status == DT_SUCCESS || status == DT_IN_PROGRESS;
|
||||
}
|
||||
|
||||
bool NavMeshLayer::AddBoxObstacle(a8::Vec3& bmin, a8::Vec3& bmax,
|
||||
ObstacleRef* obstacle_ref)
|
||||
{
|
||||
if (obstacle_ref) {
|
||||
*obstacle_ref = 0;
|
||||
}
|
||||
float pmin[3];
|
||||
pmin[0] = bmin.x;
|
||||
pmin[1] = bmin.y;
|
||||
pmin[2] = bmin.z;
|
||||
|
||||
float pmax[3];
|
||||
pmax[0] = bmax.x;
|
||||
pmax[1] = bmax.y;
|
||||
pmax[2] = bmax.z;
|
||||
|
||||
dtStatus status = tile_cache_->addBoxObstacle(pmin, pmax, obstacle_ref);
|
||||
return status == DT_SUCCESS || status == DT_IN_PROGRESS;
|
||||
}
|
||||
|
||||
bool NavMeshLayer::RemoveObstacle(const ObstacleRef& obstacle_ref)
|
||||
{
|
||||
dtStatus status = tile_cache_->removeObstacle(obstacle_ref);
|
||||
return status == DT_SUCCESS || status == DT_IN_PROGRESS;
|
||||
}
|
||||
|
||||
void NavMeshLayer::WaitRebuildOk()
|
||||
{
|
||||
while (!Update()) {}
|
||||
}
|
||||
|
||||
bool NavMeshLayer::Update()
|
||||
{
|
||||
bool up_to_date = false;
|
||||
tile_cache_->update(0, navmesh_, &up_to_date);
|
||||
return up_to_date;
|
||||
}
|
||||
|
||||
NavMeshLayer* NavigationHandle::GetLayer(int layer)
|
||||
{
|
||||
auto itr = navmesh_layers_.find(layer);
|
||||
return itr != navmesh_layers_.end() ? &itr->second : nullptr;
|
||||
}
|
||||
|
||||
void NavigationHandle::WaitRebuildOk()
|
||||
{
|
||||
for (auto& pair : navmesh_layers_) {
|
||||
pair.second.WaitRebuildOk();
|
||||
}
|
||||
}
|
||||
|
||||
bool NavigationHandle::Update()
|
||||
{
|
||||
bool up_to_date = true;
|
||||
for (auto& pair : navmesh_layers_) {
|
||||
if (!pair.second.Update() && up_to_date) {
|
||||
up_to_date = false;
|
||||
}
|
||||
}
|
||||
return up_to_date;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,19 +2,51 @@
|
||||
|
||||
#include <a8/vec3.h>
|
||||
|
||||
#include "DetourTileCache.h"
|
||||
|
||||
class dtTileCache;
|
||||
class dtNavMesh;
|
||||
class dtNavMeshQuery;
|
||||
namespace f8
|
||||
{
|
||||
|
||||
typedef dtObstacleRef ObstacleRef;
|
||||
|
||||
class NavMeshLayer
|
||||
{
|
||||
public:
|
||||
int FindStraightPath(const a8::Vec3& start, const a8::Vec3& end,
|
||||
std::vector<a8::Vec3>& path_list);
|
||||
int FindRandomPointAroundCircle(const a8::Vec3& center_pos,
|
||||
std::vector<a8::Vec3>& points, int max_points, float max_radius);
|
||||
int Raycast(const a8::Vec3& start, const a8::Vec3& end,
|
||||
std::vector<a8::Vec3>& hit_points);
|
||||
|
||||
bool AddObstacle(a8::Vec3& pos, const float radius, const float height, ObstacleRef* obstacle_ref);
|
||||
bool AddBoxObstacle(a8::Vec3& bmin, a8::Vec3& bmax, ObstacleRef* obstacle_ref);
|
||||
bool RemoveObstacle(const ObstacleRef& obstacle_ref);
|
||||
void WaitRebuildOk();
|
||||
bool Update();
|
||||
|
||||
private:
|
||||
|
||||
dtNavMesh* navmesh_ = nullptr;
|
||||
dtTileCache* tile_cache_ = nullptr;
|
||||
dtNavMeshQuery* navmesh_query_ = nullptr;
|
||||
};
|
||||
|
||||
class NavigationHandle
|
||||
{
|
||||
public:
|
||||
NavigationHandle() {};
|
||||
~NavigationHandle() {};
|
||||
|
||||
int FindStraightPath(int layer, const a8::Vec3& start, const a8::Vec3& end,
|
||||
std::vector<a8::Vec3>& path_list);
|
||||
int FindRandomPointAroundCircle(int layer, const a8::Vec3& center_pos,
|
||||
std::vector<a8::Vec3>& points, int max_points, float max_radius);
|
||||
int Raycast(int layer, const a8::Vec3& start, const a8::Vec3& end,
|
||||
std::vector<a8::Vec3>& hit_points);
|
||||
NavMeshLayer* GetLayer(int layer);
|
||||
void WaitRebuildOk();
|
||||
bool Update();
|
||||
|
||||
private:
|
||||
std::map<int, NavMeshLayer> navmesh_layers_;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user