Compare commits

..

No commits in common. "2c346139d5a4f8e73ffd2013c64ddc24c8ae269d" and "4255830d4f3aa84974d128999574a85f4e4fc534" have entirely different histories.

31 changed files with 488 additions and 860 deletions

View File

@ -48,7 +48,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset> <PlatformToolset>ClangCL</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>

View File

@ -3,34 +3,27 @@
Bullet::Bullet(Vector3f pos, Vector3f dir) : m_startpos(pos), m_currentpos(pos), m_velocity(dir) {} 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() {} Bullet::~Bullet() {}
bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordered_map<uint64_t, Player*> mapPlayer, netprot::ChunkMod** chunkmod) { bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordered_map<uint64_t, Player*> mapPlayer, netprot::ChunkMod** chunkmod) {
int max = 100 / perframe; int max = 100 / perframe;
float damage = 0.098f; float damage = 0.057f;
for (int x = 0; x < max; ++x) { for (int x = 0; x < max; ++x) {
m_currentpos += m_velocity * elapsedtime; m_currentpos += m_velocity * elapsedtime;
for (auto& [key, player] : mapPlayer) { for (auto& [key, player] : mapPlayer) {
if (key == m_shooter_id)
continue;
bool hit = false; bool hit = false;
if ((m_currentpos - player->GetPosition()).Length() < 1.5f) { if ((m_currentpos - player->GetPosition()).Length() < .6f) {
hit = true; hit = true;
} }
else if ((m_currentpos - player->GetPOV()).Length() < .7f) { if ((m_currentpos - player->GetPOV()).Length() < .2f) {
damage *= 2; // HEADSHOT! damage *= 2; // HEADSHOT!
hit = true; hit = true;
} }
if (hit && !player->AmIDead()) { if (hit && !player->AmIDead()) {
if (m_canhurt) player->InflictDamage(damage);
player->InflictDamage(damage);
player->m_hit = true; player->m_hit = true;
if (player->AmIDead()) if (player->AmIDead())
@ -43,17 +36,15 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordere
if (!world->ChunkAt(m_currentpos)) if (!world->ChunkAt(m_currentpos))
return true; return true;
else if (world->BlockAt(m_currentpos) != BTYPE_AIR) { else if (world->BlockAt(m_currentpos) != BTYPE_AIR) {
if (m_canhurt) { if (chunkmod) {
if (chunkmod) { using namespace netprot;
using namespace netprot; *chunkmod = new ChunkMod();
*chunkmod = new ChunkMod(); (*chunkmod)->old_b_type = world->BlockAt(m_currentpos);
(*chunkmod)->old_b_type = world->BlockAt(m_currentpos); (*chunkmod)->b_type = BTYPE_AIR;
(*chunkmod)->b_type = BTYPE_AIR; (*chunkmod)->pos = m_currentpos;
(*chunkmod)->pos = m_currentpos;
}
world->ChangeBlockAtPosition(BTYPE_AIR, m_currentpos);
} }
world->ChangeBlockAtPosition(BTYPE_AIR, m_currentpos);
return true; return true;
} }
else if ((m_currentpos - m_startpos).Length() > VIEW_DISTANCE) return true; else if ((m_currentpos - m_startpos).Length() > VIEW_DISTANCE) return true;

View File

@ -14,7 +14,6 @@ class Bullet {
public: public:
Bullet(Vector3f pos, Vector3f dir); Bullet(Vector3f pos, Vector3f dir);
Bullet(Vector3f pos, Vector3f dir, uint64_t tid); Bullet(Vector3f pos, Vector3f dir, uint64_t tid);
Bullet(Vector3f pos, Vector3f dir, uint64_t tid, bool canhurt);
~Bullet(); ~Bullet();
bool Update(World* world, float elapsedtime, int perframe, std::unordered_map<uint64_t, Player*> m_mapPlayer, netprot::ChunkMod** chunkmod); bool Update(World* world, float elapsedtime, int perframe, std::unordered_map<uint64_t, Player*> m_mapPlayer, netprot::ChunkMod** chunkmod);
@ -29,8 +28,6 @@ private:
m_velocity; m_velocity;
uint64_t m_shooter_id = 0; uint64_t m_shooter_id = 0;
bool m_canhurt = true;
}; };

View File

@ -35,10 +35,7 @@
#define TIME_DAMAGE_BOOST 10 //secondes #define TIME_DAMAGE_BOOST 10 //secondes
#define TIME_INVINCIBLE_BOOST 4 //secondes #define TIME_INVINCIBLE_BOOST 4 //secondes
#define STRENGTH_SPEED_BOOST 10 //Pourcentage #define STRENGTH_SPEED_BOOST 10 //Pourcentage
#define BULLET_TIME .2 //secondes #define BULLET_TIME .1
#define SYNC_ACC 600 // ms
#define CMOD_ACC 1000 // ms
typedef uint8_t BlockType; typedef uint8_t BlockType;
enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_GREENGRASS, BTYPE_LAST }; enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_GREENGRASS, BTYPE_LAST };

View File

@ -4,15 +4,14 @@
Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(position), m_rotX(rotX), m_rotY(rotY) { Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(position), m_rotX(rotX), m_rotY(rotY) {
m_velocity = Vector3f(0, 0, 0); m_velocity = Vector3f(0, 0, 0);
m_airborne = true; m_airborne = true;
m_hp = 1.0f; m_hp = 1.0f; //TODO: Remettre <20> 1.0f
m_sensitivity = 0.5f;
m_username = "Zelda Bee-Bop56"; m_username = "Zelda Bee-Bop56";
} }
Player::~Player() {} Player::~Player() {}
void Player::TurnLeftRight(float value, float sensitivity) { void Player::TurnLeftRight(float value) {
m_rotY += value * sensitivity; m_rotY += value;
if (m_rotY > 360) m_rotY = 0; if (m_rotY > 360) m_rotY = 0;
else if (m_rotY < -360) m_rotY = 0; else if (m_rotY < -360) m_rotY = 0;
@ -26,8 +25,8 @@ void Player::TurnLeftRight(float value, float sensitivity) {
m_direction.Normalize(); m_direction.Normalize();
} }
void Player::TurnTopBottom(float value, float sensitivity) { void Player::TurnTopBottom(float value) {
m_rotX += value * sensitivity; m_rotX += value;
if (m_rotX > 80) m_rotX = 80; if (m_rotX > 80) m_rotX = 80;
else if (m_rotX < -80) m_rotX = -80; else if (m_rotX < -80) m_rotX = -80;
@ -79,7 +78,7 @@ Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jum
} }
if (shoot) // Recoil! if (shoot) // Recoil!
TurnTopBottom(-1, 1.0f); TurnTopBottom(-1);
return delta; return delta;
} }
@ -123,54 +122,34 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi
bt1 = world->BlockAt(GetPosition().x + input.x, GetPosition().y, GetPosition().z); bt1 = world->BlockAt(GetPosition().x + input.x, GetPosition().y, GetPosition().z);
bt2 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 0.9f, 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); bt3 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z);
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; if (input.x > 0)
m_velocity.y += .04f; 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; m_velocity.z *= .5f;
m_velocity.x *= .5f;
} }
bt1 = world->BlockAt(GetPosition().x, GetPosition().y, GetPosition().z + input.z); bt1 = world->BlockAt(GetPosition().x, GetPosition().y, GetPosition().z + input.z);
bt2 = world->BlockAt(GetPosition().x, GetPosition().y - 0.9f, 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); bt3 = world->BlockAt(GetPosition().x, GetPosition().y - 1.7f, GetPosition().z + input.z);
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; if (input.z > 0)
m_velocity.y += .04f; input.z = m_velocity.z = 0.5f;
m_velocity.z *= .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; 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 */ /* Fin gestion de collisions */
/* Gestion de la friction */ /* Gestion de la friction */
@ -225,7 +204,11 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi
void Player::ApplyTransformation(Transformation& transformation, bool rel, bool rot) const { void Player::ApplyTransformation(Transformation& transformation, bool rel, bool rot) const {
transformation.ApplyRotation(-m_rotX, 1, 0, 0); transformation.ApplyRotation(-m_rotX, 1, 0, 0);
transformation.ApplyRotation(-m_rotY, 0, 1, 0); transformation.ApplyRotation(-m_rotY, 0, 1, 0);
if (rel) transformation.ApplyTranslation(-GetPOV()); if (rel) transformation.ApplyTranslation(-GetPOV());
} }
void Player::GetBooster(Booster boosttype) void Player::GetBooster(Booster boosttype)
@ -287,24 +270,8 @@ Vector3f Player::GetDirection() const { return m_direction; }
std::string Player::GetUsername() const { return m_username; } std::string Player::GetUsername() const { return m_username; }
void Player::SetUsername(std::string username) {
m_username = username;
}
float Player::GetSensitivity() const {
return m_sensitivity;
}
void Player::SetSensitivity(float sensitivity) {
m_sensitivity = sensitivity;
}
float Player::GetHP() const { return m_hp; } float Player::GetHP() const { return m_hp; }
void Player::SetHP(float hp) {
m_hp = hp;
}
void Player::Teleport(int& x, int& z) { void Player::Teleport(int& x, int& z) {
m_position.x -= x * CHUNK_SIZE_X; m_position.x -= x * CHUNK_SIZE_X;
m_position.z -= z * CHUNK_SIZE_Z; m_position.z -= z * CHUNK_SIZE_Z;
@ -318,6 +285,9 @@ void Player::InflictDamage(float hitPoints) {
if (m_hp < 0) if (m_hp < 0)
m_hp == 0; m_hp == 0;
//if (AmIDead())
//{ // Quand le joueur est mort.
//}
} }
int Player::getScore() const { return m_score; } int Player::getScore() const { return m_score; }

View File

@ -16,8 +16,8 @@ public:
Player(const Vector3f& position, float rotX = 0, float rotY = 0); Player(const Vector3f& position, float rotX = 0, float rotY = 0);
~Player(); ~Player();
void TurnLeftRight(float value, float sensitivity); void TurnLeftRight(float value);
void TurnTopBottom(float value, float sensitivity); void TurnTopBottom(float value);
Vector3f GetInput(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime); Vector3f GetInput(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime);
Sound ApplyPhysics(Vector3f input, World* world, float elapsedTime); Sound ApplyPhysics(Vector3f input, World* world, float elapsedTime);
void GetBooster(Booster boosttype); void GetBooster(Booster boosttype);
@ -32,11 +32,7 @@ public:
Vector3f GetVelocity() const; Vector3f GetVelocity() const;
Vector3f GetPOV() const; Vector3f GetPOV() const;
std::string GetUsername() const; std::string GetUsername() const;
void SetUsername(std::string username);
float GetSensitivity() const;
void SetSensitivity(float sensitivity);
float GetHP() const; float GetHP() const;
void SetHP(float hp);
void Teleport(int& x, int& z); void Teleport(int& x, int& z);
bool GetIsAirborne() const; bool GetIsAirborne() const;
@ -48,8 +44,6 @@ public:
std::string m_username; std::string m_username;
bool m_hit = false; bool m_hit = false;
bool Eulogy = false;
private: private:
uint64_t getId() const; uint64_t getId() const;
@ -67,7 +61,6 @@ protected:
float timeboostspeed; float timeboostspeed;
float timeboostdamage; float timeboostdamage;
float timeboostinvincible; float timeboostinvincible;
float m_sensitivity;
float m_hp; float m_hp;
@ -76,6 +69,8 @@ protected:
bool boostdamage; bool boostdamage;
bool boostinvincible; bool boostinvincible;
Vector3f InterpolatePosition(const Vector3f& vec1, const Vector3f& vec2, const Timestamp& tim1, const Timestamp& tim2, const Timestamp& now); Vector3f InterpolatePosition(const Vector3f& vec1, const Vector3f& vec2, const Timestamp& tim1, const Timestamp& tim2, const Timestamp& now);
}; };
#endif //_PLAYER_H__ #endif //_PLAYER_H__

View File

@ -49,6 +49,8 @@ void World::RemoveChunk(int nbReduit)
if (x > WORLD_SIZE_X - nbReduit) if (x > WORLD_SIZE_X - nbReduit)
chk = m_chunks.Remove(x, y); chk = m_chunks.Remove(x, y);
// TODO: MakeDirty() les voisins pour qu'ils se redessinent.
if (!chk) if (!chk)
continue; continue;
@ -165,6 +167,7 @@ void World::GetScope(unsigned int& x, unsigned int& y) {
void World::Update(Bullet* bullets[MAX_BULLETS], const Vector3f& player_pos, BlockInfo* blockinfo[BTYPE_LAST]) { void World::Update(Bullet* bullets[MAX_BULLETS], const Vector3f& player_pos, BlockInfo* blockinfo[BTYPE_LAST]) {
UpdateWorld(player_pos, blockinfo); 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) { netprot::ChunkMod* World::ChangeBlockAtCursor(BlockType blockType, const Vector3f& player_pos, const Vector3f& player_dir, bool& block, bool net) {
@ -255,6 +258,7 @@ void World::UpdateWorld(const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]
int side = 0; int side = 0;
int threads = 0; int threads = 0;
std::future<Chunk*> genThList[THREADS_GENERATE_CHUNKS]; std::future<Chunk*> genThList[THREADS_GENERATE_CHUNKS];
//std::future<void> delThList[THREADS_DELETE_CHUNKS];
if (frameGenerate > 0) --frameGenerate; if (frameGenerate > 0) --frameGenerate;
if (frameUpdate > 0) --frameUpdate; if (frameUpdate > 0) --frameUpdate;
@ -345,6 +349,101 @@ void World::UpdateWorld(const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]
side = 0; side = 0;
threads = 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(); } int World::GettbDeleted() const { return m_tbDeleted.size(); }

View File

@ -48,7 +48,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset> <PlatformToolset>ClangCL</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>

View File

@ -59,9 +59,7 @@ void Connection::getPacks(SOCKET sock) {
switch (netprot::getType(pck, 1)) { switch (netprot::getType(pck, 1)) {
using enum netprot::PACKET_TYPE; using enum netprot::PACKET_TYPE;
case INPUT: case INPUT:
if (player->AmIDead()) if (Deserialize(&in, pck, &bsize)) {
break;
else if (Deserialize(&in, pck, &bsize)) {
m_input_manifest[in.timestamp] = in; m_input_manifest[in.timestamp] = in;
m_input_vector.push_back(in); m_input_vector.push_back(in);
} }
@ -79,23 +77,8 @@ void Connection::getPacks(SOCKET sock) {
void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*> conns, const uint32_t timer) { void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*> conns, const uint32_t timer) {
static int outs = 0; static int outs = 0;
static Timestamp last = 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<Sync>(sock, &sync, &m_bufout, &m_addr);
}
}
while (!m_output_vector.empty()) { while (!m_output_vector.empty()) {
Output out = m_output_vector.front(); Output out = m_output_vector.front();
for (auto& [key, conn] : conns) { for (auto& [key, conn] : conns) {
if (m_playinfo.id == conn->GetHash(false)) if (m_playinfo.id == conn->GetHash(false))
continue; continue;
@ -108,23 +91,16 @@ void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*
outs += out.timestamp + last; outs += out.timestamp + last;
static bool syncdead = false; if (outs >= 1000) {
bool dead = player->AmIDead(); outs -= 1000;
if (outs >= SYNC_ACC || (!syncdead && dead)) {
Sync sync; Sync sync;
outs -= SYNC_ACC; sync.hp = player->GetHP();
sync.timestamp = out.timestamp; sync.timestamp = out.timestamp;
sync.position = out.position; sync.position = out.position;
sync.sid = m_loginfo.sid; sync.sid = m_loginfo.sid;
sync.timer = timer; sync.timer = timer;
sync.timestamp = out.timestamp; sync.timestamp = out.timestamp;
sync.ammo = -1; sync.ammo = -1;
sync.hp = player->GetHP();
if (dead) {
sync.timestamp = m_loginfo.sid;
syncdead = true;
}
sendPackTo<Sync>(sock, &sync, &m_bufout, &m_addr); sendPackTo<Sync>(sock, &sync, &m_bufout, &m_addr);
} }
@ -138,33 +114,27 @@ Timestamp Connection::Run(World* world) {
Timestamp tstamp = 0; Timestamp tstamp = 0;
float el; float el;
bool dead = player->AmIDead(); if (m_input_manifest.size() < 2)
if (m_input_manifest.size() < 2 && !dead)
return tstamp; return tstamp;
while (m_last_in < m_input_vector.size() - 1 || dead) { if (player->AmIDead()) {
if (!dead) { m_input_manifest.clear();
in = m_input_vector.at(m_last_in + 1); return tstamp;
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);
}
else {
el = 1. / 60.;
in = Input();
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);
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);
player->ApplyPhysics(player->GetInput(in.keys.forward, player->ApplyPhysics(player->GetInput(in.keys.forward,
in.keys.backward, in.keys.backward,
in.keys.left, in.keys.left,
@ -177,10 +147,7 @@ Timestamp Connection::Run(World* world) {
} }
out.states.jumping = player->GetIsAirborne(); out.states.jumping = player->GetIsAirborne();
out.states.running = player->GetVelocity().Length() > .5f;
Vector3f horSpeed = player->GetVelocity();
horSpeed.y = 0;
out.states.running = horSpeed.Length() > .2f;
out.states.still = !out.states.running && !out.states.jumping; out.states.still = !out.states.running && !out.states.jumping;
out.states.hit = player->m_hit; out.states.hit = player->m_hit;
player->m_hit = false; player->m_hit = false;
@ -213,7 +180,7 @@ Timestamp Connection::Run(World* world) {
else out.states.jumpshot = false; else out.states.jumpshot = false;
if (in.keys.shoot && m_shoot_acc <= 0.) { if (in.keys.shoot && m_shoot_acc <= 0.) {
Bullets.emplace_back(new Bullet(player->GetPOV() + player->GetDirection(), player->GetDirection(), GetHash(true))); Bullets.push_back(std::move(new Bullet(player->GetPOV() + player->GetDirection(), player->GetDirection(), GetHash(true))));
m_shoot_acc = BULLET_TIME; m_shoot_acc = BULLET_TIME;
} }
@ -223,12 +190,9 @@ Timestamp Connection::Run(World* world) {
out.id = m_playinfo.id; out.id = m_playinfo.id;
m_output_manifest[out.timestamp] = out; m_output_manifest[out.timestamp] = out;
m_output_vector.push_back(out); m_output_vector.push_back(out);
m_tstamp = tstamp = out.timestamp; tstamp = out.timestamp;
if (!dead) ++m_last_in;
++m_last_in;
dead = false;
} }
return tstamp; return tstamp;

View File

@ -202,8 +202,8 @@ void Server::Run() {
m_conns.erase(key); m_conns.erase(key);
continue; continue;
} }
int x = (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1) - (CHUNK_SIZE_X * WORLD_SIZE_X / 2)) / 16, 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)) / 16; y = (rand() % (CHUNK_SIZE_Y * WORLD_SIZE_Y - 1) - (CHUNK_SIZE_Y * WORLD_SIZE_Y / 2)) / 8;
conn->player = new Player(Vector3f(x + .5f, CHUNK_SIZE_Y + 1.8f, y + .5f)); conn->player = new Player(Vector3f(x + .5f, CHUNK_SIZE_Y + 1.8f, y + .5f));
conn->player->m_username = conn->GetName(); conn->player->m_username = conn->GetName();
m_players[key] = conn->player; m_players[key] = conn->player;
@ -217,7 +217,7 @@ void Server::Run() {
sendPackTo<Sync>(m_sock_udp, &sync, &m_buf, conn->getAddr()); sendPackTo<Sync>(m_sock_udp, &sync, &m_buf, conn->getAddr());
} }
int timer = m_game.countdown, timer_acc = 0, deadplayers = 0; int timer = m_game.countdown, sync_acc = 0, deadplayers = 0;
std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now(); std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();
Timestamp last = 0; Timestamp last = 0;
std::vector<Chat*> chatlog; std::vector<Chat*> chatlog;
@ -230,23 +230,22 @@ void Server::Run() {
Chat* startchat = new Chat(); Chat* startchat = new Chat();
startchat->src_id = 0; startchat->src_id = 0;
char startmess[] = "How would -YOU- like to die today, motherf-words?"; char startmess[] = "How would -YOU- like to die today, motherf-words?";
float endtime = 0.;
strcpy(startchat->mess, 140, startmess); strcpy(startchat->mess, 140, startmess);
chatlog.emplace_back(startchat); chatlog.emplace_back(startchat);
while (!endgame && endtime < 1.) { while (!endgame) {
using namespace std::chrono; using namespace std::chrono;
Timestamp tstamp = duration_cast<milliseconds>(high_resolution_clock::now() - start).count(); Timestamp tstamp = duration_cast<milliseconds>(high_resolution_clock::now() - start).count();
if (last == 0) if (last == 0)
last = tstamp; last = tstamp;
timer_acc += tstamp - last; sync_acc += tstamp - last;
if (timer_acc >= 1000) { if (sync_acc >= 1000) {
while (timer_acc >= 1000) while (sync_acc >= 1000)
timer_acc -= 1000; sync_acc -= 1000;
if (!endgame) --timer;
--timer;
std::string str = "Timer: "; std::string str = "Timer: ";
Log(str.append(std::to_string(timer)), false, false); Log(str.append(std::to_string(timer)), false, false);
} }
@ -276,43 +275,34 @@ void Server::Run() {
default: break; default: break;
} }
} }
if (!lsPck.empty()) lsPck.clear();
lsPck.clear();
/* Process */ /* Process */
if (conn->m_nsync) { if (conn->m_nsync) {
Timestamp tstamp = conn->Run(m_world); Timestamp tstamp = conn->Run(m_world);
if (conn->player->AmIDead() && !conn->player->Eulogy) { if (conn->player->AmIDead()) {
Chat* chat = new Chat(); 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;
Player* murderer = m_conns.at(conn->player->Killer)->player; std::string killer = m_conns.at(conn->player->Killer)->player->GetUsername();
if (murderer != conn->player)
murderer->addPoint();
std::string killer = murderer->GetUsername();
std::string mess = getDeathMessage(conn->player->GetUsername(), killer); std::string mess = getDeathMessage(conn->player->GetUsername(), killer);
strcpy(chat->mess, 140, mess.c_str()); strcpy(chat->mess, 140, mess.c_str());
chatlog.emplace_back(chat); chatlog.emplace_back(chat);
++deadplayers; ++deadplayers;
conn->player->Eulogy = true;
conn->m_nsync = false; conn->m_nsync = false;
} }
else { else {
for (auto& chmo : conn->ChunkDiffs) for (auto& chmo : conn->ChunkDiffs)
chunkdiffs.emplace_back(std::move(chmo)); chunkdiffs.emplace_back(std::move(chmo));
if (!conn->ChunkDiffs.empty()) conn->ChunkDiffs.clear();
conn->ChunkDiffs.clear();
for (auto& bull : conn->Bullets) { for (auto& bull : conn->Bullets) {
bullets.emplace_back(bull); bullets.emplace_back(bull);
//Log("POW!", false, false);
BulletAdd* nbul = new BulletAdd(); BulletAdd* nbul = new BulletAdd();
nbul->pos = bull->getPos(); nbul->pos = bull->getPos();
nbul->dir = bull->getVel(); nbul->dir = bull->getVel();
@ -321,50 +311,15 @@ void Server::Run() {
netbull.emplace_back(std::move(nbul)); netbull.emplace_back(std::move(nbul));
} }
if (!conn->Bullets.empty()) conn->Bullets.clear();
conn->Bullets.clear();
} }
/* Out */
conn->sendPacks(m_sock_udp, m_conns, timer);
} }
/* Out */ if ((deadplayers == players - 1 && deadplayers != 0) || timer <= 0)
conn->sendPacks(m_sock_udp, m_conns, timer);
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; endgame = true;
endtime += .001;
}
} }
for (auto& bull : netbull) { for (auto& bull : netbull) {
@ -373,43 +328,36 @@ void Server::Run() {
sendPackTo<BulletAdd>(m_sock_udp, bull, &m_buf, conn->getAddr()); sendPackTo<BulletAdd>(m_sock_udp, bull, &m_buf, conn->getAddr());
delete bull; delete bull;
} }
if (!netbull.empty()) netbull.clear();
netbull.clear();
for (auto bull = bullets.begin(); bull != bullets.end(); ++bull) { for (auto bull = bullets.begin(); bull != bullets.end(); ++bull) {
ChunkMod* cmod = nullptr; ChunkMod* cmod = nullptr;
Bullet* bullet = *bull; Bullet* bullet = *bull;
if (bullet->Update(m_world, (1. / 60.), 50, m_players, &cmod)) { if (bullet->Update(m_world, (1. / 60.), 20, m_players, &cmod)) {
if (cmod) if (cmod)
chunkdiffs.emplace_back(cmod); chunkdiffs.emplace_back(cmod);
bullit.push_back(bull); bullit.push_back(bull);
delete bullet;
} }
} }
for (auto& bull: bullit)
for (auto& bull : bullit) {
delete* bull;
bullets.erase(bull); bullets.erase(bull);
} bullit.clear();
if (!bullit.empty())
bullit.clear();
for (auto& chat : chatlog) { for (auto& chat : chatlog) {
Log(chat->mess, false, false); Log(chat->mess, false, false);
for (auto& [key, conn] : m_conns) for (auto& [key, conn] : m_conns)
sendPackTo<Chat>(m_sock_udp, chat, &m_buf, conn->getAddr()); sendPackTo<Chat>(m_sock_udp, chat, &m_buf, conn->getAddr());
delete chat; delete chat;
} }
if (!chatlog.empty()) chatlog.clear();
chatlog.clear();
for (auto& chmo : chunkdiffs) { for (auto& chmo : chunkdiffs) {
for (auto& [key, conn] : m_conns) for (auto& [key, conn] : m_conns)
sendPackTo<ChunkMod>(m_sock_udp, chmo, &m_buf, conn->getAddr()); sendPackTo<ChunkMod>(m_sock_udp, chmo, &m_buf, conn->getAddr());
delete chmo; delete chmo;
} }
if (!chunkdiffs.empty()) chunkdiffs.clear();
chunkdiffs.clear();
} }
Chat end; Chat end;
@ -419,7 +367,8 @@ void Server::Run() {
for (auto& [key, conn] : m_conns) { for (auto& [key, conn] : m_conns) {
std::string str = conn->player->GetUsername(); std::string str = conn->player->GetUsername();
Log(str.append(" ").append(std::to_string(conn->player->getScore())), false, false); Log(str.append(" ").append(std::to_string(conn->player->GetHP())), false, false);
} }
for (auto& [key, conn] : m_conns) for (auto& [key, conn] : m_conns)

View File

@ -91,7 +91,7 @@
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v143</PlatformToolset> <PlatformToolset>ClangCL</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
@ -196,7 +196,7 @@
<FloatingPointModel>Fast</FloatingPointModel> <FloatingPointModel>Fast</FloatingPointModel>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation> <GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>

View File

@ -2,40 +2,26 @@
Audio::Audio() { Audio::Audio() {
m_engine = irrklang::createIrrKlangDevice(); m_engine = irrklang::createIrrKlangDevice();
m_engine->setDopplerEffectParameters(1); m_engine->setDopplerEffectParameters(10);
m_engine->setRolloffFactor(1); m_engine->setRolloffFactor(2);
m_engine->setDefault3DSoundMinDistance(1); m_engine->setDefault3DSoundMinDistance(.1);
m_engine->setDefault3DSoundMaxDistance(1000); m_engine->setDefault3DSoundMaxDistance(1000);
} }
Audio::Audio(const char * music, const char* menumusic) { Audio::Audio(const char * music) {
m_engine = irrklang::createIrrKlangDevice(); m_engine = irrklang::createIrrKlangDevice();
m_engine->setDopplerEffectParameters(1); m_engine->setDopplerEffectParameters(1);
m_engine->setRolloffFactor(1); m_engine->setRolloffFactor(2);
m_engine->setDefault3DSoundMinDistance(1); m_engine->setDefault3DSoundMinDistance(.1);
m_engine->setDefault3DSoundMaxDistance(100); m_engine->setDefault3DSoundMaxDistance(1000);
m_music = m_engine->play2D(music, true, true, true, irrklang::ESM_STREAMING); m_music = m_engine->play2D(music, true, true, true, irrklang::ESM_STREAMING);
m_menumusic = m_engine->play2D(menumusic, true, true, true, irrklang::ESM_STREAMING);
m_music->setVolume(.5);
m_menumusic->setVolume(.5);
m_mainvolume = 0.5f;
m_engine->setSoundVolume(m_mainvolume);
m_sfxvolume = 0.5f;
} }
Audio::~Audio() { Audio::~Audio() {
if (m_music) m_music->drop(); if (m_music) m_music->drop();
if (m_menumusic) m_menumusic->drop();
if (m_engine) m_engine->drop(); if (m_engine) m_engine->drop();
} }
void Audio::playSound(const char* name, float volume = 1.) {
irrklang::ISound* sfx = m_engine->play2D(name, false, true);
sfx->setVolume(volume);
sfx->setIsPaused(false);
m_sfxes.push_back(sfx);
}
void Audio::Update3DAudio(Vector3f pos, Vector3f dir, Vector3f vel) { void Audio::Update3DAudio(Vector3f pos, Vector3f dir, Vector3f vel) {
m_engine->setListenerPosition(irrklang::vec3df(pos.x, pos.y, pos.z), m_engine->setListenerPosition(irrklang::vec3df(pos.x, pos.y, pos.z),
irrklang::vec3df(dir.x, dir.y, dir.z), irrklang::vec3df(dir.x, dir.y, dir.z),
@ -43,10 +29,9 @@ void Audio::Update3DAudio(Vector3f pos, Vector3f dir, Vector3f vel) {
} }
irrklang::ISound* Audio::Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f pos, Vector3f vel, bool is_looped = false, float volume = 1) { irrklang::ISound* Audio::Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f pos, Vector3f vel, bool is_looped = false, float volume = 1) {
sound = m_engine->play3D(name, irrklang::vec3df(pos.x, pos.y, pos.z), is_looped, true, true, is_looped? irrklang::ESM_STREAMING: irrklang::ESM_NO_STREAMING, true); sound = m_engine->play3D(name, irrklang::vec3df(pos.x, pos.y, pos.z), is_looped, false, true, is_looped? irrklang::ESM_STREAMING: irrklang::ESM_NO_STREAMING, true);
sound->setVelocity(irrklang::vec3df(vel.x, vel.y, vel.z)); sound->setVelocity(irrklang::vec3df(vel.x, vel.y, vel.z));
sound->setVolume(volume); sound->setVolume(volume);
sound->setIsPaused(false);
return sound; return sound;
} }
@ -60,76 +45,10 @@ void Audio::Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& v
// m_music = m_engine->play2D(music, false, false, false, irrklang::ESM_STREAMING); // m_music = m_engine->play2D(music, false, false, false, irrklang::ESM_STREAMING);
//} //}
void Audio::CleanupSFX() { void Audio::ToggleMusicState() { m_music->setIsPaused(!m_music->getIsPaused()); }
while (!m_sfxes.empty()) {
irrklang::ISound* sfx = m_sfxes.back();
if (sfx->isFinished()) {
sfx->drop(); // drop() fait deja la job du delete sfx.
}
else break;
m_sfxes.pop_back();
}
}
void Audio::ToggleMusicState(GameState state) {
if (m_music_on) {
switch (state) {
case PLAY:
m_music->setIsPaused(false);
m_menumusic->setIsPaused(true);
break;
case PAUSE:
m_music->setIsPaused(true);
m_menumusic->setIsPaused(true);
break;
default:
m_music->setIsPaused(true);
m_menumusic->setIsPaused(false);
break;
}
}
else {
m_music->setIsPaused(true);
m_menumusic->setIsPaused(true);
}
}
void Audio::SetMusic(bool ison, GameState state) {
m_music_on = state;
if (!state) {
m_music->setIsPaused(true);
m_menumusic->setIsPaused(true);
}
else ToggleMusicState(state);
}
bool Audio::GetMusic() {
return m_music_on;
}
void Audio::PauseEngine() { m_engine->setAllSoundsPaused(); } void Audio::PauseEngine() { m_engine->setAllSoundsPaused(); }
float Audio::GetMusicVolume() const { float Audio::GetMusicVolume() const {
return m_music->getVolume(); return m_music->getVolume();
} }
void Audio::SetMusicVolume(float volume) {
m_music->setVolume(volume);
m_menumusic->setVolume(volume);
}
float Audio::GetMainVolume() const {
return m_engine->getSoundVolume();
}
void Audio::SetMainVolume(float volume) {
m_engine->setSoundVolume(volume);
}
float Audio::GetSfxVolume() const {
return m_sfxvolume;
}
void Audio::SetSfxVolume(float volume) {
m_sfxvolume = volume;
}

View File

@ -15,46 +15,26 @@
class Audio { class Audio {
private: private:
irrklang::ISound* m_music; irrklang::ISound* m_music;
irrklang::ISound* m_menumusic;
float m_mainvolume;
float m_sfxvolume;
bool m_music_on = true;
std::vector<irrklang::ISound*> m_sfxes;
public: public:
Audio(); Audio();
Audio(const char* music, const char* menumusic); Audio(const char* music);
~Audio(); ~Audio();
irrklang::ISoundEngine* m_engine; irrklang::ISoundEngine* m_engine;
void Update3DAudio(Vector3f pos, Vector3f dir, Vector3f speed); void Update3DAudio(Vector3f pos, Vector3f dir, Vector3f speed);
irrklang::ISound* Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f pos, Vector3f vel, bool is_looped, float volume); irrklang::ISound* Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f pos, Vector3f vel, bool is_looped, float volume);
void Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& vel, float volume); void Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& vel, float volume);
//void PlaySong(const char* music); //void PlaySong(const char* music);
void CleanupSFX(); void ToggleMusicState();
void ToggleMusicState(GameState state);
void playSound(const char* sound, float volume);
void SetMusic(bool ison, GameState state);
bool GetMusic();
void PauseEngine(); void PauseEngine();
float GetMainVolume() const;
void SetMainVolume(float volume);
float GetMusicVolume() const; float GetMusicVolume() const;
void SetMusicVolume(float volume);
float GetSfxVolume() const;
void SetSfxVolume(float volume);
}; };
#endif // AUDIO_H__ #endif // AUDIO_H__

View File

@ -25,8 +25,8 @@
#define BULLET_UPDATES_PER_FRAME 20 #define BULLET_UPDATES_PER_FRAME 20
#define BASE_WIDTH 1280 #define BASE_WIDTH 640
#define BASE_HEIGHT 720 #define BASE_HEIGHT 480
#define ANIME_PATH_JUMP "./media/textures/AssetOtherPlayer/FinalPNGJumping/" #define ANIME_PATH_JUMP "./media/textures/AssetOtherPlayer/FinalPNGJumping/"
@ -50,6 +50,7 @@ enum GameState {
SPLASH, SPLASH,
LOBBY, LOBBY,
OPTIONS, OPTIONS,
QUIT,
PLAY, PLAY,
PAUSE PAUSE
}; };
@ -58,7 +59,7 @@ enum Resolution {
HD = 0, // 1280x720 (High Definition) HD = 0, // 1280x720 (High Definition)
FHD, // 1920x1080 (Full HD) FHD, // 1920x1080 (Full HD)
QHD, // 2560x1440 (Quad HD) QHD, // 2560x1440 (Quad HD)
UHD, // 3840x2160 (Ultra HD) UHD // 3840x2160 (Ultra HD)
}; };
#endif // DEFINE_H__ #endif // DEFINE_H__

View File

View File

@ -0,0 +1 @@

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -49,7 +49,6 @@ private:
bool StartMultiplayerGame(); bool StartMultiplayerGame();
bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true); bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true);
void ChangeResolution(Resolution resolution);
void InstantDamage(); void InstantDamage();
void SystemNotification(std::string systemLog); void SystemNotification(std::string systemLog);
@ -74,8 +73,6 @@ private:
void SetPlayerUsername(float elapsedTime); void SetPlayerUsername(float elapsedTime);
void SetServerAddress(float elapsedTime); void SetServerAddress(float elapsedTime);
void DisplayPauseMenu(float elapsedTime);
void DisplayOptionsMenu(); void DisplayOptionsMenu();
void DisplayAudioMenu(float centerX, float centerY); void DisplayAudioMenu(float centerX, float centerY);
void DisplayGraphicsMenu(float centerX, float centerY); void DisplayGraphicsMenu(float centerX, float centerY);
@ -89,7 +86,8 @@ private:
char SimulateKeyboard(unsigned char key); char SimulateKeyboard(unsigned char key);
void HandlePlayerInput(float elapsedTime); void HandlePlayerInput(float elapsedTime);
Audio m_audio = Audio(AUDIO_PATH "music01.wav", AUDIO_PATH "menumusic01.wav"); //udio m_menuaudio = Audio(AUDIO_PATH "menumusic.wav");
Audio m_audio = Audio(AUDIO_PATH "music01.wav");
irrklang::ISound* m_powpow, * m_scream; irrklang::ISound* m_powpow, * m_scream;
irrklang::ISound* m_whoosh[MAX_BULLETS]; irrklang::ISound* m_whoosh[MAX_BULLETS];
@ -140,9 +138,6 @@ private:
Texture m_textureCheck; Texture m_textureCheck;
Texture m_textureChecked; Texture m_textureChecked;
Texture m_texturePauseResume;
Texture m_texturePauseMainMenu;
Texture m_textureOptAudio; Texture m_textureOptAudio;
Texture m_textureOptBack; Texture m_textureOptBack;
Texture m_textureOptGameplay; Texture m_textureOptGameplay;
@ -177,10 +172,10 @@ private:
int m_nbReductionChunk = 4; int m_nbReductionChunk = 4;
int m_timerReductionChunk = 30; int m_timerReductionChunk = 30;
float m_mainvolume; float m_volPrincipal = 0.0f;
float m_musicvolume; float m_volMusique = 0.0f;
float m_sfxvolume; float m_volEffets = 0.0f;
float m_sensitivity; float m_volSensible = 0.0f;
int m_selectedOption = 0; int m_selectedOption = 0;
@ -209,18 +204,13 @@ private:
std::string m_currentInputString; std::string m_currentInputString;
std::string m_username; std::string m_username;
std::string m_serverAddr; std::string m_serverAddr;
char m_inputChar = 0; char m_inputChar = 0;
bool m_invalidChar = false; bool m_invalidChar = false;
bool m_charChanged = false; bool m_charChanged = false;
bool m_settingUsername = false; bool m_settingUsername = false;
bool m_settingServer = false; bool m_settingServer = false;
bool m_selectedSinglePlayer = false;
bool m_selectedMultiPlayer = false;
bool m_singleReady = false;
bool m_multiReady = false; bool m_multiReady = false;
bool m_key1 = false; bool m_key1 = false;
bool m_key2 = false; bool m_key2 = false;
bool m_keyK = false; bool m_keyK = false;
@ -249,7 +239,6 @@ private:
std::deque<netprot::ChunkMod*> m_chunkmod_manifest; std::deque<netprot::ChunkMod*> m_chunkmod_manifest;
std::chrono::high_resolution_clock::time_point m_startTime; std::chrono::high_resolution_clock::time_point m_startTime;
std::unordered_map<uint64_t, Player*> m_players; std::unordered_map<uint64_t, Player*> m_players;
std::set<uint64_t> m_deadplayers;
netprot::Buffer m_buf, m_bufout; netprot::Buffer m_buf, m_bufout;
netprot::ChunkMod* m_chunkmod = nullptr; netprot::ChunkMod* m_chunkmod = nullptr;

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 596 KiB

After

Width:  |  Height:  |  Size: 562 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

View File

@ -53,9 +53,9 @@ protected:
void ShowCrossCursor() const; void ShowCrossCursor() const;
bool m_istarted = false; bool m_istarted = false;
void InitWindow(int width, int height);
private: private:
void InitWindow(int width, int height);
MOUSE_BUTTON ConvertMouseButton(sf::Mouse::Button button) const; MOUSE_BUTTON ConvertMouseButton(sf::Mouse::Button button) const;
private: private:

View File

@ -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) {
} }
@ -31,9 +31,54 @@ void RemotePlayer::Feed(const netprot::Output out) {
m_position = Vector3f(out.position); m_position = Vector3f(out.position);
m_direction = Vector3f(out.direction); m_direction = Vector3f(out.direction);
current.states = out.states; 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;
} }
@ -73,25 +118,26 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
int index = 0; int index = 0;
angle = -angle; angle = -angle;
Vector3f side = angleRemote.Cross(angleCam); Vector3f side = angleRemote.Cross(angleCam);
side = -side;
static float time = 0.f; static float time = 0.f;
static bool Shooting = false; static bool Shooting = false;
bool isLeft = side.y > 0; bool isLeft = side.y > 0;
time += elapsedTime; time += elapsedTime;
if (time >= 0.05) if (time >= 200)
{ {
time -= 0.05; time -= 200;
if (!current.states.shooting)
Shooting = !Shooting; Shooting = false;
else
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;
if (angle >= 0.75) //Face - side positif if (angle >= 0.75) //Face - side positif
{ {
if (current.states.shooting) { if(current.states.shooting){
if (Shooting) if (Shooting)
index = 17; index = 17;
else else
@ -105,7 +151,7 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
} }
else if (current.states.jumping) else if (current.states.jumping)
index = 25; index = 25;
else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) else if (current.states.running && current.states.still)
index = 0; index = 0;
} }
@ -116,7 +162,6 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
index = 18; index = 18;
else else
index = 10; index = 10;
} }
else if (current.states.jumpshot) { else if (current.states.jumpshot) {
if (Shooting) if (Shooting)
@ -124,12 +169,11 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
else else
index = 34; index = 34;
} }
else if (current.states.jumping) else if (current.states.jumping )
index = 26; index = 26;
else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) else if (current.states.running && current.states.still)
index = 1; index = 1;
} }
else if (angle >= -0.25 && isLeft) //ProfileLeft else if (angle >= -0.25 && isLeft) //ProfileLeft
{ {
@ -138,20 +182,18 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
index = 20; index = 20;
else else
index = 12; index = 12;
} }
else if (current.states.jumpshot) { else if (current.states.jumpshot ) {
if (Shooting) if (Shooting)
index = 44; index = 44;
else else
index = 36; index = 36;
} }
else if (current.states.jumping) else if (current.states.jumping )
index = 28; index = 28;
else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) else if (current.states.running && current.states.still)
index = 3; index = 3;
} }
else if (angle >= -0.75 && isLeft) //BackLeft else if (angle >= -0.75 && isLeft) //BackLeft
{ {
@ -160,7 +202,6 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
index = 22; index = 22;
else else
index = 14; index = 14;
} }
else if (current.states.jumpshot) { else if (current.states.jumpshot) {
if (Shooting) if (Shooting)
@ -170,10 +211,8 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
} }
else if (current.states.jumping) else if (current.states.jumping)
index = 30; index = 30;
else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) else if (current.states.running && current.states.still)
index = 5; index = 5;
} }
else if (angle < -0.75) //Dos - side négatif else if (angle < -0.75) //Dos - side négatif
{ {
@ -182,7 +221,6 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
index = 24; index = 24;
else else
index = 16; index = 16;
} }
else if (current.states.jumpshot) { else if (current.states.jumpshot) {
if (Shooting) if (Shooting)
@ -190,14 +228,13 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
else else
index = 40; index = 40;
} }
else if (current.states.jumping) else if (current.states.jumping )
index = 32; index = 32;
else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) else if (current.states.running && current.states.still)
index = 7; index = 7;
} }
else if (angle >= 0.25 && !isLeft) //FrontRight //REVOIR L'ANIME DE SHOOTING EST PAS DRETTE else if (angle >= 0.25 && !isLeft) //FrontRight
{ {
if (current.states.shooting) { if (current.states.shooting) {
if (Shooting) if (Shooting)
@ -213,10 +250,9 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
} }
else if (current.states.jumping) else if (current.states.jumping)
index = 27; index = 27;
else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) else if (current.states.running && current.states.still)
index = 2; index = 2;
} }
else if (angle >= -0.25 && !isLeft) //ProfileRight else if (angle >= -0.25 && !isLeft) //ProfileRight
{ {
@ -234,10 +270,9 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
} }
else if (current.states.jumping) else if (current.states.jumping)
index = 29; index = 29;
else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) else if (current.states.running && current.states.still)
index = 4; index = 4;
} }
else if (angle >= -0.75 && !isLeft) //BackRight else if (angle >= -0.75 && !isLeft) //BackRight
{ {
@ -246,7 +281,6 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
index = 23; index = 23;
else else
index = 15; index = 15;
} }
else if (current.states.jumpshot) { else if (current.states.jumpshot) {
if (Shooting) if (Shooting)
@ -256,10 +290,9 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
} }
else if (current.states.jumping) else if (current.states.jumping)
index = 31; index = 31;
else if (!current.states.jumping && !current.states.shooting && !current.states.jumpshot) else if (current.states.running && current.states.still)
index = 6; index = 6;
} }
@ -271,25 +304,10 @@ void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tr
atlas.TextureIndexToCoord(index, u, v, w, h); atlas.TextureIndexToCoord(index, u, v, w, h);
glEnable(GL_BLEND); 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); glBlendEquation(GL_FUNC_ADD);
glLoadMatrixf(tran.GetMatrix().GetInternalValues()); glLoadMatrixf(tran.GetMatrix().GetInternalValues());
glDepthFunc(GL_LEQUAL);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(u, v); glVertex3f(v1.x, v1.y, v1.z); glTexCoord2f(u, v); glVertex3f(v1.x, v1.y, v1.z);
glTexCoord2f(u + w, v); glVertex3f(v2.x, v2.y, v2.z); glTexCoord2f(u + w, v); glVertex3f(v2.x, v2.y, v2.z);

View File

@ -14,8 +14,8 @@ class RemotePlayer : public Player {
public: 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 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);
RemotePlayer(netprot::PlayerInfo* pinfo, const Vector3f& pos); RemotePlayer(netprot::PlayerInfo pinfo, const Vector3f& pos);
~RemotePlayer(); ~RemotePlayer();

View File

@ -9,7 +9,7 @@ Settings::Settings(Audio& audio)
m_fullscreen(false), m_fullscreen(false),
m_brightness(0.5f), m_brightness(0.5f),
m_contrast(0.5f), m_contrast(0.5f),
m_mouseSensitivity(0.0f) { m_mouseSensitivity(0.5f) {
ApplyResolution(m_resolution); ApplyResolution(m_resolution);
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.