-
Notifications
You must be signed in to change notification settings - Fork 3
/
Events.cpp
87 lines (76 loc) · 2.24 KB
/
Events.cpp
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
#include "Events.h"
#include "File.h"
#include "KEnvironment.h"
#include "CKService.h"
#include "CKLogic.h"
void EventNodeX1::write(KEnvironment * kenv, File * file) const {
CKSrvEvent* srvEvent = kenv->levelObjects.getFirst<CKSrvEvent>();
assert(srvEvent);
int16_t actualSeqIndex; uint8_t actualBit;
auto& ids = srvEvent->evtSeqIDs;
auto it = std::find(ids.begin(), ids.end(), seqIndex);
if (it != ids.end()) {
actualSeqIndex = (int16_t)(it - ids.begin());
actualBit = bit;
}
else {
actualSeqIndex = -1;
actualBit = 0;
}
uint16_t enc = (actualSeqIndex << 3) | actualBit;
file->writeUint16(enc);
}
void EventNodeX1::read(KEnvironment * kenv, File * file, CKObject *user) {
int16_t enc = (int16_t)file->readUint16();
bit = enc & 7;
seqIndex = enc >> 3;
if (seqIndex != -1 && kenv->hasClass<CKSrvEvent>()) {
if (CKSrvEvent *srvEvent = kenv->levelObjects.getFirst<CKSrvEvent>()) {
srvEvent->sequences[seqIndex].users.push_back(user);
srvEvent->sequences[seqIndex].userFound = true;
}
}
}
void MarkerIndex::write(KEnvironment* kenv, File* file) const
{
file->writeInt32(index);
if (kenv->version >= KEnvironment::KVERSION_ARTHUR)
file->writeInt32(arSecondIndex);
}
void MarkerIndex::read(KEnvironment* kenv, File* file)
{
index = file->readInt32();
if (kenv->version >= KEnvironment::KVERSION_ARTHUR)
arSecondIndex = file->readInt32();
}
void EventNodeX2::write(KEnvironment* kenv, File* file)
{
file->writeUint32((uint32_t)datas.size());
for (auto& ref : datas)
kenv->writeObjID(file, ref.get());
}
void EventNodeX2::read(KEnvironment* kenv, File* file, CKObject* user)
{
datas.resize(file->readUint32());
for (auto& ref : datas)
ref = KWeakRef<CKComparedData>(kenv->readObjPnt(file)->cast<CKComparedData>());
}
void EventNodeX2::clean()
{
auto it = std::remove_if(datas.begin(), datas.end(), [](KWeakRef<CKComparedData>& ref) {return !ref; });
datas.erase(it, datas.end());
}
void EventNode::write(KEnvironment* kenv, File* file)
{
if (kenv->version < KEnvironment::KVERSION_XXL2)
enx1.write(kenv, file);
else
enx2.write(kenv, file);
}
void EventNode::read(KEnvironment* kenv, File* file, CKObject* user)
{
if (kenv->version < KEnvironment::KVERSION_XXL2)
enx1.read(kenv, file, user);
else
enx2.read(kenv, file, user);
}