diff options
author | Aki <please@ignore.pl> | 2022-04-06 23:48:24 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-04-06 23:48:24 +0200 |
commit | c7644a37b7801a8a1755cf6219443375797a57c5 (patch) | |
tree | 5ee7eefb6f0588ff82b1e525f0c6ce3291b52248 /StarsEx | |
parent | e644842058be99729b90b1def4ad11573d515e6f (diff) | |
download | starshatter-c7644a37b7801a8a1755cf6219443375797a57c5.zip starshatter-c7644a37b7801a8a1755cf6219443375797a57c5.tar.gz starshatter-c7644a37b7801a8a1755cf6219443375797a57c5.tar.bz2 |
Removed DataLoader "ownership" by StarServer
Actually, I will probably revert it soon enough but other changes to
DataLoader initialization are worth it. Handling this singleton mess is
rather interesting and I'm still looking for a solution that will be
nice to look at.
Diffstat (limited to 'StarsEx')
-rw-r--r-- | StarsEx/StarServer.cpp | 29 | ||||
-rw-r--r-- | StarsEx/StarServer.h | 2 |
2 files changed, 13 insertions, 18 deletions
diff --git a/StarsEx/StarServer.cpp b/StarsEx/StarServer.cpp index 22e89ec..29e9470 100644 --- a/StarsEx/StarServer.cpp +++ b/StarsEx/StarServer.cpp @@ -55,8 +55,7 @@ StarServer::StarServer() : world {nullptr}, current_mission {nullptr}, admin_server {nullptr}, - lobby_server {nullptr}, - loader {nullptr} + lobby_server {nullptr} { if (instance != nullptr) throw "StarServer may have only one instance"; @@ -65,23 +64,22 @@ StarServer::StarServer() : show_mouse = true; DataLoader::Initialize(); - loader = DataLoader::GetLoader(); - int loadstat = loader->EnableDatafile("shatter.dat"); + auto loader = DataLoader::GetLoader(); + if (!loader) throw "Could not get DataLoader instance"; + int loadstat = loader->EnableDatafile("shatter.dat"); if (loadstat != DataLoader::DATAFILE_OK) { - const char* err_msg = loadstat == DataLoader::DATAFILE_INVALID ? - "The file 'shatter.dat' appears to have been damaged. Please re-install Starshatter." : - "Starshatter cannot open the file 'shatter.dat'. Please re-install Starshatter."; - - ::Print(err_msg); - ::Print("\n\nFATAL ERROR: EXIT."); - exit(-1); + if (loadstat == DataLoader::DATAFILE_INVALID) { + throw "The file 'shatter.dat' appears to have been damaged."; + } + else { + throw "Starshatter cannot open the file 'shatter.dat'. Please check current directory."; + } } if (loader->FindFile("start.dat")) - loader->EnableDatafile("start.dat"); + loader->EnableDatafile("start.dat"); - // no images or sounds in server mode: loader->EnableMedia(false); } @@ -122,9 +120,8 @@ StarServer::~StarServer() bool StarServer::Init(HINSTANCE hi, HINSTANCE hpi, LPSTR cmdline, int nCmdShow) { - if (loader) - loader->UseFileSystem(false); - + if (auto loader = DataLoader::GetLoader()) + loader->UseFileSystem(false); return Game::Init(hi, hpi, cmdline, nCmdShow); } diff --git a/StarsEx/StarServer.h b/StarsEx/StarServer.h index dd0e866..81c846b 100644 --- a/StarsEx/StarServer.h +++ b/StarsEx/StarServer.h @@ -10,7 +10,6 @@ #ifndef StarServer_h #define StarServer_h -#include "DataLoader.h" #include "Game.h" #include "NetLobbyServer.h" #include "NetServer.h" @@ -45,7 +44,6 @@ protected: NetServer* admin_server; NetLobbyServer* lobby_server; - DataLoader* loader; private: static StarServer* instance; |