Flatland
collision_filter_registry.h
1 /*
2  * ______ __ __ __
3  * /\ _ \ __ /\ \/\ \ /\ \__
4  * \ \ \L\ \ __ __ /\_\ \_\ \ \ \____ ___\ \ ,_\ ____
5  * \ \ __ \/\ \/\ \\/\ \ /'_` \ \ '__`\ / __`\ \ \/ /',__\
6  * \ \ \/\ \ \ \_/ |\ \ \/\ \L\ \ \ \L\ \/\ \L\ \ \ \_/\__, `\
7  * \ \_\ \_\ \___/ \ \_\ \___,_\ \_,__/\ \____/\ \__\/\____/
8  * \/_/\/_/\/__/ \/_/\/__,_ /\/___/ \/___/ \/__/\/___/
9  * @copyright Copyright 2017 Avidbots Corp.
10  * @name collision_filter_registry.h
11  * @brief Defines Collision Filter Registrar
12  * @author Chunshang Li
13  *
14  * Software License Agreement (BSD License)
15  *
16  * Copyright (c) 2017, Avidbots Corp.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions
21  * are met:
22  *
23  * * Redistributions of source code must retain the above copyright
24  * notice, this list of conditions and the following disclaimer.
25  * * Redistributions in binary form must reproduce the above
26  * copyright notice, this list of conditions and the following
27  * disclaimer in the documentation and/or other materials provided
28  * with the distribution.
29  * * Neither the name of the Avidbots Corp. nor the names of its
30  * contributors may be used to endorse or promote products derived
31  * from this software without specific prior written permission.
32  *
33  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
36  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
38  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
39  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
40  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
43  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44  * POSSIBILITY OF SUCH DAMAGE.
45  */
46 
47 #ifndef FLATLAND_SERVER_COLLISION_FILTER_REGISTRY_H
48 #define FLATLAND_SERVER_COLLISION_FILTER_REGISTRY_H
49 
50 #include <map>
51 #include <string>
52 #include <vector>
53 
54 namespace flatland_server {
55 
64  public:
65  static const int LAYER_NOT_EXIST = -1;
66  static const int LAYER_ALREADY_EXIST = -2;
67  static const int LAYERS_FULL = -3;
68  static const int MAX_LAYERS = 16;
69 
74  std::map<std::string, int> layer_id_table_;
75 
80 
84  int RegisterCollide();
85 
89  int RegisterNoCollide();
90 
95  bool IsLayersFull() const;
96 
103  int RegisterLayer(std::string layer);
104 
110  int LookUpLayerId(std::string name) const;
111 
116  std::vector<std::string> GetAllLayers() const;
117 
122  int LayersCount() const;
123 
131  uint16_t GetCategoryBits(
132  const std::vector<std::string> &layers,
133  std::vector<std::string> *invalid_layers = nullptr) const;
134 };
135 }; // namespace flatland_server
136 #endif // FLATLAND_SERVER_COLLISION_FILTER_REGISTRY_H
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
Definition: collision_filter_registry.cpp:124
Definition: collision_filter_registry.h:63
static const int LAYER_ALREADY_EXIST
Layer exists.
Definition: collision_filter_registry.h:66
int RegisterNoCollide()
Get a new and unique no collision group, -ve numbers.
Definition: collision_filter_registry.cpp:64
int LayersCount() const
Get number of layers.
Definition: collision_filter_registry.cpp:120
static const int MAX_LAYERS
16 is the maximum as defined by Box2D
Definition: collision_filter_registry.h:68
bool IsLayersFull() const
Check if the number of layers maxed out.
Definition: collision_filter_registry.cpp:69
Definition: body.h:55
std::vector< std::string > GetAllLayers() const
Get all registered layers.
Definition: collision_filter_registry.cpp:109
int RegisterLayer(std::string layer)
Register a new layer.
Definition: collision_filter_registry.cpp:73
CollisionFilterRegistry()
Constructor for the collision filter registry.
Definition: collision_filter_registry.cpp:56
int no_collide_group_cnt_
internal counter to keep track of no collides groups
Definition: collision_filter_registry.h:71
static const int LAYER_NOT_EXIST
No such layer.
Definition: collision_filter_registry.h:65
static const int LAYERS_FULL
Cannot add more layers.
Definition: collision_filter_registry.h:67
int RegisterCollide()
Get a new and unique collision group, +ve numbers.
Definition: collision_filter_registry.cpp:59
int collide_group_cnt_
internal counter to keep track of collide groups
Definition: collision_filter_registry.h:73
std::map< std::string, int > layer_id_table_
Layer name to ID LUT.
Definition: collision_filter_registry.h:74
int LookUpLayerId(std::string name) const
get layer ID
Definition: collision_filter_registry.cpp:102