Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/ps/Game.cpp
Show First 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | bool CGame::StartVisualReplay(const OsPath& replayPath) | ||||
std::string type; | std::string type; | ||||
ENSURE((*m_ReplayStream >> type).good() && type == "start"); | ENSURE((*m_ReplayStream >> type).good() && type == "start"); | ||||
std::string line; | std::string line; | ||||
std::getline(*m_ReplayStream, line); | std::getline(*m_ReplayStream, line); | ||||
const ScriptInterface& scriptInterface = m_Simulation2->GetScriptInterface(); | const ScriptInterface& scriptInterface = m_Simulation2->GetScriptInterface(); | ||||
JSContext* cx = scriptInterface.GetContext(); | ScriptInterface::Request rq(scriptInterface); | ||||
JSAutoRequest rq(cx); | |||||
JS::RootedValue attribs(cx); | JS::RootedValue attribs(rq.cx); | ||||
scriptInterface.ParseJSON(line, &attribs); | scriptInterface.ParseJSON(line, &attribs); | ||||
StartGame(&attribs, ""); | StartGame(&attribs, ""); | ||||
return true; | return true; | ||||
} | } | ||||
/** | /** | ||||
* Initializes the game with the set of attributes provided. | * Initializes the game with the set of attributes provided. | ||||
* Makes calls to initialize the game view, world, and simulation objects. | * Makes calls to initialize the game view, world, and simulation objects. | ||||
* Calls are made to facilitate progress reporting of the initialization. | * Calls are made to facilitate progress reporting of the initialization. | ||||
**/ | **/ | ||||
void CGame::RegisterInit(const JS::HandleValue attribs, const std::string& savedState) | void CGame::RegisterInit(const JS::HandleValue attribs, const std::string& savedState) | ||||
{ | { | ||||
const ScriptInterface& scriptInterface = m_Simulation2->GetScriptInterface(); | const ScriptInterface& scriptInterface = m_Simulation2->GetScriptInterface(); | ||||
JSContext* cx = scriptInterface.GetContext(); | ScriptInterface::Request rq(scriptInterface); | ||||
JSAutoRequest rq(cx); | |||||
m_InitialSavedState = savedState; | m_InitialSavedState = savedState; | ||||
m_IsSavedGame = !savedState.empty(); | m_IsSavedGame = !savedState.empty(); | ||||
m_Simulation2->SetInitAttributes(attribs); | m_Simulation2->SetInitAttributes(attribs); | ||||
std::string mapType; | std::string mapType; | ||||
scriptInterface.GetProperty(attribs, "mapType", mapType); | scriptInterface.GetProperty(attribs, "mapType", mapType); | ||||
Show All 13 Lines | void CGame::RegisterInit(const JS::HandleValue attribs, const std::string& savedState) | ||||
// some point to be stored in the world object? | // some point to be stored in the world object? | ||||
if (m_GameView) | if (m_GameView) | ||||
m_GameView->RegisterInit(); | m_GameView->RegisterInit(); | ||||
if (mapType == "random") | if (mapType == "random") | ||||
{ | { | ||||
// Load random map attributes | // Load random map attributes | ||||
std::wstring scriptFile; | std::wstring scriptFile; | ||||
JS::RootedValue settings(cx); | JS::RootedValue settings(rq.cx); | ||||
scriptInterface.GetProperty(attribs, "script", scriptFile); | scriptInterface.GetProperty(attribs, "script", scriptFile); | ||||
scriptInterface.GetProperty(attribs, "settings", &settings); | scriptInterface.GetProperty(attribs, "settings", &settings); | ||||
m_World->RegisterInitRMS(scriptFile, scriptInterface.GetJSRuntime(), settings, m_PlayerID); | m_World->RegisterInitRMS(scriptFile, scriptInterface.GetJSRuntime(), settings, m_PlayerID); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
std::wstring mapFile; | std::wstring mapFile; | ||||
JS::RootedValue settings(cx); | JS::RootedValue settings(rq.cx); | ||||
scriptInterface.GetProperty(attribs, "map", mapFile); | scriptInterface.GetProperty(attribs, "map", mapFile); | ||||
scriptInterface.GetProperty(attribs, "settings", &settings); | scriptInterface.GetProperty(attribs, "settings", &settings); | ||||
m_World->RegisterInit(mapFile, scriptInterface.GetJSRuntime(), settings, m_PlayerID); | m_World->RegisterInit(mapFile, scriptInterface.GetJSRuntime(), settings, m_PlayerID); | ||||
} | } | ||||
if (m_GameView) | if (m_GameView) | ||||
RegMemFun(g_Renderer.GetSingletonPtr()->GetWaterManager(), &WaterManager::LoadWaterTextures, L"LoadWaterTextures", 80); | RegMemFun(g_Renderer.GetSingletonPtr()->GetWaterManager(), &WaterManager::LoadWaterTextures, L"LoadWaterTextures", 80); | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | PSRETURN CGame::ReallyStartGame() | ||||
if (g_NetClient) | if (g_NetClient) | ||||
g_NetClient->LoadFinished(); | g_NetClient->LoadFinished(); | ||||
// Call the reallyStartGame GUI function, but only if it exists | // Call the reallyStartGame GUI function, but only if it exists | ||||
if (g_GUI && g_GUI->GetPageCount()) | if (g_GUI && g_GUI->GetPageCount()) | ||||
{ | { | ||||
shared_ptr<ScriptInterface> scriptInterface = g_GUI->GetActiveGUI()->GetScriptInterface(); | shared_ptr<ScriptInterface> scriptInterface = g_GUI->GetActiveGUI()->GetScriptInterface(); | ||||
JSContext* cx = scriptInterface->GetContext(); | ScriptInterface::Request rq(scriptInterface); | ||||
JSAutoRequest rq(cx); | |||||
JS::RootedValue global(cx, scriptInterface->GetGlobalObject()); | JS::RootedValue global(rq.cx, scriptInterface->GetGlobalObject()); | ||||
if (scriptInterface->HasProperty(global, "reallyStartGame")) | if (scriptInterface->HasProperty(global, "reallyStartGame")) | ||||
scriptInterface->CallFunctionVoid(global, "reallyStartGame"); | scriptInterface->CallFunctionVoid(global, "reallyStartGame"); | ||||
} | } | ||||
debug_printf("GAME STARTED, ALL INIT COMPLETE\n"); | debug_printf("GAME STARTED, ALL INIT COMPLETE\n"); | ||||
// The call tree we've built for pregame probably isn't useful in-game. | // The call tree we've built for pregame probably isn't useful in-game. | ||||
if (CProfileManager::IsInitialised()) | if (CProfileManager::IsInitialised()) | ||||
▲ Show 20 Lines • Show All 133 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator