summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Cotton <steve@s.cotton.clara.co.uk>2009-04-11 22:04:13 +0100
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-16 11:34:55 +0200
commitd436967e4761b38714fd3410e4907fab829f925d (patch)
tree86f383f9993c01d99a2792fa15ff596a416d26d2
parentbb216d7fb966156b8ea2ecb284b680309b92585b (diff)
downloadmana-d436967e4761b38714fd3410e4907fab829f925d.tar.gz
mana-d436967e4761b38714fd3410e4907fab829f925d.tar.bz2
mana-d436967e4761b38714fd3410e4907fab829f925d.tar.xz
mana-d436967e4761b38714fd3410e4907fab829f925d.zip
TMXCollide wasn't handling tilesets right.
Wasn't using the translation table from template map's tilesets to target map's tilesets. Also WIP for tmx_random_fill: better control of number of objects added
-rw-r--r--tools/tmxcopy/map.cpp15
-rw-r--r--tools/tmxcopy/map.hpp12
2 files changed, 21 insertions, 6 deletions
diff --git a/tools/tmxcopy/map.cpp b/tools/tmxcopy/map.cpp
index 109d1742..9e01944c 100644
--- a/tools/tmxcopy/map.cpp
+++ b/tools/tmxcopy/map.cpp
@@ -392,6 +392,8 @@ bool Map::randomFill(Map* templateMap, const std::string& destLayerName,
/* Now generate extra tiles.
* TODO Need to configure this for desired density. For 2x1 trees, dW*dH/10 is very sparse, dW*dH/2 is dense */
srand(time(NULL));
+ int patternsGenerated = 0;
+ int occupiedAreas = 0;
for (int i = destWidth*destHeight / 10; i > 0; i--)
{
/* Pick a random location, with enough tiles left and down from it to
@@ -429,14 +431,16 @@ bool Map::randomFill(Map* templateMap, const std::string& destLayerName,
destTile.index = srcTile.index;
}
}
+ patternsGenerated++;
}
else
{
+ occupiedAreas++;
std::cout <<"Area occupied "<<x<<", "<<y<<std::endl;
}
}
- std::clog<<"copying successful!"<<std::endl;
+ std::clog<<"Generated " << patternsGenerated << " new objects" <<std::endl;
return true;
}
@@ -469,11 +473,14 @@ bool Map::translateAllLayers(Map* templateMap, const std::string& destLayerName,
for (int xy = (templateMap->getWidth() * templateMap->getHeight() -1);
xy >= 0; xy--)
{
- Tile& fromTile = fromLayer->at(xy);
- Tile& toTile = toLayer->at(xy);
+ Tile fromTile = fromLayer->at(xy);
+ Tile toTile = toLayer->at(xy);
if (!fromTile.empty())
{
- collisionTranslation[fromTile] = toTile; //FIXME - just getting it compiling so far
+ fromTile.tileset = tilesetTranslation[fromTile.tileset];
+ toTile.tileset = tilesetTranslation[toTile.tileset];
+
+ collisionTranslation[fromTile] = toTile;
}
}
diff --git a/tools/tmxcopy/map.hpp b/tools/tmxcopy/map.hpp
index d6cd3d1a..3be932ab 100644
--- a/tools/tmxcopy/map.hpp
+++ b/tools/tmxcopy/map.hpp
@@ -69,6 +69,13 @@ struct Tileset
};
+/**
+ * A tile in a layer of a map.
+ *
+ * With the exception of the emptyTile and empty() function,
+ * interpreting what this tile represents depends on the map it
+ * belongs to (specifically the ordering of that map's tilesets).
+ */
struct Tile
{
int tileset; // number of tileset
@@ -82,7 +89,8 @@ struct Tile
/* This is to allow std::map<Tile,Tile> */
bool operator< (const Tile& b) const
{
- return ((tileset < b.tileset) || (index < b.index));
+ return ((tileset < b.tileset) ||
+ ((tileset == b.tileset) && (index < b.index)));
}
bool operator!= (const Tile& b) const
@@ -144,7 +152,7 @@ class Map
/**
* Translates a layer - using the template, generates collision from visible layers (for example).
- * TODO - avoid confusion with the math term "translate"
+ * TODO - avoid confusion with the geometry term "translate"
*/
bool translateAllLayers(Map* templateMap, const std::string& destLayerName,
const ConfigurationOptions& config);