Update to 1.11.0-beta1

This commit is contained in:
dP
2021-01-23 17:31:11 +03:00
parent d3c06c25c8
commit 5e4506f493
1045 changed files with 23534 additions and 60345 deletions

30
src/core/CMakeLists.txt Normal file
View File

@@ -0,0 +1,30 @@
add_files(
alloc_func.cpp
alloc_func.hpp
alloc_type.hpp
backup_type.hpp
bitmath_func.cpp
bitmath_func.hpp
endian_func.hpp
endian_type.hpp
enum_type.hpp
geometry_func.cpp
geometry_func.hpp
geometry_type.hpp
kdtree.hpp
math_func.cpp
math_func.hpp
mem_func.hpp
multimap.hpp
overflowsafe_type.hpp
pool_func.cpp
pool_func.hpp
pool_type.hpp
random_func.cpp
random_func.hpp
smallmap_type.hpp
smallmatrix_type.hpp
smallstack_type.hpp
smallvec_type.hpp
string_compare_type.hpp
)

View File

@@ -15,27 +15,27 @@
/* Setup alignment and conversion macros */
#if TTD_ENDIAN == TTD_BIG_ENDIAN
#define FROM_BE16(x) (x)
#define FROM_BE32(x) (x)
#define TO_BE16(x) (x)
#define TO_BE32(x) (x)
#define TO_BE32X(x) (x)
#define FROM_LE16(x) BSWAP16(x)
#define FROM_LE32(x) BSWAP32(x)
#define TO_LE16(x) BSWAP16(x)
#define TO_LE32(x) BSWAP32(x)
#define TO_LE32X(x) BSWAP32(x)
# define FROM_BE16(x) (x)
# define FROM_BE32(x) (x)
# define TO_BE16(x) (x)
# define TO_BE32(x) (x)
# define TO_BE32X(x) (x)
# define FROM_LE16(x) BSWAP16(x)
# define FROM_LE32(x) BSWAP32(x)
# define TO_LE16(x) BSWAP16(x)
# define TO_LE32(x) BSWAP32(x)
# define TO_LE32X(x) BSWAP32(x)
#else
#define FROM_BE16(x) BSWAP16(x)
#define FROM_BE32(x) BSWAP32(x)
#define TO_BE16(x) BSWAP16(x)
#define TO_BE32(x) BSWAP32(x)
#define TO_BE32X(x) BSWAP32(x)
#define FROM_LE16(x) (x)
#define FROM_LE32(x) (x)
#define TO_LE16(x) (x)
#define TO_LE32(x) (x)
#define TO_LE32X(x) (x)
# define FROM_BE16(x) BSWAP16(x)
# define FROM_BE32(x) BSWAP32(x)
# define TO_BE16(x) BSWAP16(x)
# define TO_BE32(x) BSWAP32(x)
# define TO_BE32X(x) BSWAP32(x)
# define FROM_LE16(x) (x)
# define FROM_LE32(x) (x)
# define TO_LE16(x) (x)
# define TO_LE32(x) (x)
# define TO_LE32X(x) (x)
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
static inline uint16 ReadLE16Aligned(const void *x)

View File

@@ -12,10 +12,10 @@
#if defined(ARM) || defined(__arm__) || defined(__alpha__)
/** The architecture requires aligned access. */
#define OTTD_ALIGNMENT 1
# define OTTD_ALIGNMENT 1
#else
/** The architecture does not require aligned access. */
#define OTTD_ALIGNMENT 0
# define OTTD_ALIGNMENT 0
#endif
/** Little endian builds use this for TTD_ENDIAN. */
@@ -23,30 +23,8 @@
/** Big endian builds use this for TTD_ENDIAN. */
#define TTD_BIG_ENDIAN 1
/* Windows has always LITTLE_ENDIAN */
#if defined(_WIN32) || defined(__OS2__) || defined(__HAIKU__)
# define TTD_ENDIAN TTD_LITTLE_ENDIAN
#elif defined(OSX)
# include <sys/types.h>
# if __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN
# define TTD_ENDIAN TTD_LITTLE_ENDIAN
# else
# define TTD_ENDIAN TTD_BIG_ENDIAN
# endif
#elif defined(__OpenBSD__)
# include <endian.h>
# if BYTE_ORDER == LITTLE_ENDIAN
# define TTD_ENDIAN TTD_LITTLE_ENDIAN
# else
# define TTD_ENDIAN TTD_BIG_ENDIAN
# endif
#elif !defined(TESTING)
# include <sys/param.h>
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define TTD_ENDIAN TTD_LITTLE_ENDIAN
# else
# define TTD_ENDIAN TTD_BIG_ENDIAN
# endif
#endif /* _WIN32 || __OS2__ */
#if !defined(TTD_ENDIAN)
# error "TTD_ENDIAN is not defined; please set it to either TTD_LITTLE_ENDIAN or TTD_BIG_ENDIAN"
#endif /* !TTD_ENDIAN */
#endif /* ENDIAN_TYPE_HPP */

View File

@@ -22,7 +22,7 @@
Dimension maxdim(const Dimension &d1, const Dimension &d2)
{
Dimension d;
d.width = max(d1.width, d2.width);
d.height = max(d1.height, d2.height);
d.width = std::max(d1.width, d2.width);
d.height = std::max(d1.height, d2.height);
return d;
}

View File

@@ -12,8 +12,8 @@
#if defined(__APPLE__)
/* Mac OS X already has both Rect and Point declared */
#define Rect OTTD_Rect
#define Point OTTD_Point
# define Rect OTTD_Rect
# define Point OTTD_Point
#endif /* __APPLE__ */

View File

@@ -12,7 +12,6 @@
#include "../stdafx.h"
#include <vector>
#include <algorithm>
#include <limits>
/**
@@ -261,7 +260,7 @@ class Kdtree {
best = SelectNearestNodeDistance(best, this->FindNearestRecursive(xy, next, level + 1));
}
limit = min(best.second, limit);
limit = std::min(best.second, limit);
/* Check if the distance from current best is worse than distance from target to splitting line,
* if it is we also need to check the other side of the split. */

View File

@@ -10,66 +10,6 @@
#ifndef MATH_FUNC_HPP
#define MATH_FUNC_HPP
/**
* Returns the maximum of two values.
*
* This function returns the greater value of two given values.
* If they are equal the value of a is returned.
*
* @param a The first value
* @param b The second value
* @return The greater value or a if equals
*/
template <typename T>
static inline T max(const T a, const T b)
{
return (a >= b) ? a : b;
}
/**
* Returns the minimum of two values.
*
* This function returns the smaller value of two given values.
* If they are equal the value of b is returned.
*
* @param a The first value
* @param b The second value
* @return The smaller value or b if equals
*/
template <typename T>
static inline T min(const T a, const T b)
{
return (a < b) ? a : b;
}
/**
* Returns the minimum of two integer.
*
* This function returns the smaller value of two given integers.
*
* @param a The first integer
* @param b The second integer
* @return The smaller value
*/
static inline int min(const int a, const int b)
{
return min<int>(a, b);
}
/**
* Returns the minimum of two unsigned integers.
*
* This function returns the smaller value of two given unsigned integers.
*
* @param a The first unsigned integer
* @param b The second unsigned integer
* @return The smaller value
*/
static inline uint minu(const uint a, const uint b)
{
return min<uint>(a, b);
}
/**
* Returns the absolute value of (scalar) variable.
*
@@ -112,7 +52,7 @@ static inline T Align(const T x, uint n)
template <typename T>
static inline T *AlignPtr(T *x, uint n)
{
assert_compile(sizeof(size_t) == sizeof(void *));
static_assert(sizeof(size_t) == sizeof(void *));
return reinterpret_cast<T *>(Align((size_t)x, n));
}
@@ -216,7 +156,7 @@ static inline uint16 ClampToU16(const uint64 a)
* match for min(uint64, uint) than uint64 min(uint64, uint64). As such we
* need to cast the UINT16_MAX to prevent MSVC from displaying its
* infinite loads of warnings. */
return static_cast<uint16>(min<uint64>(a, static_cast<uint64>(UINT16_MAX)));
return static_cast<uint16>(std::min(a, static_cast<uint64>(UINT16_MAX)));
}
/**

View File

@@ -52,7 +52,7 @@ DEFINE_POOL_METHOD(inline void)::ResizeFor(size_t index)
assert(index >= this->size);
assert(index < Tmax_size);
size_t new_size = min(Tmax_size, Align(index + 1, Tgrowth_step));
size_t new_size = std::min(Tmax_size, Align(index + 1, Tgrowth_step));
this->data = ReallocT(this->data, new_size);
MemSetT(this->data + this->size, 0, new_size - this->size);
@@ -100,7 +100,7 @@ DEFINE_POOL_METHOD(inline void *)::AllocateItem(size_t size, size_t index)
{
assert(this->data[index] == nullptr);
this->first_unused = max(this->first_unused, index + 1);
this->first_unused = std::max(this->first_unused, index + 1);
this->items++;
Titem *item;
@@ -187,7 +187,7 @@ DEFINE_POOL_METHOD(void)::FreeItem(size_t index)
free(this->data[index]);
}
this->data[index] = nullptr;
this->first_free = min(this->first_free, index);
this->first_free = std::min(this->first_free, index);
this->items--;
if (!this->cleaning) Titem::PostDestructor(index);
}

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. */
assert_compile((uint64)(Tmax_size - 1) >> 8 * sizeof(Tindex) == 0);
static_assert((uint64)(Tmax_size - 1) >> 8 * sizeof(Tindex) == 0);
static const size_t MAX_SIZE = Tmax_size; ///< Make template parameter accessible from outside

View File

@@ -12,7 +12,7 @@
#if defined(__APPLE__)
/* Apple already has Random declared */
#define Random OTTD_Random
# define Random OTTD_Random
#endif /* __APPLE__ */
/**
@@ -57,13 +57,13 @@ static inline void RestoreRandomSeeds(const SavedRandomSeeds &storage)
void SetRandomSeed(uint32 seed);
#ifdef RANDOM_DEBUG
#ifdef __APPLE__
#define OTTD_Random() DoRandom(__LINE__, __FILE__)
#else
#define Random() DoRandom(__LINE__, __FILE__)
#endif
# ifdef __APPLE__
# define OTTD_Random() DoRandom(__LINE__, __FILE__)
# else
# define Random() DoRandom(__LINE__, __FILE__)
# endif
uint32 DoRandom(int line, const char *file);
#define RandomRange(limit) DoRandomRange(limit, __LINE__, __FILE__)
# define RandomRange(limit) DoRandomRange(limit, __LINE__, __FILE__)
uint32 DoRandomRange(uint32 limit, int line, const char *file);
#else
static inline uint32 Random()
@@ -126,7 +126,7 @@ static inline bool Chance16I(const uint a, const uint b, const uint32 r)
* @return True with (a/b) probability
*/
#ifdef RANDOM_DEBUG
#define Chance16(a, b) Chance16I(a, b, DoRandom(__LINE__, __FILE__))
# define Chance16(a, b) Chance16I(a, b, DoRandom(__LINE__, __FILE__))
#else
static inline bool Chance16(const uint a, const uint b)
{
@@ -150,7 +150,7 @@ static inline bool Chance16(const uint a, const uint b)
* @return True in (a/b) percent
*/
#ifdef RANDOM_DEBUG
#define Chance16R(a, b, r) (r = DoRandom(__LINE__, __FILE__), Chance16I(a, b, r))
# define Chance16R(a, b, r) (r = DoRandom(__LINE__, __FILE__), Chance16I(a, b, r))
#else
static inline bool Chance16R(const uint a, const uint b, uint32 &r)
{

View File

@@ -11,40 +11,26 @@
#define SMALLMAP_TYPE_HPP
#include "smallvec_type.hpp"
#include <utility>
/**
* Simple pair of data. Both types have to be POD ("Plain Old Data")!
* @tparam T Key type.
* @tparam U Value type.
*/
template <typename T, typename U>
struct SmallPair {
T first;
U second;
/** Initializes this Pair with data */
inline SmallPair(const T &first, const U &second) : first(first), second(second) { }
SmallPair() = default;
};
/**
* Implementation of simple mapping class. Both types have to be POD ("Plain Old Data")!
* It has inherited accessors from SmallVector().
* Implementation of simple mapping class.
* It has inherited accessors from std::vector().
* @tparam T Key type.
* @tparam U Value type.
* @tparam S Unit of allocation.
*
* @see SmallVector
* @see std::vector
*/
template <typename T, typename U>
struct SmallMap : std::vector<SmallPair<T, U> > {
typedef ::SmallPair<T, U> Pair;
struct SmallMap : std::vector<std::pair<T, U> > {
typedef std::pair<T, U> Pair;
typedef Pair *iterator;
typedef const Pair *const_iterator;
/** Creates new SmallMap. Data are initialized in SmallVector constructor */
/** Creates new SmallMap. Data are initialized in std::vector constructor */
inline SmallMap() { }
/** Data are freed in SmallVector destructor */
/** Data are freed in std::vector destructor */
inline ~SmallMap() { }
/**
@@ -156,8 +142,7 @@ struct SmallMap : std::vector<SmallPair<T, U> > {
for (uint i = 0; i < std::vector<Pair>::size(); i++) {
if (key == std::vector<Pair>::operator[](i).first) return std::vector<Pair>::operator[](i).second;
}
/*C++17: Pair &n = */ std::vector<Pair>::emplace_back();
Pair &n = std::vector<Pair>::back();
Pair &n = std::vector<Pair>::emplace_back();
n.first = key;
return n.second;
}

View File

@@ -234,7 +234,7 @@ public:
if (x * new_height > new_capacity) continue;
(*copy)(new_data + (x - 1) * new_height,
this->data + (x - 1) * this->height,
min(this->height, new_height));
std::min(this->height, new_height));
}
} else {
/* If matrix is shrinking copy from the front. */
@@ -242,7 +242,7 @@ public:
if ((x + 1) * new_height > new_capacity) break;
(*copy)(new_data + x * new_height,
this->data + x * this->height,
min(this->height, new_height));
std::min(this->height, new_height));
}
}
}

View File

@@ -46,7 +46,7 @@ public:
if (index < Tmax_size) {
this->data[index].valid = true;
this->first_free = index + 1;
this->first_unused = max(this->first_unused, this->first_free);
this->first_unused = std::max(this->first_unused, this->first_free);
}
return index;
}
@@ -58,7 +58,7 @@ public:
inline void Destroy(Tindex index)
{
this->data[index].valid = false;
this->first_free = min(this->first_free, index);
this->first_free = std::min(this->first_free, index);
}
private:

View File

@@ -13,7 +13,6 @@
#include "alloc_func.hpp"
#include "mem_func.hpp"
#include <vector>
#include <algorithm>
/**
* Helper function to append an item to a vector if it is not already contained