Hahaha il manquait les ChunkMods dans netprot :finnadie:
This commit is contained in:
parent
c44d1453ae
commit
20eb410b08
@ -402,6 +402,33 @@ void netprot::Serialize(Chat* chat, char* buf[], uint32_t* buflen) {
|
||||
*buflen = messize + sizeof(uint64_t) * 3 + 2;
|
||||
}
|
||||
|
||||
void netprot::Serialize(ChunkMod* chmod, char* buf[], uint32_t* buflen) {
|
||||
*buf[0] = (char)netprot::PACKET_TYPE::CHUNKMOD;
|
||||
|
||||
uint32_t vec[3];
|
||||
memcpy(vec, &chmod->pos, 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 + 1, vec8, sizeof(uint32_t) * 3);
|
||||
|
||||
memcpy(*buf + sizeof(uint32_t) * 3 + 1, &chmod->b_type, sizeof(BlockType));
|
||||
|
||||
*buflen = sizeof(uint32_t) * 3 + 2;
|
||||
}
|
||||
|
||||
void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) {
|
||||
*buf[0] = (char)netprot::PACKET_TYPE::ERRLOG;
|
||||
|
||||
@ -818,6 +845,35 @@ bool netprot::Deserialize(Chat* chat, char* buf, uint32_t *buflen) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool netprot::Deserialize(ChunkMod* chmod, char* buf, uint32_t* buflen) {
|
||||
if (*buflen <= sizeof(ChunkMod))
|
||||
return false;
|
||||
|
||||
uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
|
||||
memcpy(subvec, &buf[1], 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(&chmod->pos, vec, sizeof(uint32_t) * 3);
|
||||
|
||||
memcpy(&chmod->b_type, &buf[1 + sizeof(uint8_t) * 12], sizeof(BlockType));
|
||||
|
||||
*buflen = sizeof(uint32_t) * 3 + 2;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool netprot::Deserialize(ErrorLog* errlog, char* buf, uint32_t *buflen) {
|
||||
if (*buflen <= sizeof(ErrorLog))
|
||||
return false;
|
||||
|
@ -130,6 +130,11 @@ namespace netprot {
|
||||
Chat(Chat* cha) : src_id(cha->src_id), dest_id(cha->dest_id), dest_team_id(cha->dest_team_id) { strcpy(cha->mess, mess); }
|
||||
};
|
||||
|
||||
struct ChunkMod {
|
||||
Vector3f pos;
|
||||
BlockType b_type;
|
||||
};
|
||||
|
||||
struct ErrorLog { // srv -> cli TCP event
|
||||
char mess[140];
|
||||
bool is_fatal;
|
||||
@ -147,6 +152,7 @@ namespace netprot {
|
||||
void Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen); // srv
|
||||
void Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen); // cli/srv
|
||||
void Serialize(Chat* chat, char* buf[], uint32_t* buflen); // cli/srv
|
||||
void Serialize(ChunkMod* chmod, char* buf[], uint32_t* buflen); // srv
|
||||
void Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen); // srv
|
||||
|
||||
bool Deserialize(Input* in, char* buf, uint32_t* buflen); // srv
|
||||
@ -157,6 +163,7 @@ namespace netprot {
|
||||
bool Deserialize(PlayerInfo* pinfo, char* buf, uint32_t* buflen); // cli
|
||||
bool Deserialize(GameInfo* ginfo, char* buf, uint32_t* buflen); // cli
|
||||
bool Deserialize(Chat* chat, char* buf, uint32_t* buflen); // srv/cli
|
||||
bool Deserialize(ChunkMod* chmod, char* buf, uint32_t* buflen); // cli
|
||||
bool Deserialize(ErrorLog* errlog, char* buf, uint32_t* buflen); // srv
|
||||
|
||||
PACKET_TYPE getType(char* buf, uint32_t buflen);
|
||||
|
@ -122,9 +122,7 @@ void Connection::Run(World* world) {
|
||||
last = m_input_vector.at(m_last_in);
|
||||
|
||||
el = (double)(in.timestamp - last.timestamp) / 1000.;
|
||||
std::cout << 1. / el << std::endl;
|
||||
player.get()->SetDirection(in.direction);
|
||||
std::cout << in.direction << std::endl;
|
||||
player.get()->ApplyPhysics(player.get()->GetInput(in.keys.forward,
|
||||
in.keys.backward,
|
||||
in.keys.left,
|
||||
@ -132,7 +130,6 @@ void Connection::Run(World* world) {
|
||||
in.keys.jump, false, el), world, el);
|
||||
|
||||
out.position = player.get()->GetPositionAbs();
|
||||
player.get()->GetPositionAbs().Afficher();
|
||||
out.direction = in.direction;
|
||||
out.timestamp = in.timestamp;
|
||||
out.id = m_playinfo.id;
|
||||
|
@ -41,6 +41,10 @@ public:
|
||||
void CleanInputManifest(Timestamp time);
|
||||
|
||||
bool m_nsync = true;
|
||||
|
||||
std::vector<Bullet> m_bullet_vector;
|
||||
std::vector<ChunkMod> m_diff_vector;
|
||||
|
||||
private:
|
||||
std::unordered_map<Timestamp, Input> m_input_manifest;
|
||||
std::vector<Input> m_input_vector;
|
||||
@ -48,6 +52,7 @@ private:
|
||||
std::deque<Output> m_output_vector;
|
||||
std::unordered_map<Timestamp, Chat> m_chatlog;
|
||||
|
||||
|
||||
SOCKET m_sock;
|
||||
sockaddr_in m_addr;
|
||||
LoginInfo m_loginfo;
|
||||
|
@ -230,6 +230,9 @@ void Server::Run() {
|
||||
}
|
||||
|
||||
for (auto& [key, conn] : m_players) {
|
||||
|
||||
/* In */
|
||||
|
||||
int deadplayers = 0;
|
||||
std::vector<char*> lsPck;
|
||||
Input in; Chat chat; Sync sync;
|
||||
@ -254,6 +257,8 @@ void Server::Run() {
|
||||
}
|
||||
lsPck.clear();
|
||||
|
||||
/* Process */
|
||||
|
||||
if (conn->m_nsync) {
|
||||
if (conn->player->AmIDead()) {
|
||||
++deadplayers;
|
||||
@ -261,6 +266,9 @@ void Server::Run() {
|
||||
continue;
|
||||
}
|
||||
conn->Run(m_world);
|
||||
|
||||
/* Out */
|
||||
|
||||
conn->sendPacks(m_sock_udp, m_players, timer);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user