Generalize DrivenEngine::drv_invoke

This commit is contained in:
2024-09-02 21:48:24 -04:00
parent 47a570064c
commit bf3e963949
11 changed files with 67 additions and 101 deletions

View File

@@ -221,8 +221,7 @@ enum DrvAction {
PLAY_NOTIFY_CLOSE,
PLAY_NOTIFY_ACCEPT,
PLAY_CALL_EVENT_UPDATE,
PLAY_INVOKE_LUA_CALL,
PLAY_INVOKE_LUA_SOURCE,
PLAY_INVOKE,
PLAY_RELEASE,
};
@@ -235,8 +234,7 @@ inline static const char *action_string(DrvAction act) {
case PLAY_NOTIFY_CLOSE: return "PLAY_NOTIFY_CLOSE";
case PLAY_NOTIFY_ACCEPT: return "PLAY_NOTIFY_ACCEPT";
case PLAY_CALL_EVENT_UPDATE: return "PLAY_CALL_EVENT_UPDATE";
case PLAY_INVOKE_LUA_CALL: return "PLAY_INVOKE_LUA_CALL";
case PLAY_INVOKE_LUA_SOURCE: return "PLAY_INVOKE_LUA_SOURCE";
case PLAY_INVOKE: return "PLAY_INVOKE_LUA_CALL";
case PLAY_RELEASE: return "PLAY_RELEASE";
default: return "unknown";
}
@@ -483,15 +481,10 @@ void DrivenEngine::drv_call_event_update(double clock) {
event_update();
}
void DrivenEngine::drv_invoke_lua_call(int64_t place, uint32_t datapklen, const char *datapk) {
Invocation *inv = new Invocation(Invocation::KIND_LUA_CALL, visible_actor_id_, place, std::string_view(datapk, datapklen));
void DrivenEngine::drv_invoke(InvocationKind kind, int64_t place, uint32_t datapklen, const char *datapk) {
Invocation *inv = new Invocation(kind, visible_actor_id_, place, std::string_view(datapk, datapklen));
queued_invocations_.emplace_back(inv);
}
void DrivenEngine::drv_invoke_lua_source(uint32_t srcpklen, const char *srcpk) {
Invocation *inv = new Invocation(Invocation::KIND_LUA_SOURCE, visible_actor_id_, visible_actor_id_, std::string_view(srcpk, srcpklen));
queued_invocations_.emplace_back(inv);
rescan_lua_source_ = false;
if (kind == InvocationKind::LUA_SOURCE) rescan_lua_source_ = false;
}
//////////////////////////////////////////////////////////////////////////////
@@ -818,49 +811,28 @@ static void replay_invoke_event_update(EngineWrapper *w) {
////////////////////////
void play_invoke_lua_call(EngineWrapper *w, int64_t place, uint32_t datapklen, const char *datapk) {
void play_invoke(EngineWrapper *w, InvocationKind kind, int64_t place, uint32_t datapklen, const char *datapk) {
assert(w->rlog == nullptr);
if (w->wlog != nullptr) {
w->wlog->write_cmd_hash(PLAY_INVOKE_LUA_CALL, eng::memhash());
w->wlog->write_cmd_hash(PLAY_INVOKE, eng::memhash());
w->wlog->write_uint8(int64_t(kind));
w->wlog->write_int64(place);
w->wlog->write_string(std::string_view(datapk, datapklen));
w->wlog->flush();
}
w->engine->drv_invoke_lua_call(place, datapklen, datapk);
w->engine->drv_invoke(kind, place, datapklen, datapk);
}
void replay_invoke_lua_call(EngineWrapper *w) {
void replay_invoke(EngineWrapper *w) {
InvocationKind kind = InvocationKind(w->rlog->read_uint8());
int64_t place = w->rlog->read_int64();
std::string srcpack = w->rlog->read_string();
if (!w->rlog->good()) {
return reset_wrapper(w, "replay log corrupt in replay_invoke_lua_call");
}
w->engine->drv_invoke_lua_call(place, srcpack.size(), srcpack.c_str());
}
////////////////////////
void play_invoke_lua_source(EngineWrapper *w, uint32_t srcpklen, const char *srcpk) {
assert(w->rlog == nullptr);
if (w->wlog != nullptr) {
w->wlog->write_cmd_hash(PLAY_INVOKE_LUA_SOURCE, eng::memhash());
w->wlog->write_string(std::string_view(srcpk, srcpklen));
w->wlog->flush();
}
w->engine->drv_invoke_lua_source(srcpklen, srcpk);
}
void replay_invoke_lua_source(EngineWrapper *w) {
std::string srcpack = w->rlog->read_string();
if (!w->rlog->good()) {
return reset_wrapper(w, "replay log corrupt in replay_invoke_lua_source");
}
w->engine->drv_invoke_lua_source(srcpack.size(), srcpack.c_str());
w->engine->drv_invoke(kind, place, srcpack.size(), srcpack.c_str());
}
@@ -931,8 +903,7 @@ static void replaycore_step(EngineWrapper *w) {
case PLAY_NOTIFY_CLOSE: replay_notify_close(w); return;
case PLAY_NOTIFY_ACCEPT: replay_notify_accept(w); return;
case PLAY_CALL_EVENT_UPDATE: replay_invoke_event_update(w); return;
case PLAY_INVOKE_LUA_CALL: replay_invoke_lua_call(w); return;
case PLAY_INVOKE_LUA_SOURCE: replay_invoke_lua_source(w); return;
case PLAY_INVOKE: replay_invoke(w); return;
case PLAY_RELEASE: release(w); return;
default: return reset_wrapper(w, "Replay log corrupt in command dispatcher");
}
@@ -993,8 +964,7 @@ static void init_engine_wrapper_helper(EngineWrapper *w) {
w->play_notify_close = play_notify_close;
w->play_notify_accept = play_notify_accept;
w->play_invoke_event_update = play_invoke_event_update;
w->play_invoke_lua_call = play_invoke_lua_call;
w->play_invoke_lua_source = play_invoke_lua_source;
w->play_invoke = play_invoke;
w->replay_initialize = replaycore_initialize;
w->replay_step = replaycore_step;