Adding of _t to (u)int types, and WChar to char32_t

See: eaae0bb5e
This commit is contained in:
Jonathan G Rennison
2024-01-07 16:41:53 +00:00
parent 55d78a23be
commit 97e6f3062e
655 changed files with 7555 additions and 7555 deletions

View File

@@ -14,7 +14,7 @@
#ifndef WITH_BITMATH_BUILTINS
const uint8 _ffb_64[64] = {
const uint8_t _ffb_64[64] = {
0, 0, 1, 0, 2, 0, 1, 0,
3, 0, 1, 0, 2, 0, 1, 0,
4, 0, 1, 0, 2, 0, 1, 0,
@@ -25,13 +25,13 @@ const uint8 _ffb_64[64] = {
3, 0, 1, 0, 2, 0, 1, 0,
};
uint8 FindFirstBit32(uint32 x)
uint8_t FindFirstBit32(uint32_t x)
{
if (x == 0) return 0;
/* The macro FIND_FIRST_BIT is better to use when your x is
not more than 128. */
uint8 pos = 0;
uint8_t pos = 0;
if ((x & 0x0000ffff) == 0) { x >>= 16; pos += 16; }
if ((x & 0x000000ff) == 0) { x >>= 8; pos += 8; }
@@ -42,11 +42,11 @@ uint8 FindFirstBit32(uint32 x)
return pos;
}
uint8 FindFirstBit64(uint64 x)
uint8_t FindFirstBit64(uint64_t x)
{
if (x == 0) return 0;
if ((x & 0x00000000ffffffffULL) != 0) return FindFirstBit32(static_cast<uint32>(x));
return FindFirstBit32(static_cast<uint32>(x >> 32)) + 32;
if ((x & 0x00000000ffffffffULL) != 0) return FindFirstBit32(static_cast<uint32_t>(x));
return FindFirstBit32(static_cast<uint32_t>(x >> 32)) + 32;
}
#endif
@@ -62,11 +62,11 @@ uint8 FindFirstBit64(uint64 x)
* @param x The value to search
* @return The position of the last bit set
*/
uint8 FindLastBit64(uint64 x)
uint8_t FindLastBit64(uint64_t x)
{
if (x == 0) return 0;
uint8 pos = 0;
uint8_t pos = 0;
if ((x & 0xffffffff00000000ULL) != 0) { x >>= 32; pos += 32; }
if ((x & 0x00000000ffff0000ULL) != 0) { x >>= 16; pos += 16; }

View File

@@ -31,7 +31,7 @@
* @return The selected bits, aligned to a LSB.
*/
template <typename T>
debug_inline constexpr static uint GB(const T x, const uint8 s, const uint8 n)
debug_inline constexpr static uint GB(const T x, const uint8_t s, const uint8_t n)
{
return (x >> s) & (((T)1U << n) - 1);
}
@@ -103,7 +103,7 @@ inline T AB(T &x, const uint8_t s, const uint8_t n, const U i)
* @return True if the bit is set, false else.
*/
template <typename T>
debug_inline static bool HasBit(const T x, const uint8 y)
debug_inline static bool HasBit(const T x, const uint8_t y)
{
return (x & ((T)1U << y)) != 0;
}
@@ -193,7 +193,7 @@ inline T ToggleBit(T &x, const uint8_t y)
#else
/** Lookup table to check which bit is set in a 6 bit variable */
extern const uint8 _ffb_64[64];
extern const uint8_t _ffb_64[64];
/**
* Returns the first non-zero bit in a 6-bit value (from right).
@@ -216,7 +216,7 @@ extern const uint8 _ffb_64[64];
* @return The position of the first bit set, or 0 when value is 0
*/
template <typename T>
inline uint8 FindFirstBit(T value)
inline uint8_t FindFirstBit(T value)
{
static_assert(sizeof(T) <= sizeof(unsigned long long));
#ifdef WITH_BITMATH_BUILTINS
@@ -230,11 +230,11 @@ inline uint8 FindFirstBit(T value)
return __builtin_ctzll(unsigned_value);
}
#else
if (sizeof(T) <= sizeof(uint32)) {
extern uint8 FindFirstBit32(uint32 x);
if (sizeof(T) <= sizeof(uint32_t)) {
extern uint8_t FindFirstBit32(uint32_t x);
return FindFirstBit32(value);
} else {
extern uint8 FindFirstBit64(uint64 x);
extern uint8_t FindFirstBit64(uint64_t x);
return FindFirstBit64(value);
}
#endif
@@ -247,7 +247,7 @@ inline uint8 FindFirstBit(T value)
* @return The position of the last bit set, or 0 when value is 0
*/
template <typename T>
inline uint8 FindLastBit(T value)
inline uint8_t FindLastBit(T value)
{
static_assert(sizeof(T) <= sizeof(unsigned long long));
#ifdef WITH_BITMATH_BUILTINS
@@ -261,7 +261,7 @@ inline uint8 FindLastBit(T value)
return __builtin_clzll(1) - __builtin_clzll(unsigned_value);
}
#else
extern uint8 FindLastBit64(uint64 x);
extern uint8_t FindLastBit64(uint64_t x);
return FindLastBit64(value);
#endif
}
@@ -497,27 +497,27 @@ private:
#if defined(__APPLE__)
/* Make endian swapping use Apple's macros to increase speed
* (since it will use hardware swapping if available).
* Even though they should return uint16 and uint32, we get
* Even though they should return uint16_t and uint32_t, we get
* warnings if we don't cast those (why?) */
#define BSWAP64(x) ((uint64)CFSwapInt64((uint64)(x)))
#define BSWAP32(x) ((uint32)CFSwapInt32((uint32)(x)))
#define BSWAP16(x) ((uint16)CFSwapInt16((uint16)(x)))
#define BSWAP64(x) ((uint64_t)CFSwapInt64((uint64_t)(x)))
#define BSWAP32(x) ((uint32_t)CFSwapInt32((uint32_t)(x)))
#define BSWAP16(x) ((uint16_t)CFSwapInt16((uint16_t)(x)))
#elif defined(_MSC_VER)
/* MSVC has intrinsics for swapping, resulting in faster code */
#define BSWAP64(x) ((uint64)_byteswap_uint64((uint64)(x)))
#define BSWAP32(x) ((uint32)_byteswap_ulong((uint32)(x)))
#define BSWAP16(x) ((uint16)_byteswap_ushort((uint16)(x)))
#define BSWAP64(x) ((uint64_t)_byteswap_uint64((uint64_t)(x)))
#define BSWAP32(x) ((uint32_t)_byteswap_ulong((uint32_t)(x)))
#define BSWAP16(x) ((uint16_t)_byteswap_ushort((uint16_t)(x)))
#else
/**
* Perform a 64 bits endianness bitswap on x.
* @param x the variable to bitswap
* @return the bitswapped value.
*/
static inline uint64 BSWAP64(uint64 x)
static inline uint64_t BSWAP64(uint64_t x)
{
#if !defined(__ICC) && (defined(__GNUC__) || defined(__clang__))
/* GCC >= 4.3 provides a builtin, resulting in faster code */
return (uint64)__builtin_bswap64((uint64)x);
return (uint64_t)__builtin_bswap64((uint64_t)x);
#else
return ((x >> 56) & 0xFFULL) | ((x >> 40) & 0xFF00ULL) | ((x >> 24) & 0xFF0000ULL) | ((x >> 8) & 0xFF000000ULL) |
((x << 8) & 0xFF00000000ULL) | ((x << 24) & 0xFF0000000000ULL) | ((x << 40) & 0xFF000000000000ULL) | ((x << 56) & 0xFF00000000000000ULL);
@@ -530,11 +530,11 @@ private:
* @param x the variable to bitswap
* @return the bitswapped value.
*/
static inline uint32 BSWAP32(uint32 x)
static inline uint32_t BSWAP32(uint32_t x)
{
#if !defined(__ICC) && (defined(__GNUC__) || defined(__clang__))
/* GCC >= 4.3 provides a builtin, resulting in faster code */
return (uint32)__builtin_bswap32((uint32)x);
return (uint32_t)__builtin_bswap32((uint32_t)x);
#else
return ((x >> 24) & 0xFF) | ((x >> 8) & 0xFF00) | ((x << 8) & 0xFF0000) | ((x << 24) & 0xFF000000);
#endif /* __GNUC__ || __clang__ */
@@ -545,11 +545,11 @@ private:
* @param x the variable to bitswap
* @return the bitswapped value.
*/
static inline uint16 BSWAP16(uint16 x)
static inline uint16_t BSWAP16(uint16_t x)
{
#if !defined(__ICC) && (defined(__GNUC__) || defined(__clang__))
/* GCC >= 4.3 provides a builtin, resulting in faster code */
return (uint16)__builtin_bswap16((uint16)x);
return (uint16_t)__builtin_bswap16((uint16_t)x);
#else
return (x >> 8) | (x << 8);
#endif /* __GNUC__ || __clang__ */

View File

@@ -23,9 +23,9 @@
#endif /* RANDOM_DEBUG */
struct SimpleChecksum64 {
uint64 state = 0;
uint64_t state = 0;
void Update(uint64 input)
void Update(uint64_t input)
{
this->state = ROL(this->state, 1) ^ input ^ 0x123456789ABCDEF7ULL;
}
@@ -33,7 +33,7 @@ struct SimpleChecksum64 {
extern SimpleChecksum64 _state_checksum;
inline void UpdateStateChecksum(uint64 input)
inline void UpdateStateChecksum(uint64_t input)
{
if (_networking) _state_checksum.Update(input);
}

View File

@@ -48,7 +48,7 @@
inline uint16_t ReadLE16Aligned(const void *x)
{
return FROM_LE16(*(const uint16*)x);
return FROM_LE16(*(const uint16_t*)x);
}
inline uint16_t ReadLE16Unaligned(const void *x)
@@ -56,7 +56,7 @@ inline uint16_t ReadLE16Unaligned(const void *x)
#if OTTD_ALIGNMENT == 1
return ((const byte*)x)[0] | ((const byte*)x)[1] << 8;
#else
return FROM_LE16(*(const uint16*)x);
return FROM_LE16(*(const uint16_t*)x);
#endif /* OTTD_ALIGNMENT == 1 */
}

View File

@@ -46,10 +46,10 @@ struct Dimension {
/** Padding dimensions to apply to each side of a Rect. */
struct RectPadding {
uint8 left;
uint8 top;
uint8 right;
uint8 bottom;
uint8_t left;
uint8_t top;
uint8_t right;
uint8_t bottom;
static const RectPadding zero;
@@ -225,10 +225,10 @@ struct Rect {
};
struct Rect16 {
int16 left;
int16 top;
int16 right;
int16 bottom;
int16_t left;
int16_t top;
int16_t right;
int16_t bottom;
};
template <typename InT, typename OutT>

View File

@@ -14,7 +14,7 @@
* Simple 32 bit to 32 bit hash
* From MurmurHash3
*/
inline uint32 SimpleHash32(uint32 h)
inline uint32_t SimpleHash32(uint32_t h)
{
h ^= h >> 16;
h *= 0x85ebca6b;

View File

@@ -57,7 +57,7 @@ int GreatestCommonDivisor(int a, int b)
*/
int DivideApprox(int a, int b)
{
int random_like = (((int64) (a + b)) * ((int64) (a - b))) % b;
int random_like = (((int64_t) (a + b)) * ((int64_t) (a - b))) % b;
int remainder = a % b;
@@ -75,10 +75,10 @@ int DivideApprox(int a, int b)
* @return Rounded integer square root.
* @note Algorithm taken from http://en.wikipedia.org/wiki/Methods_of_computing_square_roots
*/
uint32 IntSqrt(uint32 num)
uint32_t IntSqrt(uint32_t num)
{
uint32 res = 0;
uint32 bit = 1UL << 30; // Second to top bit number.
uint32_t res = 0;
uint32_t bit = 1UL << 30; // Second to top bit number.
/* 'bit' starts at the highest power of four <= the argument. */
while (bit > num) bit >>= 2;
@@ -105,10 +105,10 @@ uint32 IntSqrt(uint32 num)
* @return Rounded integer square root.
* @note Algorithm taken from http://en.wikipedia.org/wiki/Methods_of_computing_square_roots
*/
uint32 IntSqrt64(uint64 num)
uint32_t IntSqrt64(uint64_t num)
{
uint64 res = 0;
uint64 bit = 1ULL << 62; // Second to top bit number.
uint64_t res = 0;
uint64_t bit = 1ULL << 62; // Second to top bit number.
/* 'bit' starts at the highest power of four <= the argument. */
while (bit > num) bit >>= 2;
@@ -126,7 +126,7 @@ uint32 IntSqrt64(uint64 num)
/* Arithmetic rounding to nearest integer. */
if (num > res) res++;
return (uint32)res;
return (uint32_t)res;
}
/**
@@ -135,10 +135,10 @@ uint32 IntSqrt64(uint64 num)
* @return Rounded integer square root.
* @note Algorithm taken from https://stackoverflow.com/a/56738014
*/
uint32 IntCbrt(uint64 num)
uint32_t IntCbrt(uint64_t num)
{
uint64 r0 = 1;
uint64 r1 = 0;
uint64_t r0 = 1;
uint64_t r1 = 0;
if (num == 0) return 0;
@@ -160,23 +160,23 @@ uint32 IntCbrt(uint64 num)
}
while (r0 < r1);
return ((uint32) r1); /* floor(cbrt(x)); */
return ((uint32_t) r1); /* floor(cbrt(x)); */
}
/**
* Compress unsigned integer into 16 bits, in a way that increases dynamic range, at the expense of precision for large values
*/
uint16 RXCompressUint(uint32 num)
uint16_t RXCompressUint(uint32_t num)
{
if (num <= 0x100) return num;
if (num <= 0x7900) return 0x100 + ((num - 0x100) >> 3);
return std::min<uint32>(UINT16_MAX, 0x1000 + ((num - 0x7900) >> 6));
return std::min<uint32_t>(UINT16_MAX, 0x1000 + ((num - 0x7900) >> 6));
}
/**
* Inverse of RXCompressUint
*/
uint32 RXDecompressUint(uint16 num)
uint32_t RXDecompressUint(uint16_t num)
{
if (num > 0x1000) return ((num - 0x1000) << 6) + 0x7900;
if (num > 0x100) return ((num - 0x100) << 3) + 0x100;

View File

@@ -420,11 +420,11 @@ inline T DivTowardsPositiveInf(T a, T b)
return (a / b) + (a % b > 0 ? 1 : 0);
}
uint32 IntSqrt(uint32 num);
uint32 IntSqrt64(uint64 num);
uint32 IntCbrt(uint64 num);
uint32_t IntSqrt(uint32_t num);
uint32_t IntSqrt64(uint64_t num);
uint32_t IntCbrt(uint64_t num);
uint16 RXCompressUint(uint32 num);
uint32 RXDecompressUint(uint16 num);
uint16_t RXCompressUint(uint32_t num);
uint32_t RXDecompressUint(uint16_t num);
#endif /* MATH_FUNC_HPP */

View File

@@ -89,11 +89,11 @@ public:
/* Operators for addition and subtraction. */
inline constexpr OverflowSafeInt operator + (const OverflowSafeInt& other) const { OverflowSafeInt result = *this; result += other; return result; }
inline constexpr OverflowSafeInt operator + (const int other) const { OverflowSafeInt result = *this; result += (int64)other; return result; }
inline constexpr OverflowSafeInt operator + (const uint other) const { OverflowSafeInt result = *this; result += (int64)other; return result; }
inline constexpr OverflowSafeInt operator + (const int other) const { OverflowSafeInt result = *this; result += (int64_t)other; return result; }
inline constexpr OverflowSafeInt operator + (const uint other) const { OverflowSafeInt result = *this; result += (int64_t)other; return result; }
inline constexpr OverflowSafeInt operator - (const OverflowSafeInt& other) const { OverflowSafeInt result = *this; result -= other; return result; }
inline constexpr OverflowSafeInt operator - (const int other) const { OverflowSafeInt result = *this; result -= (int64)other; return result; }
inline constexpr OverflowSafeInt operator - (const uint other) const { OverflowSafeInt result = *this; result -= (int64)other; return result; }
inline constexpr OverflowSafeInt operator - (const int other) const { OverflowSafeInt result = *this; result -= (int64_t)other; return result; }
inline constexpr OverflowSafeInt operator - (const uint other) const { OverflowSafeInt result = *this; result -= (int64_t)other; return result; }
inline constexpr OverflowSafeInt& operator ++ () { return *this += 1; }
inline constexpr OverflowSafeInt& operator -- () { return *this += -1; }
@@ -134,14 +134,14 @@ public:
}
/* Operators for multiplication. */
inline constexpr OverflowSafeInt operator * (const int64 factor) const { OverflowSafeInt result = *this; result *= factor; return result; }
inline constexpr OverflowSafeInt operator * (const int factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
inline constexpr OverflowSafeInt operator * (const uint factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
inline constexpr OverflowSafeInt operator * (const uint16 factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
inline constexpr OverflowSafeInt operator * (const byte factor) const { OverflowSafeInt result = *this; result *= (int64)factor; return result; }
inline constexpr OverflowSafeInt operator * (const int64_t factor) const { OverflowSafeInt result = *this; result *= factor; return result; }
inline constexpr OverflowSafeInt operator * (const int factor) const { OverflowSafeInt result = *this; result *= (int64_t)factor; return result; }
inline constexpr OverflowSafeInt operator * (const uint factor) const { OverflowSafeInt result = *this; result *= (int64_t)factor; return result; }
inline constexpr OverflowSafeInt operator * (const uint16_t factor) const { OverflowSafeInt result = *this; result *= (int64_t)factor; return result; }
inline constexpr OverflowSafeInt operator * (const byte factor) const { OverflowSafeInt result = *this; result *= (int64_t)factor; return result; }
/* Operators for division. */
inline constexpr OverflowSafeInt& operator /= (const int64 divisor) { this->m_value /= divisor; return *this; }
inline constexpr OverflowSafeInt& operator /= (const int64_t divisor) { this->m_value /= divisor; return *this; }
inline constexpr OverflowSafeInt operator / (const OverflowSafeInt& divisor) const { OverflowSafeInt result = *this; result /= divisor.m_value; return result; }
inline constexpr OverflowSafeInt operator / (const int divisor) const { OverflowSafeInt result = *this; result /= divisor; return result; }
inline constexpr OverflowSafeInt operator / (const uint divisor) const { OverflowSafeInt result = *this; result /= (int)divisor; return result; }
@@ -179,11 +179,11 @@ public:
};
/* Sometimes we got int64 operator OverflowSafeInt instead of vice versa. Handle that properly. */
template <class T> inline constexpr OverflowSafeInt<T> operator + (const int64 a, const OverflowSafeInt<T> b) { return b + a; }
template <class T> inline constexpr OverflowSafeInt<T> operator - (const int64 a, const OverflowSafeInt<T> b) { return -b + a; }
template <class T> inline constexpr OverflowSafeInt<T> operator * (const int64 a, const OverflowSafeInt<T> b) { return b * a; }
template <class T> inline constexpr OverflowSafeInt<T> operator / (const int64 a, const OverflowSafeInt<T> b) { return (OverflowSafeInt<T>)a / (int)b; }
/* Sometimes we got int64_t operator OverflowSafeInt instead of vice versa. Handle that properly. */
template <class T> inline constexpr OverflowSafeInt<T> operator + (const int64_t a, const OverflowSafeInt<T> b) { return b + a; }
template <class T> inline constexpr OverflowSafeInt<T> operator - (const int64_t a, const OverflowSafeInt<T> b) { return -b + a; }
template <class T> inline constexpr OverflowSafeInt<T> operator * (const int64_t a, const OverflowSafeInt<T> b) { return b * a; }
template <class T> inline constexpr OverflowSafeInt<T> operator / (const int64_t a, const OverflowSafeInt<T> b) { return (OverflowSafeInt<T>)a / (int)b; }
/* Sometimes we got int operator OverflowSafeInt instead of vice versa. Handle that properly. */
template <class T> inline constexpr OverflowSafeInt<T> operator + (const int a, const OverflowSafeInt<T> b) { return b + a; }
@@ -203,8 +203,8 @@ template <class T> inline constexpr OverflowSafeInt<T> operator - (const byte a
template <class T> inline constexpr OverflowSafeInt<T> operator * (const byte a, const OverflowSafeInt<T> b) { return b * (uint)a; }
template <class T> inline constexpr OverflowSafeInt<T> operator / (const byte a, const OverflowSafeInt<T> b) { return (OverflowSafeInt<T>)a / (int)b; }
typedef OverflowSafeInt<int64> OverflowSafeInt64;
typedef OverflowSafeInt<int32> OverflowSafeInt32;
typedef OverflowSafeInt<int64_t> OverflowSafeInt64;
typedef OverflowSafeInt<int32_t> OverflowSafeInt32;
/* Some basic "unit tests". Also has the bonus of confirming that constexpr is working. */
static_assert(OverflowSafeInt32(INT32_MIN) - 1 == OverflowSafeInt32(INT32_MIN));

View File

@@ -15,7 +15,7 @@
/**
* Pool-type container for POD data..
*/
template <typename PTR, size_t SIZE, uint N_PER_CHUNK, typename IDX = uint32>
template <typename PTR, size_t SIZE, uint N_PER_CHUNK, typename IDX = uint32_t>
class PodPool {
static_assert(SIZE >= sizeof(IDX));

View File

@@ -63,7 +63,7 @@ DEFINE_POOL_METHOD(inline void)::ResizeFor(size_t index)
this->free_bitmap = ReallocT(this->free_bitmap, CeilDivT<size_t>(new_size, 64));
MemSetT(this->free_bitmap + CeilDivT<size_t>(this->size, 64), 0, CeilDivT<size_t>(new_size, 64) - CeilDivT<size_t>(this->size, 64));
if (new_size % 64 != 0) {
this->free_bitmap[new_size / 64] |= (~((uint64) 0)) << (new_size % 64);
this->free_bitmap[new_size / 64] |= (~((uint64_t) 0)) << (new_size % 64);
}
this->size = new_size;
@@ -79,7 +79,7 @@ DEFINE_POOL_METHOD(inline size_t)::FindFirstFree()
size_t bitmap_end = CeilDivT<size_t>(this->first_unused, 64);
for (; bitmap_index < bitmap_end; bitmap_index++) {
uint64 available = ~this->free_bitmap[bitmap_index];
uint64_t available = ~this->free_bitmap[bitmap_index];
if (available == 0) continue;
return (bitmap_index * 64) + FindFirstBit(available);
}

View File

@@ -80,7 +80,7 @@ private:
template <class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, PoolType Tpool_type = PT_NORMAL, bool Tcache = false, bool Tzero = true>
struct Pool : PoolBase {
/* Ensure Tmax_size is within the bounds of Tindex. */
static_assert((uint64)(Tmax_size - 1) >> 8 * sizeof(Tindex) == 0);
static_assert((uint64_t)(Tmax_size - 1) >> 8 * sizeof(Tindex) == 0);
static constexpr size_t MAX_SIZE = Tmax_size; ///< Make template parameter accessible from outside
@@ -96,7 +96,7 @@ struct Pool : PoolBase {
bool cleaning; ///< True if cleaning pool (deleting all items)
Titem **data; ///< Pointer to array of pointers to Titem
uint64 *free_bitmap; ///< Pointer to free bitmap
uint64_t *free_bitmap; ///< Pointer to free bitmap
Pool(const char *name);
void CleanPool() override;

View File

@@ -28,10 +28,10 @@ Randomizer _random, _interactive_random;
* Generate the next pseudo random number
* @return the random number
*/
uint32 Randomizer::Next()
uint32_t Randomizer::Next()
{
const uint32 s = this->state[0];
const uint32 t = this->state[1];
const uint32_t s = this->state[0];
const uint32_t t = this->state[1];
this->state[0] = s + ROR(t ^ 0x1234567F, 7) + 1;
return this->state[1] = ROR(s, 3) - 1;
@@ -43,16 +43,16 @@ uint32 Randomizer::Next()
* @param limit Limit of the range to be generated from.
* @return Random number in [0,\a limit)
*/
uint32 Randomizer::Next(uint32 limit)
uint32_t Randomizer::Next(uint32_t limit)
{
return ((uint64)this->Next() * (uint64)limit) >> 32;
return ((uint64_t)this->Next() * (uint64_t)limit) >> 32;
}
/**
* (Re)set the state of the random number generator.
* @param seed the new state
*/
void Randomizer::SetSeed(uint32 seed)
void Randomizer::SetSeed(uint32_t seed)
{
this->state[0] = seed;
this->state[1] = seed;
@@ -62,14 +62,14 @@ void Randomizer::SetSeed(uint32 seed)
* (Re)set the state of the random number generators.
* @param seed the new state
*/
void SetRandomSeed(uint32 seed)
void SetRandomSeed(uint32_t seed)
{
_random.SetSeed(seed);
_interactive_random.SetSeed(seed * 0x1234567);
}
#ifdef RANDOM_DEBUG
uint32 DoRandom(int line, const char *file)
uint32_t DoRandom(int line, const char *file)
{
if (_networking && (!_network_server || (NetworkClientSocket::IsValidID(0) && NetworkClientSocket::Get(0)->status != NetworkClientSocket::STATUS_INACTIVE))) {
DEBUG(random, 0, "%s; %04x; %02x; %s:%d", debug_date_dumper().HexDate(), _frame_counter, (byte)_current_company, file, line);
@@ -78,8 +78,8 @@ uint32 DoRandom(int line, const char *file)
return _random.Next();
}
uint32 DoRandomRange(uint32 limit, int line, const char *file)
uint32_t DoRandomRange(uint32_t limit, int line, const char *file)
{
return ((uint64)DoRandom(line, file) * (uint64)limit) >> 32;
return ((uint64_t)DoRandom(line, file) * (uint64_t)limit) >> 32;
}
#endif /* RANDOM_DEBUG */

View File

@@ -22,11 +22,11 @@
*/
struct Randomizer {
/** The state of the randomizer */
uint32 state[2];
uint32_t state[2];
uint32 Next();
uint32 Next(uint32 limit);
void SetSeed(uint32 seed);
uint32_t Next();
uint32_t Next(uint32_t limit);
void SetSeed(uint32_t seed);
};
extern Randomizer _random; ///< Random used in the game state calculations
extern Randomizer _interactive_random; ///< Random used everywhere else, where it does not (directly) influence the game state
@@ -73,18 +73,18 @@ public:
}
};
void SetRandomSeed(uint32 seed);
void SetRandomSeed(uint32_t seed);
#ifdef RANDOM_DEBUG
# ifdef __APPLE__
# define OTTD_Random() DoRandom(__LINE__, __FILE__)
# else
# define Random() DoRandom(__LINE__, __FILE__)
# endif
uint32 DoRandom(int line, const char *file);
uint32_t DoRandom(int line, const char *file);
# define RandomRange(limit) DoRandomRange(limit, __LINE__, __FILE__)
uint32 DoRandomRange(uint32 limit, int line, const char *file);
uint32_t DoRandomRange(uint32_t limit, int line, const char *file);
#else
static inline uint32 Random()
static inline uint32_t Random()
{
return _random.Next();
}
@@ -96,7 +96,7 @@ void SetRandomSeed(uint32 seed);
* @param limit Limit for the range to be picked from.
* @return A random number in [0,\a limit).
*/
static inline uint32 RandomRange(uint32 limit)
static inline uint32_t RandomRange(uint32_t limit)
{
return _random.Next(limit);
}
@@ -130,7 +130,7 @@ inline uint32_t InteractiveRandomRange(uint32_t limit)
inline bool Chance16I(const uint a, const uint b, const uint32_t r)
{
assert(b != 0);
return (((uint16)r * b + b / 2) >> 16) < a;
return (((uint16_t)r * b + b / 2) >> 16) < a;
}
/**

View File

@@ -26,14 +26,14 @@ template <class T>
class ring_buffer
{
std::unique_ptr<byte, FreeDeleter> data;
uint32 head = 0;
uint32 count = 0;
uint32 mask = (uint32)-1;
uint32_t head = 0;
uint32_t count = 0;
uint32_t mask = (uint32_t)-1;
static uint32 round_up_size(uint32 size)
static uint32_t round_up_size(uint32_t size)
{
if (size <= 4) return 4;
uint8 bit = FindLastBit(size - 1);
uint8_t bit = FindLastBit(size - 1);
return 1 << (bit + 1);
}
@@ -43,15 +43,15 @@ class ring_buffer
protected:
const ring_buffer *ring = nullptr;
uint32 pos = 0;
uint32_t pos = 0;
ring_buffer_iterator_base() {}
ring_buffer_iterator_base(const ring_buffer *ring, uint32 pos)
ring_buffer_iterator_base(const ring_buffer *ring, uint32_t pos)
: ring(ring), pos(pos) {}
public:
uint32 debug_raw_position() const { return this->pos; }
uint32_t debug_raw_position() const { return this->pos; }
};
public:
@@ -68,7 +68,7 @@ public:
: ring_buffer_iterator_base(other.ring, other.pos) {}
private:
ring_buffer_iterator(const ring_buffer *ring, uint32 pos)
ring_buffer_iterator(const ring_buffer *ring, uint32_t pos)
: ring_buffer_iterator_base(ring, pos) {}
void next()
@@ -92,9 +92,9 @@ public:
void move(std::ptrdiff_t delta)
{
if (REVERSE) {
this->pos -= (uint32)delta;
this->pos -= (uint32_t)delta;
} else {
this->pos += (uint32)delta;
this->pos += (uint32_t)delta;
}
}
@@ -185,9 +185,9 @@ public:
{
dbg_assert(this->ring == other.ring);
if (REVERSE) {
return (int32)(other.pos - this->pos);
return (int32_t)(other.pos - this->pos);
} else {
return (int32)(this->pos - other.pos);
return (int32_t)(this->pos - other.pos);
}
}
};
@@ -207,11 +207,11 @@ public:
template <typename U>
void construct_from(const U &other)
{
uint32 cap = round_up_size((uint32)other.size());
uint32_t cap = round_up_size((uint32_t)other.size());
this->data.reset(MallocT<byte>(cap * sizeof(T)));
this->mask = cap - 1;
this->head = 0;
this->count = (uint32)other.size();
this->count = (uint32_t)other.size();
byte *ptr = this->data.get();
for (const T &item : other) {
new (ptr) T(item);
@@ -247,7 +247,7 @@ public:
this->clear();
if (!other.empty()) {
if (other.size() > this->capacity()) {
uint32 cap = round_up_size(other.count);
uint32_t cap = round_up_size(other.count);
this->data.reset(MallocT<byte>(cap * sizeof(T)));
this->mask = cap - 1;
}
@@ -332,9 +332,9 @@ public:
}
private:
void reallocate(uint32 new_cap)
void reallocate(uint32_t new_cap)
{
const uint32 cap = round_up_size(new_cap);
const uint32_t cap = round_up_size(new_cap);
byte *new_buf = MallocT<byte>(cap * sizeof(T));
byte *pos = new_buf;
for (T &item : *this) {
@@ -347,22 +347,22 @@ private:
this->data.reset(new_buf);
}
void *raw_ptr_at_pos(uint32 idx) const
void *raw_ptr_at_pos(uint32_t idx) const
{
return this->data.get() + (sizeof(T) * (idx & this->mask));
}
void *raw_ptr_at_offset(uint32 idx) const
void *raw_ptr_at_offset(uint32_t idx) const
{
return this->raw_ptr_at_pos(this->head + idx);
}
T *ptr_at_pos(uint32 idx) const
T *ptr_at_pos(uint32_t idx) const
{
return static_cast<T *>(this->raw_ptr_at_pos(idx));
}
T *ptr_at_offset(uint32 idx) const
T *ptr_at_offset(uint32_t idx) const
{
return static_cast<T *>(this->raw_ptr_at_offset(idx));
}
@@ -511,15 +511,15 @@ public:
}
private:
uint32 setup_insert(uint32 pos, uint32 num)
uint32_t setup_insert(uint32_t pos, uint32_t num)
{
if (this->count + num > (uint32)this->capacity()) {
if (this->count + num > (uint32_t)this->capacity()) {
/* grow container */
const uint32 cap = round_up_size(this->count + num);
const uint32_t cap = round_up_size(this->count + num);
byte *new_buf = MallocT<byte>(cap * sizeof(T));
byte *write_to = new_buf;
const uint32 end = this->head + this->count;
for (uint32 idx = this->head; idx != end; idx++) {
const uint32_t end = this->head + this->count;
for (uint32_t idx = this->head; idx != end; idx++) {
if (idx == pos) {
/* gap for inserted items */
write_to += num * sizeof(T);
@@ -529,7 +529,7 @@ private:
item.~T();
write_to += sizeof(T);
}
uint32 res = pos - this->head;
uint32_t res = pos - this->head;
this->mask = cap - 1;
this->head = 0;
this->count += num;
@@ -548,17 +548,17 @@ private:
/* middle, move data */
if (pos - this->head < (this->count / 2)) {
/* closer to the beginning, shuffle those backwards */
const uint32 new_head = this->head - num;
const uint32 insert_start = pos - num;
for (uint32 idx = new_head; idx != this->head; idx++) {
const uint32_t new_head = this->head - num;
const uint32_t insert_start = pos - num;
for (uint32_t idx = new_head; idx != this->head; idx++) {
/* Move construct to move backwards into uninitialised region */
new (this->raw_ptr_at_pos(idx)) T(std::move(*(this->ptr_at_pos(idx + num))));
}
for (uint32 idx = this->head; idx != insert_start; idx++) {
for (uint32_t idx = this->head; idx != insert_start; idx++) {
/* Move assign to move backwards in initialised region */
*this->ptr_at_pos(idx) = std::move(*this->ptr_at_pos(idx + num));
}
for (uint32 idx = insert_start; idx != pos; idx++) {
for (uint32_t idx = insert_start; idx != pos; idx++) {
/* Destruct to leave space for inserts */
this->ptr_at_pos(idx)->~T();
}
@@ -567,18 +567,18 @@ private:
return insert_start;
} else {
/* closer to the end, shuffle those forwards */
const uint32 last_inserted = pos + num - 1;
const uint32 last = this->head + this->count - 1;
const uint32 new_last = last + num;
for (uint32 idx = new_last; idx != last; idx--) {
const uint32_t last_inserted = pos + num - 1;
const uint32_t last = this->head + this->count - 1;
const uint32_t new_last = last + num;
for (uint32_t idx = new_last; idx != last; idx--) {
/* Move construct to move forwards into uninitialised region */
new (this->raw_ptr_at_pos(idx)) T(std::move(*(this->ptr_at_pos(idx - num))));
}
for (uint32 idx = last; idx != last_inserted; idx--) {
for (uint32_t idx = last; idx != last_inserted; idx--) {
/* Move assign to move forwards in initialised region */
*this->ptr_at_pos(idx) = std::move(*this->ptr_at_pos(idx - num));
}
for (uint32 idx = last_inserted; idx != pos; idx--) {
for (uint32_t idx = last_inserted; idx != pos; idx--) {
/* Destruct to leave space for inserts */
this->ptr_at_pos(idx)->~T();
}
@@ -594,7 +594,7 @@ public:
{
dbg_assert(pos.ring == this);
uint32 new_pos = this->setup_insert(pos.pos, 1);
uint32_t new_pos = this->setup_insert(pos.pos, 1);
new (this->raw_ptr_at_pos(new_pos)) T(std::forward<Args>(args)...);
return iterator(this, new_pos);
}
@@ -615,8 +615,8 @@ public:
dbg_assert(pos.ring == this);
const uint32 new_pos_start = this->setup_insert(pos.pos, (uint32)count);
uint32 new_pos = new_pos_start;
const uint32_t new_pos_start = this->setup_insert(pos.pos, (uint32_t)count);
uint32_t new_pos = new_pos_start;
for (size_t i = 0; i != count; i++) {
new (this->raw_ptr_at_pos(new_pos)) T(value);
++new_pos;
@@ -631,8 +631,8 @@ public:
dbg_assert(pos.ring == this);
const uint32 new_pos_start = this->setup_insert(pos.pos, (uint32)std::distance(first, last));
uint32 new_pos = new_pos_start;
const uint32_t new_pos_start = this->setup_insert(pos.pos, (uint32_t)std::distance(first, last));
uint32_t new_pos = new_pos_start;
for (auto iter = first; iter != last; ++iter) {
new (this->raw_ptr_at_pos(new_pos)) T(*iter);
++new_pos;
@@ -646,11 +646,11 @@ public:
}
private:
uint32 do_erase(uint32 pos, uint32 num)
uint32_t do_erase(uint32_t pos, uint32_t num)
{
if (pos == this->head) {
/* erase from beginning */
for (uint32 i = 0; i < num; i++) {
for (uint32_t i = 0; i < num; i++) {
this->ptr_at_pos(pos + i)->~T();
}
this->head += num;
@@ -658,19 +658,19 @@ private:
return this->head;
} else if (pos + num == this->head + this->count) {
/* erase from end */
for (uint32 i = 0; i < num; i++) {
for (uint32_t i = 0; i < num; i++) {
this->ptr_at_pos(pos + i)->~T();
}
this->count -= num;
return pos;
} else if (pos - this->head < this->head + this->count - (pos + num)) {
/* closer to the beginning, shuffle beginning forwards to fill gap */
const uint32 new_head = this->head + num;
const uint32 erase_end = pos + num;
for (uint32 idx = erase_end - 1; idx != new_head - 1; idx--) {
const uint32_t new_head = this->head + num;
const uint32_t erase_end = pos + num;
for (uint32_t idx = erase_end - 1; idx != new_head - 1; idx--) {
*this->ptr_at_pos(idx) = std::move(*this->ptr_at_pos(idx - num));
}
for (uint32 idx = new_head - 1; idx != this->head - 1; idx--) {
for (uint32_t idx = new_head - 1; idx != this->head - 1; idx--) {
this->ptr_at_pos(idx)->~T();
}
this->head = new_head;
@@ -678,12 +678,12 @@ private:
return pos + num;
} else {
/* closer to the end, shuffle end backwards to fill gap */
const uint32 current_end = this->head + this->count;
const uint32 new_end = current_end - num;
for (uint32 idx = pos; idx != new_end; idx++) {
const uint32_t current_end = this->head + this->count;
const uint32_t new_end = current_end - num;
for (uint32_t idx = pos; idx != new_end; idx++) {
*this->ptr_at_pos(idx) = std::move(*this->ptr_at_pos(idx + num));
}
for (uint32 idx = new_end; idx != current_end; idx++) {
for (uint32_t idx = new_end; idx != current_end; idx++) {
this->ptr_at_pos(idx)->~T();
}
this->count -= num;
@@ -712,24 +712,24 @@ public:
{
if (new_cap <= this->capacity()) return;
this->reallocate((uint32)new_cap);
this->reallocate((uint32_t)new_cap);
}
void resize(size_t new_size)
{
if (new_size < this->size()) {
for (uint32 i = (uint32)new_size; i != this->count; i++) {
for (uint32_t i = (uint32_t)new_size; i != this->count; i++) {
this->ptr_at_offset(i)->~T();
}
} else if (new_size > this->size()) {
if (new_size > this->capacity()) {
this->reallocate((uint32)new_size);
this->reallocate((uint32_t)new_size);
}
for (uint32 i = this->count; i != (uint32)new_size; i++) {
for (uint32_t i = this->count; i != (uint32_t)new_size; i++) {
new (this->raw_ptr_at_offset(i)) T();
}
}
this->count = (uint32)new_size;
this->count = (uint32_t)new_size;
}
void shrink_to_fit()
@@ -737,7 +737,7 @@ public:
if (this->empty()) {
this->clear();
this->data.reset();
this->mask = (uint32)-1;
this->mask = (uint32_t)-1;
} else if (round_up_size(this->count) < this->capacity()) {
this->reallocate(this->count);
}
@@ -745,12 +745,12 @@ public:
T &operator[](size_t index)
{
return *this->ptr_at_offset((uint32)index);
return *this->ptr_at_offset((uint32_t)index);
}
const T &operator[](size_t index) const
{
return *this->ptr_at_offset((uint32)index);
return *this->ptr_at_offset((uint32_t)index);
}
};

View File

@@ -23,13 +23,13 @@
/*
* The next couple of functions make sure we can send
* uint8, uint16, uint32 and uint64 endian-safe
* uint8_t, uint16_t, uint32_t and uint64_t endian-safe
* over the network. The least significant bytes are
* sent first.
*
* So 0x01234567 would be sent as 67 45 23 01.
*
* A bool is sent as a uint8 where zero means false
* A bool is sent as a uint8_t where zero means false
* and non-zero means true.
*/
@@ -46,7 +46,7 @@ void BufferSend_bool(std::vector<byte> &buffer, size_t limit, bool data)
* Package a 8 bits integer in the packet.
* @param data The data to send.
*/
void BufferSend_uint8(std::vector<byte> &buffer, size_t limit, uint8 data)
void BufferSend_uint8(std::vector<byte> &buffer, size_t limit, uint8_t data)
{
assert(BufferCanWriteToPacket(buffer, limit, sizeof(data)));
buffer.emplace_back(data);
@@ -56,12 +56,12 @@ void BufferSend_uint8(std::vector<byte> &buffer, size_t limit, uint8 data)
* Package a 16 bits integer in the packet.
* @param data The data to send.
*/
void BufferSend_uint16(std::vector<byte> &buffer, size_t limit, uint16 data)
void BufferSend_uint16(std::vector<byte> &buffer, size_t limit, uint16_t data)
{
assert(BufferCanWriteToPacket(buffer, limit, sizeof(data)));
buffer.insert(buffer.end(), {
(uint8)GB(data, 0, 8),
(uint8)GB(data, 8, 8),
(uint8_t)GB(data, 0, 8),
(uint8_t)GB(data, 8, 8),
});
}
@@ -69,14 +69,14 @@ void BufferSend_uint16(std::vector<byte> &buffer, size_t limit, uint16 data)
* Package a 32 bits integer in the packet.
* @param data The data to send.
*/
void BufferSend_uint32(std::vector<byte> &buffer, size_t limit, uint32 data)
void BufferSend_uint32(std::vector<byte> &buffer, size_t limit, uint32_t data)
{
assert(BufferCanWriteToPacket(buffer, limit, sizeof(data)));
buffer.insert(buffer.end(), {
(uint8)GB(data, 0, 8),
(uint8)GB(data, 8, 8),
(uint8)GB(data, 16, 8),
(uint8)GB(data, 24, 8),
(uint8_t)GB(data, 0, 8),
(uint8_t)GB(data, 8, 8),
(uint8_t)GB(data, 16, 8),
(uint8_t)GB(data, 24, 8),
});
}
@@ -84,18 +84,18 @@ void BufferSend_uint32(std::vector<byte> &buffer, size_t limit, uint32 data)
* Package a 64 bits integer in the packet.
* @param data The data to send.
*/
void BufferSend_uint64(std::vector<byte> &buffer, size_t limit, uint64 data)
void BufferSend_uint64(std::vector<byte> &buffer, size_t limit, uint64_t data)
{
assert(BufferCanWriteToPacket(buffer, limit, sizeof(data)));
buffer.insert(buffer.end(), {
(uint8)GB(data, 0, 8),
(uint8)GB(data, 8, 8),
(uint8)GB(data, 16, 8),
(uint8)GB(data, 24, 8),
(uint8)GB(data, 32, 8),
(uint8)GB(data, 40, 8),
(uint8)GB(data, 48, 8),
(uint8)GB(data, 56, 8),
(uint8_t)GB(data, 0, 8),
(uint8_t)GB(data, 8, 8),
(uint8_t)GB(data, 16, 8),
(uint8_t)GB(data, 24, 8),
(uint8_t)GB(data, 32, 8),
(uint8_t)GB(data, 40, 8),
(uint8_t)GB(data, 48, 8),
(uint8_t)GB(data, 56, 8),
});
}
@@ -147,8 +147,8 @@ void BufferSend_buffer(std::vector<byte> &buffer, size_t limit, const byte *data
assert(size <= UINT16_MAX);
assert(BufferCanWriteToPacket(buffer, limit, size + 2));
buffer.insert(buffer.end(), {
(uint8)GB(size, 0, 8),
(uint8)GB(size, 8, 8),
(uint8_t)GB(size, 0, 8),
(uint8_t)GB(size, 8, 8),
});
buffer.insert(buffer.end(), data, data + size);
}

View File

@@ -20,10 +20,10 @@
#include <limits>
void BufferSend_bool (std::vector<byte> &buffer, size_t limit, bool data);
void BufferSend_uint8 (std::vector<byte> &buffer, size_t limit, uint8 data);
void BufferSend_uint16(std::vector<byte> &buffer, size_t limit, uint16 data);
void BufferSend_uint32(std::vector<byte> &buffer, size_t limit, uint32 data);
void BufferSend_uint64(std::vector<byte> &buffer, size_t limit, uint64 data);
void BufferSend_uint8 (std::vector<byte> &buffer, size_t limit, uint8_t data);
void BufferSend_uint16(std::vector<byte> &buffer, size_t limit, uint16_t data);
void BufferSend_uint32(std::vector<byte> &buffer, size_t limit, uint32_t data);
void BufferSend_uint64(std::vector<byte> &buffer, size_t limit, uint64_t data);
void BufferSend_string(std::vector<byte> &buffer, size_t limit, const std::string_view data);
size_t BufferSend_binary_until_full(std::vector<byte> &buffer, size_t limit, const byte *begin, const byte *end);
void BufferSend_binary(std::vector<byte> &buffer, size_t limit, const byte *data, const size_t size);
@@ -37,25 +37,25 @@ struct BufferSerialisationHelper {
BufferSend_bool(self->GetSerialisationBuffer(), self->GetSerialisationLimit(), data);
}
void Send_uint8(uint8 data)
void Send_uint8(uint8_t data)
{
T *self = static_cast<T *>(this);
BufferSend_uint8(self->GetSerialisationBuffer(), self->GetSerialisationLimit(), data);
}
void Send_uint16(uint16 data)
void Send_uint16(uint16_t data)
{
T *self = static_cast<T *>(this);
BufferSend_uint16(self->GetSerialisationBuffer(), self->GetSerialisationLimit(), data);
}
void Send_uint32(uint32 data)
void Send_uint32(uint32_t data)
{
T *self = static_cast<T *>(this);
BufferSend_uint32(self->GetSerialisationBuffer(), self->GetSerialisationLimit(), data);
}
void Send_uint64(uint64 data)
void Send_uint64(uint64_t data)
{
T *self = static_cast<T *>(this);
BufferSend_uint64(self->GetSerialisationBuffer(), self->GetSerialisationLimit(), data);
@@ -130,9 +130,9 @@ public:
* Read a 8 bits integer from the packet.
* @return The read data.
*/
uint8 Recv_uint8()
uint8_t Recv_uint8()
{
uint8 n;
uint8_t n;
if (!this->CanRecvBytes(sizeof(n), true)) return 0;
@@ -146,16 +146,16 @@ public:
* Read a 16 bits integer from the packet.
* @return The read data.
*/
uint16 Recv_uint16()
uint16_t Recv_uint16()
{
uint16 n;
uint16_t n;
if (!this->CanRecvBytes(sizeof(n), true)) return 0;
auto &pos = static_cast<T *>(this)->GetDeserialisationPosition();
n = (uint16)this->GetBuffer()[pos++];
n += (uint16)this->GetBuffer()[pos++] << 8;
n = (uint16_t)this->GetBuffer()[pos++];
n += (uint16_t)this->GetBuffer()[pos++] << 8;
return n;
}
@@ -163,18 +163,18 @@ public:
* Read a 32 bits integer from the packet.
* @return The read data.
*/
uint32 Recv_uint32()
uint32_t Recv_uint32()
{
uint32 n;
uint32_t n;
if (!this->CanRecvBytes(sizeof(n), true)) return 0;
auto &pos = static_cast<T *>(this)->GetDeserialisationPosition();
n = (uint32)this->GetBuffer()[pos++];
n += (uint32)this->GetBuffer()[pos++] << 8;
n += (uint32)this->GetBuffer()[pos++] << 16;
n += (uint32)this->GetBuffer()[pos++] << 24;
n = (uint32_t)this->GetBuffer()[pos++];
n += (uint32_t)this->GetBuffer()[pos++] << 8;
n += (uint32_t)this->GetBuffer()[pos++] << 16;
n += (uint32_t)this->GetBuffer()[pos++] << 24;
return n;
}
@@ -182,22 +182,22 @@ public:
* Read a 64 bits integer from the packet.
* @return The read data.
*/
uint64 Recv_uint64()
uint64_t Recv_uint64()
{
uint64 n;
uint64_t n;
if (!this->CanRecvBytes(sizeof(n), true)) return 0;
auto &pos = static_cast<T *>(this)->GetDeserialisationPosition();
n = (uint64)this->GetBuffer()[pos++];
n += (uint64)this->GetBuffer()[pos++] << 8;
n += (uint64)this->GetBuffer()[pos++] << 16;
n += (uint64)this->GetBuffer()[pos++] << 24;
n += (uint64)this->GetBuffer()[pos++] << 32;
n += (uint64)this->GetBuffer()[pos++] << 40;
n += (uint64)this->GetBuffer()[pos++] << 48;
n += (uint64)this->GetBuffer()[pos++] << 56;
n = (uint64_t)this->GetBuffer()[pos++];
n += (uint64_t)this->GetBuffer()[pos++] << 8;
n += (uint64_t)this->GetBuffer()[pos++] << 16;
n += (uint64_t)this->GetBuffer()[pos++] << 24;
n += (uint64_t)this->GetBuffer()[pos++] << 32;
n += (uint64_t)this->GetBuffer()[pos++] << 40;
n += (uint64_t)this->GetBuffer()[pos++] << 48;
n += (uint64_t)this->GetBuffer()[pos++] << 56;
return n;
}
@@ -269,13 +269,13 @@ public:
* @param size The size of the data.
* @return The view of the data.
*/
span<const uint8> Recv_binary_view(size_t size)
span<const uint8_t> Recv_binary_view(size_t size)
{
if (!this->CanRecvBytes(size, true)) return {};
auto &pos = static_cast<T *>(this)->GetDeserialisationPosition();
span<const uint8> view { &this->GetBuffer()[pos], size };
span<const uint8_t> view { &this->GetBuffer()[pos], size };
pos += (decltype(pos)) size;
return view;
@@ -286,9 +286,9 @@ public:
* @param size The size of the data.
* @return The binary buffer.
*/
std::vector<uint8> Recv_binary(size_t size)
std::vector<uint8_t> Recv_binary(size_t size)
{
span<const uint8> view = this->Recv_binary_view(size);
span<const uint8_t> view = this->Recv_binary_view(size);
return { view.begin(), view.end() };
}
@@ -297,14 +297,14 @@ public:
* Returns a view of a length-prefixed binary buffer from the packet.
* @return The binary buffer.
*/
span<const uint8> Recv_buffer_view()
span<const uint8_t> Recv_buffer_view()
{
uint16 length = this->Recv_uint16();
uint16_t length = this->Recv_uint16();
if (!this->CanRecvBytes(length, true)) return {};
auto &pos = static_cast<T *>(this)->GetDeserialisationPosition();
span<const uint8> buffer { &this->GetBuffer()[pos], length };
span<const uint8_t> buffer { &this->GetBuffer()[pos], length };
pos += length;
return buffer;
@@ -314,9 +314,9 @@ public:
* Reads a length-prefixed binary buffer from the packet.
* @return The binary buffer.
*/
std::vector<uint8> Recv_buffer()
std::vector<uint8_t> Recv_buffer()
{
span<const uint8> view = this->Recv_buffer_view();
span<const uint8_t> view = this->Recv_buffer_view();
return { view.begin(), view.end() };
}