From 0f1788d273266326384b9fd3fdfce76563e8446e Mon Sep 17 00:00:00 2001 From: frutiemax Date: Sun, 26 Jul 2020 09:25:29 -0400 Subject: [PATCH] Part of #12457: Refactor INTRO_STATE to use strong enum --- src/openrct2-ui/windows/TitleExit.cpp | 2 +- src/openrct2-ui/windows/TitleOptions.cpp | 2 +- src/openrct2/Context.cpp | 6 +- src/openrct2/Intro.cpp | 76 +++++++++++++----------- src/openrct2/Intro.h | 4 +- src/openrct2/audio/Audio.cpp | 2 +- src/openrct2/cmdline/BenchSpriteSort.cpp | 2 +- src/openrct2/drawing/X8DrawingEngine.cpp | 2 +- src/openrct2/interface/Screenshot.cpp | 4 +- src/openrct2/paint/Painter.cpp | 2 +- 10 files changed, 53 insertions(+), 49 deletions(-) diff --git a/src/openrct2-ui/windows/TitleExit.cpp b/src/openrct2-ui/windows/TitleExit.cpp index 6b43f27b48..996dfc4239 100644 --- a/src/openrct2-ui/windows/TitleExit.cpp +++ b/src/openrct2-ui/windows/TitleExit.cpp @@ -84,7 +84,7 @@ rct_window* window_title_exit_open() */ static void window_title_exit_mouseup(rct_window* w, rct_widgetindex widgetIndex) { - if (gIntroState != INTRO_STATE_NONE) + if (gIntroState != INTRO_STATE::INTRO_STATE_NONE) return; switch (widgetIndex) diff --git a/src/openrct2-ui/windows/TitleOptions.cpp b/src/openrct2-ui/windows/TitleOptions.cpp index 8049b3e7e2..6ae229dda1 100644 --- a/src/openrct2-ui/windows/TitleOptions.cpp +++ b/src/openrct2-ui/windows/TitleOptions.cpp @@ -76,7 +76,7 @@ rct_window* window_title_options_open() static void window_title_options_mouseup(rct_window* w, rct_widgetindex widgetIndex) { - if (gIntroState != INTRO_STATE_NONE) + if (gIntroState != INTRO_STATE::INTRO_STATE_NONE) return; switch (widgetIndex) diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index d23c64a203..ee9d892680 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -726,7 +726,7 @@ namespace OpenRCT2 */ void Launch() { - gIntroState = INTRO_STATE_NONE; + gIntroState = INTRO_STATE::INTRO_STATE_NONE; if (gOpenRCT2Headless) { // NONE or OPEN are the only allowed actions for headless mode @@ -746,7 +746,7 @@ namespace OpenRCT2 switch (gOpenRCT2StartupAction) { case STARTUP_ACTION_INTRO: - gIntroState = INTRO_STATE_PUBLISHER_BEGIN; + gIntroState = INTRO_STATE::INTRO_STATE_PUBLISHER_BEGIN; title_load(); break; case STARTUP_ACTION_TITLE: @@ -1013,7 +1013,7 @@ namespace OpenRCT2 date_update_real_time_of_day(); - if (gIntroState != INTRO_STATE_NONE) + if (gIntroState != INTRO_STATE::INTRO_STATE_NONE) { intro_update(); } diff --git a/src/openrct2/Intro.cpp b/src/openrct2/Intro.cpp index d83f9a3bc7..b8a5a16dac 100644 --- a/src/openrct2/Intro.cpp +++ b/src/openrct2/Intro.cpp @@ -22,7 +22,7 @@ constexpr int32_t PALETTE_G1_IDX_DEVELOPER = 23217; constexpr int32_t PALETTE_G1_IDX_LOGO = 23224; -uint8_t gIntroState; +INTRO_STATE gIntroState; // Used mainly for timing but also for Y coordinate and fading. static int32_t _introStateCounter; @@ -43,12 +43,12 @@ void intro_update() switch (gIntroState) { - case INTRO_STATE_DISCLAIMER_1: - case INTRO_STATE_DISCLAIMER_2: + case INTRO_STATE::INTRO_STATE_DISCLAIMER_1: + case INTRO_STATE::INTRO_STATE_DISCLAIMER_2: // Originally used for the disclaimer text - gIntroState = INTRO_STATE_PUBLISHER_BEGIN; + gIntroState = INTRO_STATE::INTRO_STATE_PUBLISHER_BEGIN; [[fallthrough]]; - case INTRO_STATE_PUBLISHER_BEGIN: + case INTRO_STATE::INTRO_STATE_PUBLISHER_BEGIN: load_palette(); // Set the Y for the Infogrames logo @@ -57,9 +57,9 @@ void intro_update() // Play the chain lift sound _soundChannel = Mixer_Play_Effect(SoundId::LiftBM, MIXER_LOOP_INFINITE, MIXER_VOLUME_MAX, 0.5f, 1, true); _chainLiftFinished = false; - gIntroState++; + gIntroState = INTRO_STATE::INTRO_STATE_PUBLISHER_SCROLL; break; - case INTRO_STATE_PUBLISHER_SCROLL: + case INTRO_STATE::INTRO_STATE_PUBLISHER_SCROLL: // Move the Infogrames logo down _introStateCounter += 5; @@ -67,17 +67,17 @@ void intro_update() if (_introStateCounter > context_get_height() - 120) { _introStateCounter = -116; - gIntroState++; + gIntroState = INTRO_STATE::INTRO_STATE_DEVELOPER_BEGIN; } break; - case INTRO_STATE_DEVELOPER_BEGIN: + case INTRO_STATE::INTRO_STATE_DEVELOPER_BEGIN: // Set the Y for the Chris Sawyer logo _introStateCounter = -116; - gIntroState++; + gIntroState = INTRO_STATE::INTRO_STATE_DEVELOPER_SCROLL; break; - case INTRO_STATE_DEVELOPER_SCROLL: + case INTRO_STATE::INTRO_STATE_DEVELOPER_SCROLL: _introStateCounter += 5; // Check if logo is almost scrolled to the bottom @@ -110,20 +110,20 @@ void intro_update() // Play long peep scream sound _soundChannel = Mixer_Play_Effect(SoundId::Scream1, MIXER_LOOP_NONE, MIXER_VOLUME_MAX, 0.5f, 1, false); - gIntroState++; + gIntroState = INTRO_STATE::INTRO_STATE_LOGO_FADE_IN; _introStateCounter = 0; } break; - case INTRO_STATE_LOGO_FADE_IN: + case INTRO_STATE::INTRO_STATE_LOGO_FADE_IN: // Fade in, add 4 / 256 to fading _introStateCounter += 0x400; if (_introStateCounter > 0xFF00) { - gIntroState++; + gIntroState = INTRO_STATE::INTRO_STATE_LOGO_WAIT; _introStateCounter = 0; } break; - case INTRO_STATE_LOGO_WAIT: + case INTRO_STATE::INTRO_STATE_LOGO_WAIT: // Wait 80 game ticks _introStateCounter++; if (_introStateCounter >= 80) @@ -131,18 +131,18 @@ void intro_update() // Set fading to 256 _introStateCounter = 0xFF00; - gIntroState++; + gIntroState = INTRO_STATE::INTRO_STATE_LOGO_FADE_OUT; } break; - case INTRO_STATE_LOGO_FADE_OUT: + case INTRO_STATE::INTRO_STATE_LOGO_FADE_OUT: // Fade out, subtract 4 / 256 from fading _introStateCounter -= 0x400; if (_introStateCounter < 0) { - gIntroState = INTRO_STATE_CLEAR; + gIntroState = INTRO_STATE::INTRO_STATE_CLEAR; } break; - case INTRO_STATE_CLEAR: + case INTRO_STATE::INTRO_STATE_CLEAR: // Stop any playing sound if (_soundChannel != nullptr) { @@ -151,14 +151,16 @@ void intro_update() } // Move to next part - gIntroState++; + gIntroState = INTRO_STATE::INTRO_STATE_FINISH; _introStateCounter = 0; break; - case INTRO_STATE_FINISH: - gIntroState = INTRO_STATE_NONE; + case INTRO_STATE::INTRO_STATE_FINISH: + gIntroState = INTRO_STATE::INTRO_STATE_NONE; load_palette(); audio_start_title_music(); break; + default: + break; } } @@ -168,13 +170,13 @@ void intro_draw(rct_drawpixelinfo* dpi) switch (gIntroState) { - case INTRO_STATE_DISCLAIMER_1: - case INTRO_STATE_DISCLAIMER_2: + case INTRO_STATE::INTRO_STATE_DISCLAIMER_1: + case INTRO_STATE::INTRO_STATE_DISCLAIMER_2: break; - case INTRO_STATE_PUBLISHER_BEGIN: + case INTRO_STATE::INTRO_STATE_PUBLISHER_BEGIN: gfx_clear(dpi, BACKROUND_COLOUR_DARK); break; - case INTRO_STATE_PUBLISHER_SCROLL: + case INTRO_STATE::INTRO_STATE_PUBLISHER_SCROLL: gfx_clear(dpi, BACKROUND_COLOUR_DARK); // Draw a white rectangle for the logo background (gives a bit of white margin) @@ -190,18 +192,18 @@ void intro_draw(rct_drawpixelinfo* dpi) gfx_draw_sprite(dpi, SPR_INTRO_INFOGRAMES_01, { (screenWidth / 2) - 320 + 69, _introStateCounter + 319 }, 0); gfx_draw_sprite(dpi, SPR_INTRO_INFOGRAMES_11, { (screenWidth / 2) - 320 + 319, _introStateCounter + 319 }, 0); break; - case INTRO_STATE_DEVELOPER_BEGIN: + case INTRO_STATE::INTRO_STATE_DEVELOPER_BEGIN: gfx_clear(dpi, BACKROUND_COLOUR_DARK); gfx_transpose_palette(PALETTE_G1_IDX_DEVELOPER, 255); break; - case INTRO_STATE_DEVELOPER_SCROLL: + case INTRO_STATE::INTRO_STATE_DEVELOPER_SCROLL: gfx_clear(dpi, BACKROUND_COLOUR_DARK); // Draw Chris Sawyer logo gfx_draw_sprite(dpi, SPR_INTRO_CHRIS_SAWYER_00, { (screenWidth / 2) - 320 + 70, _introStateCounter }, 0); gfx_draw_sprite(dpi, SPR_INTRO_CHRIS_SAWYER_10, { (screenWidth / 2) - 320 + 320, _introStateCounter }, 0); break; - case INTRO_STATE_LOGO_FADE_IN: + case INTRO_STATE::INTRO_STATE_LOGO_FADE_IN: if (_introStateCounter <= 0xFF00) { gfx_transpose_palette(PALETTE_G1_IDX_LOGO, (_introStateCounter >> 8) & 0xFF); @@ -212,10 +214,10 @@ void intro_draw(rct_drawpixelinfo* dpi) } screen_intro_draw_logo(dpi); break; - case INTRO_STATE_LOGO_WAIT: + case INTRO_STATE::INTRO_STATE_LOGO_WAIT: screen_intro_draw_logo(dpi); break; - case INTRO_STATE_LOGO_FADE_OUT: + case INTRO_STATE::INTRO_STATE_LOGO_FADE_OUT: if (_introStateCounter >= 0) { gfx_transpose_palette(PALETTE_G1_IDX_LOGO, (_introStateCounter >> 8) & 0xFF); @@ -226,9 +228,11 @@ void intro_draw(rct_drawpixelinfo* dpi) } screen_intro_draw_logo(dpi); break; - case INTRO_STATE_CLEAR: + case INTRO_STATE::INTRO_STATE_CLEAR: gfx_clear(dpi, BACKROUND_COLOUR_DARK); break; + default: + break; } } @@ -261,13 +265,13 @@ static void screen_intro_skip_part() { switch (gIntroState) { - case INTRO_STATE_NONE: + case INTRO_STATE::INTRO_STATE_NONE: break; - case INTRO_STATE_DISCLAIMER_2: - gIntroState = INTRO_STATE_PUBLISHER_BEGIN; + case INTRO_STATE::INTRO_STATE_DISCLAIMER_2: + gIntroState = INTRO_STATE::INTRO_STATE_PUBLISHER_BEGIN; break; default: - gIntroState = INTRO_STATE_CLEAR; + gIntroState = INTRO_STATE::INTRO_STATE_CLEAR; break; } } diff --git a/src/openrct2/Intro.h b/src/openrct2/Intro.h index 4b4f38b142..a698288905 100644 --- a/src/openrct2/Intro.h +++ b/src/openrct2/Intro.h @@ -14,7 +14,7 @@ struct rct_drawpixelinfo; -enum INTRO_STATE +enum class INTRO_STATE : uint8_t { INTRO_STATE_NONE, INTRO_STATE_PUBLISHER_BEGIN, @@ -30,7 +30,7 @@ enum INTRO_STATE INTRO_STATE_FINISH = 255, }; -extern uint8_t gIntroState; +extern INTRO_STATE gIntroState; void intro_update(); void intro_draw(rct_drawpixelinfo* dpi); diff --git a/src/openrct2/audio/Audio.cpp b/src/openrct2/audio/Audio.cpp index ae7e808c53..559f1aa9e8 100644 --- a/src/openrct2/audio/Audio.cpp +++ b/src/openrct2/audio/Audio.cpp @@ -253,7 +253,7 @@ void audio_play_sound(SoundId soundId, int32_t volume, int32_t pan) void audio_start_title_music() { - if (gGameSoundsOff || !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) || gIntroState != INTRO_STATE_NONE) + if (gGameSoundsOff || !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) || gIntroState != INTRO_STATE::INTRO_STATE_NONE) { audio_stop_title_music(); return; diff --git a/src/openrct2/cmdline/BenchSpriteSort.cpp b/src/openrct2/cmdline/BenchSpriteSort.cpp index fdf254c07b..54c3a120a9 100644 --- a/src/openrct2/cmdline/BenchSpriteSort.cpp +++ b/src/openrct2/cmdline/BenchSpriteSort.cpp @@ -80,7 +80,7 @@ static std::vector extract_paint_session(const std::string parkFi return {}; } - gIntroState = INTRO_STATE_NONE; + gIntroState = INTRO_STATE::INTRO_STATE_NONE; gScreenFlags = SCREEN_FLAGS_PLAYING; int32_t mapSize = gMapSize; diff --git a/src/openrct2/drawing/X8DrawingEngine.cpp b/src/openrct2/drawing/X8DrawingEngine.cpp index e3994cc323..e150c7d7d3 100644 --- a/src/openrct2/drawing/X8DrawingEngine.cpp +++ b/src/openrct2/drawing/X8DrawingEngine.cpp @@ -188,7 +188,7 @@ void X8DrawingEngine::Invalidate(int32_t left, int32_t top, int32_t right, int32 void X8DrawingEngine::BeginDraw() { - if (gIntroState == INTRO_STATE_NONE) + if (gIntroState == INTRO_STATE::INTRO_STATE_NONE) { #ifdef __ENABLE_LIGHTFX__ // HACK we need to re-configure the bits if light fx has been enabled / disabled diff --git a/src/openrct2/interface/Screenshot.cpp b/src/openrct2/interface/Screenshot.cpp index 5fc29e9a69..8040d4f2df 100644 --- a/src/openrct2/interface/Screenshot.cpp +++ b/src/openrct2/interface/Screenshot.cpp @@ -444,7 +444,7 @@ static void benchgfx_render_screenshots(const char* inputPath, std::unique_ptr& uiContext) void Painter::Paint(IDrawingEngine& de) { auto dpi = de.GetDrawingPixelInfo(); - if (gIntroState != INTRO_STATE_NONE) + if (gIntroState != INTRO_STATE::INTRO_STATE_NONE) { intro_draw(dpi); }