mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge pull request #21905 from Harry-Hopkinson/refactor-constant-notation
Refactor constant notation and replace macros with constexpr.
This commit is contained in:
commit
6d0b02e524
|
@ -216,7 +216,7 @@ void TextureCache::CreateTextures()
|
||||||
|
|
||||||
void TextureCache::GeneratePaletteTexture()
|
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 height = 256;
|
||||||
constexpr int32_t width = height;
|
constexpr int32_t width = height;
|
||||||
DrawPixelInfo dpi = CreateDPI(width, height);
|
DrawPixelInfo dpi = CreateDPI(width, height);
|
||||||
|
@ -227,7 +227,7 @@ void TextureCache::GeneratePaletteTexture()
|
||||||
dpi.bits[i] = i;
|
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));
|
GLint y = PaletteToY(static_cast<FilterPaletteID>(i));
|
||||||
|
|
||||||
|
|
|
@ -224,8 +224,8 @@ WindowBase* WindowCreate(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if there are any window slots left
|
// 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.
|
// 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 + WINDOW_LIMIT_RESERVED))
|
if (g_window_list.size() >= static_cast<size_t>(gConfigGeneral.WindowLimit + kWindowLimitReserved))
|
||||||
{
|
{
|
||||||
// Close least recently used window
|
// Close least recently used window
|
||||||
for (auto& w : g_window_list)
|
for (auto& w : g_window_list)
|
||||||
|
|
|
@ -557,7 +557,7 @@ static Widget _serverListWidgets[] = {
|
||||||
|
|
||||||
void JoinServer(std::string address)
|
void JoinServer(std::string address)
|
||||||
{
|
{
|
||||||
int32_t port = NETWORK_DEFAULT_PORT;
|
int32_t port = kNetworkDefaultPort;
|
||||||
auto endBracketIndex = address.find(']');
|
auto endBracketIndex = address.find(']');
|
||||||
auto colonIndex = address.find_last_of(':');
|
auto colonIndex = address.find_last_of(':');
|
||||||
if (colonIndex != std::string::npos)
|
if (colonIndex != std::string::npos)
|
||||||
|
|
|
@ -101,7 +101,7 @@ static Widget _windowServerStartWidgets[] = {
|
||||||
WindowStartTextbox(*this, widgetIndex, _name, 64);
|
WindowStartTextbox(*this, widgetIndex, _name, 64);
|
||||||
break;
|
break;
|
||||||
case WIDX_DESCRIPTION_INPUT:
|
case WIDX_DESCRIPTION_INPUT:
|
||||||
WindowStartTextbox(*this, widgetIndex, _description, MAX_SERVER_DESCRIPTION_LENGTH);
|
WindowStartTextbox(*this, widgetIndex, _description, kMaxServerDescriptionLength);
|
||||||
break;
|
break;
|
||||||
case WIDX_GREETING_INPUT:
|
case WIDX_GREETING_INPUT:
|
||||||
WindowStartTextbox(*this, widgetIndex, _greeting, kChatInputSize);
|
WindowStartTextbox(*this, widgetIndex, _greeting, kChatInputSize);
|
||||||
|
@ -258,7 +258,7 @@ static Widget _windowServerStartWidgets[] = {
|
||||||
private:
|
private:
|
||||||
char _port[7];
|
char _port[7];
|
||||||
char _name[65];
|
char _name[65];
|
||||||
char _description[MAX_SERVER_DESCRIPTION_LENGTH];
|
char _description[kMaxServerDescriptionLength];
|
||||||
char _greeting[kChatInputSize];
|
char _greeting[kChatInputSize];
|
||||||
char _password[33];
|
char _password[33];
|
||||||
static void ScenarioSelectCallback(const utf8* path)
|
static void ScenarioSelectCallback(const utf8* path)
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
#ifndef DISABLE_NETWORK
|
#ifndef DISABLE_NETWORK
|
||||||
int32_t gNetworkStart = NETWORK_MODE_NONE;
|
int32_t gNetworkStart = NETWORK_MODE_NONE;
|
||||||
std::string gNetworkStartHost;
|
std::string gNetworkStartHost;
|
||||||
int32_t gNetworkStartPort = NETWORK_DEFAULT_PORT;
|
int32_t gNetworkStartPort = kNetworkDefaultPort;
|
||||||
std::string gNetworkStartAddress;
|
std::string gNetworkStartAddress;
|
||||||
|
|
||||||
static uint32_t _port = 0;
|
static uint32_t _port = 0;
|
||||||
|
|
|
@ -60,7 +60,7 @@ static exitcode_t HandleUriJoin(const std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
std::string hostname;
|
std::string hostname;
|
||||||
int32_t port;
|
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
|
// Set the network start configuration
|
||||||
gNetworkStart = NETWORK_MODE_CLIENT;
|
gNetworkStart = NETWORK_MODE_CLIENT;
|
||||||
|
|
|
@ -217,7 +217,7 @@ namespace Config
|
||||||
model->LastSaveScenarioDirectory = reader->GetString("last_scenario_directory", "");
|
model->LastSaveScenarioDirectory = reader->GetString("last_scenario_directory", "");
|
||||||
model->LastSaveTrackDirectory = reader->GetString("last_track_directory", "");
|
model->LastSaveTrackDirectory = reader->GetString("last_track_directory", "");
|
||||||
model->UseNativeBrowseDialog = reader->GetBoolean("use_native_browse_dialog", false);
|
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->ZoomToCursor = reader->GetBoolean("zoom_to_cursor", true);
|
||||||
model->RenderWeatherEffects = reader->GetBoolean("render_weather_effects", true);
|
model->RenderWeatherEffects = reader->GetBoolean("render_weather_effects", true);
|
||||||
model->RenderWeatherGloom = reader->GetBoolean("render_weather_gloom", true);
|
model->RenderWeatherGloom = reader->GetBoolean("render_weather_gloom", true);
|
||||||
|
@ -422,7 +422,7 @@ namespace Config
|
||||||
|
|
||||||
auto model = &gConfigNetwork;
|
auto model = &gConfigNetwork;
|
||||||
model->PlayerName = std::move(playerName);
|
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->ListenAddress = reader->GetString("listen_address", "");
|
||||||
model->DefaultPassword = reader->GetString("default_password", "");
|
model->DefaultPassword = reader->GetString("default_password", "");
|
||||||
model->StayConnected = reader->GetBoolean("stay_connected", true);
|
model->StayConnected = reader->GetBoolean("stay_connected", true);
|
||||||
|
|
|
@ -405,7 +405,7 @@ const FilterPaletteID GlassPaletteIds[COLOUR_COUNT] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Previously 0x97FCBC use it to get the correct palette from g1_elements
|
// 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_BLACK,
|
||||||
SPR_PALETTE_GREY,
|
SPR_PALETTE_GREY,
|
||||||
SPR_PALETTE_WHITE,
|
SPR_PALETTE_WHITE,
|
||||||
|
@ -904,7 +904,7 @@ void GfxDrawPickedUpPeep(DrawPixelInfo& dpi)
|
||||||
|
|
||||||
std::optional<uint32_t> GetPaletteG1Index(colour_t paletteId)
|
std::optional<uint32_t> GetPaletteG1Index(colour_t paletteId)
|
||||||
{
|
{
|
||||||
if (paletteId < PALETTE_TOTAL_OFFSETS)
|
if (paletteId < kPaletteTotalOffsets)
|
||||||
{
|
{
|
||||||
return palette_to_g1_offset[paletteId];
|
return palette_to_g1_offset[paletteId];
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 kPaletteTotalOffsets = 192;
|
||||||
constexpr uint8_t PALETTE_TOTAL_OFFSETS = 192;
|
|
||||||
|
|
||||||
#define INSET_RECT_F_30 (INSET_RECT_FLAG_BORDER_INSET | INSET_RECT_FLAG_FILL_NONE)
|
#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)
|
#define INSET_RECT_F_60 (INSET_RECT_FLAG_BORDER_INSET | INSET_RECT_FLAG_FILL_DONT_LIGHTEN)
|
||||||
|
|
|
@ -114,7 +114,7 @@ struct InteractionInfo
|
||||||
ViewportInteractionItem SpriteType = ViewportInteractionItem::None;
|
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
|
* A reference counter for whether something is forcing the grid lines to show. When the counter
|
||||||
|
|
|
@ -164,7 +164,7 @@ static void WindowCloseSurplus(int32_t cap, WindowClass avoid_classification)
|
||||||
// find the amount of windows that are currently open
|
// find the amount of windows that are currently open
|
||||||
auto count = static_cast<int32_t>(g_window_list.size());
|
auto count = static_cast<int32_t>(g_window_list.size());
|
||||||
// difference between amount open and cap = amount to close
|
// 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++)
|
for (auto i = 0; i < diff; i++)
|
||||||
{
|
{
|
||||||
// iterates through the list until it finds the newest window, or a window that can be closed
|
// 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)
|
void WindowSetWindowLimit(int32_t value)
|
||||||
{
|
{
|
||||||
int32_t prev = gConfigGeneral.WindowLimit;
|
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;
|
gConfigGeneral.WindowLimit = val;
|
||||||
ConfigSaveDefault();
|
ConfigSaveDefault();
|
||||||
// Checks if value decreases and then closes surplus
|
// Checks if value decreases and then closes surplus
|
||||||
|
|
|
@ -482,9 +482,9 @@ enum class Tool
|
||||||
using modal_callback = void (*)(int32_t result);
|
using modal_callback = void (*)(int32_t result);
|
||||||
using close_callback = void (*)();
|
using close_callback = void (*)();
|
||||||
|
|
||||||
#define WINDOW_LIMIT_MIN 4
|
constexpr int8_t kWindowLimitMin = 4;
|
||||||
#define WINDOW_LIMIT_MAX 64
|
constexpr int8_t kWindowLimitMax = 64;
|
||||||
#define WINDOW_LIMIT_RESERVED 4 // Used to reserve room for the main viewport, toolbars, etc.
|
constexpr int8_t kWindowLimitReserved = 4; // Used to reserve room for the main viewport, toolbars, etc.
|
||||||
|
|
||||||
extern WindowBase* gWindowAudioExclusive;
|
extern WindowBase* gWindowAudioExclusive;
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ private:
|
||||||
{
|
{
|
||||||
if (_lanListener->GetStatus() != SocketStatus::Listening)
|
if (_lanListener->GetStatus() != SocketStatus::Listening)
|
||||||
{
|
{
|
||||||
_lanListener->Listen(NETWORK_LAN_BROADCAST_PORT);
|
_lanListener->Listen(kNetworkLanBroadcastPort);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -119,7 +119,7 @@ private:
|
||||||
{
|
{
|
||||||
std::string sender = endpoint->GetHostname();
|
std::string sender = endpoint->GetHostname();
|
||||||
LOG_VERBOSE("Received %zu bytes from %s on LAN broadcast port", recievedBytes, sender.c_str());
|
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 body = GetBroadcastJson();
|
||||||
auto bodyDump = body.dump();
|
auto bodyDump = body.dump();
|
||||||
|
|
|
@ -270,11 +270,11 @@ std::future<std::vector<ServerListEntry>> ServerList::FetchLocalServerListAsync(
|
||||||
constexpr auto RECV_DELAY_MS = 10;
|
constexpr auto RECV_DELAY_MS = 10;
|
||||||
constexpr auto RECV_WAIT_MS = 2000;
|
constexpr auto RECV_WAIT_MS = 2000;
|
||||||
|
|
||||||
std::string_view msg = NETWORK_LAN_BROADCAST_MSG;
|
std::string_view msg = kNetworkLanBroadcastMsg;
|
||||||
auto udpSocket = CreateUdpSocket();
|
auto udpSocket = CreateUdpSocket();
|
||||||
|
|
||||||
LOG_VERBOSE("Broadcasting %zu bytes to the LAN (%s)", msg.size(), broadcastAddress.c_str());
|
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())
|
if (len != msg.size())
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Unable to broadcast server query.");
|
throw std::runtime_error("Unable to broadcast server query.");
|
||||||
|
|
|
@ -9,10 +9,12 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define NETWORK_DEFAULT_PORT 11753
|
#include <cstdint>
|
||||||
#define NETWORK_LAN_BROADCAST_PORT 11754
|
|
||||||
#define NETWORK_LAN_BROADCAST_MSG "openrct2.server.query"
|
constexpr uint16_t kNetworkDefaultPort = 11753;
|
||||||
#define MAX_SERVER_DESCRIPTION_LENGTH 256
|
constexpr uint16_t kNetworkLanBroadcastPort = 11754;
|
||||||
|
constexpr const char* kNetworkLanBroadcastMsg = "openrct2.server.query";
|
||||||
|
constexpr uint16_t kMaxServerDescriptionLength = 256;
|
||||||
|
|
||||||
#include "../Game.h"
|
#include "../Game.h"
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
|
Loading…
Reference in New Issue