Some output now going through PrintBuffer
This commit is contained in:
@@ -14,8 +14,9 @@
|
||||
#include "traceback.hpp"
|
||||
#include "textgame.hpp"
|
||||
#include "luaconsole.hpp"
|
||||
#include "print.hpp"
|
||||
#include "pprint.hpp"
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
class TextGame : public DrivenEngine {
|
||||
@@ -26,6 +27,7 @@ private:
|
||||
Gui gui_;
|
||||
int64_t gui_place_;
|
||||
int64_t actor_id_;
|
||||
int64_t printbuffer_line_;
|
||||
|
||||
void do_view_command(const StringVec &cmd);
|
||||
void do_menu_command(const StringVec &cmd);
|
||||
@@ -39,6 +41,7 @@ private:
|
||||
void do_command(const StringVec &exp);
|
||||
|
||||
void check_redirects();
|
||||
void channel_printbuffer();
|
||||
|
||||
public:
|
||||
virtual void event_init(int argc, char *argv[]);
|
||||
@@ -167,12 +170,26 @@ void TextGame::check_redirects() {
|
||||
}
|
||||
}
|
||||
|
||||
void TextGame::channel_printbuffer() {
|
||||
const PrintBuffer *printbuffer = world_->get_printbuffer(actor_id_);
|
||||
if (printbuffer == nullptr) return;
|
||||
if (printbuffer->first_line() > printbuffer_line_) {
|
||||
printbuffer_line_ = printbuffer->first_line();
|
||||
}
|
||||
while (printbuffer_line_ < printbuffer->first_unchecked()) {
|
||||
std::cerr << "* " << printbuffer->nth(printbuffer_line_) << std::endl;
|
||||
printbuffer_line_ += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TextGame::event_init(int argc, char *argv[])
|
||||
{
|
||||
world_.reset(new World(util::WORLD_TYPE_STANDALONE));
|
||||
world_->update_source(get_lua_source());
|
||||
world_->run_unittests();
|
||||
actor_id_ = world_->create_login_actor();
|
||||
printbuffer_line_ = 0;
|
||||
std::cerr << "Login actor ID: " << actor_id_ << std::endl;
|
||||
get_stdio_channel()->out()->write_bytes(console_.get_prompt());
|
||||
}
|
||||
@@ -188,9 +205,11 @@ void TextGame::event_update()
|
||||
if (action == LuaConsole::DO_LUA) {
|
||||
do_lua(console_.lua_expression());
|
||||
console_.clear();
|
||||
channel_printbuffer();
|
||||
} else if (action == LuaConsole::DO_COMMAND) {
|
||||
do_command(console_.words());
|
||||
console_.clear();
|
||||
channel_printbuffer();
|
||||
} else if (action == LuaConsole::DO_SYNTAX) {
|
||||
std::cerr << console_.syntax() << std::endl;
|
||||
console_.clear();
|
||||
|
||||
Reference in New Issue
Block a user