Jim Babwe

This commit is contained in:
MarcEricMartel 2023-11-24 14:15:40 -05:00
parent bd14cd3962
commit 573316682b
4 changed files with 14 additions and 9 deletions

View File

@ -471,8 +471,6 @@ bool netprot::Deserialize(Input* in, char* buf, uint32_t *buflen) {
memcpy(&in->direction, vec, sizeof(uint32_t) * 3); memcpy(&in->direction, vec, sizeof(uint32_t) * 3);
in->direction.Afficher();
*buflen = sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 3; *buflen = sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 3;
return true; return true;

View File

@ -52,6 +52,10 @@ void Connection::getPacks(SOCKET sock) {
Input in; Input in;
while (true) { while (true) {
lsPck = recvPacksFrom(sock, &m_buf, m_addr); lsPck = recvPacksFrom(sock, &m_buf, m_addr);
if (lsPck.empty() && !m_buf.tmp)
break;
for (auto& pck : lsPck) { for (auto& pck : lsPck) {
uint32_t bsize = m_buf.len - (pck - m_buf.ptr); uint32_t bsize = m_buf.len - (pck - m_buf.ptr);
switch (netprot::getType(pck, 1)) { switch (netprot::getType(pck, 1)) {
@ -59,8 +63,7 @@ void Connection::getPacks(SOCKET sock) {
case INPUT: case INPUT:
if (Deserialize(&in, pck, &bsize)) { if (Deserialize(&in, pck, &bsize)) {
m_input_manifest[in.timestamp] = in; m_input_manifest[in.timestamp] = in;
if (in.keys.forward == true) m_input_vector.push_back(in);
std::cout << "!!!!";
} }
break; break;
default: break; default: break;
@ -72,8 +75,7 @@ void Connection::getPacks(SOCKET sock) {
void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*> conns) { void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*> conns) {
while (m_last_out < m_output_manifest.size()) { while (m_last_out < m_output_manifest.size()) {
Output out = m_output_manifest.at(m_last_out++); Output out = m_output_vector.at(m_last_out++);
std::cout << "bip";
for (auto& [key, conn] : conns) { for (auto& [key, conn] : conns) {
if (m_playinfo.id == conn->GetHash(true)) if (m_playinfo.id == conn->GetHash(true))
continue; continue;
@ -90,9 +92,9 @@ void Connection::Run(World* world) {
if (m_input_manifest.size() < 2) if (m_input_manifest.size() < 2)
return; return;
while (m_last_in < m_input_manifest.size()) { while (m_last_in < m_input_vector.size() - 1) {
in = m_input_manifest.at(m_last_in + 1); in = m_input_vector.at(m_last_in + 1);
last = m_input_manifest.at(m_last_in); last = m_input_vector.at(m_last_in);
el = (float)(in.timestamp - last.timestamp) / 1000.; el = (float)(in.timestamp - last.timestamp) / 1000.;
player.get()->SetDirection(in.direction); player.get()->SetDirection(in.direction);
@ -108,6 +110,7 @@ void Connection::Run(World* world) {
out.id = m_playinfo.id; out.id = m_playinfo.id;
m_output_manifest[out.timestamp] = out; m_output_manifest[out.timestamp] = out;
m_output_vector.push_back(out);
++m_last_in; ++m_last_in;
} }

View File

@ -41,7 +41,9 @@ public:
void CleanInputManifest(Timestamp time); void CleanInputManifest(Timestamp time);
private: private:
std::unordered_map<Timestamp, Input> m_input_manifest; std::unordered_map<Timestamp, Input> m_input_manifest;
std::vector<Input> m_input_vector;
std::unordered_map<Timestamp, Output> m_output_manifest; std::unordered_map<Timestamp, Output> m_output_manifest;
std::vector<Output> m_output_vector;
std::unordered_map<Timestamp, Chat> m_chatlog; std::unordered_map<Timestamp, Chat> m_chatlog;
SOCKET m_sock; SOCKET m_sock;

View File

@ -201,6 +201,8 @@ void Server::Run() {
sendPack<Sync>(conn->getSock(), &sync, &m_buf); sendPack<Sync>(conn->getSock(), &sync, &m_buf);
} }
std::cout << players << " players." << std::endl;
while (!endgame) { while (!endgame) {
for (auto& [key, conn] : m_players) { for (auto& [key, conn] : m_players) {
conn->getPacks(m_sock_udp); conn->getPacks(m_sock_udp);