Ajouts dans netprotocol
This commit is contained in:
parent
6bea176979
commit
ace555a93e
@ -1,7 +1,64 @@
|
|||||||
#include "netprotocol.h"
|
#include "netprotocol.h"
|
||||||
|
|
||||||
void netprot::Serialize(Input* in, char* buf[], uint32_t* buflen) {
|
void netprot::Serialize(Input* in, char* buf[], uint32_t* buflen) {
|
||||||
|
*buf[0] = netprot::PACKET_TYPE::INPUT;
|
||||||
|
|
||||||
|
uint64_t time = in->timestamp;
|
||||||
|
uint8_t time8[sizeof(uint64_t)] = {(time >> 56) & 0xFF,
|
||||||
|
(time >> 48) & 0xFF,
|
||||||
|
(time >> 40) & 0xFF,
|
||||||
|
(time >> 32) & 0xFF,
|
||||||
|
(time >> 24) & 0xFF,
|
||||||
|
(time >> 16) & 0xFF,
|
||||||
|
(time >> 8 ) & 0xFF,
|
||||||
|
time & 0xFF};
|
||||||
|
|
||||||
|
memcpy(*buf + 1, time8, sizeof(uint64_t));
|
||||||
|
|
||||||
|
uint64_t sid = in->sid;
|
||||||
|
uint8_t sid8[sizeof(uint64_t)] = {(sid >> 56) & 0xFF,
|
||||||
|
(sid >> 48) & 0xFF,
|
||||||
|
(sid >> 40) & 0xFF,
|
||||||
|
(sid >> 32) & 0xFF,
|
||||||
|
(sid >> 24) & 0xFF,
|
||||||
|
(sid >> 16) & 0xFF,
|
||||||
|
(sid >> 8 ) & 0xFF,
|
||||||
|
sid & 0xFF};
|
||||||
|
|
||||||
|
memcpy(*buf + sizeof(uint64_t) + 1, sid8, sizeof(uint64_t));
|
||||||
|
|
||||||
|
Keys keys = in->keys;
|
||||||
|
uint8_t keys8 = // Reste un bit.
|
||||||
|
keys.forward & 0b10000000 |
|
||||||
|
keys.backward & 0b01000000 |
|
||||||
|
keys.left & 0b00100000 |
|
||||||
|
keys.right & 0b00010000 |
|
||||||
|
keys.jump & 0b00001000 |
|
||||||
|
keys.shoot & 0b00000100 |
|
||||||
|
keys.block & 0b00000010 ;
|
||||||
|
|
||||||
|
memcpy(*buf + sizeof(uint64_t) + 2, &keys8, sizeof(uint8_t));
|
||||||
|
|
||||||
|
uint32_t vec[3];
|
||||||
|
memcpy(vec, &in->direction, sizeof(Vector3f)); // Pour dénaturer les floats.
|
||||||
|
|
||||||
|
uint8_t vec8[3 * sizeof(uint32_t)] = {
|
||||||
|
(vec[0] >> 24) & 0xFF,
|
||||||
|
(vec[0] >> 16) & 0xFF,
|
||||||
|
(vec[0] >> 8) & 0xFF,
|
||||||
|
vec[0] & 0xFF,
|
||||||
|
(vec[1] >> 24) & 0xFF,
|
||||||
|
(vec[1] >> 16) & 0xFF,
|
||||||
|
(vec[1] >> 8) & 0xFF,
|
||||||
|
vec[1] & 0xFF,
|
||||||
|
(vec[2] >> 24) & 0xFF,
|
||||||
|
(vec[2] >> 16) & 0xFF,
|
||||||
|
(vec[2] >> 8) & 0xFF,
|
||||||
|
vec[2] & 0xFF};
|
||||||
|
|
||||||
|
memcpy(*buf + sizeof(uint64_t) + 3, vec8, sizeof(uint32_t) * 3);
|
||||||
|
|
||||||
|
*buflen = sizeof(uint64_t) + 3 + sizeof(uint32_t) * 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
void netprot::Serialize(Output* out, char* buf[], uint32_t* buflen) {
|
void netprot::Serialize(Output* out, char* buf[], uint32_t* buflen) {
|
||||||
|
@ -24,7 +24,8 @@ namespace netprot {
|
|||||||
left,
|
left,
|
||||||
right,
|
right,
|
||||||
jump,
|
jump,
|
||||||
shoot;
|
shoot,
|
||||||
|
block;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct States {
|
struct States {
|
||||||
|
Loading…
Reference in New Issue
Block a user