Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #12446 Refactor WEATHER to use strong enum #13434

Merged
merged 14 commits into from
Nov 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
# include <openrct2/drawing/Weather.h>
# include <openrct2/interface/Screenshot.h>
# include <openrct2/ui/UiContext.h>
# include <openrct2/util/Util.h>
# include <openrct2/world/Climate.h>
# include <unordered_map>

Expand Down Expand Up @@ -137,8 +138,8 @@ class OpenGLWeatherDrawer final : public IWeatherDrawer
const uint8_t* weatherpattern) override
{
const uint8_t* pattern = weatherpattern;
uint8_t patternXSpace = *pattern++;
uint8_t patternYSpace = *pattern++;
auto patternXSpace = *pattern++;
auto patternYSpace = *pattern++;

uint8_t patternStartXOffset = xStart % patternXSpace;
uint8_t patternStartYOffset = yStart % patternYSpace;
Expand All @@ -150,15 +151,15 @@ class OpenGLWeatherDrawer final : public IWeatherDrawer

for (; height != 0; height--)
{
uint8_t patternX = pattern[patternYPos * 2];
auto patternX = pattern[patternYPos * 2];
if (patternX != 0xFF)
{
uint32_t finalPixelOffset = width + pixelOffset;

uint32_t xPixelOffset = pixelOffset;
xPixelOffset += (static_cast<uint8_t>(patternX - patternStartXOffset)) % patternXSpace;

uint8_t patternPixel = pattern[patternYPos * 2 + 1];
auto patternPixel = pattern[patternYPos * 2 + 1];
for (; xPixelOffset < finalPixelOffset; xPixelOffset += patternXSpace)
{
int32_t pixelX = xPixelOffset % dpi->width;
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2-ui/windows/Cheats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ static void window_cheats_misc_mousedown(rct_window* w, rct_widgetindex widgetIn
w->colours[1], 0, Dropdown::Flag::StayOpen, std::size(WeatherTypes), dropdownWidget->width() - 3);

auto currentWeather = gClimateCurrent.Weather;
Dropdown::SetChecked(currentWeather, true);
Dropdown::SetChecked(EnumValue(currentWeather), true);
}
break;
case WIDX_STAFF_SPEED_DROPDOWN_BUTTON:
Expand Down Expand Up @@ -1087,7 +1087,7 @@ static void window_cheats_invalidate(rct_window* w)
}

// Current weather
window_cheats_misc_widgets[WIDX_WEATHER].text = WeatherTypes[gClimateCurrent.Weather];
window_cheats_misc_widgets[WIDX_WEATHER].text = WeatherTypes[EnumValue(gClimateCurrent.Weather)];
// Staff speed
window_cheats_misc_widgets[WIDX_STAFF_SPEED].text = _staffSpeedNames[_selectedStaffSpeed];

Expand Down
5 changes: 3 additions & 2 deletions src/openrct2/actions/SetCheatAction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ DEFINE_GAME_ACTION(SetCheatAction, GAME_COMMAND_CHEAT, GameActions::Result)
scenario_success();
break;
case CheatType::ForceWeather:
climate_force_weather(_param1);
// Todo - make sure this is safe
climate_force_weather(WeatherType{ static_cast<uint8_t>(_param1) });
break;
case CheatType::FreezeWeather:
gCheatsFreezeWeather = _param1 != 0;
Expand Down Expand Up @@ -356,7 +357,7 @@ DEFINE_GAME_ACTION(SetCheatAction, GAME_COMMAND_CHEAT, GameActions::Result)
case CheatType::SetStaffSpeed:
return { { 0, 255 }, { 0, 0 } };
case CheatType::ForceWeather:
return { { 0, WEATHER_COUNT - 1 }, { 0, 0 } };
return { { 0, EnumValue(WeatherType::Count) - 1 }, { 0, 0 } };
case CheatType::SetForcedParkRating:
return { { 0, 999 }, { 0, 0 } };
case CheatType::CreateDucks:
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/drawing/IDrawingEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#pragma once

#include "../common.h"
#include "./Weather.h"

#include <memory>
#include <string>
Expand Down
9 changes: 5 additions & 4 deletions src/openrct2/drawing/X8DrawingEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "../interface/Viewport.h"
#include "../interface/Window.h"
#include "../ui/UiContext.h"
#include "../util/Util.h"
#include "../world/Climate.h"
#include "Drawing.h"
#include "IDrawingContext.h"
Expand Down Expand Up @@ -50,8 +51,8 @@ void X8WeatherDrawer::Draw(
int32_t x, int32_t y, int32_t width, int32_t height, int32_t xStart, int32_t yStart, const uint8_t* weatherpattern)
{
const uint8_t* pattern = weatherpattern;
uint8_t patternXSpace = *pattern++;
uint8_t patternYSpace = *pattern++;
auto patternXSpace = *pattern++;
auto patternYSpace = *pattern++;

uint8_t patternStartXOffset = xStart % patternXSpace;
uint8_t patternStartYOffset = yStart % patternYSpace;
Expand All @@ -65,7 +66,7 @@ void X8WeatherDrawer::Draw(
WeatherPixel* newPixels = &_weatherPixels[_weatherPixelsCount];
for (; height != 0; height--)
{
uint8_t patternX = pattern[patternYPos * 2];
auto patternX = pattern[patternYPos * 2];
if (patternX != 0xFF)
{
if (_weatherPixelsCount < (_weatherPixelsCapacity - static_cast<uint32_t>(width)))
Expand All @@ -75,7 +76,7 @@ void X8WeatherDrawer::Draw(
uint32_t xPixelOffset = pixelOffset;
xPixelOffset += (static_cast<uint8_t>(patternX - patternStartXOffset)) % patternXSpace;

uint8_t patternPixel = pattern[patternYPos * 2 + 1];
auto patternPixel = pattern[patternYPos * 2 + 1];
for (; xPixelOffset < finalPixelOffset; xPixelOffset += patternXSpace)
{
uint8_t current_pixel = screenBits[xPixelOffset];
Expand Down
10 changes: 2 additions & 8 deletions src/openrct2/interface/Screenshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,15 +550,9 @@ int32_t cmdline_for_gfxbench(const char** argv, int32_t argc)

static void ApplyOptions(const ScreenshotOptions* options, rct_viewport& viewport)
{
if (options->weather != 0)
if (options->weather != WeatherType::Sunny && options->weather != WeatherType::Count)
{
if (options->weather < 1 || options->weather > 6)
{
throw std::runtime_error("Weather can only be set to an integer value from 1 till 6.");
}

uint8_t customWeather = options->weather - 1;
climate_force_weather(customWeather);
climate_force_weather(WeatherType{ static_cast<uint8_t>(EnumValue(options->weather) - 1) });
}

if (options->hide_guests)
Expand Down
3 changes: 2 additions & 1 deletion src/openrct2/interface/Screenshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "../common.h"
#include "../core/FileSystem.hpp"
#include "../world/Climate.h"
#include "../world/Location.hpp"
#include "ZoomLevel.h"

Expand All @@ -23,7 +24,7 @@ extern uint8_t gScreenshotCountdown;

struct ScreenshotOptions
{
int32_t weather = 0;
WeatherType weather = WeatherType::Sunny;
bool hide_guests = false;
bool hide_sprites = false;
bool clear_grass = false;
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/rct1/RCT1.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "../rct12/RCT12.h"
#include "../ride/Ride.h"
#include "../world/Banner.h"
#include "../world/Climate.h"
#include "../world/MapAnimation.h"
#include "../world/Sprite.h"

Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/rct1/S4Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2680,12 +2680,12 @@ class S4Importer final : public IParkImporter
gClimate = ClimateType{ _s4.climate };
gClimateUpdateTimer = _s4.climate_timer;
gClimateCurrent.Temperature = _s4.temperature;
gClimateCurrent.Weather = _s4.weather;
gClimateCurrent.Weather = WeatherType{ _s4.weather };
gClimateCurrent.WeatherEffect = WeatherEffectType::None;
gClimateCurrent.WeatherGloom = _s4.weather_gloom;
gClimateCurrent.Level = static_cast<WeatherLevel>(_s4.rain);
gClimateNext.Temperature = _s4.target_temperature;
gClimateNext.Weather = _s4.target_weather;
gClimateNext.Weather = WeatherType{ _s4.target_weather };
gClimateNext.WeatherEffect = WeatherEffectType::None;
gClimateNext.WeatherGloom = _s4.target_weather_gloom;
gClimateNext.Level = static_cast<WeatherLevel>(_s4.target_rain);
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/rct2/S6Exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ void S6Exporter::Export()
// byte_13CA742
// pad_013CA747
_s6.climate_update_timer = gClimateUpdateTimer;
_s6.current_weather = gClimateCurrent.Weather;
_s6.next_weather = gClimateNext.Weather;
_s6.current_weather = EnumValue(gClimateCurrent.Weather);
_s6.next_weather = EnumValue(gClimateNext.Weather);
_s6.temperature = gClimateCurrent.Temperature;
_s6.next_temperature = gClimateNext.Temperature;
_s6.current_weather_effect = static_cast<uint8_t>(gClimateCurrent.WeatherEffect);
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/rct2/S6Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ class S6Importer final : public IParkImporter
// byte_13CA742
// pad_013CA747
gClimateUpdateTimer = _s6.climate_update_timer;
gClimateCurrent.Weather = _s6.current_weather;
gClimateNext.Weather = _s6.next_weather;
gClimateCurrent.Weather = WeatherType{ _s6.current_weather };
gClimateNext.Weather = WeatherType{ _s6.next_weather };
gClimateCurrent.Temperature = _s6.temperature;
gClimateNext.Temperature = _s6.next_temperature;
gClimateCurrent.WeatherEffect = WeatherEffectType{ _s6.current_weather_effect };
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/scenario/Scenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "../ride/Ride.h"
#include "../ride/RideRatings.h"
#include "../world/Banner.h"
#include "../world/Climate.h"
#include "../world/Map.h"
#include "../world/MapAnimation.h"
#include "../world/Sprite.h"
Expand Down