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/jobutils.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/jobutils.cpp')
| -rw-r--r-- | plugins/jobutils.cpp | 116 |
1 files changed, 58 insertions, 58 deletions
diff --git a/plugins/jobutils.cpp b/plugins/jobutils.cpp index e8141423..ca234423 100644 --- a/plugins/jobutils.cpp +++ b/plugins/jobutils.cpp @@ -39,15 +39,15 @@ using df::global::job_next_id; /* Plugin registration */ -static bool job_material_hotkey(Core *c, df::viewscreen *top); +static bool job_material_hotkey(df::viewscreen *top); -static command_result job_material(Core *c, vector <string> & parameters); -static command_result job_duplicate(Core *c, vector <string> & parameters); -static command_result job_cmd(Core *c, vector <string> & parameters); +static command_result job_material(color_ostream &out, vector <string> & parameters); +static command_result job_duplicate(color_ostream &out, vector <string> & parameters); +static command_result job_cmd(color_ostream &out, vector <string> & parameters); DFHACK_PLUGIN("jobutils"); -DFhackCExport command_result plugin_init (Core *c, std::vector <PluginCommand> &commands) +DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands) { if (!world || !ui) return CR_FAILURE; @@ -99,31 +99,31 @@ 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; } /* UI state guards */ -static bool job_material_hotkey(Core *c, df::viewscreen *top) +static bool job_material_hotkey(df::viewscreen *top) { - return Gui::workshop_job_hotkey(c, top) || - Gui::build_selector_hotkey(c, top); + return Gui::workshop_job_hotkey(top) || + Gui::build_selector_hotkey(top); } /* job-material implementation */ -static command_result job_material_in_job(Core *c, MaterialInfo &new_mat) +static command_result job_material_in_job(color_ostream &out, MaterialInfo &new_mat) { - df::job *job = Gui::getSelectedWorkshopJob(c); + df::job *job = Gui::getSelectedWorkshopJob(out); if (!job) return CR_FAILURE; if (!new_mat.isValid() || new_mat.type != 0) { - c->con.printerr("New job material isn't inorganic: %s\n", - new_mat.toString().c_str()); + out.printerr("New job material isn't inorganic: %s\n", + new_mat.toString().c_str()); return CR_FAILURE; } @@ -131,22 +131,22 @@ static command_result job_material_in_job(Core *c, MaterialInfo &new_mat) if (!cur_mat.isValid() || cur_mat.type != 0) { - c->con.printerr("Current job material isn't inorganic: %s\n", - cur_mat.toString().c_str()); + out.printerr("Current job material isn't inorganic: %s\n", + cur_mat.toString().c_str()); return CR_FAILURE; } df::craft_material_class old_class = cur_mat.getCraftClass(); if (old_class == craft_material_class::None) { - c->con.printerr("Unexpected current material type: %s\n", - cur_mat.toString().c_str()); + out.printerr("Unexpected current material type: %s\n", + cur_mat.toString().c_str()); return CR_FAILURE; } if (new_mat.getCraftClass() != old_class) { - c->con.printerr("New material %s does not satisfy requirement: %s\n", - new_mat.toString().c_str(), ENUM_KEY_STR(craft_material_class, old_class)); + out.printerr("New material %s does not satisfy requirement: %s\n", + new_mat.toString().c_str(), ENUM_KEY_STR(craft_material_class, old_class)); return CR_FAILURE; } @@ -157,15 +157,15 @@ static command_result job_material_in_job(Core *c, MaterialInfo &new_mat) if (item_mat != cur_mat) { - c->con.printerr("Job item %d has different material: %s\n", - i, item_mat.toString().c_str()); + out.printerr("Job item %d has different material: %s\n", + i, item_mat.toString().c_str()); return CR_FAILURE; } if (!new_mat.matches(*item)) { - c->con.printerr("Job item %d requirements not satisfied by %s.\n", - i, new_mat.toString().c_str()); + out.printerr("Job item %d requirements not satisfied by %s.\n", + i, new_mat.toString().c_str()); return CR_FAILURE; } } @@ -181,8 +181,8 @@ static command_result job_material_in_job(Core *c, MaterialInfo &new_mat) item->mat_index = new_mat.index; } - c->con << "Applied material '" << new_mat.toString() - << "' to job " << ENUM_KEY_STR(job_type,job->job_type) << endl; + out << "Applied material '" << new_mat.toString() + << "' to job " << ENUM_KEY_STR(job_type,job->job_type) << endl; return CR_OK; } @@ -212,7 +212,7 @@ static bool build_choice_matches(df::ui_build_item_req *req, df::build_req_choic return false; } -static command_result job_material_in_build(Core *c, MaterialInfo &new_mat) +static command_result job_material_in_build(color_ostream &out, MaterialInfo &new_mat) { df::ui_build_selector *sel = ui_build_selector; df::ui_build_item_req *req = sel->requirements[ui_build_selector->req_index]; @@ -234,11 +234,11 @@ static command_result job_material_in_build(Core *c, MaterialInfo &new_mat) } } - c->con.printerr("Could not find material in list: %s\n", new_mat.toString().c_str()); + out.printerr("Could not find material in list: %s\n", new_mat.toString().c_str()); return CR_FAILURE; } -static command_result job_material(Core * c, vector <string> & parameters) +static command_result job_material(color_ostream &out, vector <string> & parameters) { // HOTKEY COMMAND: CORE ALREADY SUSPENDED @@ -246,7 +246,7 @@ static command_result job_material(Core * c, vector <string> & parameters) if (parameters.size() == 1) { if (!new_mat.find(parameters[0])) { - c->con.printerr("Could not find material: %s\n", parameters[0].c_str()); + out.printerr("Could not find material: %s\n", parameters[0].c_str()); return CR_WRONG_USAGE; } } @@ -254,21 +254,21 @@ static command_result job_material(Core * c, vector <string> & parameters) return CR_WRONG_USAGE; if (ui->main.mode == ui_sidebar_mode::QueryBuilding) - return job_material_in_job(c, new_mat); + return job_material_in_job(out, new_mat); if (ui->main.mode == ui_sidebar_mode::Build) - return job_material_in_build(c, new_mat); + return job_material_in_build(out, new_mat); return CR_WRONG_USAGE; } /* job-duplicate implementation */ -static command_result job_duplicate(Core * c, vector <string> & parameters) +static command_result job_duplicate(color_ostream &out, vector <string> & parameters) { if (!parameters.empty()) return CR_WRONG_USAGE; - df::job *job = Gui::getSelectedWorkshopJob(c); + df::job *job = Gui::getSelectedWorkshopJob(out); if (!job) return CR_FAILURE; @@ -277,14 +277,14 @@ static command_result job_duplicate(Core * c, vector <string> & parameters) job->job_type != job_type::CollectSand && job->job_type != job_type::CollectClay)) { - c->con.printerr("Cannot duplicate job %s\n", ENUM_KEY_STR(job_type,job->job_type)); + out.printerr("Cannot duplicate job %s\n", ENUM_KEY_STR(job_type,job->job_type)); return CR_FAILURE; } df::building *building = world->selected_building; if (building->jobs.size() >= 10) { - c->con.printerr("Job list is already full.\n"); + out.printerr("Job list is already full.\n"); return CR_FAILURE; } @@ -299,40 +299,40 @@ static command_result job_duplicate(Core * c, vector <string> & parameters) /* Main job command implementation */ -static df::job_item *getJobItem(Core *c, df::job *job, std::string idx) +static df::job_item *getJobItem(color_ostream &out, df::job *job, std::string idx) { if (!job) return NULL; int v = atoi(idx.c_str()); if (v < 1 || v > job->job_items.size()) { - c->con.printerr("Invalid item index.\n"); + out.printerr("Invalid item index.\n"); return NULL; } return job->job_items[v-1]; } -static command_result job_cmd(Core * c, vector <string> & parameters) +static command_result job_cmd(color_ostream &out, vector <string> & parameters) { - CoreSuspender suspend(c); + CoreSuspender suspend; std::string cmd = (parameters.empty() ? "query" : parameters[0]); if (cmd == "query" || cmd == "list") { - df::job *job = Gui::getSelectedJob(c); + df::job *job = Gui::getSelectedJob(out); if (!job) return CR_WRONG_USAGE; if (cmd == "query") { - printJobDetails(c, job); + printJobDetails(out, job); } else { - if (!Gui::workshop_job_hotkey(c, c->getTopViewscreen())) + if (!Gui::workshop_job_hotkey(Core::getTopViewscreen())) return CR_WRONG_USAGE; df::building *selected = world->selected_building; for (size_t i = 0; i < selected->jobs.size(); i++) - printJobDetails(c, selected->jobs[i]); + printJobDetails(out, selected->jobs[i]); } } else if (cmd == "item-material") @@ -340,8 +340,8 @@ static command_result job_cmd(Core * c, vector <string> & parameters) if (parameters.size() != 3) return CR_WRONG_USAGE; - df::job *job = Gui::getSelectedJob(c); - df::job_item *item = getJobItem(c, job, parameters[1]); + df::job *job = Gui::getSelectedJob(out); + df::job_item *item = getJobItem(out, job, parameters[1]); if (!item) return CR_WRONG_USAGE; @@ -349,13 +349,13 @@ static command_result job_cmd(Core * c, vector <string> & parameters) MaterialInfo minfo; if (!minfo.find(parameters[2])) { - c->con.printerr("Could not find the specified material.\n"); + out.printerr("Could not find the specified material.\n"); return CR_FAILURE; } if (minfo.isValid() && !iinfo.matches(*item, &minfo)) { - c->con.printerr("Material does not match the requirements.\n"); - printJobDetails(c, job); + out.printerr("Material does not match the requirements.\n"); + printJobDetails(out, job); return CR_FAILURE; } @@ -370,13 +370,13 @@ static command_result job_cmd(Core * c, vector <string> & parameters) item->mat_type = minfo.type; item->mat_index = minfo.index; - c->con << "Job item updated." << endl; + out << "Job item updated." << endl; if (item->item_type < 0 && minfo.isValid()) - c->con.printerr("WARNING: Due to a probable bug, creature & plant material subtype\n" + out.printerr("WARNING: Due to a probable bug, creature & plant material subtype\n" " is ignored unless the item type is also specified.\n"); - printJobDetails(c, job); + printJobDetails(out, job); return CR_OK; } else if (cmd == "item-type") @@ -384,8 +384,8 @@ static command_result job_cmd(Core * c, vector <string> & parameters) if (parameters.size() != 3) return CR_WRONG_USAGE; - df::job *job = Gui::getSelectedJob(c); - df::job_item *item = getJobItem(c, job, parameters[1]); + df::job *job = Gui::getSelectedJob(out); + df::job_item *item = getJobItem(out, job, parameters[1]); if (!item) return CR_WRONG_USAGE; @@ -393,21 +393,21 @@ static command_result job_cmd(Core * c, vector <string> & parameters) MaterialInfo minfo(item); if (!iinfo.find(parameters[2])) { - c->con.printerr("Could not find the specified item type.\n"); + out.printerr("Could not find the specified item type.\n"); return CR_FAILURE; } if (iinfo.isValid() && !iinfo.matches(*item, &minfo)) { - c->con.printerr("Item type does not match the requirements.\n"); - printJobDetails(c, job); + out.printerr("Item type does not match the requirements.\n"); + printJobDetails(out, job); return CR_FAILURE; } item->item_type = iinfo.type; item->item_subtype = iinfo.subtype; - c->con << "Job item updated." << endl; - printJobDetails(c, job); + out << "Job item updated." << endl; + printJobDetails(out, job); return CR_OK; } else |
