Flatland
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
flatland_server::CollisionFilterRegistry Class Reference

#include <collision_filter_registry.h>

Collaboration diagram for flatland_server::CollisionFilterRegistry:
Collaboration graph
[legend]

Public Member Functions

 CollisionFilterRegistry ()
 Constructor for the collision filter registry.
 
int RegisterCollide ()
 Get a new and unique collision group, +ve numbers.
 
int RegisterNoCollide ()
 Get a new and unique no collision group, -ve numbers.
 
bool IsLayersFull () const
 Check if the number of layers maxed out. More...
 
int RegisterLayer (std::string layer)
 Register a new layer. More...
 
int LookUpLayerId (std::string name) const
 get layer ID More...
 
std::vector< std::string > GetAllLayers () const
 Get all registered layers. More...
 
int LayersCount () const
 Get number of layers. More...
 
uint16_t GetCategoryBits (const std::vector< std::string > &layers, std::vector< std::string > *invalid_layers=nullptr) const
 : Get the Box2D category bits from a list of layers More...
 

Public Attributes

int no_collide_group_cnt_
 internal counter to keep track of no collides groups
 
int collide_group_cnt_
 internal counter to keep track of collide groups
 
std::map< std::string, int > layer_id_table_
 Layer name to ID LUT.
 

Static Public Attributes

static const int LAYER_NOT_EXIST = -1
 No such layer.
 
static const int LAYER_ALREADY_EXIST = -2
 Layer exists.
 
static const int LAYERS_FULL = -3
 Cannot add more layers.
 
static const int MAX_LAYERS = 16
 16 is the maximum as defined by Box2D
 

Detailed Description

This class defines a collision filter registry. It allows layers to register for unique ID's, which are used for setting Box2D collision categories and mask bits. The footprints in the model will use this to put itself on the correct collision category. It also hands out unique collide (positive numbers) and no collide (negative numbers) Box2D collision groups.

Member Function Documentation

std::vector< std::string > flatland_server::CollisionFilterRegistry::GetAllLayers ( ) const

Get all registered layers.

Returns
vector to store layer names in, will be cleared
uint16_t flatland_server::CollisionFilterRegistry::GetCategoryBits ( const std::vector< std::string > &  layers,
std::vector< std::string > *  invalid_layers = nullptr 
) const

: Get the Box2D category bits from a list of layers

Parameters
[in]layersThe layers for generating the category bits, if the input exactly equals to {"all"}, it returns all bits to 1 (0xFFFF)
[out]invalid_layersif a given layer does not exist, it is pushed to this list, optional
bool flatland_server::CollisionFilterRegistry::IsLayersFull ( ) const

Check if the number of layers maxed out.

Returns
if layers are full
int flatland_server::CollisionFilterRegistry::LayersCount ( ) const

Get number of layers.

Returns
number of layers
int flatland_server::CollisionFilterRegistry::LookUpLayerId ( std::string  name) const

get layer ID

Parameters
[in]nameName of the layer
Returns
the id of the layer, or LAYER_NOT_EXIST
int flatland_server::CollisionFilterRegistry::RegisterLayer ( std::string  layer)

Register a new layer.

Parameters
[in]layerName of the layer
Returns
assigned ID for the registered layer, or error codes LAYERS_FULL or LAYER_ALREADY_EXIST

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