Index: ps/trunk/source/network/scripting/JSInterface_Network.cpp =================================================================== --- ps/trunk/source/network/scripting/JSInterface_Network.cpp +++ ps/trunk/source/network/scripting/JSInterface_Network.cpp @@ -66,7 +66,7 @@ return; } - g_Game = new CGame(); + g_Game = new CGame(true); g_NetClient = new CNetClient(g_Game, true); g_NetClient->SetUserName(playerName); g_NetClient->SetHostingPlayerName(hostLobbyName); @@ -116,7 +116,7 @@ SDL_Delay(1000); } - g_Game = new CGame(); + g_Game = new CGame(true); g_NetClient = new CNetClient(g_Game, false); g_NetClient->SetUserName(playerName); g_NetClient->SetHostingPlayerName(hostJID.substr(0, hostJID.find("@"))); Index: ps/trunk/source/network/tests/test_Net.h =================================================================== --- ps/trunk/source/network/tests/test_Net.h +++ ps/trunk/source/network/tests/test_Net.h @@ -144,9 +144,9 @@ std::vector clients; - CGame client1Game(true); - CGame client2Game(true); - CGame client3Game(true); + CGame client1Game(false); + CGame client2Game(false); + CGame client3Game(false); CNetServer server; @@ -209,9 +209,9 @@ std::vector clients; - CGame client1Game(true); - CGame client2Game(true); - CGame client3Game(true); + CGame client1Game(false); + CGame client2Game(false); + CGame client3Game(false); CNetServer server; @@ -270,7 +270,7 @@ debug_printf("==== Connecting client 2B\n"); - CGame client2BGame(true); + CGame client2BGame(false); CNetClient client2B(&client2BGame, false); client2B.SetUserName(L"bob"); clients.push_back(&client2B); Index: ps/trunk/source/ps/Game.h =================================================================== --- ps/trunk/source/ps/Game.h +++ ps/trunk/source/ps/Game.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -81,7 +81,7 @@ CTurnManager* m_TurnManager; public: - CGame(bool disableGraphics = false, bool replayLog = true); + CGame(bool replayLog); ~CGame(); /** @@ -142,16 +142,6 @@ } /** - * Get if the graphics is disabled. - * - * @return bool true if the m_GameView is NULL, false otherwise. - */ - inline bool IsGraphicsDisabled() const - { - return !m_GameView; - } - - /** * Get m_IsVisualReplay. * * @return bool the value of m_IsVisualReplay. Index: ps/trunk/source/ps/Game.cpp =================================================================== --- ps/trunk/source/ps/Game.cpp +++ ps/trunk/source/ps/Game.cpp @@ -63,10 +63,10 @@ * Constructor * **/ -CGame::CGame(bool disableGraphics, bool replayLog): +CGame::CGame(bool replayLog): m_World(new CWorld(this)), m_Simulation2(new CSimulation2(&m_World->GetUnitManager(), g_ScriptRuntime, m_World->GetTerrain())), - m_GameView(disableGraphics ? NULL : new CGameView(this)), + m_GameView(CRenderer::IsInitialised() ? new CGameView(this) : nullptr), m_GameStarted(false), m_Paused(false), m_SimRate(1.0f), Index: ps/trunk/source/ps/GameSetup/GameSetup.cpp =================================================================== --- ps/trunk/source/ps/GameSetup/GameSetup.cpp +++ ps/trunk/source/ps/GameSetup/GameSetup.cpp @@ -696,17 +696,15 @@ void EndGame() { - const bool nonVisual = g_Game && g_Game->IsGraphicsDisabled(); - if (g_Game && g_Game->IsGameStarted() && !g_Game->IsVisualReplay() && - g_AtlasGameLoop && !g_AtlasGameLoop->running && !nonVisual) + g_AtlasGameLoop && !g_AtlasGameLoop->running && CRenderer::IsInitialised()) VisualReplay::SaveReplayMetadata(g_GUI->GetActiveGUI()->GetScriptInterface().get()); SAFE_DELETE(g_NetClient); SAFE_DELETE(g_NetServer); SAFE_DELETE(g_Game); - if (!nonVisual) + if (CRenderer::IsInitialised()) { ISoundManager::CloseGame(); g_Renderer.ResetState(); @@ -715,7 +713,7 @@ void Shutdown(int flags) { - const bool nonVisual = g_Game && g_Game->IsGraphicsDisabled(); + const bool hasRenderer = CRenderer::IsInitialised(); if ((flags & SHUTDOWN_FROM_CONFIG)) goto from_config; @@ -732,11 +730,10 @@ delete &g_TexMan; TIMER_END(L"shutdown TexMan"); - // destroy renderer if it was initialised - if (!nonVisual) + if (hasRenderer) { TIMER_BEGIN(L"shutdown Renderer"); - delete &g_Renderer; + g_Renderer.~CRenderer(); g_VBMan.Shutdown(); TIMER_END(L"shutdown Renderer"); } @@ -750,7 +747,7 @@ ShutdownSDL(); TIMER_END(L"shutdown SDL"); - if (!nonVisual) + if (hasRenderer) g_VideoMode.Shutdown(); TIMER_BEGIN(L"shutdown UserReporter"); @@ -1259,8 +1256,7 @@ if (autoStartName.empty()) return false; - const bool nonVisual = args.Has("autostart-nonvisual"); - g_Game = new CGame(nonVisual, !args.Has("autostart-disable-replay")); + g_Game = new CGame(!args.Has("autostart-disable-replay")); ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); JSContext* cx = scriptInterface.GetContext(); @@ -1532,7 +1528,7 @@ FromJSVal_vector(cx, triggerScripts, triggerScriptsVector); } - if (nonVisual) + if (!CRenderer::IsInitialised()) { CStr nonVisualScript = "scripts/NonVisualTrigger.js"; triggerScriptsVector.push_back(nonVisualScript.FromUTF8()); @@ -1626,14 +1622,16 @@ g_Game->StartGame(&attrs, ""); - if (nonVisual) + if (CRenderer::IsInitialised()) + { + InitPsAutostart(false, attrs); + } + else { // TODO: Non progressive load can fail - need a decent way to handle this LDR_NonprogressiveLoad(); ENSURE(g_Game->ReallyStartGame() == PSRETURN_OK); } - else - InitPsAutostart(false, attrs); } return true; @@ -1644,7 +1642,7 @@ if (!FileExists(OsPath(replayFile))) return false; - g_Game = new CGame(false, false); + g_Game = new CGame(false); g_Game->SetPlayerID(-1); g_Game->StartVisualReplay(replayFile); Index: ps/trunk/source/ps/Replay.cpp =================================================================== --- ps/trunk/source/ps/Replay.cpp +++ ps/trunk/source/ps/Replay.cpp @@ -183,7 +183,7 @@ Mod::CacheEnabledModVersions(g_ScriptRuntime); - g_Game = new CGame(true, false); + g_Game = new CGame(false); if (serializationtest) g_Game->GetSimulation2()->EnableSerializationTest(); if (rejointestturn > 0) Index: ps/trunk/source/ps/VisualReplay.cpp =================================================================== --- ps/trunk/source/ps/VisualReplay.cpp +++ ps/trunk/source/ps/VisualReplay.cpp @@ -65,7 +65,7 @@ if (!FileExists(replayFile)) return false; - g_Game = new CGame(false, false); + g_Game = new CGame(false); return g_Game->StartVisualReplay(replayFile); } Index: ps/trunk/source/ps/scripting/JSInterface_Game.cpp =================================================================== --- ps/trunk/source/ps/scripting/JSInterface_Game.cpp +++ ps/trunk/source/ps/scripting/JSInterface_Game.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -39,7 +39,7 @@ ENSURE(!g_NetClient); ENSURE(!g_Game); - g_Game = new CGame(); + g_Game = new CGame(true); // Convert from GUI script context to sim script context CSimulation2* sim = g_Game->GetSimulation2(); Index: ps/trunk/source/ps/scripting/JSInterface_SavedGame.cpp =================================================================== --- ps/trunk/source/ps/scripting/JSInterface_SavedGame.cpp +++ ps/trunk/source/ps/scripting/JSInterface_SavedGame.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -83,7 +83,7 @@ if (err < 0) return JS::UndefinedValue(); - g_Game = new CGame(); + g_Game = new CGame(true); { CSimulation2* sim = g_Game->GetSimulation2(); Index: ps/trunk/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp =================================================================== --- ps/trunk/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp +++ ps/trunk/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp @@ -57,7 +57,7 @@ g_Game = NULL; } - g_Game = new CGame(false, false); + g_Game = new CGame(false); // Default to player 1 for playtesting g_Game->SetPlayerID(1);