Merge pull request #21905 from Harry-Hopkinson/refactor-constant-notation

Refactor constant notation and replace macros with constexpr.
This commit is contained in:
Michael Steenbeek 2024-04-26 19:29:29 +02:00 committed by GitHub
commit 6d0b02e524
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 30 additions and 29 deletions

View File

@ -216,7 +216,7 @@ void TextureCache::CreateTextures()
void TextureCache::GeneratePaletteTexture()
{
static_assert(PALETTE_TOTAL_OFFSETS + 5 < 256, "Height of palette too large!");
static_assert(kPaletteTotalOffsets + 5 < 256, "Height of palette too large!");
constexpr int32_t height = 256;
constexpr int32_t width = height;
DrawPixelInfo dpi = CreateDPI(width, height);
@ -227,7 +227,7 @@ void TextureCache::GeneratePaletteTexture()
dpi.bits[i] = i;
}
for (int i = 0; i < PALETTE_TOTAL_OFFSETS; ++i)
for (int i = 0; i < kPaletteTotalOffsets; ++i)
{
GLint y = PaletteToY(static_cast<FilterPaletteID>(i));

View File

@ -224,8 +224,8 @@ WindowBase* WindowCreate(
}
// Check if there are any window slots left
// include WINDOW_LIMIT_RESERVED for items such as the main viewport and toolbars to not appear to be counted.
if (g_window_list.size() >= static_cast<size_t>(gConfigGeneral.WindowLimit + WINDOW_LIMIT_RESERVED))
// include kWindowLimitReserved for items such as the main viewport and toolbars to not appear to be counted.
if (g_window_list.size() >= static_cast<size_t>(gConfigGeneral.WindowLimit + kWindowLimitReserved))
{
// Close least recently used window
for (auto& w : g_window_list)

View File

@ -557,7 +557,7 @@ static Widget _serverListWidgets[] = {
void JoinServer(std::string address)
{
int32_t port = NETWORK_DEFAULT_PORT;
int32_t port = kNetworkDefaultPort;
auto endBracketIndex = address.find(']');
auto colonIndex = address.find_last_of(':');
if (colonIndex != std::string::npos)

View File

@ -101,7 +101,7 @@ static Widget _windowServerStartWidgets[] = {
WindowStartTextbox(*this, widgetIndex, _name, 64);
break;
case WIDX_DESCRIPTION_INPUT:
WindowStartTextbox(*this, widgetIndex, _description, MAX_SERVER_DESCRIPTION_LENGTH);
WindowStartTextbox(*this, widgetIndex, _description, kMaxServerDescriptionLength);
break;
case WIDX_GREETING_INPUT:
WindowStartTextbox(*this, widgetIndex, _greeting, kChatInputSize);
@ -258,7 +258,7 @@ static Widget _windowServerStartWidgets[] = {
private:
char _port[7];
char _name[65];
char _description[MAX_SERVER_DESCRIPTION_LENGTH];
char _description[kMaxServerDescriptionLength];
char _greeting[kChatInputSize];
char _password[33];
static void ScenarioSelectCallback(const utf8* path)

View File

@ -40,7 +40,7 @@
#ifndef DISABLE_NETWORK
int32_t gNetworkStart = NETWORK_MODE_NONE;
std::string gNetworkStartHost;
int32_t gNetworkStartPort = NETWORK_DEFAULT_PORT;
int32_t gNetworkStartPort = kNetworkDefaultPort;
std::string gNetworkStartAddress;
static uint32_t _port = 0;

View File

@ -60,7 +60,7 @@ static exitcode_t HandleUriJoin(const std::vector<std::string>& args)
{
std::string hostname;
int32_t port;
if (args.size() > 1 && TryParseHostnamePort(args[1], &hostname, &port, NETWORK_DEFAULT_PORT))
if (args.size() > 1 && TryParseHostnamePort(args[1], &hostname, &port, kNetworkDefaultPort))
{
// Set the network start configuration
gNetworkStart = NETWORK_MODE_CLIENT;

View File

@ -217,7 +217,7 @@ namespace Config
model->LastSaveScenarioDirectory = reader->GetString("last_scenario_directory", "");
model->LastSaveTrackDirectory = reader->GetString("last_track_directory", "");
model->UseNativeBrowseDialog = reader->GetBoolean("use_native_browse_dialog", false);
model->WindowLimit = reader->GetInt32("window_limit", WINDOW_LIMIT_MAX);
model->WindowLimit = reader->GetInt32("window_limit", kWindowLimitMax);
model->ZoomToCursor = reader->GetBoolean("zoom_to_cursor", true);
model->RenderWeatherEffects = reader->GetBoolean("render_weather_effects", true);
model->RenderWeatherGloom = reader->GetBoolean("render_weather_gloom", true);
@ -422,7 +422,7 @@ namespace Config
auto model = &gConfigNetwork;
model->PlayerName = std::move(playerName);
model->DefaultPort = reader->GetInt32("default_port", NETWORK_DEFAULT_PORT);
model->DefaultPort = reader->GetInt32("default_port", kNetworkDefaultPort);
model->ListenAddress = reader->GetString("listen_address", "");
model->DefaultPassword = reader->GetString("default_password", "");
model->StayConnected = reader->GetBoolean("stay_connected", true);

View File

@ -405,7 +405,7 @@ const FilterPaletteID GlassPaletteIds[COLOUR_COUNT] = {
};
// Previously 0x97FCBC use it to get the correct palette from g1_elements
static constexpr uint16_t palette_to_g1_offset[PALETTE_TOTAL_OFFSETS] = {
static constexpr uint16_t palette_to_g1_offset[kPaletteTotalOffsets] = {
SPR_PALETTE_BLACK,
SPR_PALETTE_GREY,
SPR_PALETTE_WHITE,
@ -904,7 +904,7 @@ void GfxDrawPickedUpPeep(DrawPixelInfo& dpi)
std::optional<uint32_t> GetPaletteG1Index(colour_t paletteId)
{
if (paletteId < PALETTE_TOTAL_OFFSETS)
if (paletteId < kPaletteTotalOffsets)
{
return palette_to_g1_offset[paletteId];
}

View File

@ -504,8 +504,7 @@ void FASTCALL BlitPixels(const uint8_t* src, uint8_t* dst, const PaletteMap& pal
}
}
#define PALETTE_TO_G1_OFFSET_COUNT 144
constexpr uint8_t PALETTE_TOTAL_OFFSETS = 192;
constexpr uint8_t kPaletteTotalOffsets = 192;
#define INSET_RECT_F_30 (INSET_RECT_FLAG_BORDER_INSET | INSET_RECT_FLAG_FILL_NONE)
#define INSET_RECT_F_60 (INSET_RECT_FLAG_BORDER_INSET | INSET_RECT_FLAG_FILL_DONT_LIGHTEN)

View File

@ -114,7 +114,7 @@ struct InteractionInfo
ViewportInteractionItem SpriteType = ViewportInteractionItem::None;
};
constexpr int32_t kMaxViewportCount = WINDOW_LIMIT_MAX;
constexpr int32_t kMaxViewportCount = kWindowLimitMax;
/**
* A reference counter for whether something is forcing the grid lines to show. When the counter

View File

@ -164,7 +164,7 @@ static void WindowCloseSurplus(int32_t cap, WindowClass avoid_classification)
// find the amount of windows that are currently open
auto count = static_cast<int32_t>(g_window_list.size());
// difference between amount open and cap = amount to close
auto diff = count - WINDOW_LIMIT_RESERVED - cap;
auto diff = count - kWindowLimitReserved - cap;
for (auto i = 0; i < diff; i++)
{
// iterates through the list until it finds the newest window, or a window that can be closed
@ -194,7 +194,7 @@ static void WindowCloseSurplus(int32_t cap, WindowClass avoid_classification)
void WindowSetWindowLimit(int32_t value)
{
int32_t prev = gConfigGeneral.WindowLimit;
int32_t val = std::clamp(value, WINDOW_LIMIT_MIN, WINDOW_LIMIT_MAX);
int32_t val = std::clamp<int32_t>(value, kWindowLimitMin, kWindowLimitMax);
gConfigGeneral.WindowLimit = val;
ConfigSaveDefault();
// Checks if value decreases and then closes surplus

View File

@ -482,9 +482,9 @@ enum class Tool
using modal_callback = void (*)(int32_t result);
using close_callback = void (*)();
#define WINDOW_LIMIT_MIN 4
#define WINDOW_LIMIT_MAX 64
#define WINDOW_LIMIT_RESERVED 4 // Used to reserve room for the main viewport, toolbars, etc.
constexpr int8_t kWindowLimitMin = 4;
constexpr int8_t kWindowLimitMax = 64;
constexpr int8_t kWindowLimitReserved = 4; // Used to reserve room for the main viewport, toolbars, etc.
extern WindowBase* gWindowAudioExclusive;

View File

@ -107,7 +107,7 @@ private:
{
if (_lanListener->GetStatus() != SocketStatus::Listening)
{
_lanListener->Listen(NETWORK_LAN_BROADCAST_PORT);
_lanListener->Listen(kNetworkLanBroadcastPort);
}
else
{
@ -119,7 +119,7 @@ private:
{
std::string sender = endpoint->GetHostname();
LOG_VERBOSE("Received %zu bytes from %s on LAN broadcast port", recievedBytes, sender.c_str());
if (String::Equals(buffer, NETWORK_LAN_BROADCAST_MSG))
if (String::Equals(buffer, kNetworkLanBroadcastMsg))
{
auto body = GetBroadcastJson();
auto bodyDump = body.dump();

View File

@ -270,11 +270,11 @@ std::future<std::vector<ServerListEntry>> ServerList::FetchLocalServerListAsync(
constexpr auto RECV_DELAY_MS = 10;
constexpr auto RECV_WAIT_MS = 2000;
std::string_view msg = NETWORK_LAN_BROADCAST_MSG;
std::string_view msg = kNetworkLanBroadcastMsg;
auto udpSocket = CreateUdpSocket();
LOG_VERBOSE("Broadcasting %zu bytes to the LAN (%s)", msg.size(), broadcastAddress.c_str());
auto len = udpSocket->SendData(broadcastAddress, NETWORK_LAN_BROADCAST_PORT, msg.data(), msg.size());
auto len = udpSocket->SendData(broadcastAddress, kNetworkLanBroadcastPort, msg.data(), msg.size());
if (len != msg.size())
{
throw std::runtime_error("Unable to broadcast server query.");

View File

@ -9,10 +9,12 @@
#pragma once
#define NETWORK_DEFAULT_PORT 11753
#define NETWORK_LAN_BROADCAST_PORT 11754
#define NETWORK_LAN_BROADCAST_MSG "openrct2.server.query"
#define MAX_SERVER_DESCRIPTION_LENGTH 256
#include <cstdint>
constexpr uint16_t kNetworkDefaultPort = 11753;
constexpr uint16_t kNetworkLanBroadcastPort = 11754;
constexpr const char* kNetworkLanBroadcastMsg = "openrct2.server.query";
constexpr uint16_t kMaxServerDescriptionLength = 256;
#include "../Game.h"
#include "../common.h"