1
0
forked from mirrors/0ad

Return the value from GuiPoll

This commit is contained in:
phosit
2024-11-11 21:54:58 +01:00
parent f23dde2f73
commit cfb742c914
3 changed files with 8 additions and 15 deletions
+6 -8
View File
@@ -357,16 +357,15 @@ void CNetClient::CheckServerConnection()
}
}
void CNetClient::GuiPoll(const ScriptRequest& rq, JS::MutableHandleValue ret)
JS::Value CNetClient::GuiPoll(const ScriptRequest& rq)
{
if (m_GuiMessageQueue.empty())
{
ret.setUndefined();
return;
}
return JS::UndefinedValue();
Script::ReadStructuredClone(rq, m_GuiMessageQueue.front(), ret);
JS::RootedValue ret{rq.cx};
Script::ReadStructuredClone(rq, m_GuiMessageQueue.front(), &ret);
m_GuiMessageQueue.pop_front();
return ret;
}
std::string CNetClient::TestReadGuiMessages()
@@ -374,10 +373,9 @@ std::string CNetClient::TestReadGuiMessages()
ScriptRequest rq(GetScriptInterface());
std::string r;
JS::RootedValue msg(rq.cx);
while (true)
{
GuiPoll(rq, &msg);
JS::RootedValue msg{rq.cx, GuiPoll(rq)};
if (msg.isUndefined())
break;
r += Script::ToString(rq, &msg) + "\n";
+1 -1
View File
@@ -156,7 +156,7 @@ public:
*
* @return next message, or the value 'undefined' if the queue is empty
*/
void GuiPoll(const ScriptRequest& rq, JS::MutableHandleValue ret);
JS::Value GuiPoll(const ScriptRequest& rq);
/**
* Add a message to the queue, to be read by GuiPoll.
@@ -198,12 +198,7 @@ CStr GetPlayerGUID()
JS::Value PollNetworkClient(const ScriptRequest& rq)
{
if (!g_NetClient)
return JS::UndefinedValue();
JS::RootedValue message{rq.cx};
g_NetClient->GuiPoll(rq, &message);
return message;
return g_NetClient ? g_NetClient->GuiPoll(rq) : JS::UndefinedValue();
}
void SendGameSetupMessage(const ScriptInterface& scriptInterface, JS::HandleValue attribs1)