diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-06 21:12:22 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-07 10:43:54 +0100 |
commit | c74680473e702bacc009897a258387445d6f3eb5 (patch) | |
tree | 800cfb1f83f0c69ae8fcd0096949e660152a80b8 /src/map.h | |
parent | f9a522c72db959b5d63061ed255735d0230fc7de (diff) | |
download | mana-c74680473e702bacc009897a258387445d6f3eb5.tar.gz mana-c74680473e702bacc009897a258387445d6f3eb5.tar.bz2 mana-c74680473e702bacc009897a258387445d6f3eb5.tar.xz mana-c74680473e702bacc009897a258387445d6f3eb5.zip |
Use the native TMX tile animation format
Rewrote the tile animation loading code based on XML tags, replacing
the code that loaded tile animations from tile properties.
Also made a number of code simplifications and optimizations:
* Replaced a number of pointer members with value members.
* Pass around Animation and TileAnimation by value, using std::move to
avoid allocating copies.
* push -> emplace
* push_front -> emplace_front
* push_back -> emplace_back
* Use range-based for loops
* Use std::vector instead of std::list for storing affected tiles
(less fragmentation)
* Avoid string copies and allocations while parsing CSV layer data.
* Replaced xmlNodeGetContent with directly accessing 'content'.
Diffstat (limited to 'src/map.h')
-rw-r--r-- | src/map.h | 33 |
1 files changed, 15 insertions, 18 deletions
@@ -25,21 +25,17 @@ #include "actor.h" #include "position.h" #include "properties.h" +#include "simpleanimation.h" #include <list> #include <vector> -class Animation; class AmbientLayer; class Graphics; class MapLayer; class Particle; -class SimpleAnimation; class Tileset; -using Tilesets = std::vector<Tileset *>; -using Layers = std::vector<MapLayer *>; - const int DEFAULT_TILE_LENGTH = 32; /** @@ -65,15 +61,17 @@ struct MetaTile class TileAnimation { public: - TileAnimation(Animation *ani); - ~TileAnimation(); + TileAnimation(Animation animation); + void update(int ticks = 1); + void addAffectedTile(MapLayer *layer, int index) { mAffected.emplace_back(layer, index); } + private: - std::list<std::pair<MapLayer*, int> > mAffected; - SimpleAnimation *mAnimation; - Image *mLastImage; + std::vector<std::pair<MapLayer*, int> > mAffected; + SimpleAnimation mAnimation; + Image *mLastImage = nullptr; }; /** @@ -212,7 +210,7 @@ class Map : public Properties * Visualizes collision layer for debugging */ void drawCollision(Graphics *graphics, int scrollX, int scrollY, - int debugFlags); + int debugFlags) const; /** * Adds a layer to this map. The map takes ownership of the layer. @@ -279,7 +277,7 @@ class Map : public Properties * @param x the horizontal tile position * @param y the vertical tile position */ - Vector getTileCenter(int x, int y); + Vector getTileCenter(int x, int y) const; std::string getMusicFile() const; std::string getName() const; @@ -327,8 +325,7 @@ class Map : public Properties /** * Adds a tile animation to the map */ - void addAnimation(int gid, TileAnimation *animation) - { mTileAnimations[gid] = animation; } + void addAnimation(int gid, TileAnimation animation); void setDebugFlags(int flags) { mDebugFlags = flags; } @@ -337,7 +334,7 @@ class Map : public Properties /** * Gets the tile animation for a specific gid */ - TileAnimation *getAnimationForGid(int gid) const; + TileAnimation *getAnimationForGid(int gid); void setMask(int mask); @@ -392,8 +389,8 @@ class Map : public Properties int mTileWidth, mTileHeight; int mMaxTileHeight, mMaxTileWidth; MetaTile *mMetaTiles; - Layers mLayers; - Tilesets mTilesets; + std::vector<MapLayer *> mLayers; + std::vector<Tileset *> mTilesets; Actors mActors; // debug flags @@ -419,7 +416,7 @@ class Map : public Properties }; std::list<ParticleEffectData> particleEffects; - std::map<int, TileAnimation*> mTileAnimations; + std::map<int, TileAnimation> mTileAnimations; int mMask = 1; }; |