Skip to content

raisin::WorldCells ​

class · #include <rayrai/WorldCells.hpp>

Bounded cell residency planning, independent of rendering and physics. Call plan(), unload released cells, then load the proposed cells on the owning thread. Commit only successful operations. Multiple interests cover viewer cameras, sensor cameras and interacting bodies independently.

Constructors & destructor ​

WorldCells ​

cpp
WorldCells(
    WorldCellBounds bounds,
    double cellSize,
    size_t residentBudget,
    size_t loadBudget=2)

Divide bounds into square cells.

Parameters

ParameterDescription
boundsWorld rectangle; the last row/column of cells is clipped to it.
cellSizeCell edge length.
residentBudgetMaximum number of resident cells.
loadBudgetMaximum number of cells plan() proposes to load per call.

Exceptions

ExceptionDescription
std::invalid_argumenton non-finite or empty bounds, a non-positive cell size, a zero budget, or a grid too large for int32 keys.

Public member functions ​

cellBounds ​

cpp
WorldCellBounds cellBounds(WorldCellKey key) const

Returns World rectangle of key.

Exceptions

ExceptionDescription
std::out_of_rangeoutside the grid.

Parameters

ParameterDescription
keyCell key.

resident ​

cpp
const std::vector<WorldCellKey> &resident() const

Returns Committed resident cells, sorted by WorldCellKey::operator<.

dimensions ​

cpp
glm::ivec2 dimensions() const

Returns Number of cells along x and y.

isResident ​

cpp
bool isResident(WorldCellKey key) const

Parameters

ParameterDescription
keyCell key.

Returns True if key has been committed as loaded.

commitLoad ​

cpp
void commitLoad(WorldCellKey key)

Record a successful load. No-op if already resident; throws std::length_error when the resident budget is full.

Parameters

ParameterDescription
keyLoaded cell.

commitUnload ​

cpp
void commitUnload(WorldCellKey key)

Record an unload; ignores keys that are not resident.

Parameters

ParameterDescription
keyUnloaded cell.

plan ​

cpp
WorldCellPlan plan(std::span<const WorldInterest> interests) const

Propose loads and unloads for the given interests without changing state.

Cells kept only by a retain radius are released first when requested cells need their capacity.

Parameters

ParameterDescription
interestsPoints that want cells resident.

Returns Loads and unloads to perform, then commit.

Exceptions

ExceptionDescription
std::invalid_argumentfor a non-finite interest or retainRadius < loadRadius.
std::length_errorif one interest's load square spans more than one million cells.

Static member functions ​

distanceSquared static ​

cpp
static double distanceSquared(WorldCellBounds bounds, glm::dvec2 position)

Parameters

ParameterDescription
boundsRectangle.
positionPoint.

Returns Squared distance from position to bounds (0 inside).

RaiSim — physics for robotics and AI.