Changeset View
Standalone View
source/simulation2/helpers/ArrayData.cpp
- This file was added.
#include "precompiled.h" | |||||
Silier: copyright | |||||
#include "ArrayData.h" | |||||
static size_t count = 8; | |||||
static bool countIsReadOnly = true; | |||||
void Simulation_SetNumberOfPlayersReadOnly(bool readOnly){ countIsReadOnly = readOnly; } | |||||
size_t Simulation_GetNumberOfPlayers(){ return count; } | |||||
void Simulation_SetNumberOfPlayers(size_t number) | |||||
{ | |||||
WARN_IF_FALSE(number <= 30); | |||||
if(!countIsReadOnly) | |||||
count = number; | |||||
} | |||||
template <size_t extra> | |||||
ArrayData<extra>::ArrayData() | |||||
{ | |||||
fillZeros(); | |||||
} | |||||
template <size_t extra> | |||||
ArrayData<extra>::ArrayData(u64 value) | |||||
{ | |||||
m_data = value; | |||||
} | |||||
template <size_t extra> | |||||
ArrayData<extra>::ArrayData(std::vector<u8> vector) | |||||
{ | |||||
m_data = 0; | |||||
for (size_t i = 0; i < vector.size() && i < size(); ++i) | |||||
setInternal(i, vector[i]); | |||||
Done Inline Actionsfor ( ++i Silier: `for (` `++i` | |||||
} | |||||
Done Inline Actionsi, ve Silier: `i, ve` | |||||
template <size_t extra> | |||||
size_t ArrayData<extra>::size(){ return count + extra;} | |||||
template <size_t extra> | |||||
u8 ArrayData<extra>::get(size_t i) const{ return getInternal(index(i));} | |||||
SilierUnsubmitted Done Inline ActionsIf you expect here i = -1 (Comment at line 119). that is not possible. size_t is non negative. Silier: If you expect here i = -1 (Comment at line 119). that is not possible. size_t is non negative. | |||||
naniAuthorUnsubmitted Done Inline Actionssize_t can accept a negative value given it just applies a % operator afterwards (C++ unsigned int specification defined) so at a practical level is the same (-1 would just return the max size_t value possible and be corrected internally to 0 inside the class) and avoids doing a type conversion. But I can change it if you are very against it. nani: size_t can accept a negative value given it just applies a % operator afterwards (C++ unsigned… | |||||
StanUnsubmitted Done Inline ActionsMaybe use ssize_t? Stan: Maybe use ssize_t? | |||||
naniAuthorUnsubmitted Done Inline ActionsFrom what I read ssize_t is not part of the c++ standard. nani: From what I read ssize_t is not part of the c++ standard. | |||||
template <size_t extra> | |||||
void ArrayData<extra>::set(size_t i, u8 v){ setInternal(index(i),v);} | |||||
template <size_t extra> | |||||
void ArrayData<extra>::fill(u64 value) | |||||
{ | |||||
m_data = 0; | |||||
for(size_t i = 0 ; i < 64; i+=2) | |||||
SilierUnsubmitted Done Inline Actionsfor ( i += 2 Silier: `for (` `i += 2` | |||||
m_data |= (value & 0x3) << i; | |||||
SilierUnsubmitted Done Inline Actionsvalue & 0x3 always returns the same result, should be computed before loop Silier: `value & 0x3` always returns the same result, should be computed before loop | |||||
} | |||||
template <size_t extra> | |||||
void ArrayData<extra>::fillZeros() | |||||
{ | |||||
m_data = 0; | |||||
} | |||||
template <size_t extra> | |||||
void ArrayData<extra>::fillOnes() | |||||
{ | |||||
m_data = std::numeric_limits<u64>::max(); | |||||
} | |||||
template <size_t extra> | |||||
bool ArrayData<extra>::isZero() const | |||||
{ | |||||
return m_data == 0; | |||||
} | |||||
template <size_t extra> | |||||
bool ArrayData<extra>::andExpandedMask(const ArrayData<extra>& second, u64 expandedMask) const | |||||
{ | |||||
Done Inline ActionsArrayData<extra>& Silier: `ArrayData<extra>& ` | |||||
Done Inline ActionsThe const is needed. nani: The const is needed. | |||||
return m_data & second.m_data & expandedMask; | |||||
} | |||||
template <size_t extra> | |||||
void ArrayData<extra>::setBitwiseOr(const ArrayData<extra>& second) | |||||
{ | |||||
Done Inline ActionsArrayData<extra>& Silier: `ArrayData<extra>& ` | |||||
m_data |= second.m_data; | |||||
} | |||||
template <size_t extra> | |||||
bool ArrayData<extra>::isEqual(const ArrayData<extra>& second) const | |||||
{ | |||||
Done Inline ActionsArrayData<extra>& Silier: `ArrayData<extra>& ` | |||||
return m_data == second.m_data; | |||||
} | |||||
template <size_t extra> | |||||
bool ArrayData<extra>::operator==(const ArrayData<extra>& second) const | |||||
{ | |||||
Done Inline ActionsArrayData<extra>& Silier: `ArrayData<extra>& ` | |||||
return m_data == second.m_data; | |||||
} | |||||
template <size_t extra> | |||||
size_t ArrayData<extra>::sizeInternal() const | |||||
{ | |||||
return 64; | |||||
} | |||||
template <size_t extra> | |||||
u8 ArrayData<extra>::getInternal(size_t i) const | |||||
{ | |||||
return (m_data >> (2*i)) & 0x3; | |||||
} | |||||
Done Inline Actions2 * i Silier: `2 * i` | |||||
template <size_t extra> | |||||
void ArrayData<extra>::setInternal(size_t i, u16 v) | |||||
{ | |||||
m_data = (m_data & ~(0x3 << 2*i)) | (u64(v & 0x3) << 2*i); | |||||
SilierUnsubmitted Done Inline Actionsstatic_cast<u64>(0x3) << 2 * i static_cast<u64>(v & 0x3) << 2 * i Silier: `static_cast<u64>(0x3) << 2 * i` `static_cast<u64>(v & 0x3) << 2 * i` | |||||
SilierUnsubmitted Done Inline Actionsstatic_cast<u64>(0x3) else you are shifting at the best 32bit number, at the worst 8bit number Silier: static_cast<u64>(0x3) else you are shifting at the best 32bit number, at the worst 8bit number | |||||
} | |||||
Done Inline Actions2 * i Silier: `2 * i` | |||||
/* Player index goes from 1 to N inclusive. */ | |||||
template <> | |||||
int ArrayData<0>::index(int i) const { return i - 1; } | |||||
/* Owner index goes from -1 to N inclusive. */ | |||||
template <> | |||||
int ArrayData<2>::index(int i) const { return i + 1; } | |||||
template <size_t extra_> | |||||
void SerializeArrayData<extra_>::operator()(ISerializer& serialize, const char* name, ArrayData<extra_>& value) | |||||
{ | |||||
SerializeU64_Unbounded()(serialize, name, value.m_data); | |||||
} | |||||
template <size_t extra_> | |||||
void SerializeArrayData<extra_>::operator()(IDeserializer& deserialize, const char* name, ArrayData<extra_>& value) | |||||
{ | |||||
SerializeU64_Unbounded()(deserialize, name, value.m_data); | |||||
} | |||||
template class ArrayData<0>; | |||||
template class ArrayData<2>; | |||||
template struct SerializeArrayData<0>; | |||||
template struct SerializeArrayData<2>; |
copyright