28 static constexpr float kUnreachable = 3.4e38f;
47 void resize(
int width,
int height,
float cellSize,
float originX,
float originY);
53 bool valid()
const {
return width_ > 0 && height_ > 0 && cellSize_ > 0.f; }
72 void setBlocked(
int cx,
int cy,
bool blocked);
75 bool isBlocked(
int cx,
int cy)
const;
81 void setCellCost(
int cx,
int cy,
float cost);
84 float getCellCost(
int cx,
int cy)
const;
87 void setAllCellCost(
float cost);
94 void setGoal(
int gx,
int gy);
97 void addGoal(
int gx,
int gy);
101 int goalCount()
const {
return int(goals_.size() / 2); }
104 bool isBuilt()
const {
return built_ && builtRevision_ == revision_; }
106 [[nodiscard]] std::uint64_t
revision() const noexcept {
return revision_; }
108 [[nodiscard]] std::uint64_t
inputRevision() const noexcept {
return inputRevision_; }
110 [[nodiscard]] std::uint64_t
builtRevision() const noexcept {
return builtRevision_; }
113 if (!
valid())
return FieldState::Unconfigured;
114 if (!built_)
return FieldState::Unbuilt;
115 return isBuilt() ? FieldState::Ready : FieldState::Stale;
126 float costAtCell(
int cx,
int cy)
const;
129 bool isReachable(
int cx,
int cy)
const;
138 void flowAtCell(
int cx,
int cy,
float &
dx,
float &
dy)
const;
146 float costAtWorld(
float wx,
float wy)
const;
155 void flowAtWorld(
float wx,
float wy,
float &
dx,
float &
dy)
const;
168 bool resolvePenetration(
float &
wx,
float &
wy,
float radius)
const;
173 const std::vector<float> &
flowX()
const {
return flowX_; }
175 const std::vector<float> &
flowY()
const {
return flowY_; }
179 void beginBuildWorking();
180 std::pair<int, int> advanceBuildWorking(
int maxWork);
182 void invalidateInputs();
184 bool inBounds(
int cx,
int cy)
const {
return cx >= 0 &&
cy >= 0 &&
cx < width_ &&
cy < height_; }
186 void worldToCell(
float wx,
float wy,
float &fx,
float &fy)
const;
188 void rebuildFlowCell(
int index);
192 float cellSize_ = 0.f;
193 float originX_ = 0.f;
194 float originY_ = 0.f;
195 std::vector<float> cost_;
196 std::vector<float> navigationCost_;
197 bool navigationDiagonal_ =
true, destinationEntryCost_ =
false;
198 bool navigationBlocked(
int cx,
int cy)
const;
199 float navigationCost(
int index)
const;
200 std::vector<float> integ_;
201 std::vector<float> flowX_;
202 std::vector<float> flowY_;
203 std::vector<int> goals_;
205 std::uint64_t revision_ = 0, builtRevision_ = 0, inputRevision_ = 0;
206 std::vector<std::pair<float, int>> buildHeap_;