TurtleBrains  0.2.1
High quality, portable, C++ API for native application and game development.
tb_tile_system.h
1 
9 #ifndef _TurtleBrains_TileSystem_h_
10 #define _TurtleBrains_TileSystem_h_
11 
12 #include "../core/tb_string.h"
13 #include "../core/tb_dynamic_structure.h"
14 #include "../graphics/tb_graphic_list.h"
15 #include "../graphics/tb_sprite_map.h"
16 #include "../math/tb_vector.h"
17 
18 #include <vector>
19 #include <map>
20 
21 namespace tbImplementation
22 {
23  class TileSystemRenderer;
24 };
25 
26 namespace TurtleBrains { namespace Game { namespace Unstable { class TileSystemCollider; }; }; };
27 namespace TurtleBrains { namespace Math { namespace Unstable { class BoundingVolume; }; }; };
28 
29 namespace TurtleBrains
30 {
31  namespace Game
32  {
33 
41 
45  extern const TileIndex kInvalidTileIndex;
46 
51 
52  extern const TileLocation kInvalidTileLocation;
53 
55 
56  extern const TileSetIndex kInvalidTileSetIndex;
57 
61  struct AboutTile
62  {
63  TileLocation mRow;
64  TileLocation mColumn;
65  TileIndex mTileIndex;
68 
69  float mCenterX;
70  float mCenterY;
71  float mTop;
72  float mLeft;
73  float mWidth;
74  float mHeight;
76  };
77 
78  typedef std::vector<AboutTile> AboutTileContainer;
79 
90  {
91  public:
92 
96  TileSystem(void);
97 
101  virtual ~TileSystem(void);
102 
107  void ClearMap(void);
108 
112  tbCore::tbString GetMapPropertyAsString(const tbCore::tbString& propertyName) const;
113 
117  int GetMapPropertyAsInteger(const tbCore::tbString& propertyName) const;
118 
122  bool GetMapPropertyAsBoolean(const tbCore::tbString& propertyName) const;
123 
127  void SetPropertiesForMap(const tbCore::DynamicStructure& mapProperties);
128 
132  void AddTileSet(const tbCore::tbString& tilesetName, const tbGraphics::SpriteMap& spriteMap,
134 
138 // void SetFlagsForTile(const tbCore::tbString& tileSetName, const TileIndex& tileIndex, const TileFlags& tileFlags);
139 
143  AboutTileContainer FindTilesWithProperty(const tbCore::tbString& tileProperty, bool onlyVisibleLayers = false) const;
144 
148  AboutTileContainer FindTilesWithPropertyEquals(const tbCore::tbString& tileProperty, bool propertyValue, bool onlyVisibleLayers = false) const;
149 
153  AboutTileContainer FindTilesWithPropertyEquals(const tbCore::tbString& tileProperty, int propertyValue, bool onlyVisibleLayers = false) const;
154 
158  AboutTileContainer FindTilesWithPropertyEquals(const tbCore::tbString& tileProperty, const tbCore::tbString& propertyValue, bool onlyVisibleLayers = false) const;
159 
163  void SetPropertiesForTile(const tbCore::tbString& tileSetName, const TileIndex& tileIndex, const tbCore::DynamicStructure& tileProperties);
164 
168  tbCore::tbString GetTilePropertyAsString(const tbCore::tbString& tileSetName, const TileIndex& tileIndex, const tbCore::tbString& propertyName) const;
169 
173  int GetTilePropertyAsInteger(const tbCore::tbString& tileSetName, const TileIndex& tileIndex, const tbCore::tbString& propertyName) const;
174 
178  bool GetTilePropertyAsBoolean(const tbCore::tbString& tileSetName, const TileIndex& tileIndex, const tbCore::tbString& propertyName) const;
179 
183  void SetTileProperty(const tbCore::tbString& tileSetName, const TileIndex& tileIndex,
184  const tbCore::tbString& propertyName, const tbCore::tbString& propertyValue);
185 
189  void SetTileProperty(const tbCore::tbString& tileSetName, const TileIndex& tileIndex,
190  const tbCore::tbString& propertyName, const int propertyValue);
191 
195  void SetTileProperty(const tbCore::tbString& tileSetName, const TileIndex& tileIndex,
196  const tbCore::tbString& propertyName, const bool propertyValue);
197 
201  void AddTileLayer(const tbCore::tbString& tileLayerName, const std::vector<TileIndex>& tileData,
202  const tbCore::tbString& tileSetName, const TileLocation& columnCount, const TileLocation& rowCount);
203 
207  void AddTileLayer(const tbCore::tbString& tileLayerName, const std::vector<TileIndex>& tileData,
208  const std::vector<TileSetIndex>& tileSetData, const TileLocation& columnCount, const TileLocation& rowCount);
209 
213  void SetLayerVisible(const tbCore::tbString& tileLayerName, const bool isVisible);
214 
218  void SetTile(const tbCore::tbString& tileLayerName, const TileLocation& tileColumn, const TileLocation& tileRow,
219  const TileIndex& toTileIndex, const TileSetIndex& toTileSetIndex = kInvalidTileSetIndex);
220 
224  //
225  //
226  //
227  //bool Move(const tbGame::Entity& entity, const tbMath::Vector2& from, tbMath::Vector2& to);
228  //bool Move(const tbMath::Unstable::BoundingVolume& boundingVolume, const tbMath::Vector2& centerFrom, tbMath::Vector2& centerTo)
229 
233  bool MoveEntity(const tbMath::Vector2& currentPosition, tbMath::Vector2& finalPosition,
234  const TurtleBrains::Math::Unstable::BoundingVolume& boundingVolume) const;
235 
239  bool IsPointInSolid(const tbMath::Vector2& pointPosition) const;
240 
244  void UpdateColliderInformation(void);
245 
247 // TileLocation PixelSpaceToColumn(const float locationX) const;
248 // TileLocation PixelSpaceToRow(const float locationY) const;
249 // float ColumnToPixelSpace(const TileLocation& column) const;
250 // float RowToPixelSpace(const TileLocation& row) const;
252 
253  protected:
254 
258  virtual void OnRender(void) const override;
259 
260  private:
261  const tbCore::DynamicStructure& GetTileProperties(const tbCore::tbString& tileSetName, const TileIndex& tileIndex) const;
262  tbCore::DynamicStructure& GetTileProperties(const tbCore::tbString& tileSetName, const TileIndex& tileIndex);
263 
264  struct TileLayer
265  {
266  tbMath::Vector2 mPosition;
267  TileLocation mTileColumns;
268  TileLocation mTileRows;
269  typedef std::vector<TileIndex> TileContainer;
270  TileContainer mTileData; //(TileIndex)-1 = no tile, 0 based on the TileSetData it lies upon.
271  typedef std::vector<TileSetIndex> TileSetContainer;
272  TileSetContainer mTileSetData; //Will be size 1 for a single Tileset, index into ordered names. Not yet implemented ...
273 
274  bool mIsVisible;
275  };
276 
277  struct TileSet
278  {
279  TileSet(const tbGraphics::SpriteMap& spriteMap);
280 
281  tbGraphics::SpriteMap mSpriteMap;
282  //TileIndex mStartTileID; //May be unneeded.
283  //TileIndex mFinalTileID; //May be unneeded.
284 
285  //Stored as the index of the tile in this tile set, so 0 would be top-left most tile in SpriteMap.
286 // typedef std::map<tbCore::uint16, std::pair<TileFlags, tbCore::DynamicStructure> > TilePropertyTable;
287  typedef std::map<tbCore::uint16, tbCore::DynamicStructure> TilePropertyTable;
288  TilePropertyTable mTileProperties;
289  tbCore::DynamicStructure mTileSetProperties;
290  };
291 
292  typedef std::vector<tbCore::tbString> NameContainer;
293  typedef std::map<tbCore::tbString, TileLayer> TileLayerTable;
294  TileLayerTable mTileLayers;
295  NameContainer mOrderedLayerNames;
296  NameContainer mOrderedTileSetNames;
297 
298  typedef std::map<tbCore::tbString, TileSet> TileSetTable;
299  TileSetTable mTileSets;
300  tbCore::DynamicStructure mMapProperties;
301 
304  typedef std::map<tbCore::tbString, tbImplementation::TileSystemRenderer*> LayerRendererTable;
305  mutable LayerRendererTable mLayerRenderers;
306 
307  TurtleBrains::Game::Unstable::TileSystemCollider* mCollider;
308  };
309 
310  namespace Extensions
311  {
316  bool LoadTileSystemFromTiled(TileSystem& tileSystem, const tbCore::tbString& tiledFilepath);
317  };
318 
319  }; /* namespace Game */
320 }; /* namespace TurtleBrains */
321 
322 namespace tbGame = TurtleBrains::Game;
323 
324 #endif /* _TurtleBrains_TileSystem_h_ */
Definition: tb_vector.h:47
TileIndex mTileIndex
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:65
Definition: tb_graphic.h:61
int GetMapPropertyAsInteger(const tbCore::tbString &propertyName) const
bool IsPointInSolid(const tbMath::Vector2 &pointPosition) const
float mCenterY
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:70
void AddTileSet(const tbCore::tbString &tilesetName, const tbGraphics::SpriteMap &spriteMap, const tbCore::DynamicStructure &tileSetProperties=tbCore::DynamicStructure::kNullValue)
AboutTileContainer FindTilesWithProperty(const tbCore::tbString &tileProperty, bool onlyVisibleLayers=false) const
virtual void OnRender(void) const override
float mHeight
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:74
float mCenterX
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:69
uint16_t uint16
Unsigned integer with a size of 16 bits. Supports values from 0 to 65535.
Definition: tb_types.h:25
static const DynamicStructure kNullValue
Definition: tb_dynamic_structure.h:556
Definition: tb_tile_system.h:89
Definition: tb_noncopyable.h:22
Contains all functions, classes and helpers related to game/application development written by Tim "B...
Definition: tb_application_dialog.h:21
bool MoveEntity(const tbMath::Vector2 &currentPosition, tbMath::Vector2 &finalPosition, const TurtleBrains::Math::Unstable::BoundingVolume &boundingVolume) const
const TileSetIndex kInvalidTileSetIndex
TODO: TIM: Documentation: Teach the user how to use this.
int GetTilePropertyAsInteger(const tbCore::tbString &tileSetName, const TileIndex &tileIndex, const tbCore::tbString &propertyName) const
void SetLayerVisible(const tbCore::tbString &tileLayerName, const bool isVisible)
tbCore::tbString mLayerName
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:67
void SetPropertiesForMap(const tbCore::DynamicStructure &mapProperties)
bool GetTilePropertyAsBoolean(const tbCore::tbString &tileSetName, const TileIndex &tileIndex, const tbCore::tbString &propertyName) const
std::vector< AboutTile > AboutTileContainer
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:78
tbCore::uint16 TileIndex
Definition: tb_tile_system.h:40
uint8_t uint8
Unsigned integer with a size of 8 bits. Supports values from 0 to 255.
Definition: tb_types.h:23
TileLocation mRow
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:63
Definition: tbu_bounding_volume.h:24
tbCore::DynamicStructure mPropertyValue
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:75
void SetTile(const tbCore::tbString &tileLayerName, const TileLocation &tileColumn, const TileLocation &tileRow, const TileIndex &toTileIndex, const TileSetIndex &toTileSetIndex=kInvalidTileSetIndex)
tbCore::tbString GetTilePropertyAsString(const tbCore::tbString &tileSetName, const TileIndex &tileIndex, const tbCore::tbString &propertyName) const
Definition: tb_tile_system.h:61
Definition: tb_dynamic_structure.h:28
float mWidth
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:73
tbCore::uint16 TileLocation
Definition: tb_tile_system.h:50
Definition: tb_sprite_map.h:23
tbCore::tbString mTileSetName
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:66
void AddTileLayer(const tbCore::tbString &tileLayerName, const std::vector< TileIndex > &tileData, const tbCore::tbString &tileSetName, const TileLocation &columnCount, const TileLocation &rowCount)
AboutTileContainer FindTilesWithPropertyEquals(const tbCore::tbString &tileProperty, bool propertyValue, bool onlyVisibleLayers=false) const
void SetTileProperty(const tbCore::tbString &tileSetName, const TileIndex &tileIndex, const tbCore::tbString &propertyName, const tbCore::tbString &propertyValue)
const TileLocation kInvalidTileLocation
TODO: TIM: Documentation: Teach the user how to use this.
float mTop
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:71
void SetPropertiesForTile(const tbCore::tbString &tileSetName, const TileIndex &tileIndex, const tbCore::DynamicStructure &tileProperties)
tbCore::tbString GetMapPropertyAsString(const tbCore::tbString &propertyName) const
float mLeft
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:72
const TileIndex kInvalidTileIndex
bool GetMapPropertyAsBoolean(const tbCore::tbString &propertyName) const
std::string tbString
Definition: tb_string.h:335
This is the heart of TurtleBrains for game developers to create GameScenes and Entities to interact w...
tbCore::uint8 TileSetIndex
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:54
Definition: tb_application_dialog.h:19
TileLocation mColumn
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:64