1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
#pragma once
using namespace std;
class Pos;
class SynchedEntityData
{
public:
class DataItem
{
friend class SynchedEntityData;
private:
const int type;
const int id;
// 4J - there used to be one "value" type here of general type Object, just storing the different (used) varieties
// here separately for us
byte value_byte;
int value_int;
short value_short;
wstring value_wstring;
std::shared_ptr<ItemInstance> value_itemInstance;
bool dirty;
public:
// There was one type here that took a generic Object type, using overloading here instead
DataItem(int type, int id, byte value);
DataItem(int type, int id, int value);
DataItem(int type, int id, const wstring& value);
DataItem(int type, int id, std::shared_ptr<ItemInstance> itemInstance);
DataItem(int type, int id, short value);
int getId();
void setValue(byte value);
void setValue(int value);
void setValue(short value);
void setValue(const wstring& value);
void setValue(std::shared_ptr<ItemInstance> value);
byte getValue_byte();
int getValue_int();
short getValue_short();
wstring getValue_wstring();
std::shared_ptr<ItemInstance> getValue_itemInstance();
int getType();
bool isDirty();
void setDirty(bool dirty);
};
public:
static const int MAX_STRING_DATA_LENGTH = 64;
static const int EOF_MARKER = 0x7f;
private:
static const int TYPE_BYTE = 0;
static const int TYPE_SHORT = 1;
static const int TYPE_INT = 2;
static const int TYPE_FLOAT = 3;
static const int TYPE_STRING = 4;
// special types (max possible value is 7):
static const int TYPE_ITEMINSTANCE = 5;
static const int TYPE_POS = 6;
private:
bool m_isEmpty;
// must have enough bits to fit the type
private:
static const int TYPE_MASK = 0xe0;
static const int TYPE_SHIFT = 5;
// the id value must fit in the remaining bits
static const int MAX_ID_VALUE = ~TYPE_MASK & 0xff;
unordered_map<int, std::shared_ptr<DataItem> > itemsById;
bool m_isDirty;
public:
SynchedEntityData();
// 4J - this function used to be a template, but there's only 3 varieties of use I've found so just hard-coding now, as
// the original had some automatic Class to type sort of conversion that's a real pain for us to actually do
void define(int id, byte value);
void define(int id, const wstring& value);
void define(int id, int value);
void define(int id, short value);
void defineNULL(int id, void *pVal);
void checkId(int id); // 4J - added to contain common code from overloaded define functions above
byte getByte(int id);
short getShort(int id);
int getInteger(int id);
float getFloat(int id);
wstring getString(int id);
std::shared_ptr<ItemInstance> getItemInstance(int id);
Pos *getPos(int id);
// 4J - using overloads rather than template here
void set(int id, byte value);
void set(int id, int value);
void set(int id, short value);
void set(int id, const wstring& value);
void set(int id, std::shared_ptr<ItemInstance>);
void markDirty(int id);
bool isDirty();
static void pack(vector<std::shared_ptr<DataItem> > *items, DataOutputStream *output); // TODO throws IOException
vector<std::shared_ptr<DataItem> > *packDirty();
void packAll(DataOutputStream *output); // throws IOException
vector<std::shared_ptr<DataItem> > *getAll();
private:
static void writeDataItem(DataOutputStream *output, std::shared_ptr<DataItem> dataItem); //throws IOException
public:
static vector<std::shared_ptr<DataItem> > *unpack(DataInputStream *input); // throws IOException
/**
* Assigns values from a list of data items.
*
* @param items
*/
public:
void assignValues(vector<std::shared_ptr<DataItem> > *items);
bool isEmpty();
// 4J Added
int getSizeInBytes();
};
|