mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 04:05:32 +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:
@@ -116,6 +116,7 @@ CNetClient::CNetClient(CGame* game) :
|
||||
AddTransition(NCS_INGAME, (uint)NMT_GAME_SETUP, NCS_INGAME, &OnGameSetup, this);
|
||||
AddTransition(NCS_INGAME, (uint)NMT_PLAYER_ASSIGNMENT, NCS_INGAME, &OnPlayerAssignment, this);
|
||||
AddTransition(NCS_INGAME, (uint)NMT_SIMULATION_COMMAND, NCS_INGAME, &OnInGame, this);
|
||||
AddTransition(NCS_INGAME, (uint)NMT_FLARE, NCS_INGAME, &OnFlare, this);
|
||||
AddTransition(NCS_INGAME, (uint)NMT_SYNC_ERROR, NCS_INGAME, &OnInGame, this);
|
||||
AddTransition(NCS_INGAME, (uint)NMT_END_COMMAND_BATCH, NCS_INGAME, &OnInGame, this);
|
||||
|
||||
@@ -489,6 +490,15 @@ void CNetClient::SendStartGameMessage(const CStr& initAttribs)
|
||||
SendMessage(&gameStart);
|
||||
}
|
||||
|
||||
void CNetClient::SendFlareMessage(const CStr& positionX, const CStr& positionY, const CStr& positionZ)
|
||||
{
|
||||
CFlareMessage flare;
|
||||
flare.m_PositionX = positionX;
|
||||
flare.m_PositionY = positionY;
|
||||
flare.m_PositionZ = positionZ;
|
||||
SendMessage(&flare);
|
||||
}
|
||||
|
||||
void CNetClient::SendRejoinedMessage()
|
||||
{
|
||||
CRejoinedMessage rejoinedMessage;
|
||||
@@ -963,3 +973,28 @@ bool CNetClient::OnInGame(CNetClient* client, CFsmEvent* event)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CNetClient::OnFlare(CNetClient* client, CFsmEvent* event)
|
||||
{
|
||||
ENSURE(event->GetType() == static_cast<uint>(NMT_FLARE));
|
||||
|
||||
CFlareMessage* message = static_cast<CFlareMessage*>(event->GetParamRef());
|
||||
|
||||
const ScriptInterface& scriptInterface = client->m_Game->GetSimulation2()->GetScriptInterface();
|
||||
ScriptRequest rq(scriptInterface);
|
||||
JS::RootedValue position(rq.cx);
|
||||
Script::CreateObject(
|
||||
rq, &position,
|
||||
// The coordinates are transmitted as strings (because because direct (de)serialisation of floating point numbers is not supported).
|
||||
"x", message->m_PositionX.ToDouble(),
|
||||
"y", message->m_PositionY.ToDouble(),
|
||||
"z", message->m_PositionZ.ToDouble()
|
||||
);
|
||||
|
||||
client->PushGuiMessage(
|
||||
"type", "flare",
|
||||
"guid", message->m_GUID,
|
||||
"position", position);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user