From fd1fe66d1397d551d0d9977852a924225d514deb Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Wed, 13 Dec 2023 14:27:11 -0500 Subject: [PATCH] SYNC_ACC CMOD_ACC GLOBALS --- SQCSim-common/define.h | 3 +++ SQCSim-srv/connection.cpp | 16 ++++++++-------- SQCSim-srv/server.cpp | 16 +++++++--------- SQCSim2021/engine.cpp | 10 +++++----- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h index 685bf5d..7dfc7ec 100644 --- a/SQCSim-common/define.h +++ b/SQCSim-common/define.h @@ -37,6 +37,9 @@ #define STRENGTH_SPEED_BOOST 10 //Pourcentage #define BULLET_TIME .1 +#define SYNC_ACC 200 +#define CMOD_ACC 1500 + typedef uint8_t BlockType; enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_GREENGRASS, BTYPE_LAST }; typedef uint8_t BoostType; diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp index ce6b02f..5587ea8 100644 --- a/SQCSim-srv/connection.cpp +++ b/SQCSim-srv/connection.cpp @@ -91,8 +91,8 @@ void Connection::sendPacks(SOCKET sock, std::unordered_map= 200) { - outs -= 200; + if (outs >= 50) { + outs -= 50; Sync sync; sync.hp = player->GetHP(); sync.timestamp = out.timestamp; @@ -117,15 +117,15 @@ Timestamp Connection::Run(World* world) { if (m_input_manifest.size() < 2) return tstamp; - //if (player->AmIDead()) { - // m_input_manifest.clear(); - // return tstamp; - //} - while (m_last_in < m_input_vector.size() - 1) { in = m_input_vector.at(m_last_in + 1); last = m_input_vector.at(m_last_in); + if (in.timestamp <= m_tstamp) { + ++m_last_in; + continue; + } + el = (double)(in.timestamp - last.timestamp) / 1000.; if (m_shoot_acc > 0.) { @@ -190,7 +190,7 @@ Timestamp Connection::Run(World* world) { out.id = m_playinfo.id; m_output_manifest[out.timestamp] = out; m_output_vector.push_back(out); - tstamp = out.timestamp; + m_tstamp = tstamp = out.timestamp; ++m_last_in; } diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index b997b12..e596144 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -242,9 +242,9 @@ void Server::Run() { if (last == 0) last = tstamp; sync_acc += tstamp - last; - if (sync_acc >= 1000) { - while (sync_acc >= 1000) - sync_acc -= 1000; + if (sync_acc >= SYNC_ACC) { + while (sync_acc >= SYNC_ACC) + sync_acc -= SYNC_ACC; --timer; std::string str = "Timer: "; Log(str.append(std::to_string(timer)), false, false); @@ -304,7 +304,6 @@ void Server::Run() { for (auto& bull : conn->Bullets) { bullets.emplace_back(bull); - //Log("POW!", false, false); BulletAdd* nbul = new BulletAdd(); nbul->pos = bull->getPos(); nbul->dir = bull->getVel(); @@ -315,12 +314,11 @@ void Server::Run() { } conn->Bullets.clear(); } - - /* Out */ - - conn->sendPacks(m_sock_udp, m_conns, timer); } - if ((deadplayers == players - 1 && deadplayers != 0) || timer <= 0) + /* Out */ + conn->sendPacks(m_sock_udp, m_conns, timer); + + if ((deadplayers == players - 1 && deadplayers != 0) || timer < 0) endgame = true; } diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 44f5fd9..1e36ead 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -1454,8 +1454,8 @@ void Engine::Render(float elapsedTime) { cmod_acc += tstamp - last; last = tstamp; - if (sync_acc >= 200) { - sync_acc -= 200; + if (sync_acc >= SYNC_ACC) { + sync_acc -= SYNC_ACC; sync.sid = id; sync.timestamp = tstamp; sync.position = m_player.GetPositionAbs(); @@ -1467,9 +1467,9 @@ void Engine::Render(float elapsedTime) { m_syncs[sync.timestamp] = sync; } - if (cmod_acc >= 2000) { - while (cmod_acc >= 2000) - cmod_acc -= 2000; + if (cmod_acc >= CMOD_ACC) { + while (cmod_acc >= CMOD_ACC) + cmod_acc -= CMOD_ACC; if (!m_chunkmod_manifest.empty()) { ChunkMod* cmod = m_chunkmod_manifest.front(); m_chunkmod_manifest.pop_front();