mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-24 19:12:56 +00:00
Unique network transmission handling of flares
This patch addresses issues concerning a1796ed71f:
Allow for a more elegant implementation of observer flares.
And still display flares even if the sender is lagging behind:
Split off flares from simulation commands.
Remove the new, problematic 'observer commands' entirely.
Provide an engine function 'SendNetworkFlare' to the JS interface.
-> which sets off the (pretty ordinary) transmission process.
Add a new type of net messages exclusively for flares
-> contains the flare's position and its sender's GUID.
This commit is contained in:
@@ -274,6 +274,29 @@ void SetTurnLength(int length)
|
||||
LOGERROR("Only network host can change turn length");
|
||||
}
|
||||
|
||||
void SendNetworkFlare(JS::HandleValue position)
|
||||
{
|
||||
ENSURE(g_NetClient);
|
||||
|
||||
ScriptRequest rq(g_NetClient->GetScriptInterface());
|
||||
ENSURE(position.isObject());
|
||||
JS::RootedObject positionObj(rq.cx, &position.toObject());
|
||||
JS::RootedValue positionX(rq.cx);
|
||||
JS::RootedValue positionY(rq.cx);
|
||||
JS::RootedValue positionZ(rq.cx);
|
||||
ENSURE(JS_GetProperty(rq.cx, positionObj, "x", &positionX));
|
||||
ENSURE(JS_GetProperty(rq.cx, positionObj, "y", &positionY));
|
||||
ENSURE(JS_GetProperty(rq.cx, positionObj, "z", &positionZ));
|
||||
|
||||
// (TODO?): Converting the doubles into strings here is a workaround because direct (de)serialisation of floating point numbers is not supported.
|
||||
// It causes somewhat awkward message handling, but the resulting efficiency losses are negligible.
|
||||
g_NetClient->SendFlareMessage(
|
||||
CStr::FromDouble(positionX.toNumber()),
|
||||
CStr::FromDouble(positionY.toNumber()),
|
||||
CStr::FromDouble(positionZ.toNumber())
|
||||
);
|
||||
}
|
||||
|
||||
void RegisterScriptFunctions(const ScriptRequest& rq)
|
||||
{
|
||||
ScriptFunction::Register<&GetDefaultPort>(rq, "GetDefaultPort");
|
||||
@@ -294,5 +317,6 @@ void RegisterScriptFunctions(const ScriptRequest& rq)
|
||||
ScriptFunction::Register<&ClearAllPlayerReady>(rq, "ClearAllPlayerReady");
|
||||
ScriptFunction::Register<&StartNetworkGame>(rq, "StartNetworkGame");
|
||||
ScriptFunction::Register<&SetTurnLength>(rq, "SetTurnLength");
|
||||
ScriptFunction::Register<&SendNetworkFlare>(rq, "SendNetworkFlare");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user