@@ -26,26 +26,26 @@ public: | |||
const String& GetName() const { return m_name; } | |||
/** Gets the index of the corresponding key, needed to call GetKey */ | |||
int GetKeyIndex(const char* name) const { return GetItemIndex(name, m_keynames); } | |||
ptrdiff_t GetKeyIndex(const char* name) const { return GetItemIndex(name, m_keynames); } | |||
/** Gets the index of the corresponding axis, needed to call GetAxis */ | |||
int GetAxisIndex(const char* name) const { return GetItemIndex(name, m_axisnames); } | |||
ptrdiff_t GetAxisIndex(const char* name) const { return GetItemIndex(name, m_axisnames); } | |||
/** Gets the index of the corresponding cursor, needed to call GetCursor */ | |||
int GetCursorIndex(const char* name) const { return GetItemIndex(name, m_cursornames); } | |||
ptrdiff_t GetCursorIndex(const char* name) const { return GetItemIndex(name, m_cursornames); } | |||
/** Gets the current state of the given key, true being pressed and false being released */ | |||
bool GetKey(int index) const { return m_keys[index]; } | |||
bool GetKey(ptrdiff_t index) const { return m_keys[index]; } | |||
/** Gets the current value of the given axis. Devices should cap this value between -1 and 1 as much as possible, through it is not guaranteed */ | |||
float GetAxis(int index) const { return m_axis[index].m1 * m_axis[index].m2; } | |||
float GetAxis(ptrdiff_t index) const { return m_axis[index].m1 * m_axis[index].m2; } | |||
/** Gets the current value of the given cursor, 0,0 being the bottom-left corner and 1,1 being the top-right corner */ | |||
vec2 GetCursor(int index) const { return m_cursors[index].m1; } | |||
vec2 GetCursor(ptrdiff_t index) const { return m_cursors[index].m1; } | |||
/** Gets the coordinate of the pixel the cursor is currently over, 0,0 being the bottom-left corner. */ | |||
ivec2 GetCursorPixel(int index) const { return m_cursors[index].m2; } | |||
ivec2 GetCursorPixel(ptrdiff_t index) const { return m_cursors[index].m2; } | |||
/** Sets a per-device-axis sensitivity factor. The value returned by the operating system will be multiplied by this value before being returned by GetAxis */ | |||
void SetAxisSensitivity(int index, float sensitivity) { m_axis[index].m2 = sensitivity; } | |||
void SetAxisSensitivity(ptrdiff_t index, float sensitivity) { m_axis[index].m2 = sensitivity; } | |||
/** Gets the per-device-axis sensitivity factor. The value returned by the operating system will be multiplied by this value before being returned by GetAxis */ | |||
float GetAxisSensitivity(int index) const { return m_axis[index].m2; } | |||
float GetAxisSensitivity(ptrdiff_t index) const { return m_axis[index].m2; } | |||
/** Gets a list of the name of all available keys in this device */ | |||
const array<String>& GetAllKeys() const { return m_keynames; } | |||
@@ -86,7 +86,7 @@ protected: | |||
~InputDevice() | |||
{ | |||
for (int i = 0; i < devices.Count(); ++i) | |||
for (ptrdiff_t i = 0; i < devices.Count(); ++i) | |||
{ | |||
if (devices[i] == this) | |||
{ | |||
@@ -100,9 +100,9 @@ private: | |||
static array<InputDevice*> devices; | |||
template <typename... T> | |||
int GetItemIndex(const char* name, const array<String, T...>& array) const | |||
ptrdiff_t GetItemIndex(const char* name, const array<String, T...>& array) const | |||
{ | |||
for (int i = 0; i < array.Count(); ++i) | |||
for (ptrdiff_t i = 0; i < array.Count(); ++i) | |||
{ | |||
if (array[i] == name) | |||
return i; | |||
@@ -112,7 +112,7 @@ private: | |||
static InputDevice* GetDevice(const char* name) | |||
{ | |||
for (int i = 0; i < devices.Count(); ++i) | |||
for (ptrdiff_t i = 0; i < devices.Count(); ++i) | |||
{ | |||
if (devices[i]->m_name == name) | |||
return devices[i]; | |||
@@ -25,7 +25,7 @@ void array_base<T, ARRAY>::Sort(int sort) | |||
if (s++ == sort) | |||
{ | |||
int d = 1; | |||
for (int i = 0; i < Count() - 1; i = lol::max(i + d, 0)) | |||
for (ptrdiff_t i = 0; i < Count() - 1; i = lol::max(i + d, (ptrdiff_t)0)) | |||
{ | |||
if (i <= 0 || m_data[i] < m_data[i + 1]) | |||
d = 1; | |||
@@ -44,9 +44,9 @@ void array_base<T, ARRAY>::Sort(int sort) | |||
} | |||
template<typename T, typename ARRAY> | |||
void array_base<T, ARRAY>::SortQuickSwap(int start, int stop) | |||
void array_base<T, ARRAY>::SortQuickSwap(ptrdiff_t start, ptrdiff_t stop) | |||
{ | |||
int m[3] = | |||
ptrdiff_t m[3] = | |||
{ | |||
rand(start, stop), | |||
rand(start, stop), | |||
@@ -57,7 +57,7 @@ void array_base<T, ARRAY>::SortQuickSwap(int start, int stop) | |||
{ | |||
if (m_data[m[i+1]] < m_data[m[i]]) | |||
{ | |||
int mt = m[i+1]; | |||
ptrdiff_t mt = m[i+1]; | |||
m[i+1] = m[i]; | |||
m[i] = mt; | |||
i = 0; | |||
@@ -67,8 +67,8 @@ void array_base<T, ARRAY>::SortQuickSwap(int start, int stop) | |||
} | |||
//actual stuff | |||
T median = m_data[m[1]]; | |||
int i0 = start; | |||
int i1 = stop - 1; | |||
ptrdiff_t i0 = start; | |||
ptrdiff_t i1 = stop - 1; | |||
bool swap = false; | |||
while (i0 < i1) | |||
{ | |||
@@ -29,7 +29,7 @@ | |||
namespace lol | |||
{ | |||
#define INDEX_NONE -1 | |||
static ptrdiff_t const INDEX_NONE = -1; | |||
/* | |||
* The base array type. | |||
@@ -52,14 +52,14 @@ public: | |||
m_count(0), | |||
m_reserved(0) | |||
{ | |||
Reserve((int)list.size()); | |||
Reserve(list.size()); | |||
for (auto elem : list) | |||
Push(elem); | |||
} | |||
inline ~array_base() | |||
{ | |||
for (int i = 0; i < m_count; i++) | |||
for (ptrdiff_t i = 0; i < m_count; i++) | |||
m_data[i].~element_t(); | |||
delete[] reinterpret_cast<uint8_t *>(m_data); | |||
} | |||
@@ -69,7 +69,7 @@ public: | |||
/* Reserve the exact number of values instead of what the other | |||
* array had reserved. Just a method for not wasting too much. */ | |||
Reserve(that.m_count); | |||
for (int i = 0; i < that.m_count; i++) | |||
for (ptrdiff_t i = 0; i < that.m_count; i++) | |||
new(&m_data[i]) element_t(that[i]); | |||
m_count = that.m_count; | |||
} | |||
@@ -87,9 +87,9 @@ public: | |||
* elements, then use placement new directly for the | |||
* remaining elements. */ | |||
Reserve(that.m_count); | |||
for (int i = 0; i < m_count && i < that.m_count; i++) | |||
for (ptrdiff_t i = 0; i < m_count && i < that.m_count; i++) | |||
m_data[i] = element_t(that[i]); | |||
for (int i = m_count; i < that.m_count; i++) | |||
for (ptrdiff_t i = m_count; i < that.m_count; i++) | |||
new(&m_data[i]) element_t(that[i]); | |||
} | |||
else | |||
@@ -98,11 +98,11 @@ public: | |||
* use placement new for the elements in the other array | |||
* that we do not have, and finally destroy the remaining | |||
* elements. */ | |||
for (int i = 0; i < m_count && i < that.m_count; i++) | |||
for (ptrdiff_t i = 0; i < m_count && i < that.m_count; i++) | |||
m_data[i] = element_t(that[i]); | |||
for (int i = m_count; i < that.m_count; i++) | |||
for (ptrdiff_t i = m_count; i < that.m_count; i++) | |||
new(&m_data[i]) element_t(that[i]); | |||
for (int i = that.m_count; i < m_count; i++) | |||
for (ptrdiff_t i = that.m_count; i < m_count; i++) | |||
m_data[i].~element_t(); | |||
} | |||
m_count = that.m_count; | |||
@@ -112,9 +112,9 @@ public: | |||
array_base& operator+=(array_base const &that) | |||
{ | |||
int todo = that.m_count; | |||
ptrdiff_t todo = that.m_count; | |||
Reserve(m_count + todo); | |||
for (int i = 0; i < todo; i++) | |||
for (ptrdiff_t i = 0; i < todo; i++) | |||
new(&m_data[m_count + i]) element_t(that[i]); | |||
m_count += todo; | |||
return *this; | |||
@@ -129,16 +129,16 @@ public: | |||
return ret; | |||
} | |||
inline element_t& operator[](int n) | |||
inline element_t& operator[](ptrdiff_t n) | |||
{ | |||
/* Allow array[0] even if size is zero so that people can | |||
* always use &array[0] to get a pointer to the data. */ | |||
ASSERT(n >= 0); | |||
ASSERT((unsigned)n < (unsigned)m_count || (!n && !m_count)); | |||
ASSERT(n < m_count || (!n && !m_count)); | |||
return m_data[n]; | |||
} | |||
inline element_t const& operator[](int n) const | |||
inline element_t const& operator[](ptrdiff_t n) const | |||
{ | |||
ASSERT(n >= 0); | |||
ASSERT(n < m_count || (!n && !m_count)); | |||
@@ -203,7 +203,7 @@ public: | |||
return true; | |||
} | |||
inline void Insert(T const &x, int pos) | |||
inline void Insert(T const &x, ptrdiff_t pos) | |||
{ | |||
ASSERT(pos >= 0); | |||
ASSERT(pos <= m_count); | |||
@@ -211,7 +211,7 @@ public: | |||
if (m_count >= m_reserved) | |||
Grow(); | |||
for (int i = m_count; i > pos; --i) | |||
for (ptrdiff_t i = m_count; i > pos; --i) | |||
{ | |||
new (&m_data[i]) element_t(m_data[i - 1]); | |||
m_data[i - 1].~element_t(); | |||
@@ -220,7 +220,7 @@ public: | |||
++m_count; | |||
} | |||
inline bool InsertUnique(T const &x, int pos) | |||
inline bool InsertUnique(T const &x, ptrdiff_t pos) | |||
{ | |||
ASSERT(pos >= 0); | |||
ASSERT(pos <= m_count); | |||
@@ -232,9 +232,9 @@ public: | |||
return true; | |||
} | |||
inline int Find(T const &x) | |||
inline ptrdiff_t Find(T const &x) | |||
{ | |||
for (int i = 0; i < m_count; ++i) | |||
for (ptrdiff_t i = 0; i < m_count; ++i) | |||
if (m_data[i] == x) | |||
return i; | |||
return INDEX_NONE; | |||
@@ -242,7 +242,7 @@ public: | |||
bool RemoveItem(T const &x) | |||
{ | |||
int idx = Find(x); | |||
ptrdiff_t idx = Find(x); | |||
if (idx != INDEX_NONE) | |||
{ | |||
Remove(idx); | |||
@@ -253,7 +253,7 @@ public: | |||
bool RemoveSwapItem(T const &x) | |||
{ | |||
int idx = Find(x); | |||
ptrdiff_t idx = Find(x); | |||
if (idx != INDEX_NONE) | |||
{ | |||
RemoveSwap(idx); | |||
@@ -264,8 +264,8 @@ public: | |||
bool SwapItem(T const &x1, T const &x2) | |||
{ | |||
int idx1 = Find(x1); | |||
int idx2 = Find(x2); | |||
ptrdiff_t idx1 = Find(x1); | |||
ptrdiff_t idx2 = Find(x2); | |||
if (idx1 != INDEX_NONE && idx2 != INDEX_NONE) | |||
{ | |||
Swap(idx1, idx2); | |||
@@ -282,7 +282,7 @@ public: | |||
return tmp; | |||
} | |||
void Swap(int pos1, int pos2) | |||
void Swap(ptrdiff_t pos1, ptrdiff_t pos2) | |||
{ | |||
ASSERT(pos1 >= 0); | |||
ASSERT(pos2 >= 0); | |||
@@ -293,7 +293,7 @@ public: | |||
std::swap((*this)[pos1], (*this)[pos2]); | |||
} | |||
void Remove(int pos, int todelete = 1) | |||
void Remove(ptrdiff_t pos, ptrdiff_t todelete = 1) | |||
{ | |||
ASSERT(todelete >= 0); | |||
ASSERT(pos - todelete >= -m_count - 1); | |||
@@ -301,14 +301,14 @@ public: | |||
if (pos < 0) | |||
pos = m_count + pos; | |||
for (int i = pos; i + todelete < m_count; i++) | |||
for (ptrdiff_t i = pos; i + todelete < m_count; i++) | |||
m_data[i] = m_data[i + todelete]; | |||
for (int i = m_count - todelete; i < m_count; i++) | |||
for (ptrdiff_t i = m_count - todelete; i < m_count; i++) | |||
m_data[i].~element_t(); | |||
m_count -= todelete; | |||
} | |||
void RemoveSwap(int pos, int todelete = 1) | |||
void RemoveSwap(ptrdiff_t pos, ptrdiff_t todelete = 1) | |||
{ | |||
ASSERT(todelete >= 0); | |||
ASSERT(pos - todelete >= -m_count - 1); | |||
@@ -316,7 +316,7 @@ public: | |||
if (pos < 0) | |||
pos = m_count + pos; | |||
for (int i = 0; i < todelete; i++) | |||
for (ptrdiff_t i = 0; i < todelete; i++) | |||
{ | |||
if (pos + i < m_count - 1 - i) | |||
m_data[pos + i] = m_data[m_count - 1 - i]; | |||
@@ -325,17 +325,17 @@ public: | |||
m_count -= todelete; | |||
} | |||
void Resize(int count, element_t e = element_t()) | |||
void Resize(ptrdiff_t count, element_t e = element_t()) | |||
{ | |||
ASSERT(count >= 0); | |||
Reserve(count); | |||
/* Too many elements? Remove them. */ | |||
for (int i = count; i < m_count; ++i) | |||
for (ptrdiff_t i = count; i < m_count; ++i) | |||
m_data[i].~element_t(); | |||
/* Not enough elements? Add some. */ | |||
for (int i = m_count; i < count; ++i) | |||
for (ptrdiff_t i = m_count; i < count; ++i) | |||
new(&m_data[i]) element_t(e); | |||
m_count = count; | |||
@@ -346,9 +346,9 @@ public: | |||
Remove(0, m_count); | |||
} | |||
void Reserve(int toreserve) | |||
void Reserve(ptrdiff_t toreserve) | |||
{ | |||
if (toreserve <= (int)m_reserved) | |||
if (toreserve <= m_reserved) | |||
return; | |||
/* This cast is not very nice, because we kill any alignment | |||
@@ -358,7 +358,7 @@ public: | |||
element_t *tmp = reinterpret_cast<element_t *>(reinterpret_cast<uintptr_t> | |||
(new uint8_t[sizeof(element_t) * toreserve])); | |||
ASSERT(tmp, "out of memory in array class"); | |||
for (int i = 0; i < m_count; i++) | |||
for (ptrdiff_t i = 0; i < m_count; i++) | |||
{ | |||
new(&tmp[i]) element_t(m_data[i]); | |||
m_data[i].~element_t(); | |||
@@ -369,15 +369,15 @@ public: | |||
} | |||
void Sort(int sort); | |||
void SortQuickSwap(int start, int stop); | |||
void SortQuickSwap(ptrdiff_t start, ptrdiff_t stop); | |||
/* Support C++11 range-based for loops */ | |||
class ConstIterator | |||
{ | |||
public: | |||
ConstIterator(array_base const *array, int pos) | |||
ConstIterator(array_base const *that, ptrdiff_t pos) | |||
: m_pos(pos), | |||
m_array(array) | |||
m_array(that) | |||
{ } | |||
bool operator !=(const ConstIterator& that) const | |||
@@ -397,16 +397,16 @@ public: | |||
} | |||
private: | |||
int m_pos; | |||
ptrdiff_t m_pos; | |||
array_base const *m_array; | |||
}; | |||
class Iterator | |||
{ | |||
public: | |||
Iterator(array_base *array, int pos) | |||
Iterator(array_base *that, ptrdiff_t pos) | |||
: m_pos(pos), | |||
m_array(array) | |||
m_array(that) | |||
{ } | |||
bool operator !=(const Iterator& that) const | |||
@@ -426,13 +426,13 @@ public: | |||
} | |||
private: | |||
int m_pos; | |||
ptrdiff_t m_pos; | |||
array_base *m_array; | |||
}; | |||
public: | |||
inline int Count() const { return m_count; } | |||
inline int Bytes() const { return m_count * sizeof(element_t); } | |||
inline ptrdiff_t Count() const { return m_count; } | |||
inline ptrdiff_t Bytes() const { return m_count * sizeof(element_t); } | |||
protected: | |||
void Grow() | |||
@@ -441,7 +441,7 @@ protected: | |||
} | |||
element_t *m_data; | |||
int m_count, m_reserved; | |||
ptrdiff_t m_count, m_reserved; | |||
}; | |||
/* | |||
@@ -34,7 +34,7 @@ public: | |||
inline V const& operator[] (E const &key) const | |||
{ | |||
/* Look for the hash in our table and return the value. */ | |||
int i = FindIndex(key); | |||
ptrdiff_t i = FindIndex(key); | |||
ASSERT(i >= 0, "trying to read a nonexistent key in map"); | |||
return m_array[i].m3; | |||
} | |||
@@ -44,7 +44,7 @@ public: | |||
{ | |||
/* Look for the hash in our table and return the value if found. */ | |||
uint32_t hashed = ((hash<K> const &)*this)(key); | |||
int i = FindIndex(key, hashed); | |||
ptrdiff_t i = FindIndex(key, hashed); | |||
if (i >= 0) | |||
return m_array[i].m3; | |||
@@ -56,7 +56,7 @@ public: | |||
template <typename E> | |||
inline void Remove(E const &key) | |||
{ | |||
int i = FindIndex(key); | |||
ptrdiff_t i = FindIndex(key); | |||
if (i >= 0) | |||
m_array.Remove(i); | |||
} | |||
@@ -70,7 +70,7 @@ public: | |||
template <typename E> | |||
inline bool TryGetValue(E const &key, V& value) | |||
{ | |||
int i = FindIndex(key); | |||
ptrdiff_t i = FindIndex(key); | |||
if (i >= 0) | |||
{ | |||
value = m_array[i].m3; | |||
@@ -88,16 +88,16 @@ public: | |||
return ret; | |||
} | |||
inline int Count() const | |||
inline ptrdiff_t Count() const | |||
{ | |||
return m_array.Count(); | |||
} | |||
private: | |||
template <typename E> | |||
inline int FindIndex(E const &key, uint32_t hashed) | |||
inline ptrdiff_t FindIndex(E const &key, uint32_t hashed) | |||
{ | |||
for (int i = 0; i < m_array.Count(); ++i) | |||
for (ptrdiff_t i = 0; i < m_array.Count(); ++i) | |||
if (m_array[i].m1 == hashed) | |||
if (m_array[i].m2 == key) | |||
return i; | |||
@@ -105,7 +105,7 @@ private: | |||
} | |||
template <typename E> | |||
inline int FindIndex(E const &key) | |||
inline ptrdiff_t FindIndex(E const &key) | |||
{ | |||
uint32_t hashed = ((hash<K> const &)*this)(key); | |||
return FindIndex(key, hashed); | |||
@@ -43,11 +43,11 @@ public: | |||
{ | |||
using namespace std; | |||
ASSERT(str); | |||
Resize((int)strlen(str)); | |||
Resize(strlen(str)); | |||
memcpy(&(*this)[0], str, Count() + 1); | |||
} | |||
inline String(char const *str, int count) | |||
inline String(char const *str, ptrdiff_t count) | |||
: Super() | |||
{ | |||
using namespace std; | |||
@@ -62,16 +62,16 @@ public: | |||
{ | |||
} | |||
inline char &operator [](int n) | |||
inline char &operator [](ptrdiff_t n) | |||
{ | |||
/* Allow n == Count() because we might have reasonable reasons | |||
* to access that hidden null character. */ | |||
ASSERT(n >= 0); | |||
ASSERT((unsigned)n <= (unsigned)Count()); | |||
ASSERT(n <= Count()); | |||
return ((Super &)*this)[n]; | |||
} | |||
inline char const &operator [](int n) const | |||
inline char const &operator [](ptrdiff_t n) const | |||
{ | |||
ASSERT(n >= 0); | |||
ASSERT(n <= Count()); | |||
@@ -90,7 +90,7 @@ public: | |||
return (*this)[Count() - 1]; | |||
} | |||
inline int Count() const | |||
inline ptrdiff_t Count() const | |||
{ | |||
return ((Super const &)*this).Count() - 1; | |||
} | |||
@@ -108,14 +108,14 @@ public: | |||
} | |||
/* Does not initialise the newly allocated characters */ | |||
void Resize(int count) | |||
void Resize(ptrdiff_t count) | |||
{ | |||
ASSERT(count >= 0); | |||
((Super &)*this).Resize(count + 1); | |||
((Super &)*this).Last() = '\0'; | |||
} | |||
String Sub(int start, int count = -1) const | |||
String Sub(ptrdiff_t start, ptrdiff_t count = -1) const | |||
{ | |||
ASSERT(start >= 0); | |||
if (start >= Count()) | |||
@@ -125,20 +125,20 @@ public: | |||
return String(&(*this)[start], count); | |||
} | |||
int IndexOf(char token) const | |||
ptrdiff_t IndexOf(char token) const | |||
{ | |||
using namespace std; | |||
char const *tmp = strchr(C(), token); | |||
return tmp ? (int)(intptr_t)(tmp - C()) : INDEX_NONE; | |||
return tmp ? (ptrdiff_t)(tmp - C()) : INDEX_NONE; | |||
} | |||
int IndexOf(char const* token) const | |||
ptrdiff_t IndexOf(char const* token) const | |||
{ | |||
using namespace std; | |||
char const *tmp = strstr(C(), token); | |||
return tmp ? (int)(intptr_t)(tmp - C()) : INDEX_NONE; | |||
return tmp ? (ptrdiff_t)(tmp - C()) : INDEX_NONE; | |||
} | |||
bool Contains(String const &s) const | |||
@@ -146,15 +146,16 @@ public: | |||
return IndexOf(s.C()) != INDEX_NONE; | |||
} | |||
int LastIndexOf(char token) const | |||
ptrdiff_t LastIndexOf(char token) const | |||
{ | |||
using namespace std; | |||
char const *tmp = strrchr(C(), token); | |||
return tmp ? (int)(intptr_t)(tmp - C()) : INDEX_NONE; | |||
return tmp ? (ptrdiff_t)(tmp - C()) : INDEX_NONE; | |||
} | |||
int Replace(const char old_token, const char new_token, bool all_occurence=false) | |||
int Replace(char const old_token, char const new_token, | |||
bool all_occurrences = false) | |||
{ | |||
using namespace std; | |||
@@ -164,7 +165,7 @@ public: | |||
{ | |||
*tmp = new_token; | |||
res++; | |||
if (!all_occurence) | |||
if (!all_occurrences) | |||
break; | |||
} | |||
return res; | |||
@@ -173,7 +174,7 @@ public: | |||
inline String& ToLower() | |||
{ | |||
char* p = C(); | |||
for (int i = 0; i < Count(); ++i) | |||
for (ptrdiff_t i = 0; i < Count(); ++i) | |||
if ('A' <= p[i] && p[i] <= 'Z') | |||
p[i] += 'a' - 'A'; | |||
return *this; | |||
@@ -182,18 +183,18 @@ public: | |||
inline String& ToUpper() | |||
{ | |||
char* p = C(); | |||
for (int i = 0; i < Count(); ++i) | |||
for (ptrdiff_t i = 0; i < Count(); ++i) | |||
if ('a' <= p[i] && p[i] <= 'z') | |||
p[i] += 'A' - 'a'; | |||
return *this; | |||
} | |||
int LastIndexOf(char const* token) const | |||
ptrdiff_t LastIndexOf(char const* token) const | |||
{ | |||
using namespace std; | |||
int token_len = (int)strlen(token); | |||
for (int i = Count() - token_len; i >= 0; --i) | |||
ptrdiff_t token_len = strlen(token); | |||
for (ptrdiff_t i = Count() - token_len; i >= 0; --i) | |||
if (strstr(C() + i, token)) | |||
return i; | |||
return -1; | |||
@@ -215,7 +216,7 @@ public: | |||
bool IsAlpha() | |||
{ | |||
for (int i = 0; i < m_count; i++) | |||
for (ptrdiff_t i = 0; i < m_count; i++) | |||
if (m_data[i] != '\0' && (m_data[i] < '0' || '9' < m_data[i])) | |||
return false; | |||
return true; | |||
@@ -230,7 +231,7 @@ public: | |||
inline String& operator +=(String const &s) | |||
{ | |||
using namespace std; | |||
int old_count = Count(); | |||
ptrdiff_t old_count = Count(); | |||
Resize(Count() + s.Count()); | |||
memcpy(&(*this)[old_count], &s[0], Count() - old_count); | |||
return *this; | |||
@@ -266,7 +267,7 @@ public: | |||
/* We parse the C string twice because of strlen + memcmp | |||
* but it's probably still faster than doing it by hand. */ | |||
using namespace std; | |||
int sz_len = (int)strlen(sz); | |||
ptrdiff_t sz_len = strlen(sz); | |||
return Count() == sz_len | |||
&& memcmp(C(), sz, sz_len) == 0; | |||
} | |||
@@ -71,7 +71,7 @@ public: | |||
ASSERT(pos.x < m_size.x); | |||
ASSERT(pos.y < m_size.y); | |||
int n = pos.y * m_size.x + pos.x; | |||
ptrdiff_t n = pos.y * m_size.x + pos.x; | |||
ASSERT(n >= 0); | |||
ASSERT(n < this->m_count); | |||
@@ -85,7 +85,7 @@ public: | |||
ASSERT(pos.x < m_size.x); | |||
ASSERT(pos.y < m_size.y); | |||
int n = pos.y * m_size.x + pos.x; | |||
ptrdiff_t n = pos.y * m_size.x + pos.x; | |||
ASSERT(n >= 0); | |||
ASSERT(n < this->m_count); | |||
@@ -95,13 +95,13 @@ public: | |||
class Column | |||
{ | |||
public: | |||
inline Column(array2d &array, int i) | |||
inline Column(array2d &array, ptrdiff_t i) | |||
: m_array(array), | |||
m_column(i) | |||
{ | |||
} | |||
inline element_t &operator [](int j) | |||
inline element_t &operator [](ptrdiff_t j) | |||
{ | |||
ASSERT(j >= 0); | |||
ASSERT(j < m_array.m_size.y); | |||
@@ -110,19 +110,19 @@ public: | |||
private: | |||
array2d<T...> &m_array; | |||
int m_column; | |||
ptrdiff_t m_column; | |||
}; | |||
class ConstColumn | |||
{ | |||
public: | |||
inline ConstColumn(array2d const &array, int i) | |||
inline ConstColumn(array2d const &array, ptrdiff_t i) | |||
: m_array(array), | |||
m_column(i) | |||
{ | |||
} | |||
inline element_t const &operator [](int j) const | |||
inline element_t const &operator [](ptrdiff_t j) const | |||
{ | |||
ASSERT(j >= 0); | |||
ASSERT(j < m_array.m_size.y); | |||
@@ -131,18 +131,18 @@ public: | |||
private: | |||
array2d<T...> const &m_array; | |||
int m_column; | |||
ptrdiff_t m_column; | |||
}; | |||
/* Access addressable columns, allowing for array[i][j] syntax. */ | |||
inline class Column operator [](int i) | |||
inline class Column operator [](ptrdiff_t i) | |||
{ | |||
ASSERT(i >= 0); | |||
ASSERT(i < m_size.x); | |||
return Column(*this, i); | |||
} | |||
inline class ConstColumn operator [](int i) const | |||
inline class ConstColumn operator [](ptrdiff_t i) const | |||
{ | |||
ASSERT(i >= 0); | |||
ASSERT(i < m_size.x); | |||
@@ -165,8 +165,8 @@ public: | |||
public: | |||
inline element_t *Data() { return super::Data(); } | |||
inline element_t const *Data() const { return super::Data(); } | |||
inline int Count() const { return super::Count(); } | |||
inline int Bytes() const { return super::Bytes(); } | |||
inline ptrdiff_t Count() const { return super::Count(); } | |||
inline ptrdiff_t Bytes() const { return super::Bytes(); } | |||
private: | |||
ivec2 m_size; | |||
@@ -77,7 +77,7 @@ public: | |||
ASSERT(pos.y < m_size.y); | |||
ASSERT(pos.z < m_size.z); | |||
int n = (pos.z * m_size.y + pos.y) * m_size.x + pos.x; | |||
ptrdiff_t n = (pos.z * m_size.y + pos.y) * m_size.x + pos.x; | |||
ASSERT(n >= 0); | |||
ASSERT(n < this->m_count); | |||
@@ -93,7 +93,7 @@ public: | |||
ASSERT(pos.y < m_size.y); | |||
ASSERT(pos.z < m_size.z); | |||
int n = (pos.z * m_size.y + pos.y) * m_size.x + pos.x; | |||
ptrdiff_t n = (pos.z * m_size.y + pos.y) * m_size.x + pos.x; | |||
ASSERT(n >= 0); | |||
ASSERT(n < this->m_count); | |||
@@ -103,7 +103,7 @@ public: | |||
class Slice | |||
{ | |||
public: | |||
inline Slice(array3d &array, int i) | |||
inline Slice(array3d &array, ptrdiff_t i) | |||
: m_array(array), | |||
m_slice(i) | |||
{ | |||
@@ -118,7 +118,7 @@ public: | |||
{ | |||
} | |||
inline element_t &operator [](int k) | |||
inline element_t &operator [](ptrdiff_t k) | |||
{ | |||
ASSERT(k >= 0); | |||
ASSERT(k < m_array.m_size.z); | |||
@@ -130,7 +130,7 @@ public: | |||
ivec2 m_line; | |||
}; | |||
inline class Line operator [](int j) | |||
inline class Line operator [](ptrdiff_t j) | |||
{ | |||
ASSERT(j >= 0); | |||
ASSERT(j < m_array.m_size.y); | |||
@@ -139,13 +139,13 @@ public: | |||
private: | |||
array3d<T...> &m_array; | |||
int m_slice; | |||
ptrdiff_t m_slice; | |||
}; | |||
class ConstSlice | |||
{ | |||
public: | |||
inline ConstSlice(array3d const &array, int i) | |||
inline ConstSlice(array3d const &array, ptrdiff_t i) | |||
: m_array(array), | |||
m_slice(i) | |||
{ | |||
@@ -160,7 +160,7 @@ public: | |||
{ | |||
} | |||
inline element_t const &operator [](int k) const | |||
inline element_t const &operator [](ptrdiff_t k) const | |||
{ | |||
ASSERT(k >= 0); | |||
ASSERT(k < m_array.m_size.z); | |||
@@ -172,7 +172,7 @@ public: | |||
ivec2 m_line; | |||
}; | |||
inline class Line operator [](int j) const | |||
inline class Line operator [](ptrdiff_t j) const | |||
{ | |||
ASSERT(j >= 0); | |||
ASSERT(j < m_array.m_size.y); | |||
@@ -181,18 +181,18 @@ public: | |||
private: | |||
array3d<T...> const &m_array; | |||
int m_slice; | |||
ptrdiff_t m_slice; | |||
}; | |||
/* Access addressable slices, allowing for array[i][j][k] syntax. */ | |||
inline class Slice operator [](int i) | |||
inline class Slice operator [](ptrdiff_t i) | |||
{ | |||
ASSERT(i >= 0); | |||
ASSERT(i < m_size.x); | |||
return Slice(*this, i); | |||
} | |||
inline class ConstSlice operator [](int i) const | |||
inline class ConstSlice operator [](ptrdiff_t i) const | |||
{ | |||
ASSERT(i >= 0); | |||
ASSERT(i < m_size.x); | |||
@@ -215,8 +215,8 @@ public: | |||
public: | |||
inline element_t *Data() { return super::Data(); } | |||
inline element_t const *Data() const { return super::Data(); } | |||
inline int Count() const { return super::Count(); } | |||
inline int Bytes() const { return super::Bytes(); } | |||
inline ptrdiff_t Count() const { return super::Count(); } | |||
inline ptrdiff_t Bytes() const { return super::Bytes(); } | |||
private: | |||
ivec3 m_size; | |||
@@ -33,7 +33,7 @@ namespace lol | |||
{ | |||
template<typename T, size_t L> | |||
template<typename T, ptrdiff_t L> | |||
class arraynd_initializer | |||
{ | |||
public: | |||
@@ -43,7 +43,7 @@ public: | |||
{ | |||
} | |||
void FillSizes(size_t * sizes) | |||
void FillSizes(ptrdiff_t * sizes) | |||
{ | |||
*sizes = std::max(*sizes, m_initializers.size()); | |||
@@ -51,9 +51,9 @@ public: | |||
subinitializer.FillSizes(sizes + 1); | |||
} | |||
void FillValues(T * values, size_t * sizes, size_t accumulator) | |||
void FillValues(T * values, ptrdiff_t * sizes, ptrdiff_t accumulator) | |||
{ | |||
int pos = 0; | |||
ptrdiff_t pos = 0; | |||
for (auto subinitializer : m_initializers) | |||
{ | |||
@@ -78,16 +78,16 @@ public: | |||
{ | |||
} | |||
void FillSizes(size_t * sizes) | |||
void FillSizes(ptrdiff_t * sizes) | |||
{ | |||
*sizes = std::max(*sizes, m_initializers.size()); | |||
} | |||
void FillValues(T * values, size_t * sizes, size_t accumulator) | |||
void FillValues(T * values, ptrdiff_t * sizes, ptrdiff_t accumulator) | |||
{ | |||
UNUSED(sizes); | |||
int pos = 0; | |||
ptrdiff_t pos = 0; | |||
for (auto value : m_initializers) | |||
{ | |||
@@ -102,7 +102,7 @@ private: | |||
}; | |||
template<size_t N, typename... T> | |||
template<ptrdiff_t N, typename... T> | |||
class arraynd : protected array<T...> | |||
{ | |||
public: | |||
@@ -113,7 +113,7 @@ public: | |||
{ | |||
} | |||
inline arraynd(vec_t<size_t, N> sizes, element_t e = element_t()) | |||
inline arraynd(vec_t<ptrdiff_t, N> sizes, element_t e = element_t()) | |||
: m_sizes(sizes) | |||
{ | |||
FixSizes(e); | |||
@@ -129,26 +129,26 @@ public: | |||
/* Access elements directly using an ivec2, ivec3 etc. index */ | |||
inline element_t const & operator[](vec_t<int, N> const &pos) const | |||
{ | |||
size_t n = pos[N - 1]; | |||
for (int i = N - 2; i >= 0; --i) | |||
ptrdiff_t n = pos[N - 1]; | |||
for (ptrdiff_t i = N - 2; i >= 0; --i) | |||
n = pos[i] + m_sizes[i + 1] * n; | |||
return super::operator[](n); | |||
} | |||
inline element_t & operator[](vec_t<int, N> const &pos) | |||
inline element_t & operator[](vec_t<ptrdiff_t, N> const &pos) | |||
{ | |||
return const_cast<element_t &>( | |||
const_cast<arraynd<N, T...> const&>(*this)[pos]); | |||
} | |||
/* Proxy to access slices */ | |||
template<typename ARRAY_TYPE, size_t L = N - 1> | |||
template<typename ARRAY_TYPE, ptrdiff_t L = N - 1> | |||
class slice | |||
{ | |||
public: | |||
typedef slice<ARRAY_TYPE, L - 1> subslice; | |||
inline slice(ARRAY_TYPE &array, size_t index, size_t accumulator) | |||
inline slice(ARRAY_TYPE &array, ptrdiff_t index, ptrdiff_t accumulator) | |||
: m_array(array), | |||
m_index(index), | |||
m_accumulator(accumulator) | |||
@@ -158,7 +158,7 @@ public: | |||
/* Accessors for the const version of the proxy */ | |||
template<bool V = L != 1 && std::is_const<ARRAY_TYPE>::value> | |||
inline typename std::enable_if<V, subslice>::type | |||
operator[](size_t pos) const | |||
operator[](ptrdiff_t pos) const | |||
{ | |||
return subslice(m_array, m_index + pos * m_accumulator, | |||
m_accumulator * m_array.m_sizes[N - L]); | |||
@@ -166,7 +166,7 @@ public: | |||
template<bool V = L == 1 && std::is_const<ARRAY_TYPE>::value> | |||
inline typename std::enable_if<V, typename ARRAY_TYPE::element_t>::type | |||
const & operator[](size_t pos) const | |||
const & operator[](ptrdiff_t pos) const | |||
{ | |||
return m_array.super::operator[](m_index + pos * m_accumulator); | |||
} | |||
@@ -174,7 +174,7 @@ public: | |||
/* Accessors for the non-const version of the proxy */ | |||
template<bool V = L != 1 && !std::is_const<ARRAY_TYPE>::value> | |||
inline typename std::enable_if<V, subslice>::type | |||
operator[](size_t pos) | |||
operator[](ptrdiff_t pos) | |||
{ | |||
return subslice(m_array, m_index + pos * m_accumulator, | |||
m_accumulator * m_array.m_sizes[N - L]); | |||
@@ -182,36 +182,36 @@ public: | |||
template<bool V = L == 1 && !std::is_const<ARRAY_TYPE>::value> | |||
inline typename std::enable_if<V, typename ARRAY_TYPE::element_t>::type | |||
& operator[](size_t pos) | |||
& operator[](ptrdiff_t pos) | |||
{ | |||
return m_array.super::operator[](m_index + pos * m_accumulator); | |||
} | |||
private: | |||
ARRAY_TYPE &m_array; | |||
size_t m_index, m_accumulator; | |||
ptrdiff_t m_index, m_accumulator; | |||
}; | |||
/* Access addressable slices, allowing for array[i][j][...] syntax. */ | |||
inline slice<arraynd<N, T...> const> operator[](size_t pos) const | |||
inline slice<arraynd<N, T...> const> operator[](ptrdiff_t pos) const | |||
{ | |||
return slice<arraynd<N, T...> const>(*this, pos, m_sizes[0]); | |||
} | |||
inline slice<arraynd<N, T...>> operator[](size_t pos) | |||
inline slice<arraynd<N, T...>> operator[](ptrdiff_t pos) | |||
{ | |||
return slice<arraynd<N, T...>>(*this, pos, m_sizes[0]); | |||
} | |||
/* Resize the array. | |||
* FIXME: data gets scrambled; should we care? */ | |||
inline void SetSize(vec_t<size_t, N> sizes, element_t e = element_t()) | |||
inline void SetSize(vec_t<ptrdiff_t, N> sizes, element_t e = element_t()) | |||
{ | |||
m_sizes = sizes; | |||
FixSizes(e); | |||
} | |||
inline vec_t<size_t, N> GetSize() const | |||
inline vec_t<ptrdiff_t, N> GetSize() const | |||
{ | |||
return this->m_sizes; | |||
} | |||
@@ -219,13 +219,13 @@ public: | |||
public: | |||
inline element_t *Data() { return super::Data(); } | |||
inline element_t const *Data() const { return super::Data(); } | |||
inline int Count() const { return super::Count(); } | |||
inline int Bytes() const { return super::Bytes(); } | |||
inline ptrdiff_t Count() const { return super::Count(); } | |||
inline ptrdiff_t Bytes() const { return super::Bytes(); } | |||
private: | |||
inline void FixSizes(element_t e = element_t()) | |||
{ | |||
size_t total_size = 1; | |||
ptrdiff_t total_size = 1; | |||
for (auto size : m_sizes) | |||
total_size *= size; | |||
@@ -233,7 +233,7 @@ private: | |||
this->Resize(total_size, e); | |||
} | |||
vec_t<size_t, N> m_sizes; | |||
vec_t<ptrdiff_t, N> m_sizes; | |||
}; | |||
} /* namespace lol */ | |||
@@ -42,10 +42,10 @@ public: | |||
~TickerData() | |||
{ | |||
ASSERT(nentities == 0, | |||
"still %i entities in ticker\n", nentities); | |||
"still %td entities in ticker\n", nentities); | |||
ASSERT(m_autolist.Count() == 0, | |||
"still %i autoreleased entities\n", m_autolist.Count()); | |||
Log::Debug("%i frames required to quit\n", frame - quitframe); | |||
"still %ti autoreleased entities\n", m_autolist.Count()); | |||
Log::Debug("%d frames required to quit\n", frame - quitframe); | |||
#if LOL_FEATURE_THREADS | |||
gametick.Push(0); | |||
@@ -59,7 +59,7 @@ private: | |||
/* Entity management */ | |||
array<Entity *> m_todolist, m_autolist; | |||
array<Entity *> m_list[Entity::ALLGROUP_END]; | |||
int nentities; | |||
ptrdiff_t nentities; | |||
/* Fixed framerate management */ | |||
int frame, recording; | |||
@@ -221,13 +221,13 @@ void TickerData::GameThreadTick() | |||
Log::Debug("-------------------------------------\n"); | |||
for (int g = 0; g < Entity::ALLGROUP_END; ++g) | |||
{ | |||
Log::Debug("%s Group %i\n", | |||
Log::Debug("%s Group %d\n", | |||
(g < Entity::GAMEGROUP_END) ? "Game" : "Draw", g); | |||
for (int i = 0; i < data->m_list[g].Count(); ++i) | |||
{ | |||
Entity *e = data->m_list[g][i]; | |||
Log::Debug(" \\-- [%p] %s (m_ref %i, destroy %i)\n", | |||
Log::Debug(" \\-- [%p] %s (m_ref %d, destroy %d)\n", | |||
e, e->GetName(), e->m_ref, e->m_destroy); | |||
} | |||
} | |||
@@ -290,7 +290,7 @@ void TickerData::GameThreadTick() | |||
#if !LOL_BUILD_RELEASE | |||
if (n) | |||
Log::Error("%i entities stuck after %i frames, poked %i\n", | |||
Log::Error("%td entities stuck after %d frames, poked %d\n", | |||
data->nentities, data->quitdelay, n); | |||
#endif | |||
@@ -48,7 +48,7 @@ public: | |||
/* New methods */ | |||
int AddTile(ibox2 rect); | |||
void AddTile(ivec2 count); | |||
int GetTileCount() const; | |||
ptrdiff_t GetTileCount() const; | |||
ivec2 GetTileSize(int tileid) const; | |||
Texture * GetTexture(); | |||
@@ -376,7 +376,7 @@ public: | |||
//Mesh Change | |||
#if NO_NACL_EM_INPUT | |||
m_mesh_id = clamp(m_mesh_id + ((int)KeyPressed(KEY_MESH_PREV) - (int)KeyPressed(KEY_MESH_NEXT)), 0, m_meshes.Count() - 1); | |||
m_mesh_id = clamp(m_mesh_id + ((int)KeyPressed(KEY_MESH_PREV) - (int)KeyPressed(KEY_MESH_NEXT)), 0, (int)m_meshes.Count() - 1); | |||
#endif //NO_NACL_EM_INPUT | |||
m_mesh_id1 = damp(m_mesh_id1, (float)m_mesh_id, .2f, seconds); | |||
@@ -27,7 +27,7 @@ LOLUNIT_FIXTURE(ArrayNDTest) | |||
LOLUNIT_TEST(Array2D) | |||
{ | |||
arraynd<2, int> a; | |||
a.SetSize(vec_t<size_t, 2>(2, 2)); | |||
a.SetSize(vec_t<ptrdiff_t, 2>(2, 2)); | |||
/* Non-const accessors */ | |||
a[0][0] = 1; | |||
@@ -58,7 +58,7 @@ LOLUNIT_FIXTURE(ArrayNDTest) | |||
LOLUNIT_TEST(ArrayNDInit) | |||
{ | |||
int const NDIM = 8; | |||
vec_t<size_t, NDIM> size; | |||
vec_t<ptrdiff_t, NDIM> size; | |||
for (int i = 0; i < NDIM; ++i) | |||
size[i] = 5; | |||
@@ -177,14 +177,14 @@ LOLUNIT_FIXTURE(StringTest) | |||
LOLUNIT_TEST(IndexOf) | |||
{ | |||
String s1 = "Hello World"; | |||
int i1 = s1.IndexOf('H'); | |||
int i2 = s1.IndexOf('W'); | |||
int i3 = s1.IndexOf('d'); | |||
int i4 = s1.IndexOf("Hello"); | |||
int i5 = s1.IndexOf("World"); | |||
int i6 = s1.IndexOf("lo"); | |||
int i7 = s1.IndexOf("Hello World"); | |||
int i8 = s1.IndexOf("Sup' dude"); | |||
ptrdiff_t i1 = s1.IndexOf('H'); | |||
ptrdiff_t i2 = s1.IndexOf('W'); | |||
ptrdiff_t i3 = s1.IndexOf('d'); | |||
ptrdiff_t i4 = s1.IndexOf("Hello"); | |||
ptrdiff_t i5 = s1.IndexOf("World"); | |||
ptrdiff_t i6 = s1.IndexOf("lo"); | |||
ptrdiff_t i7 = s1.IndexOf("Hello World"); | |||
ptrdiff_t i8 = s1.IndexOf("Sup' dude"); | |||
LOLUNIT_ASSERT(i1 == 0); | |||
LOLUNIT_ASSERT(i2 == 6); | |||
@@ -199,15 +199,15 @@ LOLUNIT_FIXTURE(StringTest) | |||
LOLUNIT_TEST(LastIndexOf) | |||
{ | |||
String s1 = "Hello World"; | |||
int i1 = s1.LastIndexOf('H'); | |||
int i2 = s1.LastIndexOf('W'); | |||
int i3 = s1.LastIndexOf('d'); | |||
int i4 = s1.LastIndexOf("Hello"); | |||
int i5 = s1.LastIndexOf("World"); | |||
int i6 = s1.LastIndexOf("lo"); | |||
int i7 = s1.LastIndexOf("Hello World"); | |||
int i8 = s1.LastIndexOf("Sup' dude"); | |||
int i9 = s1.LastIndexOf('l'); | |||
ptrdiff_t i1 = s1.LastIndexOf('H'); | |||
ptrdiff_t i2 = s1.LastIndexOf('W'); | |||
ptrdiff_t i3 = s1.LastIndexOf('d'); | |||
ptrdiff_t i4 = s1.LastIndexOf("Hello"); | |||
ptrdiff_t i5 = s1.LastIndexOf("World"); | |||
ptrdiff_t i6 = s1.LastIndexOf("lo"); | |||
ptrdiff_t i7 = s1.LastIndexOf("Hello World"); | |||
ptrdiff_t i8 = s1.LastIndexOf("Sup' dude"); | |||
ptrdiff_t i9 = s1.LastIndexOf('l'); | |||
LOLUNIT_ASSERT(i1 == 0); | |||
LOLUNIT_ASSERT(i2 == 6); | |||