Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/network/NetClient.cpp
Show All 31 Lines | |||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Compress.h" | #include "ps/Compress.h" | ||||
#include "ps/CStr.h" | #include "ps/CStr.h" | ||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||
#include "ps/Loader.h" | #include "ps/Loader.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "ps/Threading.h" | #include "ps/Threading.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "scriptinterface/JSON.h" | |||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "network/StunClient.h" | #include "network/StunClient.h" | ||||
/** | /** | ||||
* Once ping goes above turn length * command delay, | * Once ping goes above turn length * command delay, | ||||
* the game will start 'freezing' for other clients while we catch up. | * the game will start 'freezing' for other clients while we catch up. | ||||
* Since commands are sent client -> server -> client, divide by 2. | * Since commands are sent client -> server -> client, divide by 2. | ||||
* (duplicated in NetServer.cpp to avoid having to fetch the constants in a header file) | * (duplicated in NetServer.cpp to avoid having to fetch the constants in a header file) | ||||
▲ Show 20 Lines • Show All 322 Lines • ▼ Show 20 Lines | std::string CNetClient::TestReadGuiMessages() | ||||
std::string r; | std::string r; | ||||
JS::RootedValue msg(rq.cx); | JS::RootedValue msg(rq.cx); | ||||
while (true) | while (true) | ||||
{ | { | ||||
GuiPoll(&msg); | GuiPoll(&msg); | ||||
if (msg.isUndefined()) | if (msg.isUndefined()) | ||||
break; | break; | ||||
r += GetScriptInterface().ToString(&msg) + "\n"; | r += Script::ToString(rq, &msg) + "\n"; | ||||
} | } | ||||
return r; | return r; | ||||
} | } | ||||
const ScriptInterface& CNetClient::GetScriptInterface() | const ScriptInterface& CNetClient::GetScriptInterface() | ||||
{ | { | ||||
return m_Game->GetSimulation2()->GetScriptInterface(); | return m_Game->GetSimulation2()->GetScriptInterface(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 379 Lines • ▼ Show 20 Lines | bool CNetClient::OnGameStart(void* context, CFsmEvent* event) | ||||
client->m_ClientTurnManager = new CNetClientTurnManager( | client->m_ClientTurnManager = new CNetClientTurnManager( | ||||
*client->m_Game->GetSimulation2(), *client, client->m_HostID, client->m_Game->GetReplayLogger()); | *client->m_Game->GetSimulation2(), *client, client->m_HostID, client->m_Game->GetReplayLogger()); | ||||
// Parse init attributes. | // Parse init attributes. | ||||
const ScriptInterface& scriptInterface = client->m_Game->GetSimulation2()->GetScriptInterface(); | const ScriptInterface& scriptInterface = client->m_Game->GetSimulation2()->GetScriptInterface(); | ||||
ScriptRequest rq(scriptInterface); | ScriptRequest rq(scriptInterface); | ||||
JS::RootedValue initAttribs(rq.cx); | JS::RootedValue initAttribs(rq.cx); | ||||
scriptInterface.ParseJSON(message->m_InitAttributes, &initAttribs); | Script::ParseJSON(rq, message->m_InitAttributes, &initAttribs); | ||||
client->m_Game->SetPlayerID(player); | client->m_Game->SetPlayerID(player); | ||||
client->m_Game->StartGame(&initAttribs, ""); | client->m_Game->StartGame(&initAttribs, ""); | ||||
client->PushGuiMessage("type", "start", | client->PushGuiMessage("type", "start", | ||||
"initAttributes", initAttribs); | "initAttributes", initAttribs); | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 188 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator