1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-16 19:43:06 +01:00

Merge branch 'develop' into HEAD

This commit is contained in:
duncanspumpkin
2021-09-30 13:06:41 +01:00
10 changed files with 60 additions and 54 deletions

View File

@@ -806,6 +806,7 @@
7CDC7EE9B12E40FB9FE78546 /* Crypt.OpenRCT2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4248E4E4394842D4AF6119DA /* Crypt.OpenRCT2.cpp */; };
4653963391E945D397BCCA0C /* ChangeMapSizeAction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76CE81CEAF7F4538976F7C4C /* ChangeMapSizeAction.cpp */; };
F1BE1CB5525C4FF794A3F3CE /* ChangeMapSizeAction.h in Headers */ = {isa = PBXBuildFile; fileRef = C49050C073DB4CB980E1EC5A /* ChangeMapSizeAction.h */; };
B769EFE0AA1149AE93C15DED /* OrcaStream.hpp in Headers */ = {isa = PBXBuildFile; fileRef = F9061C16C67A45D7915FA229 /* OrcaStream.hpp */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -1915,6 +1916,7 @@
4248E4E4394842D4AF6119DA /* Crypt.OpenRCT2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Crypt.OpenRCT2.cpp; path = src/openrct2/core/Crypt.OpenRCT2.cpp; sourceTree = SOURCE_ROOT; };
76CE81CEAF7F4538976F7C4C /* ChangeMapSizeAction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ChangeMapSizeAction.cpp; path = src/openrct2/actions/ChangeMapSizeAction.cpp; sourceTree = SOURCE_ROOT; };
C49050C073DB4CB980E1EC5A /* ChangeMapSizeAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ChangeMapSizeAction.h; path = src/openrct2/actions/ChangeMapSizeAction.h; sourceTree = SOURCE_ROOT; };
F9061C16C67A45D7915FA229 /* OrcaStream.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = OrcaStream.hpp; path = src/openrct2/core/OrcaStream.hpp; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -2571,7 +2573,6 @@
F76C838C1EC4E7CC00FA49E2 /* MemoryStream.cpp */,
F76C838D1EC4E7CC00FA49E2 /* MemoryStream.h */,
2ADE2F24224418B2002598AF /* Meta.hpp */,
F76C838E1EC4E7CC00FA49E2 /* Nullable.hpp */,
2ADE2F23224418B1002598AF /* Numerics.hpp */,
4C8BF07523EDD108002D1F7F /* OrcaStream.hpp */,
F76C838F1EC4E7CC00FA49E2 /* Path.cpp */,
@@ -2592,6 +2593,7 @@
F4D523B8782E4C458AF1490D /* GroupVector.hpp */,
F28A181D311D4E078FDB090C /* ZipStream.hpp */,
4248E4E4394842D4AF6119DA /* Crypt.OpenRCT2.cpp */,
F9061C16C67A45D7915FA229 /* OrcaStream.hpp */,
);
path = core;
sourceTree = "<group>";
@@ -3675,6 +3677,7 @@
C8D612EB56BD4214BEC0F7FF /* GroupVector.hpp in Headers */,
B2F44E535BD14A03BE8B9D14 /* ZipStream.hpp in Headers */,
F1BE1CB5525C4FF794A3F3CE /* ChangeMapSizeAction.h in Headers */,
B769EFE0AA1149AE93C15DED /* OrcaStream.hpp in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -27,6 +27,7 @@
- Fix: [#15255] Tile Inspector shows banner information on walls that do not contain one.
- Fix: [#15257] Chat icon shows in scenario/track editor. Other icons don't disable when deactivated in options menu.
- Fix: [#15289] Unexpected behavior with duplicated banners which also caused desyncs in multiplayer.
- Fix: [#15487] Map animations do not work correctly when loading an exported SV6 file in vanilla RCT2.
- Improved: [#3417] Crash dumps are now placed in their own folder.
- Change: [#8601] Revert ToonTower base block fix to re-enable support blocking.
- Change: [#15174] [Plugin] Deprecate the type "peep" and add support to target a specific scripting api version.

View File

@@ -28,6 +28,7 @@
# include <openrct2/sprites.h>
# include <optional>
# include <string>
# include <utility>
# include <vector>
using namespace OpenRCT2;

View File

@@ -17,7 +17,7 @@
using namespace Crypt;
class OpenRCT2FNV1aAlgorithm : public FNV1aAlgorithm
class OpenRCT2FNV1aAlgorithm final : public FNV1aAlgorithm
{
private:
static constexpr uint64_t Offset = 0xCBF29CE484222325ULL;

View File

@@ -54,9 +54,9 @@ namespace OpenRCT2
}
}
void IStream::WriteString(std::string_view str)
void IStream::WriteString(const std::string_view str)
{
for (auto c : str)
for (const auto c : str)
{
if (c == '\0')
break;

View File

@@ -208,7 +208,7 @@ namespace OpenRCT2
utf8* ReadString();
std::string ReadStdString();
void WriteString(const utf8* str);
void WriteString(std::string_view string);
void WriteString(const std::string_view string);
void WriteString(const std::string& string);
};

View File

@@ -69,7 +69,7 @@ namespace OpenRCT2
ChunkEntry _currentChunk;
public:
OrcaStream(IStream& stream, Mode mode)
OrcaStream(IStream& stream, const Mode mode)
{
_stream = &stream;
_mode = mode;
@@ -121,10 +121,7 @@ namespace OpenRCT2
~OrcaStream()
{
if (_mode == Mode::READING)
{
}
else
if (_mode == Mode::WRITING)
{
const void* uncompressedData = _buffer.GetData();
const uint64_t uncompressedSize = _buffer.GetLength();
@@ -184,7 +181,7 @@ namespace OpenRCT2
return _header;
}
template<typename TFunc> bool ReadWriteChunk(uint32_t chunkId, TFunc f)
template<typename TFunc> bool ReadWriteChunk(const uint32_t chunkId, TFunc f)
{
if (_mode == Mode::READING)
{
@@ -209,12 +206,12 @@ namespace OpenRCT2
}
private:
bool SeekChunk(uint32_t id)
bool SeekChunk(const uint32_t id)
{
auto result = std::find_if(_chunks.begin(), _chunks.end(), [id](const ChunkEntry& e) { return e.Id == id; });
const auto result = std::find_if(_chunks.begin(), _chunks.end(), [id](const ChunkEntry& e) { return e.Id == id; });
if (result != _chunks.end())
{
auto offset = result->Offset;
const auto offset = result->Offset;
_buffer.SetPosition(offset);
return true;
}
@@ -238,7 +235,7 @@ namespace OpenRCT2
std::stack<ArrayState> _arrayStack;
public:
ChunkStream(MemoryStream& buffer, Mode mode)
ChunkStream(MemoryStream& buffer, const Mode mode)
: _buffer(buffer)
, _mode(mode)
{
@@ -254,7 +251,7 @@ namespace OpenRCT2
return _buffer;
}
void ReadWrite(void* addr, size_t len)
void ReadWrite(void* addr, const size_t len)
{
if (_mode == Mode::READING)
{
@@ -266,7 +263,7 @@ namespace OpenRCT2
}
}
void Read(void* addr, size_t len)
void Read(void* addr, const size_t len)
{
if (_mode == Mode::READING)
{
@@ -278,7 +275,7 @@ namespace OpenRCT2
}
}
void Write(const void* addr, size_t len)
void Write(const void* addr, const size_t len)
{
if (_mode == Mode::READING)
{
@@ -404,7 +401,7 @@ namespace OpenRCT2
Write(sv);
}
void Write(const std::string_view& v)
void Write(const std::string_view v)
{
if (_mode == Mode::READING)
{
@@ -426,7 +423,7 @@ namespace OpenRCT2
{
if (_mode == Mode::READING)
{
auto count = BeginArray();
const auto count = BeginArray();
vec.clear();
for (size_t i = 0; i < count; i++)
{
@@ -459,7 +456,7 @@ namespace OpenRCT2
{
if (_mode == Mode::READING)
{
auto count = BeginArray();
const auto count = BeginArray();
for (auto& el : arr)
{
el = {};
@@ -495,12 +492,12 @@ namespace OpenRCT2
}
private:
void ReadBuffer(void* dst, size_t len)
void ReadBuffer(void* dst, const size_t len)
{
_buffer.Read(dst, len);
}
void WriteBuffer(const void* buffer, size_t len)
void WriteBuffer(const void* buffer, const size_t len)
{
_buffer.Write(buffer, len);
}
@@ -509,7 +506,7 @@ namespace OpenRCT2
{
if constexpr (sizeof(T) > 4)
{
if (std::is_signed<T>())
if constexpr (std::is_signed<T>())
{
int64_t raw{};
Read(&raw, sizeof(raw));
@@ -545,11 +542,11 @@ namespace OpenRCT2
}
}
template<typename T, typename = std::enable_if<std::is_integral<T>::value>> void WriteInteger(T value)
template<typename T, typename = std::enable_if<std::is_integral<T>::value>> void WriteInteger(const T value)
{
if constexpr (sizeof(T) > 4)
{
if (std::is_signed<T>())
if constexpr (std::is_signed<T>())
{
auto raw = static_cast<int64_t>(value);
Write(&raw, sizeof(raw));
@@ -562,7 +559,7 @@ namespace OpenRCT2
}
else
{
if (std::is_signed<T>())
if constexpr (std::is_signed<T>())
{
auto raw = static_cast<int32_t>(value);
Write(&raw, sizeof(raw));
@@ -581,9 +578,9 @@ namespace OpenRCT2
buffer.reserve(64);
while (true)
{
char c;
char c{};
ReadBuffer(&c, sizeof(c));
if (c == 0)
if (c == '\0')
{
break;
}
@@ -593,9 +590,9 @@ namespace OpenRCT2
return buffer;
}
void WriteString(const std::string_view& s)
void WriteString(const std::string_view s)
{
char nullt = '\0';
const char nullt = '\0';
auto len = s.find('\0');
if (len == std::string_view::npos)
{
@@ -643,7 +640,7 @@ namespace OpenRCT2
return arrayState.Count == 0;
}
auto lastElSize = static_cast<size_t>(_buffer.GetPosition()) - arrayState.LastPos;
const auto lastElSize = static_cast<size_t>(_buffer.GetPosition()) - arrayState.LastPos;
if (arrayState.Count == 0)
{
// Set array element size based on first element size
@@ -663,12 +660,9 @@ namespace OpenRCT2
void EndArray()
{
auto& arrayState = _arrayStack.top();
if (_mode == Mode::READING)
if (_mode == Mode::WRITING)
{
}
else
{
size_t backupPos = _buffer.GetPosition();
const size_t backupPos = _buffer.GetPosition();
if (backupPos != static_cast<size_t>(arrayState.StartPos) + 8 && arrayState.Count == 0)
{
throw std::runtime_error("Array data was written but no elements were added.");

View File

@@ -177,6 +177,7 @@
<ClInclude Include="core\MemoryStream.h" />
<ClInclude Include="core\Meta.hpp" />
<ClInclude Include="core\Numerics.hpp" />
<ClInclude Include="core\OrcaStream.hpp" />
<ClInclude Include="core\Path.hpp" />
<ClInclude Include="core\Random.hpp" />
<ClInclude Include="core\RTL.h" />

View File

@@ -693,7 +693,7 @@ bool util_gzip_compress(FILE* source, FILE* dest)
return true;
}
std::vector<uint8_t> Gzip(const void* data, size_t dataLen)
std::vector<uint8_t> Gzip(const void* data, const size_t dataLen)
{
assert(data != nullptr);
@@ -702,18 +702,21 @@ std::vector<uint8_t> Gzip(const void* data, size_t dataLen)
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
auto ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 | 16, 8, Z_DEFAULT_STRATEGY);
if (ret != Z_OK)
{
throw std::runtime_error("deflateInit2 failed with error " + std::to_string(ret));
const auto ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 | 16, 8, Z_DEFAULT_STRATEGY);
if (ret != Z_OK)
{
throw std::runtime_error("deflateInit2 failed with error " + std::to_string(ret));
}
}
int flush;
int flush = 0;
const auto* src = static_cast<const Bytef*>(data);
size_t srcRemaining = dataLen;
do
{
auto nextBlockSize = std::min(srcRemaining, CHUNK);
const auto nextBlockSize = std::min(srcRemaining, CHUNK);
srcRemaining -= nextBlockSize;
flush = srcRemaining == 0 ? Z_FINISH : Z_NO_FLUSH;
@@ -724,7 +727,7 @@ std::vector<uint8_t> Gzip(const void* data, size_t dataLen)
output.resize(output.size() + nextBlockSize);
strm.avail_out = static_cast<uInt>(nextBlockSize);
strm.next_out = &output[output.size() - nextBlockSize];
ret = deflate(&strm, flush);
const auto ret = deflate(&strm, flush);
if (ret == Z_STREAM_ERROR)
{
throw std::runtime_error("deflate failed with error " + std::to_string(ret));
@@ -738,7 +741,7 @@ std::vector<uint8_t> Gzip(const void* data, size_t dataLen)
return output;
}
std::vector<uint8_t> Ungzip(const void* data, size_t dataLen)
std::vector<uint8_t> Ungzip(const void* data, const size_t dataLen)
{
assert(data != nullptr);
@@ -747,18 +750,21 @@ std::vector<uint8_t> Ungzip(const void* data, size_t dataLen)
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
auto ret = inflateInit2(&strm, 15 | 16);
if (ret != Z_OK)
{
throw std::runtime_error("inflateInit2 failed with error " + std::to_string(ret));
const auto ret = inflateInit2(&strm, 15 | 16);
if (ret != Z_OK)
{
throw std::runtime_error("inflateInit2 failed with error " + std::to_string(ret));
}
}
int flush;
int flush = 0;
const auto* src = static_cast<const Bytef*>(data);
size_t srcRemaining = dataLen;
do
{
auto nextBlockSize = std::min(srcRemaining, CHUNK);
const auto nextBlockSize = std::min(srcRemaining, CHUNK);
srcRemaining -= nextBlockSize;
flush = srcRemaining == 0 ? Z_FINISH : Z_NO_FLUSH;
@@ -769,7 +775,7 @@ std::vector<uint8_t> Ungzip(const void* data, size_t dataLen)
output.resize(output.size() + nextBlockSize);
strm.avail_out = static_cast<uInt>(nextBlockSize);
strm.next_out = &output[output.size() - nextBlockSize];
ret = inflate(&strm, flush);
const auto ret = inflate(&strm, flush);
if (ret == Z_STREAM_ERROR)
{
throw std::runtime_error("deflate failed with error " + std::to_string(ret));
@@ -779,7 +785,7 @@ std::vector<uint8_t> Ungzip(const void* data, size_t dataLen)
src += nextBlockSize;
} while (flush != Z_FINISH);
deflateEnd(&strm);
inflateEnd(&strm);
return output;
}

View File

@@ -58,8 +58,8 @@ uint32_t util_rand();
std::optional<std::vector<uint8_t>> util_zlib_deflate(const uint8_t* data, size_t data_in_size);
uint8_t* util_zlib_inflate(const uint8_t* data, size_t data_in_size, size_t* data_out_size);
bool util_gzip_compress(FILE* source, FILE* dest);
std::vector<uint8_t> Gzip(const void* data, size_t dataLen);
std::vector<uint8_t> Ungzip(const void* data, size_t dataLen);
std::vector<uint8_t> Gzip(const void* data, const size_t dataLen);
std::vector<uint8_t> Ungzip(const void* data, const size_t dataLen);
int8_t add_clamp_int8_t(int8_t value, int8_t value_to_add);
int16_t add_clamp_int16_t(int16_t value, int16_t value_to_add);