[General] Pack player->direction.pos to 1 byte

0.6.1
Koncord 8 years ago
parent dded330cc4
commit 7e5e877fda

@ -20,26 +20,26 @@ void PacketPlayerPosition::Packet(RakNet::BitStream *bs, bool send)
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
float rot[2]; float rot[2];
unsigned char dir;
if(send) if(send)
{ {
rot[0] = player->position.rot[0] * 0.1f; rot[0] = player->position.rot[0] * 0.1f;
rot[1] = player->position.rot[2] * 0.1f; rot[1] = player->position.rot[2] * 0.1f;
dir = (player->direction.pos[0] >= 0 ? (unsigned char)(player->direction.pos[0]) : (unsigned char) 0x3) << 2; // pack direction
dir += (player->direction.pos[1] >= 0 ? (unsigned char)(player->direction.pos[1]) : (unsigned char) 0x3);
} }
RW(rot[0], send, 1); RW(rot[0], send, 1);
RW(rot[1], send, 1); RW(rot[1], send, 1);
RW(player->position.pos, send, 1); RW(player->position.pos, send, 1);
RW(player->direction.pos[0], send, 1); RW(dir, send);
RW(player->direction.pos[1], send, 1);
if(!send) if(!send)
{ {
player->position.rot[0] = rot[0] / 0.1f; player->position.rot[0] = rot[0] / 0.1f;
player->position.rot[2] = rot[1] / 0.1f; player->position.rot[2] = rot[1] / 0.1f;
player->direction.pos[0] = (dir >> 2) == 0x3 ? -1 : dir >> 2; // unpack direction
if(abs(player->direction.pos[0]) < 1) player->direction.pos[1] = (dir & 0x3) == 0x3 ? -1 : dir & 0x3;
player->direction.pos[0] = 0;
if(abs(player->direction.pos[1]) < 1)
player->direction.pos[1] = 0;
} }
} }

Loading…
Cancel
Save