Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/network/NetMessageSim.cpp
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | public: | ||||
size_t GetLength() | size_t GetLength() | ||||
{ | { | ||||
return m_Impl.m_Length; | return m_Impl.m_Length; | ||||
} | } | ||||
}; | }; | ||||
CSimulationMessage::CSimulationMessage(const ScriptInterface& scriptInterface) : | CSimulationMessage::CSimulationMessage(const ScriptInterface& scriptInterface) : | ||||
CNetMessage(NMT_SIMULATION_COMMAND), m_ScriptInterface(scriptInterface), m_Data(scriptInterface.GetJSRuntime()) | CNetMessage(NMT_SIMULATION_COMMAND), m_ScriptInterface(scriptInterface), m_Data(scriptInterface.GetGeneralJSContext()) | ||||
{ | { | ||||
} | } | ||||
CSimulationMessage::CSimulationMessage(const ScriptInterface& scriptInterface, u32 client, i32 player, u32 turn, JS::HandleValue data) : | CSimulationMessage::CSimulationMessage(const ScriptInterface& scriptInterface, u32 client, i32 player, u32 turn, JS::HandleValue data) : | ||||
CNetMessage(NMT_SIMULATION_COMMAND), m_ScriptInterface(scriptInterface), | CNetMessage(NMT_SIMULATION_COMMAND), m_ScriptInterface(scriptInterface), | ||||
m_Client(client), m_Player(player), m_Turn(turn), m_Data(scriptInterface.GetJSRuntime(), data) | m_Client(client), m_Player(player), m_Turn(turn), m_Data(scriptInterface.GetGeneralJSContext(), data) | ||||
{ | { | ||||
} | } | ||||
CSimulationMessage::CSimulationMessage(const CSimulationMessage& orig) : | CSimulationMessage::CSimulationMessage(const CSimulationMessage& orig) : | ||||
m_Data(orig.m_ScriptInterface.GetJSRuntime()), | m_Data(orig.m_ScriptInterface.GetGeneralJSContext()), | ||||
m_Client(orig.m_Client), | m_Client(orig.m_Client), | ||||
m_Player(orig.m_Player), | m_Player(orig.m_Player), | ||||
m_ScriptInterface(orig.m_ScriptInterface), | m_ScriptInterface(orig.m_ScriptInterface), | ||||
m_Turn(orig.m_Turn), | m_Turn(orig.m_Turn), | ||||
CNetMessage(orig) | CNetMessage(orig) | ||||
{ | { | ||||
m_Data = orig.m_Data; | m_Data = orig.m_Data; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | CStr CSimulationMessage::ToString() const | ||||
std::stringstream stream; | std::stringstream stream; | ||||
stream << "CSimulationMessage { m_Client: " << m_Client << ", m_Player: " << m_Player << ", m_Turn: " << m_Turn << ", m_Data: " << source << " }"; | stream << "CSimulationMessage { m_Client: " << m_Client << ", m_Player: " << m_Player << ", m_Turn: " << m_Turn << ", m_Data: " << source << " }"; | ||||
return CStr(stream.str()); | return CStr(stream.str()); | ||||
} | } | ||||
CGameSetupMessage::CGameSetupMessage(const ScriptInterface& scriptInterface) : | CGameSetupMessage::CGameSetupMessage(const ScriptInterface& scriptInterface) : | ||||
CNetMessage(NMT_GAME_SETUP), m_ScriptInterface(scriptInterface), m_Data(scriptInterface.GetJSRuntime()) | CNetMessage(NMT_GAME_SETUP), m_ScriptInterface(scriptInterface), m_Data(scriptInterface.GetGeneralJSContext()) | ||||
{ | { | ||||
} | } | ||||
CGameSetupMessage::CGameSetupMessage(const ScriptInterface& scriptInterface, JS::HandleValue data) : | CGameSetupMessage::CGameSetupMessage(const ScriptInterface& scriptInterface, JS::HandleValue data) : | ||||
CNetMessage(NMT_GAME_SETUP), m_ScriptInterface(scriptInterface), | CNetMessage(NMT_GAME_SETUP), m_ScriptInterface(scriptInterface), | ||||
m_Data(scriptInterface.GetJSRuntime(), data) | m_Data(scriptInterface.GetGeneralJSContext(), data) | ||||
{ | { | ||||
} | } | ||||
u8* CGameSetupMessage::Serialize(u8* pBuffer) const | u8* CGameSetupMessage::Serialize(u8* pBuffer) const | ||||
{ | { | ||||
// TODO: ought to handle serialization exceptions | // TODO: ought to handle serialization exceptions | ||||
u8* pos = CNetMessage::Serialize(pBuffer); | u8* pos = CNetMessage::Serialize(pBuffer); | ||||
CBufferBinarySerializer serializer(m_ScriptInterface, pos); | CBufferBinarySerializer serializer(m_ScriptInterface, pos); | ||||
Show All 29 Lines |
Wildfire Games · Phabricator