From 947910fc3c541ffdab3b042cfa3a3926b64f0ba3 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 6 Apr 2022 21:28:00 +0200 Subject: Streamlined instance management for Game and derived classes --- StarsEx/Starshatter.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'StarsEx/Starshatter.cpp') diff --git a/StarsEx/Starshatter.cpp b/StarsEx/Starshatter.cpp index 65c7d13..23ba839 100644 --- a/StarsEx/Starshatter.cpp +++ b/StarsEx/Starshatter.cpp @@ -121,7 +121,7 @@ Mission* quick_mission = 0; int Starshatter::keymap[256]; int Starshatter::keyalt[256]; -Starshatter* Starshatter::instance = 0; +Starshatter* Starshatter::instance {nullptr}; static Mission* current_mission = 0; static Mission* cutscene_mission = 0; @@ -158,7 +158,8 @@ lens_flare(true), corona(true), nebula(true), dust(0), load_step(0), load_progress(0), chat_mode(0), exit_time(1.2), cutscene(0) { - if (!instance) + if (instance != nullptr) + throw "Starshatter may have only one instance"; instance = this; app_name = "Starshatter: The Open Source Project"; @@ -311,7 +312,8 @@ Starshatter::~Starshatter() delete input; delete head_tracker; - instance = 0; + if (instance == this) + instance = nullptr; } void -- cgit v1.1