载入中...
搜索中...
未找到
eve::hexmap::HexUnitRegistry类 参考

Owns the units of one map and their fog-of-war contribution. 更多...

#include <HexUnits.h>

Public 成员函数

 HexUnitRegistry ()=default
 Hex unit registry.
 
const HexUnitTuning & tuning () const noexcept
 Current tuning.
 
void setTuning (const HexUnitTuning &tuning) noexcept
 Replaces the tuning; ongoing travel keeps its plan but uses the new speed.
 
bool empty () const noexcept
 Whether no unit is registered.
 
std::int32_t unitCount () const noexcept
 Number of registered units.
 
Result< std::int32_t > addUnit (HexMap &map, HexVisibility &visibility, HexSearchContext &scratch, HexCoordinates location, float orientation)
 Adds a unit on location and grants its vision.
 
Result< void > removeUnit (HexMap &map, HexVisibility &visibility, HexSearchContext &scratch, std::int32_t unitId)
 Removes a unit and withdraws its vision.
 
void removeAll (HexMap &map, HexVisibility &visibility) noexcept
 Removes every unit and clears the visibility counters of the map.
 
std::int32_t unitIdAt (HexCoordinates coordinates) const noexcept
 Id of the unit occupying a cell, or -1 when the cell is free.
 
bool isOccupied (HexCoordinates coordinates) const noexcept
 Whether any unit occupies a cell.
 
HexOccupancyQuery occupancyQuery () const
 Occupancy predicate bound to this registry. @ownership The returned callable borrows *this; it must not outlive the registry.
 
Result< void > beginTravel (HexMap &map, HexVisibility &visibility, HexSearchContext &scratch, std::int32_t unitId, const std::vector< std::int32_t > &path)
 Starts travelling along path.
 
Result< HexUnitSample > advance (HexMap &map, HexVisibility &visibility, HexSearchContext &scratch, std::int32_t unitId, float dt)
 Advances one unit's travel by dt seconds and reports where it now is.
 
void advanceAll (HexMap &map, HexVisibility &visibility, HexSearchContext &scratch, float dt)
 Advances every travelling unit by dt seconds.
 
void refreshVisibility (HexMap &map, HexVisibility &visibility, HexSearchContext &scratch)
 Re-derives the whole fog of war from the units' current cells.
 
void refreshPositions (const HexMap &map) noexcept
 Re-snaps every idle unit onto its cell's current position.
 
std::vector< HexUnitState > snapshot () const
 Serializable state of every unit, in id order.
 
Result< void > restore (HexMap &map, HexVisibility &visibility, HexSearchContext &scratch, const std::vector< HexUnitState > &states)
 Replaces every unit with states, granting their vision.
 

详细描述

Owns the units of one map and their fog-of-war contribution.

A unit reserves its destination cell as soon as travel starts, exactly like the reference project: the destination is what other actors path around, and the travelled-through cells are never occupied. Vision moves with the unit as it enters each cell of the path, so the revealed corridor follows the walk.

Ownership and lifetime: owns one record per unit and one travel plan per travelling unit. occupancyQuery() returns a std::function that borrows *this; it stays valid only while this registry is alive and unmodified.

Thread affinity: main thread only; no locking and no callbacks.

在文件 HexUnits.h 第 69 行定义.

构造及析构函数说明

◆ HexUnitRegistry()

eve::hexmap::HexUnitRegistry::HexUnitRegistry ( )
default

Hex unit registry.

成员函数说明

◆ addUnit()

Result< std::int32_t > eve::hexmap::HexUnitRegistry::addUnit ( HexMap &  map,
HexVisibility &  visibility,
HexSearchContext &  scratch,
HexCoordinates  location,
float  orientation 
)

Adds a unit on location and grants its vision.

参数
mapMap the unit is placed on.
visibilityFog-of-war state to update.
scratchSearch scratch, resized to map.cellCount().
locationCell to occupy; must be inside the grid and free.
orientationInitial facing angle in degrees.
返回
The new unit id, or InvalidArgument when the cell is outside the grid or already occupied. @cost One visibility sweep over the unit's vision radius.

在文件 HexUnits.cpp 第 139 行定义.

引用了 eve::hexmap::HexMap::contains(), eve::hexmap::HexMap::empty(), eve::Result< T >::failure(), eve::hexmap::HexVisibility::increase(), eve::hexmap::HexMap::indexOf(), isOccupied(), eve::Result< T >::success(), unit , 以及 eve::hexmap::HexUnitTuning::visionRange.

◆ advance()

Result< HexUnitSample > eve::hexmap::HexUnitRegistry::advance ( HexMap &  map,
HexVisibility &  visibility,
HexSearchContext &  scratch,
std::int32_t  unitId,
float  dt 
)

Advances one unit's travel by dt seconds and reports where it now is.

This is also the single way to read a unit's current pose: dt <= 0 performs no motion and no turning, so a caller that only wants to draw an idle unit calls this with a zero delta and uses the returned sample. The sample's position is elevation- and perturbation-aware and interpolated along the travel curve, which is what a renderable needs.

参数
mapMap the unit lives on.
visibilityFog-of-war state to update as the unit crosses cells.
scratchSearch scratch.
unitIdUnit to advance.
dtElapsed seconds; values <= 0 leave both position and facing alone.
返回
The updated sample, or NotFound for an unknown id. @cost One visibility sweep per cell crossed.

在文件 HexUnits.cpp 第 275 行定义.

引用了 eve::hexmap::HexMap::coordinatesAt(), eve::hexmap::HexVisibility::decrease(), eve::Result< T >::failure(), heading, eve::hexmap::HexVisibility::increase(), left, right, eve::hexmap::HexUnitTuning::rotationSpeed, step, eve::hexmap::HexUnitTuning::travelSpeed, turn, unit, eve::hexmap::HexUnitTuning::visionRange, eve::hexmap::HexVec3::x , 以及 eve::hexmap::HexVec3::z.

被这些函数引用 advanceAll().

◆ advanceAll()

void eve::hexmap::HexUnitRegistry::advanceAll ( HexMap &  map,
HexVisibility &  visibility,
HexSearchContext &  scratch,
float  dt 
)

Advances every travelling unit by dt seconds.

在文件 HexUnits.cpp 第 320 行定义.

引用了 advance(), count , 以及 unitCount().

◆ beginTravel()

Result< void > eve::hexmap::HexUnitRegistry::beginTravel ( HexMap &  map,
HexVisibility &  visibility,
HexSearchContext &  scratch,
std::int32_t  unitId,
const std::vector< std::int32_t > &  path 
)

Starts travelling along path.

path holds linear cell indices from the unit's current cell to the destination, inclusive, as produced by findPath. The destination is reserved immediately; visibility moves to the first step and then follows the walk, so the fog is revealed along the corridor the unit walks.

参数
mapMap the unit lives on.
visibilityFog-of-war state to update.
scratchSearch scratch.
unitIdUnit to move.
pathCell indices to walk.
返回
Success, or InvalidArgument for an unknown id, a path that does not start on the unit's cell, a non-adjacent step, or an out-of-range index. @cost One visibility sweep when the unit leaves its cell and one when it enters.

在文件 HexUnits.cpp 第 219 行定义.

引用了 eve::hexmap::HexMap::cellCount(), eve::hexmap::HexMap::coordinatesAt(), eve::hexmap::HexVisibility::decrease(), eve::hexmap::HexCoordinates::distanceTo(), eve::Result< T >::failure(), eve::Result< void >::ignore(), eve::hexmap::HexVisibility::increase(), index, eve::hexmap::isValidDestination(), origin, path, eve::Result< T >::success(), unit , 以及 eve::hexmap::HexUnitTuning::visionRange.

◆ empty()

bool eve::hexmap::HexUnitRegistry::empty ( ) const
inlinenoexcept

Whether no unit is registered.

在文件 HexUnits.h 第 80 行定义.

◆ isOccupied()

bool eve::hexmap::HexUnitRegistry::isOccupied ( HexCoordinates  coordinates) const
inlinenoexcept

Whether any unit occupies a cell.

在文件 HexUnits.h 第 118 行定义.

被这些函数引用 addUnit() , 以及 occupancyQuery().

◆ occupancyQuery()

HexOccupancyQuery eve::hexmap::HexUnitRegistry::occupancyQuery ( ) const

Occupancy predicate bound to this registry. @ownership The returned callable borrows *this; it must not outlive the registry.

在文件 HexUnits.cpp 第 130 行定义.

引用了 isOccupied().

◆ refreshPositions()

void eve::hexmap::HexUnitRegistry::refreshPositions ( const HexMap &  map)
noexcept

Re-snaps every idle unit onto its cell's current position.

在文件 HexUnits.cpp 第 345 行定义.

引用了 eve::hexmap::HexMap::cellCount() , 以及 unit.

◆ refreshVisibility()

void eve::hexmap::HexUnitRegistry::refreshVisibility ( HexMap &  map,
HexVisibility &  visibility,
HexSearchContext &  scratch 
)

Re-derives the whole fog of war from the units' current cells.

Use after loading a map, after the terrain changed, or after a bulk edit invalidated the counters.

@cost One visibility sweep per unit.

在文件 HexUnits.cpp 第 332 行定义.

引用了 eve::hexmap::HexVisibility::clear(), eve::hexmap::HexMap::coordinatesAt(), eve::hexmap::HexVisibility::increase(), unit , 以及 eve::hexmap::HexUnitTuning::visionRange.

被这些函数引用 restore().

◆ removeAll()

void eve::hexmap::HexUnitRegistry::removeAll ( HexMap &  map,
HexVisibility &  visibility 
)
noexcept

Removes every unit and clears the visibility counters of the map.

参数
mapThe annotated map, whose fog chunks are dirtied for every cell that loses its last viewer.
visibilityCounters to clear.

在文件 HexUnits.cpp 第 187 行定义.

被这些函数引用 eve::hexmap::HexMapModule::adoptGrid(), eve::hexmap::HexMapModule::applyTerrain() , 以及 eve::hexmap::HexMapModule::newGrid().

◆ removeUnit()

Result< void > eve::hexmap::HexUnitRegistry::removeUnit ( HexMap &  map,
HexVisibility &  visibility,
HexSearchContext &  scratch,
std::int32_t  unitId 
)

Removes a unit and withdraws its vision.

返回
Success, or NotFound for an unknown id.

在文件 HexUnits.cpp 第 165 行定义.

引用了 eve::hexmap::HexMap::coordinatesAt(), eve::hexmap::HexVisibility::decrease(), eve::Result< T >::failure(), eve::Result< T >::success(), unit , 以及 eve::hexmap::HexUnitTuning::visionRange.

◆ restore()

Result< void > eve::hexmap::HexUnitRegistry::restore ( HexMap &  map,
HexVisibility &  visibility,
HexSearchContext &  scratch,
const std::vector< HexUnitState > &  states 
)

Replaces every unit with states, granting their vision.

The registry is cleared first; a failure leaves it empty rather than partially populated.

返回
Success, or InvalidArgument for an out-of-range or duplicated cell.

在文件 HexUnits.cpp 第 375 行定义.

引用了 eve::hexmap::HexMap::cellCount(), eve::hexmap::HexVisibility::clear(), eve::hexmap::HexMap::coordinatesAt(), eve::Result< T >::failure(), eve::hexmap::isValidDestination(), refreshVisibility(), state, eve::Result< T >::success() , 以及 unit.

被这些函数引用 eve::hexmap::HexMapModule::adoptGrid().

◆ setTuning()

void eve::hexmap::HexUnitRegistry::setTuning ( const HexUnitTuning &  tuning)
inlinenoexcept

Replaces the tuning; ongoing travel keeps its plan but uses the new speed.

在文件 HexUnits.h 第 77 行定义.

◆ snapshot()

std::vector< HexUnitState > eve::hexmap::HexUnitRegistry::snapshot ( ) const

Serializable state of every unit, in id order.

在文件 HexUnits.cpp 第 363 行定义.

引用了 state , 以及 unit.

◆ tuning()

const HexUnitTuning & eve::hexmap::HexUnitRegistry::tuning ( ) const
inlinenoexcept

Current tuning.

在文件 HexUnits.h 第 75 行定义.

◆ unitCount()

std::int32_t eve::hexmap::HexUnitRegistry::unitCount ( ) const
inlinenoexcept

Number of registered units.

在文件 HexUnits.h 第 82 行定义.

被这些函数引用 advanceAll().

◆ unitIdAt()

std::int32_t eve::hexmap::HexUnitRegistry::unitIdAt ( HexCoordinates  coordinates) const
noexcept

Id of the unit occupying a cell, or -1 when the cell is free.

在文件 HexUnits.cpp 第 117 行定义.

引用了 index.


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