Refactor code for invoke_lua_source and world.init. Also, add compile_commands.json to luprex
This commit is contained in:
@@ -22,6 +22,12 @@ public:
|
||||
eng::vector<Invocation> delayed_invocations_;
|
||||
|
||||
public:
|
||||
LpxClient() {
|
||||
set_console_prompt(console_.get_prompt());
|
||||
|
||||
set_initial_state_standalone();
|
||||
}
|
||||
|
||||
void set_initial_state_connect(const eng::string &hostspec) {
|
||||
// Create the world model.
|
||||
world_.reset(new World(WORLD_TYPE_PREDICTIVE));
|
||||
@@ -46,21 +52,16 @@ public:
|
||||
print_channeler_.reset();
|
||||
}
|
||||
|
||||
void set_initial_state_standalone(std::string_view srcpk) {
|
||||
void set_initial_state_standalone() {
|
||||
// Create the world model.
|
||||
world_.reset(new World(WORLD_TYPE_MASTER));
|
||||
|
||||
// Update the source code of the master model.
|
||||
world_->update_source(srcpk);
|
||||
|
||||
// Make sure the channel is empty.
|
||||
channel_.reset();
|
||||
|
||||
// Create the standalone actor.
|
||||
actor_id_ = world_->create_login_actor();
|
||||
|
||||
// TODO: initialize the standalone actor.
|
||||
|
||||
// Clear the unack command queue.
|
||||
unack_.clear();
|
||||
|
||||
@@ -69,8 +70,10 @@ public:
|
||||
|
||||
// Reset the print channeler
|
||||
print_channeler_.reset();
|
||||
}
|
||||
|
||||
// Trigger lua source loading.
|
||||
rescan_lua_source();
|
||||
}
|
||||
|
||||
// When the world is in synchronous mode, there's no
|
||||
// snapshot, and the commands in the unack queue are not
|
||||
@@ -96,37 +99,15 @@ public:
|
||||
}
|
||||
|
||||
void abandon_server() {
|
||||
// When we abandon the server, we leave the world model
|
||||
// hanging around to preserve the invariant that there
|
||||
// is always a world model. Then, we trigger a rescan
|
||||
// of the lua source. When the lua source shows up, then
|
||||
// we will create a standalone model to replace the client
|
||||
// model.
|
||||
|
||||
channel_.reset();
|
||||
rescan_lua_source();
|
||||
}
|
||||
|
||||
virtual void event_init(std::string_view srcpk, int argc, char *argv[]) {
|
||||
// Put the world into the starting state.
|
||||
set_initial_state_standalone(srcpk);
|
||||
|
||||
// Set the console prompt
|
||||
set_console_prompt(console_.get_prompt());
|
||||
if (channel_)
|
||||
{
|
||||
set_initial_state_standalone();
|
||||
}
|
||||
}
|
||||
|
||||
void send_invocation(const Invocation &inv) {
|
||||
if (channel_ == nullptr) {
|
||||
if ((!world_->is_authoritative()) && (inv.kind() == AccessKind::INVOKE_LUA_SOURCE)) {
|
||||
// We have a client model, but no client connection. That means we're
|
||||
// in the process of shutting down a client model. The client model
|
||||
// is supposed to linger until the lua source is reread. Once we have
|
||||
// the lua source, we're supposed to throw out the client model and
|
||||
// create a standalone model.
|
||||
set_initial_state_standalone(inv.datapack());
|
||||
} else {
|
||||
world_->invoke(inv);
|
||||
}
|
||||
world_->invoke(inv);
|
||||
} else {
|
||||
world_to_asynchronous();
|
||||
world_->invoke(inv);
|
||||
@@ -247,14 +228,27 @@ public:
|
||||
}
|
||||
|
||||
virtual void event_access(AccessKind kind, int64_t place_id, std::string_view datapk, StreamBuffer *retpk) override {
|
||||
if (place_id == 0) place_id = actor_id_;
|
||||
switch (kind) {
|
||||
case AccessKind::INVOKE_LUA_CALL:
|
||||
case AccessKind::INVOKE_LUA_EXPR:
|
||||
case AccessKind::INVOKE_FLUSH_PRINTS:
|
||||
case AccessKind::INVOKE_TICK:
|
||||
case AccessKind::INVOKE_LUA_SOURCE: {
|
||||
delayed_invocations_.emplace_back(kind, actor_id_, place_id, datapk);
|
||||
break;
|
||||
}
|
||||
case AccessKind::PROBE_LUA_CALL: {
|
||||
world_to_asynchronous();
|
||||
world_->probe_lua_call(actor_id_, place_id, datapk, retpk);
|
||||
break;
|
||||
}
|
||||
case AccessKind::CONNECT_TO_SERVER: {
|
||||
set_initial_state_connect(util::ss("nocert:", datapk, ":8085"));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
delayed_invocations_.emplace_back(kind, actor_id_, place_id, datapk);
|
||||
stdostream() << "Invalid event_access: " << int(kind) << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user