speed up dig blueprint creation by 70%

remove the unneeded cache layer. the cache is for writing. we're just
reading. all the cache is doing is adding latency as it makes its copies
of map data structures.

generating a 190x190x100 dig blueprint:
before change: 1.7s
after change:  1.0s

the performance gains aren't as important here as the reduced complexity
of the algorithm, though. for reasonably-sized blueprints, the time
savings are unnoticeable.
develop
myk002 2021-04-25 09:43:40 -07:00
parent c7958480bd
commit 9b416a8662
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
1 changed files with 10 additions and 10 deletions

@ -1,6 +1,9 @@
//Blueprint /**
//By cdombroski * Translates a region of tiles specified by the cursor and arguments/prompts
//Translates a region of tiles specified by the cursor and arguments/prompts into a series of blueprint files suitable for digfort/buildingplan/quickfort * into a series of blueprint files suitable for replay via quickfort.
*
* Written by cdombroski.
*/
#include <algorithm> #include <algorithm>
#include <sstream> #include <sstream>
@ -43,7 +46,7 @@ command_result blueprint(color_ostream &out, vector <string> &parameters);
DFhackCExport command_result plugin_init(color_ostream &out, vector<PluginCommand> &commands) DFhackCExport command_result plugin_init(color_ostream &out, vector<PluginCommand> &commands)
{ {
commands.push_back(PluginCommand("blueprint", "Convert map tiles into a blueprint", blueprint, false)); commands.push_back(PluginCommand("blueprint", "Record the structure of a live game map in a quickfort blueprint", blueprint, false));
return CR_OK; return CR_OK;
} }
@ -76,10 +79,9 @@ pair<uint32_t, uint32_t> get_building_size(df::building* b)
return pair<uint32_t, uint32_t>(b->x2 - b->x1 + 1, b->y2 - b->y1 + 1); return pair<uint32_t, uint32_t>(b->x2 - b->x1 + 1, b->y2 - b->y1 + 1);
} }
char get_tile_dig(MapExtras::MapCache mc, int32_t x, int32_t y, int32_t z) char get_tile_dig(int32_t x, int32_t y, int32_t z)
{ {
df::tiletype tt = mc.tiletypeAt(DFCoord(x, y, z)); df::tiletype_shape ts = tileShape(*Maps::getTileType(x, y , z));
df::tiletype_shape ts = tileShape(tt);
switch (ts) switch (ts)
{ {
case tiletype_shape::EMPTY: case tiletype_shape::EMPTY:
@ -102,7 +104,6 @@ char get_tile_dig(MapExtras::MapCache mc, int32_t x, int32_t y, int32_t z)
return 'r'; return 'r';
default: default:
return ' '; return ' ';
} }
} }
@ -629,7 +630,6 @@ command_result do_transform(DFCoord start, DFCoord end, string name, uint32_t ph
end.z++; end.z++;
} }
MapExtras::MapCache mc;
for (int32_t z = start.z; z < end.z; z++) for (int32_t z = start.z; z < end.z; z++)
{ {
for (int32_t y = start.y; y < end.y; y++) for (int32_t y = start.y; y < end.y; y++)
@ -644,7 +644,7 @@ command_result do_transform(DFCoord start, DFCoord end, string name, uint32_t ph
if (phases & BUILD) if (phases & BUILD)
build << get_tile_build(x, y, b) << ','; build << get_tile_build(x, y, b) << ',';
if (phases & DIG) if (phases & DIG)
dig << get_tile_dig(mc, x, y, z) << ','; dig << get_tile_dig(x, y, z) << ',';
} }
if (phases & QUERY) if (phases & QUERY)
query << "#" << endl; query << "#" << endl;