1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-20 09:23:52 +00:00
openmw-tes3mp/components/openmw-mp/Packets/Player/PacketPlayerPosition.cpp

50 lines
1.4 KiB
C++
Raw Normal View History

//
// Created by koncord on 05.01.16.
//
#include "PacketPlayerPosition.hpp"
#include <components/openmw-mp/NetworkMessages.hpp>
using namespace std;
using namespace mwmp;
PacketPlayerPosition::PacketPlayerPosition(RakNet::RakPeerInterface *peer) : PlayerPacket(peer)
{
packetID = ID_PLAYER_POSITION;
priority = MEDIUM_PRIORITY;
}
void PacketPlayerPosition::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
float rot[2];
unsigned char dir;
2017-06-08 20:34:56 +00:00
if (send)
{
if((player->movementFlags & /*Flag_ForceJump*/16) != 0)
reliability = RELIABLE_ORDERED;
else
reliability = UNRELIABLE_SEQUENCED;
rot[0] = player->position.rot[0] * 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);
}
2017-11-28 13:37:46 +00:00
RW(rot[0], send, true);
RW(rot[1], send, true);
2017-11-28 13:37:46 +00:00
RW(player->position.pos, send, true);
RW(dir, send);
2017-06-08 20:34:56 +00:00
if (!send)
{
player->position.rot[0] = rot[0] / 0.1f;
player->position.rot[2] = rot[1] / 0.1f;
player->direction.pos[0] = (dir >> 2) == 0x3 ? -1 : dir >> 2; // unpack direction
player->direction.pos[1] = (dir & 0x3) == 0x3 ? -1 : dir & 0x3;
}
}