Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
SpatialSubdivision Class Reference

A very basic subdivision scheme for finding items in ranges. More...

#include <Spatial.h>

Collaboration diagram for SpatialSubdivision:

Classes

struct  SubDivisionGrid
 

Public Member Functions

 SpatialSubdivision ()
 
 ~SpatialSubdivision ()
 
 SpatialSubdivision (const SpatialSubdivision &rhs)
 
SpatialSubdivisionoperator= (const SpatialSubdivision &rhs)
 
entity_pos_t GetDivisionSize () const
 
uint32_t GetWidth () const
 
uint32_t GetHeight () const
 
void Create (size_t count)
 
bool operator== (const SpatialSubdivision &rhs) const
 Equivalence test (ignoring order of items within each subdivision) More...
 
bool operator!= (const SpatialSubdivision &rhs) const
 
void Reset (entity_pos_t maxX, entity_pos_t maxZ, entity_pos_t divisionSize)
 
void Add (uint32_t item, CFixedVector2D toMin, CFixedVector2D toMax)
 Add an item with the given 'to' size. More...
 
void Remove (uint32_t item, CFixedVector2D fromMin, CFixedVector2D fromMax)
 Remove an item with the given 'from' size. More...
 
void Move (uint32_t item, CFixedVector2D fromMin, CFixedVector2D fromMax, CFixedVector2D toMin, CFixedVector2D toMax)
 Equivalent to Remove() then Add(), but potentially faster. More...
 
void Add (uint32_t item, CFixedVector2D to)
 Convenience function for Add() of individual points. More...
 
void Remove (uint32_t item, CFixedVector2D from)
 Convenience function for Remove() of individual points. More...
 
void Move (uint32_t item, CFixedVector2D from, CFixedVector2D to)
 Convenience function for Move() of individual points. More...
 
void GetInRange (std::vector< uint32_t > &out, CFixedVector2D posMin, CFixedVector2D posMax) const
 Returns a sorted list of unique items that includes all items within the given axis-aligned square range. More...
 
void GetNear (std::vector< uint32_t > &out, CFixedVector2D pos, entity_pos_t range) const
 Returns a sorted list of unique items that includes all items within the given circular distance of the given point. More...
 

Private Member Functions

uint32_t GetI0 (entity_pos_t x) const
 
uint32_t GetJ0 (entity_pos_t z) const
 
uint32_t GetI1 (entity_pos_t x) const
 
uint32_t GetJ1 (entity_pos_t z) const
 
uint32_t GetIndex0 (CFixedVector2D pos) const
 
uint32_t GetIndex1 (CFixedVector2D pos) const
 

Private Attributes

entity_pos_t m_DivisionSize
 
SubDivisionGridm_Divisions
 
uint32_t m_DivisionsW
 
uint32_t m_DivisionsH
 

Friends

struct SerializeHelper< SpatialSubdivision >
 

Detailed Description

A very basic subdivision scheme for finding items in ranges.

Items are stored in lists in dynamic-sized divisions. Items have a size (min/max values of their axis-aligned bounding box) and are stored in all divisions overlapping that area.

It is the caller's responsibility to ensure items are only added once, aren't removed unless they've been added, etc, and that Move/Remove are called with the same coordinates originally passed to Add (since this class doesn't remember which divisions an item occupies).

Constructor & Destructor Documentation

◆ SpatialSubdivision() [1/2]

SpatialSubdivision::SpatialSubdivision ( )
inline

◆ ~SpatialSubdivision()

SpatialSubdivision::~SpatialSubdivision ( )
inline

◆ SpatialSubdivision() [2/2]

SpatialSubdivision::SpatialSubdivision ( const SpatialSubdivision rhs)
inline

Member Function Documentation

◆ Add() [1/2]

void SpatialSubdivision::Add ( uint32_t  item,
CFixedVector2D  to 
)
inline

Convenience function for Add() of individual points.

(Note that points on a boundary may occupy multiple divisions.)

◆ Add() [2/2]

void SpatialSubdivision::Add ( uint32_t  item,
CFixedVector2D  toMin,
CFixedVector2D  toMax 
)
inline

Add an item with the given 'to' size.

The item must not already be present.

◆ Create()

void SpatialSubdivision::Create ( size_t  count)
inline

◆ GetDivisionSize()

entity_pos_t SpatialSubdivision::GetDivisionSize ( ) const
inline

◆ GetHeight()

uint32_t SpatialSubdivision::GetHeight ( ) const
inline

◆ GetI0()

uint32_t SpatialSubdivision::GetI0 ( entity_pos_t  x) const
inlineprivate

◆ GetI1()

uint32_t SpatialSubdivision::GetI1 ( entity_pos_t  x) const
inlineprivate

◆ GetIndex0()

uint32_t SpatialSubdivision::GetIndex0 ( CFixedVector2D  pos) const
inlineprivate

◆ GetIndex1()

uint32_t SpatialSubdivision::GetIndex1 ( CFixedVector2D  pos) const
inlineprivate

◆ GetInRange()

void SpatialSubdivision::GetInRange ( std::vector< uint32_t > &  out,
CFixedVector2D  posMin,
CFixedVector2D  posMax 
) const
inline

Returns a sorted list of unique items that includes all items within the given axis-aligned square range.

◆ GetJ0()

uint32_t SpatialSubdivision::GetJ0 ( entity_pos_t  z) const
inlineprivate

◆ GetJ1()

uint32_t SpatialSubdivision::GetJ1 ( entity_pos_t  z) const
inlineprivate

◆ GetNear()

void SpatialSubdivision::GetNear ( std::vector< uint32_t > &  out,
CFixedVector2D  pos,
entity_pos_t  range 
) const
inline

Returns a sorted list of unique items that includes all items within the given circular distance of the given point.

◆ GetWidth()

uint32_t SpatialSubdivision::GetWidth ( ) const
inline

◆ Move() [1/2]

void SpatialSubdivision::Move ( uint32_t  item,
CFixedVector2D  from,
CFixedVector2D  to 
)
inline

Convenience function for Move() of individual points.

◆ Move() [2/2]

void SpatialSubdivision::Move ( uint32_t  item,
CFixedVector2D  fromMin,
CFixedVector2D  fromMax,
CFixedVector2D  toMin,
CFixedVector2D  toMax 
)
inline

Equivalent to Remove() then Add(), but potentially faster.

◆ operator!=()

bool SpatialSubdivision::operator!= ( const SpatialSubdivision rhs) const
inline

◆ operator=()

SpatialSubdivision & SpatialSubdivision::operator= ( const SpatialSubdivision rhs)
inline

◆ operator==()

bool SpatialSubdivision::operator== ( const SpatialSubdivision rhs) const
inline

Equivalence test (ignoring order of items within each subdivision)

◆ Remove() [1/2]

void SpatialSubdivision::Remove ( uint32_t  item,
CFixedVector2D  from 
)
inline

Convenience function for Remove() of individual points.

◆ Remove() [2/2]

void SpatialSubdivision::Remove ( uint32_t  item,
CFixedVector2D  fromMin,
CFixedVector2D  fromMax 
)
inline

Remove an item with the given 'from' size.

The item should already be present. The size must match the size that was last used when adding the item.

◆ Reset()

void SpatialSubdivision::Reset ( entity_pos_t  maxX,
entity_pos_t  maxZ,
entity_pos_t  divisionSize 
)
inline

Friends And Related Function Documentation

◆ SerializeHelper< SpatialSubdivision >

friend struct SerializeHelper< SpatialSubdivision >
friend

Member Data Documentation

◆ m_Divisions

SubDivisionGrid* SpatialSubdivision::m_Divisions
private

◆ m_DivisionsH

uint32_t SpatialSubdivision::m_DivisionsH
private

◆ m_DivisionSize

entity_pos_t SpatialSubdivision::m_DivisionSize
private

◆ m_DivisionsW

uint32_t SpatialSubdivision::m_DivisionsW
private

The documentation for this class was generated from the following file: