From f150b14d30be840bb0f3c80fe95e54477ac49a67 Mon Sep 17 00:00:00 2001 From: jyelon Date: Fri, 13 Jun 2025 21:03:13 -0400 Subject: [PATCH] Improve consistency of naming in 'invoke/access' pipeline. --- Source/Integration/LuaCall.cpp | 4 ++-- Source/Integration/LuprexGameModeBase.cpp | 10 ++++---- Source/Integration/LuprexGameModeBase.h | 6 ++--- luprex/cpp/core/drivenengine.cpp | 28 +++++++++++------------ luprex/cpp/core/drivenengine.hpp | 6 ++--- luprex/cpp/core/enginewrapper.hpp | 16 ++++++------- luprex/cpp/core/invocation.cpp | 22 +++++++++--------- luprex/cpp/core/invocation.hpp | 20 ++++++++-------- luprex/cpp/core/lpxclient.cpp | 8 +++---- luprex/cpp/core/lpxserver.cpp | 8 +++---- luprex/cpp/core/printbuffer.cpp | 2 +- luprex/cpp/core/world-core.cpp | 10 ++++---- luprex/cpp/drv/driver.cpp | 2 +- 13 files changed, 71 insertions(+), 71 deletions(-) diff --git a/Source/Integration/LuaCall.cpp b/Source/Integration/LuaCall.cpp index ca2acac8..2a2d5e79 100644 --- a/Source/Integration/LuaCall.cpp +++ b/Source/Integration/LuaCall.cpp @@ -217,7 +217,7 @@ void UlxLuaCallLibrary::LuaCallInvoke(UObject *context, AActor *place) ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context); FlxStreamBuffer &sb = mode->LuaCallGetBuffer(); if (NotInitialized(sb)) return; - mode->LuaCallEnd(InvocationKind::LUA_INVOKE, place); + mode->LuaCallEnd(AccessKind::INVOKE_LUA_CALL, place); } @@ -226,7 +226,7 @@ bool UlxLuaCallLibrary::LuaCallProbe(UObject *context, AActor *place, UlxLuaValu ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context); FlxStreamBuffer &sb = mode->LuaCallGetBuffer(); if (NotInitialized(sb)) return false; - ReturnArray = mode->LuaCallEnd(InvocationKind::LUA_PROBE, place); + ReturnArray = mode->LuaCallEnd(AccessKind::PROBE_LUA_CALL, place); if ((ReturnArray == nullptr) || (ReturnArray->Length() < 1)) { UE_LOG(LogLuprexIntegration, Error, TEXT("corruption in lua_probe")); diff --git a/Source/Integration/LuprexGameModeBase.cpp b/Source/Integration/LuprexGameModeBase.cpp index e120eb63..f0f45f64 100644 --- a/Source/Integration/LuprexGameModeBase.cpp +++ b/Source/Integration/LuprexGameModeBase.cpp @@ -175,14 +175,14 @@ void ALuprexGameModeBase::UpdatePossessedTangible() { } } -UlxLuaValues *ALuprexGameModeBase::LuaCallEnd(InvocationKind kind, int64 place_id) { +UlxLuaValues *ALuprexGameModeBase::LuaCallEnd(AccessKind kind, int64 place_id) { std::string_view datapk = LuaCallBuffer.view(); FlxLockedWrapper w(LockableWrapper); if (place_id == 0) place_id = w.GetActor(); uint32_t retpklen; const char *retpk; - w->play_call_function(w.Get(), kind, place_id, datapk.size(), datapk.data(), &retpklen, &retpk); - if (kind == InvocationKind::LUA_PROBE) + w->play_access(w.Get(), kind, place_id, datapk.size(), datapk.data(), &retpklen, &retpk); + if (kind == AccessKind::PROBE_LUA_CALL) { UlxLuaValues *Result = NewObject(this); Result->Initialize(std::string_view(retpk, retpklen)); @@ -191,11 +191,11 @@ UlxLuaValues *ALuprexGameModeBase::LuaCallEnd(InvocationKind kind, int64 place_i else return nullptr; } -UlxLuaValues *ALuprexGameModeBase::LuaCallEnd(InvocationKind kind) { +UlxLuaValues *ALuprexGameModeBase::LuaCallEnd(AccessKind kind) { return LuaCallEnd(kind, int64(0)); } -UlxLuaValues *ALuprexGameModeBase::LuaCallEnd(InvocationKind kind, AActor *place) { +UlxLuaValues *ALuprexGameModeBase::LuaCallEnd(AccessKind kind, AActor *place) { if (place == nullptr) { return LuaCallEnd(kind, int64(0)); } else { diff --git a/Source/Integration/LuprexGameModeBase.h b/Source/Integration/LuprexGameModeBase.h index 0b38f951..31638987 100644 --- a/Source/Integration/LuprexGameModeBase.h +++ b/Source/Integration/LuprexGameModeBase.h @@ -108,9 +108,9 @@ public: // FlxStreamBuffer &LuaCallBegin() { LuaCallBuffer.clear(); return LuaCallBuffer; } FlxStreamBuffer &LuaCallGetBuffer() { return LuaCallBuffer; } - UlxLuaValues *LuaCallEnd(InvocationKind kind); - UlxLuaValues *LuaCallEnd(InvocationKind kind, int64 place_id); - UlxLuaValues *LuaCallEnd(InvocationKind kind, AActor *place); + UlxLuaValues *LuaCallEnd(AccessKind kind); + UlxLuaValues *LuaCallEnd(AccessKind kind, int64 place_id); + UlxLuaValues *LuaCallEnd(AccessKind kind, AActor *place); void LuaCallClear() { LuaCallBuffer.clear(); } // Execute a debugging command, typed on the GUI. diff --git a/luprex/cpp/core/drivenengine.cpp b/luprex/cpp/core/drivenengine.cpp index 1c5ab0a2..471b8216 100644 --- a/luprex/cpp/core/drivenengine.cpp +++ b/luprex/cpp/core/drivenengine.cpp @@ -215,7 +215,7 @@ enum DrvAction { PLAY_NOTIFY_CLOSE, PLAY_NOTIFY_ACCEPT, PLAY_UPDATE, - PLAY_CALL_FUNCTION, + PLAY_ACCESS, PLAY_RELEASE, }; @@ -228,7 +228,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_UPDATE: return "PLAY_UPDATE"; - case PLAY_CALL_FUNCTION: return "PLAY_CALL_FUNCTION"; + case PLAY_ACCESS: return "PLAY_ACCESS"; case PLAY_RELEASE: return "PLAY_RELEASE"; default: return "unknown"; } @@ -475,11 +475,11 @@ void DrivenEngine::drv_update(double clock) { event_update(); } -void DrivenEngine::drv_call_function(InvocationKind kind, int64_t place, uint32_t datapklen, const char *datapk, uint32_t *retpklen, const char **retpk) { +void DrivenEngine::drv_access(AccessKind kind, int64_t place, uint32_t datapklen, const char *datapk, uint32_t *retpklen, const char **retpk) { // This next line is a hack, because the DrivenEngine is not supposed to care about 'kind'. - if (kind == InvocationKind::LUA_SOURCE) rescan_lua_source_ = false; + if (kind == AccessKind::INVOKE_LUA_SOURCE) rescan_lua_source_ = false; call_function_retpk_.clear(); - event_call_function(kind, place, std::string_view(datapk, datapklen), &call_function_retpk_); + event_access(kind, place, std::string_view(datapk, datapklen), &call_function_retpk_); if (retpklen != nullptr) { std::string_view view = call_function_retpk_.view(); *retpklen = view.size(); @@ -811,28 +811,28 @@ static void replay_update(EngineWrapper *w) { //////////////////////// -void play_call_function(EngineWrapper *w, InvocationKind kind, int64_t place, uint32_t datapklen, const char *datapk, uint32_t *retpklen, const char **retpk) { +void play_access(EngineWrapper *w, AccessKind kind, int64_t place, uint32_t datapklen, const char *datapk, uint32_t *retpklen, const char **retpk) { assert(w->rlog == nullptr); if (w->wlog != nullptr) { - w->wlog->write_cmd_hash(PLAY_CALL_FUNCTION, eng::memhash()); + w->wlog->write_cmd_hash(PLAY_ACCESS, 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_call_function(kind, place, datapklen, datapk, retpklen, retpk); + w->engine->drv_access(kind, place, datapklen, datapk, retpklen, retpk); } -void replay_call_function(EngineWrapper *w) { - InvocationKind kind = InvocationKind(w->rlog->read_uint8()); +void replay_access(EngineWrapper *w) { + AccessKind kind = AccessKind(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_call_function_lua_call"); + return reset_wrapper(w, "replay log corrupt in replay_access"); } - w->engine->drv_call_function(kind, place, srcpack.size(), srcpack.c_str(), nullptr, nullptr); + w->engine->drv_access(kind, place, srcpack.size(), srcpack.c_str(), nullptr, nullptr); } @@ -903,7 +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_UPDATE: replay_update(w); return; - case PLAY_CALL_FUNCTION: replay_call_function(w); return; + case PLAY_ACCESS: replay_access(w); return; case PLAY_RELEASE: release(w); return; default: return reset_wrapper(w, "Replay log corrupt in command dispatcher"); } @@ -958,7 +958,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_update = play_update; - w->play_call_function = play_call_function; + w->play_access = play_access; w->replay_initialize = replaycore_initialize; w->replay_step = replaycore_step; diff --git a/luprex/cpp/core/drivenengine.hpp b/luprex/cpp/core/drivenengine.hpp index ba94bc38..389534f0 100644 --- a/luprex/cpp/core/drivenengine.hpp +++ b/luprex/cpp/core/drivenengine.hpp @@ -147,13 +147,13 @@ public: // virtual void event_init(std::string_view srcpk, int argc, char *argv[]) = 0; - // The call-function callback. This is invoked whenever drv_call_function + // The call-function callback. This is invoked whenever drv_access // is called. This is the main entry point for "general" access into the // DrivenEngine. The datapk parameter can contain any arbitrary data needed // by the call. If the call wants to return anything, it can write the // return data into the retpk datapack. // - virtual void event_call_function(InvocationKind kind, int64_t place, std::string_view datapk, StreamBuffer *retpk) {}; + virtual void event_access(AccessKind kind, int64_t place, std::string_view datapk, StreamBuffer *retpk) {}; // The update callback. You may override this in a subclass. // This will be called whenever anything changes. @@ -296,7 +296,7 @@ public: void drv_notify_close(uint32_t chid, uint32_t len, const char *data); uint32_t drv_notify_accept(uint32_t port); void drv_update(double clock); - void drv_call_function(InvocationKind kind, int64_t place, uint32_t datapklen, const char *datapk, uint32_t *retpklen, const char **retpk); + void drv_access(AccessKind kind, int64_t place, uint32_t datapklen, const char *datapk, uint32_t *retpklen, const char **retpk); private: // Find a currently-unused channel ID. Channel IDs diff --git a/luprex/cpp/core/enginewrapper.hpp b/luprex/cpp/core/enginewrapper.hpp index 477b9233..4bcde2ff 100644 --- a/luprex/cpp/core/enginewrapper.hpp +++ b/luprex/cpp/core/enginewrapper.hpp @@ -20,14 +20,14 @@ #define DRV_ERRMSG_SIZE 8192 #define DRV_SHORTSTRING_SIZE 65536 -enum class InvocationKind { +enum class AccessKind { INVALID, - LUA_INVOKE, - LUA_PROBE, - LUA_EXPR, - LUA_SOURCE, - FLUSH_PRINTS, - TICK, + INVOKE_LUA_CALL, + INVOKE_LUA_EXPR, + INVOKE_FLUSH_PRINTS, + INVOKE_TICK, + INVOKE_LUA_SOURCE, + PROBE_LUA_CALL, }; class DrivenEngine; @@ -212,7 +212,7 @@ struct EngineWrapper { // This is the main pathway for blueprints, or the unreal C++ code, // to change the state of the world. // - void (*play_call_function)(EngineWrapper *w, InvocationKind kind, int64_t place, uint32_t datapklen, const char *datapk, uint32_t *retpklen, const char **retpk); + void (*play_access)(EngineWrapper *w, AccessKind kind, int64_t place, uint32_t datapklen, const char *datapk, uint32_t *retpklen, const char **retpk); ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// diff --git a/luprex/cpp/core/invocation.cpp b/luprex/cpp/core/invocation.cpp index 0d63497f..8a721fb9 100644 --- a/luprex/cpp/core/invocation.cpp +++ b/luprex/cpp/core/invocation.cpp @@ -6,11 +6,11 @@ #include "invocation.hpp" -Invocation::Invocation() : kind_(InvocationKind::INVALID), actor_(0), place_(0) {} +Invocation::Invocation() : kind_(AccessKind::INVALID), actor_(0), place_(0) {} -Invocation::Invocation(InvocationKind kind, int64_t actor, int64_t place, std::string_view datapack) +Invocation::Invocation(AccessKind kind, int64_t actor, int64_t place, std::string_view datapack) : kind_(kind), actor_(actor), place_(place), datapack_(datapack) {} - + void Invocation::serialize(StreamBuffer *sb) const { sb->write_uint8(int64_t(kind_)); @@ -20,7 +20,7 @@ void Invocation::serialize(StreamBuffer *sb) const { } void Invocation::deserialize(StreamBuffer *sb) { - kind_ = InvocationKind(sb->read_uint8()); + kind_ = AccessKind(sb->read_uint8()); actor_ = sb->read_int64(); place_ = sb->read_int64(); datapack_ = sb->read_string(); @@ -30,13 +30,13 @@ eng::string Invocation::debug_string() const { eng::ostringstream oss; oss << "inv["; switch (kind_) { - case InvocationKind::INVALID: oss << "invalid"; break; - case InvocationKind::LUA_INVOKE: oss << "lua_invoke"; break; - case InvocationKind::LUA_PROBE: oss << "lua_probe"; break; - case InvocationKind::LUA_EXPR: oss << "lua_expr"; break; - case InvocationKind::LUA_SOURCE: oss << "lua_source"; break; - case InvocationKind::FLUSH_PRINTS: oss << "flush_prints"; break; - case InvocationKind::TICK: oss << "tick"; break; + case AccessKind::INVALID: oss << "invalid"; break; + case AccessKind::INVOKE_LUA_CALL: oss << "lua_invoke"; break; + case AccessKind::INVOKE_LUA_EXPR: oss << "lua_expr"; break; + case AccessKind::INVOKE_FLUSH_PRINTS: oss << "flush_prints"; break; + case AccessKind::INVOKE_TICK: oss << "tick"; break; + case AccessKind::INVOKE_LUA_SOURCE: oss << "lua_source"; break; + case AccessKind::PROBE_LUA_CALL: oss << "lua_probe"; break; default: oss << "UNKNOWN"; break; } oss << " a=" << actor_; diff --git a/luprex/cpp/core/invocation.hpp b/luprex/cpp/core/invocation.hpp index 3ade9986..68dadd73 100644 --- a/luprex/cpp/core/invocation.hpp +++ b/luprex/cpp/core/invocation.hpp @@ -8,28 +8,28 @@ // // The actual contents of the datapack depends on the type of invocation: // -// InvocationKind::INVALID: +// AccessKind::INVALID: // // Nothing. // -// InvocationKind::LUA_CALL: +// AccessKind::LUA_CALL: // // A lua function call. The class name, the function name, and then // the function arguments. // -// InvocationKind::LUA_EXPR: +// AccessKind::INVOKE_LUA_EXPR: // // A block of lua source code, in plaintext. // -// InvocationKind::FLUSH_PRINTS: +// AccessKind::INVOKE_FLUSH_PRINTS: // // Line number in ascii. // -// InvocationKind::TICK: +// AccessKind::INVOKE_TICK: // // Nothing. // -// InvocationKind::LUA_SOURCE: +// AccessKind::INVOKE_LUA_SOURCE: // // Packaged lua sourcecode. See drvutil::package_lua_source. // @@ -48,16 +48,16 @@ class Invocation : public eng::opnew { public: private: - InvocationKind kind_; + AccessKind kind_; int64_t actor_; int64_t place_; eng::string datapack_; public: Invocation(); - Invocation(InvocationKind kind, int64_t actor, int64_t place, std::string_view datapack); + Invocation(AccessKind kind, int64_t actor, int64_t place, std::string_view datapack); - bool valid() const { return kind_ != InvocationKind::INVALID; } - InvocationKind kind() const { return kind_; } + bool valid() const { return kind_ != AccessKind::INVALID; } + AccessKind kind() const { return kind_; } int64_t actor() const { return actor_; } int64_t place() const { return place_; } const eng::string &datapack() const { return datapack_; } diff --git a/luprex/cpp/core/lpxclient.cpp b/luprex/cpp/core/lpxclient.cpp index d0cb1cdd..16b095f6 100644 --- a/luprex/cpp/core/lpxclient.cpp +++ b/luprex/cpp/core/lpxclient.cpp @@ -117,7 +117,7 @@ public: void send_invocation(const Invocation &inv) { if (channel_ == nullptr) { - if ((!world_->is_authoritative()) && (inv.kind() == InvocationKind::LUA_SOURCE)) { + 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 @@ -179,7 +179,7 @@ public: } virtual void do_luainvoke_command(std::string_view cmd) override { - send_invocation(Invocation(InvocationKind::LUA_EXPR, actor_id_, actor_id_, cmd)); + send_invocation(Invocation(AccessKind::INVOKE_LUA_EXPR, actor_id_, actor_id_, cmd)); } virtual void do_luaprobe_command(std::string_view cmd) override { @@ -246,9 +246,9 @@ public: return true; } - virtual void event_call_function(InvocationKind kind, int64_t place_id, std::string_view datapk, StreamBuffer *retpk) override { + virtual void event_access(AccessKind kind, int64_t place_id, std::string_view datapk, StreamBuffer *retpk) override { switch (kind) { - case InvocationKind::LUA_PROBE: { + case AccessKind::PROBE_LUA_CALL: { world_to_asynchronous(); world_->probe_lua_call(actor_id_, place_id, datapk, retpk); break; diff --git a/luprex/cpp/core/lpxserver.cpp b/luprex/cpp/core/lpxserver.cpp index 785990af..1a7252ed 100644 --- a/luprex/cpp/core/lpxserver.cpp +++ b/luprex/cpp/core/lpxserver.cpp @@ -135,7 +135,7 @@ public: } virtual void do_luainvoke_command(std::string_view cmd) override { - master_->invoke(Invocation(InvocationKind::LUA_EXPR, admin_id_, admin_id_, cmd)); + master_->invoke(Invocation(AccessKind::INVOKE_LUA_EXPR, admin_id_, admin_id_, cmd)); } virtual void do_luaprobe_command(std::string_view cmd) override { @@ -193,9 +193,9 @@ public: return true; } - virtual void event_call_function(InvocationKind kind, int64_t place_id, std::string_view datapk, StreamBuffer *retpk) override { + virtual void event_access(AccessKind kind, int64_t place_id, std::string_view datapk, StreamBuffer *retpk) override { switch (kind) { - case InvocationKind::LUA_PROBE: { + case AccessKind::PROBE_LUA_CALL: { master_->snapshot(); master_->probe_lua_call(admin_id_, place_id, datapk, retpk); master_->rollback(); @@ -258,7 +258,7 @@ public: // If the clock has advanced far enough, tick the master model. if (clock >= next_tick_) { - master_->invoke(Invocation(InvocationKind::TICK, 0, 0, "")); + master_->invoke(Invocation(AccessKind::INVOKE_TICK, 0, 0, "")); for (UniqueClient &client : clients_) { client->async_diff_ = true; } diff --git a/luprex/cpp/core/printbuffer.cpp b/luprex/cpp/core/printbuffer.cpp index 90f05b25..4266a625 100644 --- a/luprex/cpp/core/printbuffer.cpp +++ b/luprex/cpp/core/printbuffer.cpp @@ -195,7 +195,7 @@ bool PrintChanneler::channel(const PrintBuffer *printbuffer, std::ostream &ostre Invocation PrintChanneler::invocation(int64_t actor_id) { char buf[80]; sprintf(buf, "%" PRId64, line_); - return Invocation(InvocationKind::FLUSH_PRINTS, actor_id, actor_id, buf); + return Invocation(AccessKind::INVOKE_FLUSH_PRINTS, actor_id, actor_id, buf); } LuaDefine(unittests_printbuffer, "", "some unit tests") { diff --git a/luprex/cpp/core/world-core.cpp b/luprex/cpp/core/world-core.cpp index f96a1a02..c7fb7d7b 100644 --- a/luprex/cpp/core/world-core.cpp +++ b/luprex/cpp/core/world-core.cpp @@ -742,19 +742,19 @@ void World::run_unittests() { void World::invoke(const Invocation &inv) { switch (inv.kind()) { - case InvocationKind::LUA_INVOKE: + case AccessKind::INVOKE_LUA_CALL: invoke_lua_call(inv.actor(), inv.place(), inv.datapack()); break; - case InvocationKind::LUA_EXPR: + case AccessKind::INVOKE_LUA_EXPR: invoke_lua_expr(inv.actor(), inv.place(), inv.datapack()); break; - case InvocationKind::FLUSH_PRINTS: + case AccessKind::INVOKE_FLUSH_PRINTS: invoke_flush_prints(inv.actor(), inv.place(), inv.datapack()); break; - case InvocationKind::TICK: + case AccessKind::INVOKE_TICK: invoke_tick(inv.actor(), inv.place(), inv.datapack()); break; - case InvocationKind::LUA_SOURCE: + case AccessKind::INVOKE_LUA_SOURCE: invoke_lua_source(inv.actor(), inv.place(), inv.datapack()); break; default: diff --git a/luprex/cpp/drv/driver.cpp b/luprex/cpp/drv/driver.cpp index f614d940..b846f6a9 100644 --- a/luprex/cpp/drv/driver.cpp +++ b/luprex/cpp/drv/driver.cpp @@ -193,7 +193,7 @@ class Driver { std::string err = drvutil::package_lua_source(".", &oss); if_error_print_and_exit(err); std::string_view ossv = oss.view(); - engw.play_call_function(&engw, InvocationKind::LUA_SOURCE, 0, ossv.size(), ossv.data(), nullptr, nullptr); + engw.play_access(&engw, AccessKind::INVOKE_LUA_SOURCE, 0, ossv.size(), ossv.data(), nullptr, nullptr); } }