Merge pull request #8 from CegepSTH/sqc_xxx_cleanup

Cleanup de l'objet Bullet - Vérifié
This commit is contained in:
mduval76 2023-09-30 17:16:10 -04:00 committed by GitHub
commit aacb3b4ceb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 82 additions and 85 deletions

View File

@ -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;
}

View File

@ -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__

View File

@ -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) {

View File

@ -24,7 +24,8 @@ namespace netprot {
left,
right,
jump,
shoot;
shoot,
block;
};
struct States {

View File

@ -20,7 +20,6 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="audio.h" />
<ClInclude Include="bullet.h" />
<ClInclude Include="chunk.h" />
<ClInclude Include="connector.h" />
<ClInclude Include="define.h" />
@ -38,7 +37,6 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="audio.cpp" />
<ClCompile Include="bullet.cpp" />
<ClCompile Include="chunk.cpp" />
<ClCompile Include="connector.cpp" />
<ClCompile Include="engine.cpp" />

View File

@ -56,9 +56,6 @@
<ClInclude Include="tool.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
<ClInclude Include="bullet.h">
<Filter>Fichiers d%27en-tête</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="chunk.cpp">
@ -106,8 +103,5 @@
<ClCompile Include="tool.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
<ClCompile Include="bullet.cpp">
<Filter>Fichiers sources</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -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;
}

View File

@ -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__

View File

@ -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;
}

View File

@ -5,8 +5,8 @@
#include <cmath>
#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"

View File

@ -7,7 +7,7 @@
#include <thread>
#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"