diff --git a/SQCSim-common/bullet.cpp b/SQCSim-common/bullet.cpp index 52824d5..5c4e6c4 100644 --- a/SQCSim-common/bullet.cpp +++ b/SQCSim-common/bullet.cpp @@ -1,10 +1,9 @@ #include "bullet.h" #include "world.h" -Bullet::Bullet(Player& player) { - m_startpos = m_currentpos = player.GetPOV() + player.GetDirection(); - m_velocity = player.GetDirection(); -} +Bullet::Bullet(Vector3f pos, Vector3f dir) : m_startpos(pos), m_currentpos(pos), m_velocity(dir) {} + +Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t tid): m_startpos(pos), m_currentpos(pos), m_velocity(dir), m_tid(tid) {} Bullet::~Bullet() {} @@ -31,6 +30,10 @@ void Bullet::Transpose(int& x, int& z) { m_startpos.z -= z * CHUNK_SIZE_Z; } -Vector3f& Bullet::getPos() { +Vector3f Bullet::getPos() { return m_currentpos; } + +uint64_t Bullet::getTeamID(){ + return m_tid; +} diff --git a/SQCSim-common/bullet.h b/SQCSim-common/bullet.h index 599eab6..d17000e 100644 --- a/SQCSim-common/bullet.h +++ b/SQCSim-common/bullet.h @@ -1,23 +1,26 @@ #ifndef BULLET_H__ #define BULLET_H__ - -#include "player.h" +#include "define.h" +#include "vector3.h" class World; class Bullet { public: - Bullet(Player& player); + Bullet(Vector3f pos, Vector3f dir); + Bullet(Vector3f pos, Vector3f dir, uint64_t tid); ~Bullet(); bool Update(World* world, float elapsedtime); void Transpose(int& x, int& z); - Vector3f& getPos(); + Vector3f getPos(); + uint64_t getTeamID(); private: - Vector3f m_startpos; - Vector3f m_currentpos; - Vector3f m_velocity; + Vector3f m_startpos, + m_currentpos, + m_velocity; + uint64_t m_tid = 0; }; #endif // BULLET_H__ diff --git a/SQCSim-common/netprotocol.cpp b/SQCSim-common/netprotocol.cpp index b692201..d4edca2 100644 --- a/SQCSim-common/netprotocol.cpp +++ b/SQCSim-common/netprotocol.cpp @@ -1,7 +1,64 @@ #include "netprotocol.h" void netprot::Serialize(Input* in, char* buf[], uint32_t* buflen) { + *buf[0] = netprot::PACKET_TYPE::INPUT; + uint64_t time = in->timestamp; + uint8_t time8[sizeof(uint64_t)] = {(time >> 56) & 0xFF, + (time >> 48) & 0xFF, + (time >> 40) & 0xFF, + (time >> 32) & 0xFF, + (time >> 24) & 0xFF, + (time >> 16) & 0xFF, + (time >> 8 ) & 0xFF, + time & 0xFF}; + + memcpy(*buf + 1, time8, sizeof(uint64_t)); + + uint64_t sid = in->sid; + uint8_t sid8[sizeof(uint64_t)] = {(sid >> 56) & 0xFF, + (sid >> 48) & 0xFF, + (sid >> 40) & 0xFF, + (sid >> 32) & 0xFF, + (sid >> 24) & 0xFF, + (sid >> 16) & 0xFF, + (sid >> 8 ) & 0xFF, + sid & 0xFF}; + + memcpy(*buf + sizeof(uint64_t) + 1, sid8, sizeof(uint64_t)); + + Keys keys = in->keys; + uint8_t keys8 = // Reste un bit. + keys.forward & 0b10000000 | + keys.backward & 0b01000000 | + keys.left & 0b00100000 | + keys.right & 0b00010000 | + keys.jump & 0b00001000 | + keys.shoot & 0b00000100 | + keys.block & 0b00000010 ; + + memcpy(*buf + sizeof(uint64_t) + 2, &keys8, sizeof(uint8_t)); + + uint32_t vec[3]; + memcpy(vec, &in->direction, sizeof(Vector3f)); // Pour dénaturer les floats. + + uint8_t vec8[3 * sizeof(uint32_t)] = { + (vec[0] >> 24) & 0xFF, + (vec[0] >> 16) & 0xFF, + (vec[0] >> 8) & 0xFF, + vec[0] & 0xFF, + (vec[1] >> 24) & 0xFF, + (vec[1] >> 16) & 0xFF, + (vec[1] >> 8) & 0xFF, + vec[1] & 0xFF, + (vec[2] >> 24) & 0xFF, + (vec[2] >> 16) & 0xFF, + (vec[2] >> 8) & 0xFF, + vec[2] & 0xFF}; + + memcpy(*buf + sizeof(uint64_t) + 3, vec8, sizeof(uint32_t) * 3); + + *buflen = sizeof(uint64_t) + 3 + sizeof(uint32_t) * 3; } void netprot::Serialize(Output* out, char* buf[], uint32_t* buflen) { diff --git a/SQCSim-common/netprotocol.h b/SQCSim-common/netprotocol.h index 7f93349..bdaf0a7 100644 --- a/SQCSim-common/netprotocol.h +++ b/SQCSim-common/netprotocol.h @@ -24,7 +24,8 @@ namespace netprot { left, right, jump, - shoot; + shoot, + block; }; struct States { diff --git a/SQCSim2021/SQCSim2021.vcxproj b/SQCSim2021/SQCSim2021.vcxproj index 005bcc5..02c2b51 100644 --- a/SQCSim2021/SQCSim2021.vcxproj +++ b/SQCSim2021/SQCSim2021.vcxproj @@ -20,7 +20,6 @@ - @@ -38,7 +37,6 @@ - diff --git a/SQCSim2021/SQCSim2021.vcxproj.filters b/SQCSim2021/SQCSim2021.vcxproj.filters index ec7b7d6..0e371d0 100644 --- a/SQCSim2021/SQCSim2021.vcxproj.filters +++ b/SQCSim2021/SQCSim2021.vcxproj.filters @@ -56,9 +56,6 @@ Fichiers d%27en-tête - - Fichiers d%27en-tête - @@ -106,8 +103,5 @@ Fichiers sources - - Fichiers sources - \ No newline at end of file diff --git a/SQCSim2021/bullet.cpp b/SQCSim2021/bullet.cpp deleted file mode 100644 index 38f4901..0000000 --- a/SQCSim2021/bullet.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "bullet.h" -#include "world.h" - -Bullet::Bullet(Player& player) { - m_startpos = m_currentpos = player.GetPOV() + player.GetDirection(); - m_velocity = player.GetDirection(); -} - -Bullet::~Bullet() {} - -bool Bullet::Update(World* world, Transformation& tran, float elapsedtime) { - for (int x = 0; x < 1000; ++x) { - m_currentpos += m_velocity * elapsedtime; - - if (!world->ChunkAt(m_currentpos)) - return true; - else if (world->BlockAt(m_currentpos) != BTYPE_AIR) { - world->ChangeBlockAtPosition(BTYPE_AIR, m_currentpos); - return true; - } - else if ((m_currentpos - m_startpos).Length() > VIEW_DISTANCE) return true; - } - - return false; -} - -void Bullet::Transpose(int& x, int& z) { - m_currentpos.x -= x * CHUNK_SIZE_X; - m_currentpos.z -= z * CHUNK_SIZE_Z; - m_startpos.x -= x * CHUNK_SIZE_X; - m_startpos.z -= z * CHUNK_SIZE_Z; -} diff --git a/SQCSim2021/bullet.h b/SQCSim2021/bullet.h deleted file mode 100644 index ce706f8..0000000 --- a/SQCSim2021/bullet.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef BULLET_H__ -#define BULLET_H__ - -#include "audio.h" -#include "player.h" -#include "vertexbuffer.h" -#include "texture.h" - -class World; - -class Bullet { -public: - Bullet(Player& player); - ~Bullet(); - - bool Update(World* world, Transformation& tran, float elapsedtime); - void Transpose(int& x, int& z); - -private: - Vector3f m_startpos; - Vector3f m_currentpos; - Vector3f m_velocity; - -}; - -#endif // BULLET_H__ - diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 5f21e66..6599890 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -374,12 +374,12 @@ void Engine::Render(float elapsedTime) { else if (bulletTime <= 0.f) { 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] = new Bullet(m_player); + m_bullets[x] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection()); break; } else if (x == MAX_BULLETS - 1) { // S'il y a pas d'espace dans l'array, prendre la place de la première balle de l'array. m_bullets[0]->~Bullet(); - m_bullets[0] = new Bullet(m_player); + m_bullets[0] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection()); } bulletTime = .1f; m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "windowsaccount.wav", m_player.GetPOV(), m_player.GetDirection() * 10, .5f); @@ -396,7 +396,7 @@ void Engine::Render(float elapsedTime) { for (int x = 0; x < MAX_BULLETS; ++x) // Array de bullets en jeu. if (m_bullets[x]) - if (m_bullets[x]->Update(&m_world, all, elapsedTime)) { + if (m_bullets[x]->Update(&m_world, elapsedTime)) { m_bullets[x]->~Bullet(); m_bullets[x] = nullptr; } diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index 5220cf8..8c525b6 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -5,8 +5,8 @@ #include #include "../SQCSim-common/array2d.h" #include "../SQCSim-common/blockinfo.h" +#include "../SQCSim-common/bullet.h" #include "define.h" -#include "bullet.h" #include "openglcontext.h" #include "texture.h" #include "transformation.h" diff --git a/SQCSim2021/world.h b/SQCSim2021/world.h index d2b0dc1..0b88748 100644 --- a/SQCSim2021/world.h +++ b/SQCSim2021/world.h @@ -7,7 +7,7 @@ #include #include "../SQCSim-common/vector3.h" #include "../SQCSim-common/array2d.h" -#include "bullet.h" +#include "../SQCSim-common/bullet.h" #include "define.h" #include "player.h" #include "chunk.h"