mirror of https://github.com/OpenRCT2/OpenRCT2.git
Remove legacy stuff in common.h (#20523)
* Remove old interop macro * Remove legacy string macro things * Unbreak the posix/linux/unix builds * Add String::IEquals and use it for case insensitive compare * Add missing include for posix * Replace _strnicmp with String::StartsWith * Add LoByte and HiByte into Util.h, swap macros * Fix android build * Hopefully last of the string things * Replace STUB directly with the warning
This commit is contained in:
parent
2b6cfafc92
commit
379287ed0f
|
@ -60,7 +60,7 @@ namespace OpenRCT2::Ui
|
|||
|
||||
std::string ShowFileDialog(SDL_Window* window, const FileDialogDesc& desc) override
|
||||
{
|
||||
STUB();
|
||||
LOG_WARNING("Function %s at %s:%d is a stub.", __PRETTY_FUNCTION__, __FILE__, __LINE__);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ namespace OpenRCT2::Ui
|
|||
std::string ShowDirectoryDialog(SDL_Window* window, const std::string& title) override
|
||||
{
|
||||
LOG_INFO(title.c_str());
|
||||
STUB();
|
||||
LOG_WARNING("Function %s at %s:%d is a stub.", __PRETTY_FUNCTION__, __FILE__, __LINE__);
|
||||
|
||||
return "/sdcard/rct2";
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ namespace OpenRCT2::Ui
|
|||
|
||||
void OpenURL(const std::string& url) override
|
||||
{
|
||||
STUB();
|
||||
LOG_WARNING("Function %s at %s:%d is a stub.", __PRETTY_FUNCTION__, __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
bool HasFilePicker() const override
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
# include <openrct2/ui/UiContext.h>
|
||||
# include <sstream>
|
||||
# include <stdexcept>
|
||||
# include <unistd.h>
|
||||
|
||||
namespace OpenRCT2::Ui
|
||||
{
|
||||
|
|
|
@ -49,7 +49,7 @@ namespace OpenRCT2::Ui
|
|||
|
||||
bool IsSteamOverlayAttached() override
|
||||
{
|
||||
STUB();
|
||||
LOG_WARNING("Function %s at %s:%d is a stub.", __PRETTY_FUNCTION__, __FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "core/Imaging.h"
|
||||
#include "core/Json.hpp"
|
||||
#include "core/Path.hpp"
|
||||
#include "core/String.hpp"
|
||||
#include "drawing/Drawing.h"
|
||||
#include "drawing/ImageImporter.h"
|
||||
#include "object/ObjectLimits.h"
|
||||
|
@ -270,7 +271,7 @@ int32_t CommandLineForSprite(const char** argv, int32_t argc)
|
|||
if (argc == 0)
|
||||
return -1;
|
||||
|
||||
if (_strcmpi(argv[0], "details") == 0)
|
||||
if (String::IEquals(argv[0], "details"))
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
|
@ -317,7 +318,7 @@ int32_t CommandLineForSprite(const char** argv, int32_t argc)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (_strcmpi(argv[0], "export") == 0)
|
||||
if (String::IEquals(argv[0], "export"))
|
||||
{
|
||||
if (argc < 4)
|
||||
{
|
||||
|
@ -351,7 +352,7 @@ int32_t CommandLineForSprite(const char** argv, int32_t argc)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (_strcmpi(argv[0], "exportall") == 0)
|
||||
if (String::IEquals(argv[0], "exportall"))
|
||||
{
|
||||
if (argc < 3)
|
||||
{
|
||||
|
@ -396,7 +397,7 @@ int32_t CommandLineForSprite(const char** argv, int32_t argc)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (_strcmpi(argv[0], "exportalldat") == 0)
|
||||
if (String::IEquals(argv[0], "exportalldat"))
|
||||
{
|
||||
if (argc < 3)
|
||||
{
|
||||
|
@ -457,7 +458,7 @@ int32_t CommandLineForSprite(const char** argv, int32_t argc)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (_strcmpi(argv[0], "create") == 0)
|
||||
if (String::IEquals(argv[0], "create"))
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
|
@ -472,7 +473,7 @@ int32_t CommandLineForSprite(const char** argv, int32_t argc)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (_strcmpi(argv[0], "append") == 0)
|
||||
if (String::IEquals(argv[0], "append"))
|
||||
{
|
||||
if (argc != 3 && argc != 5)
|
||||
{
|
||||
|
@ -524,7 +525,7 @@ int32_t CommandLineForSprite(const char** argv, int32_t argc)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (_strcmpi(argv[0], "build") == 0)
|
||||
if (String::IEquals(argv[0], "build"))
|
||||
{
|
||||
if (argc < 3)
|
||||
{
|
||||
|
@ -612,7 +613,7 @@ int32_t CommandLineForSprite(const char** argv, int32_t argc)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (_strcmpi(argv[0], "combine") == 0)
|
||||
if (String::IEquals(argv[0], "combine"))
|
||||
{
|
||||
return CommandLineForSpriteCombine(argv, argc);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "actions/ResultWithMessage.h"
|
||||
#include "audio/audio.h"
|
||||
#include "core/Path.hpp"
|
||||
#include "core/String.hpp"
|
||||
#include "entity/EntityList.h"
|
||||
#include "entity/EntityRegistry.h"
|
||||
#include "entity/Guest.h"
|
||||
|
@ -263,7 +264,7 @@ namespace Editor
|
|||
if (!loadSuccess)
|
||||
return false;
|
||||
|
||||
if (_stricmp(extension, ".sv4") == 0 || _stricmp(extension, ".sv6") == 0 || _stricmp(extension, ".sv7") == 0)
|
||||
if (String::IEquals(extension, ".sv4") || String::IEquals(extension, ".sv6") || String::IEquals(extension, ".sv7") == 0)
|
||||
{
|
||||
loadedFromSave = true;
|
||||
}
|
||||
|
|
|
@ -37,30 +37,6 @@ using colour_t = uint8_t;
|
|||
// Gets the name of a symbol as a C string
|
||||
#define nameof(symbol) #symbol
|
||||
|
||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||
# include <unistd.h>
|
||||
# define STUB() LOG_WARNING("Function %s at %s:%d is a stub.", __PRETTY_FUNCTION__, __FILE__, __LINE__)
|
||||
# define _strcmpi _stricmp
|
||||
# define _stricmp(x, y) strcasecmp((x), (y))
|
||||
# define _strnicmp(x, y, n) strncasecmp((x), (y), (n))
|
||||
|
||||
# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
# define RCT2_ENDIANNESS __ORDER_LITTLE_ENDIAN__
|
||||
# define LOBYTE(w) (static_cast<uint8_t>(w))
|
||||
# define HIBYTE(w) (static_cast<uint8_t>((static_cast<uint16_t>(w) >> 8) & 0xFF))
|
||||
# endif // __BYTE_ORDER__
|
||||
|
||||
# ifndef RCT2_ENDIANNESS
|
||||
# error Unknown endianness!
|
||||
# endif // RCT2_ENDIANNESS
|
||||
|
||||
#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||
|
||||
// BSD and macOS have MAP_ANON instead of MAP_ANONYMOUS
|
||||
#ifndef MAP_ANONYMOUS
|
||||
# define MAP_ANONYMOUS MAP_ANON
|
||||
#endif
|
||||
|
||||
#define OPENRCT2_MASTER_SERVER_URL "https://servers.openrct2.io"
|
||||
|
||||
// Time (represented as number of 100-nanosecond intervals since 0001-01-01T00:00:00Z)
|
||||
|
|
|
@ -33,6 +33,11 @@
|
|||
#include "String.hpp"
|
||||
#include "StringBuilder.h"
|
||||
|
||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||
# include <strings.h>
|
||||
# define _stricmp(x, y) strcasecmp((x), (y))
|
||||
#endif
|
||||
|
||||
namespace String
|
||||
{
|
||||
std::string ToStd(const utf8* str)
|
||||
|
|
|
@ -57,8 +57,20 @@ namespace String
|
|||
int32_t Compare(const std::string& a, const std::string& b, bool ignoreCase = false);
|
||||
int32_t Compare(const utf8* a, const utf8* b, bool ignoreCase = false);
|
||||
bool Equals(std::string_view a, std::string_view b, bool ignoreCase = false);
|
||||
inline bool IEquals(std::string_view a, std::string_view b)
|
||||
{
|
||||
return Equals(a, b, true);
|
||||
}
|
||||
bool Equals(const std::string& a, const std::string& b, bool ignoreCase = false);
|
||||
inline bool IEquals(const std::string& a, const std::string& b)
|
||||
{
|
||||
return Equals(a, b, true);
|
||||
}
|
||||
bool Equals(const utf8* a, const utf8* b, bool ignoreCase = false);
|
||||
inline bool IEquals(const utf8* a, const utf8* b)
|
||||
{
|
||||
return Equals(a, b, true);
|
||||
}
|
||||
bool StartsWith(std::string_view str, std::string_view match, bool ignoreCase = false);
|
||||
bool EndsWith(std::string_view str, std::string_view match, bool ignoreCase = false);
|
||||
bool Contains(std::string_view haystack, std::string_view needle, bool ignoreCase = false);
|
||||
|
|
|
@ -121,17 +121,17 @@ public:
|
|||
|
||||
void SetFileData(std::string_view path, std::vector<uint8_t>&& data) override
|
||||
{
|
||||
STUB();
|
||||
LOG_WARNING("Function %s at %s:%d is a stub.", __PRETTY_FUNCTION__, __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
void DeleteFile(std::string_view) override
|
||||
{
|
||||
STUB();
|
||||
LOG_WARNING("Function %s at %s:%d is a stub.", __PRETTY_FUNCTION__, __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
void RenameFile(std::string_view, std::string_view) override
|
||||
{
|
||||
STUB();
|
||||
LOG_WARNING("Function %s at %s:%d is a stub.", __PRETTY_FUNCTION__, __FILE__, __LINE__);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "../core/DataSerialiser.h"
|
||||
#include "../core/Guard.hpp"
|
||||
#include "../core/Numerics.hpp"
|
||||
#include "../core/String.hpp"
|
||||
#include "../entity/Balloon.h"
|
||||
#include "../entity/EntityRegistry.h"
|
||||
#include "../entity/MoneyEffect.h"
|
||||
|
@ -587,8 +588,10 @@ int32_t Guest::GetEasterEggNameId() const
|
|||
FormatStringLegacy(buffer, sizeof(buffer), STR_STRINGID, ft.Data());
|
||||
|
||||
for (uint32_t i = 0; i < std::size(gPeepEasterEggNames); i++)
|
||||
if (_stricmp(buffer, gPeepEasterEggNames[i]) == 0)
|
||||
{
|
||||
if (String::IEquals(buffer, gPeepEasterEggNames[i]))
|
||||
return static_cast<int32_t>(i);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -733,7 +736,7 @@ int32_t Guest::CheckEasterEggName(int32_t index) const
|
|||
FormatNameTo(ft);
|
||||
FormatStringLegacy(buffer, sizeof(buffer), STR_STRINGID, ft.Data());
|
||||
|
||||
return _stricmp(buffer, gPeepEasterEggNames[index]) == 0;
|
||||
return String::IEquals(buffer, gPeepEasterEggNames[index]);
|
||||
}
|
||||
|
||||
void Guest::Loc68F9F3()
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "../core/File.h"
|
||||
#include "../core/Imaging.h"
|
||||
#include "../core/Path.hpp"
|
||||
#include "../core/String.hpp"
|
||||
#include "../drawing/Drawing.h"
|
||||
#include "../drawing/X8DrawingEngine.h"
|
||||
#include "../localisation/Formatter.h"
|
||||
|
@ -574,7 +575,7 @@ int32_t CommandLineForScreenshot(const char** argv, int32_t argc, ScreenshotOpti
|
|||
}
|
||||
}
|
||||
|
||||
bool giantScreenshot = (argc == 5) && _stricmp(argv[2], "giant") == 0;
|
||||
bool giantScreenshot = (argc == 5) && String::IEquals(argv[2], "giant");
|
||||
if (argc != 4 && argc != 8 && !giantScreenshot)
|
||||
{
|
||||
std::printf("Usage: openrct2 screenshot <file> <output_image> <width> <height> [<x> <y> <zoom> <rotation>]\n");
|
||||
|
|
|
@ -49,8 +49,10 @@
|
|||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#include "../common.h"
|
||||
using SOCKET = int32_t;
|
||||
#define SOCKET_ERROR -1
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# include <limits.h>
|
||||
# include <locale.h>
|
||||
# include <pwd.h>
|
||||
# include <unistd.h>
|
||||
# include <vector>
|
||||
# if defined(__FreeBSD__) || defined(__NetBSD__)
|
||||
# include <stddef.h>
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
# include <pwd.h>
|
||||
# include <sys/stat.h>
|
||||
# include <sys/time.h>
|
||||
# include <unistd.h>
|
||||
|
||||
// The name of the mutex used to prevent multiple instances of the game from running
|
||||
static constexpr const utf8* SINGLE_INSTANCE_MUTEX_NAME = u8"openrct2.lock";
|
||||
|
|
|
@ -172,7 +172,7 @@ namespace RCT2
|
|||
if (!path.empty())
|
||||
{
|
||||
auto extension = Path::GetExtension(path);
|
||||
_isSV7 = _stricmp(extension.c_str(), ".sv7") == 0;
|
||||
_isSV7 = String::IEquals(extension, ".sv7");
|
||||
}
|
||||
|
||||
chunkReader.ReadChunk(&_s6.Objects, sizeof(_s6.Objects));
|
||||
|
|
|
@ -860,11 +860,11 @@ static uint8_t vehicle_sounds_update_get_pan_volume(OpenRCT2::Audio::VehicleSoun
|
|||
if (pan_y > 0)
|
||||
{
|
||||
pan_y = (0x400 - pan_y) / 4;
|
||||
vol1 = LOBYTE(pan_y);
|
||||
if (static_cast<int8_t>(HIBYTE(pan_y)) != 0)
|
||||
vol1 = LoByte(pan_y);
|
||||
if (static_cast<int8_t>(HiByte(pan_y)) != 0)
|
||||
{
|
||||
vol1 = 0xFF;
|
||||
if (static_cast<int8_t>(HIBYTE(pan_y)) < 0)
|
||||
if (static_cast<int8_t>(HiByte(pan_y)) < 0)
|
||||
{
|
||||
vol1 = 0;
|
||||
}
|
||||
|
@ -878,11 +878,11 @@ static uint8_t vehicle_sounds_update_get_pan_volume(OpenRCT2::Audio::VehicleSoun
|
|||
if (pan_x > 0)
|
||||
{
|
||||
pan_x = (0x400 - pan_x) / 4;
|
||||
vol2 = LOBYTE(pan_x);
|
||||
if (static_cast<int8_t>(HIBYTE(pan_x)) != 0)
|
||||
vol2 = LoByte(pan_x);
|
||||
if (static_cast<int8_t>(HiByte(pan_x)) != 0)
|
||||
{
|
||||
vol2 = 0xFF;
|
||||
if (static_cast<int8_t>(HIBYTE(pan_x)) < 0)
|
||||
if (static_cast<int8_t>(HiByte(pan_x)) < 0)
|
||||
{
|
||||
vol2 = 0;
|
||||
}
|
||||
|
|
|
@ -342,7 +342,7 @@ namespace OpenRCT2::Title
|
|||
|
||||
if (token[0] != 0)
|
||||
{
|
||||
if (_stricmp(token, "LOAD") == 0)
|
||||
if (String::IEquals(token, "LOAD"))
|
||||
{
|
||||
auto saveIndex = SAVE_INDEX_INVALID;
|
||||
const std::string relativePath = parts[1].data();
|
||||
|
@ -356,48 +356,48 @@ namespace OpenRCT2::Title
|
|||
}
|
||||
command = LoadParkCommand{ saveIndex };
|
||||
}
|
||||
else if (_stricmp(token, "LOCATION") == 0)
|
||||
else if (String::IEquals(token, "LOCATION"))
|
||||
{
|
||||
uint8_t locationX = atoi(parts[1].data()) & 0xFF;
|
||||
uint8_t locationY = atoi(parts[2].data()) & 0xFF;
|
||||
command = SetLocationCommand{ locationX, locationY };
|
||||
}
|
||||
else if (_stricmp(token, "ROTATE") == 0)
|
||||
else if (String::IEquals(token, "ROTATE"))
|
||||
{
|
||||
uint8_t rotations = atoi(parts[1].data()) & 0xFF;
|
||||
command = RotateViewCommand{ rotations };
|
||||
}
|
||||
else if (_stricmp(token, "ZOOM") == 0)
|
||||
else if (String::IEquals(token, "ZOOM"))
|
||||
{
|
||||
uint8_t zoom = atoi(parts[1].data()) & 0xFF;
|
||||
command = SetZoomCommand{ zoom };
|
||||
}
|
||||
else if (_stricmp(token, "SPEED") == 0)
|
||||
else if (String::IEquals(token, "SPEED"))
|
||||
{
|
||||
uint8_t speed = std::max(1, std::min(4, atoi(parts[1].data()) & 0xFF));
|
||||
command = SetSpeedCommand{ speed };
|
||||
}
|
||||
else if (_stricmp(token, "FOLLOW") == 0)
|
||||
else if (String::IEquals(token, "FOLLOW"))
|
||||
{
|
||||
auto entityID = EntityId::FromUnderlying(atoi(parts[1].data()) & 0xFFFF);
|
||||
auto followCommand = FollowEntityCommand{ entityID };
|
||||
SafeStrCpy(followCommand.Follow.SpriteName, parts[2].data(), USER_STRING_MAX_LENGTH);
|
||||
command = followCommand;
|
||||
}
|
||||
else if (_stricmp(token, "WAIT") == 0)
|
||||
else if (String::IEquals(token, "WAIT"))
|
||||
{
|
||||
uint16_t milliseconds = atoi(parts[1].data()) & 0xFFFF;
|
||||
command = WaitCommand{ milliseconds };
|
||||
}
|
||||
else if (_stricmp(token, "RESTART") == 0)
|
||||
else if (String::IEquals(token, "RESTART"))
|
||||
{
|
||||
command = RestartCommand{};
|
||||
}
|
||||
else if (_stricmp(token, "END") == 0)
|
||||
else if (String::IEquals(token, "END"))
|
||||
{
|
||||
command = EndCommand{};
|
||||
}
|
||||
else if (_stricmp(token, "LOADSC") == 0)
|
||||
else if (String::IEquals(token, "LOADSC"))
|
||||
{
|
||||
auto loadScenarioCommand = LoadScenarioCommand{};
|
||||
SafeStrCpy(loadScenarioCommand.Scenario, parts[1].data(), sizeof(loadScenarioCommand.Scenario));
|
||||
|
@ -446,12 +446,12 @@ namespace OpenRCT2::Title
|
|||
if (!whitespace)
|
||||
{
|
||||
if (part == 0
|
||||
&& ((cindex == 4 && _strnicmp(parts[0].data(), "LOAD", 4) == 0)
|
||||
|| (cindex == 6 && _strnicmp(parts[0].data(), "LOADSC", 6) == 0)))
|
||||
&& ((cindex == 4 && String::StartsWith(parts[0].data(), "LOAD", true))
|
||||
|| (cindex == 6 && String::StartsWith(parts[0].data(), "LOADSC", true))))
|
||||
{
|
||||
load = true;
|
||||
}
|
||||
else if (part == 0 && cindex == 6 && _strnicmp(parts[0].data(), "FOLLOW", 6) == 0)
|
||||
else if (part == 0 && cindex == 6 && String::StartsWith(parts[0].data(), "FOLLOW", true))
|
||||
{
|
||||
sprite = true;
|
||||
}
|
||||
|
|
|
@ -186,7 +186,7 @@ namespace TitleSequenceManager
|
|||
{
|
||||
return a.PredefinedIndex < b.PredefinedIndex;
|
||||
}
|
||||
return _strcmpi(a.Name.c_str(), b.Name.c_str()) < 0;
|
||||
return String::Compare(a.Name, b.Name, true) < 0;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -68,3 +68,13 @@ template<typename TEnum> constexpr auto EnumValue(TEnum enumerator) noexcept
|
|||
{
|
||||
return static_cast<std::underlying_type_t<TEnum>>(enumerator);
|
||||
}
|
||||
|
||||
constexpr uint8_t HiByte(uint16_t value)
|
||||
{
|
||||
return static_cast<uint8_t>(value >> 8);
|
||||
}
|
||||
|
||||
constexpr uint8_t LoByte(uint16_t value)
|
||||
{
|
||||
return static_cast<uint8_t>(value & 0xFFU);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <openrct2/Game.h>
|
||||
#include <openrct2/OpenRCT2.h>
|
||||
#include <openrct2/ParkImporter.h>
|
||||
#include <openrct2/core/String.hpp>
|
||||
#include <openrct2/platform/Platform.h>
|
||||
#include <openrct2/world/Footpath.h>
|
||||
#include <openrct2/world/Map.h>
|
||||
|
@ -57,7 +58,7 @@ protected:
|
|||
for (auto& ride : GetRideManager())
|
||||
{
|
||||
auto thisName = ride.GetName();
|
||||
if (!_strnicmp(thisName.c_str(), name, sizeof(thisName)))
|
||||
if (String::StartsWith(thisName, u8string{ name }, true))
|
||||
{
|
||||
return &ride;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue