From a6e68cbb3589cfa64cf64eca3e214059fa252333 Mon Sep 17 00:00:00 2001 From: jyelon Date: Tue, 3 Sep 2024 22:44:22 -0400 Subject: [PATCH] Move queued invocations down into lpxserver/lpxclient --- luprex/cpp/core/drivenengine.cpp | 9 ++------- luprex/cpp/core/drivenengine.hpp | 20 ++++++++++---------- luprex/cpp/core/lpxclient.cpp | 9 +++++++-- luprex/cpp/core/lpxserver.cpp | 8 ++++++-- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/luprex/cpp/core/drivenengine.cpp b/luprex/cpp/core/drivenengine.cpp index a16b074d..8de79468 100644 --- a/luprex/cpp/core/drivenengine.cpp +++ b/luprex/cpp/core/drivenengine.cpp @@ -165,12 +165,6 @@ void DrivenEngine::set_console_prompt(const eng::string &prompt) { console_prompt_ = prompt; } -eng::vector DrivenEngine::get_queued_invocations() { - eng::vector result = std::move(queued_invocations_); - queued_invocations_.clear(); - return result; -} - void DrivenEngine::rescan_lua_source() { rescan_lua_source_ = true; } @@ -483,8 +477,9 @@ void DrivenEngine::drv_update(double clock) { void DrivenEngine::drv_call_function(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); + // 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; + event_call_function(kind, place, std::string_view(datapklen, datapk)); } ////////////////////////////////////////////////////////////////////////////// diff --git a/luprex/cpp/core/drivenengine.hpp b/luprex/cpp/core/drivenengine.hpp index 4106e45e..50f773b1 100644 --- a/luprex/cpp/core/drivenengine.hpp +++ b/luprex/cpp/core/drivenengine.hpp @@ -147,6 +147,12 @@ 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 + // is called. This is the main entry point for "general" access into the + // DrivenEngine. + // + virtual void event_call_function(InvocationKind kind, int64_t place, std::string_view datapk) {}; + // The update callback. You may override this in a subclass. // This will be called whenever anything changes. // @@ -210,16 +216,11 @@ public: // Set the prompt for the console. // void set_console_prompt(const eng::string &prompt); - - // Fetches the invocation queue. - // - // This also clears the stored queue. - // - eng::vector get_queued_invocations(); - // Rescan the lua source directory. The lua source directory is read once, - // automatically, at engine creation time. If you want to read it again, - // you must trigger a rescan. The rescan is not instantaneous. + // Set the flag to rescan the lua source directory. The lua source + // directory is read once, automatically, at engine creation time. + // If you want to read it again, you must trigger a rescan. + // The rescan is not instantaneous. // // DRIVER: this merely sets a flag, which the driver will notice later, // causing the driver to update the lua source. @@ -315,7 +316,6 @@ private: int64_t visible_actor_id_; util::IdVector scan_result_; std::vector anim_queues_; - eng::vector queued_invocations_; bool rescan_lua_source_; double clock_; bool stop_driver_; diff --git a/luprex/cpp/core/lpxclient.cpp b/luprex/cpp/core/lpxclient.cpp index 6b9dcf0d..1e3cb52a 100644 --- a/luprex/cpp/core/lpxclient.cpp +++ b/luprex/cpp/core/lpxclient.cpp @@ -19,6 +19,7 @@ public: SharedChannel channel_; LuaConsole console_; PrintChanneler print_channeler_; + eng::vector delayed_invocations_; public: void set_initial_state_connect(const eng::string &hostspec) { @@ -245,12 +246,16 @@ public: return true; } + virtual void event_call_function(InvocationKind kind, int64_t place, std::string_view datapk) { + delayed_invocations_.emplace_back(kind, place, datapk); + } + virtual void event_update() { // Send invocations. We execute these using predictive execution. - eng::vector invocations = get_queued_invocations(); - for (const UniqueInvocation &inv : invocations) { + for (const UniqueInvocation &inv : delayed_invocations_) { send_invocation(*inv); } + delayed_invocations_.clear(); // Check for keyboard input on stdin. while (true) { diff --git a/luprex/cpp/core/lpxserver.cpp b/luprex/cpp/core/lpxserver.cpp index 26ee9b98..5456ff4e 100644 --- a/luprex/cpp/core/lpxserver.cpp +++ b/luprex/cpp/core/lpxserver.cpp @@ -192,16 +192,20 @@ public: return true; } + virtual void event_call_function(InvocationKind kind, int64_t place, std::string_view datapk) { + delayed_invocations_.emplace_back(kind, place, datapk); + } + virtual void event_update() override { // Get the clock. double clock = get_clock(); // Execute any queued invocations. // We just feed these directly into the master model. - eng::vector invocations = get_queued_invocations(); - for (const UniqueInvocation &inv : invocations) { + for (const UniqueInvocation &inv : delayed_invocations_) { master_->invoke(*inv); } + delayed_invocations_.clear(); // Check for keyboard input on stdin. while (true) {