ser/deser dood, wat nou?
This commit is contained in:
parent
78f7974f1c
commit
3db59a876c
@ -88,7 +88,57 @@ void netprot::Serialize(Output* out, char* buf[], uint32_t* buflen) {
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) + 1, sid8, sizeof(uint64_t));
|
||||
|
||||
// TODO: Finir ca.
|
||||
States states = out->states;
|
||||
uint8_t states8 =
|
||||
states.jumping & 0b10000000 |
|
||||
states.shooting & 0b01000000 |
|
||||
states.hit & 0b00100000 |
|
||||
states.powerup & 0b00010000 |
|
||||
states.dead & 0b00001000 |
|
||||
states.still & 0b00000100 |
|
||||
states.jumpshot & 0b00000010 |
|
||||
states.running & 0b00000001;
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) * 2 + 1, &states8, sizeof(uint8_t));
|
||||
|
||||
uint32_t vec[3];
|
||||
memcpy(vec, &out->direction, sizeof(Vector3f)); // Pour d<>naturer les floats.
|
||||
|
||||
uint8_t vec8[3 * sizeof(uint32_t)] = {
|
||||
(uint8_t)((vec[0] >> 24) & 0xFF),
|
||||
(uint8_t)((vec[0] >> 16) & 0xFF),
|
||||
(uint8_t)((vec[0] >> 8) & 0xFF),
|
||||
(uint8_t)(vec[0] & 0xFF),
|
||||
(uint8_t)((vec[1] >> 24) & 0xFF),
|
||||
(uint8_t)((vec[1] >> 16) & 0xFF),
|
||||
(uint8_t)((vec[1] >> 8) & 0xFF),
|
||||
(uint8_t)(vec[1] & 0xFF),
|
||||
(uint8_t)((vec[2] >> 24) & 0xFF),
|
||||
(uint8_t)((vec[2] >> 16) & 0xFF),
|
||||
(uint8_t)((vec[2] >> 8) & 0xFF),
|
||||
(uint8_t)(vec[2] & 0xFF) };
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) * 2 + 2, vec8, sizeof(uint32_t) * 3);
|
||||
|
||||
memcpy(vec, &out->position, sizeof(Vector3f)); // Pour d<>naturer les floats.
|
||||
|
||||
uint8_t vec82[3 * sizeof(uint32_t)] = {
|
||||
(uint8_t)((vec[0] >> 24) & 0xFF),
|
||||
(uint8_t)((vec[0] >> 16) & 0xFF),
|
||||
(uint8_t)((vec[0] >> 8) & 0xFF),
|
||||
(uint8_t)(vec[0] & 0xFF),
|
||||
(uint8_t)((vec[1] >> 24) & 0xFF),
|
||||
(uint8_t)((vec[1] >> 16) & 0xFF),
|
||||
(uint8_t)((vec[1] >> 8) & 0xFF),
|
||||
(uint8_t)(vec[1] & 0xFF),
|
||||
(uint8_t)((vec[2] >> 24) & 0xFF),
|
||||
(uint8_t)((vec[2] >> 16) & 0xFF),
|
||||
(uint8_t)((vec[2] >> 8) & 0xFF),
|
||||
(uint8_t)(vec[2] & 0xFF) };
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 3, vec82, sizeof(uint32_t) * 3);
|
||||
|
||||
*buflen = sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 6;
|
||||
}
|
||||
|
||||
void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
|
||||
@ -427,7 +477,98 @@ bool netprot::Deserialize(Input* in, char* buf, uint32_t *buflen) {
|
||||
}
|
||||
|
||||
bool netprot::Deserialize(Output* out, char* buf, uint32_t *buflen) {
|
||||
return false;
|
||||
if (*buflen <= sizeof(Output))
|
||||
return false;
|
||||
|
||||
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
|
||||
memcpy(diff, &buf[1], sizeof(uint64_t));
|
||||
out->timestamp =
|
||||
(uint64_t)diff[0] << 56 |
|
||||
(uint64_t)diff[1] << 48 |
|
||||
(uint64_t)diff[2] << 40 |
|
||||
(uint64_t)diff[3] << 32 |
|
||||
(uint64_t)diff[4] << 24 |
|
||||
(uint64_t)diff[5] << 16 |
|
||||
(uint64_t)diff[6] << 8 |
|
||||
(uint64_t)diff[7];
|
||||
|
||||
memcpy(diff, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t));
|
||||
out->id =
|
||||
(uint64_t)diff[0] << 56 |
|
||||
(uint64_t)diff[1] << 48 |
|
||||
(uint64_t)diff[2] << 40 |
|
||||
(uint64_t)diff[3] << 32 |
|
||||
(uint64_t)diff[4] << 24 |
|
||||
(uint64_t)diff[5] << 16 |
|
||||
(uint64_t)diff[6] << 8 |
|
||||
(uint64_t)diff[7];
|
||||
|
||||
uint8_t states = 0;
|
||||
memcpy(&states, &buf[1 + sizeof(uint64_t) * 2], sizeof(uint8_t));
|
||||
out->states.jumping = states & 0b10000000;
|
||||
out->states.shooting = states & 0b01000000;
|
||||
out->states.hit = states & 0b00100000;
|
||||
out->states.dead = states & 0b00010000;
|
||||
out->states.still = states & 0b00001000;
|
||||
out->states.jumpshot = states & 0b00000100;
|
||||
out->states.running = states & 0b00000010;
|
||||
|
||||
uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
|
||||
memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2], sizeof(uint8_t) * 12);
|
||||
uint32_t vec[3] = {
|
||||
(uint32_t)subvec[0] << 24 |
|
||||
(uint32_t)subvec[1] << 16 |
|
||||
(uint32_t)subvec[2] << 8 |
|
||||
(uint32_t)subvec[3],
|
||||
(uint32_t)subvec[4] << 24 |
|
||||
(uint32_t)subvec[5] << 16 |
|
||||
(uint32_t)subvec[6] << 8 |
|
||||
(uint32_t)subvec[7],
|
||||
(uint32_t)subvec[8] << 24 |
|
||||
(uint32_t)subvec[9] << 16 |
|
||||
(uint32_t)subvec[10] << 8 |
|
||||
(uint32_t)subvec[11] };
|
||||
|
||||
memcpy(&out->direction, vec, sizeof(uint32_t) * 3);
|
||||
|
||||
uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
|
||||
memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 3], sizeof(uint8_t) * 12);
|
||||
uint32_t vec[3] = {
|
||||
(uint32_t)subvec[0] << 24 |
|
||||
(uint32_t)subvec[1] << 16 |
|
||||
(uint32_t)subvec[2] << 8 |
|
||||
(uint32_t)subvec[3],
|
||||
(uint32_t)subvec[4] << 24 |
|
||||
(uint32_t)subvec[5] << 16 |
|
||||
(uint32_t)subvec[6] << 8 |
|
||||
(uint32_t)subvec[7],
|
||||
(uint32_t)subvec[8] << 24 |
|
||||
(uint32_t)subvec[9] << 16 |
|
||||
(uint32_t)subvec[10] << 8 |
|
||||
(uint32_t)subvec[11] };
|
||||
|
||||
memcpy(&out->direction, vec, sizeof(uint32_t) * 3);
|
||||
|
||||
memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 6], sizeof(uint8_t) * 12);
|
||||
uint32_t vec2[3] = {
|
||||
(uint32_t)subvec[0] << 24 |
|
||||
(uint32_t)subvec[1] << 16 |
|
||||
(uint32_t)subvec[2] << 8 |
|
||||
(uint32_t)subvec[3],
|
||||
(uint32_t)subvec[4] << 24 |
|
||||
(uint32_t)subvec[5] << 16 |
|
||||
(uint32_t)subvec[6] << 8 |
|
||||
(uint32_t)subvec[7],
|
||||
(uint32_t)subvec[8] << 24 |
|
||||
(uint32_t)subvec[9] << 16 |
|
||||
(uint32_t)subvec[10] << 8 |
|
||||
(uint32_t)subvec[11] };
|
||||
|
||||
memcpy(&out->position, vec2, sizeof(uint32_t) * 3);
|
||||
|
||||
*buflen = sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 6;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool netprot::Deserialize(Sync* sync, char* buf, uint32_t *buflen) {
|
||||
|
@ -107,8 +107,6 @@ int Connector::Connect(const char* srv_addr, std::string name) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
//if (lsPck.empty())
|
||||
//errors++;
|
||||
lsPck.clear();
|
||||
if (errors > 1000)
|
||||
return 4;
|
||||
|
Loading…
Reference in New Issue
Block a user