Merge branch 'master' into jgrpp

Remove 'byte' typedef
This commit is contained in:
Jonathan G Rennison
2024-05-07 17:21:50 +01:00
376 changed files with 2220 additions and 2152 deletions

View File

@@ -653,7 +653,7 @@ static void Save_PLYP()
return;
}
std::vector<byte> buffer = SlSaveToVector([]() {
std::vector<uint8_t> buffer = SlSaveToVector([]() {
SlWriteUint32((uint32_t)_network_company_server_id.size());
MemoryDumper::GetCurrent()->CopyBytes((const uint8_t *)_network_company_server_id.data(), _network_company_server_id.size());

View File

@@ -22,7 +22,7 @@ static void Save_DBGL()
if (_savegame_DBGL_data != nullptr) {
size_t length = strlen(_savegame_DBGL_data);
SlSetLength(length);
MemoryDumper::GetCurrent()->CopyBytes(reinterpret_cast<const byte *>(_savegame_DBGL_data), length);
MemoryDumper::GetCurrent()->CopyBytes(reinterpret_cast<const uint8_t *>(_savegame_DBGL_data), length);
} else {
SlSetLength(0);
}
@@ -33,7 +33,7 @@ static void Load_DBGL()
size_t length = SlGetFieldLength();
if (length) {
_loadgame_DBGL_data.resize(length);
ReadBuffer::GetCurrent()->CopyBytes(reinterpret_cast<byte *>(_loadgame_DBGL_data.data()), length);
ReadBuffer::GetCurrent()->CopyBytes(reinterpret_cast<uint8_t *>(_loadgame_DBGL_data.data()), length);
}
}
@@ -46,7 +46,7 @@ static void Check_DBGL()
size_t length = SlGetFieldLength();
if (length) {
_load_check_data.debug_log_data.resize(length);
ReadBuffer::GetCurrent()->CopyBytes(reinterpret_cast<byte *>(_load_check_data.debug_log_data.data()), length);
ReadBuffer::GetCurrent()->CopyBytes(reinterpret_cast<uint8_t *>(_load_check_data.debug_log_data.data()), length);
}
}
@@ -57,9 +57,9 @@ static void Save_DBGC()
const char footer[] = "*** openttd.cfg end ***\n";
if (_save_DBGC_data) {
SlSetLength(lengthof(header) + _config_file_text.size() + lengthof(footer) - 2);
MemoryDumper::GetCurrent()->CopyBytes(reinterpret_cast<const byte *>(header), lengthof(header) - 1);
MemoryDumper::GetCurrent()->CopyBytes(reinterpret_cast<const byte *>(_config_file_text.data()), _config_file_text.size());
MemoryDumper::GetCurrent()->CopyBytes(reinterpret_cast<const byte *>(footer), lengthof(footer) - 1);
MemoryDumper::GetCurrent()->CopyBytes(reinterpret_cast<const uint8_t *>(header), lengthof(header) - 1);
MemoryDumper::GetCurrent()->CopyBytes(reinterpret_cast<const uint8_t *>(_config_file_text.data()), _config_file_text.size());
MemoryDumper::GetCurrent()->CopyBytes(reinterpret_cast<const uint8_t *>(footer), lengthof(footer) - 1);
} else {
SlSetLength(0);
}
@@ -70,7 +70,7 @@ static void Load_DBGC()
size_t length = SlGetFieldLength();
if (length) {
_loadgame_DBGC_data.resize(length);
ReadBuffer::GetCurrent()->CopyBytes(reinterpret_cast<byte *>(_loadgame_DBGC_data.data()), length);
ReadBuffer::GetCurrent()->CopyBytes(reinterpret_cast<uint8_t *>(_loadgame_DBGC_data.data()), length);
}
}
@@ -83,7 +83,7 @@ static void Check_DBGC()
size_t length = SlGetFieldLength();
if (length) {
_load_check_data.debug_config_data.resize(length);
ReadBuffer::GetCurrent()->CopyBytes(reinterpret_cast<byte *>(_load_check_data.debug_config_data.data()), length);
ReadBuffer::GetCurrent()->CopyBytes(reinterpret_cast<uint8_t *>(_load_check_data.debug_config_data.data()), length);
}
}

View File

@@ -730,14 +730,14 @@ static void IgnoreWrongLengthExtraData(const SlxiSubChunkInfo *info, uint32_t le
static void loadVL(const SlxiSubChunkInfo *info, uint32_t length)
{
_sl_xv_version_label.resize(length);
ReadBuffer::GetCurrent()->CopyBytes(reinterpret_cast<byte *>(_sl_xv_version_label.data()), length);
ReadBuffer::GetCurrent()->CopyBytes(reinterpret_cast<uint8_t *>(_sl_xv_version_label.data()), length);
DEBUG(sl, 2, "SLXI version label: %s", _sl_xv_version_label.c_str());
}
static uint32_t saveVL(const SlxiSubChunkInfo *info, bool dry_run)
{
const size_t length = strlen(_openttd_revision);
if (!dry_run) MemoryDumper::GetCurrent()->CopyBytes(reinterpret_cast<const byte *>(_openttd_revision), length);
if (!dry_run) MemoryDumper::GetCurrent()->CopyBytes(reinterpret_cast<const uint8_t *>(_openttd_revision), length);
return static_cast<uint32_t>(length);
}

View File

@@ -101,7 +101,7 @@ static void Load_GLOG_common(std::vector<LoggedAction> &gamelog_actions)
{
assert(gamelog_actions.empty());
byte type;
uint8_t type;
while ((type = SlReadByte()) != GLAT_NONE) {
if (type >= GLAT_END) SlErrorCorrupt("Invalid gamelog action type");
GamelogActionType at = (GamelogActionType)type;

View File

@@ -58,7 +58,7 @@ static const uint MAP_SL_BUF_SIZE = 4096;
static void Load_MAPT()
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
for (TileIndex i = 0; i != size;) {
@@ -99,7 +99,7 @@ static void Load_MAPH()
return;
}
std::array<byte, MAP_SL_BUF_SIZE> buf;
std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
for (TileIndex i = 0; i != size;) {
@@ -110,7 +110,7 @@ static void Load_MAPH()
static void Load_MAP1()
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
for (TileIndex i = 0; i != size;) {
@@ -135,7 +135,7 @@ static void Load_MAP2()
static void Load_MAP3()
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
for (TileIndex i = 0; i != size;) {
@@ -146,7 +146,7 @@ static void Load_MAP3()
static void Load_MAP4()
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
for (TileIndex i = 0; i != size;) {
@@ -157,7 +157,7 @@ static void Load_MAP4()
static void Load_MAP5()
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
for (TileIndex i = 0; i != size;) {
@@ -168,7 +168,7 @@ static void Load_MAP5()
static void Load_MAP6()
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
if (IsSavegameVersionBefore(SLV_42)) {
@@ -192,7 +192,7 @@ static void Load_MAP6()
static void Load_MAP7()
{
std::array<byte, MAP_SL_BUF_SIZE> buf;
std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
TileIndex size = MapSize();
for (TileIndex i = 0; i != size;) {
@@ -222,7 +222,7 @@ static void Load_WMAP()
const TileIndex size = MapSize();
#if TTD_ENDIAN == TTD_LITTLE_ENDIAN
reader->CopyBytes((byte *) _m, size * 8);
reader->CopyBytes((uint8_t *) _m, size * 8);
#else
for (TileIndex i = 0; i != size; i++) {
reader->CheckBytes(8);
@@ -246,7 +246,7 @@ static void Load_WMAP()
}
} else if (_sl_xv_feature_versions[XSLFI_WHOLE_MAP_CHUNK] == 2) {
#if TTD_ENDIAN == TTD_LITTLE_ENDIAN
reader->CopyBytes((byte *) _me, size * 4);
reader->CopyBytes((uint8_t *) _me, size * 4);
#else
for (TileIndex i = 0; i != size; i++) {
reader->CheckBytes(4);
@@ -273,8 +273,8 @@ static void Save_WMAP()
SlSetLength(size * 12);
#if TTD_ENDIAN == TTD_LITTLE_ENDIAN
dumper->CopyBytes((byte *) _m, size * 8);
dumper->CopyBytes((byte *) _me, size * 4);
dumper->CopyBytes((uint8_t *) _m, size * 8);
dumper->CopyBytes((uint8_t *) _me, size * 4);
#else
for (TileIndex i = 0; i != size; i++) {
dumper->CheckBytes(8);

View File

@@ -30,7 +30,7 @@
extern TileIndex _cur_tileloop_tile;
extern TileIndex _aux_tileloop_tile;
extern uint16_t _disaster_delay;
extern byte _trees_tick_ctr;
extern uint8_t _trees_tick_ctr;
extern uint64_t _aspect_cfg_hash;
/* Keep track of current game position */
@@ -79,7 +79,7 @@ void ResetViewportAfterLoadGame()
MarkWholeScreenDirty();
}
byte _age_cargo_skip_counter; ///< Skip aging of cargo? Used before savegame version 162.
uint8_t _age_cargo_skip_counter; ///< Skip aging of cargo? Used before savegame version 162.
extern TimeoutTimer<TimerGameTick> _new_competitor_timeout;
static const NamedSaveLoad _date_desc[] = {

View File

@@ -33,10 +33,10 @@ static inline OldChunkType GetOldChunkType(OldChunkType type) {return (OldCh
static inline OldChunkType GetOldChunkVarType(OldChunkType type) {return (OldChunkType)(GB(type, 8, 8) << 8);}
static inline OldChunkType GetOldChunkFileType(OldChunkType type) {return (OldChunkType)(GB(type, 16, 8) << 16);}
static inline byte CalcOldVarLen(OldChunkType type)
static inline uint8_t CalcOldVarLen(OldChunkType type)
{
static const byte type_mem_size[] = {0, 1, 1, 2, 2, 4, 4, 8};
byte length = GB(type, 8, 8);
static const uint8_t type_mem_size[] = {0, 1, 1, 2, 2, 4, 4, 8};
uint8_t length = GB(type, 8, 8);
assert(length != 0 && length < lengthof(type_mem_size));
return type_mem_size[length];
}
@@ -46,7 +46,7 @@ static inline byte CalcOldVarLen(OldChunkType type)
* Reads a byte from a file (do not call yourself, use ReadByte())
*
*/
static byte ReadByteFromFile(LoadgameState *ls)
static uint8_t ReadByteFromFile(LoadgameState *ls)
{
/* To avoid slow reads, we read BUFFER_SIZE of bytes per time
and just return a byte per time */
@@ -73,7 +73,7 @@ static byte ReadByteFromFile(LoadgameState *ls)
* Reads a byte from the buffer and decompress if needed
*
*/
byte ReadByte(LoadgameState *ls)
uint8_t ReadByte(LoadgameState *ls)
{
/* Old savegames have a nice compression algorithm (RLE)
which means that we have a chunk, which starts with a length
@@ -109,7 +109,7 @@ byte ReadByte(LoadgameState *ls)
*/
bool LoadChunk(LoadgameState *ls, void *base, const OldChunks *chunks)
{
byte *base_ptr = (byte*)base;
uint8_t *base_ptr = (uint8_t*)base;
for (const OldChunks *chunk = chunks; chunk->type != OC_END; chunk++) {
if (((chunk->type & OC_TTD) && _savegame_type == SGT_TTO) ||
@@ -118,8 +118,8 @@ bool LoadChunk(LoadgameState *ls, void *base, const OldChunks *chunks)
continue;
}
byte *ptr = (byte*)chunk->ptr;
if (chunk->type & OC_DEREFERENCE_POINTER) ptr = *(byte**)ptr;
uint8_t *ptr = (uint8_t*)chunk->ptr;
if (chunk->type & OC_DEREFERENCE_POINTER) ptr = *(uint8_t**)ptr;
for (uint i = 0; i < chunk->amount; i++) {
/* Handle simple types */

View File

@@ -22,11 +22,11 @@ struct LoadgameState {
uint chunk_size;
bool decoding;
byte decode_char;
uint8_t decode_char;
uint buffer_count;
uint buffer_cur;
byte buffer[BUFFER_SIZE];
uint8_t buffer[BUFFER_SIZE];
uint total_read;
};
@@ -96,7 +96,7 @@ struct OldChunks {
static_assert(sizeof(TileIndex) == 4);
extern uint _bump_assert_value;
byte ReadByte(LoadgameState *ls);
uint8_t ReadByte(LoadgameState *ls);
bool LoadChunk(LoadgameState *ls, void *base, const OldChunks *chunks);
bool LoadTTDMain(LoadgameState *ls);
@@ -104,7 +104,7 @@ bool LoadTTOMain(LoadgameState *ls);
inline uint16_t ReadUint16(LoadgameState *ls)
{
byte x = ReadByte(ls);
uint8_t x = ReadByte(ls);
return x | ReadByte(ls) << 8;
}

View File

@@ -42,7 +42,7 @@
static bool _read_ttdpatch_flags; ///< Have we (tried to) read TTDPatch extra flags?
static uint16_t _old_extra_chunk_nums; ///< Number of extra TTDPatch chunks
static byte _old_vehicle_multiplier; ///< TTDPatch vehicle multiplier
static uint8_t _old_vehicle_multiplier; ///< TTDPatch vehicle multiplier
void FixOldMapArray()
{
@@ -112,7 +112,7 @@ static void FixTTDDepots()
#define FIXNUM(x, y, z) (((((x) << 16) / (y)) + 1) << z)
static uint32_t RemapOldTownName(uint32_t townnameparts, byte old_town_name_type)
static uint32_t RemapOldTownName(uint32_t townnameparts, uint8_t old_town_name_type)
{
switch (old_town_name_type) {
case 0: case 3: // English, American
@@ -304,7 +304,7 @@ static bool FixTTOMapArray()
case MP_TUNNELBRIDGE:
if (HasBit(_m[t].m5, 7)) { // bridge
byte m5 = _m[t].m5;
uint8_t m5 = _m[t].m5;
_m[t].m5 = m5 & 0xE1; // copy bits 7..5, 1
if (GB(m5, 1, 2) == 1) _m[t].m5 |= 0x02; // road bridge
if (GB(m5, 1, 2) == 3) _m[t].m2 |= 0xA0; // monorail bridge -> tubular, steel bridge
@@ -1284,7 +1284,7 @@ bool LoadOldVehicle(LoadgameState *ls, int num)
switch (v->type) {
case VEH_TRAIN: {
static const byte spriteset_rail[] = {
static const uint8_t spriteset_rail[] = {
0, 2, 4, 4, 8, 10, 12, 14, 16, 18, 20, 22, 40, 42, 44, 46,
48, 52, 54, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 120, 122,
124, 126, 128, 130, 132, 134, 136, 138, 140
@@ -1511,7 +1511,7 @@ static bool LoadOldMapPart1(LoadgameState *ls, int)
_m[i].m4 = ReadByte(ls);
}
for (uint i = 0; i < OLD_MAP_SIZE / 4; i++) {
byte b = ReadByte(ls);
uint8_t b = ReadByte(ls);
_me[i * 4 + 0].m6 = GB(b, 0, 2);
_me[i * 4 + 1].m6 = GB(b, 2, 2);
_me[i * 4 + 2].m6 = GB(b, 4, 2);
@@ -1594,8 +1594,8 @@ static bool LoadTTDPatchExtraChunks(LoadgameState *ls, int)
extern TileIndex _cur_tileloop_tile;
extern uint16_t _disaster_delay;
extern byte _trees_tick_ctr;
extern byte _age_cargo_skip_counter; // From misc_sl.cpp
extern uint8_t _trees_tick_ctr;
extern uint8_t _age_cargo_skip_counter; // From misc_sl.cpp
extern uint8_t _old_diff_level;
extern uint8_t _old_units;
static const OldChunks main_chunk[] = {
@@ -1816,7 +1816,7 @@ bool LoadTTOMain(LoadgameState *ls)
_read_ttdpatch_flags = false;
std::array<byte, 103 * sizeof(Engine)> engines; // we don't want to call Engine constructor here
std::array<uint8_t, 103 * sizeof(Engine)> engines; // we don't want to call Engine constructor here
_old_engines = (Engine *)engines.data();
std::array<StringID, 800> vehnames;
_old_vehicle_names = vehnames.data();

View File

@@ -86,7 +86,7 @@ FileToSaveLoad _file_to_saveload; ///< File to save or load in the openttd loop.
uint32_t _ttdp_version; ///< version of TTDP savegame (if applicable)
SaveLoadVersion _sl_version; ///< the major savegame version identifier
byte _sl_minor_version; ///< the minor savegame version, DO NOT USE!
uint8_t _sl_minor_version; ///< the minor savegame version, DO NOT USE!
std::string _savegame_format; ///< how to compress savegames
bool _do_autosave; ///< are we doing an autosave at the moment?
@@ -169,14 +169,14 @@ void MemoryDumper::AllocateBuffer()
if (this->saved_buf) {
const size_t offset = this->buf - this->autolen_buf;
const size_t size = (this->autolen_buf_end - this->autolen_buf) * 2;
this->autolen_buf = ReallocT<byte>(this->autolen_buf, size);
this->autolen_buf = ReallocT<uint8_t>(this->autolen_buf, size);
this->autolen_buf_end = this->autolen_buf + size;
this->buf = this->autolen_buf + offset;
this->bufe = this->autolen_buf_end;
return;
}
this->FinaliseBlock();
this->buf = MallocT<byte>(MEMORY_CHUNK_SIZE);
this->buf = MallocT<uint8_t>(MEMORY_CHUNK_SIZE);
this->blocks.emplace_back(this->buf);
this->bufe = this->buf + MEMORY_CHUNK_SIZE;
}
@@ -209,7 +209,7 @@ void MemoryDumper::StartAutoLength()
this->bufe = this->autolen_buf_end;
}
std::span<byte> MemoryDumper::StopAutoLength()
std::span<uint8_t> MemoryDumper::StopAutoLength()
{
assert(this->saved_buf != nullptr);
auto res = std::span(this->autolen_buf, this->buf - this->autolen_buf);
@@ -238,7 +238,7 @@ enum SaveLoadBlockFlags {
struct SaveLoadParams {
SaveLoadAction action; ///< are we doing a save or a load atm.
NeedLength need_length; ///< working in NeedLength (Autolength) mode?
byte block_mode; ///< ???
uint8_t block_mode; ///< ???
uint8_t block_flags; ///< block flags: SaveLoadBlockFlags
bool error; ///< did an error occur or not
@@ -248,7 +248,7 @@ struct SaveLoadParams {
uint32_t current_chunk_id; ///< Current chunk ID
btree::btree_map<uint32_t, byte> chunk_block_modes; ///< Chunk block modes
btree::btree_map<uint32_t, uint8_t> chunk_block_modes; ///< Chunk block modes
std::unique_ptr<MemoryDumper> dumper;///< Memory dumper to write the savegame to.
std::shared_ptr<SaveFilter> sf; ///< Filter to write the savegame to.
@@ -580,10 +580,10 @@ void ProcessAsyncSaveFinish()
}
/**
* Wrapper for reading a byte from the buffer.
* @return The read byte.
* Wrapper for reading a uint8_t from the buffer.
* @return The read uint8_t.
*/
byte SlReadByte()
uint8_t SlReadByte()
{
return _sl.reader->ReadByte();
}
@@ -617,10 +617,10 @@ uint64_t SlReadUint64()
}
/**
* Wrapper for writing a byte to the dumper.
* @param b The byte to write.
* Wrapper for writing a uint8_t to the dumper.
* @param b The uint8_t to write.
*/
void SlWriteByte(byte b)
void SlWriteByte(uint8_t b)
{
_sl.dumper->WriteByte(b);
}
@@ -721,21 +721,21 @@ static void SlWriteSimpleGamma(size_t i)
if (i >= (1 << 21)) {
if (i >= (1 << 28)) {
assert(i <= UINT32_MAX); // We can only support 32 bits for now.
SlWriteByte((byte)(0xF0));
SlWriteByte((byte)(i >> 24));
SlWriteByte((uint8_t)(0xF0));
SlWriteByte((uint8_t)(i >> 24));
} else {
SlWriteByte((byte)(0xE0 | (i >> 24)));
SlWriteByte((uint8_t)(0xE0 | (i >> 24)));
}
SlWriteByte((byte)(i >> 16));
SlWriteByte((uint8_t)(i >> 16));
} else {
SlWriteByte((byte)(0xC0 | (i >> 16)));
SlWriteByte((uint8_t)(0xC0 | (i >> 16)));
}
SlWriteByte((byte)(i >> 8));
SlWriteByte((uint8_t)(i >> 8));
} else {
SlWriteByte((byte)(0x80 | (i >> 8)));
SlWriteByte((uint8_t)(0x80 | (i >> 8)));
}
}
SlWriteByte((byte)i);
SlWriteByte((uint8_t)i);
}
/** Return how many bytes used to encode a gamma value */
@@ -777,7 +777,7 @@ static inline uint SlGetArrayLength(size_t length)
*/
static inline uint SlCalcConvMemLen(VarType conv)
{
static const byte conv_mem_size[] = {1, 1, 1, 2, 2, 4, 4, 8, 8, 0};
static const uint8_t conv_mem_size[] = {1, 1, 1, 2, 2, 4, 4, 8, 8, 0};
switch (GetVarMemType(conv)) {
case SLE_VAR_STRB:
@@ -798,11 +798,11 @@ static inline uint SlCalcConvMemLen(VarType conv)
* @param conv VarType type of variable that is used for calculating the size
* @return Return the size of this type in bytes
*/
static inline byte SlCalcConvFileLen(VarType conv)
static inline uint8_t SlCalcConvFileLen(VarType conv)
{
uint8_t type = GetVarFileType(conv);
if (type == SLE_FILE_VEHORDERID) return SlXvIsFeaturePresent(XSLFI_MORE_VEHICLE_ORDERS) ? 2 : 1;
static const byte conv_file_size[] = {0, 1, 1, 2, 2, 4, 4, 8, 8, 2};
static const uint8_t conv_file_size[] = {0, 1, 1, 2, 2, 4, 4, 8, 8, 2};
assert(type < lengthof(conv_file_size));
return conv_file_size[type];
}
@@ -948,7 +948,7 @@ void SlSetLength(size_t length)
*/
static void SlCopyBytes(void *ptr, size_t length)
{
byte *p = (byte *)ptr;
uint8_t *p = (uint8_t *)ptr;
switch (_sl.action) {
case SLA_LOAD_CHECK:
@@ -964,12 +964,12 @@ static void SlCopyBytes(void *ptr, size_t length)
void SlCopyBytesRead(void *p, size_t length)
{
_sl.reader->CopyBytes((byte *)p, length);
_sl.reader->CopyBytes((uint8_t *)p, length);
}
void SlCopyBytesWrite(void *p, size_t length)
{
_sl.dumper->CopyBytes((byte *)p, length);
_sl.dumper->CopyBytes((uint8_t *)p, length);
}
/** Get the length of the current object */
@@ -990,7 +990,7 @@ int64_t ReadValue(const void *ptr, VarType conv)
switch (GetVarMemType(conv)) {
case SLE_VAR_BL: return (*(const bool *)ptr != 0);
case SLE_VAR_I8: return *(const int8_t *)ptr;
case SLE_VAR_U8: return *(const byte *)ptr;
case SLE_VAR_U8: return *(const uint8_t *)ptr;
case SLE_VAR_I16: return *(const int16_t *)ptr;
case SLE_VAR_U16: return *(const uint16_t*)ptr;
case SLE_VAR_I32: return *(const int32_t *)ptr;
@@ -1014,7 +1014,7 @@ void WriteValue(void *ptr, VarType conv, int64_t val)
switch (GetVarMemType(conv)) {
case SLE_VAR_BL: *(bool *)ptr = (val != 0); break;
case SLE_VAR_I8: *(int8_t *)ptr = val; break;
case SLE_VAR_U8: *(byte *)ptr = val; break;
case SLE_VAR_U8: *(uint8_t *)ptr = val; break;
case SLE_VAR_I16: *(int16_t *)ptr = val; break;
case SLE_VAR_U16: *(uint16_t*)ptr = val; break;
case SLE_VAR_I32: *(int32_t *)ptr = val; break;
@@ -1065,7 +1065,7 @@ static void SlSaveLoadConvGeneric(void *ptr, VarType conv)
/* Read a value from the file */
switch (GetVarFileType(conv)) {
case SLE_FILE_I8: x = (int8_t )SlReadByte(); break;
case SLE_FILE_U8: x = (byte )SlReadByte(); break;
case SLE_FILE_U8: x = (uint8_t )SlReadByte(); break;
case SLE_FILE_I16: x = (int16_t )SlReadUint16(); break;
case SLE_FILE_U16: x = (uint16_t)SlReadUint16(); break;
case SLE_FILE_I32: x = (int32_t )SlReadUint32(); break;
@@ -1077,7 +1077,7 @@ static void SlSaveLoadConvGeneric(void *ptr, VarType conv)
if (SlXvIsFeaturePresent(XSLFI_MORE_VEHICLE_ORDERS)) {
x = (uint16_t)SlReadUint16();
} else {
VehicleOrderID id = (byte)SlReadByte();
VehicleOrderID id = (uint8_t)SlReadByte();
x = (id == 0xFF) ? INVALID_VEH_ORDER_ID : id;
}
break;
@@ -1307,7 +1307,7 @@ static inline size_t SlCalcArrayLen(size_t length, VarType conv)
* Save/Load an array.
* @param array The array being manipulated
* @param length The length of the array in elements
* @param conv VarType type of the atomic array (int, byte, uint64_t, etc.)
* @param conv VarType type of the atomic array (int, uint8_t, uint64_t, etc.)
*/
void SlArray(void *array, size_t length, VarType conv)
{
@@ -1371,8 +1371,8 @@ void SlArray(void *array, size_t length, VarType conv)
if (conv == SLE_INT8 || conv == SLE_UINT8) {
SlCopyBytes(array, length);
} else {
byte *a = (byte*)array;
byte mem_size = SlCalcConvMemLen(conv);
uint8_t *a = (uint8_t*)array;
uint8_t mem_size = SlCalcConvMemLen(conv);
for (; length != 0; length --) {
SlSaveLoadConv(a, conv);
@@ -1837,7 +1837,7 @@ size_t SlCalcObjMemberLength(const void *object, const SaveLoad &sld)
case SL_VARVEC: {
const size_t size_len = SlCalcConvMemLen(sld.conv);
switch (size_len) {
case 1: return SlCalcVarListLen<std::vector<byte>>(GetVariableAddress(object, sld), 1);
case 1: return SlCalcVarListLen<std::vector<uint8_t>>(GetVariableAddress(object, sld), 1);
case 2: return SlCalcVarListLen<std::vector<uint16_t>>(GetVariableAddress(object, sld), 2);
case 4: return SlCalcVarListLen<std::vector<uint32_t>>(GetVariableAddress(object, sld), 4);
case 8: return SlCalcVarListLen<std::vector<uint64_t>>(GetVariableAddress(object, sld), 8);
@@ -1848,7 +1848,7 @@ size_t SlCalcObjMemberLength(const void *object, const SaveLoad &sld)
default: NOT_REACHED();
}
break;
case SL_WRITEBYTE: return 1; // a byte is logically of size 1
case SL_WRITEBYTE: return 1; // a uint8_t is logically of size 1
case SL_VEH_INCLUDE: return SlCalcObjLength(object, GetVehicleDescription(VEH_END));
case SL_ST_INCLUDE: return SlCalcObjLength(object, GetBaseStationDescription());
default: NOT_REACHED();
@@ -1984,7 +1984,7 @@ bool SlObjectMemberGeneric(void *object, const SaveLoad &sld)
case SL_VARVEC: {
const size_t size_len = SlCalcConvMemLen(sld.conv);
switch (size_len) {
case 1: SlVarList<std::vector<byte>>(ptr, conv); break;
case 1: SlVarList<std::vector<uint8_t>>(ptr, conv); break;
case 2: SlVarList<std::vector<uint16_t>>(ptr, conv); break;
case 4: SlVarList<std::vector<uint32_t>>(ptr, conv); break;
case 8: SlVarList<std::vector<uint64_t>>(ptr, conv); break;
@@ -2366,7 +2366,7 @@ uint8_t SlSaveToTempBufferSetup()
return (uint8_t) orig_need_length;
}
std::span<byte> SlSaveToTempBufferRestore(uint8_t state)
std::span<uint8_t> SlSaveToTempBufferRestore(uint8_t state)
{
NeedLength orig_need_length = (NeedLength)state;
@@ -2396,7 +2396,7 @@ extern void SlConditionallySaveCompletion(const SlConditionallySaveState &state,
}
}
SlLoadFromBufferState SlLoadFromBufferSetup(const byte *buffer, size_t length)
SlLoadFromBufferState SlLoadFromBufferSetup(const uint8_t *buffer, size_t length)
{
assert(_sl.action == SLA_LOAD || _sl.action == SLA_LOAD_CHECK);
@@ -2408,13 +2408,13 @@ SlLoadFromBufferState SlLoadFromBufferSetup(const byte *buffer, size_t length)
ReadBuffer *reader = ReadBuffer::GetCurrent();
state.old_bufp = reader->bufp;
state.old_bufe = reader->bufe;
reader->bufp = const_cast<byte *>(buffer);
reader->bufe = const_cast<byte *>(buffer) + length;
reader->bufp = const_cast<uint8_t *>(buffer);
reader->bufe = const_cast<uint8_t *>(buffer) + length;
return state;
}
void SlLoadFromBufferRestore(const SlLoadFromBufferState &state, const byte *buffer, size_t length)
void SlLoadFromBufferRestore(const SlLoadFromBufferState &state, const uint8_t *buffer, size_t length)
{
ReadBuffer *reader = ReadBuffer::GetCurrent();
if (reader->bufp != reader->bufe || reader->bufe != buffer + length) {
@@ -2463,7 +2463,7 @@ static void SlLoadChunk(const ChunkHandler &ch)
DEBUG(sl, 2, "Loading chunk %s", ChunkIDDumper()(ch.id));
byte m = SlReadByte();
uint8_t m = SlReadByte();
size_t len;
size_t endoffs;
@@ -2550,7 +2550,7 @@ static void SlLoadCheckChunk(const ChunkHandler *ch, uint32_t chunk_id)
DEBUG(sl, 2, "Loading chunk %s", ChunkIDDumper()(chunk_id));
}
byte m = SlReadByte();
uint8_t m = SlReadByte();
size_t len;
size_t endoffs;
@@ -2837,7 +2837,7 @@ struct FileReader : LoadFilter {
this->file = nullptr;
}
size_t Read(byte *buf, size_t size) override
size_t Read(uint8_t *buf, size_t size) override
{
/* We're in the process of shutting down, i.e. in "failure" mode. */
if (this->file == nullptr) return 0;
@@ -2877,7 +2877,7 @@ struct FileWriter : SaveFilter {
if (!this->temp_name.empty()) unlink(this->temp_name.c_str());
}
void Write(byte *buf, size_t size) override
void Write(uint8_t *buf, size_t size) override
{
/* We're in the process of shutting down, i.e. in "failure" mode. */
if (this->file == nullptr) return;
@@ -2946,18 +2946,18 @@ struct LZOLoadFilter : LoadFilter {
if (lzo_init() != LZO_E_OK) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "cannot initialize decompressor");
}
size_t Read(byte *buf, size_t ssize) override
size_t Read(uint8_t *buf, size_t ssize) override
{
assert(ssize >= LZO_BUFFER_SIZE);
/* Buffer size is from the LZO docs plus the chunk header size. */
byte out[LZO_BUFFER_SIZE + LZO_BUFFER_SIZE / 16 + 64 + 3 + sizeof(uint32_t) * 2];
uint8_t out[LZO_BUFFER_SIZE + LZO_BUFFER_SIZE / 16 + 64 + 3 + sizeof(uint32_t) * 2];
uint32_t tmp[2];
uint32_t size;
lzo_uint len = ssize;
/* Read header*/
if (this->chain->Read((byte*)tmp, sizeof(tmp)) != sizeof(tmp)) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE, "File read failed");
if (this->chain->Read((uint8_t*)tmp, sizeof(tmp)) != sizeof(tmp)) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE, "File read failed");
/* Check if size is bad */
((uint32_t*)out)[0] = size = tmp[1];
@@ -2989,17 +2989,17 @@ struct LZOSaveFilter : SaveFilter {
* @param chain The next filter in this chain.
* @param compression_level The requested level of compression.
*/
LZOSaveFilter(std::shared_ptr<SaveFilter> chain, byte compression_level) : SaveFilter(std::move(chain))
LZOSaveFilter(std::shared_ptr<SaveFilter> chain, uint8_t compression_level) : SaveFilter(std::move(chain))
{
if (lzo_init() != LZO_E_OK) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "cannot initialize compressor");
}
void Write(byte *buf, size_t size) override
void Write(uint8_t *buf, size_t size) override
{
const lzo_bytep in = buf;
/* Buffer size is from the LZO docs plus the chunk header size. */
byte out[LZO_BUFFER_SIZE + LZO_BUFFER_SIZE / 16 + 64 + 3 + sizeof(uint32_t) * 2];
byte wrkmem[LZO1X_1_MEM_COMPRESS];
uint8_t out[LZO_BUFFER_SIZE + LZO_BUFFER_SIZE / 16 + 64 + 3 + sizeof(uint32_t) * 2];
uint8_t wrkmem[LZO1X_1_MEM_COMPRESS];
lzo_uint outlen;
do {
@@ -3033,7 +3033,7 @@ struct NoCompLoadFilter : LoadFilter {
{
}
size_t Read(byte *buf, size_t size) override
size_t Read(uint8_t *buf, size_t size) override
{
return this->chain->Read(buf, size);
}
@@ -3046,11 +3046,11 @@ struct NoCompSaveFilter : SaveFilter {
* @param chain The next filter in this chain.
* @param compression_level The requested level of compression.
*/
NoCompSaveFilter(std::shared_ptr<SaveFilter> chain, byte compression_level) : SaveFilter(std::move(chain))
NoCompSaveFilter(std::shared_ptr<SaveFilter> chain, uint8_t compression_level) : SaveFilter(std::move(chain))
{
}
void Write(byte *buf, size_t size) override
void Write(uint8_t *buf, size_t size) override
{
this->chain->Write(buf, size);
}
@@ -3066,7 +3066,7 @@ struct NoCompSaveFilter : SaveFilter {
/** Filter using Zlib compression. */
struct ZlibLoadFilter : LoadFilter {
z_stream z; ///< Stream state we are reading from.
byte fread_buf[MEMORY_CHUNK_SIZE]; ///< Buffer for reading from the file.
uint8_t fread_buf[MEMORY_CHUNK_SIZE]; ///< Buffer for reading from the file.
/**
* Initialise this filter.
@@ -3084,7 +3084,7 @@ struct ZlibLoadFilter : LoadFilter {
inflateEnd(&this->z);
}
size_t Read(byte *buf, size_t size) override
size_t Read(uint8_t *buf, size_t size) override
{
this->z.next_out = buf;
this->z.avail_out = (uint)size;
@@ -3110,14 +3110,14 @@ struct ZlibLoadFilter : LoadFilter {
/** Filter using Zlib compression. */
struct ZlibSaveFilter : SaveFilter {
z_stream z; ///< Stream state we are writing to.
byte buf[MEMORY_CHUNK_SIZE]; ///< output buffer
uint8_t buf[MEMORY_CHUNK_SIZE]; ///< output buffer
/**
* Initialise this filter.
* @param chain The next filter in this chain.
* @param compression_level The requested level of compression.
*/
ZlibSaveFilter(std::shared_ptr<SaveFilter> chain, byte compression_level) : SaveFilter(std::move(chain))
ZlibSaveFilter(std::shared_ptr<SaveFilter> chain, uint8_t compression_level) : SaveFilter(std::move(chain))
{
memset(&this->z, 0, sizeof(this->z));
if (deflateInit(&this->z, compression_level) != Z_OK) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "cannot initialize compressor");
@@ -3135,7 +3135,7 @@ struct ZlibSaveFilter : SaveFilter {
* @param len Amount of bytes to write.
* @param mode Mode for deflate.
*/
void WriteLoop(byte *p, size_t len, int mode)
void WriteLoop(uint8_t *p, size_t len, int mode)
{
uint n;
this->z.next_in = p;
@@ -3163,7 +3163,7 @@ struct ZlibSaveFilter : SaveFilter {
} while (this->z.avail_in || !this->z.avail_out);
}
void Write(byte *buf, size_t size) override
void Write(uint8_t *buf, size_t size) override
{
this->WriteLoop(buf, size, 0);
}
@@ -3194,8 +3194,8 @@ static const lzma_stream _lzma_init = LZMA_STREAM_INIT;
/** Filter without any compression. */
struct LZMALoadFilter : LoadFilter {
lzma_stream lzma; ///< Stream state that we are reading from.
byte fread_buf[MEMORY_CHUNK_SIZE]; ///< Buffer for reading from the file.
lzma_stream lzma; ///< Stream state that we are reading from.
uint8_t fread_buf[MEMORY_CHUNK_SIZE]; ///< Buffer for reading from the file.
/**
* Initialise this filter.
@@ -3213,7 +3213,7 @@ struct LZMALoadFilter : LoadFilter {
lzma_end(&this->lzma);
}
size_t Read(byte *buf, size_t size) override
size_t Read(uint8_t *buf, size_t size) override
{
this->lzma.next_out = buf;
this->lzma.avail_out = size;
@@ -3238,14 +3238,14 @@ struct LZMALoadFilter : LoadFilter {
/** Filter using LZMA compression. */
struct LZMASaveFilter : SaveFilter {
lzma_stream lzma; ///< Stream state that we are writing to.
byte buf[MEMORY_CHUNK_SIZE]; ///< output buffer
uint8_t buf[MEMORY_CHUNK_SIZE]; ///< output buffer
/**
* Initialise this filter.
* @param chain The next filter in this chain.
* @param compression_level The requested level of compression.
*/
LZMASaveFilter(std::shared_ptr<SaveFilter> chain, byte compression_level) : SaveFilter(std::move(chain)), lzma(_lzma_init)
LZMASaveFilter(std::shared_ptr<SaveFilter> chain, uint8_t compression_level) : SaveFilter(std::move(chain)), lzma(_lzma_init)
{
if (lzma_easy_encoder(&this->lzma, compression_level, LZMA_CHECK_CRC32) != LZMA_OK) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "cannot initialize compressor");
}
@@ -3262,7 +3262,7 @@ struct LZMASaveFilter : SaveFilter {
* @param len Amount of bytes to write.
* @param action Action for lzma_code.
*/
void WriteLoop(byte *p, size_t len, lzma_action action)
void WriteLoop(uint8_t *p, size_t len, lzma_action action)
{
size_t n;
this->lzma.next_in = p;
@@ -3282,7 +3282,7 @@ struct LZMASaveFilter : SaveFilter {
} while (this->lzma.avail_in || !this->lzma.avail_out);
}
void Write(byte *buf, size_t size) override
void Write(uint8_t *buf, size_t size) override
{
this->WriteLoop(buf, size, LZMA_RUN);
}
@@ -3307,7 +3307,7 @@ struct LZMASaveFilter : SaveFilter {
/** Filter using ZSTD compression. */
struct ZSTDLoadFilter : LoadFilter {
ZSTD_DCtx *zstd; ///< ZSTD decompression context
byte fread_buf[MEMORY_CHUNK_SIZE]; ///< Buffer for reading from the file
uint8_t fread_buf[MEMORY_CHUNK_SIZE]; ///< Buffer for reading from the file
ZSTD_inBuffer input; ///< ZSTD input buffer for fread_buf
/**
@@ -3327,7 +3327,7 @@ struct ZSTDLoadFilter : LoadFilter {
ZSTD_freeDCtx(this->zstd);
}
size_t Read(byte *buf, size_t size) override
size_t Read(uint8_t *buf, size_t size) override
{
ZSTD_outBuffer output{buf, size, 0};
@@ -3351,14 +3351,14 @@ struct ZSTDLoadFilter : LoadFilter {
/** Filter using ZSTD compression. */
struct ZSTDSaveFilter : SaveFilter {
ZSTD_CCtx *zstd; ///< ZSTD compression context
byte buf[MEMORY_CHUNK_SIZE]; ///< output buffer
uint8_t buf[MEMORY_CHUNK_SIZE]; ///< output buffer
/**
* Initialise this filter.
* @param chain The next filter in this chain.
* @param compression_level The requested level of compression.
*/
ZSTDSaveFilter(std::shared_ptr<SaveFilter> chain, byte compression_level) : SaveFilter(std::move(chain))
ZSTDSaveFilter(std::shared_ptr<SaveFilter> chain, uint8_t compression_level) : SaveFilter(std::move(chain))
{
this->zstd = ZSTD_createCCtx();
if (!this->zstd) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "cannot initialize compressor");
@@ -3380,7 +3380,7 @@ struct ZSTDSaveFilter : SaveFilter {
* @param len Amount of bytes to write.
* @param mode Mode for ZSTD_compressStream2.
*/
void WriteLoop(byte *p, size_t len, ZSTD_EndDirective mode)
void WriteLoop(uint8_t *p, size_t len, ZSTD_EndDirective mode)
{
ZSTD_inBuffer input{p, len, 0};
@@ -3396,7 +3396,7 @@ struct ZSTDSaveFilter : SaveFilter {
} while (!finished);
}
void Write(byte *buf, size_t size) override
void Write(uint8_t *buf, size_t size) override
{
this->WriteLoop(buf, size, ZSTD_e_continue);
}
@@ -3414,7 +3414,7 @@ struct ZSTDSaveFilter : SaveFilter {
************* END OF CODE *****************
*******************************************/
enum SaveLoadFormatFlags : byte {
enum SaveLoadFormatFlags : uint8_t {
SLF_NONE = 0,
SLF_NO_THREADED_LOAD = 1 << 0, ///< Unsuitable for threaded loading
SLF_REQUIRES_ZSTD = 1 << 1, ///< Automatic selection requires the zstd flag
@@ -3426,12 +3426,12 @@ struct SaveLoadFormat {
const char *name; ///< name of the compressor/decompressor (debug-only)
uint32_t tag; ///< the 4-letter tag by which it is identified in the savegame
std::shared_ptr<LoadFilter> (*init_load)(std::shared_ptr<LoadFilter> chain); ///< Constructor for the load filter.
std::shared_ptr<SaveFilter> (*init_write)(std::shared_ptr<SaveFilter> chain, byte compression); ///< Constructor for the save filter.
std::shared_ptr<LoadFilter> (*init_load)(std::shared_ptr<LoadFilter> chain); ///< Constructor for the load filter.
std::shared_ptr<SaveFilter> (*init_write)(std::shared_ptr<SaveFilter> chain, uint8_t compression); ///< Constructor for the save filter.
byte min_compression; ///< the minimum compression level of this format
byte default_compression; ///< the default compression level of this format
byte max_compression; ///< the maximum compression level of this format
uint8_t min_compression; ///< the minimum compression level of this format
uint8_t default_compression; ///< the default compression level of this format
uint8_t max_compression; ///< the maximum compression level of this format
SaveLoadFormatFlags flags; ///< flags
};
@@ -3483,7 +3483,7 @@ static const SaveLoadFormat _saveload_formats[] = {
* @param compression_level Output for telling what compression level we want.
* @return Pointer to SaveLoadFormat struct giving all characteristics of this type of savegame
*/
static const SaveLoadFormat *GetSavegameFormat(const std::string &full_name, byte *compression_level, SaveModeFlags flags)
static const SaveLoadFormat *GetSavegameFormat(const std::string &full_name, uint8_t *compression_level, SaveModeFlags flags)
{
const SaveLoadFormat *def = lastof(_saveload_formats);
@@ -3606,14 +3606,14 @@ static void SaveFileError()
static SaveOrLoadResult SaveFileToDisk(bool threaded)
{
try {
byte compression;
uint8_t compression;
const SaveLoadFormat *fmt = GetSavegameFormat(_savegame_format, &compression, _sl.save_flags);
DEBUG(sl, 3, "Using compression format: %s, level: %u", fmt->name, compression);
/* We have written our stuff to memory, now write it to file! */
uint32_t hdr[2] = { fmt->tag, TO_BE32((uint32_t) (SAVEGAME_VERSION | SAVEGAME_VERSION_EXT) << 16) };
_sl.sf->Write((byte*)hdr, sizeof(hdr));
_sl.sf->Write((uint8_t*)hdr, sizeof(hdr));
_sl.sf = fmt->init_write(_sl.sf, compression);
_sl.dumper->Flush(*(_sl.sf));
@@ -3724,7 +3724,7 @@ struct ThreadedLoadFilter : LoadFilter {
uint count_ready = 0;
size_t read_offsets[BUFFER_COUNT];
size_t read_counts[BUFFER_COUNT];
byte read_buf[MEMORY_CHUNK_SIZE * BUFFER_COUNT]; ///< Buffers for reading from source.
uint8_t read_buf[MEMORY_CHUNK_SIZE * BUFFER_COUNT]; ///< Buffers for reading from source.
bool no_thread = false;
bool have_exception = false;
@@ -3788,7 +3788,7 @@ struct ThreadedLoadFilter : LoadFilter {
}
}
size_t Read(byte *buf, size_t size) override
size_t Read(uint8_t *buf, size_t size) override
{
if (this->no_thread) return this->chain->Read(buf, size);
@@ -3846,7 +3846,7 @@ static SaveOrLoadResult DoLoad(std::shared_ptr<LoadFilter> reader, bool load_che
});
uint32_t hdr[2];
if (_sl.lf->Read((byte*)hdr, sizeof(hdr)) != sizeof(hdr)) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
if (_sl.lf->Read((uint8_t*)hdr, sizeof(hdr)) != sizeof(hdr)) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
SaveLoadVersion original_sl_version = SL_MIN_VERSION;
@@ -4332,7 +4332,7 @@ SaveLoadVersion GeneralUpstreamChunkLoadInfo::GetLoadVersion()
{
extern SaveLoadVersion _sl_xv_upstream_version;
byte block_mode = _sl.chunk_block_modes[_sl.current_chunk_id];
uint8_t block_mode = _sl.chunk_block_modes[_sl.current_chunk_id];
return (block_mode == CH_TABLE || block_mode == CH_SPARSE_TABLE) ? _sl_xv_upstream_version : _sl_version;
}

View File

@@ -56,7 +56,7 @@ enum SavegameType {
SGT_INVALID = 0xFF, ///< broken savegame (used internally)
};
enum SaveModeFlags : byte {
enum SaveModeFlags : uint8_t {
SMF_NONE = 0,
SMF_NET_SERVER = 1 << 0, ///< Network server save
SMF_ZSTD_OK = 1 << 1, ///< Zstd OK
@@ -275,7 +275,7 @@ using upstream_sl::MakeConditionallyUpstreamChunkHandler;
using upstream_sl::MakeSaveUpstreamFeatureConditionalLoadUpstreamChunkHandler;
struct NullStruct {
byte null;
uint8_t null;
};
/** A table of ChunkHandler entries. */
@@ -905,10 +905,10 @@ inline constexpr void *SlVarWrapper(void* ptr)
* @param minor Minor number of the version to check against. If \a minor is 0 or not specified, only the major number is checked.
* @return Savegame version is earlier than the specified version.
*/
inline bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor = 0)
inline bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor = 0)
{
extern SaveLoadVersion _sl_version;
extern byte _sl_minor_version;
extern uint8_t _sl_minor_version;
return _sl_version < major || (minor > 0 && _sl_version == major && _sl_minor_version < minor);
}
@@ -971,7 +971,7 @@ inline void *GetVariableAddress(const void *object, const SaveLoad &sld)
/* Everything else should be a non-null pointer. */
assert(object != nullptr);
#endif
return const_cast<byte *>((const byte *)object + (ptrdiff_t)sld.address);
return const_cast<uint8_t *>((const uint8_t *)object + (ptrdiff_t)sld.address);
}
int64_t ReadValue(const void *ptr, VarType conv);
@@ -992,10 +992,10 @@ size_t SlCalcObjLength(const void *object, const SaveLoadTable &slt);
* @return Span of the saved data, in the autolength temp buffer
*/
template <typename F>
std::span<byte> SlSaveToTempBuffer(F proc)
std::span<uint8_t> SlSaveToTempBuffer(F proc)
{
extern uint8_t SlSaveToTempBufferSetup();
extern std::span<byte> SlSaveToTempBufferRestore(uint8_t state);
extern std::span<uint8_t> SlSaveToTempBufferRestore(uint8_t state);
uint8_t state = SlSaveToTempBufferSetup();
proc();
@@ -1011,7 +1011,7 @@ std::span<byte> SlSaveToTempBuffer(F proc)
template <typename F>
std::vector<uint8_t> SlSaveToVector(F proc)
{
std::span<byte> result = SlSaveToTempBuffer(proc);
std::span<uint8_t> result = SlSaveToTempBuffer(proc);
return std::vector<uint8_t>(result.begin(), result.end());
}
@@ -1040,8 +1040,8 @@ bool SlConditionallySave(F proc)
struct SlLoadFromBufferState {
size_t old_obj_len;
byte *old_bufp;
byte *old_bufe;
uint8_t *old_bufp;
uint8_t *old_bufe;
};
/**
@@ -1049,10 +1049,10 @@ struct SlLoadFromBufferState {
* @param proc The callback procedure that is called
*/
template <typename F>
void SlLoadFromBuffer(const byte *buffer, size_t length, F proc)
void SlLoadFromBuffer(const uint8_t *buffer, size_t length, F proc)
{
extern SlLoadFromBufferState SlLoadFromBufferSetup(const byte *buffer, size_t length);
extern void SlLoadFromBufferRestore(const SlLoadFromBufferState &state, const byte *buffer, size_t length);
extern SlLoadFromBufferState SlLoadFromBufferSetup(const uint8_t *buffer, size_t length);
extern void SlLoadFromBufferRestore(const SlLoadFromBufferState &state, const uint8_t *buffer, size_t length);
SlLoadFromBufferState state = SlLoadFromBufferSetup(buffer, length);
proc();

View File

@@ -26,11 +26,11 @@ static const size_t MEMORY_CHUNK_SIZE = 128 * 1024;
/** A buffer for reading (and buffering) savegame data. */
struct ReadBuffer {
byte buf[MEMORY_CHUNK_SIZE]; ///< Buffer we're going to read from.
byte *bufp; ///< Location we're at reading the buffer.
byte *bufe; ///< End of the buffer we can read from.
uint8_t buf[MEMORY_CHUNK_SIZE]; ///< Buffer we're going to read from.
uint8_t *bufp; ///< Location we're at reading the buffer.
uint8_t *bufe; ///< End of the buffer we can read from.
std::shared_ptr<LoadFilter> reader; ///< The filter used to actually read.
size_t read; ///< The amount of read bytes so far from the filter.
size_t read; ///< The amount of read bytes so far from the filter.
/**
* Initialise our variables.
@@ -47,7 +47,7 @@ struct ReadBuffer {
inline void SkipBytes(size_t bytes)
{
byte *b = this->bufp + bytes;
uint8_t *b = this->bufp + bytes;
if (likely(b <= this->bufe)) {
this->bufp = b;
} else {
@@ -55,12 +55,12 @@ struct ReadBuffer {
}
}
inline byte RawReadByte()
inline uint8_t RawReadByte()
{
return *this->bufp++;
}
inline byte ReadByte()
inline uint8_t ReadByte()
{
if (unlikely(this->bufp == this->bufe)) {
this->AcquireBytes();
@@ -69,7 +69,7 @@ struct ReadBuffer {
return RawReadByte();
}
inline byte PeekByte()
inline uint8_t PeekByte()
{
if (unlikely(this->bufp == this->bufe)) {
this->AcquireBytes();
@@ -120,7 +120,7 @@ struct ReadBuffer {
#endif
}
inline void CopyBytes(byte *ptr, size_t length)
inline void CopyBytes(uint8_t *ptr, size_t length)
{
while (length) {
if (unlikely(this->bufp == this->bufe)) {
@@ -134,7 +134,7 @@ struct ReadBuffer {
}
}
inline void CopyBytes(std::span<byte> buffer)
inline void CopyBytes(std::span<uint8_t> buffer)
{
this->CopyBytes(buffer.data(), buffer.size());
}
@@ -153,10 +153,10 @@ struct ReadBuffer {
/** Container for dumping the savegame (quickly) to memory. */
struct MemoryDumper {
struct BufferInfo {
byte *data;
uint8_t *data;
size_t size = 0;
BufferInfo(byte *d) : data(d) {}
BufferInfo(uint8_t *d) : data(d) {}
~BufferInfo() { free(this->data); }
BufferInfo(const BufferInfo &) = delete;
@@ -164,19 +164,19 @@ struct MemoryDumper {
};
std::vector<BufferInfo> blocks; ///< Buffer with blocks of allocated memory.
byte *buf = nullptr; ///< Buffer we're going to write to.
byte *bufe = nullptr; ///< End of the buffer we write to.
uint8_t *buf = nullptr; ///< Buffer we're going to write to.
uint8_t *bufe = nullptr; ///< End of the buffer we write to.
size_t completed_block_bytes = 0; ///< Total byte count of completed blocks.
byte *autolen_buf = nullptr;
byte *autolen_buf_end = nullptr;
byte *saved_buf = nullptr;
byte *saved_bufe = nullptr;
uint8_t *autolen_buf = nullptr;
uint8_t *autolen_buf_end = nullptr;
uint8_t *saved_buf = nullptr;
uint8_t *saved_bufe = nullptr;
MemoryDumper()
{
const size_t size = 8192;
this->autolen_buf = CallocT<byte>(size);
this->autolen_buf = CallocT<uint8_t>(size);
this->autolen_buf_end = this->autolen_buf + size;
}
@@ -199,7 +199,7 @@ struct MemoryDumper {
* Write a single byte into the dumper.
* @param b The byte to write.
*/
inline void WriteByte(byte b)
inline void WriteByte(uint8_t b)
{
/* Are we at the end of this chunk? */
if (unlikely(this->buf == this->bufe)) {
@@ -209,7 +209,7 @@ struct MemoryDumper {
*this->buf++ = b;
}
inline void CopyBytes(const byte *ptr, size_t length)
inline void CopyBytes(const uint8_t *ptr, size_t length)
{
while (length) {
if (unlikely(this->buf == this->bufe)) {
@@ -223,12 +223,12 @@ struct MemoryDumper {
}
}
inline void CopyBytes(std::span<const byte> buffer)
inline void CopyBytes(std::span<const uint8_t> buffer)
{
this->CopyBytes(buffer.data(), buffer.size());
}
inline void RawWriteByte(byte b)
inline void RawWriteByte(uint8_t b)
{
*this->buf++ = b;
}
@@ -277,7 +277,7 @@ struct MemoryDumper {
void Flush(SaveFilter &writer);
size_t GetSize() const;
void StartAutoLength();
std::span<byte> StopAutoLength();
std::span<uint8_t> StopAutoLength();
bool IsAutoLengthActive() const { return this->saved_buf != nullptr; }
};

View File

@@ -418,8 +418,8 @@ enum SaveLoadVersion : uint16_t {
SL_CHILLPP_233 = 233,
};
byte SlReadByte();
void SlWriteByte(byte b);
uint8_t SlReadByte();
void SlWriteByte(uint8_t b);
int SlReadUint16();
uint32_t SlReadUint32();

View File

@@ -34,7 +34,7 @@ struct LoadFilter {
* @param len The number of bytes to read.
* @return The number of actually read bytes.
*/
virtual size_t Read(byte *buf, size_t len) = 0;
virtual size_t Read(uint8_t *buf, size_t len) = 0;
/**
* Reset this filter to read from the beginning of the file.
@@ -78,7 +78,7 @@ struct SaveFilter {
* @param buf The bytes to write.
* @param len The number of bytes to write.
*/
virtual void Write(byte *buf, size_t len) = 0;
virtual void Write(uint8_t *buf, size_t len) = 0;
/**
* Prepare everything to finish writing the savegame.
@@ -95,7 +95,7 @@ struct SaveFilter {
* @param compression_level The requested level of compression.
* @tparam T The type of save filter to create.
*/
template <typename T> std::shared_ptr<SaveFilter> CreateSaveFilter(std::shared_ptr<SaveFilter> chain, byte compression_level)
template <typename T> std::shared_ptr<SaveFilter> CreateSaveFilter(std::shared_ptr<SaveFilter> chain, uint8_t compression_level)
{
return std::make_shared<T>(chain, compression_level);
}

View File

@@ -121,7 +121,7 @@ enum SaveLoadTypes {
SL_VARVEC = 14, ///< Save/load a primitive type vector.
};
typedef byte SaveLoadType; ///< Save/load type. @see SaveLoadTypes
typedef uint8_t SaveLoadType; ///< Save/load type. @see SaveLoadTypes
/** SaveLoad type struct. Do NOT use this directly but use the SLE_ macros defined just below! */
struct SaveLoad {

View File

@@ -15,7 +15,7 @@
#include "saveload.h"
#include "saveload_buffer.h"
typedef std::vector<byte> Buffer;
typedef std::vector<uint8_t> Buffer;
// Variable length integers are stored in Variable Length Quantity
// format (http://en.wikipedia.org/wiki/Variable-length_quantity)
@@ -25,18 +25,18 @@ static void WriteVLI(Buffer &b, uint i)
uint lsmask = 0x7F;
uint msmask = ~0x7F;
while(i & msmask) {
byte part = (i & lsmask) | 0x80;
uint8_t part = (i & lsmask) | 0x80;
b.push_back(part);
i >>= 7;
}
b.push_back((byte) i);
b.push_back((uint8_t) i);
}
static uint ReadVLI()
{
uint shift = 0;
uint val = 0;
byte b;
uint8_t b;
b = SlReadByte();
while(b & 0x80) {

View File

@@ -22,7 +22,7 @@
#include "../safeguards.h"
static byte _old_last_vehicle_type;
static uint8_t _old_last_vehicle_type;
static uint8_t _num_specs;
static uint8_t _num_roadstop_specs;
static uint32_t _num_roadstop_custom_tiles;

View File

@@ -69,7 +69,7 @@ std::string CopyFromOldName(StringID id)
std::ostringstream tmp;
std::ostreambuf_iterator<char> strto(tmp);
for (; *strfrom != '\0'; strfrom++) {
char32_t c = (byte)*strfrom;
char32_t c = (uint8_t)*strfrom;
/* Map from non-ISO8859-15 characters to UTF-8. */
switch (c) {

View File

@@ -257,7 +257,7 @@ static void CheckValidVehicles()
}
}
extern byte _age_cargo_skip_counter; // From misc_sl.cpp
extern uint8_t _age_cargo_skip_counter; // From misc_sl.cpp
static std::vector<Vehicle *> _load_invalid_vehicles_to_delete;
@@ -1279,7 +1279,7 @@ struct train_venc {
uint16_t cached_veh_weight;
uint16_t cached_uncapped_decel;
uint8_t cached_deceleration;
byte user_def_data;
uint8_t user_def_data;
int16_t cached_curve_speed_mod;
uint16_t cached_max_curve_speed;
};