Add 'ostream' method to class StreamBuffer, and use it.

This commit is contained in:
2021-11-03 12:31:13 -04:00
parent 17a1155906
commit 7cbf40e3d6
5 changed files with 71 additions and 25 deletions

View File

@@ -5,7 +5,6 @@
#include <signal.h>
#include <vector>
#include <string>
#include <iostream>
#include "luastack.hpp"
#include "util.hpp"
#include "gui.hpp"
@@ -52,13 +51,13 @@ public:
void TextGame::do_view_command(const StringVec &cmd) {
if (cmd.size() != 1) {
std::cerr << "v command (view) takes no arguments" << std::endl;
stdostream() << "v command (view) takes no arguments" << std::endl;
return;
}
for (int64_t id : world_->get_near(actor_id_, 100, true)) {
const Tangible *tan = world_->tangible_get(id);
const AnimStep &aqback = tan->anim_queue_.back();
std::cerr << id << ": " << aqback.graphic() << " " << aqback.plane() << " " << aqback.xyz().debug_string() << std::endl;
stdostream() << id << ": " << aqback.graphic() << " " << aqback.plane() << " " << aqback.xyz().debug_string() << std::endl;
}
}
@@ -69,14 +68,14 @@ void TextGame::do_menu_command(const StringVec &cmd) {
} else if (cmd.size() == 2) {
id = util::strtoint(cmd[1], -1);
} else {
std::cerr << "m command (menu) expects a tangible ID or defaults to actor_id" << std::endl;
stdostream() << "m command (menu) expects a tangible ID or defaults to actor_id" << std::endl;
return;
}
gui_place_ = id;
world_->update_gui(actor_id_, id, &gui_);
int index = 0;
for (const GuiElt &elt : gui_.elts()) {
std::cerr << index << " " << elt.label() << std::endl;
stdostream() << index << " " << elt.label() << std::endl;
index += 1;
}
}
@@ -86,16 +85,16 @@ void TextGame::do_choose_command(const StringVec &cmd) {
if (cmd.size() == 1) {
index = util::strtoint(cmd[0], -1);
} else {
std::cerr << "c command (choose) expects a menu line number" << std::endl;
stdostream() << "c command (choose) expects a menu line number" << std::endl;
return;
}
const Gui::EltVec &elts = gui_.elts();
if ((index < 0) || (index >= int(elts.size()))) {
std::cerr << "No menu item #" << index << std::endl;
stdostream() << "No menu item #" << index << std::endl;
return;
}
std::string action = elts[index].action();
std::cerr << "Invoking plan: " << action << std::endl;
stdostream() << "Invoking plan: " << action << std::endl;
InvocationData dummyresult;
dummyresult["flavor"] = "chocolate";
dummyresult["color"] = "blue";
@@ -112,7 +111,7 @@ void TextGame::do_lua(const std::string &exp) {
void TextGame::do_snapshot_command(const StringVec &cmd) {
if (cmd.size() != 1) {
std::cerr << "s command (snapshot) takes no arguments" << std::endl;
stdostream() << "s command (snapshot) takes no arguments" << std::endl;
return;
}
world_->snapshot();
@@ -120,7 +119,7 @@ void TextGame::do_snapshot_command(const StringVec &cmd) {
void TextGame::do_rollback_command(const StringVec &cmd) {
if (cmd.size() != 1) {
std::cerr << "r command (rollback) takes no arguments" << std::endl;
stdostream() << "r command (rollback) takes no arguments" << std::endl;
return;
}
world_->rollback();
@@ -131,7 +130,7 @@ void TextGame::do_tick_command(const StringVec &cmd) {
if (cmd.size() == 2) {
clock = util::strtoint(cmd[1], -1);
} else {
std::cerr << "t command (tick) expects a time value" << std::endl;
stdostream() << "t command (tick) expects a time value" << std::endl;
return;
}
world_->run_scheduled_threads(clock);
@@ -139,7 +138,7 @@ void TextGame::do_tick_command(const StringVec &cmd) {
void TextGame::do_quit_command(const StringVec &cmd) {
if (cmd.size() != 1) {
std::cerr << "q command (quit) takes no arguments" << std::endl;
stdostream() << "q command (quit) takes no arguments" << std::endl;
return;
}
actor_id_ = 0;
@@ -155,7 +154,7 @@ void TextGame::do_command(const StringVec &words) {
else if (words[0] == "t") do_tick_command(words);
else if (util::validinteger(words[0])) do_choose_command(words);
else {
std::cerr << "Unknown command: " << words[0] << std::endl;
stdostream() << "Unknown command: " << words[0] << std::endl;
}
}
@@ -164,7 +163,7 @@ void TextGame::check_redirects() {
for (const auto &p : redir) {
if (p.first == actor_id_) {
actor_id_ = p.second;
std::cerr << "Login actor ID: " << actor_id_ << std::endl;
stdostream() << "Login actor ID: " << actor_id_ << std::endl;
gui_.clear();
}
}
@@ -177,7 +176,7 @@ void TextGame::channel_printbuffer() {
printbuffer_line_ = printbuffer->first_line();
}
while (printbuffer_line_ < printbuffer->first_unchecked()) {
std::cerr << "* " << printbuffer->nth(printbuffer_line_) << std::endl;
stdostream() << "* " << printbuffer->nth(printbuffer_line_) << std::endl;
printbuffer_line_ += 1;
}
if (printbuffer_line_ > printbuffer->first_line()) {
@@ -195,7 +194,7 @@ void TextGame::event_init(int argc, char *argv[])
world_->run_unittests();
actor_id_ = world_->create_login_actor();
printbuffer_line_ = 0;
std::cerr << "Login actor ID: " << actor_id_ << std::endl;
stdostream() << "Login actor ID: " << actor_id_ << std::endl;
get_stdio_channel()->out()->write_bytes(console_.get_prompt());
}
@@ -216,7 +215,7 @@ void TextGame::event_update()
console_.clear();
channel_printbuffer();
} else if (action == LuaConsole::DO_SYNTAX) {
std::cerr << console_.syntax() << std::endl;
stdostream() << console_.syntax() << std::endl;
console_.clear();
}
check_redirects();