Index: source/graphics/Camera.cpp =================================================================== --- source/graphics/Camera.cpp +++ source/graphics/Camera.cpp @@ -200,7 +200,7 @@ CVector3D CCamera::GetWorldCoordinates(int px, int py, bool aboveWater) const { - CHFTracer tracer(g_Game->GetWorld()->GetTerrain()); + CHFTracer tracer(CGame::GetGame()->GetWorld()->GetTerrain()); int x, z; CVector3D origin, dir, delta, terrainPoint, waterPoint; @@ -227,7 +227,7 @@ // Clamp the water intersection to within the map's bounds, so that // we'll always return a valid position on the map - ssize_t mapSize = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); + ssize_t mapSize = CGame::GetGame()->GetWorld()->GetTerrain()->GetVerticesPerSide(); if (gotWater) { waterPoint.X = clamp(waterPoint.X, 0.f, (float)((mapSize-1)*TERRAIN_TILE_SIZE)); @@ -287,7 +287,7 @@ { // Basically the same as GetWorldCoordinates - CHFTracer tracer(g_Game->GetWorld()->GetTerrain()); + CHFTracer tracer(CGame::GetGame()->GetWorld()->GetTerrain()); int x, z; CVector3D origin, dir, delta, terrainPoint, waterPoint; @@ -305,7 +305,7 @@ // Clamp the water intersection to within the map's bounds, so that // we'll always return a valid position on the map - ssize_t mapSize = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); + ssize_t mapSize = CGame::GetGame()->GetWorld()->GetTerrain()->GetVerticesPerSide(); if (gotWater) { waterPoint.X = clamp(waterPoint.X, 0.f, (float)((mapSize-1)*TERRAIN_TILE_SIZE)); Index: source/graphics/CinemaManager.cpp =================================================================== --- source/graphics/CinemaManager.cpp +++ source/graphics/CinemaManager.cpp @@ -58,12 +58,12 @@ void CCinemaManager::Update(const float deltaRealTime) const { - CmpPtr cmpCinemaManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity()); + CmpPtr cmpCinemaManager(CGame::GetGame()->GetSimulation2()->GetSimContext().GetSystemEntity()); if (!cmpCinemaManager) return; if (IsPlaying()) - cmpCinemaManager->PlayQueue(deltaRealTime, g_Game->GetView()->GetCamera()); + cmpCinemaManager->PlayQueue(deltaRealTime, CGame::GetGame()->GetView()->GetCamera()); } void CCinemaManager::Render() const @@ -76,7 +76,7 @@ void CCinemaManager::DrawPaths() const { - CmpPtr cmpCinemaManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity()); + CmpPtr cmpCinemaManager(CGame::GetGame()->GetSimulation2()->GetSimContext().GetSystemEntity()); if (!cmpCinemaManager) return; @@ -124,7 +124,7 @@ glEnd(); // Height indicator - if (g_Game && g_Game->GetWorld() && g_Game->GetWorld()->GetTerrain()) + if (CGame::IsGameInitialised() && CGame::GetGame()->GetWorld() && CGame::GetGame()->GetWorld()->GetTerrain()) { glLineWidth(1.1f); glBegin(GL_LINES); @@ -132,7 +132,7 @@ { time = start * i / spline.MaxDistance.ToFloat(); CVector3D tmp = spline.GetPosition(time); - float groundY = g_Game->GetWorld()->GetTerrain()->GetExactGroundLevel(tmp.X, tmp.Z); + float groundY = CGame::GetGame()->GetWorld()->GetTerrain()->GetExactGroundLevel(tmp.X, tmp.Z); glVertex3f(tmp.X, tmp.Y, tmp.Z); glVertex3f(tmp.X, groundY, tmp.Z); } @@ -240,13 +240,13 @@ bool CCinemaManager::IsEnabled() const { - CmpPtr cmpCinemaManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity()); + CmpPtr cmpCinemaManager(CGame::GetGame()->GetSimulation2()->GetSimContext().GetSystemEntity()); return cmpCinemaManager && cmpCinemaManager->IsEnabled(); } bool CCinemaManager::IsPlaying() const { - return IsEnabled() && g_Game && !g_Game->m_Paused; + return IsEnabled() && CGame::IsGameInitialised() && !CGame::GetGame()->m_Paused; } bool CCinemaManager::GetPathsDrawing() const Index: source/graphics/GameView.cpp =================================================================== --- source/graphics/GameView.cpp +++ source/graphics/GameView.cpp @@ -1053,10 +1053,10 @@ InReaction game_view_handler(const SDL_Event_* ev) { // put any events that must be processed even if inactive here - if (!g_app_has_focus || !g_Game || !g_Game->IsGameStarted() || g_Game->GetView()->GetCinema()->IsEnabled()) + if (!g_app_has_focus || !CGame::IsGameInitialised() || !CGame::GetGame()->IsGameStarted() || CGame::GetGame()->GetView()->GetCinema()->IsEnabled()) return IN_PASS; - CGameView *pView=g_Game->GetView(); + CGameView *pView=CGame::GetGame()->GetView(); return pView->HandleEvent(ev); } Index: source/graphics/LOSTexture.cpp =================================================================== --- source/graphics/LOSTexture.cpp +++ source/graphics/LOSTexture.cpp @@ -342,7 +342,7 @@ if (!cmpRangeManager) return; - ICmpRangeManager::CLosQuerier los(cmpRangeManager->GetLosQuerier(g_Game->GetSimulation2()->GetSimContext().GetCurrentDisplayedPlayer())); + ICmpRangeManager::CLosQuerier los(cmpRangeManager->GetLosQuerier(CGame::GetGame()->GetSimulation2()->GetSimContext().GetCurrentDisplayedPlayer())); GenerateBitmap(los, &losData[0], m_MapSize, m_MapSize, pitch); Index: source/graphics/UnitAnimation.cpp =================================================================== --- source/graphics/UnitAnimation.cpp +++ source/graphics/UnitAnimation.cpp @@ -202,7 +202,7 @@ if ( !hasSoundPos && !m_ActionSound.empty() ) { - CmpPtr cmpSoundManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpSoundManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (cmpSoundManager) cmpSoundManager->PlaySoundGroup(m_ActionSound, m_Entity); } @@ -213,7 +213,7 @@ { if (!m_ActionSound.empty() ) { - CmpPtr cmpSoundManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpSoundManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (cmpSoundManager) cmpSoundManager->PlaySoundGroup(m_ActionSound, m_Entity); } Index: source/graphics/scripting/JSInterface_GameView.cpp =================================================================== --- source/graphics/scripting/JSInterface_GameView.cpp +++ source/graphics/scripting/JSInterface_GameView.cpp @@ -31,22 +31,22 @@ #define IMPLEMENT_BOOLEAN_SCRIPT_SETTING(NAME) \ bool JSI_GameView::Get##NAME##Enabled(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) \ { \ - if (!g_Game || !g_Game->GetView()) \ + if (!CGame::IsGameInitialised() || !CGame::GetGame()->GetView()) \ { \ LOGERROR("Trying to get a setting from GameView when it's not initialized!"); \ return false; \ } \ - return g_Game->GetView()->Get##NAME##Enabled(); \ + return CGame::GetGame()->GetView()->Get##NAME##Enabled(); \ } \ \ void JSI_GameView::Set##NAME##Enabled(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), bool Enabled) \ { \ - if (!g_Game || !g_Game->GetView()) \ + if (!CGame::IsGameInitialised() || !CGame::GetGame()->GetView()) \ { \ LOGERROR("Trying to set a setting of GameView when it's not initialized!"); \ return; \ } \ - g_Game->GetView()->Set##NAME##Enabled(Enabled); \ + CGame::GetGame()->GetView()->Set##NAME##Enabled(Enabled); \ } IMPLEMENT_BOOLEAN_SCRIPT_SETTING(Culling); @@ -74,10 +74,10 @@ */ float JSI_GameView::CameraGetX(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - if (!g_Game || !g_Game->GetView()) + if (!CGame::IsGameInitialised() || !CGame::GetGame()->GetView()) return -1; - return g_Game->GetView()->GetCameraX(); + return CGame::GetGame()->GetView()->GetCameraX(); } /** @@ -85,10 +85,10 @@ */ float JSI_GameView::CameraGetZ(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - if (!g_Game || !g_Game->GetView()) + if (!CGame::IsGameInitialised() || !CGame::GetGame()->GetView()) return -1; - return g_Game->GetView()->GetCameraZ(); + return CGame::GetGame()->GetView()->GetCameraZ(); } /** @@ -96,17 +96,17 @@ */ void JSI_GameView::CameraMoveTo(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), entity_pos_t x, entity_pos_t z) { - if (!g_Game || !g_Game->GetWorld() || !g_Game->GetView() || !g_Game->GetWorld()->GetTerrain()) + if (!CGame::IsGameInitialised() || !CGame::GetGame()->GetWorld() || !CGame::GetGame()->GetView() || !CGame::GetGame()->GetWorld()->GetTerrain()) return; - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); + CTerrain* terrain = CGame::GetGame()->GetWorld()->GetTerrain(); CVector3D target; target.X = x.ToFloat(); target.Z = z.ToFloat(); target.Y = terrain->GetExactGroundLevel(target.X, target.Z); - g_Game->GetView()->MoveCameraTarget(target); + CGame::GetGame()->GetView()->MoveCameraTarget(target); } /** @@ -114,7 +114,7 @@ */ void JSI_GameView::SetCameraTarget(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), float x, float y, float z) { - g_Game->GetView()->ResetCameraTarget(CVector3D(x, y, z)); + CGame::GetGame()->GetView()->ResetCameraTarget(CVector3D(x, y, z)); } /** @@ -122,7 +122,7 @@ */ void JSI_GameView::SetCameraData(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), entity_pos_t x, entity_pos_t y, entity_pos_t z, entity_pos_t rotx, entity_pos_t roty, entity_pos_t zoom) { - if (!g_Game || !g_Game->GetWorld() || !g_Game->GetView() || !g_Game->GetWorld()->GetTerrain()) + if (!CGame::IsGameInitialised() || !CGame::GetGame()->GetWorld() || !CGame::GetGame()->GetView() || !CGame::GetGame()->GetWorld()->GetTerrain()) return; CVector3D Pos = CVector3D(x.ToFloat(), y.ToFloat(), z.ToFloat()); @@ -130,7 +130,7 @@ float RotY = roty.ToFloat(); float Zoom = zoom.ToFloat(); - g_Game->GetView()->SetCamera(Pos, RotX, RotY, Zoom); + CGame::GetGame()->GetView()->SetCamera(Pos, RotX, RotY, Zoom); } /** @@ -139,10 +139,10 @@ */ void JSI_GameView::CameraFollow(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), entity_id_t entityid) { - if (!g_Game || !g_Game->GetView()) + if (!CGame::IsGameInitialised() || !CGame::GetGame()->GetView()) return; - g_Game->GetView()->CameraFollow(entityid, false); + CGame::GetGame()->GetView()->CameraFollow(entityid, false); } /** @@ -151,23 +151,23 @@ */ void JSI_GameView::CameraFollowFPS(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), entity_id_t entityid) { - if (!g_Game || !g_Game->GetView()) + if (!CGame::IsGameInitialised() || !CGame::GetGame()->GetView()) return; - g_Game->GetView()->CameraFollow(entityid, true); + CGame::GetGame()->GetView()->CameraFollow(entityid, true); } entity_id_t JSI_GameView::GetFollowedEntity(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - if (!g_Game || !g_Game->GetView()) + if (!CGame::IsGameInitialised() || !CGame::GetGame()->GetView()) return INVALID_ENTITY; - return g_Game->GetView()->GetFollowedEntity(); + return CGame::GetGame()->GetView()->GetFollowedEntity(); } CFixedVector3D JSI_GameView::GetTerrainAtScreenPoint(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int x, int y) { - CVector3D pos = g_Game->GetView()->GetCamera()->GetWorldCoordinates(x, y, true); + CVector3D pos = CGame::GetGame()->GetView()->GetCamera()->GetWorldCoordinates(x, y, true); return CFixedVector3D(fixed::FromFloat(pos.X), fixed::FromFloat(pos.Y), fixed::FromFloat(pos.Z)); } Index: source/gui/CDropDown.cpp =================================================================== --- source/gui/CDropDown.cpp +++ source/gui/CDropDown.cpp @@ -147,8 +147,8 @@ break; CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_enter", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_enter", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); break; } @@ -162,8 +162,8 @@ break; CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_leave", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_leave", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); break; } @@ -176,8 +176,8 @@ if (!enabled) { CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); break; } @@ -196,8 +196,8 @@ GetScrollBar(0).SetPos(m_ItemsYPositions.empty() ? 0 : m_ItemsYPositions[m_ElementHighlight] - 60); CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_opened", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_opened", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); return; // overshadow } @@ -212,8 +212,8 @@ GetScrollBar(0).SetZ(GetBufferedZ()); CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_closed", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_closed", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); return; // overshadow } @@ -271,8 +271,8 @@ if (m_Open) { CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_closed", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_closed", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); } m_Open = false; break; Index: source/gui/CList.cpp =================================================================== --- source/gui/CList.cpp +++ source/gui/CList.cpp @@ -197,8 +197,8 @@ if (!enabled) { CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); break; } @@ -209,8 +209,8 @@ UpdateAutoScroll(); CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); if (timer_Time() - m_LastItemClickTime < SELECT_DBLCLICK_RATE && hovered == m_PrevSelectedItem) this->SendEvent(GUIM_MOUSE_DBLCLICK_LEFT_ITEM, "mouseleftdoubleclickitem"); @@ -458,8 +458,8 @@ GUI::SetSetting(this, "selected", selected); CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); } } @@ -474,8 +474,8 @@ GUI::SetSetting(this, "selected", selected); CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); } } Index: source/gui/COList.cpp =================================================================== --- source/gui/COList.cpp +++ source/gui/COList.cpp @@ -183,8 +183,8 @@ ScriptEvent("selectioncolumnchange"); CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); return; } Index: source/gui/IGUIButtonBehavior.cpp =================================================================== --- source/gui/IGUIButtonBehavior.cpp +++ source/gui/IGUIButtonBehavior.cpp @@ -42,16 +42,16 @@ if (!enabled) break; - if (g_SoundManager && GUI::GetSetting(this, "sound_enter", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_enter", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); break; case GUIM_MOUSE_LEAVE: if (!enabled) break; - if (g_SoundManager && GUI::GetSetting(this, "sound_leave", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_leave", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); break; case GUIM_MOUSE_DBLCLICK_LEFT: @@ -66,14 +66,14 @@ case GUIM_MOUSE_PRESS_LEFT: if (!enabled) { - if (g_SoundManager && GUI::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); break; } // Button was clicked - if (g_SoundManager && GUI::GetSetting(this, "sound_pressed", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_pressed", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); SendEvent(GUIM_PRESSED, "press"); m_Pressed = true; break; @@ -90,14 +90,14 @@ case GUIM_MOUSE_PRESS_RIGHT: if (!enabled) { - if (g_SoundManager && GUI::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); break; } // Button was right-clicked - if (g_SoundManager && GUI::GetSetting(this, "sound_pressed", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_pressed", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); SendEvent(GUIM_PRESSED_MOUSE_RIGHT, "pressright"); m_PressedRight = true; break; @@ -109,8 +109,8 @@ if (m_PressedRight) { m_PressedRight = false; - if (g_SoundManager && GUI::GetSetting(this, "sound_released", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_released", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); } break; @@ -121,8 +121,8 @@ if (m_Pressed) { m_Pressed = false; - if (g_SoundManager && GUI::GetSetting(this, "sound_released", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (ISoundManager::IsCreated() && GUI::GetSetting(this, "sound_released", soundPath) == PSRETURN_OK && !soundPath.empty()) + ISoundManager::GetSoundManager()->PlayAsUI(soundPath.c_str(), false); } break; Index: source/gui/MiniMap.cpp =================================================================== --- source/gui/MiniMap.cpp +++ source/gui/MiniMap.cpp @@ -220,12 +220,12 @@ void CMiniMap::SetCameraPos() { - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); + CTerrain* terrain = CGame::GetGame()->GetWorld()->GetTerrain(); CVector3D target; GetMouseWorldCoordinates(target.X, target.Z); target.Y = terrain->GetExactGroundLevel(target.X, target.Z); - g_Game->GetView()->MoveCameraTarget(target); + CGame::GetGame()->GetView()->MoveCameraTarget(target); } float CMiniMap::GetAngle() @@ -379,16 +379,16 @@ // The terrain isn't actually initialized until the map is loaded, which // happens when the game is started, so abort until then. - if (!(GetGUI() && g_Game && g_Game->IsGameStarted())) + if (!(GetGUI() && CGame::GetGame() && CGame::GetGame()->IsGameStarted())) return; - CSimulation2* sim = g_Game->GetSimulation2(); + CSimulation2* sim = CGame::GetGame()->GetSimulation2(); CmpPtr cmpRangeManager(*sim, SYSTEM_ENTITY); ENSURE(cmpRangeManager); // Set our globals in case they hadn't been set before - m_Camera = g_Game->GetView()->GetCamera(); - m_Terrain = g_Game->GetWorld()->GetTerrain(); + m_Camera = CGame::GetGame()->GetView()->GetCamera(); + m_Terrain = CGame::GetGame()->GetWorld()->GetTerrain(); m_Width = (u32)(m_CachedActualSize.right - m_CachedActualSize.left); m_Height = (u32)(m_CachedActualSize.bottom - m_CachedActualSize.top); m_MapSize = m_Terrain->GetVerticesPerSide(); @@ -446,7 +446,7 @@ // Draw territory boundaries glEnable(GL_BLEND); - CTerritoryTexture& territoryTexture = g_Game->GetView()->GetTerritoryTexture(); + CTerritoryTexture& territoryTexture = CGame::GetGame()->GetView()->GetTerritoryTexture(); shader->BindTexture(str_baseTex, territoryTexture.GetTexture()); const CMatrix3D* territoryTransform = territoryTexture.GetMinimapTextureMatrix(); @@ -457,7 +457,7 @@ tech->EndPass(); // Draw the LOS quad in black, using alpha values from the LOS texture - CLOSTexture& losTexture = g_Game->GetView()->GetLOSTexture(); + CLOSTexture& losTexture = CGame::GetGame()->GetView()->GetLOSTexture(); CShaderDefines losDefines; losDefines.Add(str_MINIMAP_LOS, str_1); @@ -531,7 +531,7 @@ ICmpMinimap* cmpMinimap = static_cast(it->second); if (cmpMinimap->GetRenderData(v.r, v.g, v.b, posX, posZ)) { - ICmpRangeManager::ELosVisibility vis = cmpRangeManager->GetLosVisibility(it->first, g_Game->GetSimulation2()->GetSimContext().GetCurrentDisplayedPlayer()); + ICmpRangeManager::ELosVisibility vis = cmpRangeManager->GetLosVisibility(it->first, CGame::GetGame()->GetSimulation2()->GetSimContext().GetCurrentDisplayedPlayer()); if (vis != ICmpRangeManager::VIS_HIDDEN) { v.a = 255; Index: source/main.cpp =================================================================== --- source/main.cpp +++ source/main.cpp @@ -239,7 +239,7 @@ return; double fpsLimit = 0.0; - CFG_GET_VAL(g_Game && g_Game->IsGameStarted() ? "adaptivefps.session" : "adaptivefps.menu", fpsLimit); + CFG_GET_VAL(CGame::IsGameInitialised() && CGame::GetGame()->IsGameStarted() ? "adaptivefps.session" : "adaptivefps.menu", fpsLimit); // Keep in sync with options.json if (fpsLimit < 20.0 || fpsLimit >= 100.0) @@ -275,7 +275,7 @@ break; // just finished loading case INFO::ALL_COMPLETE: - g_Game->ReallyStartGame(); + CGame::GetGame()->ReallyStartGame(); wcscpy_s(description, ARRAY_SIZE(description), L"Game is starting.."); // LDR_ProgressiveLoad returns L""; set to valid text to // avoid problems in converting to JSString @@ -387,11 +387,11 @@ ogl_WarnIfError(); - if (g_Game && g_Game->IsGameStarted() && need_update) + if (CGame::IsGameInitialised() && CGame::GetGame()->IsGameStarted() && need_update) { - g_Game->Update(realTimeSinceLastFrame); + CGame::GetGame()->Update(realTimeSinceLastFrame); - g_Game->GetView()->Update(float(realTimeSinceLastFrame)); + CGame::GetGame()->GetView()->Update(float(realTimeSinceLastFrame)); } // Immediately flush any messages produced by simulation code @@ -435,11 +435,11 @@ static u32 turn = 0; debug_printf("Turn %u (%u)...\n", turn++, DEFAULT_TURN_LENGTH_SP); - g_Game->GetSimulation2()->Update(DEFAULT_TURN_LENGTH_SP); + CGame::GetGame()->GetSimulation2()->Update(DEFAULT_TURN_LENGTH_SP); g_Profiler.Frame(); - if (g_Game->IsGameFinished()) + if (CGame::GetGame()->IsGameFinished()) QuitEngine(); } Index: source/network/scripting/JSInterface_Network.cpp =================================================================== --- source/network/scripting/JSInterface_Network.cpp +++ source/network/scripting/JSInterface_Network.cpp @@ -55,7 +55,7 @@ { ENSURE(!g_NetClient); ENSURE(!g_NetServer); - ENSURE(!g_Game); + ENSURE(!CGame::IsGameInitialised()); // Always use lobby authentication for lobby matches to prevent impersonation and smurfing, in particular through mods that implemented an UI for arbitrary or other players nicknames. g_NetServer = new CNetServer(static_cast(g_XmppClient)); @@ -65,9 +65,8 @@ SAFE_DELETE(g_NetServer); return; } - - g_Game = new CGame(); - g_NetClient = new CNetClient(g_Game, true); + CGame::InitGame(); + g_NetClient = new CNetClient(CGame::GetGame(), true); g_NetClient->SetUserName(playerName); g_NetClient->SetHostingPlayerName(hostLobbyName); @@ -75,7 +74,7 @@ { pCxPrivate->pScriptInterface->ReportError("Failed to connect to server"); SAFE_DELETE(g_NetClient); - SAFE_DELETE(g_Game); + CGame::DeInitGame(); } } @@ -83,7 +82,7 @@ { ENSURE(!g_NetClient); ENSURE(!g_NetServer); - ENSURE(!g_Game); + ENSURE(!CGame::IsGameInitialised()); ENetHost* enetClient = nullptr; if (g_XmppClient && useSTUN) @@ -117,8 +116,8 @@ SDL_Delay(1000); } - g_Game = new CGame(); - g_NetClient = new CNetClient(g_Game, false); + CGame::InitGame(); + g_NetClient = new CNetClient(CGame::GetGame(), false); g_NetClient->SetUserName(playerName); g_NetClient->SetHostingPlayerName(hostJID.substr(0, hostJID.find("@"))); @@ -129,7 +128,7 @@ { pCxPrivate->pScriptInterface->ReportError("Failed to connect to server"); SAFE_DELETE(g_NetClient); - SAFE_DELETE(g_Game); + CGame::DeInitGame(); } } @@ -139,7 +138,7 @@ SAFE_DELETE(g_NetServer); SAFE_DELETE(g_NetClient); - SAFE_DELETE(g_Game); + CGame::DeInitGame(); } CStr JSI_Network::GetPlayerGUID(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) Index: source/ps/Game.h =================================================================== --- source/ps/Game.h +++ source/ps/Game.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2018 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -79,8 +79,14 @@ player_id_t m_ViewedPlayerID; CTurnManager* m_TurnManager; - +private: + static CGame* s_Game; public: + static CGame* GetGame(); + static void InitGame(bool disableGraphics = false, bool replayLog = true); + static void DeInitGame(); + static bool IsGameInitialised(); + CGame(bool disableGraphics = false, bool replayLog = true); ~CGame(); @@ -229,6 +235,4 @@ u32 m_FinalReplayTurn; }; -extern CGame *g_Game; - #endif Index: source/ps/Game.cpp =================================================================== --- source/ps/Game.cpp +++ source/ps/Game.cpp @@ -55,10 +55,33 @@ extern GameLoopState* g_AtlasGameLoop; /** - * Globally accessible pointer to the CGame object. + * Static pointer to the CGame object. **/ -CGame *g_Game=NULL; +CGame* CGame::s_Game = NULL; +CGame* CGame::GetGame() +{ + return s_Game; +} +void CGame::InitGame(bool disableGraphics /*=false*/, bool replayLog /*=true*/) +{ + if (s_Game) + DeInitGame(); + + s_Game = new CGame(disableGraphics, replayLog); +} +void CGame::DeInitGame() +{ + if (!s_Game) + return; + + delete s_Game; + s_Game = NULL; +} +bool CGame::IsGameInitialised() +{ + return s_Game != NULL; +} /** * Constructor * @@ -412,8 +435,8 @@ { m_TurnManager->Interpolate(deltaSimTime, deltaRealTime); - if ( g_SoundManager ) - g_SoundManager->IdleTask(); + if (ISoundManager::IsCreated()) + ISoundManager::GetSoundManager()->IdleTask(); } } Index: source/ps/GameSetup/GameSetup.cpp =================================================================== --- source/ps/GameSetup/GameSetup.cpp +++ source/ps/GameSetup/GameSetup.cpp @@ -194,8 +194,8 @@ { PROFILE3("render"); - if (g_SoundManager) - g_SoundManager->IdleTask(); + if (ISoundManager::IsCreated()) + ISoundManager::GetSoundManager()->IdleTask(); ogl_WarnIfError(); @@ -204,19 +204,19 @@ ogl_WarnIfError(); // prepare before starting the renderer frame - if (g_Game && g_Game->IsGameStarted()) - g_Game->GetView()->BeginFrame(); + if (CGame::IsGameInitialised() && CGame::GetGame()->IsGameStarted()) + CGame::GetGame()->GetView()->BeginFrame(); - if (g_Game) - g_Renderer.SetSimulation(g_Game->GetSimulation2()); + if (CGame::IsGameInitialised()) + g_Renderer.SetSimulation(CGame::GetGame()->GetSimulation2()); // start new frame g_Renderer.BeginFrame(); ogl_WarnIfError(); - if (g_Game && g_Game->IsGameStarted()) - g_Game->GetView()->Render(); + if (CGame::GetGame() && CGame::GetGame()->IsGameStarted()) + CGame::GetGame()->GetView()->Render(); ogl_WarnIfError(); @@ -229,8 +229,8 @@ ogl_WarnIfError(); } - if (g_Game && g_Game->IsGameStarted()) - g_Game->GetView()->GetCinema()->Render(); + if (CGame::IsGameInitialised() && CGame::GetGame()->IsGameStarted()) + CGame::GetGame()->GetView()->GetCinema()->Render(); ogl_WarnIfError(); @@ -500,7 +500,7 @@ void InitPsAutostart(bool networked, JS::HandleValue attrs) { // The GUI has not been initialized yet, so use the simulation scriptinterface for this variable - ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); + ScriptInterface& scriptInterface = CGame::GetGame()->GetSimulation2()->GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -511,7 +511,7 @@ { JS::RootedValue localPlayer(cx); scriptInterface.Eval("({})", &localPlayer); - scriptInterface.SetProperty(localPlayer, "player", g_Game->GetPlayerID()); + scriptInterface.SetProperty(localPlayer, "player", CGame::GetGame()->GetPlayerID()); scriptInterface.SetProperty(playerAssignments, "local", localPlayer); } @@ -678,15 +678,15 @@ void EndGame() { - const bool nonVisual = g_Game && g_Game->IsGraphicsDisabled(); + const bool nonVisual = CGame::IsGameInitialised() && CGame::GetGame()->IsGraphicsDisabled(); - if (g_Game && g_Game->IsGameStarted() && !g_Game->IsVisualReplay() && + if (CGame::IsGameInitialised() && CGame::GetGame()->IsGameStarted() && !CGame::GetGame()->IsVisualReplay() && g_AtlasGameLoop && !g_AtlasGameLoop->running && !nonVisual) VisualReplay::SaveReplayMetadata(g_GUI->GetActiveGUI()->GetScriptInterface().get()); SAFE_DELETE(g_NetClient); SAFE_DELETE(g_NetServer); - SAFE_DELETE(g_Game); + CGame::DeInitGame(); if (!nonVisual) { @@ -697,7 +697,7 @@ void Shutdown(int flags) { - const bool nonVisual = g_Game && g_Game->IsGraphicsDisabled(); + const bool nonVisual = CGame::GetGame() && CGame::GetGame()->IsGraphicsDisabled(); if ((flags & SHUTDOWN_FROM_CONFIG)) goto from_config; @@ -1240,9 +1240,10 @@ return false; const bool nonVisual = args.Has("autostart-nonvisual"); - g_Game = new CGame(nonVisual, !nonVisual); + + CGame::InitGame(nonVisual, !nonVisual); - ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); + ScriptInterface& scriptInterface = CGame::GetGame()->GetSimulation2()->GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -1581,7 +1582,7 @@ bool ok = g_NetServer->SetupConnection(PS_DEFAULT_PORT); ENSURE(ok); - g_NetClient = new CNetClient(g_Game, true); + g_NetClient = new CNetClient(CGame::GetGame(), true); g_NetClient->SetUserName(userName); g_NetClient->SetupConnection("127.0.0.1", PS_DEFAULT_PORT); } @@ -1589,7 +1590,7 @@ { InitPsAutostart(true, attrs); - g_NetClient = new CNetClient(g_Game, false); + g_NetClient = new CNetClient(CGame::GetGame(), false); g_NetClient->SetUserName(userName); CStr ip = args.Get("autostart-client"); @@ -1601,15 +1602,15 @@ } else { - g_Game->SetPlayerID(args.Has("autostart-player") ? args.Get("autostart-player").ToInt() : 1); + CGame::GetGame()->SetPlayerID(args.Has("autostart-player") ? args.Get("autostart-player").ToInt() : 1); - g_Game->StartGame(&attrs, ""); + CGame::GetGame()->StartGame(&attrs, ""); if (nonVisual) { // TODO: Non progressive load can fail - need a decent way to handle this LDR_NonprogressiveLoad(); - ENSURE(g_Game->ReallyStartGame() == PSRETURN_OK); + ENSURE(CGame::GetGame()->ReallyStartGame() == PSRETURN_OK); } else InitPsAutostart(false, attrs); @@ -1623,14 +1624,14 @@ if (!FileExists(OsPath(replayFile))) return false; - g_Game = new CGame(false, false); - g_Game->SetPlayerID(-1); - g_Game->StartVisualReplay(replayFile); + CGame::InitGame(false, false); + CGame::GetGame()->SetPlayerID(-1); + CGame::GetGame()->StartVisualReplay(replayFile); - ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); + ScriptInterface& scriptInterface = CGame::GetGame()->GetSimulation2()->GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); - JS::RootedValue attrs(cx, g_Game->GetSimulation2()->GetInitAttributes()); + JS::RootedValue attrs(cx, CGame::GetGame()->GetSimulation2()->GetInitAttributes()); InitPsAutostart(false, attrs); Index: source/ps/Replay.cpp =================================================================== --- source/ps/Replay.cpp +++ source/ps/Replay.cpp @@ -183,13 +183,13 @@ Mod::CacheEnabledModVersions(g_ScriptRuntime); - g_Game = new CGame(true, false); + CGame::InitGame(true, false); if (serializationtest) - g_Game->GetSimulation2()->EnableSerializationTest(); + CGame::GetGame()->GetSimulation2()->EnableSerializationTest(); if (rejointestturn > 0) - g_Game->GetSimulation2()->EnableRejoinTest(rejointestturn); + CGame::GetGame()->GetSimulation2()->EnableRejoinTest(rejointestturn); if (ooslog) - g_Game->GetSimulation2()->EnableOOSLog(); + CGame::GetGame()->GetSimulation2()->EnableOOSLog(); // Need some stuff for terrain movement costs: // (TODO: this ought to be independent of any graphics code) @@ -204,7 +204,7 @@ u32 turnLength = 0; { - JSContext* cx = g_Game->GetSimulation2()->GetScriptInterface().GetContext(); + JSContext* cx = CGame::GetGame()->GetSimulation2()->GetScriptInterface().GetContext(); JSAutoRequest rq(cx); std::string type; @@ -215,16 +215,16 @@ std::string line; std::getline(*m_Stream, line); JS::RootedValue attribs(cx); - ENSURE(g_Game->GetSimulation2()->GetScriptInterface().ParseJSON(line, &attribs)); + ENSURE(CGame::GetGame()->GetSimulation2()->GetScriptInterface().ParseJSON(line, &attribs)); - CheckReplayMods(g_Game->GetSimulation2()->GetScriptInterface(), attribs); + CheckReplayMods(CGame::GetGame()->GetSimulation2()->GetScriptInterface(), attribs); - g_Game->StartGame(&attribs, ""); + CGame::GetGame()->StartGame(&attribs, ""); // TODO: Non progressive load can fail - need a decent way to handle this LDR_NonprogressiveLoad(); - PSRETURN ret = g_Game->ReallyStartGame(); + PSRETURN ret = CGame::GetGame()->ReallyStartGame(); ENSURE(ret == PSRETURN_OK); } else if (type == "turn") @@ -240,8 +240,8 @@ std::string line; std::getline(*m_Stream, line); JS::RootedValue data(cx); - g_Game->GetSimulation2()->GetScriptInterface().ParseJSON(line, &data); - g_Game->GetSimulation2()->GetScriptInterface().FreezeObject(data, true); + CGame::GetGame()->GetSimulation2()->GetScriptInterface().ParseJSON(line, &data); + CGame::GetGame()->GetSimulation2()->GetScriptInterface().FreezeObject(data, true); commands.emplace_back(SimulationCommand(player, cx, data)); } else if (type == "hash" || type == "hash-quick") @@ -258,7 +258,7 @@ g_Profiler2.IncrementFrameNumber(); PROFILE2_ATTR("%d", g_Profiler2.GetFrameNumber()); - g_Game->GetSimulation2()->Update(turnLength, commands); + CGame::GetGame()->GetSimulation2()->Update(turnLength, commands); commands.clear(); } @@ -277,12 +277,12 @@ g_Profiler2.SaveToFile(); std::string hash; - bool ok = g_Game->GetSimulation2()->ComputeStateHash(hash, false); + bool ok = CGame::GetGame()->GetSimulation2()->ComputeStateHash(hash, false); ENSURE(ok); debug_printf("# Final state: %s\n", Hexify(hash).c_str()); timer_DisplayClientTotals(); - SAFE_DELETE(g_Game); + CGame::DeInitGame(); // Must be explicitly destructed here to avoid callbacks from the JSAPI trying to use g_Profiler2 when // it's already destructed. @@ -303,7 +303,7 @@ return; std::string hash; - ENSURE(g_Game->GetSimulation2()->ComputeStateHash(hash, quick)); + ENSURE(CGame::GetGame()->GetSimulation2()->ComputeStateHash(hash, quick)); std::string hexHash = Hexify(hash); Index: source/ps/SavedGame.cpp =================================================================== --- source/ps/SavedGame.cpp +++ source/ps/SavedGame.cpp @@ -85,7 +85,7 @@ simulation.GetScriptInterface().SetProperty(metadata, "engine_version", std::string(engine_version)); simulation.GetScriptInterface().SetProperty(metadata, "mods", mods); simulation.GetScriptInterface().SetProperty(metadata, "time", (double)now); - simulation.GetScriptInterface().SetProperty(metadata, "playerID", g_Game->GetPlayerID()); + simulation.GetScriptInterface().SetProperty(metadata, "playerID", CGame::GetGame()->GetPlayerID()); simulation.GetScriptInterface().SetProperty(metadata, "initAttributes", initAttributes); JS::RootedValue guiMetadata(cx); @@ -94,12 +94,12 @@ // get some camera data JS::RootedValue cameraMetadata(cx); simulation.GetScriptInterface().Eval("({})", &cameraMetadata); - simulation.GetScriptInterface().SetProperty(cameraMetadata, "PosX", g_Game->GetView()->GetCameraPosX()); - simulation.GetScriptInterface().SetProperty(cameraMetadata, "PosY", g_Game->GetView()->GetCameraPosY()); - simulation.GetScriptInterface().SetProperty(cameraMetadata, "PosZ", g_Game->GetView()->GetCameraPosZ()); - simulation.GetScriptInterface().SetProperty(cameraMetadata, "RotX", g_Game->GetView()->GetCameraRotX()); - simulation.GetScriptInterface().SetProperty(cameraMetadata, "RotY", g_Game->GetView()->GetCameraRotY()); - simulation.GetScriptInterface().SetProperty(cameraMetadata, "Zoom", g_Game->GetView()->GetCameraZoom()); + simulation.GetScriptInterface().SetProperty(cameraMetadata, "PosX", CGame::GetGame()->GetView()->GetCameraPosX()); + simulation.GetScriptInterface().SetProperty(cameraMetadata, "PosY", CGame::GetGame()->GetView()->GetCameraPosY()); + simulation.GetScriptInterface().SetProperty(cameraMetadata, "PosZ", CGame::GetGame()->GetView()->GetCameraPosZ()); + simulation.GetScriptInterface().SetProperty(cameraMetadata, "RotX", CGame::GetGame()->GetView()->GetCameraRotX()); + simulation.GetScriptInterface().SetProperty(cameraMetadata, "RotY", CGame::GetGame()->GetView()->GetCameraRotY()); + simulation.GetScriptInterface().SetProperty(cameraMetadata, "Zoom", CGame::GetGame()->GetView()->GetCameraZoom()); simulation.GetScriptInterface().SetProperty(guiMetadata, "camera", cameraMetadata); simulation.GetScriptInterface().SetProperty(metadata, "gui", guiMetadata); Index: source/ps/TouchInput.cpp =================================================================== --- source/ps/TouchInput.cpp +++ source/ps/TouchInput.cpp @@ -128,7 +128,7 @@ { m_State = STATE_PANNING; - CCamera& camera = *(g_Game->GetView()->GetCamera()); + CCamera& camera = *(CGame::GetGame()->GetView()->GetCamera()); m_PanFocus = camera.GetWorldCoordinates(m_FirstTouchPos.X, m_FirstTouchPos.Y, true); m_PanDist = (m_PanFocus - camera.GetOrientation().GetTranslation()).Y; } @@ -136,7 +136,7 @@ if (m_State == STATE_PANNING && id == 0) { - CCamera& camera = *(g_Game->GetView()->GetCamera()); + CCamera& camera = *(CGame::GetGame()->GetView()->GetCamera()); CVector3D origin, dir; camera.BuildCameraRay(x, y, origin, dir); dir *= m_PanDist / dir.Y; @@ -150,7 +150,7 @@ float newDist = (m_Pos[id] - m_Pos[1 - id]).Length(); float zoomDist = (newDist - oldDist) * -0.005f * m_PanDist; - CCamera& camera = *(g_Game->GetView()->GetCamera()); + CCamera& camera = *(CGame::GetGame()->GetView()->GetCamera()); CVector3D origin, dir; camera.BuildCameraRay(m_Pos[0].X, m_Pos[0].Y, origin, dir); dir *= zoomDist; Index: source/ps/Util.cpp =================================================================== --- source/ps/Util.cpp +++ source/ps/Util.cpp @@ -292,7 +292,7 @@ void WriteBigScreenshot(const VfsPath& extension, int tiles) { // If the game hasn't started yet then use WriteScreenshot to generate the image. - if(g_Game == NULL){ WriteScreenshot(L".bmp"); return; } + if(!CGame::IsGameInitialised()){ WriteScreenshot(L".bmp"); return; } // get next available numbered filename // note: %04d -> always 4 digits, so sorting by filename works correctly. @@ -346,8 +346,8 @@ { g_Renderer.Resize(tile_w, tile_h); SViewPort vp = { 0, 0, tile_w, tile_h }; - g_Game->GetView()->GetCamera()->SetViewPort(vp); - g_Game->GetView()->SetCameraProjection(); + CGame::GetGame()->GetView()->GetCamera()->SetViewPort(vp); + CGame::GetGame()->GetView()->SetCameraProjection(); } #if !CONFIG2_GLES @@ -372,7 +372,7 @@ for (int tile_x = 0; tile_x < tiles; ++tile_x) { // Adjust the camera to render the appropriate region - g_Game->GetView()->GetCamera()->SetProjectionTile(tiles, tile_x, tile_y); + CGame::GetGame()->GetView()->GetCamera()->SetProjectionTile(tiles, tile_x, tile_y); RenderLogger(false); RenderGui(false); @@ -404,9 +404,9 @@ { g_Renderer.Resize(g_xres, g_yres); SViewPort vp = { 0, 0, g_xres, g_yres }; - g_Game->GetView()->GetCamera()->SetViewPort(vp); - g_Game->GetView()->SetCameraProjection(); - g_Game->GetView()->GetCamera()->SetProjectionTile(1, 0, 0); + CGame::GetGame()->GetView()->GetCamera()->SetViewPort(vp); + CGame::GetGame()->GetView()->SetCameraProjection(); + CGame::GetGame()->GetView()->GetCamera()->SetProjectionTile(1, 0, 0); } if (tex_write(&t, filename) == INFO::OK) Index: source/ps/VideoMode.cpp =================================================================== --- source/ps/VideoMode.cpp +++ source/ps/VideoMode.cpp @@ -437,8 +437,8 @@ if (g_Console) g_Console->UpdateScreenSize(w, h); - if (g_Game) - g_Game->GetView()->SetViewport(vp); + if (CGame::IsGameInitialised()) + CGame::GetGame()->GetView()->SetViewport(vp); } int CVideoMode::GetBestBPP() Index: source/ps/VisualReplay.cpp =================================================================== --- source/ps/VisualReplay.cpp +++ source/ps/VisualReplay.cpp @@ -53,15 +53,15 @@ { ENSURE(!g_NetServer); ENSURE(!g_NetClient); - ENSURE(!g_Game); + ENSURE(!CGame::IsGameInitialised()); const OsPath replayFile = VisualReplay::GetDirectoryName() / directory / L"commands.txt"; if (!FileExists(replayFile)) return false; - g_Game = new CGame(false, false); - return g_Game->StartVisualReplay(replayFile); + CGame::InitGame(false, false); + return CGame::GetGame()->StartVisualReplay(replayFile); } bool VisualReplay::ReadCacheFile(const ScriptInterface& scriptInterface, JS::MutableHandleObject cachedReplaysObject) @@ -472,7 +472,7 @@ } // Get the directory of the currently active replay - const OsPath fileName = g_Game->GetReplayLogger().GetDirectory() / L"metadata.json"; + const OsPath fileName = CGame::GetGame()->GetReplayLogger().GetDirectory() / L"metadata.json"; CreateDirectories(fileName.Parent(), 0700); std::ofstream stream (OsString(fileName).c_str(), std::ofstream::out | std::ofstream::trunc); Index: source/ps/scripting/JSInterface_Game.cpp =================================================================== --- source/ps/scripting/JSInterface_Game.cpp +++ source/ps/scripting/JSInterface_Game.cpp @@ -37,20 +37,20 @@ { ENSURE(!g_NetServer); ENSURE(!g_NetClient); - ENSURE(!g_Game); + ENSURE(!CGame::IsGameInitialised()); - g_Game = new CGame(); + CGame::InitGame(); // Convert from GUI script context to sim script context - CSimulation2* sim = g_Game->GetSimulation2(); + CSimulation2* sim = CGame::GetGame()->GetSimulation2(); JSContext* cxSim = sim->GetScriptInterface().GetContext(); JSAutoRequest rqSim(cxSim); JS::RootedValue gameAttribs(cxSim, sim->GetScriptInterface().CloneValueFromOtherContext(*(pCxPrivate->pScriptInterface), attribs)); - g_Game->SetPlayerID(playerID); - g_Game->StartGame(&gameAttribs, ""); + CGame::GetGame()->SetPlayerID(playerID); + CGame::GetGame()->StartGame(&gameAttribs, ""); } void JSI_Game::Script_EndGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) @@ -60,62 +60,62 @@ int JSI_Game::GetPlayerID(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - if (!g_Game) + if (!CGame::IsGameInitialised()) return -1; - return g_Game->GetPlayerID(); + return CGame::GetGame()->GetPlayerID(); } void JSI_Game::SetPlayerID(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int id) { - if (!g_Game) + if (!CGame::IsGameInitialised()) return; - g_Game->SetPlayerID(id); + CGame::GetGame()->SetPlayerID(id); } void JSI_Game::SetViewedPlayer(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int id) { - if (!g_Game) + if (!CGame::IsGameInitialised()) return; - g_Game->SetViewedPlayerID(id); + CGame::GetGame()->SetViewedPlayerID(id); } float JSI_Game::GetSimRate(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - return g_Game->GetSimRate(); + return CGame::GetGame()->GetSimRate(); } void JSI_Game::SetSimRate(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), float rate) { - g_Game->SetSimRate(rate); + CGame::GetGame()->SetSimRate(rate); } bool JSI_Game::IsPaused(ScriptInterface::CxPrivate* pCxPrivate) { - if (!g_Game) + if (!CGame::IsGameInitialised()) { JS_ReportError(pCxPrivate->pScriptInterface->GetContext(), "Game is not started"); return false; } - return g_Game->m_Paused; + return CGame::GetGame()->m_Paused; } void JSI_Game::SetPaused(ScriptInterface::CxPrivate* pCxPrivate, bool pause, bool sendMessage) { - if (!g_Game) + if (!CGame::IsGameInitialised()) { JS_ReportError(pCxPrivate->pScriptInterface->GetContext(), "Game is not started"); return; } - g_Game->m_Paused = pause; + CGame::GetGame()->m_Paused = pause; #if CONFIG2_AUDIO - if (g_SoundManager) - g_SoundManager->Pause(pause); + if (ISoundManager::IsCreated()) + ISoundManager::GetSoundManager()->Pause(pause); #endif if (g_NetClient && sendMessage) @@ -124,37 +124,37 @@ bool JSI_Game::IsVisualReplay(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - if (!g_Game) + if (!CGame::IsGameInitialised()) return false; - return g_Game->IsVisualReplay(); + return CGame::GetGame()->IsVisualReplay(); } std::wstring JSI_Game::GetCurrentReplayDirectory(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - if (!g_Game) + if (!CGame::IsGameInitialised()) return std::wstring(); - if (g_Game->IsVisualReplay()) - return g_Game->GetReplayPath().Parent().Filename().string(); + if (CGame::GetGame()->IsVisualReplay()) + return CGame::GetGame()->GetReplayPath().Parent().Filename().string(); - return g_Game->GetReplayLogger().GetDirectory().Filename().string(); + return CGame::GetGame()->GetReplayLogger().GetDirectory().Filename().string(); } void JSI_Game::EnableTimeWarpRecording(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), unsigned int numTurns) { - g_Game->GetTurnManager()->EnableTimeWarpRecording(numTurns); + CGame::GetGame()->GetTurnManager()->EnableTimeWarpRecording(numTurns); } void JSI_Game::RewindTimeWarp(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - g_Game->GetTurnManager()->RewindTimeWarp(); + CGame::GetGame()->GetTurnManager()->RewindTimeWarp(); } void JSI_Game::DumpTerrainMipmap(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { VfsPath filename(L"screenshots/terrainmipmap.png"); - g_Game->GetWorld()->GetTerrain()->GetHeightMipmap().DumpToDisk(filename); + CGame::GetGame()->GetWorld()->GetTerrain()->GetHeightMipmap().DumpToDisk(filename); OsPath realPath; g_VFS->GetRealPath(filename, realPath); LOGMESSAGERENDER("Terrain mipmap written to '%s'", realPath.string8()); Index: source/ps/scripting/JSInterface_SavedGame.cpp =================================================================== --- source/ps/scripting/JSInterface_SavedGame.cpp +++ source/ps/scripting/JSInterface_SavedGame.cpp @@ -41,25 +41,25 @@ void JSI_SavedGame::SaveGame(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename, const std::wstring& description, JS::HandleValue GUIMetadata) { shared_ptr GUIMetadataClone = pCxPrivate->pScriptInterface->WriteStructuredClone(GUIMetadata); - if (SavedGames::Save(filename, description, *g_Game->GetSimulation2(), GUIMetadataClone) < 0) + if (SavedGames::Save(filename, description, *CGame::GetGame()->GetSimulation2(), GUIMetadataClone) < 0) LOGERROR("Failed to save game"); } void JSI_SavedGame::SaveGamePrefix(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& prefix, const std::wstring& description, JS::HandleValue GUIMetadata) { shared_ptr GUIMetadataClone = pCxPrivate->pScriptInterface->WriteStructuredClone(GUIMetadata); - if (SavedGames::SavePrefix(prefix, description, *g_Game->GetSimulation2(), GUIMetadataClone) < 0) + if (SavedGames::SavePrefix(prefix, description, *CGame::GetGame()->GetSimulation2(), GUIMetadataClone) < 0) LOGERROR("Failed to save game"); } void JSI_SavedGame::QuickSave(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - g_Game->GetTurnManager()->QuickSave(); + CGame::GetGame()->GetTurnManager()->QuickSave(); } void JSI_SavedGame::QuickLoad(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - g_Game->GetTurnManager()->QuickLoad(); + CGame::GetGame()->GetTurnManager()->QuickLoad(); } JS::Value JSI_SavedGame::StartSavedGame(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& name) @@ -73,8 +73,7 @@ ENSURE(!g_NetServer); ENSURE(!g_NetClient); - - ENSURE(!g_Game); +// ENSURE(!CGame::IsGameInitialised()); // Load the saved game data from disk JS::RootedValue guiContextMetadata(cxGui); @@ -83,10 +82,10 @@ if (err < 0) return JS::UndefinedValue(); - g_Game = new CGame(); + CGame::InitGame(); { - CSimulation2* sim = g_Game->GetSimulation2(); + CSimulation2* sim = CGame::GetGame()->GetSimulation2(); JSContext* cxGame = sim->GetScriptInterface().GetContext(); JSAutoRequest rq(cxGame); @@ -98,8 +97,8 @@ int playerID; sim->GetScriptInterface().GetProperty(gameContextMetadata, "playerID", playerID); - g_Game->SetPlayerID(playerID); - g_Game->StartGame(&gameInitAttributes, savedState); + CGame::GetGame()->SetPlayerID(playerID); + CGame::GetGame()->StartGame(&gameInitAttributes, savedState); } return guiContextMetadata; Index: source/renderer/PatchRData.cpp =================================================================== --- source/renderer/PatchRData.cpp +++ source/renderer/PatchRData.cpp @@ -1248,7 +1248,7 @@ void CPatchRData::RenderPriorities(CTextRenderer& textRenderer) { CTerrain* terrain = m_Patch->m_Parent; - CCamera* camera = g_Game->GetView()->GetCamera(); + CCamera* camera = CGame::GetGame()->GetView()->GetCamera(); for (ssize_t j = 0; j < PATCH_SIZE; ++j) { Index: source/renderer/PostprocManager.cpp =================================================================== --- source/renderer/PostprocManager.cpp +++ source/renderer/PostprocManager.cpp @@ -430,8 +430,8 @@ shader->Uniform(str_width, m_Width); shader->Uniform(str_height, m_Height); - shader->Uniform(str_zNear, g_Game->GetView()->GetNear()); - shader->Uniform(str_zFar, g_Game->GetView()->GetFar()); + shader->Uniform(str_zNear, CGame::GetGame()->GetView()->GetNear()); + shader->Uniform(str_zFar, CGame::GetGame()->GetView()->GetFar()); shader->Uniform(str_brightness, g_LightEnv.m_Brightness); shader->Uniform(str_hdr, g_LightEnv.m_Contrast); Index: source/renderer/RenderModifiers.cpp =================================================================== --- source/renderer/RenderModifiers.cpp +++ source/renderer/RenderModifiers.cpp @@ -117,5 +117,5 @@ shader->Uniform(m_BindingShadingColor, model->GetShadingColor()); if (m_BindingPlayerColor.Active()) - shader->Uniform(m_BindingPlayerColor, g_Game->GetPlayerColor(model->GetPlayerID())); + shader->Uniform(m_BindingPlayerColor, CGame::GetGame()->GetPlayerColor(model->GetPlayerID())); } Index: source/renderer/Renderer.cpp =================================================================== --- source/renderer/Renderer.cpp +++ source/renderer/Renderer.cpp @@ -833,8 +833,8 @@ RecomputeSystemShaderDefines(); // We might need to regenerate some render data after changing path - if (g_Game) - g_Game->GetWorld()->GetTerrain()->MakeDirty(RENDERDATA_UPDATE_COLOR); + if (CGame::IsGameInitialised()) + CGame::GetGame()->GetWorld()->GetTerrain()->MakeDirty(RENDERDATA_UPDATE_COLOR); } @@ -1550,7 +1550,7 @@ ogl_WarnIfError(); // render water - if (m_WaterManager->m_RenderWater && g_Game && waterScissor.GetVolume() > 0) + if (m_WaterManager->m_RenderWater && CGame::GetGame() && waterScissor.GetVolume() > 0) { // render transparent stuff, but only the solid parts that can occlude block water RenderTransparentModels(context, cullGroup, TRANSPARENT_OPAQUE, false); Index: source/renderer/SkyManager.cpp =================================================================== --- source/renderer/SkyManager.cpp +++ source/renderer/SkyManager.cpp @@ -242,7 +242,7 @@ glPushMatrix(); // Translate so we are at the center of the map. - ssize_t mapSize = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); + ssize_t mapSize = CGame::GetGame()->GetWorld()->GetTerrain()->GetVerticesPerSide(); glTranslatef(mapSize*(TERRAIN_TILE_SIZE/2.0f), m_HorizonHeight, mapSize*(TERRAIN_TILE_SIZE/2.0f) ); // Rotate so that the "left" face, which contains the brightest part of each Index: source/renderer/TerrainOverlay.cpp =================================================================== --- source/renderer/TerrainOverlay.cpp +++ source/renderer/TerrainOverlay.cpp @@ -269,7 +269,7 @@ void TerrainTextureOverlay::RenderAfterWater(int cullGroup) { - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); + CTerrain* terrain = CGame::GetGame()->GetWorld()->GetTerrain(); ssize_t w = (ssize_t)(terrain->GetTilesPerSide() * m_TexelsPerTile); ssize_t h = (ssize_t)(terrain->GetTilesPerSide() * m_TexelsPerTile); Index: source/renderer/TerrainRenderer.cpp =================================================================== --- source/renderer/TerrainRenderer.cpp +++ source/renderer/TerrainRenderer.cpp @@ -839,7 +839,7 @@ PROFILE3_GPU("simple water"); WaterManager* WaterMgr = g_Renderer.GetWaterManager(); - CLOSTexture& losTexture = g_Game->GetView()->GetLOSTexture(); + CLOSTexture& losTexture = CGame::GetGame()->GetView()->GetLOSTexture(); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); Index: source/renderer/WaterManager.cpp =================================================================== --- source/renderer/WaterManager.cpp +++ source/renderer/WaterManager.cpp @@ -417,7 +417,7 @@ // Calculate our binary heightmap from the terrain heightmap. void WaterManager::RecomputeDistanceHeightmap() { - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); + CTerrain* terrain = CGame::GetGame()->GetWorld()->GetTerrain(); if (!terrain || !terrain->GetHeightMap()) return; @@ -484,7 +484,7 @@ void WaterManager::CreateWaveMeshes() { size_t SideSize = m_MapSize*2; - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); + CTerrain* terrain = CGame::GetGame()->GetWorld()->GetTerrain(); if (!terrain || !terrain->GetHeightMap()) return; @@ -948,7 +948,7 @@ // Calculate The blurred normal map to get an idea of where water ought to go. void WaterManager::RecomputeBlurredNormalMap() { - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); + CTerrain* terrain = CGame::GetGame()->GetWorld()->GetTerrain(); if (!terrain || !terrain->GetHeightMap()) return; @@ -1022,7 +1022,7 @@ if (m_WindStrength == NULL) m_WindStrength = new float[m_MapSize*m_MapSize]; - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); + CTerrain* terrain = CGame::GetGame()->GetWorld()->GetTerrain(); if (!terrain || !terrain->GetHeightMap()) return; Index: source/simulation2/components/CCmpCommandQueue.cpp =================================================================== --- source/simulation2/components/CCmpCommandQueue.cpp +++ source/simulation2/components/CCmpCommandQueue.cpp @@ -99,8 +99,8 @@ PROFILE2_ATTR("command: %s", GetSimContext().GetScriptInterface().StringifyJSON(&cmd, false).c_str()); // TODO: would be nicer to not use globals - if (g_Game && g_Game->GetTurnManager()) - g_Game->GetTurnManager()->PostCommand(cmd); + if (CGame::IsGameInitialised() && CGame::GetGame()->GetTurnManager()) + CGame::GetGame()->GetTurnManager()->PostCommand(cmd); } virtual void FlushTurn(const std::vector& commands) Index: source/simulation2/components/CCmpSoundManager.cpp =================================================================== --- source/simulation2/components/CCmpSoundManager.cpp +++ source/simulation2/components/CCmpSoundManager.cpp @@ -62,7 +62,7 @@ virtual void PlaySoundGroup(const std::wstring& name, entity_id_t source) { - if (!g_SoundManager || (source == INVALID_ENTITY)) + if (!ISoundManager::IsCreated() || (source == INVALID_ENTITY)) return; int currentPlayer = GetSimContext().GetCurrentDisplayedPlayer(); @@ -81,21 +81,21 @@ playerOwned = cmpOwnership->GetOwner() == currentPlayer; CVector3D sourcePos = CVector3D(cmpPosition->GetPosition()); - g_SoundManager->PlayAsGroup(name, sourcePos, source, playerOwned); + ISoundManager::GetSoundManager()->PlayAsGroup(name, sourcePos, source, playerOwned); } virtual void PlaySoundGroupAtPosition(const std::wstring& name, const CFixedVector3D& sourcePos) { - if (!g_SoundManager) + if (!ISoundManager::IsCreated()) return; - g_SoundManager->PlayAsGroup(name, CVector3D(sourcePos), INVALID_ENTITY, false); + ISoundManager::GetSoundManager()->PlayAsGroup(name, CVector3D(sourcePos), INVALID_ENTITY, false); } virtual void StopMusic() { - if (!g_SoundManager) + if (!ISoundManager::IsCreated()) return; - g_SoundManager->Pause(true); + ISoundManager::GetSoundManager()->Pause(true); } }; Index: source/simulation2/scripting/JSInterface_Simulation.cpp =================================================================== --- source/simulation2/scripting/JSInterface_Simulation.cpp +++ source/simulation2/scripting/JSInterface_Simulation.cpp @@ -36,26 +36,26 @@ JS::Value JSI_Simulation::GetInitAttributes(ScriptInterface::CxPrivate* pCxPrivate) { - if (!g_Game) + if (!CGame::IsGameInitialised()) return JS::UndefinedValue(); - JSContext* cx = g_Game->GetSimulation2()->GetScriptInterface().GetContext(); + JSContext* cx = CGame::GetGame()->GetSimulation2()->GetScriptInterface().GetContext(); JSAutoRequest rq(cx); JS::RootedValue initAttribs(cx); - g_Game->GetSimulation2()->GetInitAttributes(&initAttribs); + CGame::GetGame()->GetSimulation2()->GetInitAttributes(&initAttribs); return pCxPrivate->pScriptInterface->CloneValueFromOtherContext( - g_Game->GetSimulation2()->GetScriptInterface(), + CGame::GetGame()->GetSimulation2()->GetScriptInterface(), initAttribs); } JS::Value JSI_Simulation::GuiInterfaceCall(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& name, JS::HandleValue data) { - if (!g_Game) + if (!CGame::IsGameInitialised()) return JS::UndefinedValue(); - CSimulation2* sim = g_Game->GetSimulation2(); + CSimulation2* sim = CGame::GetGame()->GetSimulation2(); ENSURE(sim); CmpPtr cmpGuiInterface(*sim, SYSTEM_ENTITY); @@ -66,17 +66,17 @@ JSAutoRequest rqSim(cxSim); JS::RootedValue arg(cxSim, sim->GetScriptInterface().CloneValueFromOtherContext(*(pCxPrivate->pScriptInterface), data)); JS::RootedValue ret(cxSim); - cmpGuiInterface->ScriptCall(g_Game->GetViewedPlayerID(), name, arg, &ret); + cmpGuiInterface->ScriptCall(CGame::GetGame()->GetViewedPlayerID(), name, arg, &ret); return pCxPrivate->pScriptInterface->CloneValueFromOtherContext(sim->GetScriptInterface(), ret); } void JSI_Simulation::PostNetworkCommand(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue cmd) { - if (!g_Game) + if (!CGame::IsGameInitialised()) return; - CSimulation2* sim = g_Game->GetSimulation2(); + CSimulation2* sim = CGame::GetGame()->GetSimulation2(); ENSURE(sim); CmpPtr cmpCommandQueue(*sim, SYSTEM_ENTITY); @@ -94,32 +94,32 @@ { OsPath path = psLogDir()/"sim_dump.txt"; std::ofstream file (OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc); - g_Game->GetSimulation2()->DumpDebugState(file); + CGame::GetGame()->GetSimulation2()->DumpDebugState(file); } entity_id_t JSI_Simulation::PickEntityAtPoint(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int x, int y) { - return EntitySelection::PickEntityAtPoint(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), x, y, g_Game->GetViewedPlayerID(), false); + return EntitySelection::PickEntityAtPoint(*CGame::GetGame()->GetSimulation2(), *CGame::GetGame()->GetView()->GetCamera(), x, y, CGame::GetGame()->GetViewedPlayerID(), false); } std::vector JSI_Simulation::PickPlayerEntitiesInRect(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int x0, int y0, int x1, int y1, int player) { - return EntitySelection::PickEntitiesInRect(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), x0, y0, x1, y1, player, false); + return EntitySelection::PickEntitiesInRect(*CGame::GetGame()->GetSimulation2(), *CGame::GetGame()->GetView()->GetCamera(), x0, y0, x1, y1, player, false); } std::vector JSI_Simulation::PickPlayerEntitiesOnScreen(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int player) { - return EntitySelection::PickEntitiesInRect(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), 0, 0, g_xres, g_yres, player, false); + return EntitySelection::PickEntitiesInRect(*CGame::GetGame()->GetSimulation2(), *CGame::GetGame()->GetView()->GetCamera(), 0, 0, g_xres, g_yres, player, false); } std::vector JSI_Simulation::PickNonGaiaEntitiesOnScreen(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - return EntitySelection::PickNonGaiaEntitiesInRect(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), 0, 0, g_xres, g_yres, false); + return EntitySelection::PickNonGaiaEntitiesInRect(*CGame::GetGame()->GetSimulation2(), *CGame::GetGame()->GetView()->GetCamera(), 0, 0, g_xres, g_yres, false); } std::vector JSI_Simulation::PickSimilarPlayerEntities(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& templateName, bool includeOffScreen, bool matchRank, bool allowFoundations) { - return EntitySelection::PickSimilarEntities(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), templateName, g_Game->GetViewedPlayerID(), includeOffScreen, matchRank, false, allowFoundations); + return EntitySelection::PickSimilarEntities(*CGame::GetGame()->GetSimulation2(), *CGame::GetGame()->GetView()->GetCamera(), templateName, CGame::GetGame()->GetViewedPlayerID(), includeOffScreen, matchRank, false, allowFoundations); } JS::Value JSI_Simulation::GetAIs(ScriptInterface::CxPrivate* pCxPrivate) Index: source/simulation2/system/SimContext.h =================================================================== --- source/simulation2/system/SimContext.h +++ source/simulation2/system/SimContext.h @@ -50,7 +50,7 @@ /** * Returns the player ID that the current display is being rendered for. - * Currently relies on g_Game being initialised (evil globals...) + * Currently relies on CGame::GetGame() being initialised (evil globals...) */ int GetCurrentDisplayedPlayer() const; Index: source/simulation2/system/SimContext.cpp =================================================================== --- source/simulation2/system/SimContext.cpp +++ source/simulation2/system/SimContext.cpp @@ -67,5 +67,5 @@ int CSimContext::GetCurrentDisplayedPlayer() const { - return g_Game ? g_Game->GetViewedPlayerID() : -1; + return CGame::GetGame()? CGame::GetGame()->GetViewedPlayerID() : -1; } Index: source/soundmanager/ISoundManager.h =================================================================== --- source/soundmanager/ISoundManager.h +++ source/soundmanager/ISoundManager.h @@ -26,11 +26,15 @@ class ISoundManager { +private: + static ISoundManager* s_SoundManager; public: virtual ~ISoundManager() {}; static void CreateSoundManager(); static void SetEnabled(bool doEnable); + static ISoundManager* GetSoundManager(); + static bool IsCreated(); static void CloseGame(); virtual void StartWorker() = 0; @@ -52,7 +56,5 @@ virtual bool InDistress() = 0; }; -extern ISoundManager* g_SoundManager; - #endif // INCLUDED_ISOUNDMANAGER_H Index: source/soundmanager/SoundManager.cpp =================================================================== --- source/soundmanager/SoundManager.cpp +++ source/soundmanager/SoundManager.cpp @@ -32,8 +32,6 @@ #include "ps/Profiler2.h" #include "ps/XML/Xeromyces.h" -ISoundManager* g_SoundManager = NULL; - #define SOURCE_NUM 64 #if CONFIG2_AUDIO @@ -122,7 +120,7 @@ return; int pauseTime = 500; - if (g_SoundManager->InDistress()) + if (ISoundManager::GetSoundManager()->InDistress()) pauseTime = 50; { @@ -181,26 +179,33 @@ CSoundManagerWorker(ISoundManager* UNUSED(other)){}; }; - +ISoundManager* ISoundManager::s_SoundManager = NULL; void ISoundManager::CreateSoundManager() { - if (!g_SoundManager) - { - g_SoundManager = new CSoundManager(); - g_SoundManager->StartWorker(); - } + if (s_SoundManager) + return; + + s_SoundManager = new CSoundManager(); + s_SoundManager->StartWorker(); } - void ISoundManager::SetEnabled(bool doEnable) { - if (g_SoundManager && !doEnable) - SAFE_DELETE(g_SoundManager); - else if (!g_SoundManager && doEnable) + if (s_SoundManager && !doEnable) + SAFE_DELETE(s_SoundManager); + else if (!s_SoundManager && doEnable) ISoundManager::CreateSoundManager(); } +ISoundManager* ISoundManager::GetSoundManager() +{ + return s_SoundManager; +} +bool ISoundManager::IsCreated() +{ + return s_SoundManager != NULL; +} void ISoundManager::CloseGame() { - if (CSoundManager* aSndMgr = (CSoundManager*)g_SoundManager) + if (CSoundManager* aSndMgr = (CSoundManager*)s_SoundManager) aSndMgr->SetAmbientItem(NULL); } Index: source/soundmanager/data/OggData.cpp =================================================================== --- source/soundmanager/data/OggData.cpp +++ source/soundmanager/data/OggData.cpp @@ -58,7 +58,7 @@ bool COggData::InitOggFile(const VfsPath& itemPath) { - CSoundManager* sndManager = (CSoundManager*)g_SoundManager; + CSoundManager* sndManager = (CSoundManager*)ISoundManager::GetSoundManager(); if (!sndManager) return false; @@ -119,7 +119,7 @@ int COggData::FetchDataIntoBuffer(int count, ALuint* buffers) { - CSoundManager* sndManager = (CSoundManager*)g_SoundManager; + CSoundManager* sndManager = (CSoundManager*)ISoundManager::GetSoundManager(); if (!sndManager) return 0; Index: source/soundmanager/items/CBufferItem.cpp =================================================================== --- source/soundmanager/items/CBufferItem.cpp +++ source/soundmanager/items/CBufferItem.cpp @@ -58,7 +58,7 @@ delete[] al_buf; } alSourcei(m_ALSource, AL_BUFFER, 0); - ((CSoundManager*)g_SoundManager)->ReleaseALSource(m_ALSource); + ((CSoundManager*)ISoundManager::GetSoundManager())->ReleaseALSource(m_ALSource); AL_CHECK; m_ALSource = 0; Index: source/soundmanager/items/CSoundBase.cpp =================================================================== --- source/soundmanager/items/CSoundBase.cpp +++ source/soundmanager/items/CSoundBase.cpp @@ -44,7 +44,7 @@ AL_CHECK; alSourcei(m_ALSource, AL_BUFFER, 0L); AL_CHECK; - ((CSoundManager*)g_SoundManager)->ReleaseALSource(m_ALSource); + ((CSoundManager*)ISoundManager::GetSoundManager())->ReleaseALSource(m_ALSource); AL_CHECK; m_ALSource = 0; } @@ -94,7 +94,7 @@ bool CSoundBase::InitOpenAL() { alGetError(); /* clear error */ - m_ALSource = ((CSoundManager*)g_SoundManager)->GetALSource( this ); + m_ALSource = ((CSoundManager*)ISoundManager::GetSoundManager())->GetALSource( this ); AL_CHECK; @@ -286,9 +286,9 @@ if (err != AL_NO_ERROR) { if (err == AL_INVALID) - ((CSoundManager*)g_SoundManager)->SetDistressThroughError(); + ((CSoundManager*)ISoundManager::GetSoundManager())->SetDistressThroughError(); else - ((CSoundManager*)g_SoundManager)->al_ReportError(err, __func__, __LINE__); + ((CSoundManager*)ISoundManager::GetSoundManager())->al_ReportError(err, __func__, __LINE__); } } } Index: source/soundmanager/items/CStreamItem.cpp =================================================================== --- source/soundmanager/items/CStreamItem.cpp +++ source/soundmanager/items/CStreamItem.cpp @@ -55,7 +55,7 @@ } alSourcei(m_ALSource, AL_BUFFER, 0); AL_CHECK; - ((CSoundManager*)g_SoundManager)->ReleaseALSource(m_ALSource); + ((CSoundManager*)ISoundManager::GetSoundManager())->ReleaseALSource(m_ALSource); AL_CHECK; m_ALSource = 0; } Index: source/soundmanager/scripting/JSInterface_Sound.cpp =================================================================== --- source/soundmanager/scripting/JSInterface_Sound.cpp +++ source/soundmanager/scripting/JSInterface_Sound.cpp @@ -34,49 +34,49 @@ void StartMusic(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) + if (CSoundManager* sndManager = (CSoundManager*)ISoundManager::GetSoundManager()) sndManager->SetMusicEnabled(true); } void StopMusic(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) + if (CSoundManager* sndManager = (CSoundManager*)ISoundManager::GetSoundManager()) sndManager->SetMusicEnabled(false); } void ClearPlaylist(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { - if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) + if (CSoundManager* sndManager = (CSoundManager*)ISoundManager::GetSoundManager()) sndManager->ClearPlayListItems(); } void AddPlaylistItem(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& filename) { - if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) + if (CSoundManager* sndManager = (CSoundManager*)ISoundManager::GetSoundManager()) sndManager->AddPlayListItem(VfsPath(filename)); } void StartPlaylist(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), bool looping) { - if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) + if (CSoundManager* sndManager = (CSoundManager*)ISoundManager::GetSoundManager()) sndManager->StartPlayList(looping ); } void PlayMusic(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& filename, bool looping) { - if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) + if (CSoundManager* sndManager = (CSoundManager*)ISoundManager::GetSoundManager()) sndManager->PlayAsMusic(filename, looping); } void PlayUISound(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& filename, bool looping) { - if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) + if (CSoundManager* sndManager = (CSoundManager*)ISoundManager::GetSoundManager()) sndManager->PlayAsUI(filename, looping); } void PlayAmbientSound(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& filename, bool looping) { - if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) + if (CSoundManager* sndManager = (CSoundManager*)ISoundManager::GetSoundManager()) sndManager->PlayAsAmbient(filename, looping); } @@ -87,31 +87,31 @@ void SetMasterGain(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), float gain) { - if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) + if (CSoundManager* sndManager = (CSoundManager*)ISoundManager::GetSoundManager()) sndManager->SetMasterGain(gain); } void SetMusicGain(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), float gain) { - if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) + if (CSoundManager* sndManager = (CSoundManager*)ISoundManager::GetSoundManager()) sndManager->SetMusicGain(gain); } void SetAmbientGain(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), float gain) { - if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) + if (CSoundManager* sndManager = (CSoundManager*)ISoundManager::GetSoundManager()) sndManager->SetAmbientGain(gain); } void SetActionGain(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), float gain) { - if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) + if (CSoundManager* sndManager = (CSoundManager*)ISoundManager::GetSoundManager()) sndManager->SetActionGain(gain); } void SetUIGain(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), float gain) { - if (CSoundManager* sndManager = (CSoundManager*)g_SoundManager) + if (CSoundManager* sndManager = (CSoundManager*)ISoundManager::GetSoundManager()) sndManager->SetUIGain(gain); } Index: source/soundmanager/scripting/SoundGroup.cpp =================================================================== --- source/soundmanager/scripting/SoundGroup.cpp +++ source/soundmanager/scripting/SoundGroup.cpp @@ -42,8 +42,6 @@ #include -extern CGame *g_Game; - #define PI 3.14126f @@ -106,14 +104,14 @@ { float x, y; float answer = 0.0; - const size_t screenWidth = g_Game->GetView()->GetCamera()->GetViewPort().m_Width; - const size_t screenHeight = g_Game->GetView()->GetCamera()->GetViewPort().m_Height; + const size_t screenWidth = CGame::GetGame()->GetView()->GetCamera()->GetViewPort().m_Width; + const size_t screenHeight = CGame::GetGame()->GetView()->GetCamera()->GetViewPort().m_Height; float bufferSize = screenWidth * 0.10; float yBufferSize = 15; const size_t audioWidth = screenWidth; float radianCap = PI / 3; - g_Game->GetView()->GetCamera()->GetScreenCoordinates(position, x, y); + CGame::GetGame()->GetView()->GetCamera()->GetScreenCoordinates(position, x, y); onScreen = true; @@ -156,7 +154,7 @@ void CSoundGroup::UploadPropertiesAndPlay(size_t theIndex, const CVector3D& position, entity_id_t source) { #if CONFIG2_AUDIO - if (!g_SoundManager) + if (!ISoundManager::IsCreated()) return; bool isOnscreen = false; @@ -176,13 +174,13 @@ if (sndData == nullptr) return; - ISoundItem* hSound = static_cast(g_SoundManager)->ItemForEntity(source, sndData); + ISoundItem* hSound = static_cast(ISoundManager::GetSoundManager())->ItemForEntity(source, sndData); if (hSound == nullptr) return; if (!TestFlag(eOmnipresent)) { - CVector3D origin = g_Game->GetView()->GetCamera()->GetOrientation().GetTranslation(); + CVector3D origin = CGame::GetGame()->GetView()->GetCamera()->GetOrientation().GetTranslation(); float sndDist = origin.Y; float itemDist = (position - origin).Length(); @@ -208,7 +206,7 @@ m_Gain = RandFloat(m_GainLower, m_GainUpper); hSound->SetCone(m_ConeInnerAngle, m_ConeOuterAngle, m_ConeOuterGain); - static_cast(g_SoundManager)->PlayGroupItem(hSound, m_Gain); + static_cast(ISoundManager::GetSoundManager())->PlayGroupItem(hSound, m_Gain); #else // !CONFIG2_AUDIO UNUSED2(theIndex); @@ -242,7 +240,7 @@ #if CONFIG2_AUDIO ReleaseGroup(); - if ( g_SoundManager ) { + if (ISoundManager::IsCreated()) { for (size_t i = 0; i < filenames.size(); i++) { VfsPath thePath = m_filepath/filenames[i]; Index: source/tools/atlas/GameInterface/Brushes.cpp =================================================================== --- source/tools/atlas/GameInterface/Brushes.cpp +++ source/tools/atlas/GameInterface/Brushes.cpp @@ -35,7 +35,7 @@ { public: BrushTerrainOverlay(const Brush* brush) - : TerrainOverlay(g_Game->GetSimulation2()->GetSimContext(), 300), m_Brush(brush) + : TerrainOverlay(CGame::GetGame()->GetSimulation2()->GetSimContext(), 300), m_Brush(brush) { } Index: source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp +++ source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp @@ -38,32 +38,32 @@ MESSAGEHANDLER(CameraReset) { - if (!g_Game || g_Game->GetView()->GetCinema()->IsEnabled()) + if (!CGame::IsGameInitialised() || CGame::GetGame()->GetView()->GetCinema()->IsEnabled()) return; - CVector3D focus = g_Game->GetView()->GetCamera()->GetFocus(); + CVector3D focus = CGame::GetGame()->GetView()->GetCamera()->GetFocus(); CVector3D target; - if (!g_Game->GetWorld()->GetTerrain()->IsOnMap(focus.X, focus.Z)) + if (!CGame::GetGame()->GetWorld()->GetTerrain()->IsOnMap(focus.X, focus.Z)) { target = CVector3D( - g_Game->GetWorld()->GetTerrain()->GetMaxX()/2.f, + CGame::GetGame()->GetWorld()->GetTerrain()->GetMaxX()/2.f, focus.Y, - g_Game->GetWorld()->GetTerrain()->GetMaxZ()/2.f); + CGame::GetGame()->GetWorld()->GetTerrain()->GetMaxZ()/2.f); } else { target = focus; } - g_Game->GetView()->ResetCameraTarget(target); + CGame::GetGame()->GetView()->ResetCameraTarget(target); UNUSED2(msg); } MESSAGEHANDLER(ScrollConstant) { - if (!g_Game || g_Game->GetView()->GetCinema()->IsEnabled()) + if (!CGame::IsGameInitialised() || CGame::GetGame()->GetView()->GetCinema()->IsEnabled()) return; if (msg->dir < 0 || msg->dir > 5) @@ -76,18 +76,18 @@ } } -// TODO: change all these g_Game->...GetCamera() bits to use the current AtlasView's +// TODO: change all these CGame::GetGame()->...GetCamera() bits to use the current AtlasView's // camera instead. MESSAGEHANDLER(Scroll) { - if (!g_Game || g_Game->GetView()->GetCinema()->IsEnabled()) // TODO: do this better (probably a separate AtlasView class for cinematics) + if (!CGame::IsGameInitialised() || CGame::GetGame()->GetView()->GetCinema()->IsEnabled()) // TODO: do this better (probably a separate AtlasView class for cinematics) return; static CVector3D targetPos; static float targetDistance = 0.f; - CMatrix3D& camera = g_Game->GetView()->GetCamera()->m_Orientation; + CMatrix3D& camera = CGame::GetGame()->GetView()->GetCamera()->m_Orientation; static CVector3D lastCameraPos = camera.GetTranslation(); @@ -117,10 +117,10 @@ CVector3D origin, dir; float x, y; msg->pos->GetScreenSpace(x, y); - g_Game->GetView()->GetCamera()->BuildCameraRay((int)x, (int)y, origin, dir); + CGame::GetGame()->GetView()->GetCamera()->BuildCameraRay((int)x, (int)y, origin, dir); dir *= targetDistance; camera.Translate(targetPos - dir - origin); - g_Game->GetView()->GetCamera()->UpdateFrustum(); + CGame::GetGame()->GetView()->GetCamera()->UpdateFrustum(); } else { @@ -131,7 +131,7 @@ MESSAGEHANDLER(SmoothZoom) { - if (!g_Game || g_Game->GetView()->GetCinema()->IsEnabled()) + if (!CGame::IsGameInitialised() || CGame::GetGame()->GetView()->GetCinema()->IsEnabled()) return; g_AtlasGameLoop->input.zoomDelta += msg->amount; @@ -139,13 +139,13 @@ MESSAGEHANDLER(RotateAround) { - if (!g_Game || g_Game->GetView()->GetCinema()->IsEnabled()) + if (!CGame::IsGameInitialised() || CGame::GetGame()->GetView()->GetCinema()->IsEnabled()) return; static CVector3D focusPos; static float lastX = 0.f, lastY = 0.f; - CMatrix3D& camera = g_Game->GetView()->GetCamera()->m_Orientation; + CMatrix3D& camera = CGame::GetGame()->GetView()->GetCamera()->m_Orientation; if (msg->type == eRotateAroundType::FROM) { @@ -179,7 +179,7 @@ camera._21 = 0.f; // (_21 = Y component returned by GetLeft()) camera.Translate(focusPos + offset); - g_Game->GetView()->GetCamera()->UpdateFrustum(); + CGame::GetGame()->GetView()->GetCamera()->UpdateFrustum(); lastX = x; lastY = y; @@ -222,17 +222,17 @@ QUERYHANDLER(GetView) { - if (!g_Game) + if (!CGame::IsGameInitialised()) return; - CVector3D focus = g_Game->GetView()->GetCamera()->GetFocus(); + CVector3D focus = CGame::GetGame()->GetView()->GetCamera()->GetFocus(); sCameraInfo info; info.pX = focus.X; info.pY = focus.Y; info.pZ = focus.Z; - CQuaternion quatRot = g_Game->GetView()->GetCamera()->m_Orientation.GetRotation(); + CQuaternion quatRot = CGame::GetGame()->GetView()->GetCamera()->m_Orientation.GetRotation(); quatRot.Normalize(); CVector3D rotation = quatRot.ToEulerAngles(); @@ -245,10 +245,10 @@ MESSAGEHANDLER(SetView) { - if (!g_Game || g_Game->GetView()->GetCinema()->IsEnabled()) + if (!CGame::IsGameInitialised() || CGame::GetGame()->GetView()->GetCinema()->IsEnabled()) return; - CGameView* view = g_Game->GetView(); + CGameView* view = CGame::GetGame()->GetView(); view->ResetCameraTarget(view->GetCamera()->GetFocus()); sCameraInfo cam = msg->info; Index: source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp +++ source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp @@ -81,7 +81,7 @@ std::vector GetCurrentPaths() { std::vector atlasPaths; - CmpPtr cmpCinemaManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpCinemaManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (!cmpCinemaManager) return atlasPaths; const std::map& paths = cmpCinemaManager->GetPaths(); @@ -137,14 +137,14 @@ paths[pathName] = CCinemaPath(data, spline, TNSpline()); } - CmpPtr cmpCinemaManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpCinemaManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (cmpCinemaManager) cmpCinemaManager->SetPaths(paths); } QUERYHANDLER(GetCameraInfo) { sCameraInfo info; - CMatrix3D* cam = &g_Game->GetView()->GetCamera()->m_Orientation; + CMatrix3D* cam = &CGame::GetGame()->GetView()->GetCamera()->m_Orientation; CQuaternion quatRot = cam->GetRotation(); quatRot.Normalize(); @@ -165,7 +165,7 @@ MESSAGEHANDLER(CinemaEvent) { - CmpPtr cmpCinemaManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpCinemaManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (!cmpCinemaManager) return; @@ -175,7 +175,7 @@ } else if ( msg->mode == eCinemaEventMode::RESET ) { -// g_Game->GetView()->ResetCamera(); +// CGame::GetGame()->GetView()->ResetCamera(); } else ENSURE(false); @@ -185,7 +185,7 @@ { void Do() { - CmpPtr cmpCinemaManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpCinemaManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (!cmpCinemaManager) return; @@ -196,14 +196,14 @@ pathData.m_Mode = L"ease_inout"; pathData.m_Style = L"default"; - CVector3D focus = g_Game->GetView()->GetCamera()->GetFocus(); + CVector3D focus = CGame::GetGame()->GetView()->GetCamera()->GetFocus(); CFixedVector3D target( fixed::FromFloat(focus.X), fixed::FromFloat(focus.Y), fixed::FromFloat(focus.Z) ); - CVector3D camera = g_Game->GetView()->GetCamera()->GetOrientation().GetTranslation(); + CVector3D camera = CGame::GetGame()->GetView()->GetCamera()->GetOrientation().GetTranslation(); CFixedVector3D position( fixed::FromFloat(camera.X), fixed::FromFloat(camera.Y), @@ -231,7 +231,7 @@ { void Do() { - CmpPtr cmpCinemaManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpCinemaManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (!cmpCinemaManager) return; @@ -270,8 +270,8 @@ { void Do() { - if (g_Game && g_Game->GetView() && g_Game->GetView()->GetCinema()) - g_Game->GetView()->GetCinema()->SetPathsDrawing(msg->drawPaths); + if (CGame::IsGameInitialised() && CGame::GetGame()->GetView() && CGame::GetGame()->GetView()->GetCinema()) + CGame::GetGame()->GetView()->GetCinema()->SetPathsDrawing(msg->drawPaths); } void Redo() @@ -293,8 +293,8 @@ float middle1 = lower + delta, middle2 = lower + 2.0f * delta; CVector3D p1 = base + dir * middle1, p2 = base + dir * middle2; CVector2D s1, s2; - g_Game->GetView()->GetCamera()->GetScreenCoordinates(p1, s1.X, s1.Y); - g_Game->GetView()->GetCamera()->GetScreenCoordinates(p2, s2.X, s2.Y); + CGame::GetGame()->GetView()->GetCamera()->GetScreenCoordinates(p1, s1.X, s1.Y); + CGame::GetGame()->GetView()->GetCamera()->GetScreenCoordinates(p2, s2.X, s2.Y); if ((s1 - screen).Length() < (s2 - screen).Length()) upper = middle2; else @@ -308,7 +308,7 @@ if (index < 0) \ return; \ CStrW name = *msg->node->name; \ - CmpPtr cmpCinemaManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); \ + CmpPtr cmpCinemaManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); \ if (!cmpCinemaManager || !cmpCinemaManager->HasPath(name)) \ return; \ const CCinemaPath& path = cmpCinemaManager->GetPaths().find(name)->second; \ @@ -334,7 +334,7 @@ TNSpline targetSpline = path.GetTargetSpline(); TNSpline& spline = msg->node->targetNode ? targetSpline : positionSpline; - CVector3D focus = g_Game->GetView()->GetCamera()->GetFocus(); + CVector3D focus = CGame::GetGame()->GetView()->GetCamera()->GetFocus(); CFixedVector3D target( fixed::FromFloat(focus.X), fixed::FromFloat(focus.Y), @@ -463,7 +463,7 @@ data.Position.Z.ToFloat() ); CVector2D screen_pos; - g_Game->GetView()->GetCamera()->GetScreenCoordinates(position, screen_pos.X, screen_pos.Y); + CGame::GetGame()->GetView()->GetCamera()->GetScreenCoordinates(position, screen_pos.X, screen_pos.Y); if ((screen_pos - cursor).Length() < MINIMAL_SCREEN_DISTANCE) { node.index = i; @@ -481,7 +481,7 @@ QUERYHANDLER(PickPathNode) { AtlasMessage::sCinemaPathNode node; - CmpPtr cmpCinemaManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpCinemaManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (!cmpCinemaManager) { msg->node = node; @@ -509,7 +509,7 @@ { CVector3D position = GetNearestPointToScreenCoords(base, direction, cursor, 0, length); CVector2D screen_position; - g_Game->GetView()->GetCamera()->GetScreenCoordinates(position, screen_position.X, screen_position.Y); + CGame::GetGame()->GetView()->GetCamera()->GetScreenCoordinates(position, screen_position.X, screen_position.Y); return (cursor - screen_position).Length() < MINIMAL_SCREEN_DISTANCE; } @@ -522,7 +522,7 @@ const TNSpline& spline = msg->node->targetNode ? path.GetTargetSpline() : path; CFixedVector3D pos = spline.GetAllNodes()[index].Position; CVector3D position(pos.X.ToFloat(), pos.Y.ToFloat(), pos.Z.ToFloat()); - CVector3D camera = g_Game->GetView()->GetCamera()->GetOrientation().GetTranslation(); + CVector3D camera = CGame::GetGame()->GetView()->GetCamera()->GetOrientation().GetTranslation(); float scale = (position - camera).Length() / 10.0; CVector2D cursor; Index: source/tools/atlas/GameInterface/Handlers/ElevationHandlers.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/ElevationHandlers.cpp +++ source/tools/atlas/GameInterface/Handlers/ElevationHandlers.cpp @@ -40,8 +40,8 @@ public: void Init() { - m_Heightmap = g_Game->GetWorld()->GetTerrain()->GetHeightMap(); - m_VertsPerSide = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); + m_Heightmap = CGame::GetGame()->GetWorld()->GetTerrain()->GetHeightMap(); + m_VertsPerSide = CGame::GetGame()->GetWorld()->GetTerrain()->GetVerticesPerSide(); } void RaiseVertex(ssize_t x, ssize_t y, int amount) @@ -110,8 +110,8 @@ void MakeDirty() { - g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); - CmpPtr cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CGame::GetGame()->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); + CmpPtr cmpTerrain(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (cmpTerrain) cmpTerrain->MakeDirty(m_i0, m_j0, m_i1, m_j1); } @@ -192,8 +192,8 @@ void MakeDirty() { - g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); - CmpPtr cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CGame::GetGame()->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); + CmpPtr cmpTerrain(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (cmpTerrain) cmpTerrain->MakeDirty(m_i0, m_j0, m_i1, m_j1); } @@ -304,8 +304,8 @@ void MakeDirty() { - g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); - CmpPtr cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CGame::GetGame()->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); + CmpPtr cmpTerrain(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (cmpTerrain) cmpTerrain->MakeDirty(m_i0, m_j0, m_i1, m_j1); } @@ -378,8 +378,8 @@ void MakeDirty() { - g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); - CmpPtr cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CGame::GetGame()->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_VERTICES); + CmpPtr cmpTerrain(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (cmpTerrain) cmpTerrain->MakeDirty(m_i0, m_j0, m_i1, m_j1); } Index: source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp +++ source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp @@ -40,7 +40,7 @@ { sEnvironmentSettings s; - CmpPtr cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpWaterManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); ENSURE(cmpWaterManager); s.waterheight = cmpWaterManager->GetExactWaterLevel(0, 0) / (65536.f * HEIGHT_SCALE); @@ -95,7 +95,7 @@ void SetSettings(const sEnvironmentSettings& s) { - CmpPtr cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpWaterManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); ENSURE(cmpWaterManager); cmpWaterManager->SetWaterLevel(entity_pos_t::FromFloat(s.waterheight * (65536.f * HEIGHT_SCALE))); @@ -184,7 +184,7 @@ void Redo() { - CmpPtr cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpWaterManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); ENSURE(cmpWaterManager); cmpWaterManager->RecomputeWaterData(); Index: source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp +++ source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp @@ -51,32 +51,26 @@ { void InitGame() { - if (g_Game) - { - delete g_Game; - g_Game = NULL; - } - - g_Game = new CGame(false, false); + CGame::InitGame(false, false); // Default to player 1 for playtesting - g_Game->SetPlayerID(1); + CGame::GetGame()->SetPlayerID(1); } void StartGame(JS::MutableHandleValue attrs) { - g_Game->StartGame(attrs, ""); + CGame::GetGame()->StartGame(attrs, ""); // TODO: Non progressive load can fail - need a decent way to handle this LDR_NonprogressiveLoad(); // Disable fog-of-war - this must be done before starting the game, // as visual actors cache their visibility state on first render. - CmpPtr cmpRangeManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpRangeManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (cmpRangeManager) cmpRangeManager->SetLosRevealAll(-1, true); - PSRETURN ret = g_Game->ReallyStartGame(); + PSRETURN ret = CGame::GetGame()->ReallyStartGame(); ENSURE(ret == PSRETURN_OK); } } @@ -90,7 +84,7 @@ InitGame(); // Random map - const ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); + const ScriptInterface& scriptInterface = CGame::GetGame()->GetSimulation2()->GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -117,7 +111,7 @@ InitGame(); - const ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); + const ScriptInterface& scriptInterface = CGame::GetGame()->GetSimulation2()->GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -150,7 +144,7 @@ { InitGame(); - const ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); + const ScriptInterface& scriptInterface = CGame::GetGame()->GetSimulation2()->GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -178,20 +172,20 @@ // resize terrain to heightmap size // Notice that the number of tiles/pixels per side of the heightmap image is // one less than the number of vertices per side of the heightmap. - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); + CTerrain* terrain = CGame::GetGame()->GetWorld()->GetTerrain(); terrain->Resize((sqrt(heightmap_source.size()) - 1) / PATCH_SIZE); // copy heightmap data into map - u16* heightmap = g_Game->GetWorld()->GetTerrain()->GetHeightMap(); - ENSURE(heightmap_source.size() == (std::size_t) SQR(g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide())); + u16* heightmap = CGame::GetGame()->GetWorld()->GetTerrain()->GetHeightMap(); + ENSURE(heightmap_source.size() == (std::size_t) SQR(CGame::GetGame()->GetWorld()->GetTerrain()->GetVerticesPerSide())); std::copy(heightmap_source.begin(), heightmap_source.end(), heightmap); // update simulation - CmpPtr cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpTerrain(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (cmpTerrain) cmpTerrain->ReloadTerrain(); - g_Game->GetView()->GetLOSTexture().MakeDirty(); + CGame::GetGame()->GetView()->GetLOSTexture().MakeDirty(); } MESSAGEHANDLER(SaveMap) @@ -199,16 +193,16 @@ CMapWriter writer; VfsPath pathname = VfsPath(*msg->filename).ChangeExtension(L".pmp"); writer.SaveMap(pathname, - g_Game->GetWorld()->GetTerrain(), + CGame::GetGame()->GetWorld()->GetTerrain(), g_Renderer.GetWaterManager(), g_Renderer.GetSkyManager(), - &g_LightEnv, g_Game->GetView()->GetCamera(), g_Game->GetView()->GetCinema(), + &g_LightEnv, CGame::GetGame()->GetView()->GetCamera(), CGame::GetGame()->GetView()->GetCinema(), &g_Renderer.GetPostprocManager(), - g_Game->GetSimulation2()); + CGame::GetGame()->GetSimulation2()); } QUERYHANDLER(GetMapSettings) { - msg->settings = g_Game->GetSimulation2()->GetMapSettingsString(); + msg->settings = CGame::GetGame()->GetSimulation2()->GetMapSettingsString(); } BEGIN_COMMAND(SetMapSettings) @@ -217,12 +211,12 @@ void SetSettings(const std::string& settings) { - g_Game->GetSimulation2()->SetMapSettings(settings); + CGame::GetGame()->GetSimulation2()->SetMapSettings(settings); } void Do() { - m_OldSettings = g_Game->GetSimulation2()->GetMapSettingsString(); + m_OldSettings = CGame::GetGame()->GetSimulation2()->GetMapSettingsString(); m_NewSettings = *msg->settings; SetSettings(m_NewSettings); @@ -249,17 +243,17 @@ MESSAGEHANDLER(LoadPlayerSettings) { - g_Game->GetSimulation2()->LoadPlayerSettings(msg->newplayers); + CGame::GetGame()->GetSimulation2()->LoadPlayerSettings(msg->newplayers); } QUERYHANDLER(GetMapSizes) { - msg->sizes = g_Game->GetSimulation2()->GetMapSizes(); + msg->sizes = CGame::GetGame()->GetSimulation2()->GetMapSizes(); } QUERYHANDLER(GetRMSData) { - msg->data = g_Game->GetSimulation2()->GetRMSData(); + msg->data = CGame::GetGame()->GetSimulation2()->GetRMSData(); } BEGIN_COMMAND(ResizeMap) @@ -272,18 +266,18 @@ void MakeDirty() { - CmpPtr cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpTerrain(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (cmpTerrain) cmpTerrain->ReloadTerrain(); // The LOS texture won't normally get updated when running Atlas // (since there's no simulation updates), so explicitly dirty it - g_Game->GetView()->GetLOSTexture().MakeDirty(); + CGame::GetGame()->GetView()->GetLOSTexture().MakeDirty(); } void ResizeTerrain(int tiles) { - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); + CTerrain* terrain = CGame::GetGame()->GetWorld()->GetTerrain(); terrain->Resize(tiles / PATCH_SIZE); @@ -292,7 +286,7 @@ void Do() { - CmpPtr cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpTerrain(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (!cmpTerrain) { m_OldTiles = m_NewTiles = 0; Index: source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp +++ source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp @@ -61,8 +61,8 @@ { g_Renderer.Resize(w, h); SViewPort vp = { 0, 0, w, h }; - g_Game->GetView()->GetCamera()->SetViewPort(vp); - g_Game->GetView()->SetCameraProjection(); + CGame::GetGame()->GetView()->GetCamera()->SetViewPort(vp); + CGame::GetGame()->GetView()->SetCameraProjection(); } unsigned char* img = new unsigned char [w*h*3]; @@ -113,8 +113,8 @@ { g_Renderer.Resize(g_xres, g_yres); SViewPort vp = { 0, 0, g_xres, g_yres }; - g_Game->GetView()->GetCamera()->SetViewPort(vp); - g_Game->GetView()->SetCameraProjection(); + CGame::GetGame()->GetView()->GetCamera()->SetViewPort(vp); + CGame::GetGame()->GetView()->SetCameraProjection(); } } @@ -128,7 +128,7 @@ { UNUSED2(msg); - CmpPtr cmpSoundManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpSoundManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (cmpSoundManager) cmpSoundManager->StopMusic(); } Index: source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp +++ source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp @@ -65,7 +65,7 @@ // Helpers for object constraints bool CheckEntityObstruction(entity_id_t ent) { - CmpPtr cmpObstruction(*g_Game->GetSimulation2(), ent); + CmpPtr cmpObstruction(*CGame::GetGame()->GetSimulation2(), ent); if (cmpObstruction) { ICmpObstruction::EFoundationCheck result = cmpObstruction->CheckFoundation("default"); @@ -77,7 +77,7 @@ void CheckObstructionAndUpdateVisual(entity_id_t id) { - CmpPtr cmpVisual(*g_Game->GetSimulation2(), id); + CmpPtr cmpVisual(*CGame::GetGame()->GetSimulation2(), id); if (cmpVisual) { if (!CheckEntityObstruction(id)) @@ -91,7 +91,7 @@ { std::vector objects; - CmpPtr cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpTemplateManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (cmpTemplateManager) { std::vector names = cmpTemplateManager->FindAllTemplates(true); @@ -132,7 +132,7 @@ // Default color - white CColor color(1.0f, 1.0f, 1.0f, 1.0f); - CSimulation2& sim = *g_Game->GetSimulation2(); + CSimulation2& sim = *CGame::GetGame()->GetSimulation2(); CmpPtr cmpOwnership(sim, id); if (cmpOwnership) { @@ -156,7 +156,7 @@ MESSAGEHANDLER(SetSelectionPreview) { - CSimulation2& sim = *g_Game->GetSimulation2(); + CSimulation2& sim = *CGame::GetGame()->GetSimulation2(); // Cache player colors for performance PlayerColorMap playerColors; @@ -251,7 +251,7 @@ { std::vector ids = *msg->ids; - CmpPtr cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpTemplateManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); ENSURE(cmpTemplateManager); XML_Start(); @@ -266,12 +266,12 @@ XML_Setting("Template", cmpTemplateManager->GetCurrentTemplateName(id)); //Player - CmpPtr cmpOwnership(*g_Game->GetSimulation2(), id); + CmpPtr cmpOwnership(*CGame::GetGame()->GetSimulation2(), id); if (cmpOwnership) XML_Setting("Player", (int)cmpOwnership->GetOwner()); //Adding position to make some relative position later - CmpPtr cmpPosition(*g_Game->GetSimulation2(), id); + CmpPtr cmpPosition(*CGame::GetGame()->GetSimulation2(), id); if (cmpPosition) { CFixedVector3D pos = cmpPosition->GetPosition(); @@ -290,7 +290,7 @@ } // Adding actor seed - CmpPtr cmpVisual(*g_Game->GetSimulation2(), id); + CmpPtr cmpVisual(*CGame::GetGame()->GetSimulation2(), id); if (cmpVisual) XML_Setting("ActorSeed", (unsigned int)cmpVisual->GetActorSeed()); @@ -381,7 +381,7 @@ // Use 'clamp' with a value slightly less than the width, so that converting // to integer (rounding towards zero) will put it on the tile inside the edge // instead of just outside - float mapWidth = (g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide()-1)*TERRAIN_TILE_SIZE; + float mapWidth = (CGame::GetGame()->GetWorld()->GetTerrain()->GetVerticesPerSide()-1)*TERRAIN_TILE_SIZE; float delta = 1e-6f; // fraction of map width - must be > FLT_EPSILON float xOnMap = clamp(vec.X, 0.f, mapWidth * (1.f - delta)); @@ -392,7 +392,7 @@ { vec.X = xOnMap; vec.Z = zOnMap; - vec.Y = g_Game->GetWorld()->GetTerrain()->GetExactGroundLevel(xOnMap, zOnMap); + vec.Y = CGame::GetGame()->GetWorld()->GetTerrain()->GetExactGroundLevel(xOnMap, zOnMap); } return vec; @@ -410,7 +410,7 @@ if (g_PreviewEntitiesID.size() == 0) return; - CmpPtr cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpTemplateManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); ENSURE(cmpTemplateManager); PlayerColorMap playerColor; @@ -422,13 +422,13 @@ std::string templateName = cmpTemplateManager->GetCurrentTemplateName(ent); std::wstring wTemplateName(templateName.begin() + 8, templateName.end()); //Create new entity - entity_id_t new_ent = g_Game->GetSimulation2()->AddEntity(wTemplateName); + entity_id_t new_ent = CGame::GetGame()->GetSimulation2()->AddEntity(wTemplateName); if (new_ent == INVALID_ENTITY) continue; //get position, get rotation - CmpPtr cmpPositionNew(*g_Game->GetSimulation2(), new_ent); - CmpPtr cmpPositionOld(*g_Game->GetSimulation2(), ent); + CmpPtr cmpPositionNew(*CGame::GetGame()->GetSimulation2(), new_ent); + CmpPtr cmpPositionOld(*CGame::GetGame()->GetSimulation2(), ent); if (cmpPositionNew && cmpPositionOld) { @@ -441,24 +441,24 @@ } //get owner - CmpPtr cmpOwnershipNew(*g_Game->GetSimulation2(), new_ent); - CmpPtr cmpOwnershipOld(*g_Game->GetSimulation2(), ent); + CmpPtr cmpOwnershipNew(*CGame::GetGame()->GetSimulation2(), new_ent); + CmpPtr cmpOwnershipOld(*CGame::GetGame()->GetSimulation2(), ent); if (cmpOwnershipNew && cmpOwnershipOld) cmpOwnershipNew->SetOwner(cmpOwnershipOld->GetOwner()); //getVisual - CmpPtr cmpVisualNew(*g_Game->GetSimulation2(), new_ent); - CmpPtr cmpVisualOld(*g_Game->GetSimulation2(), ent); + CmpPtr cmpVisualNew(*CGame::GetGame()->GetSimulation2(), new_ent); + CmpPtr cmpVisualOld(*CGame::GetGame()->GetSimulation2(), ent); if (cmpVisualNew && cmpVisualOld) cmpVisualNew->SetActorSeed(cmpVisualOld->GetActorSeed()); //Update g_selectedObject and higligth g_Selection.push_back(new_ent); - CmpPtr cmpSelectable(*g_Game->GetSimulation2(), new_ent); + CmpPtr cmpSelectable(*CGame::GetGame()->GetSimulation2(), new_ent); if (cmpSelectable) cmpSelectable->SetSelectionHighlight(GetOwnerPlayerColor(playerColor, new_ent), true); - g_Game->GetSimulation2()->DestroyEntity(ent); + CGame::GetGame()->GetSimulation2()->DestroyEntity(ent); } g_PreviewEntitiesID.clear(); @@ -476,7 +476,7 @@ // so get its position and whether it's floating CFixedVector3D referencePos; - CmpPtr cmpPosition(*g_Game->GetSimulation2(), referenceEntity); + CmpPtr cmpPosition(*CGame::GetGame()->GetSimulation2(), referenceEntity); if (cmpPosition && cmpPosition->IsInWorld()) referencePos = cmpPosition->GetPosition(); @@ -491,7 +491,7 @@ { entity_id_t id = (entity_id_t)g_PreviewEntitiesID[i]; CFixedVector3D posFinal; - CmpPtr cmpPosition(*g_Game->GetSimulation2(), id); + CmpPtr cmpPosition(*CGame::GetGame()->GetSimulation2(), id); if (cmpPosition && cmpPosition->IsInWorld()) { // Calculate this object's position @@ -514,7 +514,7 @@ { //Time to delete all preview objects for (entity_id_t ent : g_PreviewEntitiesID) - g_Game->GetSimulation2()->DestroyEntity(ent); + CGame::GetGame()->GetSimulation2()->DestroyEntity(ent); g_PreviewEntitiesID.clear(); } @@ -523,7 +523,7 @@ g_PreviewEntityID = INVALID_ENTITY; else { - g_PreviewEntityID = g_Game->GetSimulation2()->AddLocalEntity(L"preview|" + *msg->id); + g_PreviewEntityID = CGame::GetGame()->GetSimulation2()->AddLocalEntity(L"preview|" + *msg->id); g_PreviewEntitiesID.push_back(g_PreviewEntityID); } @@ -535,7 +535,7 @@ { // Update the unit's position and orientation: - CmpPtr cmpPosition(*g_Game->GetSimulation2(), g_PreviewEntityID); + CmpPtr cmpPosition(*CGame::GetGame()->GetSimulation2(), g_PreviewEntityID); if (cmpPosition) { CVector3D pos = GetUnitPos(msg->pos, cmpPosition->CanFloat()); @@ -558,11 +558,11 @@ // TODO: handle random variations somehow - CmpPtr cmpVisual(*g_Game->GetSimulation2(), g_PreviewEntityID); + CmpPtr cmpVisual(*CGame::GetGame()->GetSimulation2(), g_PreviewEntityID); if (cmpVisual) cmpVisual->SetActorSeed(msg->actorseed); - CmpPtr cmpOwnership(*g_Game->GetSimulation2(), g_PreviewEntityID); + CmpPtr cmpOwnership(*CGame::GetGame()->GetSimulation2(), g_PreviewEntityID); if (cmpOwnership) cmpOwnership->SetOwner((player_id_t)msg->settings->player); @@ -604,22 +604,22 @@ void Redo() { - m_EntityID = g_Game->GetSimulation2()->AddEntity(*msg->id); + m_EntityID = CGame::GetGame()->GetSimulation2()->AddEntity(*msg->id); if (m_EntityID == INVALID_ENTITY) return; - CmpPtr cmpPosition(*g_Game->GetSimulation2(), m_EntityID); + CmpPtr cmpPosition(*CGame::GetGame()->GetSimulation2(), m_EntityID); if (cmpPosition) { cmpPosition->JumpTo(entity_pos_t::FromFloat(m_Pos.X), entity_pos_t::FromFloat(m_Pos.Z)); cmpPosition->SetYRotation(entity_angle_t::FromFloat(m_Angle)); } - CmpPtr cmpOwnership(*g_Game->GetSimulation2(), m_EntityID); + CmpPtr cmpOwnership(*CGame::GetGame()->GetSimulation2(), m_EntityID); if (cmpOwnership) cmpOwnership->SetOwner(m_Player); - CmpPtr cmpVisual(*g_Game->GetSimulation2(), m_EntityID); + CmpPtr cmpVisual(*CGame::GetGame()->GetSimulation2(), m_EntityID); if (cmpVisual) { cmpVisual->SetActorSeed(m_ActorSeed); @@ -631,7 +631,7 @@ { if (m_EntityID != INVALID_ENTITY) { - g_Game->GetSimulation2()->DestroyEntity(m_EntityID); + CGame::GetGame()->GetSimulation2()->DestroyEntity(m_EntityID); m_EntityID = INVALID_ENTITY; } } @@ -646,7 +646,7 @@ // Normally this function would be called with a player ID to check LOS, // but in Atlas the entire map is revealed, so just pass INVALID_PLAYER - entity_id_t ent = EntitySelection::PickEntityAtPoint(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), x, y, INVALID_PLAYER, msg->selectActors);; + entity_id_t ent = EntitySelection::PickEntityAtPoint(*CGame::GetGame()->GetSimulation2(), *CGame::GetGame()->GetView()->GetCamera(), x, y, INVALID_PLAYER, msg->selectActors);; if (ent == INVALID_ENTITY) msg->id = INVALID_ENTITY; @@ -655,7 +655,7 @@ msg->id = ent; // Calculate offset of object from original mouse click position // so it gets moved by that offset - CmpPtr cmpPosition(*g_Game->GetSimulation2(), ent); + CmpPtr cmpPosition(*CGame::GetGame()->GetSimulation2(), ent); if (!cmpPosition || !cmpPosition->IsInWorld()) { // error @@ -667,7 +667,7 @@ CVector3D centre = CVector3D(fixed.X.ToFloat(), fixed.Y.ToFloat(), fixed.Z.ToFloat()); float cx, cy; - g_Game->GetView()->GetCamera()->GetScreenCoordinates(centre, cx, cy); + CGame::GetGame()->GetView()->GetCamera()->GetScreenCoordinates(centre, cx, cy); msg->offsetx = (int)(cx - x); msg->offsety = (int)(cy - y); @@ -683,13 +683,13 @@ msg->end->GetScreenSpace(x1, y1); // Since owner selections are meaningless in Atlas, use INVALID_PLAYER - msg->ids = EntitySelection::PickEntitiesInRect(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), x0, y0, x1, y1, INVALID_PLAYER, msg->selectActors); + msg->ids = EntitySelection::PickEntitiesInRect(*CGame::GetGame()->GetSimulation2(), *CGame::GetGame()->GetView()->GetCamera(), x0, y0, x1, y1, INVALID_PLAYER, msg->selectActors); } QUERYHANDLER(PickSimilarObjects) { - CmpPtr cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpTemplateManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); ENSURE(cmpTemplateManager); entity_id_t ent = msg->id; @@ -697,11 +697,11 @@ // If unit has ownership, only pick units from the same player player_id_t owner = INVALID_PLAYER; - CmpPtr cmpOwnership(*g_Game->GetSimulation2(), ent); + CmpPtr cmpOwnership(*CGame::GetGame()->GetSimulation2(), ent); if (cmpOwnership) owner = cmpOwnership->GetOwner(); - msg->ids = EntitySelection::PickSimilarEntities(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), templateName, owner, false, true, true, false); + msg->ids = EntitySelection::PickSimilarEntities(*CGame::GetGame()->GetSimulation2(), *CGame::GetGame()->GetView()->GetCamera(), templateName, owner, false, true, true, false); } MESSAGEHANDLER(ResetSelectionColor) @@ -710,7 +710,7 @@ for (entity_id_t ent : g_Selection) { - CmpPtr cmpVisual(*g_Game->GetSimulation2(), ent); + CmpPtr cmpVisual(*CGame::GetGame()->GetSimulation2(), ent); if (cmpVisual) cmpVisual->SetShadingColor(fixed::FromDouble(1), fixed::FromDouble(1), fixed::FromDouble(1), fixed::FromDouble(1)); } @@ -730,7 +730,7 @@ CVector3D pivotPos(0, 0, 0); bool pivotFloating = false; - CmpPtr cmpPosition(*g_Game->GetSimulation2(), (entity_id_t)msg->pivot); + CmpPtr cmpPosition(*CGame::GetGame()->GetSimulation2(), (entity_id_t)msg->pivot); if (cmpPosition && cmpPosition->IsInWorld()) { pivotFloating = cmpPosition->CanFloat(); @@ -745,7 +745,7 @@ for (entity_id_t id : ids) { - CmpPtr cmpPosition(*g_Game->GetSimulation2(), id); + CmpPtr cmpPosition(*CGame::GetGame()->GetSimulation2(), id); if (!cmpPosition || !cmpPosition->IsInWorld()) { // error @@ -768,7 +768,7 @@ { for (const std::pair& p : map) { - CmpPtr cmpPosition(*g_Game->GetSimulation2(), p.first); + CmpPtr cmpPosition(*CGame::GetGame()->GetSimulation2(), p.first); if (!cmpPosition) return; @@ -817,7 +817,7 @@ // Compute min position and max position for (entity_id_t id : ids) { - CmpPtr cmpPosition(*g_Game->GetSimulation2(), id); + CmpPtr cmpPosition(*CGame::GetGame()->GetSimulation2(), id); if (!cmpPosition) continue; @@ -860,7 +860,7 @@ { for (const std::pair& p : position) { - CmpPtr cmpPosition(*g_Game->GetSimulation2(), p.first); + CmpPtr cmpPosition(*CGame::GetGame()->GetSimulation2(), p.first); if (!cmpPosition) return; @@ -945,7 +945,7 @@ for (entity_id_t id : ids) { - CmpPtr cmpPosition(*g_Game->GetSimulation2(), id); + CmpPtr cmpPosition(*CGame::GetGame()->GetSimulation2(), id); if (!cmpPosition) return; @@ -964,7 +964,7 @@ { for (const std::pair& p : angles) { - CmpPtr cmpPosition(*g_Game->GetSimulation2(), p.first); + CmpPtr cmpPosition(*CGame::GetGame()->GetSimulation2(), p.first); if (!cmpPosition) return; @@ -1017,7 +1017,7 @@ void Redo() { - CSimulation2& sim = *g_Game->GetSimulation2(); + CSimulation2& sim = *CGame::GetGame()->GetSimulation2(); CmpPtr cmpTemplateManager(sim, SYSTEM_ENTITY); ENSURE(cmpTemplateManager); @@ -1041,14 +1041,14 @@ } oldObjects.push_back(obj); - g_Game->GetSimulation2()->DestroyEntity(obj.entityID); + CGame::GetGame()->GetSimulation2()->DestroyEntity(obj.entityID); } - g_Game->GetSimulation2()->FlushDestroyedEntities(); + CGame::GetGame()->GetSimulation2()->FlushDestroyedEntities(); } void Undo() { - CSimulation2& sim = *g_Game->GetSimulation2(); + CSimulation2& sim = *CGame::GetGame()->GetSimulation2(); for (size_t i = 0; i < oldObjects.size(); ++i) { @@ -1083,7 +1083,7 @@ std::vector ids; player_id_t playerID = msg->player; - const CSimulation2::InterfaceListUnordered& cmps = g_Game->GetSimulation2()->GetEntitiesWithInterfaceUnordered(IID_Ownership); + const CSimulation2::InterfaceListUnordered& cmps = CGame::GetGame()->GetSimulation2()->GetEntitiesWithInterfaceUnordered(IID_Ownership); for (CSimulation2::InterfaceListUnordered::const_iterator eit = cmps.begin(); eit != cmps.end(); ++eit) { if (static_cast(eit->second)->GetOwner() == playerID) @@ -1105,7 +1105,7 @@ std::vector ids = *msg->ids; std::vector names; - CmpPtr cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CmpPtr cmpTemplateManager(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); ENSURE(cmpTemplateManager); for (size_t i = 0; i < ids.size(); ++i) Index: source/tools/atlas/GameInterface/Handlers/PlayerHandlers.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/PlayerHandlers.cpp +++ source/tools/atlas/GameInterface/Handlers/PlayerHandlers.cpp @@ -27,17 +27,17 @@ QUERYHANDLER(GetCivData) { - msg->data = g_Game->GetSimulation2()->GetCivData(); + msg->data = CGame::GetGame()->GetSimulation2()->GetCivData(); } QUERYHANDLER(GetPlayerDefaults) { - msg->defaults = g_Game->GetSimulation2()->GetPlayerDefaults(); + msg->defaults = CGame::GetGame()->GetSimulation2()->GetPlayerDefaults(); } QUERYHANDLER(GetAIData) { - msg->data = g_Game->GetSimulation2()->GetAIData(); + msg->data = CGame::GetGame()->GetSimulation2()->GetAIData(); } } Index: source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp +++ source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp @@ -153,7 +153,7 @@ g_CurrentBrush.m_Centre = msg->pos->GetWorldSpace(); g_CurrentBrush.GetCentre(x, y); - CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); + CTerrain* terrain = CGame::GetGame()->GetWorld()->GetTerrain(); CMiniPatch* tile = terrain->GetTile(x, y); if (tile) { @@ -199,8 +199,8 @@ public: void Init() { - m_Terrain = g_Game->GetWorld()->GetTerrain(); - m_VertsPerSide = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); + m_Terrain = CGame::GetGame()->GetWorld()->GetTerrain(); + m_VertsPerSide = CGame::GetGame()->GetWorld()->GetTerrain()->GetVerticesPerSide(); } void UpdatePriority(ssize_t x, ssize_t y, CTerrainTextureEntry* tex, ssize_t priorityScale, ssize_t& priority) @@ -280,7 +280,7 @@ void MakeDirty() { - g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_INDICES); + CGame::GetGame()->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_INDICES); } void Do() @@ -366,8 +366,8 @@ void MakeDirty() { - g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_INDICES); - CmpPtr cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CGame::GetGame()->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_INDICES); + CmpPtr cmpTerrain(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (cmpTerrain) cmpTerrain->MakeDirty(m_i0, m_j0, m_i1, m_j1); } @@ -445,8 +445,8 @@ void MakeDirty() { - g_Game->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_INDICES); - CmpPtr cmpTerrain(*g_Game->GetSimulation2(), SYSTEM_ENTITY); + CGame::GetGame()->GetWorld()->GetTerrain()->MakeDirty(m_i0, m_j0, m_i1, m_j1, RENDERDATA_UPDATE_INDICES); + CmpPtr cmpTerrain(*CGame::GetGame()->GetSimulation2(), SYSTEM_ENTITY); if (cmpTerrain) cmpTerrain->MakeDirty(m_i0, m_j0, m_i1, m_j1); } Index: source/tools/atlas/GameInterface/InputProcessor.cpp =================================================================== --- source/tools/atlas/GameInterface/InputProcessor.cpp +++ source/tools/atlas/GameInterface/InputProcessor.cpp @@ -44,10 +44,10 @@ bool InputProcessor::ProcessInput(GameLoopState* state) { - if (! g_Game) + if (! CGame::GetGame()) return false; - CCamera* camera = g_Game->GetView()->GetCamera(); + CCamera* camera = CGame::GetGame()->GetView()->GetCamera(); CVector3D leftwards = camera->m_Orientation.GetLeft(); Index: source/tools/atlas/GameInterface/Misc.cpp =================================================================== --- source/tools/atlas/GameInterface/Misc.cpp +++ source/tools/atlas/GameInterface/Misc.cpp @@ -35,7 +35,7 @@ break; case 1: - return g_Game->GetView()->GetCamera()->GetWorldCoordinates(type1.x, type1.y, floating); + return CGame::GetGame()->GetView()->GetCamera()->GetWorldCoordinates(type1.x, type1.y, floating); break; case 2: @@ -54,7 +54,7 @@ switch (type) { case 1: - return g_Game->GetView()->GetCamera()->GetWorldCoordinates(type1.x, type1.y, h); + return CGame::GetGame()->GetView()->GetCamera()->GetWorldCoordinates(type1.x, type1.y, h); default: return GetWorldSpace(floating); @@ -78,7 +78,7 @@ switch (type) { case 0: - g_Game->GetView()->GetCamera()->GetScreenCoordinates(CVector3D(type0.x, type0.y, type0.x), x, y); + CGame::GetGame()->GetView()->GetCamera()->GetScreenCoordinates(CVector3D(type0.x, type0.y, type0.x), x, y); break; case 1: Index: source/tools/atlas/GameInterface/SimState.cpp =================================================================== --- source/tools/atlas/GameInterface/SimState.cpp +++ source/tools/atlas/GameInterface/SimState.cpp @@ -26,7 +26,7 @@ { SimState* simState = new SimState(); - if (! g_Game->GetSimulation2()->SerializeState(simState->stream)) + if (! CGame::GetGame()->GetSimulation2()->SerializeState(simState->stream)) { delete simState; return NULL; @@ -37,5 +37,5 @@ void SimState::Thaw() { - g_Game->GetSimulation2()->DeserializeState(stream); + CGame::GetGame()->GetSimulation2()->DeserializeState(stream); } Index: source/tools/atlas/GameInterface/View.cpp =================================================================== --- source/tools/atlas/GameInterface/View.cpp +++ source/tools/atlas/GameInterface/View.cpp @@ -173,7 +173,7 @@ AtlasViewGame::AtlasViewGame() : m_SpeedMultiplier(0.f), m_IsTesting(false), m_DrawMoveTool(false) { - ENSURE(g_Game); + ENSURE(CGame::GetGame()); } AtlasViewGame::~AtlasViewGame() @@ -184,7 +184,7 @@ CSimulation2* AtlasViewGame::GetSimulation2() { - return g_Game->GetSimulation2(); + return CGame::GetGame()->GetSimulation2(); } void AtlasViewGame::Update(float realFrameLength) @@ -192,28 +192,28 @@ const float actualFrameLength = realFrameLength * m_SpeedMultiplier; // Clean up any entities destroyed during UI message processing - g_Game->GetSimulation2()->FlushDestroyedEntities(); + CGame::GetGame()->GetSimulation2()->FlushDestroyedEntities(); if (m_SpeedMultiplier == 0.f) { // Update unit interpolation - g_Game->Interpolate(0.0, realFrameLength); + CGame::GetGame()->Interpolate(0.0, realFrameLength); } else { // Update the whole world // (Tell the game update not to interpolate graphics - we'll do that // ourselves) - g_Game->Update(actualFrameLength, false); + CGame::GetGame()->Update(actualFrameLength, false); // Interpolate the graphics - we only want to do this once per visual frame, - // not in every call to g_Game->Update - g_Game->Interpolate(actualFrameLength, realFrameLength); + // not in every call to CGame::GetGame()->Update + CGame::GetGame()->Interpolate(actualFrameLength, realFrameLength); } // Cinematic motion should be independent of simulation update, so we can // preview the cinematics by themselves - g_Game->GetView()->GetCinema()->Update(realFrameLength); + CGame::GetGame()->GetView()->GetCinema()->Update(realFrameLength); } void AtlasViewGame::Render() @@ -221,7 +221,7 @@ SViewPort vp = { 0, 0, g_xres, g_yres }; CCamera& camera = GetCamera(); camera.SetViewPort(vp); - camera.SetProjection(g_Game->GetView()->GetNear(), g_Game->GetView()->GetFar(), g_Game->GetView()->GetFOV()); + camera.SetProjection(CGame::GetGame()->GetView()->GetNear(), CGame::GetGame()->GetView()->GetFar(), CGame::GetGame()->GetView()->GetFOV()); camera.UpdateFrustum(); ::Render(); @@ -352,12 +352,12 @@ CCamera& AtlasViewGame::GetCamera() { - return *g_Game->GetView()->GetCamera(); + return *CGame::GetGame()->GetView()->GetCamera(); } bool AtlasViewGame::WantsHighFramerate() { - if (g_Game->GetView()->GetCinema()->IsPlaying()) + if (CGame::GetGame()->GetView()->GetCinema()->IsPlaying()) return true; if (m_SpeedMultiplier != 0.f) @@ -400,7 +400,7 @@ std::stringstream stream; if (binary) { - if (! g_Game->GetSimulation2()->SerializeState(stream)) + if (! CGame::GetGame()->GetSimulation2()->SerializeState(stream)) return L"(internal error)"; // We can't return raw binary data, because we want to handle it with wxJS which // doesn't like \0 bytes in strings, so return it as hex @@ -418,7 +418,7 @@ } else { - if (! g_Game->GetSimulation2()->DumpDebugState(stream)) + if (! CGame::GetGame()->GetSimulation2()->DumpDebugState(stream)) return L"(internal error)"; return wstring_from_utf8(stream.str()); }