From a3284252b9d6760935cde23f64ca95a3bc4140c7 Mon Sep 17 00:00:00 2001 From: Erlite Date: Mon, 26 Dec 2022 15:51:42 +0100 Subject: Process all squirrel messages in the buffer instead of one per frame. (#381) * Process all squirrel messages in the buffer instead of one per frame. * Move on to the next message if no function is found,. --- NorthstarDLL/squirrel/squirrel.cpp | 51 +++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/NorthstarDLL/squirrel/squirrel.cpp b/NorthstarDLL/squirrel/squirrel.cpp index d594ede9..58f79e00 100644 --- a/NorthstarDLL/squirrel/squirrel.cpp +++ b/NorthstarDLL/squirrel/squirrel.cpp @@ -527,38 +527,37 @@ template void StubUnsafeSQFuncs() template void SquirrelManager::ProcessMessageBuffer() { - auto maybeMessage = messageBuffer->pop(); - if (!maybeMessage) + while (std::optional maybeMessage = messageBuffer->pop()) { - return; - } + SquirrelMessage message = maybeMessage.value(); - SquirrelMessage message = maybeMessage.value(); + SQObject functionobj {}; + int result = sq_getfunction(m_pSQVM->sqvm, message.functionName.c_str(), &functionobj, 0); + if (result != 0) // This func returns 0 on success for some reason + { + NS::log::squirrel_logger()->error( + "ProcessMessageBuffer was unable to find function with name '{}'. Is it global?", message.functionName); + continue; + } - SQObject functionobj {}; - int result = sq_getfunction(m_pSQVM->sqvm, message.functionName.c_str(), &functionobj, 0); - if (result != 0) // This func returns 0 on success for some reason - { - NS::log::squirrel_logger()->error( - "ProcessMessageBuffer was unable to find function with name '{}'. Is it global?", message.functionName); - return; - } - pushobject(m_pSQVM->sqvm, &functionobj); // Push the function object - pushroottable(m_pSQVM->sqvm); - if (message.isExternal) - { - message.externalFunc(m_pSQVM->sqvm); - } - else - { - for (auto& v : message.args) + pushobject(m_pSQVM->sqvm, &functionobj); // Push the function object + pushroottable(m_pSQVM->sqvm); + + if (message.isExternal) { - // Execute lambda to push arg to stack - v(); + message.externalFunc(m_pSQVM->sqvm); + } + else + { + for (auto& v : message.args) + { + // Execute lambda to push arg to stack + v(); + } } - } - _call(m_pSQVM->sqvm, message.args.size()); + _call(m_pSQVM->sqvm, message.args.size()); + } } ADD_SQFUNC( -- cgit v1.2.3