blob: cae28e912c38d27d6540290978327da409328431 (
plain)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
#include "stdafx.h"
#include <iostream>
#include "InputOutputStream.h"
#include "PacketListener.h"
#include "MoveEntityPacket.h"
MoveEntityPacket::MoveEntityPacket()
{
hasRot = false;
id = -1;
xa = 0;
ya = 0;
za = 0;
yRot = 0;
xRot = 0;
}
MoveEntityPacket::MoveEntityPacket(int id)
{
this->id = id;
hasRot = false;
xa = 0;
ya = 0;
za = 0;
yRot = 0;
xRot = 0;
}
void MoveEntityPacket::read(DataInputStream *dis) //throws IOException
{
id = dis->readShort();
}
void MoveEntityPacket::write(DataOutputStream *dos) //throws IOException
{
if( (id < 0 ) || (id >= 2048 ) )
{
// We shouln't be tracking an entity that doesn't have a short type of id
__debugbreak();
}
dos->writeShort(static_cast<short>(id));
}
void MoveEntityPacket::handle(PacketListener *listener)
{
listener->handleMoveEntity(shared_from_this());
}
int MoveEntityPacket::getEstimatedSize()
{
return 2;
}
bool MoveEntityPacket::canBeInvalidated()
{
return true;
}
bool MoveEntityPacket::isInvalidatedBy(shared_ptr<Packet> packet)
{
shared_ptr<MoveEntityPacket> target = dynamic_pointer_cast<MoveEntityPacket>(packet);
return target != nullptr && target->id == id;
}
MoveEntityPacket::PosRot::PosRot()
{
hasRot = true;
}
MoveEntityPacket::PosRot::PosRot(int id, char xa, char ya, char za, char yRot, char xRot) : MoveEntityPacket( id )
{
this->xa = xa;
this->ya = ya;
this->za = za;
this->yRot = yRot;
this->xRot = xRot;
hasRot = true;
}
void MoveEntityPacket::PosRot::read(DataInputStream *dis) //throws IOException
{
MoveEntityPacket::read(dis);
xa = dis->readByte();
ya = dis->readByte();
za = dis->readByte();
yRot = dis->readByte();
xRot = dis->readByte();
}
void MoveEntityPacket::PosRot::write(DataOutputStream *dos) //throws IOException
{
MoveEntityPacket::write(dos);
dos->writeByte(xa);
dos->writeByte(ya);
dos->writeByte(za);
dos->writeByte(yRot);
dos->writeByte(xRot);
}
int MoveEntityPacket::PosRot::getEstimatedSize()
{
return 2+5;
}
MoveEntityPacket::Pos::Pos()
{
}
MoveEntityPacket::Pos::Pos(int id, char xa, char ya, char za) : MoveEntityPacket(id)
{
this->xa = xa;
this->ya = ya;
this->za = za;
}
void MoveEntityPacket::Pos::read(DataInputStream *dis) //throws IOException
{
MoveEntityPacket::read(dis);
xa = dis->readByte();
ya = dis->readByte();
za = dis->readByte();
}
void MoveEntityPacket::Pos::write(DataOutputStream *dos) //throws IOException
{
MoveEntityPacket::write(dos);
dos->writeByte(xa);
dos->writeByte(ya);
dos->writeByte(za);
}
int MoveEntityPacket::Pos::getEstimatedSize()
{
return 2+3;
}
MoveEntityPacket::Rot::Rot()
{
hasRot = true;
}
MoveEntityPacket::Rot::Rot(int id, char yRot, char xRot) : MoveEntityPacket(id)
{
this->yRot = yRot;
this->xRot = xRot;
hasRot = true;
}
void MoveEntityPacket::Rot::read(DataInputStream *dis) //throws IOException
{
MoveEntityPacket::read(dis);
yRot = dis->readByte();
xRot = dis->readByte();
}
void MoveEntityPacket::Rot::write(DataOutputStream *dos) //throws IOException
{
MoveEntityPacket::write(dos);
dos->writeByte(yRot);
dos->writeByte(xRot);
}
int MoveEntityPacket::Rot::getEstimatedSize()
{
return 2+2;
}
|