summaryrefslogtreecommitdiff
path: root/plugins/probe.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-03-10 15:55:42 +0400
committerAlexander Gavrilov2012-03-10 15:55:42 +0400
commit8cc82d5876c902cbb4f0b3fa6cf15cf268dd942b (patch)
tree4be7625f1bbe15b81d00373316047137d3422464 /plugins/probe.cpp
parentb2737e2bed5f013a4dfbf6e19650ca60498a9afd (diff)
downloaddfhack-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/probe.cpp')
-rw-r--r--plugins/probe.cpp169
1 files changed, 84 insertions, 85 deletions
diff --git a/plugins/probe.cpp b/plugins/probe.cpp
index ea3dd85e..04448d01 100644
--- a/plugins/probe.cpp
+++ b/plugins/probe.cpp
@@ -33,13 +33,13 @@ using namespace df::enums;
using df::global::world;
using df::global::cursor;
-command_result df_probe (Core * c, vector <string> & parameters);
-command_result df_cprobe (Core * c, vector <string> & parameters);
-command_result df_bprobe (Core * c, vector <string> & parameters);
+command_result df_probe (color_ostream &out, vector <string> & parameters);
+command_result df_cprobe (color_ostream &out, vector <string> & parameters);
+command_result df_bprobe (color_ostream &out, vector <string> & parameters);
DFHACK_PLUGIN("probe");
-DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
+DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("probe",
@@ -54,20 +54,19 @@ 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 )
{
return CR_OK;
}
-command_result df_cprobe (Core * c, vector <string> & parameters)
+command_result df_cprobe (color_ostream &out, vector <string> & parameters)
{
- Console & con = c->con;
- CoreSuspender suspend(c);
+ CoreSuspender suspend;
int32_t cursorX, cursorY, cursorZ;
Gui::getCursorCoords(cursorX,cursorY,cursorZ);
if(cursorX == -30000)
{
- con.printerr("No cursor; place cursor over creature to probe.\n");
+ out.printerr("No cursor; place cursor over creature to probe.\n");
}
else
{
@@ -76,7 +75,7 @@ command_result df_cprobe (Core * c, vector <string> & parameters)
df::unit * unit = world->units.all[i];
if(unit->pos.x == cursorX && unit->pos.y == cursorY && unit->pos.z == cursorZ)
{
- con.print("Creature %d, race %d (%x), civ %d (%x)\n", unit->id, unit->race, unit->race, unit->civ_id, unit->civ_id);
+ out.print("Creature %d, race %d (%x), civ %d (%x)\n", unit->id, unit->race, unit->race, unit->civ_id, unit->civ_id);
break;
}
}
@@ -84,29 +83,29 @@ command_result df_cprobe (Core * c, vector <string> & parameters)
return CR_OK;
}
-command_result df_probe (Core * c, vector <string> & parameters)
+command_result df_probe (color_ostream &out, vector <string> & parameters)
{
//bool showBlock, showDesig, showOccup, showTile, showMisc;
- Console & con = c->con;
+
/*
if (!parseOptions(parameters, showBlock, showDesig, showOccup,
showTile, showMisc))
{
- con.printerr("Unknown parameters!\n");
+ out.printerr("Unknown parameters!\n");
return CR_FAILURE;
}
*/
- CoreSuspender suspend(c);
+ CoreSuspender suspend;
+
+ DFHack::Materials *Materials = Core::getInstance().getMaterials();
- DFHack::Materials *Materials = c->getMaterials();
- DFHack::VersionInfo* mem = c->vinfo;
std::vector<t_matglossInorganic> inorganic;
bool hasmats = Materials->CopyInorganicMaterials(inorganic);
if (!Maps::IsValid())
{
- c->con.printerr("Map is not available!\n");
+ out.printerr("Map is not available!\n");
return CR_FAILURE;
}
MapExtras::MapCache mc;
@@ -118,7 +117,7 @@ command_result df_probe (Core * c, vector <string> & parameters)
Gui::getCursorCoords(cursorX,cursorY,cursorZ);
if(cursorX == -30000)
{
- con.printerr("No cursor; place cursor over tile to probe.\n");
+ out.printerr("No cursor; place cursor over tile to probe.\n");
return CR_FAILURE;
}
DFCoord cursor (cursorX,cursorY,cursorZ);
@@ -131,17 +130,17 @@ command_result df_probe (Core * c, vector <string> & parameters)
MapExtras::Block * b = mc.BlockAt(cursor/16);
if(!b && !b->valid)
{
- con.printerr("No data.\n");
+ out.printerr("No data.\n");
return CR_OK;
}
mapblock40d & block = b->raw;
- con.print("block addr: 0x%x\n\n", block.origin);
+ out.print("block addr: 0x%x\n\n", block.origin);
/*
if (showBlock)
{
- con.print("block flags:\n");
- print_bits<uint32_t>(block.blockflags.whole,con);
- con.print("\n\n");
+ out.print("block flags:\n");
+ print_bits<uint32_t>(block.blockflags.whole,out);
+ out.print("\n\n");
}
*/
df::tiletype tiletype = mc.tiletypeAt(cursor);
@@ -149,96 +148,96 @@ command_result df_probe (Core * c, vector <string> & parameters)
/*
if(showDesig)
{
- con.print("designation\n");
+ out.print("designation\n");
print_bits<uint32_t>(block.designation[tileX][tileY].whole,
- con);
- con.print("\n\n");
+ out);
+ out.print("\n\n");
}
if(showOccup)
{
- con.print("occupancy\n");
+ out.print("occupancy\n");
print_bits<uint32_t>(block.occupancy[tileX][tileY].whole,
- con);
- con.print("\n\n");
+ out);
+ out.print("\n\n");
}
*/
// tiletype
- con.print("tiletype: %d", tiletype);
+ out.print("tiletype: %d", tiletype);
if(tileName(tiletype))
- con.print(" = %s",tileName(tiletype));
- con.print("\n");
+ out.print(" = %s",tileName(tiletype));
+ out.print("\n");
df::tiletype_shape shape = tileShape(tiletype);
df::tiletype_material material = tileMaterial(tiletype);
df::tiletype_special special = tileSpecial(tiletype);
df::tiletype_variant variant = tileVariant(tiletype);
- con.print("%-10s: %4d %s\n","Class" ,shape,
+ out.print("%-10s: %4d %s\n","Class" ,shape,
ENUM_KEY_STR(tiletype_shape, shape));
- con.print("%-10s: %4d %s\n","Material" ,
+ out.print("%-10s: %4d %s\n","Material" ,
material, ENUM_KEY_STR(tiletype_material, material));
- con.print("%-10s: %4d %s\n","Special" ,
+ out.print("%-10s: %4d %s\n","Special" ,
special, ENUM_KEY_STR(tiletype_special, special));
- con.print("%-10s: %4d %s\n" ,"Variant" ,
+ out.print("%-10s: %4d %s\n" ,"Variant" ,
variant, ENUM_KEY_STR(tiletype_variant, variant));
- con.print("%-10s: %s\n" ,"Direction",
+ out.print("%-10s: %s\n" ,"Direction",
tileDirection(tiletype).getStr());
- con.print("\n");
+ out.print("\n");
- con.print("temperature1: %d U\n",mc.temperature1At(cursor));
- con.print("temperature2: %d U\n",mc.temperature2At(cursor));
+ out.print("temperature1: %d U\n",mc.temperature1At(cursor));
+ out.print("temperature2: %d U\n",mc.temperature2At(cursor));
// biome, geolayer
- con << "biome: " << des.bits.biome << std::endl;
- con << "geolayer: " << des.bits.geolayer_index
+ out << "biome: " << des.bits.biome << std::endl;
+ out << "geolayer: " << des.bits.geolayer_index
<< std::endl;
int16_t base_rock = mc.baseMaterialAt(cursor);
if(base_rock != -1)
{
- con << "Layer material: " << dec << base_rock;
+ out << "Layer material: " << dec << base_rock;
if(hasmats)
- con << " / " << inorganic[base_rock].id
+ out << " / " << inorganic[base_rock].id
<< " / "
<< inorganic[base_rock].name
<< endl;
else
- con << endl;
+ out << endl;
}
int16_t vein_rock = mc.veinMaterialAt(cursor);
if(vein_rock != -1)
{
- con << "Vein material (final): " << dec << vein_rock;
+ out << "Vein material (final): " << dec << vein_rock;
if(hasmats)
- con << " / " << inorganic[vein_rock].id
+ out << " / " << inorganic[vein_rock].id
<< " / "
<< inorganic[vein_rock].name
<< endl;
else
- con << endl;
+ out << endl;
}
// liquids
if(des.bits.flow_size)
{
if(des.bits.liquid_type == tile_liquid::Magma)
- con <<"magma: ";
- else con <<"water: ";
- con << des.bits.flow_size << std::endl;
+ out <<"magma: ";
+ else out <<"water: ";
+ out << des.bits.flow_size << std::endl;
}
if(des.bits.flow_forbid)
- con << "flow forbid" << std::endl;
+ out << "flow forbid" << std::endl;
if(des.bits.pile)
- con << "stockpile?" << std::endl;
+ out << "stockpile?" << std::endl;
if(des.bits.rained)
- con << "rained?" << std::endl;
+ out << "rained?" << std::endl;
if(des.bits.smooth)
- con << "smooth?" << std::endl;
+ out << "smooth?" << std::endl;
if(des.bits.water_salt)
- con << "salty" << endl;
+ out << "salty" << endl;
if(des.bits.water_stagnant)
- con << "stagnant" << endl;
+ out << "stagnant" << endl;
- #define PRINT_FLAG( X ) con.print("%-16s= %c\n", #X , ( des.X ? 'Y' : ' ' ) )
+ #define PRINT_FLAG( X ) out.print("%-16s= %c\n", #X , ( des.X ? 'Y' : ' ' ) )
PRINT_FLAG( bits.hidden );
PRINT_FLAG( bits.light );
PRINT_FLAG( bits.outside );
@@ -254,37 +253,37 @@ command_result df_probe (Core * c, vector <string> & parameters)
PRINT_FLAG( bits.feature_local );
if(local.type != -1)
{
- con.print("%-16s", "");
- con.print(" %4d", block.local_feature);
- con.print(" (%2d)", local.type);
- con.print(" addr 0x%X ", local.origin);
- con.print(" %s\n", sa_feature(local.type));
+ out.print("%-16s", "");
+ out.print(" %4d", block.local_feature);
+ out.print(" (%2d)", local.type);
+ out.print(" addr 0x%X ", local.origin);
+ out.print(" %s\n", sa_feature(local.type));
}
PRINT_FLAG( bits.feature_global );
if(global.type != -1)
{
- con.print("%-16s", "");
- con.print(" %4d", block.global_feature);
- con.print(" (%2d)", global.type);
- con.print(" %s\n", sa_feature(global.type));
+ out.print("%-16s", "");
+ out.print(" %4d", block.global_feature);
+ out.print(" (%2d)", global.type);
+ out.print(" %s\n", sa_feature(global.type));
}
#undef PRINT_FLAG
- con << "local feature idx: " << block.local_feature
+ out << "local feature idx: " << block.local_feature
<< endl;
- con << "global feature idx: " << block.global_feature
+ out << "global feature idx: " << block.global_feature
<< endl;
- con << "mystery: " << block.mystery << endl;
- con << std::endl;
+ out << "mystery: " << block.mystery << endl;
+ out << std::endl;
return CR_OK;
}
-command_result df_bprobe (Core * c, vector <string> & parameters)
+command_result df_bprobe (color_ostream &out, vector <string> & parameters)
{
- CoreSuspender suspend(c);
+ CoreSuspender suspend;
if(cursor->x == -30000)
{
- c->con.printerr("No cursor; place cursor over tile to probe.\n");
+ out.printerr("No cursor; place cursor over tile to probe.\n");
return CR_FAILURE;
}
@@ -299,38 +298,38 @@ command_result df_bprobe (Core * c, vector <string> & parameters)
continue;
string name;
building.origin->getName(&name);
- c->con.print("Building %i - \"%s\" - type %s", building.origin->id, name.c_str(), ENUM_KEY_STR(building_type, building.type));
+ out.print("Building %i - \"%s\" - type %s", building.origin->id, name.c_str(), ENUM_KEY_STR(building_type, building.type));
switch (building.type)
{
case building_type::Furnace:
- c->con.print(", subtype %s", ENUM_KEY_STR(furnace_type, building.furnace_type));
+ out.print(", subtype %s", ENUM_KEY_STR(furnace_type, building.furnace_type));
if (building.furnace_type == furnace_type::Custom)
- c->con.print(", custom type %i (%s)", building.custom_type, world->raws.buildings.all[building.custom_type]->code.c_str());
+ out.print(", custom type %i (%s)", building.custom_type, world->raws.buildings.all[building.custom_type]->code.c_str());
break;
case building_type::Workshop:
- c->con.print(", subtype %s", ENUM_KEY_STR(workshop_type, building.workshop_type));
+ out.print(", subtype %s", ENUM_KEY_STR(workshop_type, building.workshop_type));
if (building.workshop_type == workshop_type::Custom)
- c->con.print(", custom type %i (%s)", building.custom_type, world->raws.buildings.all[building.custom_type]->code.c_str());
+ out.print(", custom type %i (%s)", building.custom_type, world->raws.buildings.all[building.custom_type]->code.c_str());
break;
case building_type::Construction:
- c->con.print(", subtype %s", ENUM_KEY_STR(construction_type, building.construction_type));
+ out.print(", subtype %s", ENUM_KEY_STR(construction_type, building.construction_type));
break;
case building_type::Shop:
- c->con.print(", subtype %s", ENUM_KEY_STR(shop_type, building.shop_type));
+ out.print(", subtype %s", ENUM_KEY_STR(shop_type, building.shop_type));
break;
case building_type::SiegeEngine:
- c->con.print(", subtype %s", ENUM_KEY_STR(siegeengine_type, building.siegeengine_type));
+ out.print(", subtype %s", ENUM_KEY_STR(siegeengine_type, building.siegeengine_type));
break;
case building_type::Trap:
- c->con.print(", subtype %s", ENUM_KEY_STR(trap_type, building.trap_type));
+ out.print(", subtype %s", ENUM_KEY_STR(trap_type, building.trap_type));
break;
default:
if (building.subtype != -1)
- c->con.print(", subtype %i", building.subtype);
+ out.print(", subtype %i", building.subtype);
break;
}
- c->con.print("\n");
+ out.print("\n");
}
return CR_OK;