Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit fb90ec4

Browse files
committed
Made LoadingGUI a singleton, members are no longer static and have been renamed slightly
Added clear method to it and used that in default constructor Disabled clone constructor and = operator
1 parent 4dc0765 commit fb90ec4

File tree

3 files changed

+67
-43
lines changed

3 files changed

+67
-43
lines changed

Main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ int g_DifficultySetting = 4;
133133
int g_StationOffsetX;
134134
int g_StationOffsetY;
135135

136-
LoadingGUI *g_LoadingGUI;
137136
MainMenuGUI *g_pMainMenuGUI = 0;
138137
ScenarioGUI *g_pScenarioGUI = 0;
139138
Controller *g_pMainMenuController = 0;
@@ -1958,7 +1957,8 @@ int main(int argc, char *argv[]) {
19581957
g_AudioMan.SetMusicVolume(0);
19591958
}
19601959

1961-
g_LoadingGUI->InitLoadingScreen();
1960+
new LoadingGUI();
1961+
g_LoadingGUI.InitLoadingScreen();
19621962
InitMainMenu();
19631963

19641964
if (g_LaunchIntoEditor) {

Menus/LoadingGUI.cpp

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,26 @@ extern volatile bool g_Quit;
2020

2121
namespace RTE {
2222

23-
GUIControlManager *LoadingGUI::s_LoadingGUI = 0;
24-
AllegroInput *LoadingGUI::s_GUIInput = 0;
25-
AllegroScreen *LoadingGUI::s_GUIScreen = 0;
26-
Writer *LoadingGUI::s_LoadingLogWriter = 0;
27-
BITMAP *LoadingGUI::s_LoadingGUIBitmap = 0;
28-
int LoadingGUI::s_LoadingGUIPosX = 0;
29-
int LoadingGUI::s_LoadingGUIPosY = 0;
23+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
24+
25+
void LoadingGUI::Clear() {
26+
m_ControlManager = 0;
27+
m_GUIInput = 0;
28+
m_GUIScreen = 0;
29+
m_LoadingLogWriter = 0;
30+
m_LoadingGUIBitmap = 0;
31+
m_PosX = 0;
32+
m_PosY = 0;
33+
}
3034

3135
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3236

3337
void LoadingGUI::InitLoadingScreen() {
3438
g_FrameMan.LoadPalette("Base.rte/palette.bmp");
3539

3640
// Create the main GUI
37-
s_GUIInput = new AllegroInput(-1);
38-
s_GUIScreen = new AllegroScreen(g_FrameMan.GetBackBuffer32());
41+
m_GUIInput = new AllegroInput(-1);
42+
m_GUIScreen = new AllegroScreen(g_FrameMan.GetBackBuffer32());
3943

4044
// Loading splash screen
4145
g_FrameMan.ClearBackBuffer32();
@@ -55,22 +59,22 @@ namespace RTE {
5559
g_FrameMan.FlipFrameBuffers();
5660

5761
// Set up the loading GUI
58-
if (!s_LoadingGUI) {
59-
s_LoadingGUI = new GUIControlManager();
62+
if (!m_ControlManager) {
63+
m_ControlManager = new GUIControlManager();
6064

6165
// TODO: This should be using the 32bpp main menu skin, but isn't because it needs the config of the base for its listbox
6266
// Can get away with this hack for now because the list box that the loading menu uses displays ok when drawn on a 32bpp buffer,
6367
// when it's 8bpp internally, since it does not use any masked_blit calls to draw list boxes.
6468
// Note also how the GUIScreen passed in here has been created with an 8bpp bitmap, since that is what determines what the GUI manager uses internally
65-
if (!s_LoadingGUI->Create(s_GUIScreen, s_GUIInput, "Base.rte/GUIs/Skins/MainMenu", "LoadingSkin.ini")) {
69+
if (!m_ControlManager->Create(m_GUIScreen, m_GUIInput, "Base.rte/GUIs/Skins/MainMenu", "LoadingSkin.ini")) {
6670
RTEAbort("Failed to create GUI Control Manager and load it from Base.rte/GUIs/Skins/MainMenu/LoadingSkin.ini");
6771
}
68-
s_LoadingGUI->Load("Base.rte/GUIs/LoadingGUI.ini");
72+
m_ControlManager->Load("Base.rte/GUIs/LoadingGUI.ini");
6973
}
7074

7175
// Place and clear the sectionProgress box
72-
dynamic_cast<GUICollectionBox *>(s_LoadingGUI->GetControl("root"))->SetSize(g_FrameMan.GetResX(), g_FrameMan.GetResY());
73-
GUIListBox *pBox = dynamic_cast<GUIListBox *>(s_LoadingGUI->GetControl("ProgressBox"));
76+
dynamic_cast<GUICollectionBox *>(m_ControlManager->GetControl("root"))->SetSize(g_FrameMan.GetResX(), g_FrameMan.GetResY());
77+
GUIListBox *pBox = dynamic_cast<GUIListBox *>(m_ControlManager->GetControl("ProgressBox"));
7478
// Make the box a bit bigger if there's room in higher, HD resolutions
7579
if (g_FrameMan.GetResX() >= 960) {
7680
// Make the loading progress box fill the right third of the screen
@@ -83,17 +87,17 @@ namespace RTE {
8387
pBox->ClearList();
8488

8589
// New mechanism to speed up loading times as it turned out that a massive amount of time is spent to update GUI control.
86-
if (!g_SettingsMan.DisableLoadingScreen() && !s_LoadingGUIBitmap) {
90+
if (!g_SettingsMan.DisableLoadingScreen() && !m_LoadingGUIBitmap) {
8791
pBox->SetVisible(false);
88-
s_LoadingGUIBitmap = create_bitmap_ex(8, pBox->GetWidth(), pBox->GetHeight());
89-
clear_to_color(s_LoadingGUIBitmap, 54);
90-
rect(s_LoadingGUIBitmap, 0, 0, pBox->GetWidth() - 1, pBox->GetHeight() - 1, 33);
91-
rect(s_LoadingGUIBitmap, 1, 1, pBox->GetWidth() - 2, pBox->GetHeight() - 2, 33);
92-
s_LoadingGUIPosX = pBox->GetXPos();
93-
s_LoadingGUIPosY = pBox->GetYPos();
92+
m_LoadingGUIBitmap = create_bitmap_ex(8, pBox->GetWidth(), pBox->GetHeight());
93+
clear_to_color(m_LoadingGUIBitmap, 54);
94+
rect(m_LoadingGUIBitmap, 0, 0, pBox->GetWidth() - 1, pBox->GetHeight() - 1, 33);
95+
rect(m_LoadingGUIBitmap, 1, 1, pBox->GetWidth() - 2, pBox->GetHeight() - 2, 33);
96+
m_PosX = pBox->GetXPos();
97+
m_PosY = pBox->GetYPos();
9498
}
9599
// Create the loading log writer
96-
if (!s_LoadingLogWriter) { s_LoadingLogWriter = new Writer("LogLoading.txt"); }
100+
if (!m_LoadingLogWriter) { m_LoadingLogWriter = new Writer("LogLoading.txt"); }
97101

98102
// Load all the data modules
99103
LoadDataModules();
@@ -104,26 +108,26 @@ namespace RTE {
104108
void LoadingGUI::LoadingSplashProgressReport(std::string reportString, bool newItem) {
105109
if (g_System.GetLogToCLI()) { g_System.PrintLoadingToCLI(reportString, newItem); }
106110

107-
if (s_LoadingGUI) {
111+
if (g_LoadingGUI.m_ControlManager) {
108112
g_UInputMan.Update();
109113
if (newItem) {
110114
// Write out the last line to the log file before starting a new one
111-
if (s_LoadingLogWriter->WriterOK()) { *s_LoadingLogWriter << reportString << "\n"; }
115+
if (g_LoadingGUI.m_LoadingLogWriter->WriterOK()) { *g_LoadingGUI.m_LoadingLogWriter << reportString << "\n"; }
112116
// Scroll bitmap upwards
113-
if (s_LoadingGUIBitmap) { blit(s_LoadingGUIBitmap, s_LoadingGUIBitmap, 2, 12, 2, 2, s_LoadingGUIBitmap->w - 3, s_LoadingGUIBitmap->h - 12); }
117+
if (g_LoadingGUI.m_LoadingGUIBitmap) { blit(g_LoadingGUI.m_LoadingGUIBitmap, g_LoadingGUI.m_LoadingGUIBitmap, 2, 12, 2, 2, g_LoadingGUI.m_LoadingGUIBitmap->w - 3, g_LoadingGUI.m_LoadingGUIBitmap->h - 12); }
114118
}
115-
if (s_LoadingGUIBitmap) {
116-
AllegroBitmap bmp(s_LoadingGUIBitmap);
119+
if (g_LoadingGUI.m_LoadingGUIBitmap) {
120+
AllegroBitmap bmp(g_LoadingGUI.m_LoadingGUIBitmap);
117121
// Clear current line
118-
rectfill(s_LoadingGUIBitmap, 2, s_LoadingGUIBitmap->h - 12, s_LoadingGUIBitmap->w - 3, s_LoadingGUIBitmap->h - 3, 54);
122+
rectfill(g_LoadingGUI.m_LoadingGUIBitmap, 2, g_LoadingGUI.m_LoadingGUIBitmap->h - 12, g_LoadingGUI.m_LoadingGUIBitmap->w - 3, g_LoadingGUI.m_LoadingGUIBitmap->h - 3, 54);
119123
// Print new line
120-
g_FrameMan.GetSmallFont()->DrawAligned(&bmp, 5, s_LoadingGUIBitmap->h - 12, reportString.c_str(), GUIFont::Left);
124+
g_FrameMan.GetSmallFont()->DrawAligned(&bmp, 5, g_LoadingGUI.m_LoadingGUIBitmap->h - 12, reportString.c_str(), GUIFont::Left);
121125
// DrawAligned - MaxWidth is useless here, so we're just drawing lines manually
122-
vline(s_LoadingGUIBitmap, s_LoadingGUIBitmap->w - 2, s_LoadingGUIBitmap->h - 12, s_LoadingGUIBitmap->h - 2, 33);
123-
vline(s_LoadingGUIBitmap, s_LoadingGUIBitmap->w - 1, s_LoadingGUIBitmap->h - 12, s_LoadingGUIBitmap->h - 2, 33);
126+
vline(g_LoadingGUI.m_LoadingGUIBitmap, g_LoadingGUI.m_LoadingGUIBitmap->w - 2, g_LoadingGUI.m_LoadingGUIBitmap->h - 12, g_LoadingGUI.m_LoadingGUIBitmap->h - 2, 33);
127+
vline(g_LoadingGUI.m_LoadingGUIBitmap, g_LoadingGUI.m_LoadingGUIBitmap->w - 1, g_LoadingGUI.m_LoadingGUIBitmap->h - 12, g_LoadingGUI.m_LoadingGUIBitmap->h - 2, 33);
124128

125129
// Draw onto current frame buffer
126-
blit(s_LoadingGUIBitmap, g_FrameMan.GetBackBuffer32(), 0, 0, s_LoadingGUIPosX, s_LoadingGUIPosY, s_LoadingGUIBitmap->w, s_LoadingGUIBitmap->h);
130+
blit(g_LoadingGUI.m_LoadingGUIBitmap, g_FrameMan.GetBackBuffer32(), 0, 0, g_LoadingGUI.m_PosX, g_LoadingGUI.m_PosY, g_LoadingGUI.m_LoadingGUIBitmap->w, g_LoadingGUI.m_LoadingGUIBitmap->h);
127131

128132
g_FrameMan.FlipFrameBuffers();
129133
}

Menus/LoadingGUI.h

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#ifndef _LOADINGUI_
22
#define _LOADINGGUI_
33

4+
#include "Singleton.h"
5+
46
struct BITMAP;
57

8+
#define g_LoadingGUI LoadingGUI::Instance()
9+
610
namespace RTE {
711

812
class AllegroScreen;
@@ -13,10 +17,15 @@ namespace RTE {
1317
/// <summary>
1418
/// Represents the loading screen GUI when starting the game.
1519
/// </summary>
16-
class LoadingGUI {
20+
class LoadingGUI : public Singleton<LoadingGUI> {
1721

1822
public:
1923

24+
/// <summary>
25+
/// Constructor method used to instantiate a LoadingGUI object in system memory.
26+
/// </summary>
27+
LoadingGUI() { Clear(); }
28+
2029
/// <summary>
2130
/// Creates the loading screen and the log writer, then calls loading all the modules.
2231
/// </summary>
@@ -47,14 +56,25 @@ namespace RTE {
4756
static const unsigned int s_FileBufferSize = 8192; //!< Buffer to hold data read from the zip file.
4857
static const unsigned int s_MaxUnzippedFileSize = 104857600; //!< Maximum size of single file being extracted from zip archive (100MiB).
4958

50-
static GUIControlManager *s_LoadingGUI; //!< Manager of the whole LoadingGUI.
51-
static AllegroInput *s_GUIInput; //!< Input interface of this.
52-
static AllegroScreen *s_GUIScreen; //!< Screen interface of this.
53-
static Writer *s_LoadingLogWriter; //!< The Writer that generates the loading log.
59+
GUIControlManager *m_ControlManager; //!< Manager of the whole LoadingGUI.
60+
AllegroInput *m_GUIInput; //!< Input interface of this.
61+
AllegroScreen *m_GUIScreen; //!< Screen interface of this.
62+
Writer *m_LoadingLogWriter; //!< The Writer that generates the loading log.
63+
BITMAP *m_LoadingGUIBitmap; //!< BITMAP that the progress report will be drawn into.
64+
65+
int m_PosX; //!< Position of the progress report box on X axis.
66+
int m_PosY; //!< Position of the progress report box on Y axis.
67+
68+
private:
69+
70+
/// <summary>
71+
/// Clears all the member variables of this LoadingGUI, effectively resetting the members of this abstraction level only.
72+
/// </summary>
73+
void Clear();
5474

55-
static BITMAP *s_LoadingGUIBitmap; //!< BITMAP that the progress report will be drawn into.
56-
static int s_LoadingGUIPosX; //!< Position of the progress report box on X axis.
57-
static int s_LoadingGUIPosY; //!< Position of the progress report box on Y axis.
75+
// Disallow the use of some implicit methods.
76+
LoadingGUI(const LoadingGUI &reference) {}
77+
LoadingGUI &operator=(const LoadingGUI &rhs) {}
5878
};
5979
}
6080
#endif

0 commit comments

Comments
 (0)