tile2d
Loading...
Searching...
No Matches
tileMap.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "body.hpp"
4
11T2D_NAMESPACE_BEGIN
12
20template<typename T>
22
23 bool isMultiTile = false;
24 bool isMainTile = false;
25 union {
26
27 // will be accessed when isMainTile is true
28 struct {
29 uint16_t width;
30 uint16_t height;
31 } mutliTile;
32
33 // will be accessed when isMainTile is false but isMultiTile is true
34 glm::i32vec2 mainTilePos;
35 };
36
37 T userData;
38};
39
51 template<typename Integer>
52 Float getMomentOfInertia(const glm::vec<2, Integer>& tileDimensions) const {
53 // MOI scalar of a rectangle
54 // I = (1 / 12) * m(w * w + h * h)
55
56 constexpr Float one_twelfth = 1.0f / 12.0f;
57
58 return one_twelfth * getMass(tileDimensions) * (sqaure(tileWidth * tileDimensions.x) + sqaure(tileHeight * tileDimensions.y));
59 }
60
66 template<typename Integer>
67 Float getMass(const glm::vec<2, Integer>& tileDimensions) const {
68 // area = width * height
69 // mass = area * density
70 return (tileWidth * (Float)tileDimensions.x) * (tileHeight * (Float)tileDimensions.y) * density;
71 }
72
73 // Must be set
74 Float density = 1.0f;
75 uint8_t staticFriction = 255; // [0 - 255] -> [0.0 = 1.0]
76 uint8_t dynamicFriction = 255; // [0 - 255] -> [0.0 = 1.0]
77 uint8_t restitution = 0;// [0 - 255] -> [0.0 = 1.0]
78};
79
80/* Forward Declaration */
81template<typename TileType>
82class TileBody;
83
84/* Used for construction of a TileMap */
86
87template<typename TileType>
88class TileMap {
89 friend class TileBody<TileType>;
90 template<class ATileType, class TileMapAllocator, class PhysicsWorld>
91 friend class CreateTileMap;
92
93public:
98
99 virtual ~TileMap() {}
100
108 inline const PhysicsTileProperties& getPhysicsTileProperties(const glm::i32vec2& tilePos) const {
109 return m_physicsTiles.find(tilePos)->second;
110 }
111
119 inline TileProperties<TileType>& getTileProperties(const glm::i32vec2& tilePos) {
120 return m_tiles.find(tilePos)->second;
121 }
122
126 void beginBulkInsert();
127
131 void endBulkInsert();
132
136 void beginBulkErase();
137
141 void endBulkErase();
142
153 bool addTile(const glm::i32vec2& pos, const TileProperties<TileType>& props, const PhysicsTileProperties& physicsProperties = {});
154
162 bool removeTile(const glm::i32vec2& pos) noexcept;
163
173 inline glm::u16vec2 getTileDimensions(const glm::i32vec2& pos) const {
174 auto& props = m_tiles.find(pos)->second;
175
176 if (props.isMultiTile) {
177 assert(props.isMainTile);
178 return { props.mutliTile.width, props.mutliTile.height };
179 }
180
181 return { 1, 1 };
182 }
183
193 inline vec2 getRealTileDimensions(const glm::i32vec2& pos) const {
194 return (vec2)getTileDimensions(pos) * tileSize;
195 }
196
202 size_t count() const {
203 return m_tiles.size();
204 }
205
212
213public:
219 struct Iterator {
220 using ContainerIterator = typename FlatMap<glm::i32vec2, TileProperties<TileType>>::iterator;
221 private:
222 ContainerIterator m_it;
223 public:
224 Iterator(const ContainerIterator& it)
225 : m_it(it) {}
226
227 const glm::i32vec2& operator*() const {
228 return m_it->first;
229 }
230
231 Iterator& operator++() {
232 m_it = ++m_it;
233 return *this;
234 }
235
236 Iterator& operator--() {
237 m_it = --m_it;
238 return *this;
239 }
240
241 bool operator!=(const Iterator& other) const {
242 return m_it != other.m_it;
243 }
244 };
245
246 Iterator begin() { return Iterator(m_tiles.begin()); }
247 Iterator end() { return Iterator(m_tiles.end()); }
248
249protected:
254 m_body = body;
255 }
256
257protected:
258 FlatMap<glm::i32vec2, TileProperties<TileType>> m_tiles;
259 FlatMap<glm::i32vec2, PhysicsTileProperties> m_physicsTiles;
260
261private:
262 TileBody<TileType>* m_body;
263};
264
270template<typename TileType>
271class TileBody : public Body {
272 friend class TileMap<TileType>;
273public:
280 SpatialIndex() = default;
281 SpatialIndex(const glm::i32vec2& pos)
282 : aabb(), pos(pos) {
283
284 }
285 SpatialIndex(const AABB<Float>& aabb, const glm::i32vec2& pos)
286 : aabb(aabb), pos(pos) {
287
288 }
289
290 AABB<Float> aabb;
291 glm::i32vec2 pos;
292
293 inline bool operator==(const SpatialIndex& other) const {
294 return pos == other.pos;
295 }
296 };
297
298public:
303 : Body(id, BodyType::Tile), m_tileMap(tileMap) {
304 clear();
305
306 tileMap.setTileBody(this);
307 }
308
309 inline virtual void integrate(Float dt) override {
310 Body::integrate(dt);
311 }
312
313 inline virtual AABB<Float> getAABB() const override {
314 return getAABB(getLocalAABB(), Transform());
315 }
316
322 inline TileMap<TileType>& tileMap() const {
323 return m_tileMap;
324 }
325
331 inline std::array<vec2, 2> normals() const {
332 const SinCos& sincos = m_transform.sincos;
333
334 // _1_2, 2_3
335 return { vec2(sincos.cos, sincos.sin), vec2(-sincos.sin, sincos.cos) };
336 }
337
338public: /* Tiles! */
346 inline vec2 getTileLocalPoint(const glm::i32vec2& iPos) const {
347 return (vec2)iPos * vec2(tileWidth, tileHeight) + m_tileMap.getRealTileDimensions(iPos) * Float(0.5f);
348 }
349
357 inline vec2 getTileWorldPoint(const glm::i32vec2& iPos) const {
358 return getWorldPoint(getTileLocalPoint(iPos));
359 }
360
368 inline TOBB getTileWorldOBB(const glm::i32vec2& iPos) const {
369 return getTileWorldOBBOffset(iPos, vec2(0.0f));
370 }
371
380 inline TOBB getTileWorldOBBOffset(const glm::i32vec2& iPos, const vec2& worldOffset) const {
381 TOBB tileOBB;
382
383 tileOBB.extent = m_tileMap.getRealTileDimensions(iPos) * Float(0.5);
384 tileOBB.transform.pos = getTileWorldPoint(iPos) + worldOffset;
385 tileOBB.transform.rot = m_transform.rot;
386 tileOBB.transform.sincos = m_transform.sincos;
387
388 return tileOBB;
389 }
390
399 inline std::array<vec2, 4> getTileWorldOBBOffsetVertices(const glm::i32vec2& iPos, const vec2& worldOffset) const {
400 vec2 extent = m_tileMap.getRealTileDimensions(iPos) * Float(0.5);
401 vec2 worldPos = getTileWorldPoint(iPos) + worldOffset;
402 const vec2 wExt = rotate({ extent.x, extent.y }, m_transform.sincos);
403 const vec2 blExt = rotate({ extent.x, -extent.y }, m_transform.sincos);
404 const vec2 trExt = -blExt;
405
406 return {
407 worldPos - wExt,
408 {worldPos.x + blExt.x, worldPos.y + blExt.y},
409 worldPos + wExt,
410 {worldPos.x + trExt.x, worldPos.y + trExt.y}
411 };
412 }
413
421 inline AABB<Float> getTileWorldAABB(const glm::i32vec2& iPos) const {
422 vec2 tileDim = m_tileMap.getRealTileDimensions(iPos);
423
424 return AABB(getTileWorldPoint(iPos), tileDim.x * Float(0.5), tileDim.y * Float(0.5)).rotate(m_transform.sincos);
425 }
426
434 inline AABB<Float> getTileLocalAABB(const glm::i32vec2& iPos) const {
435 vec2 tileDim = m_tileMap.getRealTileDimensions(iPos);
436
437 return { getTileLocalPoint(iPos), tileDim.x * Float(0.5), tileDim.y * Float(0.5) };
438 }
439
440public:
449 template<typename OutIt>
450 inline void queryChunks(const AABB<Float>& intersectBox, OutIt chunks) const {
451 const glm::i32vec2 minChunk = getChunkCoords(intersectBox.min());
452 const glm::i32vec2 maxChunk = getChunkCoords(intersectBox.max());
453
454 assert(minChunk.x <= maxChunk.x);
455 assert(minChunk.y <= maxChunk.y);
456
457 for (int32_t y = minChunk.y; y <= maxChunk.y; y++) {
458 for (int32_t x = minChunk.x; x <= maxChunk.x; x++) {
459 glm::i32vec2 coord(x, y);
460
461 if (m_chunks.contains(coord)) {
462 chunks++;
463 *chunks = SpatialIndex(getChunkAABB(coord), coord);
464 }
465 }
466 }
467 }
468
477 template<typename OutIt>
478 inline void queryTiles(const AABB<Float>& intersectBox, OutIt tiles) const {
479 glm::i32vec2 minTiles = getTileCoords(intersectBox.min());
480 glm::i32vec2 maxTiles = getTileCoords(intersectBox.max());
481
482 assert(minTiles.x <= maxTiles.x);
483 assert(minTiles.y <= maxTiles.y);
484
485 for (int32_t y = minTiles.y; y <= maxTiles.y; y++) {
486 for (int32_t x = minTiles.x; x <= maxTiles.x; x++) {
487 glm::i32vec2 coord(x, y);
488
489 if (m_tileMap.m_tiles.contains(coord)) {
490 tiles++;
491 if (m_tileMap.m_tiles[coord].isMultiTile && !m_tileMap.m_tiles[coord].isMainTile)
492 *tiles = SpatialIndex(m_tileMap.m_tiles[coord].mainTilePos);
493 else
494 *tiles = SpatialIndex(coord);
495 }
496 }
497 }
498 }
499
507 glm::i32vec2 getChunkCoords(const vec2& localCoords) const {
508 return (glm::i32vec2)glm::floor(localCoords / (tileSize * vec2(chunkWidth, chunkHeight)));
509 }
510
518 inline glm::i32vec2 getChunkCoords(const glm::i32vec2& tileCoords) const {
519 glm::i32vec2 chunk = {
520 tileCoords.x / chunkWidth,
521 tileCoords.y / chunkHeight
522 };
523
524 return chunk;
525 }
526
534 glm::i32vec2 getTileCoords(const vec2& localCoords) const {
535 return (glm::i32vec2)glm::floor(localCoords / (tileSize));
536 }
537
545 inline AABB<Float> getChunkAABB(const glm::i32vec2& chunk) const {
546 constexpr vec2 chunkDim((Float)(tileWidth * chunkWidth), (Float)(tileHeight * chunkHeight));
547
548 return AABB((vec2)chunk * chunkDim + chunkDim * Float(0.5f), chunkDim.x * Float(0.5), chunkDim.y * Float(0.5));
549 }
550
551protected:
552 inline void insertIntoChunk(const glm::i32vec2& tile) {
553 glm::i32vec2 chunk = getChunk(tile);
554
555 if (m_chunks.find(chunk) == m_chunks.end()) {
556 m_chunks.insert(chunk);
557 }
558 }
559
560 // gets the local AABB of this object
561 inline AABB<Float> getLocalAABB() const {
562 const vec2 halfDim = {
563 (Float)corners.width() * tileWidth * Float(0.5f) + tileWidth * Float(0.5f),
564 (Float)corners.height() * tileHeight * Float(0.5f) + tileHeight * Float(0.5f)
565 };
566 return AABB(halfDim) + getTileLocalPointNoDim(corners.min()) + halfDim;
567 }
568
569 // get the local position of a tile without accounting for the tiles actual dimensions
570 inline vec2 getTileLocalPointNoDim(const glm::i32vec2& iPos) const {
571 return (vec2)iPos * vec2(tileWidth, tileHeight);
572 }
573
574 inline void calculateRotationalInertia() {
575 m_I = 0.0f;
576 for (const auto& pair : m_tileMap.m_physicsTiles) {
577 auto tileDimensions = m_tileMap.getTileDimensions(pair.first);
578 m_I += parallelAxisTheorem<Float>(
579 pair.second.template getMomentOfInertia<uint16_t>(tileDimensions),
580 pair.second.template getMass<uint16_t>(tileDimensions),
581 glm::length2(getTileLocalPoint(pair.first) - m_centroid));
582 }
583 if (m_I != 0.0f && !m_flags[IS_STATIC])
584 m_inverseI = 1.0f / m_I;
585 else
586 m_inverseI = 0.0f;
587 }
588
589 inline void calculateRotationalInertiaAndAABB() {
590 m_I = 0.0f;
591 clear();
592 auto& min = corners.min();
593 auto& max = corners.max();
594 for (const auto& pair : m_tileMap.m_physicsTiles) {
595 const glm::i32vec2& tilePos = pair.first;
596 const glm::u16vec2 tileDimensions = m_tileMap.getTileDimensions(tilePos);
597
598 if (tilePos.x < min.x) {
599 min.x = tilePos.x;
600 }
601 if (tilePos.y < min.y) {
602 min.y = tilePos.y;
603 }
604 if (tilePos.x + (tileDimensions.x - 1) > max.x) {
605 max.x = tilePos.x + (tileDimensions.x - 1);
606 }
607 if (tilePos.y + (tileDimensions.y - 1) > max.y) {
608 max.y = tilePos.y + (tileDimensions.y - 1);
609 }
610
611 m_I += parallelAxisTheorem<Float>(
612 pair.second.template getMomentOfInertia<uint16_t>(tileDimensions),
613 pair.second.template getMass<uint16_t>(tileDimensions),
614 glm::length2(getTileLocalPoint(tilePos) - m_centroid));
615 }
616
617 if (m_I != 0.0f && !m_flags[IS_STATIC])
618 m_inverseI = 1.0f / m_I;
619 else
620 m_inverseI = 0.0f;
621 }
622
623protected: /* For use within the Tile Map Class*/
624 void addTile(const glm::i32vec2& iPos) {
625 const vec2 pos = getTileLocalPoint(iPos);
626 const glm::u16vec2 tileDimensions = m_tileMap.getTileDimensions(iPos);
627 const PhysicsTileProperties& physicsProperties = m_tileMap.m_physicsTiles.at(iPos);
628 const Float tileMass = physicsProperties.getMass<uint16_t>(tileDimensions);
629
630 m_unweightedCentroid += pos;
631 m_centroid = m_unweightedCentroid / (Float)m_tileMap.m_physicsTiles.size();
632 if (!isBulkAdd) {
633 calculateRotationalInertia();
634 }
635
636 m_mass += tileMass;
637 if(!m_flags[IS_STATIC])
638 m_inverseMass = 1.0f / m_mass;
639 m_unweightedCom += tileMass * pos;
640 m_com = m_unweightedCom * m_inverseMass;
641
642 for (auto y = iPos.y; y < (iPos.y + (int32_t)tileDimensions.y); y++) {
643 for (auto x = iPos.x; x < (iPos.x + (int32_t)tileDimensions.x); x++) {
644 insertIntoChunk({ x, y });
645 }
646 }
647
648 auto& min = corners.min();
649 auto& max = corners.max();
650 if (iPos.x < min.x) {
651 min.x = iPos.x;
652 }
653 if (iPos.y < min.y) {
654 min.y = iPos.y;
655 }
656 if (iPos.x + (tileDimensions.x - 1) > max.x) {
657 max.x = iPos.x + (tileDimensions.x - 1);
658 }
659 if (iPos.y + (tileDimensions.y - 1) > max.y) {
660 max.y = iPos.y + (tileDimensions.y - 1);
661 }
662
663 assert(isValid());
664 }
665
666 void removeTile(const glm::i32vec2& iPos) {
667 const vec2 pos = getTileLocalPoint(iPos);
668 const glm::u16vec2 tileDimensions = m_tileMap.getTileDimensions(iPos);
669 const PhysicsTileProperties& physicsProperties = m_tileMap.m_physicsTiles.at(iPos);
670 const Float tileMass = physicsProperties.getMass<uint16_t>(tileDimensions);
671
672 m_mass -= tileMass;
673 if (m_mass != 0.0f && !m_flags[IS_STATIC])
674 m_inverseMass = 1.0f / m_mass;
675 else
676 m_inverseMass = 0.0f;
677 m_unweightedCom -= tileMass * pos;
678 m_com = m_unweightedCom * m_inverseMass;
679
680 m_unweightedCentroid -= pos;
681 m_centroid = m_unweightedCentroid / (Float)(m_tileMap.m_physicsTiles.size() - 1);
682 if (!isBulkErase) {
683 calculateRotationalInertiaAndAABB();
684 }
685
686 assert(isValid());
687 }
688
689 void beginBulkInsert() {
690 isBulkAdd = true;
691 }
692
693 void endBulkInsert() {
694 isBulkAdd = false;
695
696 calculateRotationalInertia();
697 }
698
699 void beginBulkErase() {
700 isBulkErase = true;
701 }
702
703 void endBulkErase() {
704 isBulkErase = false;
705
706 calculateRotationalInertiaAndAABB();
707 }
708
709private:
710 void clear() {
711 corners.setMin(glm::i32vec2(std::numeric_limits<int32_t>::max()));
712 corners.setMax(glm::i32vec2(-std::numeric_limits<int32_t>::max()));
713 }
714
715 bool isBulkErase = false;
716 bool isBulkAdd = false;
717 TileMap<TileType>& m_tileMap;
718 AABB<int32_t> corners;
719 boost::unordered_flat_set<glm::i32vec2> m_chunks;
720};
721
722template<typename TileType>
723bool TileMap<TileType>::addTile(const glm::i32vec2& pos, const TileProperties<TileType>& props, const PhysicsTileProperties& physicsProperties) {
724 assert(m_body);
725
726 if (m_tiles.contains(pos))
727 return false;
728
729 if (props.isMultiTile) {
730 glm::i32vec2 endPos = {
731 pos.x + props.mutliTile.width,
732 pos.y + props.mutliTile.height
733 };
734
735 TileProperties<TileType> bufferTileProperties = props;
736 bufferTileProperties.isMainTile = false;
737 bufferTileProperties.mainTilePos = pos;
738
739 // ensure the area is clear
740 for (auto y = pos.y; y < endPos.y; y++) {
741 for (auto x = pos.x; x < endPos.x; x++) {
742 if (m_tiles.contains({ x, y })) {
743 return false;
744 }
745 }
746 }
747
748 for (auto y = pos.y; y < endPos.y; y++) {
749 for (auto x = pos.x; x < endPos.x; x++) {
750 m_tiles[{x, y}] = bufferTileProperties;
751 }
752 }
753 }
754
755 m_tiles[pos] = props;
756 m_physicsTiles.insert(std::pair(pos, physicsProperties));
757 m_body->addTile(pos);
758
759 return true;
760}
761
762template<typename TileType>
763bool TileMap<TileType>::removeTile(const glm::i32vec2& pos) noexcept {
764 assert(m_body);
765
766 if (!m_tiles.contains(pos))
767 return false;
768
769 m_body->removeTile(pos);
770 m_physicsTiles.erase(pos);
771
772 TileProperties<TileType>& tileProperties = m_tiles.at(pos);
773 if (tileProperties.isMultiTile) {
774 if (!tileProperties.isMainTile)
775 throw "Attempt to remove multi tile that isn't the main tile\n";
776
777 glm::i32vec2 endPos = {
778 pos.x + tileProperties.mutliTile.width,
779 pos.y + tileProperties.mutliTile.height
780 };
781
782 for (auto y = pos.y; y < endPos.y; y++) {
783 for (auto x = pos.x; x < endPos.x; x++) {
784 m_tiles.erase({ x, y });
785 }
786 }
787
788 return;
789 }
790
791 m_tiles.erase(pos);
792
793 return true;
794}
795
796template<typename TileType>
798 assert(m_body);
799 m_body->beginBulkInsert();
800}
801
802template<typename TileType>
804 assert(m_body);
805 m_body->endBulkInsert();
806}
807
808template<typename TileType>
810 assert(m_body);
811 m_body->beginBulkErase();
812}
813
814template<typename TileType>
816 assert(m_body);
817 m_body->endBulkErase();
818}
819
820template<typename TileType>
822 return *m_body;
823}
824
825template<class TileType, class TileMapAllocator, class PhysicsWorld>
827 std::pair<TileMap<TileType>*, Body*> operator()(TileMapAllocator& tileMapAllocator, PhysicsWorld& physicsWorld) {
828 TileMap<TileType>* tileMap = tileMapAllocator.construct<_CreateTileMap>(_CreateTileMap());
829 Body* tileBody = physicsWorld.createTileBody(*tileMap);
830
831 return { tileMap, tileBody };
832 }
833};
834
843template<class TileType, class TileMapAllocator, class PhysicsWorld>
844std::pair<TileMap<TileType>*, WorldBody*> createTileMap(TileMapAllocator& tileMapAllocator, PhysicsWorld& physicsWorld) {
845 return CreateTileMap<TileType, TileMapAllocator, PhysicsWorld>()(tileMapAllocator, physicsWorld);
846}
847
848T2D_NAMESPACE_END
Contains different types of rigid bodies aside from TileBody. See tileMap.hpp.
Extends the functionality of WorldBody to allow for things such as angular velocity.
Definition body.hpp:238
virtual void integrate(Float dt) override
Integerates this body, meaning the linear velocity and angular velocity will be integrated into the p...
Definition body.hpp:253
virtual vec2 getWorldPoint(const vec2 &localPoint) const override
Gets a local position thats within the local space of this body and transforms into the world space.
Definition body.hpp:278
For use with a TileMap<>, allows collisions with other rigid bodies inside World<>
Definition tileMap.hpp:271
TileMap< TileType > & tileMap() const
Returns the tile map attached to this rigid body.
Definition tileMap.hpp:322
void queryChunks(const AABB< Float > &intersectBox, OutIt chunks) const
Will get the list of chunks that intersect intersectBox, along with their AABBS.
Definition tileMap.hpp:450
vec2 getTileLocalPoint(const glm::i32vec2 &iPos) const
Returns the local center of the tile located at iPos.
Definition tileMap.hpp:346
virtual AABB< Float > getAABB() const override
Returns the AABB of this body.
Definition tileMap.hpp:313
AABB< Float > getTileWorldAABB(const glm::i32vec2 &iPos) const
Returns the world AABB of a tile located at iPos.
Definition tileMap.hpp:421
std::array< vec2, 2 > normals() const
Returns the normals of this body. Can be used for all tiles of this body.
Definition tileMap.hpp:331
AABB< Float > getChunkAABB(const glm::i32vec2 &chunk) const
Get the AABB of the chunk located at chunk.
Definition tileMap.hpp:545
glm::i32vec2 getTileCoords(const vec2 &localCoords) const
Get the tile that contains localCoords. Tile may or may not exist.
Definition tileMap.hpp:534
glm::i32vec2 getChunkCoords(const glm::i32vec2 &tileCoords) const
Get the chunk that contains tileCoords. Chunk may or may not exist.
Definition tileMap.hpp:518
void queryTiles(const AABB< Float > &intersectBox, OutIt tiles) const
Will get the list of tiles that intersect intersectBox.
Definition tileMap.hpp:478
vec2 getTileWorldPoint(const glm::i32vec2 &iPos) const
Returns the world center of the tile located at iPos.
Definition tileMap.hpp:357
glm::i32vec2 getChunkCoords(const vec2 &localCoords) const
Get the chunk that contains localCoords. Chunk may or may not exist.
Definition tileMap.hpp:507
std::array< vec2, 4 > getTileWorldOBBOffsetVertices(const glm::i32vec2 &iPos, const vec2 &worldOffset) const
Returns the world vertices of the tile located at iPos. with an added offset.
Definition tileMap.hpp:399
TOBB getTileWorldOBBOffset(const glm::i32vec2 &iPos, const vec2 &worldOffset) const
Returns the world oriented bounding box of the tile located at iPos. with an added offset.
Definition tileMap.hpp:380
TOBB getTileWorldOBB(const glm::i32vec2 &iPos) const
Returns the world oriented bounding box of the tile located at iPos.
Definition tileMap.hpp:368
AABB< Float > getTileLocalAABB(const glm::i32vec2 &iPos) const
Returns the local AABB of a tile located at iPos.
Definition tileMap.hpp:434
virtual void integrate(Float dt) override
Integerates this body, meaning the linear velocity and angular velocity will be integrated into the p...
Definition tileMap.hpp:309
TileBody(TileMap< TileType > &tileMap, uint32_t id)
Do not call directly, to construct a TileBody use createTileMap()
Definition tileMap.hpp:302
Definition tileMap.hpp:88
void beginBulkErase()
Used to speed up the erasure of a large amount of tiles. To use for speed up, call before erasing a l...
Definition tileMap.hpp:809
vec2 getRealTileDimensions(const glm::i32vec2 &pos) const
Returns the REAL tile dimensions, meaning world dimensions, of the tile located at pos.
Definition tileMap.hpp:193
TileMap(_CreateTileMap)
Do not call directly, to construct a tileMap use createTileMap()
Definition tileMap.hpp:97
bool removeTile(const glm::i32vec2 &pos) noexcept
Removes a tile at pos.
Definition tileMap.hpp:763
const PhysicsTileProperties & getPhysicsTileProperties(const glm::i32vec2 &tilePos) const
Returns the physical properties of a tile located at tilePos.
Definition tileMap.hpp:108
TileProperties< TileType > & getTileProperties(const glm::i32vec2 &tilePos)
Returns the properties of a tile located at tilePos.
Definition tileMap.hpp:119
TileBody< TileType > & body()
Returns the rigid body attached to this tile map.
Definition tileMap.hpp:821
void beginBulkInsert()
Used to speed up the insert of a large amount of tiles. To use for speed up, call before inserting a ...
Definition tileMap.hpp:797
bool addTile(const glm::i32vec2 &pos, const TileProperties< TileType > &props, const PhysicsTileProperties &physicsProperties={})
Adds a tile at pos with the properties of props and the physics properties set to physicsProperties....
Definition tileMap.hpp:723
glm::u16vec2 getTileDimensions(const glm::i32vec2 &pos) const
Returns the tile dimensions of the tile located at pos.
Definition tileMap.hpp:173
void endBulkErase()
Used to speed up the erasure of a large amount of tiles. To use for speed up, call after erasing a la...
Definition tileMap.hpp:815
size_t count() const
Returns the amount of tiles, including the sub-tiles of multi-tiles.
Definition tileMap.hpp:202
void setTileBody(TileBody< TileType > *body)
Definition tileMap.hpp:253
void endBulkInsert()
Used to speed up the insert of a large amount of tiles. To use for speed up, call after inserting a l...
Definition tileMap.hpp:803
The abstract base class of all Rigid Bodies that defines essential methods and members to be used in ...
Definition body.hpp:30
uint32_t id() const
Returns the id assigned to this body the physics world.
Definition body.hpp:48
Definition tileMap.hpp:85
Definition math.hpp:203
Definition tileMap.hpp:826
Contains the physical properties of a tile, such as elasticity.
Definition tileMap.hpp:45
Float getMass(const glm::vec< 2, Integer > &tileDimensions) const
Returns the mass of this tile with using the area calculated from tileDimensions.
Definition tileMap.hpp:67
Float getMomentOfInertia(const glm::vec< 2, Integer > &tileDimensions) const
Returns the rotational inertia of this tile.
Definition tileMap.hpp:52
Used to simplify the use of precalculated values for sine and cosine.
Definition math.hpp:80
Definition math.hpp:390
A spatial index where pos may point towards a chunk or tile.
Definition tileMap.hpp:279
Allows iteration of tiles with for loops/.
Definition tileMap.hpp:219
Contains the data of a tile or multi tile.
Definition tileMap.hpp:21
Definition math.hpp:142
std::pair< TileMap< TileType > *, WorldBody * > createTileMap(TileMapAllocator &tileMapAllocator, PhysicsWorld &physicsWorld)
Creates a tile map and a tile body using tileMapAllocator for the tileMap and the physicsWorld for th...
Definition tileMap.hpp:844