Merge branch 'master' into jgrpp

# Conflicts:
#	os/macosx/notarize.sh
#	src/3rdparty/CMakeLists.txt
#	src/3rdparty/squirrel/squirrel/sqcompiler.cpp
#	src/3rdparty/squirrel/squirrel/sqdebug.cpp
#	src/3rdparty/squirrel/squirrel/sqvm.cpp
#	src/console_cmds.cpp
#	src/core/span_type.hpp
#	src/crashlog.cpp
#	src/currency.h
#	src/date_gui.cpp
#	src/driver.cpp
#	src/fios.cpp
#	src/genworld_gui.cpp
#	src/hotkeys.cpp
#	src/misc_gui.cpp
#	src/music/os2_m.cpp
#	src/network/core/os_abstraction.h
#	src/network/network_server.cpp
#	src/newgrf.cpp
#	src/newgrf_config.h
#	src/newgrf_text.cpp
#	src/openttd.cpp
#	src/os/macosx/font_osx.cpp
#	src/os/macosx/misc_osx.cpp
#	src/os/os2/CMakeLists.txt
#	src/os/os2/os2.cpp
#	src/os/unix/CMakeLists.txt
#	src/os/windows/font_win32.cpp
#	src/os/windows/win32_main.cpp
#	src/saveload/saveload.cpp
#	src/script/api/script_text.cpp
#	src/settings.cpp
#	src/settings_gui.cpp
#	src/stdafx.h
#	src/strings.cpp
#	src/timetable_gui.cpp
#	src/town_gui.cpp
#	src/train_cmd.cpp
#	src/video/dedicated_v.cpp
#	src/video/video_driver.cpp
#	src/video/win32_v.cpp
#	src/viewport.cpp
#	src/waypoint_gui.cpp
#	src/widgets/dropdown_type.h
#	src/window.cpp
#	src/window_gui.h
This commit is contained in:
Jonathan G Rennison
2023-09-12 20:06:47 +01:00
242 changed files with 4733 additions and 6402 deletions

View File

@@ -60,8 +60,7 @@ const byte *MidiGetStandardSysexMessage(MidiSysexMessage msg, size_t &length)
* RAII-compliant to make teardown in error situations easier.
*/
class ByteBuffer {
byte *buf;
size_t buflen;
std::vector<byte> buf;
size_t pos;
public:
/**
@@ -73,31 +72,22 @@ public:
*/
ByteBuffer(FILE *file, size_t len)
{
this->buf = MallocT<byte>(len);
if (fread(this->buf, 1, len, file) == len) {
this->buflen = len;
this->buf.resize(len);
if (fread(this->buf.data(), 1, len, file) == len) {
this->pos = 0;
} else {
/* invalid state */
this->buflen = 0;
this->buf.clear();
}
}
/**
* Destructor, frees the buffer.
*/
~ByteBuffer()
{
free(this->buf);
}
/**
* Return whether the buffer was constructed successfully.
* @return true is the buffer contains data
*/
bool IsValid() const
{
return this->buflen > 0;
return this->buf.size() > 0;
}
/**
@@ -106,7 +96,7 @@ public:
*/
bool IsEnd() const
{
return this->pos >= this->buflen;
return this->pos >= this->buf.size();
}
/**
@@ -149,8 +139,8 @@ public:
bool ReadBuffer(byte *dest, size_t length)
{
if (this->IsEnd()) return false;
if (this->buflen - this->pos < length) return false;
memcpy(dest, this->buf + this->pos, length);
if (this->buf.size() - this->pos < length) return false;
std::copy(std::begin(this->buf) + this->pos, std::begin(this->buf) + this->pos + length, dest);
this->pos += length;
return true;
}
@@ -164,8 +154,8 @@ public:
bool ReadDataBlock(MidiFile::DataBlock *dest, size_t length)
{
if (this->IsEnd()) return false;
if (this->buflen - this->pos < length) return false;
dest->data.insert(dest->data.end(), this->buf + this->pos, this->buf + this->pos + length);
if (this->buf.size() - this->pos < length) return false;
dest->data.insert(dest->data.end(), std::begin(this->buf) + this->pos, std::begin(this->buf) + this->pos + length);
this->pos += length;
return true;
}
@@ -178,7 +168,7 @@ public:
bool Skip(size_t count)
{
if (this->IsEnd()) return false;
if (this->buflen - this->pos < count) return false;
if (this->buf.size() - this->pos < count) return false;
this->pos += count;
return true;
}