26 #define GRID_BOUNDS_DEBUG 0 28 #define GRID_BOUNDS_DEBUG 1 47 template <
typename U,
typename =
int>
struct has_value_type : std::false_type { };
48 template <
typename U>
struct has_value_type <U, decltype(
std::declval<typename U::value_type>(), 0)> : std::true_type { };
50 template <
typename U,
typename A,
typename B>
using if_ =
typename std::conditional<U::value, A, B>::type;
128 return m_W == 0 &&
m_H == 0;
137 static_assert(!std::is_same<T, T>::value,
"Not implemented.");
142 #if GRID_BOUNDS_DEBUG 145 for (
int j = j0; j < j1; ++j)
148 for (
int i = i0; i < i1; ++i)
194 #if GRID_BOUNDS_DEBUG 197 for (
int i=0; i <
m_H*
m_W; ++i)
206 #if GRID_BOUNDS_DEBUG 209 for (
int i = 0; i <
m_H*
m_W; ++i)
213 void set(
int i,
int j,
const T& value)
215 #if GRID_BOUNDS_DEBUG 221 T&
operator[](std::pair<u16, u16> coords) {
return get(coords.first, coords.second); }
222 T&
get(std::pair<u16, u16> coords) {
return get(coords.first, coords.second); }
224 T&
operator[](std::pair<u16, u16> coords)
const {
return get(coords.first, coords.second); }
225 T&
get(std::pair<u16, u16> coords)
const {
return get(coords.first, coords.second); }
229 #if GRID_BOUNDS_DEBUG 235 T&
get(
int i,
int j)
const 237 #if GRID_BOUNDS_DEBUG 262 size_t len = value.
m_H * value.
m_W;
269 for (
size_t i = 1; i < len; ++i)
271 if (prevVal == value.
m_Data[i])
279 prevVal = value.
m_Data[i];
292 for (
size_t i = 0; i < len;)
298 std::fill(&value.
m_Data[i], &value.
m_Data[i+count], el);
314 enum { BucketBits = 4, BucketSize = 1 << BucketBits };
318 size_t b = (j >> BucketBits) * m_BW + (i >> BucketBits);
321 m_Data[b] =
new T[BucketSize*BucketSize]();
331 m_BW = (
u16)((
m_W + BucketSize-1) >> BucketBits);
332 m_BH = (
u16)((
m_H + BucketSize-1) >> BucketBits);
345 for (
size_t i = 0; i < (size_t)(m_BW*m_BH); ++i)
352 void set(
int i,
int j,
const T& value)
354 #if GRID_BOUNDS_DEBUG 357 GetBucket(i, j)[(j % BucketSize)*BucketSize + (i % BucketSize)] = value;
362 #if GRID_BOUNDS_DEBUG 365 return GetBucket(i, j)[(j % BucketSize)*BucketSize + (i % BucketSize)];
392 bool wasDirty = dirty;
401 else if (dirty && !globallyDirty)
413 globallyDirty =
false;
414 dirtinessGrid.
reset();
418 #endif // INCLUDED_GRID void swap(Grid &g)
Definition: Grid.h:101
#define NONCOPYABLE(className)
Indicates that a class is noncopyable (usually due to const or reference members, or because the clas...
Definition: code_annotation.h:227
void clear()
Definition: Grid.h:172
bool operator==(const Grid &g) const
Definition: Grid.h:117
Grid & operator=(const Grid &g)
Definition: Grid.h:79
Helper templates definitions for serializing/deserializing common objects.
T & operator[](std::pair< u16, u16 > coords)
Definition: Grid.h:221
Similar to Grid, except optimised for sparse usage (the grid is subdivided into buckets whose content...
Definition: Grid.h:310
Grid()
Definition: Grid.h:58
bool blank() const
Definition: Grid.h:126
T & operator[](std::pair< u16, u16 > coords) const
Definition: Grid.h:224
uint16_t u16
Definition: types.h:38
void operator()(ISerializer &serialize, const char *name, Grid< T > &value)
Definition: Grid.h:260
bool operator!=(const Grid &g) const
Definition: Grid.h:124
Serialization interface; see serialization overview.
Definition: ISerializer.h:120
u16 height() const
Definition: Grid.h:132
u16 m_H
Definition: Grid.h:249
void Serializer(S &serialize, const char *name, Args &&... args)
Definition: SerializeTemplates.h:51
Grid(u16 w, u16 h)
Definition: Grid.h:62
virtual void NumberU32_Unbounded(const char *name, uint32_t &out)
Definition: IDeserializer.cpp:124
bool compare_sizes(const Grid< U > *g) const
Definition: Grid.h:244
Definition: ShaderDefines.cpp:30
Basic 2D array, intended for storing tile data, plus support for lazy updates by ICmpObstructionManag...
Definition: TerritoryBoundary.h:27
typename std::conditional< U::value, A, B >::type if_
Definition: Grid.h:50
void reset_data(default_type)
Definition: Grid.h:161
bool _any_set_in_square(int i0, int j0, int i1, int j1, is_pod) const
Definition: Grid.h:140
void reset_data(is_pod)
Definition: Grid.h:162
void reset()
Definition: Grid.h:343
u16 width() const
Definition: Grid.h:131
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
Definition: debug.h:290
uint32_t u32
Definition: types.h:39
SparseGrid(u16 w, u16 h)
Definition: Grid.h:327
void bitwise_or(const Grid &g)
Definition: Grid.h:201
bool _any_set_in_square(int, int, int, int, default_type) const
Definition: Grid.h:135
void reset()
Definition: Grid.h:165
void resize(u16 w, u16 h)
Definition: Grid.h:177
~Grid()
Definition: Grid.h:108
~SparseGrid()
Definition: Grid.h:337
#define T(string_literal)
Definition: secure_crt.cpp:77
void add(const Grid &g)
Definition: Grid.h:192
void NumberU32_Unbounded(const char *name, uint32_t value)
Serialize a number.
Definition: ISerializer.h:171
void copy_data(T *o, default_type)
Definition: Grid.h:76
Definition: SerializeTemplates.h:41
u16 m_W
Definition: Grid.h:368
bool compare_data(T *o, default_type) const
Definition: Grid.h:114
if_< std::is_pod< U >, is_pod, if_< has_value_type< U >, is_container, default_type > > dispatch
Definition: Grid.h:55
bool any_set_in_square(int i0, int j0, int i1, int j1) const
Definition: Grid.h:156
T * m_Data
Definition: Grid.h:250
T ** m_Data
Definition: Grid.h:370
bool compare_data(T *o, is_pod) const
Definition: Grid.h:115
#define SAFE_ARRAY_DELETE(p)
delete memory ensuing from new[] and set the pointer to zero (thus making double-frees safe / a no-op...
Definition: code_generation.h:121
u16 m_W
Definition: Grid.h:249
void operator()(IDeserializer &deserialize, const char *name, Grid< T > &value)
Definition: Grid.h:285
u16 value_type
Definition: Grid.h:72
void copy_data(T *o, is_pod)
Definition: Grid.h:77
void NumberU16_Unbounded(const char *name, uint16_t value)
Serialize a number.
Definition: ISerializer.h:161
size_t m_DirtyID
Definition: Grid.h:372
Grid(const Grid &g)
Definition: Grid.h:67
u16 m_BW
Definition: Grid.h:369
virtual void NumberU16_Unbounded(const char *name, uint16_t &out)
Definition: IDeserializer.cpp:110
T * GetBucket(int i, int j)
Definition: Grid.h:316
Deserialization interface; see serialization overview.
Definition: IDeserializer.h:34