summaryrefslogtreecommitdiff
path: root/plugins/reveal.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/reveal.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/reveal.cpp')
-rw-r--r--plugins/reveal.cpp81
1 files changed, 41 insertions, 40 deletions
diff --git a/plugins/reveal.cpp b/plugins/reveal.cpp
index a5d00195..ed9f1332 100644
--- a/plugins/reveal.cpp
+++ b/plugins/reveal.cpp
@@ -58,15 +58,15 @@ enum revealstate
revealstate revealed = NOT_REVEALED;
-command_result reveal(DFHack::Core * c, std::vector<std::string> & params);
-command_result unreveal(DFHack::Core * c, std::vector<std::string> & params);
-command_result revtoggle(DFHack::Core * c, std::vector<std::string> & params);
-command_result revflood(DFHack::Core * c, std::vector<std::string> & params);
-command_result nopause(DFHack::Core * c, std::vector<std::string> & params);
+command_result reveal(color_ostream &out, std::vector<std::string> & params);
+command_result unreveal(color_ostream &out, std::vector<std::string> & params);
+command_result revtoggle(color_ostream &out, std::vector<std::string> & params);
+command_result revflood(color_ostream &out, std::vector<std::string> & params);
+command_result nopause(color_ostream &out, std::vector<std::string> & params);
DFHACK_PLUGIN("reveal");
-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("reveal","Reveal the map. 'reveal hell' will also reveal hell. 'reveal demon' won't pause.",reveal));
@@ -77,9 +77,9 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
return CR_OK;
}
-DFhackCExport command_result plugin_onupdate ( Core * c )
+DFhackCExport command_result plugin_onupdate ( color_ostream &out )
{
- DFHack::World *World =c->getWorld();
+ DFHack::World *World = Core::getInstance().getWorld();
t_gamemodes gm;
World->ReadGameMode(gm);
if(gm.g_mode == GAMEMODE_DWARF)
@@ -97,12 +97,12 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
return CR_OK;
}
-DFhackCExport command_result plugin_shutdown ( Core * c )
+DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{
return CR_OK;
}
-command_result nopause (Core * c, std::vector <std::string> & parameters)
+command_result nopause (color_ostream &out, std::vector <std::string> & parameters)
{
if (parameters.size() == 1 && (parameters[0] == "0" || parameters[0] == "1"))
{
@@ -110,17 +110,17 @@ command_result nopause (Core * c, std::vector <std::string> & parameters)
nopause_state = 0;
else
nopause_state = 1;
- c->con.print("nopause %sactivated.\n", (nopause_state ? "" : "de"));
+ out.print("nopause %sactivated.\n", (nopause_state ? "" : "de"));
}
else
{
- c->con.print("Disable pausing (doesn't affect pause forced by reveal).\nActivate with 'nopause 1', deactivate with 'nopause 0'.\nCurrent state: %d.\n", nopause_state);
+ out.print("Disable pausing (doesn't affect pause forced by reveal).\nActivate with 'nopause 1', deactivate with 'nopause 0'.\nCurrent state: %d.\n", nopause_state);
}
return CR_OK;
}
-void revealAdventure(DFHack::Core * c)
+void revealAdventure(color_ostream &out)
{
for (size_t i = 0; i < world->map.map_blocks.size(); i++)
{
@@ -138,10 +138,10 @@ void revealAdventure(DFHack::Core * c)
designations[x][y].bits.pile = 1;
}
}
- c->con.print("Local map revealed.\n");
+ out.print("Local map revealed.\n");
}
-command_result reveal(DFHack::Core * c, std::vector<std::string> & params)
+command_result reveal(color_ostream &out, std::vector<std::string> & params)
{
bool no_hell = true;
bool pause = true;
@@ -151,7 +151,7 @@ command_result reveal(DFHack::Core * c, std::vector<std::string> & params)
no_hell = false;
else if(params[i] == "help" || params[i] == "?")
{
- c->con.print("Reveals the map, by default ignoring hell.\n"
+ out.print("Reveals the map, by default ignoring hell.\n"
"Options:\n"
"hell - also reveal hell, while forcing the game to pause.\n"
"demon - reveal hell, do not pause.\n"
@@ -168,25 +168,26 @@ command_result reveal(DFHack::Core * c, std::vector<std::string> & params)
no_hell = false;
pause = false;
}
- Console & con = c->con;
+ auto & con = out;
if(revealed != NOT_REVEALED)
{
con.printerr("Map is already revealed or this is a different map.\n");
return CR_FAILURE;
}
- CoreSuspender suspend(c);
- DFHack::World *World =c->getWorld();
+ CoreSuspender suspend;
+
+ DFHack::World *World = Core::getInstance().getWorld();
if (!Maps::IsValid())
{
- c->con.printerr("Map is not available!\n");
+ out.printerr("Map is not available!\n");
return CR_FAILURE;
}
t_gamemodes gm;
World->ReadGameMode(gm);
if(gm.g_mode == GAMEMODE_ADVENTURE)
{
- revealAdventure(c);
+ revealAdventure(out);
return CR_OK;
}
if(gm.g_mode != GAMEMODE_DWARF)
@@ -237,14 +238,14 @@ command_result reveal(DFHack::Core * c, std::vector<std::string> & params)
return CR_OK;
}
-command_result unreveal(DFHack::Core * c, std::vector<std::string> & params)
+command_result unreveal(color_ostream &out, std::vector<std::string> & params)
{
- Console & con = c->con;
+ auto & con = out;
for(size_t i = 0; i < params.size();i++)
{
if(params[i] == "help" || params[i] == "?")
{
- c->con.print("Reverts the previous reveal operation, hiding the map again.\n");
+ out.print("Reverts the previous reveal operation, hiding the map again.\n");
return CR_OK;
}
}
@@ -253,12 +254,12 @@ command_result unreveal(DFHack::Core * c, std::vector<std::string> & params)
con.printerr("There's nothing to revert!\n");
return CR_FAILURE;
}
- CoreSuspender suspend(c);
+ CoreSuspender suspend;
- DFHack::World *World =c->getWorld();
+ DFHack::World *World = Core::getInstance().getWorld();
if (!Maps::IsValid())
{
- c->con.printerr("Map is not available!\n");
+ out.printerr("Map is not available!\n");
return CR_FAILURE;
}
t_gamemodes gm;
@@ -294,56 +295,56 @@ command_result unreveal(DFHack::Core * c, std::vector<std::string> & params)
return CR_OK;
}
-command_result revtoggle (DFHack::Core * c, std::vector<std::string> & params)
+command_result revtoggle (color_ostream &out, std::vector<std::string> & params)
{
for(size_t i = 0; i < params.size();i++)
{
if(params[i] == "help" || params[i] == "?")
{
- c->con.print("Toggles between reveal and unreveal.\nCurrently it: ");
+ out.print("Toggles between reveal and unreveal.\nCurrently it: ");
break;
}
}
if(revealed)
{
- return unreveal(c,params);
+ return unreveal(out,params);
}
else
{
- return reveal(c,params);
+ return reveal(out,params);
}
}
-command_result revflood(DFHack::Core * c, std::vector<std::string> & params)
+command_result revflood(color_ostream &out, std::vector<std::string> & params)
{
for(size_t i = 0; i < params.size();i++)
{
if(params[i] == "help" || params[i] == "?")
{
- c->con.print("This command hides the whole map. Then, starting from the cursor,\n"
+ out.print("This command hides the whole map. Then, starting from the cursor,\n"
"reveals all accessible tiles. Allows repairing parma-revealed maps.\n"
);
return CR_OK;
}
}
- CoreSuspender suspend(c);
+ CoreSuspender suspend;
uint32_t x_max,y_max,z_max;
- World * World = c->getWorld();
+ World * World = Core::getInstance().getWorld();
if (!Maps::IsValid())
{
- c->con.printerr("Map is not available!\n");
+ out.printerr("Map is not available!\n");
return CR_FAILURE;
}
if(revealed != NOT_REVEALED)
{
- c->con.printerr("This is only safe to use with non-revealed map.\n");
+ out.printerr("This is only safe to use with non-revealed map.\n");
return CR_FAILURE;
}
t_gamemodes gm;
World->ReadGameMode(gm);
if(gm.g_type != GAMETYPE_DWARF_MAIN && gm.g_mode != GAMEMODE_DWARF )
{
- c->con.printerr("Only in proper dwarf mode.\n");
+ out.printerr("Only in proper dwarf mode.\n");
return CR_FAILURE;
}
int32_t cx, cy, cz;
@@ -354,7 +355,7 @@ command_result revflood(DFHack::Core * c, std::vector<std::string> & params)
Gui::getCursorCoords(cx,cy,cz);
if(cx == -30000)
{
- c->con.printerr("Cursor is not active. Point the cursor at some empty space you want to be unhidden.\n");
+ out.printerr("Cursor is not active. Point the cursor at some empty space you want to be unhidden.\n");
return CR_FAILURE;
}
DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz);
@@ -362,7 +363,7 @@ command_result revflood(DFHack::Core * c, std::vector<std::string> & params)
df::tiletype tt = MCache->tiletypeAt(xy);
if(isWallTerrain(tt))
{
- c->con.printerr("Point the cursor at some empty space you want to be unhidden.\n");
+ out.printerr("Point the cursor at some empty space you want to be unhidden.\n");
delete MCache;
return CR_FAILURE;
}