summaryrefslogtreecommitdiffhomepage
path: root/StarsEx/Game.cpp
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-04-06 21:28:00 +0200
committerAki <please@ignore.pl>2022-04-06 21:53:47 +0200
commit947910fc3c541ffdab3b042cfa3a3926b64f0ba3 (patch)
treea4d6b261d0edaa516d34b3fcb4baa8f84381adad /StarsEx/Game.cpp
parenta793e933b1e7e5b62fe4e15403e1d5fb33dc2dd4 (diff)
downloadstarshatter-947910fc3c541ffdab3b042cfa3a3926b64f0ba3.zip
starshatter-947910fc3c541ffdab3b042cfa3a3926b64f0ba3.tar.gz
starshatter-947910fc3c541ffdab3b042cfa3a3926b64f0ba3.tar.bz2
Streamlined instance management for Game and derived classes
Diffstat (limited to 'StarsEx/Game.cpp')
-rw-r--r--StarsEx/Game.cpp42
1 files changed, 18 insertions, 24 deletions
diff --git a/StarsEx/Game.cpp b/StarsEx/Game.cpp
index 272dd17..3d3315e 100644
--- a/StarsEx/Game.cpp
+++ b/StarsEx/Game.cpp
@@ -23,40 +23,34 @@
#include "WndProc.h"
#include "SoundCard.h"
-// +--------------------------------------------------------------------+
-Game* game = 0;
+Game* Game::instance {nullptr};
-// +--------------------------------------------------------------------+
Game::Game() :
- world(0),
- status(Game::OK),
- exit_code(0),
- game_mode(MENU_MODE)
+ world {nullptr},
+ status {OK},
+ exit_code {0},
+ game_mode {MENU_MODE},
+ active {false},
+ paused {false},
+ server {false},
+ show_mouse {false},
+ frame_number {0}
{
+ if (instance != nullptr)
+ throw "Game may have only one instance";
+ instance = this;
Clock::Init();
- if (!game) {
- game = this;
-
- active = false;
- paused = false;
- server = false;
- show_mouse = false;
- frame_number = 0;
- }
- else
- status = TOO_MANY;
}
+
Game::~Game()
{
- if (game == this)
- game = 0;
-
Clock::Close();
-
- delete world;
+ if (world) delete world;
+ if (instance == this)
+ instance = nullptr;
}
// +--------------------------------------------------------------------+
@@ -184,7 +178,7 @@ Game::UpdateScreen()
Game*
Game::GetInstance()
{
- return game;
+ return instance;
}
// +--------------------------------------------------------------------+