summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-02-17 10:26:46 +0100
committerAki <please@ignore.pl>2022-02-17 10:26:46 +0100
commit2ae135bbe43065978a4659278d18d9533d8a3b27 (patch)
tree4ac25460a2d7fb9ef1a478b3da59f6ae78b6bda1
parentf49d139c6bb975a68478eedd9763028443f47d25 (diff)
downloadstarshatter-2ae135bbe43065978a4659278d18d9533d8a3b27.zip
starshatter-2ae135bbe43065978a4659278d18d9533d8a3b27.tar.gz
starshatter-2ae135bbe43065978a4659278d18d9533d8a3b27.tar.bz2
Everything but panic and singleton impl is now instance based
-rw-r--r--Stars45/Game.cpp39
-rw-r--r--Stars45/Game.h80
2 files changed, 56 insertions, 63 deletions
diff --git a/Stars45/Game.cpp b/Stars45/Game.cpp
index d0a5735..c1c4463 100644
--- a/Stars45/Game.cpp
+++ b/Stars45/Game.cpp
@@ -744,15 +744,13 @@ Game::InitContent()
void
Game::UseLocale(Locale* locale)
{
- if (game) {
- DataLoader* loader = DataLoader::GetLoader();
- loader->SetDataPath("Content/");
- delete game->content;
+ DataLoader* loader = DataLoader::GetLoader();
+ loader->SetDataPath("Content/");
+ delete content;
- game->content = new(__FILE__,__LINE__) ContentBundle("content", locale);
+ content = new(__FILE__,__LINE__) ContentBundle("content", locale);
- loader->SetDataPath(0);
- }
+ loader->SetDataPath(0);
}
// +--------------------------------------------------------------------+
@@ -1012,28 +1010,22 @@ Game::GetVideo()
Color
Game::GetScreenColor()
{
- if (game)
- return game->screen_color;
-
- return Color::Black;
+ return screen_color;
}
void
Game::SetScreenColor(Color c)
{
- if (game) {
- game->screen_color = c;
-
- if (game->screen)
- game->screen->SetBackgroundColor(c);
- }
+ screen_color = c;
+ if (screen)
+ screen->SetBackgroundColor(c);
}
int
Game::GetScreenWidth()
{
- if (game && game->video)
- return game->video->Width();
+ if (video)
+ return video->Width();
return 0;
}
@@ -1041,8 +1033,8 @@ Game::GetScreenWidth()
int
Game::GetScreenHeight()
{
- if (game && game->video)
- return game->video->Height();
+ if (video)
+ return video->Height();
return 0;
}
@@ -1141,7 +1133,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM uParam, LPARAM lParam)
break;
case WM_SETCURSOR:
- if (Game::ShowMouse()) {
+ if (game && game->ShowMouse()) {
return DefWindowProc(hwnd, message, uParam, lParam);
}
else {
@@ -1366,8 +1358,9 @@ GetKeyPlus(int& key, int& shift)
DWORD GetRealTime()
{
+ Game* game = Game::GetInstance();
if (game)
- return Game::RealTime();
+ return game->RealTime();
return timeGetTime();
}
diff --git a/Stars45/Game.h b/Stars45/Game.h
index 9463338..6245b40 100644
--- a/Stars45/Game.h
+++ b/Stars45/Game.h
@@ -67,50 +67,50 @@ public:
// GENERAL GAME CLASS UTILITY METHODS:
//
- static void Panic(const char* msg=0);
+ static Game* GetInstance();
+ static void Panic(const char* msg=0);
+ static const char* GetPanicMessage() { return panicbuf; }
+
bool DisplayModeSupported(int w, int h, int bpp);
- static int MaxTexSize();
- static int MaxTexAspect();
- static int GammaLevel();
- static void SetGammaLevel(int g);
- static void SetMaxTexSize(int n);
-
- static DWORD RealTime();
- static DWORD GameTime();
- static DWORD TimeCompression();
- static void SetTimeCompression(DWORD comp);
- static DWORD Frame();
- static void ResetGameTime();
- static void SkipGameTime(double seconds);
-
- static double FrameRate();
- static double FrameTime();
- static double GUITime();
- static void SetMaxFrameLength(double seconds) { max_frame_length = seconds; }
- static void SetMinFrameLength(double seconds) { min_frame_length = seconds; }
- static double GetMaxFrameLength() { return max_frame_length; }
- static double GetMinFrameLength() { return min_frame_length; }
-
- static Game* GetInstance();
- Video* GetVideo();
- static Color GetScreenColor();
- static void SetScreenColor(Color c);
- static int GetScreenWidth();
- static int GetScreenHeight();
+ int MaxTexSize();
+ int MaxTexAspect();
+ int GammaLevel();
+ void SetGammaLevel(int g);
+ void SetMaxTexSize(int n);
+
+ DWORD RealTime();
+ DWORD GameTime();
+ DWORD TimeCompression();
+ void SetTimeCompression(DWORD comp);
+ DWORD Frame();
+ void ResetGameTime();
+ void SkipGameTime(double seconds);
+
+ double FrameRate();
+ double FrameTime();
+ double GUITime();
+ void SetMaxFrameLength(double seconds) { max_frame_length = seconds; }
+ void SetMinFrameLength(double seconds) { min_frame_length = seconds; }
+ double GetMaxFrameLength() { return max_frame_length; }
+ double GetMinFrameLength() { return min_frame_length; }
- static bool Active() { return active; }
- static bool Paused() { return paused; }
- static bool Server() { return server; }
- static bool ShowMouse() { return show_mouse; }
- static bool IsWindowed();
+ Video* GetVideo();
+ Color GetScreenColor();
+ void SetScreenColor(Color c);
+ int GetScreenWidth();
+ int GetScreenHeight();
- static HINSTANCE GetHINST();
- static HWND GetHWND();
+ bool Active() { return active; }
+ bool Paused() { return paused; }
+ bool Server() { return server; }
+ bool ShowMouse() { return show_mouse; }
+ bool IsWindowed();
- static void UseLocale(Locale* locale);
- static Text GetText(const char* key);
+ HINSTANCE GetHINST();
+ HWND GetHWND();
- static const char* GetPanicMessage() { return panicbuf; }
+ void UseLocale(Locale* locale);
+ Text GetText(const char* key);
virtual bool GameLoop();
virtual void UpdateWorld();
@@ -199,7 +199,7 @@ protected:
double max_frame_length;
double min_frame_length;
- char panicbuf[256];
+ static char panicbuf[256];
};
// +--------------------------------------------------------------------+