1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 01:59:43 +01:00

De-C++-ify struct ScreenSettings

This includes:
- Removing the constructor in favor of actually being able to see that
  there's an actual function called being made initializing the struct
- Removing the use of a reference in Screen::init() in favor of using a
  pointer
- Adding the struct qualifier everywhere (it's not much typing),
  although technically you could typedef it in C, but I'd rather much
  not typedef just to remove a tag qualifier
This commit is contained in:
Misa 2021-12-25 00:18:51 -08:00
parent d0ffafe117
commit 1e157f3cc9
6 changed files with 37 additions and 36 deletions

View file

@ -4021,7 +4021,7 @@ void Game::unlocknum( int t )
#endif #endif
} }
void Game::loadstats(ScreenSettings* screen_settings) void Game::loadstats(struct ScreenSettings* screen_settings)
{ {
tinyxml2::XMLDocument doc; tinyxml2::XMLDocument doc;
tinyxml2::XMLHandle hDoc(&doc); tinyxml2::XMLHandle hDoc(&doc);
@ -4100,7 +4100,7 @@ void Game::loadstats(ScreenSettings* screen_settings)
deserializesettings(dataNode, screen_settings); deserializesettings(dataNode, screen_settings);
} }
void Game::deserializesettings(tinyxml2::XMLElement* dataNode, ScreenSettings* screen_settings) void Game::deserializesettings(tinyxml2::XMLElement* dataNode, struct ScreenSettings* screen_settings)
{ {
// Don't duplicate controller buttons! // Don't duplicate controller buttons!
controllerButton_flip.clear(); controllerButton_flip.clear();
@ -4327,13 +4327,13 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, ScreenSettings* s
bool Game::savestats(bool sync /*= true*/) bool Game::savestats(bool sync /*= true*/)
{ {
ScreenSettings screen_settings; struct ScreenSettings screen_settings;
gameScreen.GetSettings(&screen_settings); gameScreen.GetSettings(&screen_settings);
return savestats(&screen_settings, sync); return savestats(&screen_settings, sync);
} }
bool Game::savestats(const ScreenSettings* screen_settings, bool sync /*= true*/) bool Game::savestats(const struct ScreenSettings* screen_settings, bool sync /*= true*/)
{ {
tinyxml2::XMLDocument doc; tinyxml2::XMLDocument doc;
bool already_exists = FILESYSTEM_loadTiXml2Document("saves/unlock.vvv", doc); bool already_exists = FILESYSTEM_loadTiXml2Document("saves/unlock.vvv", doc);
@ -4436,7 +4436,7 @@ void Game::savestatsandsettings_menu(void)
} }
} }
void Game::serializesettings(tinyxml2::XMLElement* dataNode, const ScreenSettings* screen_settings) void Game::serializesettings(tinyxml2::XMLElement* dataNode, const struct ScreenSettings* screen_settings)
{ {
tinyxml2::XMLDocument& doc = xml::get_document(dataNode); tinyxml2::XMLDocument& doc = xml::get_document(dataNode);
@ -4563,7 +4563,7 @@ void Game::serializesettings(tinyxml2::XMLElement* dataNode, const ScreenSetting
xml::update_tag(dataNode, "controllerSensitivity", key.sensitivity); xml::update_tag(dataNode, "controllerSensitivity", key.sensitivity);
} }
void Game::loadsettings(ScreenSettings* screen_settings) void Game::loadsettings(struct ScreenSettings* screen_settings)
{ {
tinyxml2::XMLDocument doc; tinyxml2::XMLDocument doc;
tinyxml2::XMLHandle hDoc(&doc); tinyxml2::XMLHandle hDoc(&doc);
@ -4592,13 +4592,13 @@ void Game::loadsettings(ScreenSettings* screen_settings)
bool Game::savesettings(void) bool Game::savesettings(void)
{ {
ScreenSettings screen_settings; struct ScreenSettings screen_settings;
gameScreen.GetSettings(&screen_settings); gameScreen.GetSettings(&screen_settings);
return savesettings(&screen_settings); return savesettings(&screen_settings);
} }
bool Game::savesettings(const ScreenSettings* screen_settings) bool Game::savesettings(const struct ScreenSettings* screen_settings)
{ {
tinyxml2::XMLDocument doc; tinyxml2::XMLDocument doc;
bool already_exists = FILESYSTEM_loadTiXml2Document("saves/settings.vvv", doc); bool already_exists = FILESYSTEM_loadTiXml2Document("saves/settings.vvv", doc);

View file

@ -165,20 +165,20 @@ public:
void unlocknum(int t); void unlocknum(int t);
void loadstats(ScreenSettings* screen_settings); void loadstats(struct ScreenSettings* screen_settings);
bool savestats(const ScreenSettings* screen_settings, bool sync = true); bool savestats(const struct ScreenSettings* screen_settings, bool sync = true);
bool savestats(bool sync = true); bool savestats(bool sync = true);
void deletestats(void); void deletestats(void);
void deserializesettings(tinyxml2::XMLElement* dataNode, ScreenSettings* screen_settings); void deserializesettings(tinyxml2::XMLElement* dataNode, struct ScreenSettings* screen_settings);
void serializesettings(tinyxml2::XMLElement* dataNode, const ScreenSettings* screen_settings); void serializesettings(tinyxml2::XMLElement* dataNode, const struct ScreenSettings* screen_settings);
void loadsettings(ScreenSettings* screen_settings); void loadsettings(struct ScreenSettings* screen_settings);
bool savesettings(const ScreenSettings* screen_settings); bool savesettings(const struct ScreenSettings* screen_settings);
bool savesettings(void); bool savesettings(void);
bool savestatsandsettings(void); bool savestatsandsettings(void);

View file

@ -20,27 +20,27 @@ extern "C"
); );
} }
ScreenSettings::ScreenSettings(void) void ScreenSettings_default(struct ScreenSettings* _this)
{ {
windowWidth = 320; _this->windowWidth = 320;
windowHeight = 240; _this->windowHeight = 240;
fullscreen = false; _this->fullscreen = false;
useVsync = true; // Now that uncapped is the default... _this->useVsync = true; // Now that uncapped is the default...
scalingMode = 0; _this->scalingMode = 0;
linearFilter = false; _this->linearFilter = false;
badSignal = false; _this->badSignal = false;
} }
void Screen::init(const ScreenSettings& settings) void Screen::init(const struct ScreenSettings* settings)
{ {
m_window = NULL; m_window = NULL;
m_renderer = NULL; m_renderer = NULL;
m_screenTexture = NULL; m_screenTexture = NULL;
m_screen = NULL; m_screen = NULL;
isWindowed = !settings.fullscreen; isWindowed = !settings->fullscreen;
scalingMode = settings.scalingMode; scalingMode = settings->scalingMode;
isFiltered = settings.linearFilter; isFiltered = settings->linearFilter;
vsync = settings.useVsync; vsync = settings->useVsync;
SDL_SetHintWithPriority( SDL_SetHintWithPriority(
SDL_HINT_RENDER_SCALE_QUALITY, SDL_HINT_RENDER_SCALE_QUALITY,
@ -85,9 +85,9 @@ void Screen::init(const ScreenSettings& settings)
240 240
); );
badSignalEffect = settings.badSignal; badSignalEffect = settings->badSignal;
ResizeScreen(settings.windowWidth, settings.windowHeight); ResizeScreen(settings->windowWidth, settings->windowHeight);
} }
void Screen::destroy(void) void Screen::destroy(void)
@ -105,7 +105,7 @@ void Screen::destroy(void)
#undef X #undef X
} }
void Screen::GetSettings(ScreenSettings* settings) void Screen::GetSettings(struct ScreenSettings* settings)
{ {
int width, height; int width, height;
GetWindowSize(&width, &height); GetWindowSize(&width, &height);

View file

@ -8,10 +8,10 @@
class Screen class Screen
{ {
public: public:
void init(const ScreenSettings& settings); void init(const struct ScreenSettings* settings);
void destroy(void); void destroy(void);
void GetSettings(ScreenSettings* settings); void GetSettings(struct ScreenSettings* settings);
void LoadIcon(void); void LoadIcon(void);

View file

@ -3,8 +3,6 @@
struct ScreenSettings struct ScreenSettings
{ {
ScreenSettings(void);
int windowWidth; int windowWidth;
int windowHeight; int windowHeight;
bool fullscreen; bool fullscreen;
@ -14,4 +12,6 @@ struct ScreenSettings
bool badSignal; bool badSignal;
}; };
void ScreenSettings_default(struct ScreenSettings* _this);
#endif /* SCREENSETTINGS_H */ #endif /* SCREENSETTINGS_H */

View file

@ -571,10 +571,11 @@ int main(int argc, char *argv[])
{ {
// Prioritize unlock.vvv first (2.2 and below), // Prioritize unlock.vvv first (2.2 and below),
// but settings have been migrated to settings.vvv (2.3 and up) // but settings have been migrated to settings.vvv (2.3 and up)
ScreenSettings screen_settings; struct ScreenSettings screen_settings;
ScreenSettings_default(&screen_settings);
game.loadstats(&screen_settings); game.loadstats(&screen_settings);
game.loadsettings(&screen_settings); game.loadsettings(&screen_settings);
gameScreen.init(screen_settings); gameScreen.init(&screen_settings);
} }
graphics.create_buffers(gameScreen.GetFormat()); graphics.create_buffers(gameScreen.GetFormat());