From d436967e4761b38714fd3410e4907fab829f925d Mon Sep 17 00:00:00 2001 From: Steve Cotton Date: Sat, 11 Apr 2009 22:04:13 +0100 Subject: 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 --- tools/tmxcopy/map.cpp | 15 +++++++++++---- tools/tmxcopy/map.hpp | 12 ++++++++++-- 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 "<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 */ 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); -- cgit v1.2.3-60-g2f50