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 
36 
37  extern const TileIndex kInvalidTileIndex;
38  extern const TileLocation kInvalidTileLocation;
39 
41 
42  extern const TileSetIndex kInvalidTileSetIndex;
43 
47  struct AboutTile
48  {
49  TileLocation mRow;
50  TileLocation mColumn;
51  TileIndex mTileIndex;
52 
53  float mCenterX;
54  float mCenterY;
55  float mTop;
56  float mLeft;
57  float mWidth;
58  float mHeight;
60  };
61 
62  typedef std::vector<AboutTile> AboutTileContainer;
63 
70  {
71  public:
72 
76  TileSystem(void);
77 
81  virtual ~TileSystem(void);
82 
87  void ClearMap(void);
88 
92  tbCore::tbString GetMapPropertyAsString(const tbCore::tbString& propertyName) const;
93 
97  int GetMapPropertyAsInteger(const tbCore::tbString& propertyName) const;
98 
102  bool GetMapPropertyAsBoolean(const tbCore::tbString& propertyName) const;
103 
107  void SetPropertiesForMap(const tbCore::DynamicStructure& mapProperties);
108 
112  void AddTileSet(const tbCore::tbString& tilesetName, const tbGraphics::SpriteMap& spriteMap,
114 
118 // void SetFlagsForTile(const tbCore::tbString& tileSetName, const TileIndex& tileIndex, const TileFlags& tileFlags);
119 
123  AboutTileContainer FindTilesWithProperty(const tbCore::tbString& tileProperty, bool onlyVisibleLayers = false) const;
124 
128  AboutTileContainer FindTilesWithPropertyEquals(const tbCore::tbString& tileProperty, bool propertyValue, bool onlyVisibleLayers = false) const;
129 
133  AboutTileContainer FindTilesWithPropertyEquals(const tbCore::tbString& tileProperty, int propertyValue, bool onlyVisibleLayers = false) const;
134 
138  AboutTileContainer FindTilesWithPropertyEquals(const tbCore::tbString& tileProperty, const tbCore::tbString& propertyValue, bool onlyVisibleLayers = false) const;
139 
143  void SetPropertiesForTile(const tbCore::tbString& tileSetName, const TileIndex& tileIndex, const tbCore::DynamicStructure& tileProperties);
144 
148  tbCore::tbString GetTilePropertyAsString(const tbCore::tbString& tileSetName, const TileIndex& tileIndex, const tbCore::tbString& propertyName) const;
149 
153  int GetTilePropertyAsInteger(const tbCore::tbString& tileSetName, const TileIndex& tileIndex, const tbCore::tbString& propertyName) const;
154 
158  bool GetTilePropertyAsBoolean(const tbCore::tbString& tileSetName, const TileIndex& tileIndex, const tbCore::tbString& propertyName) const;
159 
163  void SetTileProperty(const tbCore::tbString& tileSetName, const TileIndex& tileIndex,
164  const tbCore::tbString& propertyName, const tbCore::tbString& propertyValue);
165 
169  void SetTileProperty(const tbCore::tbString& tileSetName, const TileIndex& tileIndex,
170  const tbCore::tbString& propertyName, const int propertyValue);
171 
175  void SetTileProperty(const tbCore::tbString& tileSetName, const TileIndex& tileIndex,
176  const tbCore::tbString& propertyName, const bool propertyValue);
177 
181  void AddTileLayer(const tbCore::tbString& tileLayerName, const std::vector<TileIndex>& tileData,
182  const tbCore::tbString& tileSetName, const TileLocation& columnCount, const TileLocation& rowCount);
183 
187  void AddTileLayer(const tbCore::tbString& tileLayerName, const std::vector<TileIndex>& tileData,
188  const std::vector<TileSetIndex>& tileSetData, const TileLocation& columnCount, const TileLocation& rowCount);
189 
193  void SetLayerVisible(const tbCore::tbString& tileLayerName, const bool isVisible);
194 
195 
199  //
200  //
201  //
202  //bool Move(const tbGame::EntityInterface& entity, const tbMath::Vector2& from, tbMath::Vector2& to);
203  //bool Move(const tbMath::Unstable::BoundingVolume& boundingVolume, const tbMath::Vector2& centerFrom, tbMath::Vector2& centerTo)
204 
208  bool MoveEntity(const tbMath::Vector2& currentPosition, tbMath::Vector2& finalPosition,
209  const TurtleBrains::Math::Unstable::BoundingVolume& boundingVolume) const;
210 
214  bool IsPointInSolid(const tbMath::Vector2& pointPosition) const;
215 
219  void UpdateColliderInformation(void);
220 
222 // TileLocation PixelSpaceToColumn(const float locationX) const;
223 // TileLocation PixelSpaceToRow(const float locationY) const;
224 // float ColumnToPixelSpace(const TileLocation& column) const;
225 // float RowToPixelSpace(const TileLocation& row) const;
227 
228  protected:
229 
233  virtual void OnRender(void) const override;
234 
235  private:
236  const tbCore::DynamicStructure& GetTileProperties(const tbCore::tbString& tileSetName, const TileIndex& tileIndex) const;
237  tbCore::DynamicStructure& GetTileProperties(const tbCore::tbString& tileSetName, const TileIndex& tileIndex);
238 
239  struct TileLayer
240  {
241  tbMath::Vector2 mPosition;
242  TileLocation mTileColumns;
243  TileLocation mTileRows;
244  typedef std::vector<TileIndex> TileContainer;
245  TileContainer mTileData; //(TileIndex)-1 = no tile, 0 based on the TileSetData it lies upon.
246  typedef std::vector<TileSetIndex> TileSetContainer;
247  TileSetContainer mTileSetData; //Will be size 1 for a single Tileset, index into ordered names. Not yet implemented ...
248 
249  bool mIsVisible;
250  };
251 
252  struct TileSet
253  {
254  TileSet(const tbGraphics::SpriteMap& spriteMap);
255 
256  tbGraphics::SpriteMap mSpriteMap;
257  //TileIndex mStartTileID; //May be unneeded.
258  //TileIndex mFinalTileID; //May be unneeded.
259 
260  //Stored as the index of the tile in this tile set, so 0 would be top-left most tile in SpriteMap.
261 // typedef std::map<tbCore::uint16, std::pair<TileFlags, tbCore::DynamicStructure> > TilePropertyTable;
262  typedef std::map<tbCore::uint16, tbCore::DynamicStructure> TilePropertyTable;
263  TilePropertyTable mTileProperties;
264  tbCore::DynamicStructure mTileSetProperties;
265  };
266 
267  typedef std::vector<tbCore::tbString> NameContainer;
268  typedef std::map<tbCore::tbString, TileLayer> TileLayerTable;
269  TileLayerTable mTileLayers;
270  NameContainer mOrderedLayerNames;
271  NameContainer mOrderedTileSetNames;
272 
273  typedef std::map<tbCore::tbString, TileSet> TileSetTable;
274  TileSetTable mTileSets;
275  tbCore::DynamicStructure mMapProperties;
276 
279  typedef std::map<tbCore::tbString, tbImplementation::TileSystemRenderer*> LayerRendererTable;
280  mutable LayerRendererTable mLayerRenderers;
281 
282  TurtleBrains::Game::Unstable::TileSystemCollider* mCollider;
283  };
284 
285  namespace Extensions
286  {
291  bool LoadTileSystemFromTiled(TileSystem& tileSystem, const tbCore::tbString& tiledFilepath);
292  };
293 
294  }; /* namespace Game */
295 }; /* namespace TurtleBrains */
296 
297 namespace tbGame = TurtleBrains::Game;
298 
299 #endif /* _TurtleBrains_TileSystem_h_ */
Definition: tb_vector.h:48
TileIndex mTileIndex
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:51
Definition: tb_graphic_list.h:25
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:54
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:58
float mCenterX
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:53
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:554
Definition: tb_tile_system.h:69
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)
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:62
tbCore::uint16 TileIndex
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:34
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:49
Definition: tbu_bounding_volume.h:24
tbCore::DynamicStructure mPropertyValue
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:59
tbCore::tbString GetTilePropertyAsString(const tbCore::tbString &tileSetName, const TileIndex &tileIndex, const tbCore::tbString &propertyName) const
Definition: tb_tile_system.h:47
Definition: tb_dynamic_structure.h:28
float mWidth
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:57
tbCore::uint16 TileLocation
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:35
Definition: tb_sprite_map.h:23
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:55
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:56
const TileIndex kInvalidTileIndex
TODO: TIM: Documentation: Teach the user how to use this.
bool GetMapPropertyAsBoolean(const tbCore::tbString &propertyName) const
std::string tbString
Definition: tb_string.h:293
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:40
Definition: tb_application_dialog.h:19
TileLocation mColumn
TODO: TIM: Documentation: Teach the user how to use this.
Definition: tb_tile_system.h:50