From 9dddb791657288c5b6ed09511069c58f38218962 Mon Sep 17 00:00:00 2001 From: Quietust Date: Thu, 19 Jan 2012 22:34:06 -0600 Subject: [PATCH] Optimize tubefill, and also try to handle the floors above newly filled tiles (as well as tiles which were floors to begin with) --- plugins/tubefill.cpp | 84 ++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 49 deletions(-) diff --git a/plugins/tubefill.cpp b/plugins/tubefill.cpp index 22955f0dc..32ee3f484 100644 --- a/plugins/tubefill.cpp +++ b/plugins/tubefill.cpp @@ -10,10 +10,12 @@ #include "PluginManager.h" #include "modules/Maps.h" #include "modules/World.h" -#include "modules/MapCache.h" #include "modules/Gui.h" -using MapExtras::MapCache; +#include "TileTypes.h" + using namespace DFHack; +using namespace DFHack::Simple; +using df::global::world; DFhackCExport command_result tubefill(DFHack::Core * c, std::vector & params); @@ -36,14 +38,8 @@ DFhackCExport command_result plugin_shutdown ( Core * c ) DFhackCExport command_result tubefill(DFHack::Core * c, std::vector & params) { - uint32_t x_max,y_max,z_max; - DFHack::designations40d designations; - DFHack::tiletypes40d tiles; - - int32_t oldT, newT; uint64_t count = 0; - int dirty=0; for(int i = 0; i < params.size();i++) { if(params[i] == "help" || params[i] == "?") @@ -62,55 +58,45 @@ DFhackCExport command_result tubefill(DFHack::Core * c, std::vector return CR_FAILURE; } - Maps::getSize(x_max,y_max,z_max); - // walk the map - for (uint32_t x = 0; x< x_max;x++) + for (uint32_t i = 0; i < world->map.map_blocks.size(); i++) { - for (uint32_t y = 0; y< y_max;y++) + df::map_block *block = world->map.map_blocks[i]; + df::map_block *above = Maps::getBlockAbs(block->map_pos.x, block->map_pos.y, block->map_pos.z + 1); + if (block->local_feature == -1) + continue; + DFHack::t_feature feature; + DFCoord coord(block->map_pos.x >> 4, block->map_pos.y >> 4, block->map_pos.z); + if (!Maps::GetLocalFeature(feature, coord, block->local_feature)) + continue; + if (feature.type != df::feature_type::deep_special_tube) + continue; + for (uint32_t x = 0; x < 16; x++) { - for (uint32_t z = 0; z< z_max;z++) + for (uint32_t y = 0; y < 16; y++) { - DFHack::t_feature locf; - DFHack::t_feature glof; - if (Maps::ReadFeatures(x,y,z,&locf,&glof)) - { - // we're looking for addy tubes - if(locf.type == -1) continue; - if(locf.type != df::feature_type::deep_special_tube) continue; + if (!block->designation[x][y].bits.feature_local) + continue; - dirty=0; - Maps::ReadDesignations(x,y,z, &designations); - Maps::ReadTileTypes(x,y,z, &tiles); + // Is the tile already a wall? + if (tileShape(block->tiletype[x][y]) == WALL) + continue; - for (uint32_t ty=0;ty<16;++ty) - { - for (uint32_t tx=0;tx<16;++tx) - { - if(!designations[tx][ty].bits.feature_local) continue; - oldT = tiles[tx][ty]; - if ( DFHack::tileShape(oldT) != DFHack::WALL ) - { - //Current tile is not a wall. - //Set current tile, as accurately as can be expected - //newT = DFHack::findSimilarTileType(oldT,DFHack::WALL); - newT = DFHack::findTileType( DFHack::WALL, DFHack::FEATSTONE, DFHack::tilevariant_invalid, DFHack::TILE_NORMAL, DFHack::TileDirection() ); + // Set current tile, as accurately as can be expected + // block->tiletype[x][y] = findSimilarTileType(block->tiletype[x][y], WALL); - //If no change, skip it (couldn't find a good tile type) - if ( oldT == newT) continue; - //Set new tile type, clear designation - tiles[tx][ty] = newT; - dirty=1; - ++count; - } - } - } - //If anything was changed, write it all. - if (dirty) - { - Maps::WriteTileTypes(x,y,z, &tiles); - } + // Check the tile above this one, in case we need to add a floor + if (above) + { + // if this tile isn't a local feature, it's likely the tile underneath was originally just a floor + // it's also possible there was just solid non-feature stone above, but we don't care enough to check + if (!above->designation[x][y].bits.feature_local) + continue; + if ((tileShape(above->tiletype[x][y]) == EMPTY) || (tileShape(above->tiletype[x][y]) == RAMP_TOP)) + above->tiletype[x][y] = findTileType(FLOOR, FEATSTONE, tilevariant_invalid, TILE_NORMAL, TileDirection()); } + block->tiletype[x][y] = findTileType(WALL, FEATSTONE, tilevariant_invalid, TILE_NORMAL, TileDirection()); + ++count; } } }