From 1e157f3cc94a0dc2244d07a83748315299880c8d Mon Sep 17 00:00:00 2001 From: Misa Date: Sat, 25 Dec 2021 00:18:51 -0800 Subject: [PATCH] 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 --- desktop_version/src/Game.cpp | 16 +++++++------- desktop_version/src/Game.h | 12 +++++------ desktop_version/src/Screen.cpp | 32 ++++++++++++++-------------- desktop_version/src/Screen.h | 4 ++-- desktop_version/src/ScreenSettings.h | 4 ++-- desktop_version/src/main.cpp | 5 +++-- 6 files changed, 37 insertions(+), 36 deletions(-) diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 85e145ad..81ce0c9c 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -4021,7 +4021,7 @@ void Game::unlocknum( int t ) #endif } -void Game::loadstats(ScreenSettings* screen_settings) +void Game::loadstats(struct ScreenSettings* screen_settings) { tinyxml2::XMLDocument doc; tinyxml2::XMLHandle hDoc(&doc); @@ -4100,7 +4100,7 @@ void Game::loadstats(ScreenSettings* 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! controllerButton_flip.clear(); @@ -4327,13 +4327,13 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, ScreenSettings* s bool Game::savestats(bool sync /*= true*/) { - ScreenSettings screen_settings; + struct ScreenSettings screen_settings; gameScreen.GetSettings(&screen_settings); 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; 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); @@ -4563,7 +4563,7 @@ void Game::serializesettings(tinyxml2::XMLElement* dataNode, const ScreenSetting xml::update_tag(dataNode, "controllerSensitivity", key.sensitivity); } -void Game::loadsettings(ScreenSettings* screen_settings) +void Game::loadsettings(struct ScreenSettings* screen_settings) { tinyxml2::XMLDocument doc; tinyxml2::XMLHandle hDoc(&doc); @@ -4592,13 +4592,13 @@ void Game::loadsettings(ScreenSettings* screen_settings) bool Game::savesettings(void) { - ScreenSettings screen_settings; + struct ScreenSettings screen_settings; gameScreen.GetSettings(&screen_settings); return savesettings(&screen_settings); } -bool Game::savesettings(const ScreenSettings* screen_settings) +bool Game::savesettings(const struct ScreenSettings* screen_settings) { tinyxml2::XMLDocument doc; bool already_exists = FILESYSTEM_loadTiXml2Document("saves/settings.vvv", doc); diff --git a/desktop_version/src/Game.h b/desktop_version/src/Game.h index 973766fe..dad68415 100644 --- a/desktop_version/src/Game.h +++ b/desktop_version/src/Game.h @@ -165,20 +165,20 @@ public: 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); 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 savestatsandsettings(void); diff --git a/desktop_version/src/Screen.cpp b/desktop_version/src/Screen.cpp index 30fb7179..57b18645 100644 --- a/desktop_version/src/Screen.cpp +++ b/desktop_version/src/Screen.cpp @@ -20,27 +20,27 @@ extern "C" ); } -ScreenSettings::ScreenSettings(void) +void ScreenSettings_default(struct ScreenSettings* _this) { - windowWidth = 320; - windowHeight = 240; - fullscreen = false; - useVsync = true; // Now that uncapped is the default... - scalingMode = 0; - linearFilter = false; - badSignal = false; + _this->windowWidth = 320; + _this->windowHeight = 240; + _this->fullscreen = false; + _this->useVsync = true; // Now that uncapped is the default... + _this->scalingMode = 0; + _this->linearFilter = false; + _this->badSignal = false; } -void Screen::init(const ScreenSettings& settings) +void Screen::init(const struct ScreenSettings* settings) { m_window = NULL; m_renderer = NULL; m_screenTexture = NULL; m_screen = NULL; - isWindowed = !settings.fullscreen; - scalingMode = settings.scalingMode; - isFiltered = settings.linearFilter; - vsync = settings.useVsync; + isWindowed = !settings->fullscreen; + scalingMode = settings->scalingMode; + isFiltered = settings->linearFilter; + vsync = settings->useVsync; SDL_SetHintWithPriority( SDL_HINT_RENDER_SCALE_QUALITY, @@ -85,9 +85,9 @@ void Screen::init(const ScreenSettings& settings) 240 ); - badSignalEffect = settings.badSignal; + badSignalEffect = settings->badSignal; - ResizeScreen(settings.windowWidth, settings.windowHeight); + ResizeScreen(settings->windowWidth, settings->windowHeight); } void Screen::destroy(void) @@ -105,7 +105,7 @@ void Screen::destroy(void) #undef X } -void Screen::GetSettings(ScreenSettings* settings) +void Screen::GetSettings(struct ScreenSettings* settings) { int width, height; GetWindowSize(&width, &height); diff --git a/desktop_version/src/Screen.h b/desktop_version/src/Screen.h index aa3d076c..0bfac967 100644 --- a/desktop_version/src/Screen.h +++ b/desktop_version/src/Screen.h @@ -8,10 +8,10 @@ class Screen { public: - void init(const ScreenSettings& settings); + void init(const struct ScreenSettings* settings); void destroy(void); - void GetSettings(ScreenSettings* settings); + void GetSettings(struct ScreenSettings* settings); void LoadIcon(void); diff --git a/desktop_version/src/ScreenSettings.h b/desktop_version/src/ScreenSettings.h index 2f60a9d0..9e5e6a32 100644 --- a/desktop_version/src/ScreenSettings.h +++ b/desktop_version/src/ScreenSettings.h @@ -3,8 +3,6 @@ struct ScreenSettings { - ScreenSettings(void); - int windowWidth; int windowHeight; bool fullscreen; @@ -14,4 +12,6 @@ struct ScreenSettings bool badSignal; }; +void ScreenSettings_default(struct ScreenSettings* _this); + #endif /* SCREENSETTINGS_H */ diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index 50909257..0e4402d8 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -571,10 +571,11 @@ int main(int argc, char *argv[]) { // Prioritize unlock.vvv first (2.2 and below), // 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.loadsettings(&screen_settings); - gameScreen.init(screen_settings); + gameScreen.init(&screen_settings); } graphics.create_buffers(gameScreen.GetFormat());