Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/helpers/ArrayData.h
- This file was added.
/* Copyright (C) 2020 Wildfire Games. | |||||
* This file is part of 0 A.D. | |||||
Silier: copyright | |||||
* | |||||
* 0 A.D. is free software: you can redistribute it and/or modify | |||||
* it under the terms of the GNU General Public License as published by | |||||
* the Free Software Foundation, either version 2 of the License, or | |||||
* (at your option) any later version. | |||||
* | |||||
* 0 A.D. is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
* GNU General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU General Public License | |||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef ARRAYDATA | |||||
Done Inline ActionsI would be careful using u64 as we still compile with 32 bit compiler, that means storing that value in 2 registers instead just one what makes reading and writing slower. (just a note, did not check if we can do something about it to not use u64) Silier: I would be careful using u64 as we still compile with 32 bit compiler, that means storing that… | |||||
Done Inline Actionsok nani: ok | |||||
#define ARRAYDATA | |||||
#include "simulation2/serialization/SerializeTemplates.h" | |||||
SilierUnsubmitted Done Inline Actionsminus one \n Silier: minus one \n | |||||
void Simulation_SetNumberOfPlayersReadOnly(bool readOnly); | |||||
size_t Simulation_GetNumberOfPlayers(); | |||||
void Simulation_SetNumberOfPlayers(size_t number); | |||||
template <size_t extra, typename T, u8 mask, size_t nBits> | |||||
class ArrayData | |||||
{ | |||||
public: | |||||
Done Inline ActionsArrayData<extra>& Silier: `ArrayData<extra>& ` | |||||
Done Inline ActionsArrayData<extra>& Silier: `ArrayData<extra>& ` | |||||
ArrayData(); | |||||
ArrayData(T value); | |||||
Done Inline ActionsArrayData<extra>& Silier: `ArrayData<extra>& ` | |||||
ArrayData(const std::vector<u8>& vector); | |||||
// Returns an ArrayData with all bits set to one | |||||
static ArrayData<extra, T, mask, nBits> allOnes(); | |||||
static size_t size(); | |||||
u8 get(int i) const; | |||||
void set(int i, u8 v); | |||||
void fill(T value); | |||||
void fillZeros(); | |||||
void fillOnes(); | |||||
bool isZero() const; | |||||
bool andExpandedMask(const ArrayData<extra, T, mask, nBits>& second, T expandedMask) const; | |||||
void setBitwiseOr(const ArrayData<extra, T, mask, nBits>& second); | |||||
bool operator==(const ArrayData<extra, T, mask, nBits>& second) const; | |||||
bool operator!=(const ArrayData<extra, T, mask, nBits>& second) const; | |||||
template <size_t extra_, u8 mask_, size_t nBits_> | |||||
friend struct SerializeArrayData; | |||||
Not Done Inline ActionsIs there a convention for this? players_data_t? Dunno just wondering Stan: Is there a convention for this?
players_data_t? Dunno just wondering | |||||
private: | |||||
constexpr size_t sizeInternal() const; | |||||
u8 getInternal(size_t i) const; | |||||
void setInternal(size_t i, u8 v); | |||||
int index(int i) const; | |||||
T m_data; | |||||
}; | |||||
template <size_t extra_, u8 mask_, size_t nBits_> | |||||
struct SerializeArrayData | |||||
{ | |||||
void operator()(ISerializer& serialize, const char* name, ArrayData<extra_, u32, mask_, nBits_>& value); | |||||
void operator()(IDeserializer& deserialize, const char* name, ArrayData<extra_, u32, mask_, nBits_>& value); | |||||
void operator()(ISerializer& serialize, const char* name, ArrayData<extra_, u64, mask_, nBits_>& value); | |||||
void operator()(IDeserializer& deserialize, const char* name, ArrayData<extra_, u64, mask_, nBits_>& value); | |||||
}; | |||||
using PlayersData1b = ArrayData<0, u32, 0x1, 1>; | |||||
using PlayersData2b = ArrayData<0, u64, 0x3, 2>; | |||||
using OwnersData1b = ArrayData<2, u32, 0x1, 1>; | |||||
using SerializePlayersData1b = SerializeArrayData<0, 0x1, 1>; | |||||
using SerializePlayersData2b = SerializeArrayData<0, 0x3, 2>; | |||||
using SerializeOwnersData1b = SerializeArrayData<2, 0x1, 1>; | |||||
#endif // ARRAYDATA |
Wildfire Games · Phabricator
copyright