f8/cpp/navigation_handle.cc
aozhiwei 646ec15f5a 1
2019-11-05 15:22:38 +08:00

104 lines
2.8 KiB
C++

#include "precompile.h"
#include "navigation_handle.h"
namespace f8
{
int NavMeshLayer::FindStraightPath(const a8::Vec3& start, const a8::Vec3& end,
std::vector<a8::Vec3>& path_list)
{
return 0;
}
int NavMeshLayer::FindRandomPointAroundCircle(const a8::Vec3& center_pos,
std::vector<a8::Vec3>& points,
int max_points, float max_radius)
{
return 0;
}
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;
}
}