From 4d7ca74c55edff30e34df1c36824a128211bfeb8 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 6 Apr 2022 21:35:26 +0200 Subject: Moved world ownership to concrete game classes --- StarsEx/Game.cpp | 4 ---- StarsEx/Game.h | 6 ------ StarsEx/StarServer.cpp | 14 +++++++++----- StarsEx/StarServer.h | 3 +++ StarsEx/Starshatter.cpp | 6 +++--- StarsEx/Starshatter.h | 3 +++ 6 files changed, 18 insertions(+), 18 deletions(-) (limited to 'StarsEx') diff --git a/StarsEx/Game.cpp b/StarsEx/Game.cpp index 3d3315e..54f9204 100644 --- a/StarsEx/Game.cpp +++ b/StarsEx/Game.cpp @@ -28,7 +28,6 @@ Game* Game::instance {nullptr}; Game::Game() : - world {nullptr}, status {OK}, exit_code {0}, game_mode {MENU_MODE}, @@ -48,7 +47,6 @@ Game::Game() : Game::~Game() { Clock::Close(); - if (world) delete world; if (instance == this) instance = nullptr; } @@ -155,8 +153,6 @@ Game::GameLoop() void Game::UpdateWorld() { - if (world) - world->ExecFrame(Clock::GetInstance()->Delta()); } // +--------------------------------------------------------------------+ diff --git a/StarsEx/Game.h b/StarsEx/Game.h index 48629c6..b350e2c 100644 --- a/StarsEx/Game.h +++ b/StarsEx/Game.h @@ -14,10 +14,6 @@ // +--------------------------------------------------------------------+ -class Universe; - -// +--------------------------------------------------------------------+ - class Game { public: @@ -74,8 +70,6 @@ public: virtual bool InitGame(); protected: - Universe* world; - int status; int exit_code; int game_mode; diff --git a/StarsEx/StarServer.cpp b/StarsEx/StarServer.cpp index eea6784..7d6d8bc 100644 --- a/StarsEx/StarServer.cpp +++ b/StarsEx/StarServer.cpp @@ -65,9 +65,13 @@ static bool exit_latch = true; // +--------------------------------------------------------------------+ -StarServer::StarServer() -: loader(0), time_mark(0), minutes(0), -admin_server(0), lobby_server(0) +StarServer::StarServer() : + world {nullptr}, + loader(0), + time_mark(0), + minutes(0), + admin_server(0), + lobby_server(0) { if (instance != nullptr) throw "StarServer may have only one instance"; @@ -109,8 +113,8 @@ StarServer::~StarServer() // delete all the ships and stuff // BEFORE getting rid of the system // and weapons catalogs! - delete world; - world = 0; // don't let base class double delete the world + if (world) delete world; + world = nullptr; Drive::Close(); Explosion::Close(); diff --git a/StarsEx/StarServer.h b/StarsEx/StarServer.h index f1562bc..7b13c13 100644 --- a/StarsEx/StarServer.h +++ b/StarsEx/StarServer.h @@ -17,6 +17,7 @@ // +--------------------------------------------------------------------+ +class Universe; class Campaign; class Ship; class Sim; @@ -54,6 +55,8 @@ protected: virtual void UpdateWorld(); virtual void InstantiateMission(); + Universe* world; + NetServer* admin_server; NetLobbyServer* lobby_server; DataLoader* loader; diff --git a/StarsEx/Starshatter.cpp b/StarsEx/Starshatter.cpp index 23ba839..5121d33 100644 --- a/StarsEx/Starshatter.cpp +++ b/StarsEx/Starshatter.cpp @@ -144,7 +144,7 @@ enum CHAT_MODES { // +--------------------------------------------------------------------+ Starshatter::Starshatter() -: gamewin(0), menuscreen(0), loadscreen(0), planscreen(0), +: world{nullptr}, gamewin(0), menuscreen(0), loadscreen(0), planscreen(0), cmpnscreen(0), gamescreen(0), splash(0), splash_index(0), input(0), loader(0), cam_dir(0), music_dir(0), field_of_view(2), time_mark(0), minutes(0), @@ -264,8 +264,8 @@ Starshatter::~Starshatter() // delete all the ships and stuff // BEFORE getting rid of the system // and weapons catalogs! - delete world; - world = 0; // don't let base class double delete the world + if (world) delete world; + world = nullptr; delete quick_mission; diff --git a/StarsEx/Starshatter.h b/StarsEx/Starshatter.h index ecd1a62..78673cb 100644 --- a/StarsEx/Starshatter.h +++ b/StarsEx/Starshatter.h @@ -35,6 +35,7 @@ class DataLoader; class Font; class TrackIR; class Mission; +class Universe; class NetServer; class NetLobby; @@ -132,6 +133,8 @@ protected: virtual bool ResizeVideo(); virtual void InitMouse(); + Universe* world; + Window* gamewin; MenuScreen* menuscreen; LoadScreen* loadscreen; -- cgit v1.1