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