Refactor constants/macros (#21483)

* Refactor constants in AudioMixer.h

* Refactor constants in Map.h

* Rename kMinimumLandHeight_BIG to kMinimumLandZ
This commit is contained in:
Harry Hopkinson 2024-03-01 20:23:29 +00:00 committed by GitHub
parent a79b062136
commit 14f0479c94
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 44 additions and 44 deletions

View file

@ -48,7 +48,7 @@ namespace OpenRCT2::Audio
AudioChannelImpl()
{
AudioChannelImpl::SetRate(1);
AudioChannelImpl::SetVolume(MIXER_VOLUME_MAX);
AudioChannelImpl::SetVolume(kMixerVolumeMax);
AudioChannelImpl::SetPan(0.5f);
}
@ -155,7 +155,7 @@ namespace OpenRCT2::Audio
void SetVolume(int32_t volume) override
{
_volume = std::clamp(volume, 0, MIXER_VOLUME_MAX);
_volume = std::clamp(volume, 0, kMixerVolumeMax);
}
[[nodiscard]] float GetPan() const override
@ -265,7 +265,7 @@ namespace OpenRCT2::Audio
{
_done = true;
}
else if (_loop == MIXER_LOOP_INFINITE)
else if (_loop == kMixerLoopInfinite)
{
_offset = 0;
}

View file

@ -327,7 +327,7 @@ int32_t AudioMixer::ApplyVolume(const IAudioChannel* channel, void* buffer, size
if (startVolume != endVolume)
{
// Set to max since we are adjusting the volume ourselves
mixVolume = MIXER_VOLUME_MAX;
mixVolume = kMixerVolumeMax;
// Fade between volume levels to smooth out sound and minimize clicks from sudden volume changes
int32_t fadeLength = static_cast<int32_t>(len) / _format.BytesPerSample();
@ -378,7 +378,7 @@ void AudioMixer::EffectPanU8(const IAudioChannel* channel, uint8_t* data, int32_
void AudioMixer::EffectFadeS16(int16_t* data, int32_t length, int32_t startvolume, int32_t endvolume)
{
static_assert(SDL_MIX_MAXVOLUME == MIXER_VOLUME_MAX, "Max volume differs between OpenRCT2 and SDL2");
static_assert(SDL_MIX_MAXVOLUME == kMixerVolumeMax, "Max volume differs between OpenRCT2 and SDL2");
float startvolume_f = static_cast<float>(startvolume) / SDL_MIX_MAXVOLUME;
float endvolume_f = static_cast<float>(endvolume) / SDL_MIX_MAXVOLUME;
@ -391,7 +391,7 @@ void AudioMixer::EffectFadeS16(int16_t* data, int32_t length, int32_t startvolum
void AudioMixer::EffectFadeU8(uint8_t* data, int32_t length, int32_t startvolume, int32_t endvolume)
{
static_assert(SDL_MIX_MAXVOLUME == MIXER_VOLUME_MAX, "Max volume differs between OpenRCT2 and SDL2");
static_assert(SDL_MIX_MAXVOLUME == kMixerVolumeMax, "Max volume differs between OpenRCT2 and SDL2");
float startvolume_f = static_cast<float>(startvolume) / SDL_MIX_MAXVOLUME;
float endvolume_f = static_cast<float>(endvolume) / SDL_MIX_MAXVOLUME;

View file

@ -813,7 +813,7 @@ private:
mapgenSettings.mapSize = _mapSize;
mapgenSettings.height = _baseHeight;
mapgenSettings.water_level = _waterLevel + MINIMUM_WATER_HEIGHT;
mapgenSettings.water_level = _waterLevel + kMinimumWaterHeight;
mapgenSettings.floor = _randomTerrain ? -1 : _floorTexture;
mapgenSettings.wall = _randomTerrain ? -1 : _wallTexture;
mapgenSettings.trees = _placeTrees;
@ -886,11 +886,11 @@ private:
Invalidate();
break;
case WIDX_SIMPLEX_WATER_LEVEL_UP:
_waterLevel = std::min(_waterLevel + MINIMUM_WATER_HEIGHT, MINIMUM_WATER_HEIGHT + MAXIMUM_WATER_HEIGHT);
_waterLevel = std::min(_waterLevel + kMinimumWaterHeight, kMinimumWaterHeight + kMaximumWaterHeight);
Invalidate();
break;
case WIDX_SIMPLEX_WATER_LEVEL_DOWN:
_waterLevel = std::max(_waterLevel - MINIMUM_WATER_HEIGHT, 0);
_waterLevel = std::max(_waterLevel - kMinimumWaterHeight, 0);
Invalidate();
break;
case WIDX_SIMPLEX_RANDOM_TERRAIN_CHECKBOX:
@ -1093,11 +1093,11 @@ private:
InvalidateWidget(WIDX_HEIGHTMAP_HIGH);
break;
case WIDX_HEIGHTMAP_WATER_LEVEL_UP:
_waterLevel = std::min(_waterLevel + MINIMUM_WATER_HEIGHT, MINIMUM_WATER_HEIGHT + MAXIMUM_WATER_HEIGHT);
_waterLevel = std::min(_waterLevel + kMinimumWaterHeight, kMinimumWaterHeight + kMaximumWaterHeight);
InvalidateWidget(WIDX_HEIGHTMAP_WATER_LEVEL);
break;
case WIDX_HEIGHTMAP_WATER_LEVEL_DOWN:
_waterLevel = std::max(_waterLevel - MINIMUM_WATER_HEIGHT, 0);
_waterLevel = std::max(_waterLevel - kMinimumWaterHeight, 0);
InvalidateWidget(WIDX_HEIGHTMAP_WATER_LEVEL);
break;
}

View file

@ -3487,7 +3487,7 @@ void RideConstructionTooldownConstruct(const ScreenCoordsXY& screenCoords)
z -= bx;
// FIX not sure exactly why it starts trial and error place from a lower Z, but it causes issues with disable clearance
if (!gCheatsDisableClearanceChecks && z > MINIMUM_LAND_HEIGHT_BIG)
if (!gCheatsDisableClearanceChecks && z > kMinimumLandZ)
{
z -= LAND_HEIGHT_STEP;
}

View file

@ -472,8 +472,8 @@ static void FixInvalidSurfaces()
auto& gameState = GetGameState();
if (x == 0 || x == gameState.MapSize.x - 1 || y == 0 || y == gameState.MapSize.y - 1)
{
surfaceElement->SetBaseZ(MINIMUM_LAND_HEIGHT_BIG);
surfaceElement->SetClearanceZ(MINIMUM_LAND_HEIGHT_BIG);
surfaceElement->SetBaseZ(kMinimumLandZ);
surfaceElement->SetClearanceZ(kMinimumLandZ);
surfaceElement->SetSlope(0);
surfaceElement->SetWaterHeight(0);
}

View file

@ -98,7 +98,7 @@ void IntroUpdate()
}
// Play the track friction sound
_soundChannel = CreateAudioChannel(SoundId::TrackFrictionBM, true, MIXER_VOLUME_MAX, 0.25f, 0.75);
_soundChannel = CreateAudioChannel(SoundId::TrackFrictionBM, true, kMixerVolumeMax, 0.25f, 0.75);
}
// Check if logo is off the screen...ish

View file

@ -186,23 +186,23 @@ StringId LandSetHeightAction::CheckParameters() const
return STR_OFF_EDGE_OF_MAP;
}
if (_height < MINIMUM_LAND_HEIGHT)
if (_height < kMinimumLandHeight)
{
return STR_TOO_LOW;
}
// Divide by 2 and subtract 7 to get the in-game units.
if (_height > MAXIMUM_LAND_HEIGHT)
if (_height > kMaximumLandHeight)
{
return STR_TOO_HIGH;
}
if (_height > MAXIMUM_LAND_HEIGHT - 2 && (_style & TILE_ELEMENT_SURFACE_SLOPE_MASK) != 0)
if (_height > kMaximumLandHeight - 2 && (_style & TILE_ELEMENT_SURFACE_SLOPE_MASK) != 0)
{
return STR_TOO_HIGH;
}
if (_height == MAXIMUM_LAND_HEIGHT - 2 && (_style & TILE_ELEMENT_SURFACE_DIAGONAL_FLAG))
if (_height == kMaximumLandHeight - 2 && (_style & TILE_ELEMENT_SURFACE_DIAGONAL_FLAG))
{
return STR_TOO_HIGH;
}

View file

@ -151,12 +151,12 @@ StringId WaterSetHeightAction::CheckParameters() const
return STR_OFF_EDGE_OF_MAP;
}
if (_height < MINIMUM_WATER_HEIGHT)
if (_height < kMinimumWaterHeight)
{
return STR_TOO_LOW;
}
if (_height > MAXIMUM_WATER_HEIGHT)
if (_height > kMaximumWaterHeight)
{
return STR_TOO_HIGH;
}

View file

@ -500,7 +500,7 @@ namespace OpenRCT2::Audio
}
mixer->Lock();
auto channel = mixer->Play(source, loop ? MIXER_LOOP_INFINITE : MIXER_LOOP_NONE, forget);
auto channel = mixer->Play(source, loop ? kMixerLoopInfinite : kMixerLoopNone, forget);
if (channel != nullptr)
{
channel->SetGroup(group);
@ -515,7 +515,7 @@ namespace OpenRCT2::Audio
int32_t DStoMixerVolume(int32_t volume)
{
return static_cast<int32_t>(MIXER_VOLUME_MAX * (std::pow(10.0f, static_cast<float>(volume) / 2000)));
return static_cast<int32_t>(kMixerVolumeMax * (std::pow(10.0f, static_cast<float>(volume) / 2000)));
}
float DStoMixerPan(int32_t pan)

View file

@ -13,9 +13,9 @@
namespace OpenRCT2::Audio
{
constexpr int32_t MIXER_VOLUME_MAX = 128;
constexpr int32_t MIXER_LOOP_NONE = 0;
constexpr int32_t MIXER_LOOP_INFINITE = -1;
constexpr int32_t kMixerVolumeMax = 128;
constexpr int32_t kMixerLoopNone = 0;
constexpr int32_t kMixerLoopInfinite = -1;
enum class SoundId : uint8_t;

View file

@ -261,10 +261,10 @@ namespace OpenRCT2::Audio
AudioObject* GetBaseAudioObject();
std::shared_ptr<IAudioChannel> CreateAudioChannel(
SoundId soundId, bool loop = false, int32_t volume = MIXER_VOLUME_MAX, float pan = 0.5f, double rate = 1,
SoundId soundId, bool loop = false, int32_t volume = kMixerVolumeMax, float pan = 0.5f, double rate = 1,
bool forget = false);
std::shared_ptr<IAudioChannel> CreateAudioChannel(
IAudioSource* source, MixerGroup group, bool loop = false, int32_t volume = MIXER_VOLUME_MAX, float pan = 0.5f,
IAudioSource* source, MixerGroup group, bool loop = false, int32_t volume = kMixerVolumeMax, float pan = 0.5f,
double rate = 1, bool forget = false);
int32_t DStoMixerVolume(int32_t volume);

View file

@ -232,7 +232,7 @@ void ChatAddHistory(std::string_view s)
// Log to file (src only as logging does its own timestamp)
NetworkAppendChatLog(s);
CreateAudioChannel(SoundId::NewsItem, 0, MIXER_VOLUME_MAX, 0.5f, 1.5f, true);
CreateAudioChannel(SoundId::NewsItem, 0, kMixerVolumeMax, 0.5f, 1.5f, true);
}
void ChatInput(enum ChatInput input)

View file

@ -306,7 +306,7 @@ void VirtualFloorPaint(PaintSession& session)
{ 0, -COORDS_XY_STEP },
};
if (_virtualFloorHeight < MINIMUM_LAND_HEIGHT)
if (_virtualFloorHeight < kMinimumLandHeight)
return;
uint8_t direction = session.CurrentRotation;

View file

@ -593,8 +593,8 @@ static void ViewportSurfaceDrawTileSideBottom(
if (neighbour.tile_element == nullptr || neighbourIsClippedAway)
{
// The neighbour tile doesn't exist or isn't drawn - assume minimum height to draw full edges
neighbourCornerHeight2 = MINIMUM_LAND_HEIGHT / 2;
neighbourCornerHeight1 = MINIMUM_LAND_HEIGHT / 2;
neighbourCornerHeight2 = kMinimumLandHeight / 2;
neighbourCornerHeight1 = kMinimumLandHeight / 2;
}
if (isWater && neighbour.tile_element != nullptr)

View file

@ -547,14 +547,14 @@ int16_t TileElementHeight(const CoordsXY& loc)
{
// Off the map
if (!MapIsLocationValid(loc))
return MINIMUM_LAND_HEIGHT_BIG;
return kMinimumLandZ;
// Get the surface element for the tile
auto surfaceElement = MapGetSurfaceElementAt(loc);
if (surfaceElement == nullptr)
{
return MINIMUM_LAND_HEIGHT_BIG;
return kMinimumLandZ;
}
auto height = surfaceElement->GetBaseZ();
@ -567,7 +567,7 @@ int16_t TileElementHeight(const CoordsXYZ& loc, uint8_t slope)
{
// Off the map
if (!MapIsLocationValid(loc))
return MINIMUM_LAND_HEIGHT_BIG;
return kMinimumLandZ;
auto height = loc.z;
@ -1471,8 +1471,8 @@ static void ClearElementAt(const CoordsXY& loc, TileElement** elementPtr)
switch (element->GetType())
{
case TileElementType::Surface:
element->BaseHeight = MINIMUM_LAND_HEIGHT;
element->ClearanceHeight = MINIMUM_LAND_HEIGHT;
element->BaseHeight = kMinimumLandHeight;
element->ClearanceHeight = kMinimumLandHeight;
element->Owner = 0;
element->AsSurface()->SetSlope(TILE_ELEMENT_SLOPE_FLAT);
element->AsSurface()->SetSurfaceObjectIndex(0);

View file

@ -16,10 +16,10 @@
#include <initializer_list>
#include <vector>
constexpr uint8_t MINIMUM_LAND_HEIGHT = 2;
constexpr uint8_t MAXIMUM_LAND_HEIGHT = 254;
constexpr uint8_t MINIMUM_WATER_HEIGHT = 2;
constexpr uint8_t MAXIMUM_WATER_HEIGHT = 254;
constexpr uint8_t kMinimumLandHeight = 2;
constexpr uint8_t kMaximumLandHeight = 254;
constexpr uint8_t kMinimumWaterHeight = 2;
constexpr uint8_t kMaximumWaterHeight = 254;
/**
* The land height that counts as 0 metres/feet for the land height labels and altitude graphs.
*/
@ -33,7 +33,7 @@ constexpr const int32_t MAXIMUM_MAP_SIZE_BIG = COORDS_XY_STEP * MAXIMUM_MAP_SIZE
constexpr int32_t MAXIMUM_TILE_START_XY = MAXIMUM_MAP_SIZE_BIG - COORDS_XY_STEP;
constexpr const int32_t LAND_HEIGHT_STEP = 2 * COORDS_Z_STEP;
constexpr const int32_t WATER_HEIGHT_STEP = 2 * COORDS_Z_STEP;
constexpr const int32_t MINIMUM_LAND_HEIGHT_BIG = MINIMUM_LAND_HEIGHT * COORDS_Z_STEP;
constexpr const int32_t kMinimumLandZ = kMinimumLandHeight * COORDS_Z_STEP;
constexpr TileCoordsXY DEFAULT_MAP_SIZE = { 150, 150 };
// How high construction has to be off the ground when the player owns construction rights, in tile coords.
constexpr uint8_t ConstructionRightsClearanceSmall = 3;

View file

@ -107,8 +107,8 @@ void TileElement::ClearAs(TileElementType newType)
Type = 0;
SetType(newType);
Flags = 0;
BaseHeight = MINIMUM_LAND_HEIGHT;
ClearanceHeight = MINIMUM_LAND_HEIGHT;
BaseHeight = kMinimumLandHeight;
ClearanceHeight = kMinimumLandHeight;
Owner = 0;
std::fill_n(Pad05, sizeof(Pad05), 0x00);
std::fill_n(Pad08, sizeof(Pad08), 0x00);