From 183c5f186a58435740cf0248b5ac32062d92f62d Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Tue, 3 Oct 2023 12:43:54 -0400 Subject: [PATCH 1/6] =?UTF-8?q?Architecture=20g=C3=A9n=C3=A9rale?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SQCSim-common/player.cpp | 6 ++++ SQCSim-common/player.h | 8 ++++- SQCSim2021/SQCSim2021.vcxproj | 5 ++-- SQCSim2021/SQCSim2021.vcxproj.filters | 7 +++-- SQCSim2021/connector.h | 2 ++ SQCSim2021/engine.cpp | 4 +-- SQCSim2021/engine.h | 4 +-- SQCSim2021/remoteplayer.h | 25 ++++++++++++++++ .../{worldrenderer.cpp => renderer.cpp} | 16 ++++++---- SQCSim2021/renderer.h | 30 +++++++++++++++++++ SQCSim2021/worldrenderer.h | 23 -------------- 11 files changed, 93 insertions(+), 37 deletions(-) create mode 100644 SQCSim2021/remoteplayer.h rename SQCSim2021/{worldrenderer.cpp => renderer.cpp} (92%) create mode 100644 SQCSim2021/renderer.h delete mode 100644 SQCSim2021/worldrenderer.h diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp index 9fe810c..10ec32c 100644 --- a/SQCSim-common/player.cpp +++ b/SQCSim-common/player.cpp @@ -8,6 +8,8 @@ Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(po m_username = "Zelda Bee-Bop56"; } +Player::~Player() {} + void Player::TurnLeftRight(float value) { m_rotY += value; if (m_rotY > 360) m_rotY = 0; @@ -206,3 +208,7 @@ void Player::Teleport(int& x, int& z) { m_position.x -= x * CHUNK_SIZE_X; m_position.z -= z * CHUNK_SIZE_Z; } + +Vector3f Player::InterpolatePosition(const Vector3f& vec1, const Vector3f& vec2, const Timestamp& tim1, const Timestamp& tim2, const Timestamp& now) { + return Vector3f(); +} diff --git a/SQCSim-common/player.h b/SQCSim-common/player.h index e439fa2..d592613 100644 --- a/SQCSim-common/player.h +++ b/SQCSim-common/player.h @@ -12,6 +12,8 @@ public: enum Sound { NOSOUND, STEP, FALL }; Player(const Vector3f& position, float rotX = 0, float rotY = 0); + ~Player(); + void TurnLeftRight(float value); void TurnTopBottom(float value); Vector3f GetInput(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime); @@ -26,12 +28,13 @@ public: float GetHP() const; void Teleport(int& x, int& z); -private: +protected: Vector3f m_position; Vector3f m_velocity; Vector3f m_direction; std::string m_username; + uint64_t id = 0; float m_rotX = 0; float m_rotY = 0; @@ -40,6 +43,9 @@ private: float m_hp; bool m_airborne; + + Vector3f InterpolatePosition(const Vector3f& vec1, const Vector3f& vec2, const Timestamp& tim1, const Timestamp& tim2, const Timestamp& now); + }; #endif //_PLAYER_H__ diff --git a/SQCSim2021/SQCSim2021.vcxproj b/SQCSim2021/SQCSim2021.vcxproj index d120d7b..eadb743 100644 --- a/SQCSim2021/SQCSim2021.vcxproj +++ b/SQCSim2021/SQCSim2021.vcxproj @@ -25,13 +25,14 @@ + - + @@ -46,7 +47,7 @@ - + diff --git a/SQCSim2021/SQCSim2021.vcxproj.filters b/SQCSim2021/SQCSim2021.vcxproj.filters index 3bf0928..b5d2499 100644 --- a/SQCSim2021/SQCSim2021.vcxproj.filters +++ b/SQCSim2021/SQCSim2021.vcxproj.filters @@ -47,7 +47,10 @@ Fichiers d%27en-tête - + + Fichiers d%27en-tête + + Fichiers d%27en-tête @@ -88,7 +91,7 @@ Fichiers sources - + Fichiers sources diff --git a/SQCSim2021/connector.h b/SQCSim2021/connector.h index 297be6f..3ded42b 100644 --- a/SQCSim2021/connector.h +++ b/SQCSim2021/connector.h @@ -17,6 +17,8 @@ public: //void SendInput(); //int Sync(); + + // void updateRemotePlayers(std::map rplayers); private: #ifdef _WIN32 WSADATA m_wsaData; diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index f44eb96..2e2d99f 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -531,9 +531,9 @@ void Engine::Render(float elapsedTime) { m_bullets[x] = nullptr; } - m_wrenderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas); + m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas); m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo); - m_wrenderer.UpdateWorld(&m_world, m_player.GetPosition(), m_blockinfo); + m_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo); if (m_isSkybox) m_skybox.Render(skybox); diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index fa3a088..5d85415 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -18,7 +18,7 @@ #include "audio.h" #include "textureatlas.h" #include "connector.h" -#include "worldrenderer.h" +#include "renderer.h" class Engine : public OpenglContext { public: @@ -60,7 +60,7 @@ private: TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST); World m_world = World(); - WorldRenderer m_wrenderer = WorldRenderer(); + Renderer m_renderer = Renderer(); Texture m_textureSkybox; Texture m_textureFont; diff --git a/SQCSim2021/remoteplayer.h b/SQCSim2021/remoteplayer.h new file mode 100644 index 0000000..bc84d76 --- /dev/null +++ b/SQCSim2021/remoteplayer.h @@ -0,0 +1,25 @@ +#ifndef REMOTEPLAYER_H__ +#define REMOTEPLAYER_H__ +#include "../SQCSim-common/player.h" +#include "../SQCSim-common/netprotocol.h" +#include "define.h" +#include "textureatlas.h" +#include "shader.h" + +class RemotePlayer : public Player { +public: + enum Anim { STILL, RUNNING, JUMPING, SHOOTING, JUMPSHOOT, DEAD }; + + RemotePlayer(); + + void Init(); + void Feed(const netprot::Output out); + +private: + netprot::Output current, next; + float m_aminacc; + Anim m_animstate; + uint64_t m_team_id; + +}; +#endif \ No newline at end of file diff --git a/SQCSim2021/worldrenderer.cpp b/SQCSim2021/renderer.cpp similarity index 92% rename from SQCSim2021/worldrenderer.cpp rename to SQCSim2021/renderer.cpp index dcf6d45..e506c94 100644 --- a/SQCSim2021/worldrenderer.cpp +++ b/SQCSim2021/renderer.cpp @@ -1,13 +1,13 @@ -#include "worldrenderer.h" +#include "renderer.h" -WorldRenderer::WorldRenderer() { +Renderer::Renderer() { m_meshes.Reset(nullptr); } -WorldRenderer::~WorldRenderer() { +Renderer::~Renderer() { } -void WorldRenderer::RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation& world, Shader& shader, TextureAtlas& atlas) { +void Renderer::RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation& world, Shader& shader, TextureAtlas& atlas) const { rendercount = 0; Vector3f angle; Vector3f cursor; @@ -107,7 +107,7 @@ void WorldRenderer::RenderWorld(World* origin, int& rendercount, const Vector3f& glStencilFunc(GL_GREATER, 1, 0xFF); }; -void WorldRenderer::UpdateWorld(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]) { +void Renderer::UpdateMesh(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]) { int cx = player.x; int cy = player.z; static int frameUpdate = 2; @@ -211,3 +211,9 @@ void WorldRenderer::UpdateWorld(World* origin, const Vector3f& player, BlockInfo } } } + +void Renderer::RenderPlayer(Player* player, Transformation tran) const { +} + +void Renderer::RenderPlayer(RemotePlayer* rplayer, const Vector3f& player_pos, const Vector3f& player_dir) const { +} diff --git a/SQCSim2021/renderer.h b/SQCSim2021/renderer.h new file mode 100644 index 0000000..8afdc3b --- /dev/null +++ b/SQCSim2021/renderer.h @@ -0,0 +1,30 @@ +#ifndef RENDERER_H__ +#define RENDERER_H__ +#include +#include +#include "../SQCSim-common/world.h" +#include "../SQCSim-common/transformation.h" +#include "define.h" +#include "mesh.h" +#include "textureatlas.h" +#include "shader.h" +#include "remoteplayer.h" + +class Renderer { +private: + Array2d m_meshes = Array2d(WORLD_SIZE_X, WORLD_SIZE_Y); + + TextureAtlas* m_playertext = nullptr; + Shader* m_playershader = nullptr; + +public: + Renderer(); + ~Renderer(); + + void UpdateMesh(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]); + + void RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation& world, Shader& shader, TextureAtlas& atlas) const; + void RenderPlayer(Player* player, Transformation tran) const; + void RenderPlayer(RemotePlayer* rplayer, const Vector3f& player_pos, const Vector3f& player_dir) const; +}; +#endif \ No newline at end of file diff --git a/SQCSim2021/worldrenderer.h b/SQCSim2021/worldrenderer.h deleted file mode 100644 index 46e6624..0000000 --- a/SQCSim2021/worldrenderer.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef WORLDRENDERER_H__ -#define WORLDRENDERER_H__ -#include -#include -#include "../SQCSim-common/world.h" -#include "../SQCSim-common/transformation.h" -#include "define.h" -#include "mesh.h" -#include "textureatlas.h" -#include "shader.h" - -class WorldRenderer { -private: - Array2d m_meshes = Array2d(WORLD_SIZE_X, WORLD_SIZE_Y); - -public: - WorldRenderer(); - ~WorldRenderer(); - - void RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation& world, Shader& shader, TextureAtlas& atlas); - void UpdateWorld(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]); -}; -#endif \ No newline at end of file From d7e55c8446847867c2735be03969d4f53cea037a Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Sun, 15 Oct 2023 16:23:43 -0400 Subject: [PATCH 2/6] =?UTF-8?q?D=C3=A9but=20de=20la=20classe=20remoteplaye?= =?UTF-8?q?r.cpp,=20=C3=A0=20v=C3=A9rifier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + SQCSim-common/netprotocol.h | 6 ++- SQCSim2021/SQCSim2021.vcxproj | 1 + SQCSim2021/SQCSim2021.vcxproj.filters | 3 ++ SQCSim2021/remoteplayer.cpp | 65 +++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 SQCSim2021/remoteplayer.cpp diff --git a/.gitignore b/.gitignore index f0c1c5a..1e812db 100644 --- a/.gitignore +++ b/.gitignore @@ -373,3 +373,5 @@ FodyWeavers.xsd /x64/Release/SQCSim2023.exe /x64/Debug/SQCSim2023.exe /x64/Debug/SQCSim2021.pdb +SQCSim2021/SQCSim2021.vcxproj.filters +SQCSim2021/SQCSim2021.vcxproj diff --git a/SQCSim-common/netprotocol.h b/SQCSim-common/netprotocol.h index d7c7a93..f7692b4 100644 --- a/SQCSim-common/netprotocol.h +++ b/SQCSim-common/netprotocol.h @@ -33,7 +33,11 @@ namespace netprot { bool jumping, shooting, hit, - powerup; + powerup, + dead, + still, + jumpshot, + running; }; struct Input { // cli -> srv UDP ~frame diff --git a/SQCSim2021/SQCSim2021.vcxproj b/SQCSim2021/SQCSim2021.vcxproj index eadb743..04701c8 100644 --- a/SQCSim2021/SQCSim2021.vcxproj +++ b/SQCSim2021/SQCSim2021.vcxproj @@ -41,6 +41,7 @@ + diff --git a/SQCSim2021/SQCSim2021.vcxproj.filters b/SQCSim2021/SQCSim2021.vcxproj.filters index b5d2499..5c8a864 100644 --- a/SQCSim2021/SQCSim2021.vcxproj.filters +++ b/SQCSim2021/SQCSim2021.vcxproj.filters @@ -94,5 +94,8 @@ Fichiers sources + + Fichiers sources + \ No newline at end of file diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp new file mode 100644 index 0000000..6dfb3a4 --- /dev/null +++ b/SQCSim2021/remoteplayer.cpp @@ -0,0 +1,65 @@ +#include "remoteplayer.h" +#include +#include + + +RemotePlayer::RemotePlayer() : Player(Vector3f(0, 0, 0), 0, 0), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), next() { + +} + +void RemotePlayer::Init() { + +} + +void RemotePlayer::Feed(const netprot::Output out) { + + next.position = out.position; + next.direction = out.direction; + next.states = out.states; + next.id = out.id; + + //a revoir pour le jump et le shoot en meme temps lorsque les test seront possible + + if (current.position != next.position) + { + Vector3f positionDelta = next.position - current.position; + m_position = next.position + positionDelta; + m_direction = next.direction; + m_team_id = next.id; + + } + + if(next.direction != current.direction) + { + m_direction = next.direction; + current.direction = next.direction; + } + + if (next.states.shooting) { + m_animstate = Anim::SHOOTING; + } + else if (next.states.jumping) { + m_animstate = Anim::JUMPING; + } + else if (next.states.dead) { + m_animstate = Anim::DEAD; + } + else if(next.states.jumpshot){ + m_animstate = Anim::JUMPSHOOT; + } + else if (next.states.still) { + m_animstate = Anim::STILL; + } + else if (next.states.running) { + m_animstate = Anim::RUNNING; + } + + + current.direction = next.direction; + current.position = next.position; + current.states = next.states; + current.id = next.id; + + + +} \ No newline at end of file From 67a49a4cadbff5e46ff055f44b2284a763f40afd Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Mon, 23 Oct 2023 15:35:31 -0400 Subject: [PATCH 3/6] push de remote player --- SQCSim2021/remoteplayer.cpp | 54 ++++++++++++++++++++----------------- SQCSim2021/remoteplayer.h | 4 +-- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index 6dfb3a4..1bf39c9 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -3,7 +3,7 @@ #include -RemotePlayer::RemotePlayer() : Player(Vector3f(0, 0, 0), 0, 0), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), next() { +RemotePlayer::RemotePlayer() : Player(Vector3f(0, 0, 0), 0, 0), m_aminacc(0.0f), m_animstate(Anim::STILL), m_team_id(0), current(), previous() { } @@ -13,52 +13,58 @@ void RemotePlayer::Init() { void RemotePlayer::Feed(const netprot::Output out) { - next.position = out.position; - next.direction = out.direction; - next.states = out.states; - next.id = out.id; + current.position = out.position; + current.direction = out.direction; + current.states = out.states; + current.id = out.id; //a revoir pour le jump et le shoot en meme temps lorsque les test seront possible - if (current.position != next.position) + if (current.position != previous.position) { - Vector3f positionDelta = next.position - current.position; - m_position = next.position + positionDelta; - m_direction = next.direction; - m_team_id = next.id; + Vector3f positionDelta = current.position - previous.position; + m_position = current.position + positionDelta; + m_direction = current.direction; + m_team_id = current.id; } - if(next.direction != current.direction) + if(current.direction != previous.direction) { - m_direction = next.direction; - current.direction = next.direction; + m_direction = current.direction; + current.direction = current.direction; } - if (next.states.shooting) { + if (current.states.shooting) { + true; m_animstate = Anim::SHOOTING; } - else if (next.states.jumping) { + else if (current.states.jumping) { + true; m_animstate = Anim::JUMPING; } - else if (next.states.dead) { + else if (current.states.dead) { + true; m_animstate = Anim::DEAD; } - else if(next.states.jumpshot){ - m_animstate = Anim::JUMPSHOOT; + else if(current.states.powerup){ + true; + m_animstate = Anim::POWERUP; } - else if (next.states.still) { + else if (current.states.still) { + true; m_animstate = Anim::STILL; } - else if (next.states.running) { + else if (current.states.running) { + true; m_animstate = Anim::RUNNING; } - current.direction = next.direction; - current.position = next.position; - current.states = next.states; - current.id = next.id; + previous.direction = current.direction; + previous.position = current.position; + previous.states = current.states; + previous.id = current.id; diff --git a/SQCSim2021/remoteplayer.h b/SQCSim2021/remoteplayer.h index bc84d76..70b585b 100644 --- a/SQCSim2021/remoteplayer.h +++ b/SQCSim2021/remoteplayer.h @@ -8,7 +8,7 @@ class RemotePlayer : public Player { public: - enum Anim { STILL, RUNNING, JUMPING, SHOOTING, JUMPSHOOT, DEAD }; + enum Anim { STILL = 1, RUNNING = 2, JUMPING = 4, SHOOTING = 8, POWERUP = 16, DEAD = 32 }; RemotePlayer(); @@ -16,7 +16,7 @@ public: void Feed(const netprot::Output out); private: - netprot::Output current, next; + netprot::Output current, previous; float m_aminacc; Anim m_animstate; uint64_t m_team_id; From ae201846b14bbb027ca63f482020ccba22d22d78 Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Fri, 27 Oct 2023 13:54:37 -0400 Subject: [PATCH 4/6] push de correction --- SQCSim2021/remoteplayer.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index 1bf39c9..6ff160c 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -25,7 +25,8 @@ void RemotePlayer::Feed(const netprot::Output out) { Vector3f positionDelta = current.position - previous.position; m_position = current.position + positionDelta; m_direction = current.direction; - m_team_id = current.id; + //Rajouter un get ID public dans la classe player + //m_team_id = current.id; } @@ -36,27 +37,27 @@ void RemotePlayer::Feed(const netprot::Output out) { } if (current.states.shooting) { - true; + //true; m_animstate = Anim::SHOOTING; } else if (current.states.jumping) { - true; + //true; m_animstate = Anim::JUMPING; } else if (current.states.dead) { - true; + //true; m_animstate = Anim::DEAD; } else if(current.states.powerup){ - true; + //true; m_animstate = Anim::POWERUP; } else if (current.states.still) { - true; + //true; m_animstate = Anim::STILL; } else if (current.states.running) { - true; + //true; m_animstate = Anim::RUNNING; } From 57d60e02a76eb1332816abbb837a58d0cf32f854 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Fri, 27 Oct 2023 13:55:15 -0400 Subject: [PATCH 5/6] getId() --- SQCSim-common/player.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp index 10ec32c..57c2259 100644 --- a/SQCSim-common/player.cpp +++ b/SQCSim-common/player.cpp @@ -209,6 +209,8 @@ void Player::Teleport(int& x, int& z) { m_position.z -= z * CHUNK_SIZE_Z; } +uint64_t Player::getId() const { return id; } + Vector3f Player::InterpolatePosition(const Vector3f& vec1, const Vector3f& vec2, const Timestamp& tim1, const Timestamp& tim2, const Timestamp& now) { return Vector3f(); } From 889884490b84b7c652b33a09fc19257e45d179e5 Mon Sep 17 00:00:00 2001 From: Claudel-D-Roy <112507354+Claudel-D-Roy@users.noreply.github.com> Date: Fri, 27 Oct 2023 13:56:48 -0400 Subject: [PATCH 6/6] push avant merge --- SQCSim2021/remoteplayer.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp index 6ff160c..1d2de20 100644 --- a/SQCSim2021/remoteplayer.cpp +++ b/SQCSim2021/remoteplayer.cpp @@ -24,9 +24,7 @@ void RemotePlayer::Feed(const netprot::Output out) { { Vector3f positionDelta = current.position - previous.position; m_position = current.position + positionDelta; - m_direction = current.direction; - //Rajouter un get ID public dans la classe player - //m_team_id = current.id; + m_direction = current.direction; }