diff options
| author | Alexander Gavrilov | 2012-03-10 15:55:42 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-03-10 15:55:42 +0400 |
| commit | 8cc82d5876c902cbb4f0b3fa6cf15cf268dd942b (patch) | |
| tree | 4be7625f1bbe15b81d00373316047137d3422464 /plugins/tiletypes.cpp | |
| parent | b2737e2bed5f013a4dfbf6e19650ca60498a9afd (diff) | |
| download | dfhack-8cc82d5876c902cbb4f0b3fa6cf15cf268dd942b.tar.gz dfhack-8cc82d5876c902cbb4f0b3fa6cf15cf268dd942b.tar.bz2 dfhack-8cc82d5876c902cbb4f0b3fa6cf15cf268dd942b.tar.xz | |
Make plugins accept explicit output stream references.
This is an incompatible change to the plugin ABI.
The Console is not thread-safe unless used indirectly
via color_ostream_proxy, so everything should use their
per-thread stream.
Diffstat (limited to 'plugins/tiletypes.cpp')
| -rw-r--r-- | plugins/tiletypes.cpp | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/plugins/tiletypes.cpp b/plugins/tiletypes.cpp index 5b322e95..8825d811 100644 --- a/plugins/tiletypes.cpp +++ b/plugins/tiletypes.cpp @@ -633,11 +633,11 @@ public: CommandHistory tiletypes_hist; -command_result df_tiletypes (Core * c, vector <string> & parameters); +command_result df_tiletypes (color_ostream &out, vector <string> & parameters); DFHACK_PLUGIN("tiletypes"); -DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands) +DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) { tiletypes_hist.load("tiletypes.history"); commands.clear(); @@ -645,13 +645,13 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> return CR_OK; } -DFhackCExport command_result plugin_shutdown ( Core * c ) +DFhackCExport command_result plugin_shutdown ( color_ostream &out ) { tiletypes_hist.save("tiletypes.history"); return CR_OK; } -command_result df_tiletypes (Core * c, vector <string> & parameters) +command_result df_tiletypes (color_ostream &out, vector <string> & parameters) { uint32_t x_max = 0, y_max = 0, z_max = 0; int32_t x = 0, y = 0, z = 0; @@ -660,7 +660,7 @@ command_result df_tiletypes (Core * c, vector <string> & parameters) { if(parameters[i] == "help" || parameters[i] == "?") { - c->con.print("This tool allows painting tiles types with a brush, using an optional filter.\n" + out.print("This tool allows painting tiles types with a brush, using an optional filter.\n" "The tool is interactive, similarly to the liquids tool.\n" "Further help is available inside.\n" ); @@ -668,25 +668,28 @@ command_result df_tiletypes (Core * c, vector <string> & parameters) } } + assert(out.is_console()); + Console &con = static_cast<Console&>(out); + TileType filter, paint; Brush *brush = new RectangleBrush(1,1); bool end = false; std::string brushname = "point"; int width = 1, height = 1, z_levels = 1; - c->con << "Welcome to the tiletype tool.\nType 'help' or '?' for a list of available commands, 'q' to quit.\nPress return after a command to confirm." << std::endl; - c->con.printerr("THIS TOOL CAN BE DANGEROUS. YOU'VE BEEN WARNED.\n"); + con << "Welcome to the tiletype tool.\nType 'help' or '?' for a list of available commands, 'q' to quit.\nPress return after a command to confirm." << std::endl; + con.printerr("THIS TOOL CAN BE DANGEROUS. YOU'VE BEEN WARNED.\n"); while (!end) { - c->con << "Filter: " << filter << std::endl - << "Paint: " << paint << std::endl - << "Brush: " << brushname << std::endl; + con << "Filter: " << filter << std::endl + << "Paint: " << paint << std::endl + << "Brush: " << brushname << std::endl; std::string input = ""; std::string command = ""; std::string option = ""; std::string value = ""; - c->con.lineedit("tiletypes> ",input,tiletypes_hist); + con.lineedit("tiletypes> ",input,tiletypes_hist); tiletypes_hist.add(input); std::istringstream ss(input); ss >> command >> option >> value; @@ -695,7 +698,7 @@ command_result df_tiletypes (Core * c, vector <string> & parameters) if (command == "help" || command == "?") { - help(c->con,option); + help(con,option); } else if (command == "quit" || command == "q") { @@ -720,19 +723,19 @@ command_result df_tiletypes (Core * c, vector <string> & parameters) std::stringstream ss; CommandHistory hist; ss << "Set range width <" << width << "> "; - c->con.lineedit(ss.str(),command,hist); + con.lineedit(ss.str(),command,hist); width = command == "" ? width : toint(command); if (width < 1) width = 1; ss.str(""); ss << "Set range height <" << height << "> "; - c->con.lineedit(ss.str(),command,hist); + con.lineedit(ss.str(),command,hist); height = command == "" ? height : toint(command); if (height < 1) height = 1; ss.str(""); ss << "Set range z-levels <" << z_levels << "> "; - c->con.lineedit(ss.str(),command,hist); + con.lineedit(ss.str(),command,hist); z_levels = command == "" ? z_levels : toint(command); if (z_levels < 1) z_levels = 1; @@ -763,29 +766,30 @@ command_result df_tiletypes (Core * c, vector <string> & parameters) { if (paint.empty()) { - c->con.printerr("Set the paint first.\n"); + con.printerr("Set the paint first.\n"); continue; } - CoreSuspender suspend(c); + CoreSuspender suspend; + if (!Maps::IsValid()) { - c->con.printerr("Map is not available!\n"); + con.printerr("Map is not available!\n"); return CR_FAILURE; } Maps::getSize(x_max, y_max, z_max); if (!Gui::getCursorCoords(x,y,z)) { - c->con.printerr("Can't get cursor coords! Make sure you have a cursor active in DF.\n"); + con.printerr("Can't get cursor coords! Make sure you have a cursor active in DF.\n"); return CR_FAILURE; } - c->con.print("Cursor coords: (%d, %d, %d)\n",x,y,z); + con.print("Cursor coords: (%d, %d, %d)\n",x,y,z); DFHack::DFCoord cursor(x,y,z); MapExtras::MapCache map; coord_vec all_tiles = brush->points(map, cursor); - c->con.print("working...\n"); + con.print("working...\n"); for (coord_vec::iterator iter = all_tiles.begin(); iter != all_tiles.end(); ++iter) { @@ -895,11 +899,11 @@ command_result df_tiletypes (Core * c, vector <string> & parameters) if (map.WriteAll()) { - c->con.print("OK\n"); + con.print("OK\n"); } else { - c->con.printerr("Something failed horribly! RUN!\n"); + con.printerr("Something failed horribly! RUN!\n"); } } } |
