From d4f46eef45a05d0c364cba16ed3c11f550ae6e77 Mon Sep 17 00:00:00 2001 From: jyelon Date: Thu, 29 Aug 2024 17:45:05 -0400 Subject: [PATCH] Get rid of invoke_engio --- luprex/cpp/core/drivenengine.cpp | 35 ----------------------- luprex/cpp/core/drivenengine.hpp | 1 - luprex/cpp/core/enginewrapper.hpp | 11 ++------ luprex/cpp/core/invocation.cpp | 1 - luprex/cpp/core/invocation.hpp | 11 +++----- luprex/cpp/core/world-core.cpp | 47 ------------------------------- luprex/cpp/core/world.hpp | 4 --- 7 files changed, 7 insertions(+), 103 deletions(-) diff --git a/luprex/cpp/core/drivenengine.cpp b/luprex/cpp/core/drivenengine.cpp index 2c75a317..6198d431 100644 --- a/luprex/cpp/core/drivenengine.cpp +++ b/luprex/cpp/core/drivenengine.cpp @@ -221,7 +221,6 @@ enum DrvAction { PLAY_NOTIFY_CLOSE, PLAY_NOTIFY_ACCEPT, PLAY_CALL_EVENT_UPDATE, - PLAY_INVOKE_ENGIO, PLAY_INVOKE_LUA_CALL, PLAY_INVOKE_LUA_SOURCE, PLAY_RELEASE, @@ -236,7 +235,6 @@ 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_ENGIO: return "PLAY_INVOKE_ENGIO"; case PLAY_INVOKE_LUA_CALL: return "PLAY_INVOKE_LUA_CALL"; case PLAY_INVOKE_LUA_SOURCE: return "PLAY_INVOKE_LUA_SOURCE"; case PLAY_RELEASE: return "PLAY_RELEASE"; @@ -485,11 +483,6 @@ void DrivenEngine::drv_call_event_update(double clock) { event_update(); } -void DrivenEngine::drv_invoke_engio(int64_t place, uint32_t datapklen, const char *datapk) { - Invocation *inv = new Invocation(Invocation::KIND_ENGIO, visible_actor_id_, place, std::string_view(datapk, datapklen)); - queued_invocations_.emplace_back(inv); -} - 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)); queued_invocations_.emplace_back(inv); @@ -825,32 +818,6 @@ static void replay_invoke_event_update(EngineWrapper *w) { //////////////////////// -void play_invoke_engio(EngineWrapper *w, int64_t place, uint32_t datapklen, const char *datapk) { - assert(w->rlog == nullptr); - if (w->wlog != nullptr) { - w->wlog->write_cmd_hash(PLAY_INVOKE_ENGIO, eng::memhash()); - w->wlog->write_int64(place); - w->wlog->write_string(std::string_view(datapk, datapklen)); - w->wlog->flush(); - } - - w->engine->drv_invoke_engio(place, datapklen, datapk); -} - -void replay_invoke_engio(EngineWrapper *w) { - 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_engio"); - } - - w->engine->drv_invoke_engio(place, srcpack.size(), srcpack.c_str()); -} - - -//////////////////////// - - void play_invoke_lua_call(EngineWrapper *w, int64_t place, uint32_t datapklen, const char *datapk) { assert(w->rlog == nullptr); if (w->wlog != nullptr) { @@ -964,7 +931,6 @@ 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_ENGIO: replay_invoke_engio(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_RELEASE: release(w); return; @@ -1027,7 +993,6 @@ 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_engio = play_invoke_engio; w->play_invoke_lua_call = play_invoke_lua_call; w->play_invoke_lua_source = play_invoke_lua_source; diff --git a/luprex/cpp/core/drivenengine.hpp b/luprex/cpp/core/drivenengine.hpp index da21bfe6..4521153f 100644 --- a/luprex/cpp/core/drivenengine.hpp +++ b/luprex/cpp/core/drivenengine.hpp @@ -293,7 +293,6 @@ public: void drv_notify_close(uint32_t chid, uint32_t len, const char *data); uint32_t drv_notify_accept(uint32_t port); void drv_call_event_update(double clock); - void drv_invoke_engio(int64_t place, uint32_t datapklen, const char *datapk); void drv_invoke_lua_call(int64_t place, uint32_t datapklen, const char *datapk); void drv_invoke_lua_source(uint32_t srcpklen, const char *srcpk); diff --git a/luprex/cpp/core/enginewrapper.hpp b/luprex/cpp/core/enginewrapper.hpp index 78bc26dd..e461d27c 100644 --- a/luprex/cpp/core/enginewrapper.hpp +++ b/luprex/cpp/core/enginewrapper.hpp @@ -197,16 +197,11 @@ struct EngineWrapper { // void (*play_invoke_event_update)(EngineWrapper *w, double clock); - // Send an invoke/KIND_ENGIO - // - // This is the main pathway for the graphics engine to control the player - // character. - // - void (*play_invoke_engio)(EngineWrapper *w, int64_t place, uint32_t datapklen, const char *datapk); - // Send an invoke/KIND_LUA_CALL // - // This is the main pathway for blueprints to reach into lua. + // This is the main pathway for blueprints, or the unreal C++ code, + // to reach into lua. The datapack mus contain a classname, a function + // name, and then arguments for the function. // void (*play_invoke_lua_call)(EngineWrapper *w, int64_t place, uint32_t datapklen, const char *datapk); diff --git a/luprex/cpp/core/invocation.cpp b/luprex/cpp/core/invocation.cpp index 4a480372..4e2d1839 100644 --- a/luprex/cpp/core/invocation.cpp +++ b/luprex/cpp/core/invocation.cpp @@ -31,7 +31,6 @@ eng::string Invocation::debug_string() const { oss << "inv["; switch (kind_) { case KIND_INVALID: oss << "invalid"; break; - case KIND_ENGIO: oss << "engio"; break; case KIND_LUA_CALL: oss << "lua_call"; break; case KIND_LUA: oss << "lua"; break; case KIND_FLUSH_PRINTS: oss << "flush_prints"; break; diff --git a/luprex/cpp/core/invocation.hpp b/luprex/cpp/core/invocation.hpp index d7a3d1e9..5af94798 100644 --- a/luprex/cpp/core/invocation.hpp +++ b/luprex/cpp/core/invocation.hpp @@ -12,13 +12,11 @@ // // Nothing. // -// KIND_ENGIO: +// KIND_LUA_CALL: +// +// A lua function call. The class name, the function name, and then +// the function arguments. // -// First, a function name is read from the datapack. The function -// name must be a lua function inside class "engio". The function -// is called with arguments: actor, place, and then additional -// arguments of simple dynamic type read from the datapack. -// // KIND_LUA: // // A block of lua source code, in plaintext. @@ -50,7 +48,6 @@ class Invocation : public eng::opnew { public: enum Kind { KIND_INVALID, - KIND_ENGIO, KIND_LUA_CALL, KIND_LUA, KIND_FLUSH_PRINTS, diff --git a/luprex/cpp/core/world-core.cpp b/luprex/cpp/core/world-core.cpp index 638ecb32..41d1702a 100644 --- a/luprex/cpp/core/world-core.cpp +++ b/luprex/cpp/core/world-core.cpp @@ -551,9 +551,6 @@ void World::run_unittests() { void World::invoke(const Invocation &inv) { switch (inv.kind()) { - case Invocation::KIND_ENGIO: - invoke_engio(inv.actor(), inv.place(), inv.datapack()); - break; case Invocation::KIND_LUA_CALL: invoke_lua_call(inv.actor(), inv.place(), inv.datapack()); break; @@ -742,50 +739,6 @@ void push_simple_dynamic(lua_State *L, StreamBuffer *sb) { } } -void World::invoke_engio(int64_t actor_id, int64_t place_id, std::string_view datapack) { - assert(stack_is_clear()); - - // Use a streambuffer to parse the datapack. - StreamBuffer datasb(datapack); - - // Extract the function name from the datapack. - eng::string funcname; - try { - funcname = datasb.read_string_limit(100); - } catch (const StreamException &ex) { - return; - } - if (!sv::is_lua_id(funcname)) { - return; - } - - { - lua_State *L = state(); - LuaVar engio, func; - LuaExtStack LS(L, engio, func); - - // Get the closure (engio.funcname). - eng::string err = LS.getclass(engio, "engio"); - if ((!err.empty()) || (!LS.istable(engio))) { - return; - } - LS.rawget(func, engio, funcname); - - // Spawn a thread, pushing extra arguments from the datapack. - int nargs = 0; - try { - while (!datasb.empty()) { - push_simple_dynamic(L, &datasb); - nargs++; - } - } catch (const StreamException &exc) { - return; - } - spawn(LS, actor_id, place_id, func, true, nargs, false); - } - run_scheduled_threads(); - assert(stack_is_clear()); -} void World::invoke_lua_call(int64_t actor_id, int64_t place_id, std::string_view datapack) { assert(stack_is_clear()); diff --git a/luprex/cpp/core/world.hpp b/luprex/cpp/core/world.hpp index 30bc4d92..960007dc 100644 --- a/luprex/cpp/core/world.hpp +++ b/luprex/cpp/core/world.hpp @@ -390,10 +390,6 @@ private: // static void store_global_pointer(lua_State *L, World *w); - // Invoke a player method, used by the graphics engine to control the player. - // - void invoke_engio(int64_t actor_id, int64_t place_id, std::string_view datapack); - // Invoke the lua_call operation. // void invoke_lua_call(int64_t actor_id, int64_t place_id, std::string_view datapack);