TurtleBrains  0.3.1
High quality, portable, C++ framework for rapid 2D 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  class Entity; //Forward declare for MoveEntity method.
34 
41  typedef tbCore::uint16 TileIndex;
42 
46  extern const TileIndex kInvalidTileIndex;
47 
52 
53  extern const TileLocation kInvalidTileLocation;
54 
56 
57  extern const TileSetIndex kInvalidTileSetIndex;
58 
62  struct AboutTile
63  {
64  TileLocation mRow;
65  TileLocation mColumn;
66  TileIndex mTileIndex;
69 
70  float mCenterX;
71  float mCenterY;
72  float mTop;
73  float mLeft;
74  float mWidth;
75  float mHeight;
77  };
78 
79  typedef std::vector<AboutTile> AboutTileContainer;
80 
91  {
92  public:
93 
97  TileSystem(void);
98 
102  virtual ~TileSystem(void);
103 
108  void ClearMap(void);
109 
113  tbCore::tbString GetMapPropertyAsString(const tbCore::tbString& propertyName) const;
114 
118  int GetMapPropertyAsInteger(const tbCore::tbString& propertyName) const;
119 
123  bool GetMapPropertyAsBoolean(const tbCore::tbString& propertyName) const;
124 
128  void SetPropertiesForMap(const tbCore::DynamicStructure& mapProperties);
129 
133  void AddTileSet(const tbCore::tbString& tilesetName, const tbGraphics::SpriteMap& spriteMap,
135 
139 // void SetFlagsForTile(const tbCore::tbString& tileSetName, const TileIndex& tileIndex, const TileFlags& tileFlags);
140 
144  AboutTileContainer FindTilesWithProperty(const tbCore::tbString& tileProperty, bool onlyVisibleLayers = false) const;
145 
149  AboutTileContainer FindTilesWithPropertyEquals(const tbCore::tbString& tileProperty, bool propertyValue, bool onlyVisibleLayers = false) const;
150 
154  AboutTileContainer FindTilesWithPropertyEquals(const tbCore::tbString& tileProperty, int propertyValue, bool onlyVisibleLayers = false) const;
155 
159  AboutTileContainer FindTilesWithPropertyEquals(const tbCore::tbString& tileProperty, const tbCore::tbString& propertyValue, bool onlyVisibleLayers = false) const;
160 
164  void SetPropertiesForTile(const tbCore::tbString& tileSetName, const TileIndex& tileIndex, const tbCore::DynamicStructure& tileProperties);
165 
169  tbCore::tbString GetTilePropertyAsString(const tbCore::tbString& tileSetName, const TileIndex& tileIndex, const tbCore::tbString& propertyName) const;
170 
174  int GetTilePropertyAsInteger(const tbCore::tbString& tileSetName, const TileIndex& tileIndex, const tbCore::tbString& propertyName) const;
175 
179  bool GetTilePropertyAsBoolean(const tbCore::tbString& tileSetName, const TileIndex& tileIndex, const tbCore::tbString& propertyName) const;
180 
184  void SetTileProperty(const tbCore::tbString& tileSetName, const TileIndex& tileIndex,
185  const tbCore::tbString& propertyName, const tbCore::tbString& propertyValue);
186 
190  void SetTileProperty(const tbCore::tbString& tileSetName, const TileIndex& tileIndex,
191  const tbCore::tbString& propertyName, const int propertyValue);
192 
196  void SetTileProperty(const tbCore::tbString& tileSetName, const TileIndex& tileIndex,
197  const tbCore::tbString& propertyName, const bool propertyValue);
198 
202  void AddTileLayer(const tbCore::tbString& tileLayerName, const std::vector<TileIndex>& tileData,
203  const tbCore::tbString& tileSetName, const TileLocation& columnCount, const TileLocation& rowCount);
204 
208  void AddTileLayer(const tbCore::tbString& tileLayerName, const std::vector<TileIndex>& tileData,
209  const std::vector<TileSetIndex>& tileSetData, const TileLocation& columnCount, const TileLocation& rowCount);
210 
214  void SetLayerVisible(const tbCore::tbString& tileLayerName, const bool isVisible);
215 
219  void SetTile(const tbCore::tbString& tileLayerName, const TileLocation& tileColumn, const TileLocation& tileRow,
220  const TileIndex& toTileIndex, const TileSetIndex& toTileSetIndex = kInvalidTileSetIndex);
221 
225  //
226  //
227  //
228  //bool Move(const tbGame::Entity& entity, const tbMath::Vector2& from, tbMath::Vector2& to);
229  //bool Move(const tbMath::Unstable::BoundingVolume& boundingVolume, const tbMath::Vector2& centerFrom, tbMath::Vector2& centerTo)
230 
234  bool MoveEntity(const tbMath::Vector2& currentPosition, tbMath::Vector2& finalPosition,
235  const TurtleBrains::Math::Unstable::BoundingVolume& boundingVolume) const;
236 
240  bool MoveEntity(Entity& entity, const tbMath::Vector2& fromOldPosition, const tbMath::Vector2& toNewPosition) const;
241 
245  bool IsPointInSolid(const tbMath::Vector2& pointPosition) const;
246 
250  void UpdateColliderInformation(void);
251 
253 // TileLocation PixelSpaceToColumn(const float locationX) const;
254 // TileLocation PixelSpaceToRow(const float locationY) const;
255 // float ColumnToPixelSpace(const TileLocation& column) const;
256 // float RowToPixelSpace(const TileLocation& row) const;
258 
259  protected:
260 
264  virtual void OnRender(void) const override;
265 
266  private:
267  const tbCore::DynamicStructure& GetTileProperties(const tbCore::tbString& tileSetName, const TileIndex& tileIndex) const;
268  tbCore::DynamicStructure& GetTileProperties(const tbCore::tbString& tileSetName, const TileIndex& tileIndex);
269 
270  struct TileLayer
271  {
272  tbMath::Vector2 mPosition;
273  TileLocation mTileColumns;
274  TileLocation mTileRows;
275  typedef std::vector<TileIndex> TileContainer;
276  TileContainer mTileData; //(TileIndex)-1 = no tile, 0 based on the TileSetData it lies upon.
277  typedef std::vector<TileSetIndex> TileSetContainer;
278  TileSetContainer mTileSetData; //Will be size 1 for a single Tileset, index into ordered names. Not yet implemented ...
279 
280  bool mIsVisible;
281  };
282 
283  struct TileSet
284  {
285  TileSet(const tbGraphics::SpriteMap& spriteMap);
286 
287  tbGraphics::SpriteMap mSpriteMap;
288  //TileIndex mStartTileID; //May be unneeded.
289  //TileIndex mFinalTileID; //May be unneeded.
290 
291  //Stored as the index of the tile in this tile set, so 0 would be top-left most tile in SpriteMap.
292 // typedef std::map<tbCore::uint16, std::pair<TileFlags, tbCore::DynamicStructure> > TilePropertyTable;
293  typedef std::map<tbCore::uint16, tbCore::DynamicStructure> TilePropertyTable;
294  TilePropertyTable mTileProperties;
295  tbCore::DynamicStructure mTileSetProperties;
296  };
297 
298  typedef std::vector<tbCore::tbString> NameContainer;
299  typedef std::map<tbCore::tbString, TileLayer> TileLayerTable;
300  TileLayerTable mTileLayers;
301  NameContainer mOrderedLayerNames;
302  NameContainer mOrderedTileSetNames;
303 
304  typedef std::map<tbCore::tbString, TileSet> TileSetTable;
305  TileSetTable mTileSets;
306  tbCore::DynamicStructure mMapProperties;
307 
310  typedef std::map<tbCore::tbString, tbImplementation::TileSystemRenderer*> LayerRendererTable;
311  mutable LayerRendererTable mLayerRenderers;
312 
313  TurtleBrains::Game::Unstable::TileSystemCollider* mCollider;
314  };
315 
316  }; /* namespace Game */
317 }; /* namespace TurtleBrains */
318 
319 namespace tbGame = TurtleBrains::Game;
320 
321 #endif /* _TurtleBrains_TileSystem_h_ */
Definition: tb_vector.h:47
TileIndex mTileIndex
TODO: TurtleBrains: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:66
Definition: tb_graphic.h:61
Definition: tb_entity.h:46
int GetMapPropertyAsInteger(const tbCore::tbString &propertyName) const
bool IsPointInSolid(const tbMath::Vector2 &pointPosition) const
float mCenterY
TODO: TurtleBrains: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:71
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: TurtleBrains: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:75
float mCenterX
TODO: TurtleBrains: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:70
uint16_t uint16
Unsigned integer with a size of 16 bits. Supports values from 0 to 65535.
Definition: tb_types.h:26
static const DynamicStructure kNullValue
Definition: tb_dynamic_structure.h:707
Definition: tb_tile_system.h:90
Definition: tb_noncopyable.h:22
Here is some information about the primary namespace.
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: TurtleBrains: 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: TurtleBrains: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:68
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: TurtleBrains: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:79
tbCore::uint16 TileIndex
Definition: tb_tile_system.h:33
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: TurtleBrains: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:64
Definition: tbu_bounding_volume.h:24
tbCore::DynamicStructure mPropertyValue
TODO: TurtleBrains: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:76
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:62
Definition: tb_dynamic_structure.h:57
float mWidth
TODO: TurtleBrains: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:74
tbCore::uint16 TileLocation
Definition: tb_tile_system.h:51
Definition: tb_sprite_map.h:23
tbCore::tbString mTileSetName
TODO: TurtleBrains: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:67
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: TurtleBrains: Documentation: Teach the user how to use this.
float mTop
TODO: TurtleBrains: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:72
void SetPropertiesForTile(const tbCore::tbString &tileSetName, const TileIndex &tileIndex, const tbCore::DynamicStructure &tileProperties)
tbCore::tbString GetMapPropertyAsString(const tbCore::tbString &propertyName) const
float mLeft
TODO: TurtleBrains: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:73
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: TurtleBrains: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:55
Definition: tb_application_dialog.h:19
TileLocation mColumn
TODO: TurtleBrains: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:65