From c9ebfd348cb135da5f315706ecd06687d9d8c689 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Wed, 13 Dec 2023 12:38:19 -0500 Subject: [PATCH 01/47] woups --- SQCSim2021/remoteplayer.cpp | 4 ++-- SQCSim2021/remoteplayer.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index 47bd809..3affaae 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -8,11 +8,11 @@ -RemotePlayer::RemotePlayer(netprot::PlayerInfo pinfo) : m_pinfo(pinfo), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), previous(), m_texture_front(), Player(Vector3f(0, 0, 0)){ +RemotePlayer::RemotePlayer(netprot::PlayerInfo* pinfo) : m_pinfo(*pinfo), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), previous(), m_texture_front(), Player(Vector3f(0, 0, 0)){ } -RemotePlayer::RemotePlayer(netprot::PlayerInfo pinfo, const Vector3f& pos) : m_pinfo(pinfo), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), previous(), m_texture_front(), Player(pos) { +RemotePlayer::RemotePlayer(netprot::PlayerInfo* pinfo, const Vector3f& pos) : m_pinfo(*pinfo), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), previous(), m_texture_front(), Player(pos) { } diff --git a/SQCSim2021/remoteplayer.h b/SQCSim2021/remoteplayer.h index fcd5626..238360b 100644 --- a/SQCSim2021/remoteplayer.h +++ b/SQCSim2021/remoteplayer.h @@ -14,8 +14,8 @@ class RemotePlayer : public Player { public: enum Anim: uint8_t { STILL = 1, RUNNING = 2, JUMPING = 4, SHOOTING = 8, POWERUP = 16, DEAD = 32 }; // A REVOIR VOIR DEFINE.H POUR LES ANIMES - RemotePlayer(netprot::PlayerInfo pinfo); - RemotePlayer(netprot::PlayerInfo pinfo, const Vector3f& pos); + RemotePlayer(netprot::PlayerInfo* pinfo); + RemotePlayer(netprot::PlayerInfo* pinfo, const Vector3f& pos); ~RemotePlayer(); From 7ffccc8bf8485f4f5b250883ebe631ee7eb1cdf2 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Wed, 13 Dec 2023 12:39:24 -0500 Subject: [PATCH 02/47] woups^2 --- SQCSim2021/engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index d27ca25..20dde9b 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -609,7 +609,7 @@ bool Engine::StartMultiplayerGame() { m_player = Player(m_conn.getOrigin().position); for (auto& [key, player] : m_conn.m_players) - m_players[key] = new RemotePlayer(player); + m_players[key] = new RemotePlayer(&player); //m_world.SetSeed(m_conn.getSeed()); m_world.SetSeed(9370707); From a6b6ac870a176c16608c0ba1f0d673fc7bc383a3 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Wed, 13 Dec 2023 13:01:52 -0500 Subject: [PATCH 03/47] Update sync plus vite. --- SQCSim-srv/connection.cpp | 4 ++-- SQCSim2021/engine.cpp | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp index 669ae8f..1c823ce 100644 --- a/SQCSim-srv/connection.cpp +++ b/SQCSim-srv/connection.cpp @@ -91,8 +91,8 @@ void Connection::sendPacks(SOCKET sock, std::unordered_map= 1000) { - outs -= 1000; + if (outs >= 200) { + outs -= 200; Sync sync; sync.hp = player->GetHP(); sync.timestamp = out.timestamp; diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 5a7a186..b22fd26 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -1453,8 +1453,8 @@ void Engine::Render(float elapsedTime) { cmod_acc += tstamp - last; last = tstamp; - if (sync_acc >= 1000) { - sync_acc -= 1000; + if (sync_acc >= 200) { + sync_acc -= 200; sync.sid = id; sync.timestamp = tstamp; sync.position = m_player.GetPositionAbs(); @@ -1466,9 +1466,9 @@ void Engine::Render(float elapsedTime) { m_syncs[sync.timestamp] = sync; } - if (cmod_acc >= 3000) { - while (cmod_acc >= 3000) - cmod_acc -= 3000; + if (cmod_acc >= 2000) { + while (cmod_acc >= 2000) + cmod_acc -= 2000; if (!m_chunkmod_manifest.empty()) { ChunkMod* cmod = m_chunkmod_manifest.front(); m_chunkmod_manifest.pop_front(); @@ -1511,7 +1511,7 @@ void Engine::Render(float elapsedTime) { Sync comp = m_syncs[sync.timestamp]; std::cout << sync.hp << std::endl; - + m_otherplayerpos = sync.position; m_player.InflictDamage(sync.hp - comp.hp); Vector3f diff = sync.position - comp.position; From 64655856e9f3779e86efa1d5269ff9c9b7875fa3 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Wed, 13 Dec 2023 13:13:34 -0500 Subject: [PATCH 04/47] gniah. --- SQCSim2021/engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index b22fd26..89a4029 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -379,7 +379,7 @@ void Engine::DisplayHud(int timer) { // HP Bar float playerHp = m_player.GetHP(); if (playerHp < 0.) - playerHp == 0; + playerHp = 0; float facteurOmbrage = m_displayInfo ? 0.5f : 1.0f; float hpBarWidthProportion = 0.25f; From 8fbb92ec5b8a77e7dcf2bb58bcbb520bb063d8d1 Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Wed, 13 Dec 2023 13:17:29 -0500 Subject: [PATCH 05/47] ghfudk --- SQCSim2021/remoteplayer.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index 3affaae..321c64d 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -124,17 +124,15 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr bool isLeft = side.y > 0; time += elapsedTime; - if (time >= 200) + if (time >= 100) { - time -= 200; + time -= 100; if (!current.states.shooting) Shooting = false; else Shooting = !Shooting; } - - if (angle >= 0.75) //Face - side positif { if(current.states.shooting){ @@ -142,6 +140,8 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr index = 17; else index = 9; + + std::cout << "face" << std::endl; } else if (current.states.jumpshot) { if (Shooting) @@ -162,6 +162,8 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr index = 18; else index = 10; + + std::cout << "Frontleft" << std::endl; } else if (current.states.jumpshot) { if (Shooting) @@ -182,6 +184,9 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr index = 20; else index = 12; + + std::cout << "ProfileLeft" << std::endl; + } else if (current.states.jumpshot ) { if (Shooting) @@ -202,6 +207,8 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr index = 22; else index = 14; + + std::cout << "BackLeft" << std::endl; } else if (current.states.jumpshot) { if (Shooting) @@ -221,6 +228,8 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr index = 24; else index = 16; + + std::cout << "Dos" << std::endl; } else if (current.states.jumpshot) { if (Shooting) @@ -241,6 +250,8 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr index = 19; else index = 11; + + std::cout << "FrontRight" << std::endl; } else if (current.states.jumpshot) { if (Shooting) @@ -261,6 +272,8 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr index = 21; else index = 13; + + std::cout << "ProfileRight" << std::endl; } else if (current.states.jumpshot) { if (Shooting) @@ -281,6 +294,10 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr index = 23; else index = 15; + + std::cout << "BackRight" << std::endl; + + } else if (current.states.jumpshot) { if (Shooting) From 0e45b2b81e32487dfffa7a812ced6bc27cea5dcc Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Wed, 13 Dec 2023 13:33:44 -0500 Subject: [PATCH 06/47] essaie no. 89657657457 --- SQCSim2021/remoteplayer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index 321c64d..9ed594c 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -130,9 +130,11 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr if (!current.states.shooting) Shooting = false; else - Shooting = !Shooting; + Shooting = true; } + std::cout << "shooting : " << current.states.shooting << " jumping : " << current.states.jumping << " jumpshot : " << current.states.jumpshot << " running : " << current.states.running << " still : " << current.states.still << " dead : " << current.states.dead << " hit : " << current.states.hit << std::endl; + if (angle >= 0.75) //Face - side positif { if(current.states.shooting){ From 83fc600ce2591c580bb6ccc7872b40c92aaffa13 Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Wed, 13 Dec 2023 13:46:57 -0500 Subject: [PATCH 07/47] l;kjhgfd --- SQCSim2021/remoteplayer.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index 9ed594c..8dd4676 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -153,7 +153,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr } else if (current.states.jumping) index = 25; - else if (current.states.running && current.states.still) + else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 0; } @@ -175,7 +175,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr } else if (current.states.jumping ) index = 26; - else if (current.states.running && current.states.still) + else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 1; } @@ -198,7 +198,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr } else if (current.states.jumping ) index = 28; - else if (current.states.running && current.states.still) + else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 3; } @@ -220,7 +220,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr } else if (current.states.jumping) index = 30; - else if (current.states.running && current.states.still) + else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 5; } else if (angle < -0.75) //Dos - side négatif @@ -241,7 +241,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr } else if (current.states.jumping ) index = 32; - else if (current.states.running && current.states.still) + else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 7; } @@ -263,7 +263,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr } else if (current.states.jumping) index = 27; - else if (current.states.running && current.states.still) + else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 2; } @@ -285,7 +285,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr } else if (current.states.jumping) index = 29; - else if (current.states.running && current.states.still) + else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 4; } @@ -309,7 +309,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr } else if (current.states.jumping) index = 31; - else if (current.states.running && current.states.still) + else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 6; } From 18d6d58203fc06464f57a34b8cc9331a3838a6a0 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Wed, 13 Dec 2023 13:47:34 -0500 Subject: [PATCH 08/47] There's a bullet without my name on it. --- SQCSim-common/bullet.cpp | 8 ++++++-- SQCSim-common/bullet.h | 3 +++ SQCSim-srv/connection.cpp | 2 +- SQCSim-srv/server.cpp | 10 ++++++---- SQCSim2021/engine.cpp | 11 +++++++++-- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/SQCSim-common/bullet.cpp b/SQCSim-common/bullet.cpp index a489c55..53fe339 100644 --- a/SQCSim-common/bullet.cpp +++ b/SQCSim-common/bullet.cpp @@ -3,7 +3,10 @@ Bullet::Bullet(Vector3f pos, Vector3f dir) : m_startpos(pos), m_currentpos(pos), m_velocity(dir) {} -Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t shooter_id): m_startpos(pos), m_currentpos(pos), m_velocity(dir), m_shooter_id(shooter_id) {} +Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t shooter_id) : m_startpos(pos), m_currentpos(pos), m_velocity(dir), m_shooter_id(shooter_id) {} + + +Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t shooter_id, bool canhurt): m_startpos(pos), m_currentpos(pos), m_velocity(dir), m_shooter_id(shooter_id), m_canhurt(canhurt) {} Bullet::~Bullet() {} @@ -23,7 +26,8 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordere hit = true; } if (hit && !player->AmIDead()) { - player->InflictDamage(damage); + if (m_canhurt) + player->InflictDamage(damage); player->m_hit = true; if (player->AmIDead()) diff --git a/SQCSim-common/bullet.h b/SQCSim-common/bullet.h index 3f875d9..252fd70 100644 --- a/SQCSim-common/bullet.h +++ b/SQCSim-common/bullet.h @@ -14,6 +14,7 @@ class Bullet { public: Bullet(Vector3f pos, Vector3f dir); Bullet(Vector3f pos, Vector3f dir, uint64_t tid); + Bullet(Vector3f pos, Vector3f dir, uint64_t tid, bool canhurt); ~Bullet(); bool Update(World* world, float elapsedtime, int perframe, std::unordered_map m_mapPlayer, netprot::ChunkMod** chunkmod); @@ -27,6 +28,8 @@ private: m_currentpos, m_velocity; uint64_t m_shooter_id = 0; + + bool m_canhurt = true; }; diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp index 1c823ce..c125974 100644 --- a/SQCSim-srv/connection.cpp +++ b/SQCSim-srv/connection.cpp @@ -147,7 +147,7 @@ Timestamp Connection::Run(World* world) { } out.states.jumping = player->GetIsAirborne(); - out.states.running = player->GetVelocity().Length() > .5f; + out.states.running = player->GetVelocity().Length() > .2f; out.states.still = !out.states.running && !out.states.jumping; out.states.hit = player->m_hit; player->m_hit = false; diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index edf740c..b997b12 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -202,8 +202,8 @@ void Server::Run() { m_conns.erase(key); continue; } - int x = (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1) - (CHUNK_SIZE_X * WORLD_SIZE_X / 2)) / 8, - y = (rand() % (CHUNK_SIZE_Y * WORLD_SIZE_Y - 1) - (CHUNK_SIZE_Y * WORLD_SIZE_Y / 2)) / 8; + int x = (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1) - (CHUNK_SIZE_X * WORLD_SIZE_X / 2)) / 16, + y = (rand() % (CHUNK_SIZE_Y * WORLD_SIZE_Y - 1) - (CHUNK_SIZE_Y * WORLD_SIZE_Y / 2)) / 16; conn->player = new Player(Vector3f(x + .5f, CHUNK_SIZE_Y + 1.8f, y + .5f)); conn->player->m_username = conn->GetName(); m_players[key] = conn->player; @@ -280,11 +280,14 @@ void Server::Run() { /* Process */ if (conn->m_nsync) { + if (conn->player->AmIDead()) + conn->m_nsync = false; + Timestamp tstamp = conn->Run(m_world); if (conn->player->AmIDead()) { 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(conn->player->Killer)->player->GetUsername(); @@ -293,7 +296,6 @@ void Server::Run() { strcpy(chat->mess, 140, mess.c_str()); chatlog.emplace_back(chat); ++deadplayers; - conn->m_nsync = false; } else { for (auto& chmo : conn->ChunkDiffs) diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 89a4029..db23ef3 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -1512,7 +1512,8 @@ void Engine::Render(float elapsedTime) { std::cout << sync.hp << std::endl; m_otherplayerpos = sync.position; - m_player.InflictDamage(sync.hp - comp.hp); + + m_player.InflictDamage(sync.hp - m_player.GetHP()); Vector3f diff = sync.position - comp.position; @@ -1558,7 +1559,7 @@ void Engine::Render(float elapsedTime) { break; case BULLET: if (Deserialize(&bull, pck, &bsize)) { - Bullet* bult = new Bullet(bull.pos, bull.dir); + Bullet* bult = new Bullet(bull.pos, bull.dir, bull.id, false); for (int x = 0; x < MAX_BULLETS; ++x) // Ajouter une balle dans l'array (aussi connu sous le nom de "faire pow pow"). if (!m_bullets[x]) { m_bullets[x] = bult; @@ -2333,6 +2334,12 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) { m_gamestate = GameState::MAIN_MENU; m_selectedPlayOptions = false; m_audio.ToggleMusicState(m_gamestate); + if (m_networkgame) { + if (m_conn.m_sock_udp) + closesocket(m_conn.m_sock_udp); + if (m_conn.m_sock_udp) + closesocket(m_conn.m_sock_udp); + } } } } From f4347d35df722a6dabb94365bf26e26da9b3d300 Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Wed, 13 Dec 2023 13:51:37 -0500 Subject: [PATCH 09/47] secret --- SQCSim2021/remoteplayer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index 8dd4676..68db0d2 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -116,7 +116,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr float angle = angleRemote.Dot(angleCam); int index = 0; - angle = -angle; + //angle = -angle; Vector3f side = angleRemote.Cross(angleCam); static float time = 0.f; From c801877a0cb8b1e90d89d9752530a7fe0f39d020 Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Wed, 13 Dec 2023 13:53:10 -0500 Subject: [PATCH 10/47] polipocket --- SQCSim2021/remoteplayer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index 68db0d2..03bd101 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -116,8 +116,9 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr float angle = angleRemote.Dot(angleCam); int index = 0; - //angle = -angle; + angle = -angle; Vector3f side = angleRemote.Cross(angleCam); + side = -side; static float time = 0.f; static bool Shooting = false; From d8cbc27ca956c6fc67cbe1f5ef1ad38900686c47 Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Wed, 13 Dec 2023 14:06:11 -0500 Subject: [PATCH 11/47] ALLO --- SQCSim2021/remoteplayer.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index 03bd101..5ca6ba9 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -125,9 +125,9 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr bool isLeft = side.y > 0; time += elapsedTime; - if (time >= 100) + if (time >= 500) { - time -= 100; + time -= 500; if (!current.states.shooting) Shooting = false; else @@ -144,7 +144,6 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr else index = 9; - std::cout << "face" << std::endl; } else if (current.states.jumpshot) { if (Shooting) @@ -157,6 +156,8 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 0; + + } else if (angle >= 0.25 && isLeft) //Frontleft { @@ -166,7 +167,6 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr else index = 10; - std::cout << "Frontleft" << std::endl; } else if (current.states.jumpshot) { if (Shooting) @@ -178,6 +178,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr index = 26; else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 1; + } else if (angle >= -0.25 && isLeft) //ProfileLeft @@ -188,8 +189,6 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr else index = 12; - std::cout << "ProfileLeft" << std::endl; - } else if (current.states.jumpshot ) { if (Shooting) @@ -201,6 +200,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr index = 28; else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 3; + } else if (angle >= -0.75 && isLeft) //BackLeft @@ -211,7 +211,6 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr else index = 14; - std::cout << "BackLeft" << std::endl; } else if (current.states.jumpshot) { if (Shooting) @@ -223,6 +222,8 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr index = 30; else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 5; + + } else if (angle < -0.75) //Dos - side négatif { @@ -232,7 +233,6 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr else index = 16; - std::cout << "Dos" << std::endl; } else if (current.states.jumpshot) { if (Shooting) @@ -244,6 +244,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr index = 32; else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 7; + } else if (angle >= 0.25 && !isLeft) //FrontRight @@ -253,8 +254,6 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr index = 19; else index = 11; - - std::cout << "FrontRight" << std::endl; } else if (current.states.jumpshot) { if (Shooting) @@ -267,6 +266,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 2; + } else if (angle >= -0.25 && !isLeft) //ProfileRight { @@ -275,8 +275,6 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr index = 21; else index = 13; - - std::cout << "ProfileRight" << std::endl; } else if (current.states.jumpshot) { if (Shooting) @@ -289,6 +287,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 4; + } else if (angle >= -0.75 && !isLeft) //BackRight { @@ -298,9 +297,6 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr else index = 15; - std::cout << "BackRight" << std::endl; - - } else if (current.states.jumpshot) { if (Shooting) @@ -313,6 +309,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 6; + } From e31e6707207754ea342dd161aa730fef87da079f Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Wed, 13 Dec 2023 14:06:22 -0500 Subject: [PATCH 12/47] Yaya --- SQCSim-common/player.cpp | 4 ++++ SQCSim-common/player.h | 1 + SQCSim-srv/connection.cpp | 10 +++++----- SQCSim2021/engine.cpp | 3 ++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp index 85df138..845b96f 100644 --- a/SQCSim-common/player.cpp +++ b/SQCSim-common/player.cpp @@ -272,6 +272,10 @@ std::string Player::GetUsername() const { return m_username; } float Player::GetHP() const { return m_hp; } +void Player::SetHP(float hp) { + m_hp = hp; +} + void Player::Teleport(int& x, int& z) { m_position.x -= x * CHUNK_SIZE_X; m_position.z -= z * CHUNK_SIZE_Z; diff --git a/SQCSim-common/player.h b/SQCSim-common/player.h index 6117605..ac2dce6 100644 --- a/SQCSim-common/player.h +++ b/SQCSim-common/player.h @@ -33,6 +33,7 @@ public: Vector3f GetPOV() const; std::string GetUsername() const; float GetHP() const; + void SetHP(float hp); void Teleport(int& x, int& z); bool GetIsAirborne() const; diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp index c125974..ce6b02f 100644 --- a/SQCSim-srv/connection.cpp +++ b/SQCSim-srv/connection.cpp @@ -117,10 +117,10 @@ Timestamp Connection::Run(World* world) { if (m_input_manifest.size() < 2) return tstamp; - if (player->AmIDead()) { - m_input_manifest.clear(); - 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); @@ -131,7 +131,7 @@ Timestamp Connection::Run(World* world) { if (m_shoot_acc > 0.) { m_shoot_acc -= el; if (m_shoot_acc < 0.) - m_shoot_acc = 0; + m_shoot_acc = 0.; } player->SetDirection(in.direction); diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index db23ef3..44f5fd9 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -618,6 +618,7 @@ bool Engine::StartMultiplayerGame() { //m_world.SetSeed(m_conn.getSeed()); m_world.SetSeed(9370707); m_networkgame = true; + m_player.m_username = m_username; } else { std::cout << "Erreur de connexion." << std::endl; @@ -1513,7 +1514,7 @@ void Engine::Render(float elapsedTime) { std::cout << sync.hp << std::endl; m_otherplayerpos = sync.position; - m_player.InflictDamage(sync.hp - m_player.GetHP()); + m_player.SetHP(sync.hp); Vector3f diff = sync.position - comp.position; From edebad86a6e3ae33908af584b0c69a5ae0362d84 Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Wed, 13 Dec 2023 14:26:46 -0500 Subject: [PATCH 13/47] Blahblahblah --- SQCSim2021/remoteplayer.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index 5ca6ba9..4e4b324 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -125,13 +125,15 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr bool isLeft = side.y > 0; time += elapsedTime; - if (time >= 500) + if (time >= 250) { - time -= 500; - if (!current.states.shooting) + time -= 250; + + Shooting = !Shooting; + /*if (!current.states.shooting) Shooting = false; else - Shooting = true; + Shooting = true;*/ } std::cout << "shooting : " << current.states.shooting << " jumping : " << current.states.jumping << " jumpshot : " << current.states.jumpshot << " running : " << current.states.running << " still : " << current.states.still << " dead : " << current.states.dead << " hit : " << current.states.hit << std::endl; From fd1fe66d1397d551d0d9977852a924225d514deb Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Wed, 13 Dec 2023 14:27:11 -0500 Subject: [PATCH 14/47] 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(); From 4c3803c02e719f19e5fc35a8d22bc1ebe7e3bd8d Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Wed, 13 Dec 2023 14:46:53 -0500 Subject: [PATCH 15/47] pleurer en animation --- SQCSim2021/remoteplayer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index 4e4b324..ae0e92f 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -125,9 +125,9 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr bool isLeft = side.y > 0; time += elapsedTime; - if (time >= 250) + if (time >= 100) { - time -= 250; + time -= 100; Shooting = !Shooting; /*if (!current.states.shooting) From a85c5cc626ce46a5af5fbad4b9e826775a69fd98 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Wed, 13 Dec 2023 15:04:08 -0500 Subject: [PATCH 16/47] :gun: --- SQCSim-common/bullet.cpp | 20 ++++++++------- SQCSim-common/define.h | 4 +-- SQCSim-common/player.h | 2 ++ SQCSim-srv/connection.cpp | 52 ++++++++++++++++++++++++--------------- SQCSim-srv/server.cpp | 25 ++++++++++--------- 5 files changed, 61 insertions(+), 42 deletions(-) diff --git a/SQCSim-common/bullet.cpp b/SQCSim-common/bullet.cpp index 53fe339..72da0c1 100644 --- a/SQCSim-common/bullet.cpp +++ b/SQCSim-common/bullet.cpp @@ -12,7 +12,7 @@ Bullet::~Bullet() {} bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordered_map mapPlayer, netprot::ChunkMod** chunkmod) { int max = 100 / perframe; - float damage = 0.057f; + float damage = 0.098f; for (int x = 0; x < max; ++x) { m_currentpos += m_velocity * elapsedtime; @@ -40,15 +40,17 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordere if (!world->ChunkAt(m_currentpos)) return true; else if (world->BlockAt(m_currentpos) != BTYPE_AIR) { - if (chunkmod) { - using namespace netprot; - *chunkmod = new ChunkMod(); - (*chunkmod)->old_b_type = world->BlockAt(m_currentpos); - (*chunkmod)->b_type = BTYPE_AIR; - (*chunkmod)->pos = m_currentpos; - } + if (m_canhurt) { + if (chunkmod) { + using namespace netprot; + *chunkmod = new ChunkMod(); + (*chunkmod)->old_b_type = world->BlockAt(m_currentpos); + (*chunkmod)->b_type = BTYPE_AIR; + (*chunkmod)->pos = m_currentpos; + } - world->ChangeBlockAtPosition(BTYPE_AIR, m_currentpos); + world->ChangeBlockAtPosition(BTYPE_AIR, m_currentpos); + } return true; } else if ((m_currentpos - m_startpos).Length() > VIEW_DISTANCE) return true; diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h index 7dfc7ec..a684da9 100644 --- a/SQCSim-common/define.h +++ b/SQCSim-common/define.h @@ -37,8 +37,8 @@ #define STRENGTH_SPEED_BOOST 10 //Pourcentage #define BULLET_TIME .1 -#define SYNC_ACC 200 -#define CMOD_ACC 1500 +#define SYNC_ACC 200 // ms +#define CMOD_ACC 1500 // ms typedef uint8_t BlockType; enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_GREENGRASS, BTYPE_LAST }; diff --git a/SQCSim-common/player.h b/SQCSim-common/player.h index ac2dce6..b9a4211 100644 --- a/SQCSim-common/player.h +++ b/SQCSim-common/player.h @@ -45,6 +45,8 @@ public: std::string m_username; bool m_hit = false; + bool Eulogy = false; + private: uint64_t getId() const; diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp index 5587ea8..b912416 100644 --- a/SQCSim-srv/connection.cpp +++ b/SQCSim-srv/connection.cpp @@ -77,8 +77,10 @@ void Connection::getPacks(SOCKET sock) { void Connection::sendPacks(SOCKET sock, std::unordered_map conns, const uint32_t timer) { static int outs = 0; static Timestamp last = 0; + while (!m_output_vector.empty()) { Output out = m_output_vector.front(); + for (auto& [key, conn] : conns) { if (m_playinfo.id == conn->GetHash(false)) continue; @@ -91,8 +93,8 @@ void Connection::sendPacks(SOCKET sock, std::unordered_map= 50) { - outs -= 50; + if (outs >= SYNC_ACC) { + outs -= SYNC_ACC; Sync sync; sync.hp = player->GetHP(); sync.timestamp = out.timestamp; @@ -114,27 +116,33 @@ Timestamp Connection::Run(World* world) { Timestamp tstamp = 0; float el; + bool dead = player->AmIDead(); + if (m_input_manifest.size() < 2) 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; + while (m_last_in < m_input_vector.size() - 1 || dead) { + if (!dead) { + 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.) { + m_shoot_acc -= el; + if (m_shoot_acc < 0.) + m_shoot_acc = 0.; + } + player->SetDirection(in.direction); } - - el = (double)(in.timestamp - last.timestamp) / 1000.; - - if (m_shoot_acc > 0.) { - m_shoot_acc -= el; - if (m_shoot_acc < 0.) - m_shoot_acc = 0.; + else { + el = 1. / 60.; + in = Input(); + } - - player->SetDirection(in.direction); + player->ApplyPhysics(player->GetInput(in.keys.forward, in.keys.backward, in.keys.left, @@ -147,7 +155,10 @@ Timestamp Connection::Run(World* world) { } out.states.jumping = player->GetIsAirborne(); - out.states.running = player->GetVelocity().Length() > .2f; + + Vector3f horSpeed = player->GetVelocity(); + horSpeed.y = 0; + out.states.running = horSpeed.Length() > .2f; out.states.still = !out.states.running && !out.states.jumping; out.states.hit = player->m_hit; player->m_hit = false; @@ -192,7 +203,8 @@ Timestamp Connection::Run(World* world) { m_output_vector.push_back(out); m_tstamp = tstamp = out.timestamp; - ++m_last_in; + if (!dead) + ++m_last_in; } return tstamp; diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index e596144..f0f15a3 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -217,7 +217,7 @@ void Server::Run() { sendPackTo(m_sock_udp, &sync, &m_buf, conn->getAddr()); } - int timer = m_game.countdown, sync_acc = 0, deadplayers = 0; + int timer = m_game.countdown, timer_acc = 0, deadplayers = 0; std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now(); Timestamp last = 0; std::vector chatlog; @@ -241,10 +241,10 @@ void Server::Run() { if (last == 0) last = tstamp; - sync_acc += tstamp - last; - if (sync_acc >= SYNC_ACC) { - while (sync_acc >= SYNC_ACC) - sync_acc -= SYNC_ACC; + timer_acc += tstamp - last; + if (timer_acc >= 1000) { + while (timer_acc >= 1000) + timer_acc -= 1000; --timer; std::string str = "Timer: "; Log(str.append(std::to_string(timer)), false, false); @@ -280,22 +280,26 @@ void Server::Run() { /* Process */ if (conn->m_nsync) { - if (conn->player->AmIDead()) - conn->m_nsync = false; Timestamp tstamp = conn->Run(m_world); - if (conn->player->AmIDead()) { + if (conn->player->AmIDead() && !conn->player->Eulogy) { Chat* chat = new Chat(); chat->dest_id = chat->dest_team_id = chat->src_id = 0; - std::string killer = m_conns.at(conn->player->Killer)->player->GetUsername(); + Player* murderer = m_conns.at(conn->player->Killer)->player; + + murderer->addPoint(); + + std::string killer = murderer->GetUsername(); std::string mess = getDeathMessage(conn->player->GetUsername(), killer); strcpy(chat->mess, 140, mess.c_str()); chatlog.emplace_back(chat); ++deadplayers; + + conn->player->Eulogy = true; } else { for (auto& chmo : conn->ChunkDiffs) @@ -367,8 +371,7 @@ void Server::Run() { for (auto& [key, conn] : m_conns) { std::string str = conn->player->GetUsername(); - Log(str.append(" ").append(std::to_string(conn->player->GetHP())), false, false); - + Log(str.append(" ").append(std::to_string(conn->player->getScore())), false, false); } for (auto& [key, conn] : m_conns) From a11c52cf77aa21ba53cfe146a4d1a9c2a71f6cd8 Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Wed, 13 Dec 2023 15:14:38 -0500 Subject: [PATCH 17/47] AH BEN TABARNOUCHE --- SQCSim2021/remoteplayer.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index ae0e92f..0538475 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -125,9 +125,9 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr bool isLeft = side.y > 0; time += elapsedTime; - if (time >= 100) + if (time >= 0.5) { - time -= 100; + time -= 0.5; Shooting = !Shooting; /*if (!current.states.shooting) @@ -135,8 +135,9 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr else Shooting = true;*/ } - - std::cout << "shooting : " << current.states.shooting << " jumping : " << current.states.jumping << " jumpshot : " << current.states.jumpshot << " running : " << current.states.running << " still : " << current.states.still << " dead : " << current.states.dead << " hit : " << current.states.hit << std::endl; + //std::cout << Shooting << std::endl; + //std::cout << time << std::endl; + //std::cout << "shooting : " << current.states.shooting << " jumping : " << current.states.jumping << " jumpshot : " << current.states.jumpshot << " running : " << current.states.running << " still : " << current.states.still << " dead : " << current.states.dead << " hit : " << current.states.hit << std::endl; if (angle >= 0.75) //Face - side positif { From 53e0af3f94358a344fee7ceb715de4a63f010cef Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Wed, 13 Dec 2023 15:18:17 -0500 Subject: [PATCH 18/47] PUSHING STUFF INTO THE VOID --- SQCSim2021/remoteplayer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index 0538475..e3329bb 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -125,9 +125,9 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr bool isLeft = side.y > 0; time += elapsedTime; - if (time >= 0.5) + if (time >= 0.05) { - time -= 0.5; + time -= 0.05; Shooting = !Shooting; /*if (!current.states.shooting) From c7c38ed44d575995edb40c2c5690b134f297debb Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Wed, 13 Dec 2023 15:21:19 -0500 Subject: [PATCH 19/47] Suicide is NOT the answer. --- SQCSim-srv/server.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index f0f15a3..b06476d 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -289,7 +289,8 @@ void Server::Run() { Player* murderer = m_conns.at(conn->player->Killer)->player; - murderer->addPoint(); + if (murderer != conn->player) + murderer->addPoint(); std::string killer = murderer->GetUsername(); From 28dc760cbaaeef55bd96c56244dba1cbe7eb2f11 Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Wed, 13 Dec 2023 15:21:23 -0500 Subject: [PATCH 20/47] potatoes --- SQCSim2021/remoteplayer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index e3329bb..70112ce 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -135,7 +135,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr else Shooting = true;*/ } - //std::cout << Shooting << std::endl; + std::cout << Shooting << std::endl; //std::cout << time << std::endl; //std::cout << "shooting : " << current.states.shooting << " jumping : " << current.states.jumping << " jumpshot : " << current.states.jumpshot << " running : " << current.states.running << " still : " << current.states.still << " dead : " << current.states.dead << " hit : " << current.states.hit << std::endl; From 08204934c8b6a9c0b495af061b3570d9ae1cc70e Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Wed, 13 Dec 2023 15:23:14 -0500 Subject: [PATCH 21/47] No more 1. --- SQCSim2021/engine.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 1e36ead..a58dacc 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -1510,8 +1510,6 @@ void Engine::Render(float elapsedTime) { } if (m_syncs.count(sync.timestamp)) { Sync comp = m_syncs[sync.timestamp]; - - std::cout << sync.hp << std::endl; m_otherplayerpos = sync.position; m_player.SetHP(sync.hp); From 37a86d42a34d4ee880fa261855acdb4b63828dfa Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Wed, 13 Dec 2023 15:29:12 -0500 Subject: [PATCH 22/47] lol infinite loop --- SQCSim-srv/connection.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp index b912416..520c886 100644 --- a/SQCSim-srv/connection.cpp +++ b/SQCSim-srv/connection.cpp @@ -205,6 +205,8 @@ Timestamp Connection::Run(World* world) { if (!dead) ++m_last_in; + + dead = false; } return tstamp; From 6d4f592278399919e547ef3969faf2929f855ddc Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Wed, 13 Dec 2023 15:45:17 -0500 Subject: [PATCH 23/47] k. --- SQCSim2021/remoteplayer.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index 70112ce..6de6160 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -146,7 +146,6 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr index = 17; else index = 9; - } else if (current.states.jumpshot) { if (Shooting) @@ -159,8 +158,6 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 0; - - } else if (angle >= 0.25 && isLeft) //Frontleft { @@ -250,7 +247,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr } - else if (angle >= 0.25 && !isLeft) //FrontRight + else if (angle >= 0.25 && !isLeft) //FrontRight //REVOIR L'ANIME DE SHOOTING EST PAS DRETTE { if (current.states.shooting) { if (Shooting) From 5a3ce00cb22737f4c6ce776292aecffe7098ea17 Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:10:21 -0500 Subject: [PATCH 24/47] kjhg --- SQCSim2021/remoteplayer.cpp | 53 ++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index 6de6160..5520790 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -8,7 +8,7 @@ -RemotePlayer::RemotePlayer(netprot::PlayerInfo* pinfo) : m_pinfo(*pinfo), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), previous(), m_texture_front(), Player(Vector3f(0, 0, 0)){ +RemotePlayer::RemotePlayer(netprot::PlayerInfo* pinfo) : m_pinfo(*pinfo), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), previous(), m_texture_front(), Player(Vector3f(0, 0, 0)) { } @@ -24,7 +24,7 @@ RemotePlayer::~RemotePlayer() void RemotePlayer::Init() { - + } void RemotePlayer::Feed(const netprot::Output out) { @@ -108,7 +108,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr Vector3f angleRemote = GetDirection(); Vector3f angleCam = (v1 - v2).Cross(v3 - v2); - + angleCam.y = 0; angleRemote.y = 0; angleCam.Normalize(); @@ -127,21 +127,16 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr time += elapsedTime; if (time >= 0.05) { - time -= 0.05; + time -= 0.05; - Shooting = !Shooting; - /*if (!current.states.shooting) - Shooting = false; - else - Shooting = true;*/ + Shooting = !Shooting; } - std::cout << Shooting << std::endl; - //std::cout << time << std::endl; - //std::cout << "shooting : " << current.states.shooting << " jumping : " << current.states.jumping << " jumpshot : " << current.states.jumpshot << " running : " << current.states.running << " still : " << current.states.still << " dead : " << current.states.dead << " hit : " << current.states.hit << std::endl; + + std::cout << "shooting : " << current.states.shooting << " jumping : " << current.states.jumping << " jumpshot : " << current.states.jumpshot << " running : " << current.states.running << " still : " << current.states.still << " dead : " << current.states.dead << " hit : " << current.states.hit << std::endl; if (angle >= 0.75) //Face - side positif { - if(current.states.shooting){ + if (current.states.shooting) { if (Shooting) index = 17; else @@ -174,12 +169,12 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr else index = 34; } - else if (current.states.jumping ) + else if (current.states.jumping) index = 26; else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 1; - + } else if (angle >= -0.25 && isLeft) //ProfileLeft { @@ -190,18 +185,18 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr index = 12; } - else if (current.states.jumpshot ) { + else if (current.states.jumpshot) { if (Shooting) index = 44; else index = 36; } - else if (current.states.jumping ) + else if (current.states.jumping) index = 28; else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 3; - + } else if (angle >= -0.75 && isLeft) //BackLeft { @@ -240,12 +235,12 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr else index = 40; } - else if (current.states.jumping ) + else if (current.states.jumping) index = 32; else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) index = 7; - + } else if (angle >= 0.25 && !isLeft) //FrontRight //REVOIR L'ANIME DE SHOOTING EST PAS DRETTE { @@ -311,7 +306,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr } - + float u, v, w, h; @@ -321,9 +316,23 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr atlas.TextureIndexToCoord(index, u, v, w, h); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + + if (current.states.hit) + { + glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); + glBlendColor(1.f, 0.f, 0.f, 1.f); + + } + else { + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + glBlendEquation(GL_FUNC_ADD); + + + glLoadMatrixf(tran.GetMatrix().GetInternalValues()); glBegin(GL_QUADS); glTexCoord2f(u, v); glVertex3f(v1.x, v1.y, v1.z); From 49374a7dea08ad75ff4cc50c835b6f7fa2c7d7aa Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Wed, 13 Dec 2023 16:10:23 -0500 Subject: [PATCH 25/47] Let's all die! --- SQCSim-srv/connection.cpp | 15 +++++++++---- SQCSim-srv/server.cpp | 46 ++++++++++++++++++++++++++++++++++----- SQCSim2021/engine.cpp | 3 +++ 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp index 520c886..700c1da 100644 --- a/SQCSim-srv/connection.cpp +++ b/SQCSim-srv/connection.cpp @@ -93,16 +93,23 @@ void Connection::sendPacks(SOCKET sock, std::unordered_map= SYNC_ACC) { - outs -= SYNC_ACC; + static bool syncdead = false; + bool dead = player->AmIDead(); + + if (outs >= SYNC_ACC || (!syncdead && dead)) { Sync sync; - sync.hp = player->GetHP(); + outs -= SYNC_ACC; sync.timestamp = out.timestamp; sync.position = out.position; sync.sid = m_loginfo.sid; sync.timer = timer; sync.timestamp = out.timestamp; sync.ammo = -1; + sync.hp = player->GetHP(); + if (dead) { + sync.timestamp = m_loginfo.sid; + syncdead = true; + } sendPackTo(sock, &sync, &m_bufout, &m_addr); } @@ -118,7 +125,7 @@ Timestamp Connection::Run(World* world) { bool dead = player->AmIDead(); - if (m_input_manifest.size() < 2) + if (m_input_manifest.size() < 2 && !dead) return tstamp; while (m_last_in < m_input_vector.size() - 1 || dead) { diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index b06476d..6d7153c 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -230,12 +230,12 @@ void Server::Run() { Chat* startchat = new Chat(); startchat->src_id = 0; char startmess[] = "How would -YOU- like to die today, motherf-words?"; - + float endtime = 0.; strcpy(startchat->mess, 140, startmess); chatlog.emplace_back(startchat); - while (!endgame) { + while (!endgame && endtime < 1.) { using namespace std::chrono; Timestamp tstamp = duration_cast(high_resolution_clock::now() - start).count(); @@ -245,7 +245,8 @@ void Server::Run() { if (timer_acc >= 1000) { while (timer_acc >= 1000) timer_acc -= 1000; - --timer; + if (!endgame) + --timer; std::string str = "Timer: "; Log(str.append(std::to_string(timer)), false, false); } @@ -323,8 +324,43 @@ void Server::Run() { /* Out */ conn->sendPacks(m_sock_udp, m_conns, timer); - if ((deadplayers == players - 1 && deadplayers != 0) || timer < 0) + if ((deadplayers == players - 1 && deadplayers != 0) || timer < 0) { + if (!endgame) { + Chat* gameover = new Chat(); + gameover->dest_id = gameover->dest_team_id = gameover->src_id = 0; + std::string winner, winmess; + int score = 0; + bool plural = false; + for (auto& [key, conn] : m_conns) { + if (conn->player->getScore() > score) { + winner = conn->player->GetUsername(); + score = conn->player->getScore(); + plural = false; + } + else if (conn->player->getScore() == score) { + winner = winner.append(" and ").append(conn->player->GetUsername()); + plural = true; + } + } + + winmess = "And the winner"; + if (!plural) + winmess = winmess.append(" is "); + else winmess = winmess.append("s are "); + + winmess = winmess.append(winner).append(" with ").append(std::to_string(score)).append(" point"); + + if (score > 1) + winmess = winmess.append("s."); + else winmess = winmess.append("."); + + strcpy(gameover->mess, 140, winmess.c_str()); + + chatlog.emplace_back(gameover); + } endgame = true; + endtime += .001; + } } for (auto& bull : netbull) { @@ -338,7 +374,7 @@ void Server::Run() { for (auto bull = bullets.begin(); bull != bullets.end(); ++bull) { ChunkMod* cmod = nullptr; Bullet* bullet = *bull; - if (bullet->Update(m_world, (1. / 60.), 20, m_players, &cmod)) { + if (bullet->Update(m_world, (1. / 60.), 10, m_players, &cmod)) { if (cmod) chunkdiffs.emplace_back(cmod); bullit.push_back(bull); diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index a58dacc..e174ac6 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -1508,6 +1508,9 @@ void Engine::Render(float elapsedTime) { SystemNotification("syncsid be no good."); break; } + if (sync.timestamp == m_conn.getId()) { + m_player.SetHP(sync.hp); + } if (m_syncs.count(sync.timestamp)) { Sync comp = m_syncs[sync.timestamp]; m_otherplayerpos = sync.position; From 325c6b60f9cfa6c3d66e172a4a03260aedd1390b Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Wed, 13 Dec 2023 16:29:13 -0500 Subject: [PATCH 26/47] keep in sync when dead --- SQCSim-common/bullet.cpp | 2 +- SQCSim-srv/connection.cpp | 13 +++++++++++++ SQCSim-srv/server.cpp | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/SQCSim-common/bullet.cpp b/SQCSim-common/bullet.cpp index 72da0c1..87412da 100644 --- a/SQCSim-common/bullet.cpp +++ b/SQCSim-common/bullet.cpp @@ -18,7 +18,7 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordere for (auto& [key, player] : mapPlayer) { bool hit = false; - if ((m_currentpos - player->GetPosition()).Length() < .6f) { + if ((m_currentpos - player->GetPosition()).Length() < 1.f) { hit = true; } if ((m_currentpos - player->GetPOV()).Length() < .2f) { diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp index 700c1da..34db420 100644 --- a/SQCSim-srv/connection.cpp +++ b/SQCSim-srv/connection.cpp @@ -77,6 +77,19 @@ void Connection::getPacks(SOCKET sock) { void Connection::sendPacks(SOCKET sock, std::unordered_map conns, const uint32_t timer) { static int outs = 0; static Timestamp last = 0; + static uint32_t lasttimer = timer; + + if (m_output_vector.empty() && player->AmIDead()) { + if (timer != lasttimer) { + lasttimer = timer; + Sync sync; + sync.timestamp = sync.sid = m_loginfo.sid; + sync.hp = 0; + sync.ammo = -1; + sync.timer = timer; + sendPackTo(sock, &sync, &m_bufout, &m_addr); + } + } while (!m_output_vector.empty()) { Output out = m_output_vector.front(); diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index 6d7153c..2a8825e 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -374,7 +374,7 @@ void Server::Run() { for (auto bull = bullets.begin(); bull != bullets.end(); ++bull) { ChunkMod* cmod = nullptr; Bullet* bullet = *bull; - if (bullet->Update(m_world, (1. / 60.), 10, m_players, &cmod)) { + if (bullet->Update(m_world, (1. / 60.), 100, m_players, &cmod)) { if (cmod) chunkdiffs.emplace_back(cmod); bullit.push_back(bull); From b8899b8f8608096cdd74b7c0f03a9efbff1fe8aa Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Wed, 13 Dec 2023 16:30:20 -0500 Subject: [PATCH 27/47] NO CHEATING! --- SQCSim-srv/connection.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp index 34db420..c9fd885 100644 --- a/SQCSim-srv/connection.cpp +++ b/SQCSim-srv/connection.cpp @@ -59,7 +59,9 @@ void Connection::getPacks(SOCKET sock) { switch (netprot::getType(pck, 1)) { using enum netprot::PACKET_TYPE; case INPUT: - if (Deserialize(&in, pck, &bsize)) { + if (player->AmIDead()) + break; + else if (Deserialize(&in, pck, &bsize)) { m_input_manifest[in.timestamp] = in; m_input_vector.push_back(in); } From 26d03ca5cc02ee6a068357e04d97952c76db63d0 Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:32:43 -0500 Subject: [PATCH 28/47] =?UTF-8?q?horribl=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SQCSim2021/remoteplayer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index 5520790..6f465e8 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -334,6 +334,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr glLoadMatrixf(tran.GetMatrix().GetInternalValues()); + glDepthFunc(GL_LEQUAL); glBegin(GL_QUADS); glTexCoord2f(u, v); glVertex3f(v1.x, v1.y, v1.z); glTexCoord2f(u + w, v); glVertex3f(v2.x, v2.y, v2.z); From f564e37544bdbce7a1b5b88210c323bf37206c7b Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sat, 16 Dec 2023 12:32:54 -0500 Subject: [PATCH 29/47] YYYAAAAAAARRRGGHH? --- SQCSim2021/engine.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 106fac0..69eb44b 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -1443,14 +1443,15 @@ void Engine::Render(float elapsedTime) { if ((m_player.GetPosition().y < -1.7f || m_player.AmIDead()) && !died) { m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false, m_sfxvolume); died = true; - } - if (m_player.GetPosition().y < -21.f || died) { - died = false; std::string user = m_player.m_username.append(" (Dead)"); m_player = Player(Vector3f(.5, CHUNK_SIZE_Y + 1.7f, .5), 0, 0); m_player.m_username = user; m_player.InflictDamage(-m_player.GetHP()); } + /*if (m_player.GetPosition().y < -21.f || died) { + died = false; + + }*/ m_time += elapsedTime; From dec9da63959f41273614e7f3ccf84c6e18ebe351 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sat, 16 Dec 2023 12:48:08 -0500 Subject: [PATCH 30/47] no more whoosh --- SQCSim2021/engine.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 69eb44b..141f100 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -1410,19 +1410,19 @@ void Engine::Render(float elapsedTime) { m_chunkmod = nullptr; } m_bullets[x] = nullptr; - if (m_whoosh[x]){ + /*if (m_whoosh[x]){ m_whoosh[x]->drop(); m_whoosh[x] = nullptr; - } + }*/ break; } - else if (!m_whoosh[x]) { + /*else if (!m_whoosh[x]) { m_whoosh[x] = m_audio.Create3DAudioObj(m_whoosh[x], AUDIO_PATH "noise.wav", m_bullets[x]->getPos(), m_bullets[x]->getVel(), true, (m_bullets[x]->getPos() - m_player.GetPosition()).Length()); } else { Vector3f pos = m_bullets[x]->getPos(), vel = m_bullets[x]->getVel(); m_audio.Render3DAudioObj(m_whoosh[x], pos, vel, m_sfxvolume); - } + }*/ } } } From 547d0fb3f8640f724cd250f966d0e489511241e7 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sat, 16 Dec 2023 12:57:04 -0500 Subject: [PATCH 31/47] =?UTF-8?q?=C3=87a=20devrait=20crier=20moins?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SQCSim2021/engine.cpp | 3 ++- SQCSim2021/engine.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 141f100..01021b1 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -1564,8 +1564,9 @@ void Engine::Render(float elapsedTime) { } RemotePlayer* rt = static_cast(m_players[out.id]); rt->Feed(out); - if (rt->AmIDead()) { + if (rt->AmIDead() && !m_deadplayers.count(out.id)) { m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false, m_sfxvolume); + m_deadplayers.insert(out.id); } } break; diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index 1a1303a..cd3ee36 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -249,6 +249,7 @@ private: std::deque m_chunkmod_manifest; std::chrono::high_resolution_clock::time_point m_startTime; std::unordered_map m_players; + std::set m_deadplayers; netprot::Buffer m_buf, m_bufout; netprot::ChunkMod* m_chunkmod = nullptr; From 38bab49806dfab2e4c7b4a7f3fdf8209b3e821f4 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sat, 16 Dec 2023 13:05:04 -0500 Subject: [PATCH 32/47] Log de se faire tirer --- SQCSim-srv/server.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index 2a8825e..835783a 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -281,6 +281,11 @@ void Server::Run() { /* Process */ if (conn->m_nsync) { + if (conn->player->m_hit) { + std::string str = conn->player->GetUsername(); + str = str.append(" has been hit: ").append(std::to_string(conn->player->GetHP())); + Log(str, false, false); + } Timestamp tstamp = conn->Run(m_world); From 7803f46a6b05d5c6048d6bab366838650c9a08da Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sat, 16 Dec 2023 13:14:37 -0500 Subject: [PATCH 33/47] WE ARE THE WORLD. --- SQCSim2021/engine.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 01021b1..25f7428 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -634,6 +634,7 @@ bool Engine::StartMultiplayerGame() { std::cout << "Erreur de creation de socket." << std::endl; ok = false; } + m_world.BuildWorld(); return ok; } From 1c2a691638dfae82093937e8f489331dc8cac9aa Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sat, 16 Dec 2023 14:01:08 -0500 Subject: [PATCH 34/47] Bullet Time is slow. --- SQCSim-common/SQCSim-common.vcxproj | 2 +- SQCSim-common/bullet.cpp | 4 ++-- SQCSim-common/define.h | 2 +- SQCSim-srv/SQCSim-srv.vcxproj | 2 +- SQCSim-srv/server.cpp | 2 +- SQCSim2021/SQCSim2021.vcxproj | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/SQCSim-common/SQCSim-common.vcxproj b/SQCSim-common/SQCSim-common.vcxproj index c618082..4ba7bd4 100644 --- a/SQCSim-common/SQCSim-common.vcxproj +++ b/SQCSim-common/SQCSim-common.vcxproj @@ -48,7 +48,7 @@ StaticLibrary false - ClangCL + v143 true Unicode diff --git a/SQCSim-common/bullet.cpp b/SQCSim-common/bullet.cpp index 87412da..ab3d18e 100644 --- a/SQCSim-common/bullet.cpp +++ b/SQCSim-common/bullet.cpp @@ -18,10 +18,10 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordere for (auto& [key, player] : mapPlayer) { bool hit = false; - if ((m_currentpos - player->GetPosition()).Length() < 1.f) { + if ((m_currentpos - player->GetPosition()).Length() < .5f) { hit = true; } - if ((m_currentpos - player->GetPOV()).Length() < .2f) { + else if ((m_currentpos - player->GetPOV()).Length() < .2f) { damage *= 2; // HEADSHOT! hit = true; } diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h index a684da9..f6737af 100644 --- a/SQCSim-common/define.h +++ b/SQCSim-common/define.h @@ -35,7 +35,7 @@ #define TIME_DAMAGE_BOOST 10 //secondes #define TIME_INVINCIBLE_BOOST 4 //secondes #define STRENGTH_SPEED_BOOST 10 //Pourcentage -#define BULLET_TIME .1 +#define BULLET_TIME .2 #define SYNC_ACC 200 // ms #define CMOD_ACC 1500 // ms diff --git a/SQCSim-srv/SQCSim-srv.vcxproj b/SQCSim-srv/SQCSim-srv.vcxproj index b0dcd9c..d080276 100644 --- a/SQCSim-srv/SQCSim-srv.vcxproj +++ b/SQCSim-srv/SQCSim-srv.vcxproj @@ -48,7 +48,7 @@ Application false - ClangCL + v143 true Unicode diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index 835783a..be92139 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -379,7 +379,7 @@ void Server::Run() { for (auto bull = bullets.begin(); bull != bullets.end(); ++bull) { ChunkMod* cmod = nullptr; Bullet* bullet = *bull; - if (bullet->Update(m_world, (1. / 60.), 100, m_players, &cmod)) { + if (bullet->Update(m_world, (1. / 60.), 20, m_players, &cmod)) { if (cmod) chunkdiffs.emplace_back(cmod); bullit.push_back(bull); diff --git a/SQCSim2021/SQCSim2021.vcxproj b/SQCSim2021/SQCSim2021.vcxproj index 7d14bc6..661f995 100644 --- a/SQCSim2021/SQCSim2021.vcxproj +++ b/SQCSim2021/SQCSim2021.vcxproj @@ -91,7 +91,7 @@ false true Unicode - ClangCL + v143 From da94565c3e4644b4a8d9f057456f30640142029b Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Sat, 16 Dec 2023 14:41:00 -0500 Subject: [PATCH 35/47] EL NIINIOOO --- SQCSim2021/remoteplayer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index 6f465e8..3287a59 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -132,7 +132,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr Shooting = !Shooting; } - std::cout << "shooting : " << current.states.shooting << " jumping : " << current.states.jumping << " jumpshot : " << current.states.jumpshot << " running : " << current.states.running << " still : " << current.states.still << " dead : " << current.states.dead << " hit : " << current.states.hit << std::endl; + //std::cout << "shooting : " << current.states.shooting << " jumping : " << current.states.jumping << " jumpshot : " << current.states.jumpshot << " running : " << current.states.running << " still : " << current.states.still << " dead : " << current.states.dead << " hit : " << current.states.hit << std::endl; if (angle >= 0.75) //Face - side positif { From 63d1f997ca460c7f5118f7d2007651cfa5bf6006 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sat, 16 Dec 2023 14:41:01 -0500 Subject: [PATCH 36/47] blob --- SQCSim-common/define.h | 2 +- SQCSim-srv/server.cpp | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h index f6737af..e1f9c0a 100644 --- a/SQCSim-common/define.h +++ b/SQCSim-common/define.h @@ -35,7 +35,7 @@ #define TIME_DAMAGE_BOOST 10 //secondes #define TIME_INVINCIBLE_BOOST 4 //secondes #define STRENGTH_SPEED_BOOST 10 //Pourcentage -#define BULLET_TIME .2 +#define BULLET_TIME .2 //secondes #define SYNC_ACC 200 // ms #define CMOD_ACC 1500 // ms diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index be92139..1113a9a 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -281,11 +281,11 @@ void Server::Run() { /* Process */ if (conn->m_nsync) { - if (conn->player->m_hit) { + /*if (conn->player->m_hit) { std::string str = conn->player->GetUsername(); str = str.append(" has been hit: ").append(std::to_string(conn->player->GetHP())); Log(str, false, false); - } + }*/ Timestamp tstamp = conn->Run(m_world); @@ -367,7 +367,7 @@ void Server::Run() { endtime += .001; } } - + for (auto& bull : netbull) { for (auto& [key, conn] : m_conns) if (bull->id != conn->GetHash(false)) // Pour pas repitcher au joueur sa propre balle. @@ -375,6 +375,9 @@ void Server::Run() { delete bull; } netbull.clear(); + + if (!bullets.empty()) + std::cout << "Bullets: " << bullets.size() << std::endl; for (auto bull = bullets.begin(); bull != bullets.end(); ++bull) { ChunkMod* cmod = nullptr; @@ -386,12 +389,13 @@ void Server::Run() { delete bullet; } } + for (auto& bull: bullit) bullets.erase(bull); bullit.clear(); for (auto& chat : chatlog) { - Log(chat->mess, false, false); + Log(chat->mess, false, false); for (auto& [key, conn] : m_conns) sendPackTo(m_sock_udp, chat, &m_buf, conn->getAddr()); delete chat; From 1065357e70520c740ee05d0d9e783f9355c35ec1 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sat, 16 Dec 2023 15:05:06 -0500 Subject: [PATCH 37/47] Eh? --- SQCSim-common/netprotocol.cpp | 8 ++++---- SQCSim-srv/server.cpp | 21 +++++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/SQCSim-common/netprotocol.cpp b/SQCSim-common/netprotocol.cpp index 68feda2..d9b5b73 100644 --- a/SQCSim-common/netprotocol.cpp +++ b/SQCSim-common/netprotocol.cpp @@ -1173,11 +1173,11 @@ netprot::Packet netprot::makePack(void* ptr, PACKET_TYPE type) { } void netprot::recvPacks(SOCKET sock, Buffer* buf, std::vector* lsPck) { - int len = buf->tmp ? buf->tmp - buf->ptr : 0, + int len = 0,//buf->tmp ? buf->tmp - buf->ptr : 0, end = 0; - char* cursor = buf->tmp ? buf->tmp : nullptr, - * next = buf->tmp ? buf->tmp + 1 : buf->ptr, - * last = buf->tmp ? buf->tmp : buf->ptr; + char* cursor = nullptr,//buf->tmp ? buf->tmp : nullptr, + * next = buf->ptr,//buf->tmp ? buf->tmp + 1 : buf->ptr, + * last = buf->ptr,//buf->tmp ? buf->tmp : buf->ptr; bool ended = true; struct pollfd fds[1]; diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index 1113a9a..1eefbf2 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -374,15 +374,13 @@ void Server::Run() { sendPackTo(m_sock_udp, bull, &m_buf, conn->getAddr()); delete bull; } - netbull.clear(); + if (!netbull.empty()) + netbull.clear(); - if (!bullets.empty()) - std::cout << "Bullets: " << bullets.size() << std::endl; - for (auto bull = bullets.begin(); bull != bullets.end(); ++bull) { ChunkMod* cmod = nullptr; Bullet* bullet = *bull; - if (bullet->Update(m_world, (1. / 60.), 20, m_players, &cmod)) { + if (bullet->Update(m_world, (1. / 60.), 1, m_players, &cmod)) { if (cmod) chunkdiffs.emplace_back(cmod); bullit.push_back(bull); @@ -392,7 +390,12 @@ void Server::Run() { for (auto& bull: bullit) bullets.erase(bull); - bullit.clear(); + + if (!bullets.empty()) + bullets.clear(); + + if (!bullit.empty()) + bullit.clear(); for (auto& chat : chatlog) { Log(chat->mess, false, false); @@ -400,14 +403,16 @@ void Server::Run() { sendPackTo(m_sock_udp, chat, &m_buf, conn->getAddr()); delete chat; } - chatlog.clear(); + if (!chatlog.empty()) + chatlog.clear(); for (auto& chmo : chunkdiffs) { for (auto& [key, conn] : m_conns) sendPackTo(m_sock_udp, chmo, &m_buf, conn->getAddr()); delete chmo; } - chunkdiffs.clear(); + if (!chunkdiffs.empty()) + chunkdiffs.clear(); } Chat end; From ba6b3832519d45afde4cd3a712468efe217e6b8d Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sat, 16 Dec 2023 15:05:26 -0500 Subject: [PATCH 38/47] erratum --- SQCSim-common/netprotocol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQCSim-common/netprotocol.cpp b/SQCSim-common/netprotocol.cpp index d9b5b73..2caf0eb 100644 --- a/SQCSim-common/netprotocol.cpp +++ b/SQCSim-common/netprotocol.cpp @@ -1177,7 +1177,7 @@ void netprot::recvPacks(SOCKET sock, Buffer* buf, std::vector* lsPck) { end = 0; char* cursor = nullptr,//buf->tmp ? buf->tmp : nullptr, * next = buf->ptr,//buf->tmp ? buf->tmp + 1 : buf->ptr, - * last = buf->ptr,//buf->tmp ? buf->tmp : buf->ptr; + * last = buf->ptr;//buf->tmp ? buf->tmp : buf->ptr; bool ended = true; struct pollfd fds[1]; From 745f40bc37a52480433b981a8dd45e4f3ea48921 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sat, 16 Dec 2023 15:11:48 -0500 Subject: [PATCH 39/47] REVERT. --- SQCSim-common/netprotocol.cpp | 8 ++++---- SQCSim-srv/server.cpp | 3 --- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/SQCSim-common/netprotocol.cpp b/SQCSim-common/netprotocol.cpp index 2caf0eb..68feda2 100644 --- a/SQCSim-common/netprotocol.cpp +++ b/SQCSim-common/netprotocol.cpp @@ -1173,11 +1173,11 @@ netprot::Packet netprot::makePack(void* ptr, PACKET_TYPE type) { } void netprot::recvPacks(SOCKET sock, Buffer* buf, std::vector* lsPck) { - int len = 0,//buf->tmp ? buf->tmp - buf->ptr : 0, + int len = buf->tmp ? buf->tmp - buf->ptr : 0, end = 0; - char* cursor = nullptr,//buf->tmp ? buf->tmp : nullptr, - * next = buf->ptr,//buf->tmp ? buf->tmp + 1 : buf->ptr, - * last = buf->ptr;//buf->tmp ? buf->tmp : buf->ptr; + char* cursor = buf->tmp ? buf->tmp : nullptr, + * next = buf->tmp ? buf->tmp + 1 : buf->ptr, + * last = buf->tmp ? buf->tmp : buf->ptr; bool ended = true; struct pollfd fds[1]; diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index 1eefbf2..a2ca2c9 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -391,9 +391,6 @@ void Server::Run() { for (auto& bull: bullit) bullets.erase(bull); - if (!bullets.empty()) - bullets.clear(); - if (!bullit.empty()) bullit.clear(); From 2eacc0477b138726a5ec4afcc8cf3a9c918ee2d3 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sat, 16 Dec 2023 15:15:25 -0500 Subject: [PATCH 40/47] ?! --- SQCSim-common/define.h | 4 ++-- SQCSim-srv/server.cpp | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h index e1f9c0a..47a4db0 100644 --- a/SQCSim-common/define.h +++ b/SQCSim-common/define.h @@ -37,8 +37,8 @@ #define STRENGTH_SPEED_BOOST 10 //Pourcentage #define BULLET_TIME .2 //secondes -#define SYNC_ACC 200 // ms -#define CMOD_ACC 1500 // ms +#define SYNC_ACC 100 // ms +#define CMOD_ACC 1000 // ms typedef uint8_t BlockType; enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_GREENGRASS, BTYPE_LAST }; diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index a2ca2c9..70b5c05 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -384,12 +384,13 @@ void Server::Run() { if (cmod) chunkdiffs.emplace_back(cmod); bullit.push_back(bull); - delete bullet; } } - for (auto& bull: bullit) + for (auto& bull : bullit) { + delete* bull; bullets.erase(bull); + } if (!bullit.empty()) bullit.clear(); From 7f9462881c7df63a65c2a80bace41d05dd4eab85 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sat, 16 Dec 2023 15:27:20 -0500 Subject: [PATCH 41/47] Oops, all changes! --- SQCSim-common/define.h | 2 +- SQCSim-srv/connection.cpp | 2 +- SQCSim2021/engine.cpp | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h index 47a4db0..4ad61c0 100644 --- a/SQCSim-common/define.h +++ b/SQCSim-common/define.h @@ -37,7 +37,7 @@ #define STRENGTH_SPEED_BOOST 10 //Pourcentage #define BULLET_TIME .2 //secondes -#define SYNC_ACC 100 // ms +#define SYNC_ACC 600 // ms #define CMOD_ACC 1000 // ms typedef uint8_t BlockType; diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp index c9fd885..19469ad 100644 --- a/SQCSim-srv/connection.cpp +++ b/SQCSim-srv/connection.cpp @@ -213,7 +213,7 @@ Timestamp Connection::Run(World* world) { else out.states.jumpshot = false; if (in.keys.shoot && m_shoot_acc <= 0.) { - Bullets.push_back(std::move(new Bullet(player->GetPOV() + player->GetDirection(), player->GetDirection(), GetHash(true)))); + Bullets.emplace_back(new Bullet(player->GetPOV() + player->GetDirection(), player->GetDirection(), GetHash(true))); m_shoot_acc = BULLET_TIME; } diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 25f7428..4de61f3 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -679,7 +679,8 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) { ss.str(""); fPosY -= charSize; - ss << " Remote Position : " << m_otherplayerpos; + Vector3f pos = Vector3f(m_otherplayerpos.x + CHUNK_SIZE_X * WORLD_SIZE_X / 2, m_otherplayerpos.y, m_otherplayerpos.z + CHUNK_SIZE_Z * WORLD_SIZE_Y / 2); + ss << " Remote Position : " << pos; PrintText(fPosX, fPosY, ss.str()); ss.str(""); fPosY -= charSize; From 5e1e8366cef39b41893dee3ee9c2c6da91bdcaac Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Sat, 16 Dec 2023 15:52:27 -0500 Subject: [PATCH 42/47] j'push des choses --- SQCSim2021/remoteplayer.cpp | 47 +------------------------------------ 1 file changed, 1 insertion(+), 46 deletions(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index 3287a59..3a47218 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -31,54 +31,9 @@ void RemotePlayer::Feed(const netprot::Output out) { m_position = Vector3f(out.position); m_direction = Vector3f(out.direction); - current.states = out.states; + - //current.position = out.position; - //current.direction = out.direction; - //current.states = out.states; - //current.id = out.id; - - //if (current.position != previous.position) - //{ - // Vector3f positionDelta = current.position - previous.position; - // m_position = current.position + positionDelta; - // m_direction = current.direction; - - //} - - //if(current.direction != previous.direction) - //{ - // m_direction = current.direction; - // current.direction = current.direction; - //} - - //if (current.states.shooting) { - // m_animstate = Anim::SHOOTING; - //} - //else if (current.states.jumping) { - // m_animstate = Anim::JUMPING; - //} - //else if (current.states.dead) { - // m_animstate = Anim::DEAD; - //} - //else if(current.states.powerup){ - // m_animstate = Anim::POWERUP; - //} - //else if (current.states.still) { - // m_animstate = Anim::STILL; - //} - //else if (current.states.running) { - // m_animstate = Anim::RUNNING; - //} - - //previous.direction = current.direction; - //previous.position = current.position; - //previous.states = current.states; - //previous.id = current.id; - - //m_direction = current.direction; - //m_position = current.position; } From 90892ce7d382a91903d489db0028471582e6f783 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sat, 16 Dec 2023 15:52:39 -0500 Subject: [PATCH 43/47] pop. --- SQCSim-common/bullet.cpp | 4 ++-- SQCSim-srv/server.cpp | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/SQCSim-common/bullet.cpp b/SQCSim-common/bullet.cpp index ab3d18e..b55d8af 100644 --- a/SQCSim-common/bullet.cpp +++ b/SQCSim-common/bullet.cpp @@ -18,10 +18,10 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordere for (auto& [key, player] : mapPlayer) { bool hit = false; - if ((m_currentpos - player->GetPosition()).Length() < .5f) { + if ((m_currentpos - player->GetPosition()).Length() < 1.5f) { hit = true; } - else if ((m_currentpos - player->GetPOV()).Length() < .2f) { + else if ((m_currentpos - player->GetPOV()).Length() < .7f) { damage *= 2; // HEADSHOT! hit = true; } diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index 70b5c05..93df310 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -276,7 +276,8 @@ void Server::Run() { default: break; } } - lsPck.clear(); + if (!lsPck.empty()) + lsPck.clear(); /* Process */ @@ -311,7 +312,8 @@ void Server::Run() { else { for (auto& chmo : conn->ChunkDiffs) chunkdiffs.emplace_back(std::move(chmo)); - conn->ChunkDiffs.clear(); + if (!conn->ChunkDiffs.empty()) + conn->ChunkDiffs.clear(); for (auto& bull : conn->Bullets) { bullets.emplace_back(bull); @@ -323,7 +325,8 @@ void Server::Run() { netbull.emplace_back(std::move(nbul)); } - conn->Bullets.clear(); + if (!conn->Bullets.empty()) + conn->Bullets.clear(); } } /* Out */ From 678776d6e66091bccc41cede0c290f91183babb2 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sat, 16 Dec 2023 16:13:20 -0500 Subject: [PATCH 44/47] Remove the dead code. --- SQCSim-common/bullet.cpp | 3 ++ SQCSim-common/player.cpp | 7 --- SQCSim-common/world.cpp | 99 ---------------------------------------- SQCSim-srv/server.cpp | 8 +--- 4 files changed, 5 insertions(+), 112 deletions(-) diff --git a/SQCSim-common/bullet.cpp b/SQCSim-common/bullet.cpp index b55d8af..a88509e 100644 --- a/SQCSim-common/bullet.cpp +++ b/SQCSim-common/bullet.cpp @@ -17,6 +17,9 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordere m_currentpos += m_velocity * elapsedtime; for (auto& [key, player] : mapPlayer) { + if (key == m_shooter_id) + continue; + bool hit = false; if ((m_currentpos - player->GetPosition()).Length() < 1.5f) { hit = true; diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp index 2a14091..1ad5fff 100644 --- a/SQCSim-common/player.cpp +++ b/SQCSim-common/player.cpp @@ -205,11 +205,7 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi void Player::ApplyTransformation(Transformation& transformation, bool rel, bool rot) const { transformation.ApplyRotation(-m_rotX, 1, 0, 0); transformation.ApplyRotation(-m_rotY, 0, 1, 0); - - if (rel) transformation.ApplyTranslation(-GetPOV()); - - } void Player::GetBooster(Booster boosttype) @@ -302,9 +298,6 @@ void Player::InflictDamage(float hitPoints) { if (m_hp < 0) m_hp == 0; - //if (AmIDead()) - //{ // Quand le joueur est mort. - //} } int Player::getScore() const { return m_score; } diff --git a/SQCSim-common/world.cpp b/SQCSim-common/world.cpp index 2791ca1..039bd6b 100644 --- a/SQCSim-common/world.cpp +++ b/SQCSim-common/world.cpp @@ -49,8 +49,6 @@ void World::RemoveChunk(int nbReduit) if (x > WORLD_SIZE_X - nbReduit) chk = m_chunks.Remove(x, y); - // TODO: MakeDirty() les voisins pour qu'ils se redessinent. - if (!chk) continue; @@ -167,7 +165,6 @@ void World::GetScope(unsigned int& x, unsigned int& y) { void World::Update(Bullet* bullets[MAX_BULLETS], const Vector3f& player_pos, BlockInfo* blockinfo[BTYPE_LAST]) { UpdateWorld(player_pos, blockinfo); - //TransposeWorld(player_pos, bullets); } netprot::ChunkMod* World::ChangeBlockAtCursor(BlockType blockType, const Vector3f& player_pos, const Vector3f& player_dir, bool& block, bool net) { @@ -258,7 +255,6 @@ void World::UpdateWorld(const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST] int side = 0; int threads = 0; std::future genThList[THREADS_GENERATE_CHUNKS]; - //std::future delThList[THREADS_DELETE_CHUNKS]; if (frameGenerate > 0) --frameGenerate; if (frameUpdate > 0) --frameUpdate; @@ -349,101 +345,6 @@ void World::UpdateWorld(const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST] side = 0; threads = 0; - - //if (!frameUpdate) - // while (side * CHUNK_SIZE_X <= VIEW_DISTANCE * 2) { - // int tx = -side, ty = -side; - - // for (; tx <= side; ++tx) { - // if (frameUpdate) - // break; - // unsigned int chx = cx + tx * CHUNK_SIZE_X, chy = cy + ty * CHUNK_SIZE_Z; - // if (ChunkAt(chx, 1, chy) && - // ChunkAt(chx, 1, chy)->IsDirty()) { - // updateThList[threads++] = - // std::async(std::launch::async, - // [](Chunk* chunk, BlockInfo* blockinfo[BTYPE_LAST], World* world) { - // chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this); - // if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS; - // } - // } - // for (; ty <= side; ++ty) { - // if (frameUpdate) - // break; - // unsigned int chx = cx + tx * CHUNK_SIZE_X, chy = cy + ty * CHUNK_SIZE_Z; - // if (ChunkAt(chx, 1, chy) && - // ChunkAt(chx, 1, chy)->IsDirty()) { - // updateThList[threads++] = - // std::async(std::launch::async, - // [](Chunk* chunk, BlockInfo* blockinfo[BTYPE_LAST], World* world) { - // chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this); - // if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS; - // } - // } - // for (; tx >= -side; --tx) { - // if (frameUpdate) - // break; - // unsigned int chx = cx + tx * CHUNK_SIZE_X, chy = cy + ty * CHUNK_SIZE_Z; - // if (ChunkAt(chx, 1, chy) && - // ChunkAt(chx, 1, chy)->IsDirty()) { - // updateThList[threads++] = - // std::async(std::launch::async, - // [](Chunk* chunk, BlockInfo* blockinfo[BTYPE_LAST], World* world) { - // chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this); - // if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS; - // } - // } - // for (; ty >= -side; --ty) { - // if (frameUpdate) - // break; - // unsigned int chx = cx + tx * CHUNK_SIZE_X, chy = cy + ty * CHUNK_SIZE_Z; - // if (ChunkAt(chx, 1, chy) && - // ChunkAt(chx, 1, chy)->IsDirty()) { - // updateThList[threads++] = - // std::async(std::launch::async, - // [](Chunk* chunk, BlockInfo* blockinfo[BTYPE_LAST], World* world) { - // chunk->Update(blockinfo, world); return chunk; }, ChunkAt(chx, 1, chy), blockinfo, this); - // if (threads == THREADS_UPDATE_CHUNKS) frameUpdate = FRAMES_UPDATE_CHUNKS; - // } - // } - // if (frameUpdate) - // break; - // ++side; - // } - - //if (threads > 0) { - // for (int i = 0; i < threads; ++i) { - // updateThList[i].wait(); - // Chunk* chunk = updateThList[i].get(); - // chunk->FlushMeshToVBO(); - // } - //} - - threads = 0; - - //int del = THREADS_DELETE_CHUNKS; - //while (!m_tbDeleted.empty() && del--) { // Moins rapide que le bout en dessous, mais -beaucoup- plus stable. - // m_tbDeleted.back()->FlushVBO(); - // m_tbDeleted.back()->~Chunk(); - // m_tbDeleted.pop_back(); - //} - - /*while (!m_tbDeleted.empty() && !frameDelete) { - if (m_tbDeleted.back()) { - m_tbDeleted.back()->FlushVBO(); - delThList[threads] = - std::async(std::launch::async, - [](Chunk* chunk) { delete chunk; }, m_tbDeleted.back()); - m_tbDeleted.pop_back(); - if (++threads > THREADS_DELETE_CHUNKS) frameDelete = FRAMES_DELETE_CHUNKS; - } - else m_tbDeleted.pop_back(); - }*/ - - /*for (int x = 0; x < threads; ++x) { - delThList[x].wait(); - delThList[x].get(); - }*/ } int World::GettbDeleted() const { return m_tbDeleted.size(); } diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index 93df310..09ad867 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -282,11 +282,6 @@ void Server::Run() { /* Process */ if (conn->m_nsync) { - /*if (conn->player->m_hit) { - std::string str = conn->player->GetUsername(); - str = str.append(" has been hit: ").append(std::to_string(conn->player->GetHP())); - Log(str, false, false); - }*/ Timestamp tstamp = conn->Run(m_world); @@ -308,6 +303,7 @@ void Server::Run() { ++deadplayers; conn->player->Eulogy = true; + conn->m_nsync = false; } else { for (auto& chmo : conn->ChunkDiffs) @@ -383,7 +379,7 @@ void Server::Run() { for (auto bull = bullets.begin(); bull != bullets.end(); ++bull) { ChunkMod* cmod = nullptr; Bullet* bullet = *bull; - if (bullet->Update(m_world, (1. / 60.), 1, m_players, &cmod)) { + if (bullet->Update(m_world, (1. / 60.), 50, m_players, &cmod)) { if (cmod) chunkdiffs.emplace_back(cmod); bullit.push_back(bull); From 6efda6122d32773fa72bc142375b5a2468f5d6ca Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sat, 16 Dec 2023 16:21:25 -0500 Subject: [PATCH 45/47] LETS TRY WITHOUT DAS JOOMP --- SQCSim-common/player.cpp | 53 ++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp index 1ad5fff..90191a9 100644 --- a/SQCSim-common/player.cpp +++ b/SQCSim-common/player.cpp @@ -123,15 +123,7 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi bt1 = world->BlockAt(GetPosition().x + input.x, GetPosition().y, GetPosition().z); bt2 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 0.9f, GetPosition().z); bt3 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z); - if (bt1 == BTYPE_AIR && bt2 != BTYPE_AIR && bt3 != BTYPE_AIR) { - if (input.x > 0) - input.x = m_velocity.x = 0.5f; - else - input.x = m_velocity.x = -0.5f; - m_velocity.y = 0.3; - m_velocity.z *= .5f; - } - else if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) { + if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) { input.x = m_velocity.x = 0; m_velocity.z *= .5f; } @@ -139,19 +131,44 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi bt1 = world->BlockAt(GetPosition().x, GetPosition().y, GetPosition().z + input.z); bt2 = world->BlockAt(GetPosition().x, GetPosition().y - 0.9f, GetPosition().z + input.z); bt3 = world->BlockAt(GetPosition().x, GetPosition().y - 1.7f, GetPosition().z + input.z); - if (bt1 == BTYPE_AIR && bt2 != BTYPE_AIR && bt3 != BTYPE_AIR) { - if (input.z > 0) - input.z = m_velocity.z = 0.5f; - else - input.z = m_velocity.z = -0.5f; - m_velocity.y = 0.3; - m_velocity.x *= .5f; - } - else if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) { + if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) { input.z = m_velocity.z = 0; m_velocity.x *= .5f; } + + //bt1 = world->BlockAt(GetPosition().x + input.x, GetPosition().y, GetPosition().z); + //bt2 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 0.9f, GetPosition().z); + //bt3 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z); + //if (bt1 == BTYPE_AIR && bt2 != BTYPE_AIR && bt3 != BTYPE_AIR) { + // if (input.x > 0) + // input.x = m_velocity.x = 0.5f; + // else + // input.x = m_velocity.x = -0.5f; + // m_velocity.y = 0.3; + // m_velocity.z *= .5f; + //} + //else if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) { + // input.x = m_velocity.x = 0; + // m_velocity.z *= .5f; + //} + + //bt1 = world->BlockAt(GetPosition().x, GetPosition().y, GetPosition().z + input.z); + //bt2 = world->BlockAt(GetPosition().x, GetPosition().y - 0.9f, GetPosition().z + input.z); + //bt3 = world->BlockAt(GetPosition().x, GetPosition().y - 1.7f, GetPosition().z + input.z); + //if (bt1 == BTYPE_AIR && bt2 != BTYPE_AIR && bt3 != BTYPE_AIR) { + // if (input.z > 0) + // input.z = m_velocity.z = 0.5f; + // else + // input.z = m_velocity.z = -0.5f; + // m_velocity.y = 0.3; + // m_velocity.x *= .5f; + //} + //else if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) { + // input.z = m_velocity.z = 0; + // m_velocity.x *= .5f; + //} + /* Fin gestion de collisions */ /* Gestion de la friction */ From 75f745efb859e26550b0e2ef7de13051cbc85363 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sat, 16 Dec 2023 16:23:47 -0500 Subject: [PATCH 46/47] Update player.cpp --- SQCSim-common/player.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp index 90191a9..5d73e3e 100644 --- a/SQCSim-common/player.cpp +++ b/SQCSim-common/player.cpp @@ -136,7 +136,6 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi m_velocity.x *= .5f; } - //bt1 = world->BlockAt(GetPosition().x + input.x, GetPosition().y, GetPosition().z); //bt2 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 0.9f, GetPosition().z); //bt3 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z); From 0782f37e0a1f5200daea2643bc6c8d768fb983f1 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sat, 16 Dec 2023 16:43:25 -0500 Subject: [PATCH 47/47] Might as well jump, JUMP! --- SQCSim-common/player.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp index 5d73e3e..5b322d5 100644 --- a/SQCSim-common/player.cpp +++ b/SQCSim-common/player.cpp @@ -124,15 +124,19 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi bt2 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 0.9f, GetPosition().z); bt3 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z); if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) { - input.x = m_velocity.x = 0; + //input.x = m_velocity.x = 0; + m_velocity.y += .04f; m_velocity.z *= .5f; + m_velocity.x *= .5f; } bt1 = world->BlockAt(GetPosition().x, GetPosition().y, GetPosition().z + input.z); bt2 = world->BlockAt(GetPosition().x, GetPosition().y - 0.9f, GetPosition().z + input.z); bt3 = world->BlockAt(GetPosition().x, GetPosition().y - 1.7f, GetPosition().z + input.z); if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) { - input.z = m_velocity.z = 0; + //input.z = m_velocity.z = 0; + m_velocity.y += .04f; + m_velocity.z *= .5f; m_velocity.x *= .5f; }