Merge branch 'SQC-15_online' of https://github.com/CegepSTH/SQCSim2023 into SQC-15_online

This commit is contained in:
Claudel-D-Roy 2023-12-06 14:31:13 -05:00
commit 2596a35af4
5 changed files with 40 additions and 28 deletions

View File

@ -181,8 +181,6 @@ void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + 1, ammo8, sizeof(uint16_t)); memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + 1, ammo8, sizeof(uint16_t));
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t) + 1, &sync->hp, sizeof(uint8_t));
uint32_t vec[3]; uint32_t vec[3];
memcpy(vec, &sync->position, sizeof(Vector3f)); // Pour d<>naturer les floats. memcpy(vec, &sync->position, sizeof(Vector3f)); // Pour d<>naturer les floats.
@ -202,7 +200,17 @@ void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t) + 2, vec8, sizeof(uint32_t) * 3); memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t) + 2, vec8, sizeof(uint32_t) * 3);
*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + 2; uint32_t hp;
memcpy(&hp, &sync->hp, sizeof(float));
uint8_t hp8[4] = {
(uint8_t)((hp >> 24) & 0xFF),
(uint8_t)((hp >> 16) & 0xFF),
(uint8_t)((hp >> 8) & 0xFF),
(uint8_t)(hp & 0xFF) };
*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float) + 1;
} }
void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) { void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) {
@ -691,7 +699,6 @@ bool netprot::Deserialize(Sync* sync, char* buf, uint32_t *buflen) {
(uint16_t)diff[0] << 8 | (uint16_t)diff[0] << 8 |
(uint16_t)diff[1]; (uint16_t)diff[1];
memcpy(&sync->hp, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t)], sizeof(uint8_t));
uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 }; 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) + sizeof(uint16_t)], sizeof(uint8_t) * 12); memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t)], sizeof(uint8_t) * 12);
@ -711,7 +718,18 @@ bool netprot::Deserialize(Sync* sync, char* buf, uint32_t *buflen) {
memcpy(&sync->position, vec, sizeof(uint32_t) * 3); memcpy(&sync->position, vec, sizeof(uint32_t) * 3);
*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + 2; uint8_t hp8[4];
memcpy(&hp8, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t)], sizeof(uint32_t));
uint32_t hp = (uint32_t)hp8[0] << 24 |
(uint32_t)hp8[1] << 16 |
(uint32_t)hp8[2] << 8 |
(uint32_t)hp8[3];
memcpy(&sync->hp, &hp, sizeof(float));
*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float);
return true; return true;
} }

View File

@ -80,7 +80,7 @@ namespace netprot {
uint64_t sid = 0; uint64_t sid = 0;
uint32_t timer = 0; uint32_t timer = 0;
uint16_t ammo = 0; uint16_t ammo = 0;
uint8_t hp = 0; float hp = 0;
Vector3f position; Vector3f position;
Sync() {} Sync() {}
Sync(Sync* sync) : timestamp(sync->timestamp), sid(sync->sid), timer(sync->timer), ammo(sync->ammo), hp(sync->hp), position(sync->position) {} Sync(Sync* sync) : timestamp(sync->timestamp), sid(sync->sid), timer(sync->timer), ammo(sync->ammo), hp(sync->hp), position(sync->position) {}
@ -125,9 +125,11 @@ namespace netprot {
uint64_t src_id = 0, uint64_t src_id = 0,
dest_id = 0, dest_id = 0,
dest_team_id = 0; dest_team_id = 0;
char mess[140]; // Good 'nough for twitr, good 'nough for me. char* mess = new char[140]; // Good 'nough for twitr, good 'nough for me.
Chat() {} Chat() {}
Chat(Chat* cha) : src_id(cha->src_id), dest_id(cha->dest_id), dest_team_id(cha->dest_team_id) { strcpy(cha->mess, mess); } Chat(Chat* cha) : src_id(cha->src_id), dest_id(cha->dest_id), dest_team_id(cha->dest_team_id) {
strcpy(mess, 140, cha->mess); }
~Chat() { delete[] mess; }
}; };
struct ChunkMod { struct ChunkMod {

View File

@ -80,9 +80,6 @@ void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*
for (auto& [key, conn] : conns) { for (auto& [key, conn] : conns) {
if (m_playinfo.id == conn->GetHash(false)) if (m_playinfo.id == conn->GetHash(false))
continue; continue;
//std::cout << m_playinfo.id << ": " << m_playinfo.name << ": " << conn->GetName() << std::endl;
//std::cout << out.id << ": " << out.position << std::endl;
sendPackTo<Output>(sock, &out, &m_bufout, conn->getAddr()); sendPackTo<Output>(sock, &out, &m_bufout, conn->getAddr());
} }
++outs; ++outs;
@ -142,8 +139,8 @@ Timestamp Connection::Run(World* world) {
in.keys.right, in.keys.right,
in.keys.jump, false, el), world, el); in.keys.jump, false, el), world, el);
if (player->GetPosition().y < -10.) { if (player->GetPosition().y < -20.) {
player->InflictDamage(9000); player->InflictDamage(9000.);
player->Killer = GetHash(true); player->Killer = GetHash(true);
} }

View File

@ -276,16 +276,14 @@ void Server::Run() {
Chat* chat = new Chat(); Chat* chat = new Chat();
chat->dest_id = chat->dest_team_id = chat->src_id = 0; chat->dest_id = chat->dest_team_id = chat->src_id = 0;
std::string killer = m_conns.at(key)->player->GetUsername(); std::string killer = m_conns.at(conn->player->Killer)->player->GetUsername();
std::string mess = getDeathMessage(conn->player->GetUsername(), killer); std::string mess = getDeathMessage(conn->player->GetUsername(), killer);
strcpy(chat->mess, 140, mess.c_str()); strcpy(chat->mess, 140, mess.c_str());
Log(mess, false, false);
chatlog.emplace_back(chat); chatlog.emplace_back(chat);
++deadplayers; ++deadplayers;
conn->m_nsync == false; conn->m_nsync = false;
} }
else { else {
for (auto& chmo : conn->ChunkDiffs) for (auto& chmo : conn->ChunkDiffs)
@ -342,12 +340,6 @@ void Server::Run() {
delete chmo; delete chmo;
} }
//for (auto& bull : outbox_bullets)
//delete bull;
//for (auto& bull : netbull)
//delete bull;
outbox_bullets.clear(); outbox_bullets.clear();
netbull.clear(); netbull.clear();
chunkdiffs.clear(); chunkdiffs.clear();
@ -358,7 +350,7 @@ void Server::Run() {
end.src_id = 0; end.src_id = 0;
char endmess[] = "Game over, mothereffers."; char endmess[] = "Game over, mothereffers.";
strcpy(end.mess, endmess); strcpy(end.mess, 140, endmess);
for (auto& [key, conn] : m_conns) for (auto& [key, conn] : m_conns)
sendPackTo<Chat>(m_sock_udp, &end, &m_buf, conn->getAddr()); sendPackTo<Chat>(m_sock_udp, &end, &m_buf, conn->getAddr());
@ -451,6 +443,7 @@ std::string Server::getDeathMessage(std::string username, std::string killer) co
mess.append(killer); mess.append(killer);
mess.append(temp.substr(indk + 1)); mess.append(temp.substr(indk + 1));
} }
else mess.append(temp.substr(ind + 1));
} }
else { else {
mess.append(temp.substr(0, indk)); mess.append(temp.substr(0, indk));

View File

@ -1332,8 +1332,6 @@ void Engine::Render(float elapsedTime) {
if (m_isSkybox) m_skybox.Render(skybox); if (m_isSkybox) m_skybox.Render(skybox);
DrawHud(elapsedTime, bloc);
DisplayPovGun();
ProcessNotificationQueue(); ProcessNotificationQueue();
if (m_damage) { if (m_damage) {
InstantDamage(); InstantDamage();
@ -1420,8 +1418,9 @@ void Engine::Render(float elapsedTime) {
} }
if (m_syncs.count(sync.timestamp)) { if (m_syncs.count(sync.timestamp)) {
Sync comp = m_syncs[sync.timestamp]; Sync comp = m_syncs[sync.timestamp];
m_player.InflictDamage(sync.hp - comp.hp);
std::cout << "HP: " << sync.hp << std::endl;
//m_player.InflictDamage(sync.hp - comp.hp);
Vector3f diff = sync.position - comp.position; Vector3f diff = sync.position - comp.position;
@ -1502,6 +1501,9 @@ void Engine::Render(float elapsedTime) {
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
} }
DrawHud(elapsedTime, bloc);
DisplayPovGun();
} }
} }