Event driven engine, further work.

This commit is contained in:
2021-10-05 12:54:37 -04:00
parent bc22dc89af
commit bce756d1fd
11 changed files with 61 additions and 115 deletions

View File

@@ -170,24 +170,17 @@ void TextGame::check_redirects() {
}
}
void TextGame::init()
void TextGame::event_update()
{
world_.reset(new World(util::WORLD_TYPE_STANDALONE));
std::unique_ptr<util::LuaSource> lsource = get_lua_source();
world_->update_source(*lsource);
world_->run_unittests();
actor_id_ = world_->create_login_actor();
std::cerr << "Login actor ID: " << actor_id_ << std::endl;
console_.clear();
}
void TextGame::update() {
check_redirects();
if (actor_id_ == 0) {
stop_driver();
return;
if (world_ == nullptr) {
world_.reset(new World(util::WORLD_TYPE_STANDALONE));
world_->update_source(get_lua_source());
world_->run_unittests();
actor_id_ = world_->create_login_actor();
std::cerr << "Login actor ID: " << actor_id_ << std::endl;
}
// Process lines from stdin.
world_->update_source(get_lua_source());
while (true) {
std::string line = get_stdio_channel()->in()->readline();
if (line == "") break;
@@ -200,9 +193,11 @@ void TextGame::update() {
} else if (action == LuaConsole::DO_SYNTAX) {
std::cerr << console_.syntax() << std::endl;
}
check_redirects();
if (actor_id_ == 0) {
stop_driver();
return;
}
}
// Process lua source if available.
std::unique_ptr<util::LuaSource> source = get_lua_source();
if (source != nullptr) world_->update_source(*source);
}