Files
OpenRCT2-Web/src/openrct2/drawing/Weather.cpp
T

198 lines
6.4 KiB
C++
Raw Normal View History

2016-06-03 23:06:22 +01:00
/*****************************************************************************
* Copyright (c) 2014-2024 OpenRCT2 developers
2016-06-03 23:06:22 +01:00
*
2018-06-15 14:07:34 +02:00
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
2016-06-03 23:06:22 +01:00
*
2018-06-15 14:07:34 +02:00
* OpenRCT2 is licensed under the GNU General Public License version 3.
2016-06-03 23:06:22 +01:00
*****************************************************************************/
#include "Weather.h"
2018-06-22 22:59:03 +02:00
#include "../Game.h"
#include "../GameState.h"
#include "../config/Config.h"
#include "../interface/Viewport.h"
2018-03-19 23:28:40 +01:00
#include "../ride/TrackDesign.h"
#include "../scenario/Scenario.h"
#include "../ui/UiContext.h"
#include "../world/Climate.h"
#include "Drawing.h"
2016-06-03 23:06:22 +01:00
#include "IDrawingEngine.h"
using namespace OpenRCT2;
2017-03-25 03:16:40 +00:00
using namespace OpenRCT2::Drawing;
static void DrawLightRain(
2023-04-03 22:18:42 +02:00
DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height);
static void DrawHeavyRain(
2023-04-03 22:18:42 +02:00
DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height);
static void DrawLightSnow(
2023-04-03 22:18:42 +02:00
DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height);
static void DrawHeavySnow(
2023-04-03 22:18:42 +02:00
DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height);
2016-06-03 23:06:22 +01:00
/**
*
* rct2: 0x009AC058
*/
2020-09-14 21:36:30 +02:00
const DrawWeatherFunc DrawRainFunctions[] = {
nullptr,
&DrawLightRain,
&DrawHeavyRain,
};
2016-06-03 23:06:22 +01:00
2020-02-20 22:57:04 +00:00
const DrawWeatherFunc DrawSnowFunctions[] = {
nullptr,
&DrawLightSnow,
&DrawHeavySnow,
};
2016-06-03 23:06:22 +01:00
/**
*
* rct2: 0x00684218
*/
2023-04-03 22:18:42 +02:00
void DrawWeather(DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer)
2016-06-03 23:06:22 +01:00
{
2022-10-16 17:27:01 +02:00
if (gConfigGeneral.RenderWeatherEffects)
2016-06-03 23:06:22 +01:00
{
2018-12-05 19:29:51 +01:00
uint32_t viewFlags = 0;
const auto* viewport = WindowGetViewport(WindowGetMain());
2018-12-05 19:29:51 +01:00
if (viewport != nullptr)
viewFlags = viewport->flags;
2020-02-20 22:57:04 +00:00
// Get weather draw function and draw weather
auto weatherLevel = gClimateCurrent.Level;
if (weatherLevel != WeatherLevel::None && !gTrackDesignSaveMode && !(viewFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES))
{
2020-02-20 22:57:04 +00:00
auto drawFunc = DrawRainFunctions[static_cast<int8_t>(weatherLevel)];
if (ClimateIsSnowing())
2020-02-20 22:57:04 +00:00
{
drawFunc = DrawSnowFunctions[static_cast<int8_t>(weatherLevel)];
}
auto uiContext = GetContext()->GetUiContext();
2020-09-14 21:36:30 +02:00
uiContext->DrawWeatherAnimation(weatherDrawer, dpi, drawFunc);
}
2016-06-03 23:06:22 +01:00
}
}
/**
*
* rct2: 0x00684114
*/
static void DrawLightRain(
2023-04-03 22:18:42 +02:00
DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height)
2016-06-03 23:06:22 +01:00
{
const auto currentTicks = GetGameState().CurrentTicks;
int32_t x_start = -static_cast<int32_t>(currentTicks) + 8;
int32_t y_start = (currentTicks * 3) + 7;
2016-06-03 23:06:22 +01:00
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, RainPattern);
2016-06-03 23:06:22 +01:00
x_start = -static_cast<int32_t>(currentTicks) + 0x18;
y_start = (currentTicks * 4) + 0x0D;
2016-06-03 23:06:22 +01:00
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, RainPattern);
2016-06-03 23:06:22 +01:00
}
/**
*
* rct2: 0x0068416D
*/
static void DrawHeavyRain(
2023-04-03 22:18:42 +02:00
DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height)
2016-06-03 23:06:22 +01:00
{
const auto currentTicks = GetGameState().CurrentTicks;
int32_t x_start = -static_cast<int32_t>(currentTicks);
int32_t y_start = currentTicks * 5;
2016-06-03 23:06:22 +01:00
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, RainPattern);
2016-06-03 23:06:22 +01:00
x_start = -static_cast<int32_t>(currentTicks) + 0x10;
y_start = (currentTicks * 6) + 5;
2016-06-03 23:06:22 +01:00
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, RainPattern);
2016-06-03 23:06:22 +01:00
x_start = -static_cast<int32_t>(currentTicks) + 8;
y_start = (currentTicks * 3) + 7;
2016-06-03 23:06:22 +01:00
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, RainPattern);
2016-06-03 23:06:22 +01:00
x_start = -static_cast<int32_t>(currentTicks) + 0x18;
y_start = (currentTicks * 4) + 0x0D;
2016-06-03 23:06:22 +01:00
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, RainPattern);
2020-02-20 22:57:04 +00:00
}
static void DrawLightSnow(
2023-04-03 22:18:42 +02:00
DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height)
2020-02-20 22:57:04 +00:00
{
const auto currentTicks = GetGameState().CurrentTicks;
const uint32_t t = currentTicks / 2;
const int32_t negT = -static_cast<int32_t>(t);
const double cosTick = static_cast<double>(currentTicks) * 0.05;
2020-02-20 22:57:04 +00:00
int32_t x_start = negT + 1 + (cos(1.0 + cosTick) * 6);
2020-02-20 22:57:04 +00:00
int32_t y_start = t + 1;
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, SnowPattern);
2020-02-20 22:57:04 +00:00
x_start = negT + 16 + (cos(cosTick) * 6);
2020-02-20 22:57:04 +00:00
y_start = t + 16;
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, SnowPattern);
2020-02-20 22:57:04 +00:00
}
static void DrawHeavySnow(
2023-04-03 22:18:42 +02:00
DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height)
2020-02-20 22:57:04 +00:00
{
const auto currentTicks = GetGameState().CurrentTicks;
int32_t x_start = -static_cast<int32_t>(currentTicks * 3) + 1;
int32_t y_start = currentTicks + 23;
2020-02-20 22:57:04 +00:00
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, SnowPattern);
2020-02-20 22:57:04 +00:00
x_start = -static_cast<int32_t>(currentTicks * 4) + 6;
y_start = currentTicks + 5;
2020-02-20 22:57:04 +00:00
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, SnowPattern);
2020-02-20 22:57:04 +00:00
x_start = -static_cast<int32_t>(currentTicks * 2) + 11;
y_start = currentTicks + 18;
2020-02-20 22:57:04 +00:00
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, SnowPattern);
2020-02-20 22:57:04 +00:00
x_start = -static_cast<int32_t>(currentTicks * 3) + 17;
y_start = currentTicks + 11;
2020-02-20 22:57:04 +00:00
y_start = -y_start;
x_start += left;
y_start += top;
weatherDrawer->Draw(dpi, left, top, width, height, x_start, y_start, SnowPattern);
2016-06-03 23:06:22 +01:00
}