aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErlite <ys.aameziane@gmail.com>2022-12-26 15:51:42 +0100
committerGitHub <noreply@github.com>2022-12-26 15:51:42 +0100
commita3284252b9d6760935cde23f64ca95a3bc4140c7 (patch)
treeed9fc5c39612f42f11f1d9eeee5ad517008e58cc
parent2c5dd95395faab0462c68e7ec676c97e42967860 (diff)
downloadNorthstarLauncher-a3284252b9d6760935cde23f64ca95a3bc4140c7.tar.gz
NorthstarLauncher-a3284252b9d6760935cde23f64ca95a3bc4140c7.zip
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,.
-rw-r--r--NorthstarDLL/squirrel/squirrel.cpp51
1 files 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 <ScriptContext context> void StubUnsafeSQFuncs()
template <ScriptContext context> void SquirrelManager<context>::ProcessMessageBuffer()
{
- auto maybeMessage = messageBuffer->pop();
- if (!maybeMessage)
+ while (std::optional<SquirrelMessage> 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<context>()->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<context>()->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(