summaryrefslogtreecommitdiff
path: root/plugins/dwarfexport
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/dwarfexport
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/dwarfexport')
-rw-r--r--plugins/dwarfexport/dwarfexport.cpp43
1 files changed, 21 insertions, 22 deletions
diff --git a/plugins/dwarfexport/dwarfexport.cpp b/plugins/dwarfexport/dwarfexport.cpp
index 5ac8fb24..9cdf0573 100644
--- a/plugins/dwarfexport/dwarfexport.cpp
+++ b/plugins/dwarfexport/dwarfexport.cpp
@@ -32,12 +32,12 @@ using df::global::world;
// Here go all the command declarations...
// mostly to allow having the mandatory stuff on top of the file and commands on the bottom
-command_result export_dwarves (Core * c, std::vector <std::string> & parameters);
+command_result export_dwarves (color_ostream &con, std::vector <std::string> & parameters);
DFHACK_PLUGIN("dwarfexport");
// Mandatory init function. If you have some global state, create it here.
-DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
+DFhackCExport command_result plugin_init (color_ostream &con, std::vector <PluginCommand> &commands)
{
// Fill the command list with your commands.
commands.push_back(PluginCommand("dwarfexport",
@@ -48,7 +48,7 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
}
// This is called right before the plugin library is removed from memory.
-DFhackCExport command_result plugin_shutdown ( Core * c )
+DFhackCExport command_result plugin_shutdown (color_ostream &con)
{
return CR_OK;
}
@@ -86,7 +86,7 @@ static void element(const char* name, const uint32_t content, ostream& out, cons
out << extra_indent << " <" << name << ">" << content << "</" << name << ">" << endl;
}
-static void printAttributes(Core* c, df::unit* cre, ostream& out) {
+static void printAttributes(color_ostream &con, df::unit* cre, ostream& out) {
out << " <Attributes>" << endl;
for (int i = 0; i < NUM_CREATURE_PHYSICAL_ATTRIBUTES; i++) {
element(physicals[i], cre->body.physical_attrs[i].unk1, out, " ");
@@ -101,7 +101,7 @@ static void printAttributes(Core* c, df::unit* cre, ostream& out) {
out << " </Attributes>" << endl;
}
-static void printTraits(Core* c, df::unit* cre, ostream& out)
+static void printTraits(color_ostream &con, df::unit* cre, ostream& out)
{
out << " <Traits>" << endl;
@@ -114,7 +114,7 @@ static void printTraits(Core* c, df::unit* cre, ostream& out)
"' value='" << s->traits[index] << "'>";
//FIXME: needs reimplementing trait string generation
/*
- string trait = c->vinfo->getTrait(i, s->traits[i]);
+ string trait = con->vinfo->getTrait(i, s->traits[i]);
if (!trait.empty()) {
out << trait.c_str();
}
@@ -139,7 +139,7 @@ static int32_t getCreatureAge(df::unit* cre)
return yearDifference;
}
-static void printLabors(Core* c, df::unit* cre, ostream& out)
+static void printLabors(color_ostream &con, df::unit* cre, ostream& out)
{
// Using British spelling here, consistent with Runesmith
out << " <Labours>" << endl;
@@ -154,7 +154,7 @@ static void printLabors(Core* c, df::unit* cre, ostream& out)
out << " </Labours>" << endl;
}
-static void printSkill(Core* c, df::unit_skill* skill, ostream& out)
+static void printSkill(color_ostream &con, df::unit_skill* skill, ostream& out)
{
out << " <Skill>" << endl;
@@ -164,7 +164,7 @@ static void printSkill(Core* c, df::unit_skill* skill, ostream& out)
out << " </Skill>" << endl;
}
-static void printSkills(Core* c, df::unit* cre, ostream& out)
+static void printSkills(color_ostream &con, df::unit* cre, ostream& out)
{
std::vector<df::unit_skill* > vSkills = cre->status.current_soul->skills;
@@ -172,7 +172,7 @@ static void printSkills(Core* c, df::unit* cre, ostream& out)
out << " <Skills>" << endl;
for (int iCount = 0; iCount < vSkills.size(); iCount++)
{
- printSkill(c, vSkills.at(iCount), out);
+ printSkill(con, vSkills.at(iCount), out);
}
out << " </Skills>" << endl;
@@ -184,43 +184,43 @@ static void printSkills(Core* c, df::unit* cre, ostream& out)
// Sex
// Attributes
// Traits
-static void export_dwarf(Core* c, df::unit* cre, ostream& out) {
+static void export_dwarf(color_ostream &con, df::unit* cre, ostream& out) {
string info = cre->name.first_name;
info += " ";
info += Translation::TranslateName(&cre->name, false);
info[0] = toupper(info[0]);
- c->con.print("Exporting %s\n", info.c_str());
+ con.print("Exporting %s\n", info.c_str());
out << " <Creature>" << endl;
element("Name", info.c_str(), out);
element("Nickname", cre->name.nickname.c_str(), out);
element("Sex", cre->sex == 0 ? "Female" : "Male", out);
element("Age", getCreatureAge(cre), out); // Added age, active labors, and skills March 9, 2012
- printAttributes(c, cre, out);
- printTraits(c, cre, out);
- printLabors(c, cre, out);
- printSkills(c, cre, out);
+ printAttributes(con, cre, out);
+ printTraits(con, cre, out);
+ printLabors(con, cre, out);
+ printSkills(con, cre, out);
out << " </Creature>" << endl;
}
-command_result export_dwarves (Core * c, std::vector <std::string> & parameters)
+command_result export_dwarves (color_ostream &con, std::vector <std::string> & parameters)
{
string filename;
if (parameters.size() == 1) {
filename = parameters[0];
} else {
- c->con.print("export <filename>\n");
+ con.print("export <filename>\n");
return CR_OK;
}
ofstream outf(filename);
if (!outf) {
- c->con.printerr("Failed to open file %s\n", filename.c_str());
+ con.printerr("Failed to open file %s\n", filename.c_str());
return CR_FAILURE;
}
- c->Suspend();
+ CoreSuspender suspend;
uint32_t race = ui->race_id;
uint32_t civ = ui->civ_id;
@@ -231,11 +231,10 @@ command_result export_dwarves (Core * c, std::vector <std::string> & parameters)
{
df::unit* cre = world->units.all[i];
if (cre->race == race && cre->civ_id == civ) {
- export_dwarf(c, cre, outf);
+ export_dwarf(con, cre, outf);
}
}
outf << "</Creatures>" << endl;
- c->Resume();
return CR_OK;
}