SQC-15_online #1
@ -37,7 +37,7 @@ void netprot::Serialize(Input* in, char* buf[], uint32_t* buflen) {
|
||||
keys.shoot & 0b00000100 |
|
||||
keys.block & 0b00000010 ;
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) + 2, &keys8, sizeof(uint8_t));
|
||||
memcpy(*buf + sizeof(uint64_t) * 2 + 1, &keys8, sizeof(uint8_t));
|
||||
|
||||
uint32_t vec[3];
|
||||
memcpy(vec, &in->direction, sizeof(Vector3f)); // Pour dénaturer les floats.
|
||||
@ -56,13 +56,13 @@ void netprot::Serialize(Input* in, char* buf[], uint32_t* buflen) {
|
||||
(vec[2] >> 8) & 0xFF,
|
||||
vec[2] & 0xFF};
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) + 3, vec8, sizeof(uint32_t) * 3);
|
||||
memcpy(*buf + sizeof(uint64_t) * 2 + 2, vec8, sizeof(uint32_t) * 3);
|
||||
|
||||
*buflen = sizeof(uint64_t) + 3 + sizeof(uint32_t) * 3;
|
||||
*buflen = sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 3;
|
||||
}
|
||||
|
||||
void netprot::Serialize(Output* out, char* buf[], uint32_t* buflen) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
|
||||
@ -308,7 +308,7 @@ bool netprot::Deserialize(Input* in, char* buf, const uint32_t buflen) {
|
||||
(uint64_t)diff[7];
|
||||
|
||||
uint8_t keys = 0;
|
||||
memcpy(&keys, &buf[2 + sizeof(uint64_t)], sizeof(uint8_t));
|
||||
memcpy(&keys, &buf[1 + sizeof(uint64_t) * 2], sizeof(uint8_t));
|
||||
in->keys.forward = keys && 0b10000000;
|
||||
in->keys.backward = keys && 0b01000000;
|
||||
in->keys.left = keys && 0b00100000;
|
||||
@ -318,7 +318,7 @@ bool netprot::Deserialize(Input* in, char* buf, const uint32_t buflen) {
|
||||
in->keys.block = keys && 0b00000010;
|
||||
|
||||
uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
|
||||
memcpy(subvec, &buf[3 + sizeof(uint64_t)], sizeof(uint8_t) * 12);
|
||||
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 |
|
||||
|
@ -118,6 +118,7 @@ namespace netprot {
|
||||
PacketType getType(char* buf, uint32_t buflen); // srv/cli
|
||||
|
||||
template <class T> void sendPack(SOCKET sock, T* pack, char** buf, uint32_t* buflen);
|
||||
template <class T> void sendPackTo(SOCKET sock, T* pack, char** buf, uint32_t* buflen, sockaddr_in* sockad);
|
||||
|
||||
template <class T>
|
||||
void sendPack(SOCKET sock, T* pack, char** buf, uint32_t* buflen) {
|
||||
@ -126,6 +127,14 @@ namespace netprot {
|
||||
*buflen = BUFFER_LENGTH;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void sendPackTo(SOCKET sock, T* pack, char** buf, uint32_t* buflen, sockaddr_in* sockad) {
|
||||
sockaddr_in addr = *sockad;
|
||||
netprot::Serialize(pack, buf, buflen);
|
||||
sendto(sock, *buf, *buflen, 0, (sockaddr*)&addr, sizeof(addr));
|
||||
*buflen = BUFFER_LENGTH;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -783,7 +783,7 @@ void Engine::Render(float elapsedTime) {
|
||||
static char* buf = new char[BUFFER_LENGTH];
|
||||
uint32_t buflen = BUFFER_LENGTH;
|
||||
netprot::Input input;
|
||||
sockaddr_in addr = m_conn.m_srvsockaddr;
|
||||
//sockaddr_in addr = m_conn.m_srvsockaddr;
|
||||
|
||||
input.direction = m_player.GetDirection();
|
||||
input.sid = m_conn.getId();
|
||||
@ -796,10 +796,10 @@ void Engine::Render(float elapsedTime) {
|
||||
input.keys.block = m_mouseR;
|
||||
input.keys.shoot = m_mouseL;
|
||||
|
||||
netprot::Serialize(&input, &buf, &buflen);
|
||||
sendto(m_conn.m_sock_udp, buf, buflen, 0, (sockaddr*)&addr, sizeof(addr));
|
||||
//netprot::Serialize(&input, &buf, &buflen);
|
||||
//sendto(m_conn.m_sock_udp, buf, buflen, 0, (sockaddr*)&addr, sizeof(addr));
|
||||
|
||||
//netprot::sendPackTo<netprot::Input>(m_conn.m_sock_udp, &input, &buf, &buflen, &m_conn.m_srvsockaddr);
|
||||
netprot::sendPackTo<netprot::Input>(m_conn.m_sock_udp, &input, &buf, &buflen, &m_conn.m_srvsockaddr);
|
||||
}
|
||||
}
|
||||
else if (m_gamestate == GameState::MAIN_MENU || m_gamestate == GameState::OPTIONS)
|
||||
|
Loading…
Reference in New Issue
Block a user