载入中...
搜索中...
未找到
eve::crowd::CrowdField类 参考

连续流场(flow field)。 更多...

#include <CrowdField.h>

Public 成员函数

 CrowdField ()=default
 Crowd field.
 
void resize (int width, int height, float cellSize, float originX, float originY)
 配置网格(保留原有 cost/goals,若尺寸变化则重置)。
 
void clear ()
 清空全部数据(回到无效状态)。
 
bool valid () const
 是否配置了有效网格。
 
int getWidth () const
 网格尺寸访问器。
 
int getHeight () const
 Returns the height.
 
float getCellSize () const
 Returns the cell size.
 
float getOriginX () const
 Returns the origin x.
 
float getOriginY () const
 Returns the origin y.
 
void setBlocked (int cx, int cy, bool blocked)
 设置/清除某格阻挡。
 
bool isBlocked (int cx, int cy) const
 查询某格是否阻挡。
 
void setCellCost (int cx, int cy, float cost)
 设置某格地形代价(进入该格的移动成本)。
 
float getCellCost (int cx, int cy) const
 查询地形代价(越界/阻挡返回 0)。
 
void setAllCellCost (float cost)
 把全部格子设为同一地形代价(通常 build 前重置用)。
 
void setGoal (int gx, int gy)
 设定唯一目标格(等价 clearGoals + addGoal)。
 
void addGoal (int gx, int gy)
 Append a unique goal cell; existing goals leave revision unchanged.
 
void clearGoals ()
 清空目标列表。
 
int goalCount () const
 目标个数。
 
bool isBuilt () const
 Whether directions were built for the current terrain and goals.
 
std::uint64_t revision () const noexcept
 Read owner-local terrain/goal revision; snapshots preserve it.
 
std::uint64_t inputRevision () const noexcept
 Navigation geometry/cost/rule epoch; goal edits and field publications do not change it.
 
std::uint64_t builtRevision () const noexcept
 Read revision consumed by the last completed build.
 
FieldState state () const noexcept
 Distinguish absent, unbuilt, current and stale navigation.
 
void build ()
 Legacy synchronous build; publish the completed staged Dijkstra result atomically. @thread Owner thread only. @reentrancy No callbacks. @cost Copies field storage then performs global Dijkstra; amortize at explicit navigation rebuild boundaries.
 
float costAtCell (int cx, int cy) const
 查询格级积分代价(未 build 返回 kUnreachable)。
 
bool isReachable (int cx, int cy) const
 某格是否可达(积分代价有限且非负)。
 
void flowAtCell (int cx, int cy, float &dx, float &dy) const
 查询格级方向向量(单位长度;目标格/阻挡/不可达为 0)。
 
float costAtWorld (float wx, float wy) const
 查询世界坐标处的积分代价(双线性插值;场外返回 kUnreachable)。
 
void flowAtWorld (float wx, float wy, float &dx, float &dy) const
 查询世界坐标处的跟随方向(双线性插值后归一化)。
 
bool resolvePenetration (float &wx, float &wy, float radius) const
 圆 vs 阻挡格碰撞消解:把圆心从覆盖到的阻挡格中推出来。
 
const std::vector< float > & integration () const
 只读访问积分场(调试渲染用)。
 
const std::vector< float > & flowX () const
 只读访问方向场 X 分量(调试渲染用)。
 
const std::vector< float > & flowY () const
 只读访问方向场 Y 分量(调试渲染用)。
 

静态 Public 属性

static constexpr float kUnreachable = 3.4e38f
 不可达/阻挡的积分代价。
 

友元

class Crowd
 

详细描述

连续流场(flow field)。

build() 从所有目标格做一次 8 邻域 Dijkstra,得到到目标的积分代价 (integration cost);随后由中心差分求梯度,生成每格的单位方向向量 (沿代价下降方向)。flowAtWorld() 用双线性插值给出任意世界坐标的方向, 供单位逐帧采样跟随。

在文件 CrowdField.h 第 25 行定义.

构造及析构函数说明

◆ CrowdField()

eve::crowd::CrowdField::CrowdField ( )
default

Crowd field.

成员函数说明

◆ addGoal()

void eve::crowd::CrowdField::addGoal ( int  gx,
int  gy 
)

Append a unique goal cell; existing goals leave revision unchanged.

在文件 CrowdField.cpp 第 133 行定义.

引用了 index.

◆ build()

void eve::crowd::CrowdField::build ( )

Legacy synchronous build; publish the completed staged Dijkstra result atomically. @thread Owner thread only. @reentrancy No callbacks. @cost Copies field storage then performs global Dijkstra; amortize at explicit navigation rebuild boundaries.

异常
std::bad_allocLeaves the previously published field unchanged on allocation failure.

在文件 CrowdField.cpp 第 162 行定义.

◆ builtRevision()

std::uint64_t eve::crowd::CrowdField::builtRevision ( ) const
inlinenoexcept

Read revision consumed by the last completed build.

在文件 CrowdField.h 第 110 行定义.

◆ clear()

void eve::crowd::CrowdField::clear ( )

清空全部数据(回到无效状态)。

在文件 CrowdField.cpp 第 68 行定义.

◆ clearGoals()

void eve::crowd::CrowdField::clearGoals ( )

清空目标列表。

在文件 CrowdField.cpp 第 143 行定义.

◆ costAtCell()

float eve::crowd::CrowdField::costAtCell ( int  cx,
int  cy 
) const

查询格级积分代价(未 build 返回 kUnreachable)。

在文件 CrowdField.cpp 第 283 行定义.

引用了 cx, cy, index, isBuilt() , 以及 kUnreachable.

被这些函数引用 isReachable().

◆ costAtWorld()

float eve::crowd::CrowdField::costAtWorld ( float  wx,
float  wy 
) const

查询世界坐标处的积分代价(双线性插值;场外返回 kUnreachable)。

参数
wx世界 X
wy世界 Y
返回
插值后的积分代价

在文件 CrowdField.cpp 第 300 行定义.

引用了 c, index, isBuilt(), kUnreachable, valid(), w, wx , 以及 wy.

◆ flowAtCell()

void eve::crowd::CrowdField::flowAtCell ( int  cx,
int  cy,
float &  dx,
float &  dy 
) const

查询格级方向向量(单位长度;目标格/阻挡/不可达为 0)。

参数
cx列
cy行
[out]dx方向 X
[out]dy方向 Y

在文件 CrowdField.cpp 第 292 行定义.

引用了 cx, cy, dx, dy, index , 以及 isBuilt().

◆ flowAtWorld()

void eve::crowd::CrowdField::flowAtWorld ( float  wx,
float  wy,
float &  dx,
float &  dy 
) const

查询世界坐标处的跟随方向(双线性插值后归一化)。

参数
wx世界 X
wy世界 Y
[out]dx方向 X(场外/全不可达为 0)
[out]dy方向 Y

在文件 CrowdField.cpp 第 335 行定义.

引用了 dx, dy, index, isBuilt(), sx, sy, valid(), wx, wy, x , 以及 y.

◆ flowX()

const std::vector< float > & eve::crowd::CrowdField::flowX ( ) const
inline

只读访问方向场 X 分量(调试渲染用)。

在文件 CrowdField.h 第 173 行定义.

被这些函数引用 resize().

◆ flowY()

const std::vector< float > & eve::crowd::CrowdField::flowY ( ) const
inline

只读访问方向场 Y 分量(调试渲染用)。

在文件 CrowdField.h 第 175 行定义.

被这些函数引用 resize().

◆ getCellCost()

float eve::crowd::CrowdField::getCellCost ( int  cx,
int  cy 
) const

查询地形代价(越界/阻挡返回 0)。

在文件 CrowdField.cpp 第 111 行定义.

引用了 cx, cy , 以及 index.

◆ getCellSize()

float eve::crowd::CrowdField::getCellSize ( ) const
inline

Returns the cell size.

在文件 CrowdField.h 第 60 行定义.

被这些函数引用 eve::crowd::Crowd::Impl::selectAvoidanceVelocity().

◆ getHeight()

int eve::crowd::CrowdField::getHeight ( ) const
inline

Returns the height.

在文件 CrowdField.h 第 58 行定义.

被这些函数引用 eve::crowd::Crowd::Impl::selectAvoidanceVelocity().

◆ getOriginX()

float eve::crowd::CrowdField::getOriginX ( ) const
inline

Returns the origin x.

在文件 CrowdField.h 第 62 行定义.

被这些函数引用 eve::crowd::Crowd::Impl::selectAvoidanceVelocity().

◆ getOriginY()

float eve::crowd::CrowdField::getOriginY ( ) const
inline

Returns the origin y.

在文件 CrowdField.h 第 64 行定义.

被这些函数引用 eve::crowd::Crowd::Impl::selectAvoidanceVelocity().

◆ getWidth()

int eve::crowd::CrowdField::getWidth ( ) const
inline

网格尺寸访问器。

在文件 CrowdField.h 第 56 行定义.

被这些函数引用 eve::crowd::Crowd::Impl::selectAvoidanceVelocity().

◆ goalCount()

int eve::crowd::CrowdField::goalCount ( ) const
inline

目标个数。

在文件 CrowdField.h 第 101 行定义.

◆ inputRevision()

std::uint64_t eve::crowd::CrowdField::inputRevision ( ) const
inlinenoexcept

Navigation geometry/cost/rule epoch; goal edits and field publications do not change it.

在文件 CrowdField.h 第 108 行定义.

被这些函数引用 eve::crowd::Crowd::Impl::isFlowLeaseCurrent().

◆ integration()

const std::vector< float > & eve::crowd::CrowdField::integration ( ) const
inline

只读访问积分场(调试渲染用)。

在文件 CrowdField.h 第 171 行定义.

被这些函数引用 resize().

◆ isBlocked()

bool eve::crowd::CrowdField::isBlocked ( int  cx,
int  cy 
) const

查询某格是否阻挡。

在文件 CrowdField.cpp 第 95 行定义.

引用了 cx, cy , 以及 index.

被这些函数引用 resolvePenetration().

◆ isBuilt()

bool eve::crowd::CrowdField::isBuilt ( ) const
inline

Whether directions were built for the current terrain and goals.

在文件 CrowdField.h 第 104 行定义.

被这些函数引用 costAtCell(), costAtWorld(), flowAtCell(), flowAtWorld() , 以及 eve::crowd::Crowd::Impl::navigationField().

◆ isReachable()

bool eve::crowd::CrowdField::isReachable ( int  cx,
int  cy 
) const

某格是否可达(积分代价有限且非负)。

在文件 CrowdField.cpp 第 288 行定义.

引用了 costAtCell(), cx , 以及 cy.

◆ resize()

void eve::crowd::CrowdField::resize ( int  width,
int  height,
float  cellSize,
float  originX,
float  originY 
)

配置网格(保留原有 cost/goals,若尺寸变化则重置)。

参数
width列数(>0)
height行数(>0)
cellSize每格世界尺寸(>0)
originX世界原点 X(格 (0,0) 左下角)
originY世界原点 Y

Identical geometry is a no-op. All buffer allocations precede geometry/revision publication. @thread Owner thread only. @reentrancy No callbacks. @cost Allocates grid-sized derived storage; amortize at explicit surface configuration boundaries.

异常
std::invalid_argumentNonfinite geometry is rejected without changing the field.
std::length_errorGrid dimensions exceed signed index range.
std::bad_allocBuffer preparation fails without changing the field.

在文件 CrowdField.cpp 第 33 行定义.

引用了 count, flowX(), flowY(), height, integration(), kUnreachable, size , 以及 width.

◆ resolvePenetration()

bool eve::crowd::CrowdField::resolvePenetration ( float &  wx,
float &  wy,
float  radius 
) const

圆 vs 阻挡格碰撞消解:把圆心从覆盖到的阻挡格中推出来。

按单位半径展开 AABB,检查覆盖到的格;对每个阻挡格沿穿透最小的轴推出, 使单位圆不再与任何阻挡格重叠。墙角处可能需迭代 2 次。

参数
[in,out]wx圆心世界 X
[in,out]wy圆心世界 Y
radius单位半径
返回
是否发生了推挤

在文件 CrowdField.cpp 第 373 行定义.

引用了 cx, cy, distance, dx, dy, isBlocked(), left, radius, right, scale, up, valid(), wx , 以及 wy.

被这些函数引用 eve::crowd::Crowd::Impl::selectAvoidanceVelocity().

◆ revision()

std::uint64_t eve::crowd::CrowdField::revision ( ) const
inlinenoexcept

Read owner-local terrain/goal revision; snapshots preserve it.

在文件 CrowdField.h 第 106 行定义.

◆ setAllCellCost()

void eve::crowd::CrowdField::setAllCellCost ( float  cost)

把全部格子设为同一地形代价(通常 build 前重置用)。

在文件 CrowdField.cpp 第 116 行定义.

引用了 cost.

◆ setBlocked()

void eve::crowd::CrowdField::setBlocked ( int  cx,
int  cy,
bool  blocked 
)

设置/清除某格阻挡。

参数
cx列
cy行
blockedtrue=阻挡(cost 记为 0)

在文件 CrowdField.cpp 第 84 行定义.

引用了 cx, cy, index , 以及 value.

◆ setCellCost()

void eve::crowd::CrowdField::setCellCost ( int  cx,
int  cy,
float  cost 
)

设置某格地形代价(进入该格的移动成本)。

参数
cost0=阻挡,>=1 可走(越大越难走)

在文件 CrowdField.cpp 第 100 行定义.

引用了 cost, cx, cy, index , 以及 value.

◆ setGoal()

void eve::crowd::CrowdField::setGoal ( int  gx,
int  gy 
)

设定唯一目标格(等价 clearGoals + addGoal)。

参数
gx目标列
gy目标行

在文件 CrowdField.cpp 第 125 行定义.

◆ state()

FieldState eve::crowd::CrowdField::state ( ) const
inlinenoexcept

Distinguish absent, unbuilt, current and stale navigation.

在文件 CrowdField.h 第 112 行定义.

引用了 valid.

◆ valid()

bool eve::crowd::CrowdField::valid ( ) const
inline

是否配置了有效网格。

在文件 CrowdField.h 第 53 行定义.

被这些函数引用 costAtWorld(), flowAtWorld(), resolvePenetration() , 以及 eve::crowd::Crowd::Impl::selectAvoidanceVelocity().

友元及相关函数文档

◆ Crowd

friend class Crowd
friend

在文件 CrowdField.h 第 178 行定义.

类成员变量说明

◆ kUnreachable

constexpr float eve::crowd::CrowdField::kUnreachable = 3.4e38f
staticconstexpr

不可达/阻挡的积分代价。

在文件 CrowdField.h 第 28 行定义.

被这些函数引用 costAtCell(), costAtWorld(), eve::crowd::Crowd::Impl::preparePreferredVelocities() , 以及 resize().


该类的文档由以下文件生成: