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:
Vantha
2024-12-03 21:24:55 +01:00
committed by phosit
parent 75205699d0
commit 960bd5eace
11 changed files with 125 additions and 55 deletions
@@ -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");
}
}