diff --git a/.gitignore b/.gitignore index f15149d..8ffde58 100644 --- a/.gitignore +++ b/.gitignore @@ -378,3 +378,5 @@ FodyWeavers.xsd /SQCSim2021/cmake/* !/SQCSim2021/cmake/CMakeLists.txt /SQCSim2021/SQCSim-client +SQCSim2021/SQCSim2021.vcxproj.filters +SQCSim2021/SQCSim2021.vcxproj diff --git a/SQCSim-common/SQCSim-common.vcxproj b/SQCSim-common/SQCSim-common.vcxproj index 991cd1d..c618082 100644 --- a/SQCSim-common/SQCSim-common.vcxproj +++ b/SQCSim-common/SQCSim-common.vcxproj @@ -48,7 +48,7 @@ StaticLibrary false - v143 + ClangCL true Unicode @@ -76,6 +76,7 @@ true WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + stdcpp20 Console @@ -90,6 +91,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + stdcpp20 Console @@ -104,6 +106,7 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + stdcpp20 Console @@ -118,7 +121,7 @@ true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true - stdcpp17 + stdcpp20 Console @@ -131,6 +134,7 @@ + @@ -144,6 +148,7 @@ + diff --git a/SQCSim-common/SQCSim-common.vcxproj.filters b/SQCSim-common/SQCSim-common.vcxproj.filters index 26c6c05..45814cf 100644 --- a/SQCSim-common/SQCSim-common.vcxproj.filters +++ b/SQCSim-common/SQCSim-common.vcxproj.filters @@ -54,6 +54,9 @@ Fichiers d%27en-tête + + Fichiers d%27en-tête + @@ -80,5 +83,8 @@ Fichiers sources + + Fichiers sources + \ No newline at end of file diff --git a/SQCSim-common/boostinfo.cpp b/SQCSim-common/boostinfo.cpp new file mode 100644 index 0000000..9b54626 --- /dev/null +++ b/SQCSim-common/boostinfo.cpp @@ -0,0 +1,32 @@ +#include "boostinfo.h" +#include + +BoostInfo::BoostInfo(BoostType type, const std::string& name, float u, float v, float s, int dur) : m_type(type), m_name(name), m_u(u), m_v(v), m_s(s), m_durability(dur) +{ +} + +BoostInfo::~BoostInfo() +{ +} + +BoostType BoostInfo::GetType() const +{ + return m_type; +} + +void BoostInfo::GetTexture(float& u, float& v, float& s) +{ + u = m_u; + v = m_v; + s = m_s; +} + +void BoostInfo::Show() const +{ + std::cout << "Type: " << m_type << std::endl; + std::cout << "Nom: " << m_name << std::endl; + std::cout << "Durabilite: " << m_durability << std::endl; + std::cout << "Coordonnees Texture: " << m_u << ", " << m_v << ", " << m_s << std::endl; +} + + diff --git a/SQCSim-common/boostinfo.h b/SQCSim-common/boostinfo.h new file mode 100644 index 0000000..e76d1ed --- /dev/null +++ b/SQCSim-common/boostinfo.h @@ -0,0 +1,29 @@ +#ifndef BOOSTINFO_H__ +#define BOOSTINFO_H__ + +#include +#include "define.h" + +class BoostInfo +{ +public: + BoostInfo(BoostType type, const std::string& name, float u, float v, float s, int dur); + ~BoostInfo(); + + BoostType GetType() const; + + void GetTexture(float& u, float& v, float& s); + + void Show() const; + +private: + BoostType m_type; + float m_u; + float m_v; + float m_s; + std::string m_name; + int m_durability; + +}; + +#endif // BOOSTINFO_H__ diff --git a/SQCSim-common/bullet.cpp b/SQCSim-common/bullet.cpp index 873879d..a489c55 100644 --- a/SQCSim-common/bullet.cpp +++ b/SQCSim-common/bullet.cpp @@ -3,24 +3,53 @@ 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(Vector3f pos, Vector3f dir, uint64_t shooter_id): m_startpos(pos), m_currentpos(pos), m_velocity(dir), m_shooter_id(shooter_id) {} Bullet::~Bullet() {} -bool Bullet::Update(World* world, float elapsedtime, int perframe) { +bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordered_map mapPlayer, netprot::ChunkMod** chunkmod) { int max = 100 / perframe; + float damage = 0.057f; for (int x = 0; x < max; ++x) { m_currentpos += m_velocity * elapsedtime; + for (auto& [key, player] : mapPlayer) { + bool hit = false; + if ((m_currentpos - player->GetPosition()).Length() < .6f) { + hit = true; + } + if ((m_currentpos - player->GetPOV()).Length() < .2f) { + damage *= 2; // HEADSHOT! + hit = true; + } + if (hit && !player->AmIDead()) { + player->InflictDamage(damage); + player->m_hit = true; + + if (player->AmIDead()) + player->Killer = m_shooter_id; + + return true; + } + } + 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; + } + world->ChangeBlockAtPosition(BTYPE_AIR, m_currentpos); return true; } else if ((m_currentpos - m_startpos).Length() > VIEW_DISTANCE) return true; } - + return false; } @@ -39,6 +68,6 @@ Vector3f Bullet::getVel() const { return m_velocity; } -uint64_t Bullet::getTeamID(){ - return m_tid; -} +//uint64_t Bullet::getTeamID(){ +// return m_tid; +//} diff --git a/SQCSim-common/bullet.h b/SQCSim-common/bullet.h index 1b5e227..3f875d9 100644 --- a/SQCSim-common/bullet.h +++ b/SQCSim-common/bullet.h @@ -1,10 +1,14 @@ #ifndef BULLET_H__ #define BULLET_H__ +#include #include "define.h" #include "vector3.h" +#include "player.h" +#include "netprotocol.h" class World; +class Player; class Bullet { public: @@ -12,17 +16,19 @@ public: Bullet(Vector3f pos, Vector3f dir, uint64_t tid); ~Bullet(); - bool Update(World* world, float elapsedtime, int perframe); + bool Update(World* world, float elapsedtime, int perframe, std::unordered_map m_mapPlayer, netprot::ChunkMod** chunkmod); void Transpose(int& x, int& z); Vector3f getPos() const; Vector3f getVel() const; - uint64_t getTeamID(); + //uint64_t getTeamID(); private: Vector3f m_startpos, m_currentpos, m_velocity; - uint64_t m_tid = 0; + uint64_t m_shooter_id = 0; + + }; #endif // BULLET_H__ diff --git a/SQCSim-common/chunk.cpp b/SQCSim-common/chunk.cpp index cb93218..0f30cb8 100644 --- a/SQCSim-common/chunk.cpp +++ b/SQCSim-common/chunk.cpp @@ -1,137 +1,312 @@ #include "chunk.h" #include "world.h" +#include -Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y) { - //std::ostringstream pos; // Vérifie l'existence d'un fichier .chunk avec sa position. - //pos << CHUNK_PATH << x << '_' << y << ".chunk"; - //std::ifstream input(pos.str(), std::fstream::binary); - //if (input.fail()) { - OpenSimplexNoise::Noise simplex = OpenSimplexNoise::Noise(seed); - m_blocks.Reset(BTYPE_AIR); +Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y) { + //std::ostringstream pos; // V�rifie l'existence d'un fichier .chunk avec sa position. + //pos << CHUNK_PATH << x << '_' << y << ".chunk"; + //std::ifstream input(pos.str(), std::fstream::binary); - for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Montagnes - for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { - float xnoiz, ynoiz; - xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 4096.; - ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 4096.; - double height = 0; - for (int x = 0; x < 39; ++x) { - height += simplex.eval(xnoiz, ynoiz); - height *= .79; - xnoiz *= 1.139; - ynoiz *= 1.139; - } - height = height * 2000. * simplex.eval((double)(ix + x * CHUNK_SIZE_X) / 512., (double)(iz + y * CHUNK_SIZE_Z) / 512.); - height /= (CHUNK_SIZE_Y / 1.9); - height += 15.; - for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) - SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); - } - for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Collines - for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { - float xnoiz, ynoiz; - xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 512.; - ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 512.; - float height = simplex.eval(xnoiz, ynoiz) * 50.f;// +1.f; - for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) { - if (GetBlock(ix, iy, iz) == BTYPE_AIR) - SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr); - } - } - for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Lacs" - for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { - for (int iy = 0; iy < 13; ++iy) { - if (GetBlock(ix, iy, iz) == BTYPE_AIR) - SetBlock(ix, iy, iz, BTYPE_ICE, nullptr); - } - } - //for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Arbres" - // for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { - // float xnoiz, ynoiz; - // xnoiz = (double)(iz * CHUNK_SIZE_Y + x * CHUNK_SIZE_X) / 256.; - // ynoiz = (double)(ix * CHUNK_SIZE_Y + y * CHUNK_SIZE_Z) / 256.; - // bool tree = (int)(abs(simplex.eval(xnoiz, ynoiz)) * 17933.f) % CHUNK_SIZE_Y > 126 ? true : false; - // for (int iy = 0; iy < CHUNK_SIZE_Y - 10; ++iy) - // if (GetBlock(ix, iy, iz) == BTYPE_AIR) - // if (GetBlock(ix, iy - 1, iz) == BTYPE_GRASS) - // if (tree) { - // for (int i = 0; i < (int)(abs(simplex.eval(xnoiz, ynoiz) * 4)) % 42 + 1; ++i) - // SetBlock(ix, iy + i, iz, BTYPE_DIRT, nullptr); - // break; - // } - // } - /* } - else { - input.seekg(0, std::ios_base::end); - int size = input.tellg(); - input.seekg(0, std::ios_base::beg); + //if (input.fail()) { + OpenSimplexNoise::Noise simplex = OpenSimplexNoise::Noise(seed); + int ratio = 0; - char data[CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z]; - input.read(data, size); - input.close(); + ratio = x * y % 7; + m_blocks.Reset(BTYPE_AIR); + +#pragma region Montagnes et Grass des montagnes + for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) + for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { + float xnoiz, ynoiz; + xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 4796.; + ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 4796.; + double height = 0; + for (int x = 0; x < 39; ++x) { + height += simplex.eval(xnoiz, ynoiz); + height *= .79; + xnoiz *= 1.1305; + ynoiz *= 1.1305; + } + height = height * 2000. * simplex.eval((double)(ix + x * CHUNK_SIZE_X) / 512., (double)(iz + y * CHUNK_SIZE_Z) / 512.); + height /= (CHUNK_SIZE_Y / 1.9); + height += 15.; + for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) { + if (iy < 20) + { + //std::cout << "" << ynoiz << std::endl; + SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr); + } + else if (iy == 20 || iy == 21) { + double fractionalPart = ynoiz - static_cast(ynoiz); + + if (iy == 20) { + if (fractionalPart < 0.3) { + SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr); + } + else { + SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); + } + } + else if (iy == 21) { + if (fractionalPart < 0.6) { + SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr); + } + else { + SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); + } + } + } + else + { + SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); + } + } + } +#pragma endregion + +#pragma region Lacs + for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) + for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { + for (int iy = 0; iy < 13; ++iy) { + if (iy < 5 && GetBlock(ix, iy, iz) == BTYPE_AIR) { + SetBlock(ix, iy, iz, BTYPE_ICE, nullptr); + } + else if (iy >= 5 && GetBlock(ix, iy, iz) == BTYPE_AIR) { + SetBlock(ix, iy, iz, BTYPE_ICE, nullptr); + } + } + } +#pragma endregion + + //int rnd = rand() % 15; + if (ratio == 1) + for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // structure + for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { + for (int iy = 0; iy < 14; ++iy) { + if (ix == 3) + if (GetBlock(ix, iy, iz) == BTYPE_AIR) + Structure(ix, iy, iz, 2); + } + } + if (ratio == 3) + for (int ix = 0; ix < CHUNK_SIZE_Z; ++ix) // structure + for (int iz = 0; iz < CHUNK_SIZE_X; ++iz) { + for (int iy = 0; iy < 14; ++iy) { + if (iz == 4) + if (GetBlock(ix, iy, iz) == BTYPE_AIR) + Structure(ix, iy, iz, 1); + } + } + if (ratio == 5) + for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // structure + for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { + for (int iy = 0; iy < 14; ++iy) { + if (ix == 3) + if (GetBlock(ix, iy, iz) == BTYPE_AIR) + Structure(ix, iy, iz, 2); + } + } + + + + + +#pragma region Arbre + double valeurRnd = 0; + int treeheight = 10; + int lastTreeX = -1; + int lastTreeZ = -1; + + int minDistanceBetweenTrees = 10; // Définir la distance minimale entre les arbres + + + for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) { + for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { + if (GetBlock(ix, 0, iz) != BTYPE_ICE) { + float xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 4796.; + float ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 4796.; + double height = 0; + for (int i = 0; i < 39; ++i) { + height += simplex.eval(xnoiz, ynoiz); + height *= .79; + xnoiz *= 1.1305; + ynoiz *= 1.1305; + } + height = height * 2000. * simplex.eval((double)(ix + x * CHUNK_SIZE_X) / 512., (double)(iz + y * CHUNK_SIZE_Z) / 512.); + height /= (CHUNK_SIZE_Y / 1.9); + height += 15.; + if (GetBlock(ix, (int)height, iz) == BTYPE_GRASS || (GetBlock(ix, (int)height, iz) == BTYPE_METAL)) { + valeurRnd = simplex.eval(xnoiz, ynoiz); + int distanceThreshold = 20; + // Vérifie si l'emplacement n'est pas à l'intérieur des lacs + bool isInsideLake = false; + for (int iy = 0; iy < 13; ++iy) { + if (GetBlock(ix, iy, iz) == BTYPE_ICE) { + isInsideLake = true; + break; + } + } + if (!isInsideLake && ((valeurRnd > -0.4 && valeurRnd < -0.38) || (valeurRnd > -0.35 && valeurRnd < -0.31) + || (valeurRnd > 0.3 && valeurRnd < 0.32) || (valeurRnd > 0.37 && valeurRnd < 0.39)) + ) { + if (lastTreeX == -1 || abs(ix - lastTreeX) > minDistanceBetweenTrees || abs(iz - lastTreeZ) > minDistanceBetweenTrees) { + if (valeurRnd < 0.1) + treeheight = 10; + else { + treeheight = valeurRnd * 20; + if (treeheight < 5) + treeheight = 5; + } + PlaceTree(ix, height, iz, treeheight); + lastTreeX = ix; + lastTreeZ = iz; + } + } + } + } + } + } +#pragma endregion + + + + + + + + + //else { + // input.seekg(0, std::ios_base::end); + // int size = input.tellg(); + // input.seekg(0, std::ios_base::beg); + + // char data[CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z]; + // input.read(data, size); + // input.close(); + + // for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) + // for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) + // for (int iy = 0; iy < CHUNK_SIZE_Y; ++iy) + // m_blocks.Set(ix, iy, iz, data[ix + (iz * CHUNK_SIZE_X) + (iy * CHUNK_SIZE_Z * CHUNK_SIZE_X)]); + //}*/ + + + + + //for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Collines +// for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { +// float xnoiz, ynoiz; +// xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 512.; +// ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 512.; +// float height = simplex.eval(xnoiz, ynoiz) * 50.f;// +1.f; +// for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) { +// if (iy < 10 && GetBlock(ix, iy, iz) == BTYPE_AIR) { +// SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); // Collines +// } +// else if (iy >= 10 && GetBlock(ix, iy, iz) == BTYPE_AIR) { +// SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr); // Grass des collines +// } +// } +// } - for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) - for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) - for (int iy = 0; iy < CHUNK_SIZE_Y; ++iy) - m_blocks.Set(ix, iy, iz, data[ix + (iz * CHUNK_SIZE_X) + (iy * CHUNK_SIZE_Z * CHUNK_SIZE_X)]); - }*/ } +void Chunk::PlaceTree(int x, int y, int z, int height) { + // Vérifie si les coordonnées x, y, z sont dans les limites du chunk + if (x < 0 || x >= CHUNK_SIZE_X || y < 0 || y >= CHUNK_SIZE_Y || z < 0 || z >= CHUNK_SIZE_Z) { + // Coordonnées hors limites du chunk, sortie anticipée pour éviter tout accès non valide + return; + } + + // Place la tige de l'arbre + for (int iy = 0; iy < height + 1; ++iy) { + if (y + iy < CHUNK_SIZE_Y) { // Vérifie si la hauteur est à l'intérieur des limites du chunk + SetBlock(x, y + iy, z, BTYPE_DIRT, nullptr); + } + } + + // Place les feuilles de l'arbre + int foliageHeight = height / 2; + for (int dy = 0; dy < foliageHeight; ++dy) { + for (int dx = -4; dx <= 4; ++dx) { + for (int dz = -4; dz <= 4; ++dz) { + // Vérifie que les coordonnées se trouvent à l'intérieur des limites du chunk + if (x + dx >= 0 && x + dx < CHUNK_SIZE_X && y + height + dy >= 0 && y + height + dy < CHUNK_SIZE_Y && + z + dz >= 0 && z + dz < CHUNK_SIZE_Z) { + // Vérifie si le bloc est à une distance acceptable du centre des feuilles pour les placer + double distanceSquared = dx * dx + dy * dy + dz * dz; + if (distanceSquared < 20) { + SetBlock(x + dx, y + height + dy, z + dz, BTYPE_GREENGRASS, nullptr); + } + } + } + } + } +} + + + + + Chunk::~Chunk() { - /*if (m_isModified) { - char data[CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z]; + /*if (m_isModified) { + char data[CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z]; - for (int x = 0; x < CHUNK_SIZE_X; ++x) - for (int z = 0; z < CHUNK_SIZE_Z; ++z) - for (int y = 0; y < CHUNK_SIZE_Y; ++y) - data[x + (z * CHUNK_SIZE_X) + (y * CHUNK_SIZE_Z * CHUNK_SIZE_X)] = (char)GetBlock(x, y, z); + for (int x = 0; x < CHUNK_SIZE_X; ++x) + for (int z = 0; z < CHUNK_SIZE_Z; ++z) + for (int y = 0; y < CHUNK_SIZE_Y; ++y) + data[x + (z * CHUNK_SIZE_X) + (y * CHUNK_SIZE_Z * CHUNK_SIZE_X)] = (char)GetBlock(x, y, z); - std::ostringstream pos; - pos << CHUNK_PATH << m_posX << '_' << m_posY << ".chunk"; + std::ostringstream pos; + pos << CHUNK_PATH << m_posX << '_' << m_posY << ".chunk"; - std::ofstream output(pos.str(), std::fstream::binary); - output.write(data, sizeof(data)); - output.close(); - }*/ + std::ofstream output(pos.str(), std::fstream::binary); + output.write(data, sizeof(data)); + output.close(); + }*/ } void Chunk::RemoveBlock(int x, int y, int z, World* world) { - m_blocks.Set(x, y, z, BTYPE_AIR); - CheckNeighbors(x, y, world); - m_isDirty = true; + m_blocks.Set(x, y, z, BTYPE_AIR); + CheckNeighbors(x, y, world); + m_isDirty = true; } void Chunk::SetBlock(int x, int y, int z, BlockType type, World* world) { - m_blocks.Set(x, y, z, type); - if (world) CheckNeighbors(x, z, world); // Si nullptr, ne pas vérifier les chunks voisines. - m_isDirty = true; + m_blocks.Set(x, y, z, type); + if (world) CheckNeighbors(x, z, world); // Si nullptr, ne pas v�rifier les chunks voisines. + m_isDirty = true; } BlockType Chunk::GetBlock(int x, int y, int z) { return m_blocks.Get(x, y, z); } void Chunk::CheckNeighbors(unsigned int x, unsigned int z, World* world) { - unsigned int cx, cy; + unsigned int cx, cy; - world->GetScope(cx, cy); + world->GetScope(cx, cy); - if (x == 0 && m_posX - cx >= 0 && - world->ChunkAt((m_posX - cx - 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)) - world->ChunkAt((m_posX - cx - 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)->MakeDirty(); - else if (x == CHUNK_SIZE_X - 1 && m_posX - cx < WORLD_SIZE_X && - world->ChunkAt((m_posX - cx + 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)) - world->ChunkAt((m_posX - cx + 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)->MakeDirty(); + if (x == 0 && m_posX - cx >= 0 && + world->ChunkAt((m_posX - cx - 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)) + world->ChunkAt((m_posX - cx - 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)->MakeDirty(); + else if (x == CHUNK_SIZE_X - 1 && m_posX - cx < WORLD_SIZE_X && + world->ChunkAt((m_posX - cx + 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)) + world->ChunkAt((m_posX - cx + 1) * CHUNK_SIZE_X, 1, (m_posY - cy) * CHUNK_SIZE_Z)->MakeDirty(); - if (z == 0 && m_posY - cy >= 0 && - world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy - 1) * CHUNK_SIZE_Z)) - world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy - 1) * CHUNK_SIZE_Z)->MakeDirty(); - else if (z == CHUNK_SIZE_X - 1 && m_posY - cy < WORLD_SIZE_Y && - world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy + 1) * CHUNK_SIZE_Z)) - world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy + 1) * CHUNK_SIZE_Z)->MakeDirty(); + if (z == 0 && m_posY - cy >= 0 && + world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy - 1) * CHUNK_SIZE_Z)) + world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy - 1) * CHUNK_SIZE_Z)->MakeDirty(); + else if (z == CHUNK_SIZE_X - 1 && m_posY - cy < WORLD_SIZE_Y && + world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy + 1) * CHUNK_SIZE_Z)) + world->ChunkAt((m_posX - cx) * CHUNK_SIZE_X, 1, (m_posY - cy + 1) * CHUNK_SIZE_Z)->MakeDirty(); } void Chunk::GetPosition(unsigned int& x, unsigned int& y) const { x = m_posX; y = m_posY; } + + + + bool Chunk::IsDirty() const { return m_isDirty; } void Chunk::MakeDirty() { m_isDirty = true; } @@ -140,3 +315,11 @@ void Chunk::MakeClean() { m_isDirty = false; } void Chunk::MakeModified() { m_isModified = true; } + +void Chunk::Structure(int x, int y, int z,int height) +{ + for (int i = 0; i < height; i++) + { + SetBlock(x, i + y, z, BTYPE_GRASS, nullptr); + } +} diff --git a/SQCSim-common/chunk.h b/SQCSim-common/chunk.h index b053928..edda885 100644 --- a/SQCSim-common/chunk.h +++ b/SQCSim-common/chunk.h @@ -27,7 +27,9 @@ class Chunk { BlockType GetBlock(int x, int y, int z); void CheckNeighbors(unsigned int x, unsigned int z, World* world); void GetPosition(unsigned int& x, unsigned int& y) const; + void PlaceTree(int x, int y, int z, int height); + void Structure(int x, int y, int z, int height); bool IsDirty() const; void MakeDirty(); void MakeClean(); diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h index f65bc2b..685bf5d 100644 --- a/SQCSim-common/define.h +++ b/SQCSim-common/define.h @@ -4,12 +4,14 @@ #include #include -#define SRV_PORT 1025 -#define CLI_PORT 1026 +#define SRV_PORT 10000 +#define CLI_PORT 10001 -#define CHUNK_SIZE_X 4 +#define BUFFER_LENGTH 1500 + +#define CHUNK_SIZE_X 6 #define CHUNK_SIZE_Y 64 -#define CHUNK_SIZE_Z 4 +#define CHUNK_SIZE_Z 6 #define MAX_SELECTION_DISTANCE 5 #define SEED 0 #define COUNTDOWN 300 @@ -25,23 +27,43 @@ #define THREADS_UPDATE_CHUNKS 6 #define THREADS_DELETE_CHUNKS 3 -#define VIEW_DISTANCE 512 // Si les chunks arrêtent de s'afficher pendant une game et qu'il y a un access violation quand tu quitte, il faut augmenter ce chiffre. +#define VIEW_DISTANCE 512 // Si les chunks arr�tent de s'afficher pendant une game et qu'il y a un access violation quand tu quitte, il faut augmenter ce chiffre. #define TEXTURE_SIZE 512 #define MAX_BULLETS 512 +#define TIME_SPEED_BOOST 10 //secondes +#define TIME_DAMAGE_BOOST 10 //secondes +#define TIME_INVINCIBLE_BOOST 4 //secondes +#define STRENGTH_SPEED_BOOST 10 //Pourcentage +#define BULLET_TIME .1 + typedef uint8_t BlockType; -enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_LAST }; +enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_GREENGRASS, BTYPE_LAST }; +typedef uint8_t BoostType; +enum BOOST_TYPE { BTYPE_SPEED, BTYPE_HEAL, BTYPE_DAMAGE, BTYPE_INVINCIBLE, BTYPE_BOOST_LAST }; + +//anim +enum ANIM_TYPE { STILL = 0, SHOOTING = 8, JUMPING = 16, JUMPINGSHOOTING = 24, DEAD = 32, TYPE_LAST = 40}; +enum ANIM_POS {FRONT, QUARTER_FRONT_LEFT, QUATER_FRONT_RIGHT, PROFIL_LEFT, PROFIL_RIGHT, QUARTER_BACK_LEFT, QUARTER_BACK_RIGHT, BACK , POS_LAST}; + typedef uint64_t Timestamp; #ifdef _WIN32 #pragma comment(lib,"wsock32.lib") // Pour pouvoir faire fonctionner le linker sans le vcxproject #pragma comment(lib,"ws2_32.lib") + #include #include #include #include +#define poll WSAPoll +#define flag_t u_long +#define addrlen_t int +#define ioctl ioctlsocket +#define SOCK_NONBLOCK FIONBIO +#define strcpy strcpy_s #define popen _popen #define pclose _pclose @@ -51,10 +73,14 @@ typedef uint64_t Timestamp; #include #include #include +#include #include #include #include +#include +#define flag_t unsigned int +#define addrlen_t unsigned int #define SOCKET int #define INVALID_SOCKET -1 #define closesocket close diff --git a/SQCSim-common/netprotocol.cpp b/SQCSim-common/netprotocol.cpp index d4edca2..68feda2 100644 --- a/SQCSim-common/netprotocol.cpp +++ b/SQCSim-common/netprotocol.cpp @@ -1,90 +1,237 @@ #include "netprotocol.h" void netprot::Serialize(Input* in, char* buf[], uint32_t* buflen) { - *buf[0] = netprot::PACKET_TYPE::INPUT; + *buf[0] = (char)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}; + uint8_t time8[sizeof(uint64_t)] = { (uint8_t)((time >> 56) & 0xFF), + (uint8_t)((time >> 48) & 0xFF), + (uint8_t)((time >> 40) & 0xFF), + (uint8_t)((time >> 32) & 0xFF), + (uint8_t)((time >> 24) & 0xFF), + (uint8_t)((time >> 16) & 0xFF), + (uint8_t)((time >> 8) & 0xFF), + (uint8_t)(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}; + uint8_t sid8[sizeof(uint64_t)] = { (uint8_t)((sid >> 56) & 0xFF), + (uint8_t)((sid >> 48) & 0xFF), + (uint8_t)((sid >> 40) & 0xFF), + (uint8_t)((sid >> 32) & 0xFF), + (uint8_t)((sid >> 24) & 0xFF), + (uint8_t)((sid >> 16) & 0xFF), + (uint8_t)((sid >> 8) & 0xFF), + (uint8_t)(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 ; + (keys.forward ? 0b10000000 : 0) | + (keys.backward ? 0b01000000 : 0) | + (keys.left ? 0b00100000 : 0) | + (keys.right ? 0b00010000 : 0) | + (keys.jump ? 0b00001000 : 0) | + (keys.shoot ? 0b00000100 : 0) | + (keys.block ? 0b00000010 : 0); - memcpy(*buf + sizeof(uint64_t) + 2, &keys8, sizeof(uint8_t)); + memcpy(*buf + sizeof(uint64_t) * 2 + 1, &keys8, sizeof(uint8_t)); uint32_t vec[3]; - memcpy(vec, &in->direction, sizeof(Vector3f)); // Pour dénaturer les floats. + 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}; + (uint8_t)((vec[0] >> 24) & 0xFF), + (uint8_t)((vec[0] >> 16) & 0xFF), + (uint8_t)((vec[0] >> 8) & 0xFF), + (uint8_t)(vec[0] & 0xFF), + (uint8_t)((vec[1] >> 24) & 0xFF), + (uint8_t)((vec[1] >> 16) & 0xFF), + (uint8_t)((vec[1] >> 8) & 0xFF), + (uint8_t)(vec[1] & 0xFF), + (uint8_t)((vec[2] >> 24) & 0xFF), + (uint8_t)((vec[2] >> 16) & 0xFF), + (uint8_t)((vec[2] >> 8) & 0xFF), + (uint8_t)(vec[2] & 0xFF) }; - memcpy(*buf + sizeof(uint64_t) + 3, vec8, sizeof(uint32_t) * 3); + memcpy(*buf + sizeof(uint64_t) * 2 + 2, vec8, sizeof(uint32_t) * 3); - *buflen = sizeof(uint64_t) + 3 + sizeof(uint32_t) * 3; + *buflen = sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 3; } void netprot::Serialize(Output* out, char* buf[], uint32_t* buflen) { + *buf[0] = (char)netprot::PACKET_TYPE::OUTPUT; + uint64_t time = out->timestamp; + uint8_t time8[sizeof(uint64_t)] = { (uint8_t)((time >> 56) & 0xFF), + (uint8_t)((time >> 48) & 0xFF), + (uint8_t)((time >> 40) & 0xFF), + (uint8_t)((time >> 32) & 0xFF), + (uint8_t)((time >> 24) & 0xFF), + (uint8_t)((time >> 16) & 0xFF), + (uint8_t)((time >> 8) & 0xFF), + (uint8_t)(time & 0xFF) }; + + memcpy(*buf + 1, time8, sizeof(uint64_t)); + + uint64_t sid = out->id; + uint8_t sid8[sizeof(uint64_t)] = { (uint8_t)((sid >> 56) & 0xFF), + (uint8_t)((sid >> 48) & 0xFF), + (uint8_t)((sid >> 40) & 0xFF), + (uint8_t)((sid >> 32) & 0xFF), + (uint8_t)((sid >> 24) & 0xFF), + (uint8_t)((sid >> 16) & 0xFF), + (uint8_t)((sid >> 8) & 0xFF), + (uint8_t)(sid & 0xFF) }; + + memcpy(*buf + sizeof(uint64_t) + 1, sid8, sizeof(uint64_t)); + + States states = out->states; + uint8_t states8 = + (states.jumping ? 0b10000000 : 0) | + (states.shooting ? 0b01000000 : 0) | + (states.hit ? 0b00100000 : 0) | + (states.powerup ? 0b00010000 : 0) | + (states.dead ? 0b00001000 : 0) | + (states.still ? 0b00000100 : 0) | + (states.jumpshot ? 0b00000010 : 0) | + (states.running ? 0b00000001 : 0); + + memcpy(*buf + sizeof(uint64_t) * 2 + 1, &states8, sizeof(uint8_t)); + + uint32_t vec[3]; + memcpy(vec, &out->direction, sizeof(Vector3f)); // Pour d�naturer les floats. + + uint8_t vec8[3 * sizeof(uint32_t)] = { + (uint8_t)((vec[0] >> 24) & 0xFF), + (uint8_t)((vec[0] >> 16) & 0xFF), + (uint8_t)((vec[0] >> 8) & 0xFF), + (uint8_t)(vec[0] & 0xFF), + (uint8_t)((vec[1] >> 24) & 0xFF), + (uint8_t)((vec[1] >> 16) & 0xFF), + (uint8_t)((vec[1] >> 8) & 0xFF), + (uint8_t)(vec[1] & 0xFF), + (uint8_t)((vec[2] >> 24) & 0xFF), + (uint8_t)((vec[2] >> 16) & 0xFF), + (uint8_t)((vec[2] >> 8) & 0xFF), + (uint8_t)(vec[2] & 0xFF) }; + + memcpy(*buf + sizeof(uint64_t) * 2 + 2, vec8, sizeof(uint32_t) * 3); + + memcpy(vec, &out->position, sizeof(Vector3f)); // Pour d�naturer les floats. + + uint8_t vec82[3 * sizeof(uint32_t)] = { + (uint8_t)((vec[0] >> 24) & 0xFF), + (uint8_t)((vec[0] >> 16) & 0xFF), + (uint8_t)((vec[0] >> 8) & 0xFF), + (uint8_t)(vec[0] & 0xFF), + (uint8_t)((vec[1] >> 24) & 0xFF), + (uint8_t)((vec[1] >> 16) & 0xFF), + (uint8_t)((vec[1] >> 8) & 0xFF), + (uint8_t)(vec[1] & 0xFF), + (uint8_t)((vec[2] >> 24) & 0xFF), + (uint8_t)((vec[2] >> 16) & 0xFF), + (uint8_t)((vec[2] >> 8) & 0xFF), + (uint8_t)(vec[2] & 0xFF) }; + + memcpy(*buf + sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 3, vec82, sizeof(uint32_t) * 3); + + *buflen = sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 6; } void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) { - + *buf[0] = (char)netprot::PACKET_TYPE::SYNC; + uint64_t time = sync->timestamp; + uint8_t stamp8[sizeof(uint64_t)] = { (uint8_t)((time >> 56) & 0xFF), + (uint8_t)((time >> 48) & 0xFF), + (uint8_t)((time >> 40) & 0xFF), + (uint8_t)((time >> 32) & 0xFF), + (uint8_t)((time >> 24) & 0xFF), + (uint8_t)((time >> 16) & 0xFF), + (uint8_t)((time >> 8) & 0xFF), + (uint8_t)(time & 0xFF) }; + + memcpy(*buf + 1, stamp8, sizeof(uint64_t)); + + uint64_t sid = sync->sid; + uint8_t sid8[sizeof(uint64_t)] = { (uint8_t)((sid >> 56) & 0xFF), + (uint8_t)((sid >> 48) & 0xFF), + (uint8_t)((sid >> 40) & 0xFF), + (uint8_t)((sid >> 32) & 0xFF), + (uint8_t)((sid >> 24) & 0xFF), + (uint8_t)((sid >> 16) & 0xFF), + (uint8_t)((sid >> 8) & 0xFF), + (uint8_t)(sid & 0xFF) }; + + memcpy(*buf + sizeof(uint64_t) + 1, sid8, sizeof(uint64_t)); + + uint32_t timer = sync->timer; + uint8_t time8[sizeof(uint32_t)] = { (uint8_t)((timer >> 24) & 0xFF), + (uint8_t)((timer >> 16) & 0xFF), + (uint8_t)((timer >> 8) & 0xFF), + (uint8_t)(timer & 0xFF) }; + + memcpy(*buf + sizeof(uint64_t) * 2 + 1, time8, sizeof(uint32_t)); + + uint16_t ammo = sync->ammo; + uint8_t ammo8[sizeof(uint16_t)] = { (uint8_t)((ammo >> 8) & 0xFF), + (uint8_t)(ammo & 0xFF) }; + + memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + 1, ammo8, sizeof(uint16_t)); + + uint32_t vec[3]; + memcpy(vec, &sync->position, sizeof(Vector3f)); // Pour d�naturer les floats. + + uint8_t vec8[3 * sizeof(uint32_t)] = { + (uint8_t)((vec[0] >> 24) & 0xFF), + (uint8_t)((vec[0] >> 16) & 0xFF), + (uint8_t)((vec[0] >> 8) & 0xFF), + (uint8_t)(vec[0] & 0xFF), + (uint8_t)((vec[1] >> 24) & 0xFF), + (uint8_t)((vec[1] >> 16) & 0xFF), + (uint8_t)((vec[1] >> 8) & 0xFF), + (uint8_t)(vec[1] & 0xFF), + (uint8_t)((vec[2] >> 24) & 0xFF), + (uint8_t)((vec[2] >> 16) & 0xFF), + (uint8_t)((vec[2] >> 8) & 0xFF), + (uint8_t)(vec[2] & 0xFF) }; + + memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t) + 1, vec8, sizeof(uint32_t) * 3); + + uint32_t hp; + + memcpy(&hp, &sync->hp, sizeof(float)); + + uint8_t hp8[4] = { + (uint8_t)((hp >> 24) & 0xFF), + (uint8_t)((hp >> 16) & 0xFF), + (uint8_t)((hp >> 8) & 0xFF), + (uint8_t)(hp & 0xFF) }; + + memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + 1, hp8, sizeof(float)); + + *buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float) + 1; } void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) { - *buf[0] = netprot::PACKET_TYPE::TEAMINF; + *buf[0] = (char)netprot::PACKET_TYPE::TEAMINF; size_t namesize = std::strlen(tinfo->name) + 1; - memcpy(*buf + 1, &tinfo->name, namesize); + strcpy(*buf + 1, namesize, tinfo->name); + uint64_t tid = tinfo->id; uint8_t tid8[sizeof(uint64_t)] = { - (tid >> 56) & 0xFF, - (tid >> 48) & 0xFF, - (tid >> 40) & 0xFF, - (tid >> 32) & 0xFF, - (tid >> 24) & 0xFF, - (tid >> 16) & 0xFF, - (tid >> 8) & 0xFF, - tid & 0xFF + (uint8_t)((tid >> 56) & 0xFF), + (uint8_t)((tid >> 48) & 0xFF), + (uint8_t)((tid >> 40) & 0xFF), + (uint8_t)((tid >> 32) & 0xFF), + (uint8_t)((tid >> 24) & 0xFF), + (uint8_t)((tid >> 16) & 0xFF), + (uint8_t)((tid >> 8) & 0xFF), + (uint8_t)(tid & 0xFF) }; memcpy(*buf + namesize + 2, tid8, sizeof(uint64_t)); @@ -93,35 +240,36 @@ void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) { } void netprot::Serialize(LoginInfo* linfo, char* buf[], uint32_t* buflen) { - *buf[0] = netprot::PACKET_TYPE::LOGINF; + *buf[0] = (char)netprot::PACKET_TYPE::LOGINF; size_t namesize = std::strlen(linfo->name) + 1; - - memcpy(*buf + 1, &linfo->name, namesize); + + strcpy(*buf + 1, namesize, linfo->name); + uint64_t sid = linfo->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 + uint8_t sid8[sizeof(uint64_t)] = { + (uint8_t)((sid >> 56) & 0xFF), + (uint8_t)((sid >> 48) & 0xFF), + (uint8_t)((sid >> 40) & 0xFF), + (uint8_t)((sid >> 32) & 0xFF), + (uint8_t)((sid >> 24) & 0xFF), + (uint8_t)((sid >> 16) & 0xFF), + (uint8_t)((sid >> 8) & 0xFF), + (uint8_t)(sid & 0xFF) }; memcpy(*buf + namesize + 2, sid8, sizeof(uint64_t)); uint64_t tid = linfo->tid; uint8_t tid8[sizeof(uint64_t)] = { - (tid >> 56) & 0xFF, - (tid >> 48) & 0xFF, - (tid >> 40) & 0xFF, - (tid >> 32) & 0xFF, - (tid >> 24) & 0xFF, - (tid >> 16) & 0xFF, - (tid >> 8) & 0xFF, - tid & 0xFF + (uint8_t)((tid >> 56) & 0xFF), + (uint8_t)((tid >> 48) & 0xFF), + (uint8_t)((tid >> 40) & 0xFF), + (uint8_t)((tid >> 32) & 0xFF), + (uint8_t)((tid >> 24) & 0xFF), + (uint8_t)((tid >> 16) & 0xFF), + (uint8_t)((tid >> 8) & 0xFF), + (uint8_t)(tid & 0xFF) }; memcpy(*buf + namesize + 2 + sizeof(uint64_t), tid8, sizeof(uint64_t)); @@ -130,35 +278,36 @@ void netprot::Serialize(LoginInfo* linfo, char* buf[], uint32_t* buflen) { } void netprot::Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen) { - *buf[0] = netprot::PACKET_TYPE::PLAYINF; + *buf[0] = (char)netprot::PACKET_TYPE::PLAYINF; size_t namesize = std::strlen(pinfo->name) + 1; - memcpy(*buf + 1, &pinfo->name, namesize); + strcpy(*buf + 1, namesize, pinfo->name); + uint64_t id = pinfo->id; uint8_t id8[sizeof(uint64_t)] = { - (id >> 56) & 0xFF, - (id >> 48) & 0xFF, - (id >> 40) & 0xFF, - (id >> 32) & 0xFF, - (id >> 24) & 0xFF, - (id >> 16) & 0xFF, - (id >> 8) & 0xFF, - id & 0xFF + (uint8_t)((id >> 56) & 0xFF), + (uint8_t)((id >> 48) & 0xFF), + (uint8_t)((id >> 40) & 0xFF), + (uint8_t)((id >> 32) & 0xFF), + (uint8_t)((id >> 24) & 0xFF), + (uint8_t)((id >> 16) & 0xFF), + (uint8_t)((id >> 8) & 0xFF), + (uint8_t)(id & 0xFF) }; memcpy(*buf + namesize + 2, id8, sizeof(uint64_t)); uint64_t tid = pinfo->tid; uint8_t tid8[sizeof(uint64_t)] = { - (tid >> 56) & 0xFF, - (tid >> 48) & 0xFF, - (tid >> 40) & 0xFF, - (tid >> 32) & 0xFF, - (tid >> 24) & 0xFF, - (tid >> 16) & 0xFF, - (tid >> 8) & 0xFF, - tid & 0xFF + (uint8_t)((tid >> 56) & 0xFF), + (uint8_t)((tid >> 48) & 0xFF), + (uint8_t)((tid >> 40) & 0xFF), + (uint8_t)((tid >> 32) & 0xFF), + (uint8_t)((tid >> 24) & 0xFF), + (uint8_t)((tid >> 16) & 0xFF), + (uint8_t)((tid >> 8) & 0xFF), + (uint8_t)(tid & 0xFF) }; memcpy(*buf + namesize + 2 + sizeof(uint64_t), tid8, sizeof(uint64_t)); @@ -167,46 +316,46 @@ void netprot::Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen) { } void netprot::Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen) { - *buf[0] = netprot::PACKET_TYPE::GAMEINFO; + *buf[0] = (char)netprot::PACKET_TYPE::GAMEINFO; uint64_t game = ginfo->seed; uint8_t seed8[sizeof(uint64_t)] = { - (game >> 56) & 0xFF, - (game >> 48) & 0xFF, - (game >> 40) & 0xFF, - (game >> 32) & 0xFF, - (game >> 24) & 0xFF, - (game >> 16) & 0xFF, - (game >> 8) & 0xFF, - game & 0xFF + (uint8_t)((game >> 56) & 0xFF), + (uint8_t)((game >> 48) & 0xFF), + (uint8_t)((game >> 40) & 0xFF), + (uint8_t)((game >> 32) & 0xFF), + (uint8_t)((game >> 24) & 0xFF), + (uint8_t)((game >> 16) & 0xFF), + (uint8_t)((game >> 8) & 0xFF), + (uint8_t)(game & 0xFF) }; memcpy(*buf + 1, seed8, sizeof(uint64_t)); game = ginfo->countdown; uint8_t count8[sizeof(uint64_t)] = { - (game >> 56) & 0xFF, - (game >> 48) & 0xFF, - (game >> 40) & 0xFF, - (game >> 32) & 0xFF, - (game >> 24) & 0xFF, - (game >> 16) & 0xFF, - (game >> 8) & 0xFF, - game & 0xFF + (uint8_t)((game >> 56) & 0xFF), + (uint8_t)((game >> 48) & 0xFF), + (uint8_t)((game >> 40) & 0xFF), + (uint8_t)((game >> 32) & 0xFF), + (uint8_t)((game >> 24) & 0xFF), + (uint8_t)((game >> 16) & 0xFF), + (uint8_t)((game >> 8) & 0xFF), + (uint8_t)(game & 0xFF) }; memcpy(*buf + sizeof(uint64_t) + 1, count8, sizeof(uint64_t)); game = ginfo->countdown; uint8_t gtype8[sizeof(uint64_t)] = { - (game >> 56) & 0xFF, - (game >> 48) & 0xFF, - (game >> 40) & 0xFF, - (game >> 32) & 0xFF, - (game >> 24) & 0xFF, - (game >> 16) & 0xFF, - (game >> 8) & 0xFF, - game & 0xFF + (uint8_t)((game >> 56) & 0xFF), + (uint8_t)((game >> 48) & 0xFF), + (uint8_t)((game >> 40) & 0xFF), + (uint8_t)((game >> 32) & 0xFF), + (uint8_t)((game >> 24) & 0xFF), + (uint8_t)((game >> 16) & 0xFF), + (uint8_t)((game >> 8) & 0xFF), + (uint8_t)(game & 0xFF) }; memcpy(*buf + sizeof(uint64_t) + 1, gtype8, sizeof(uint64_t)); @@ -215,59 +364,158 @@ void netprot::Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen) { } void netprot::Serialize(Chat* chat, char* buf[], uint32_t* buflen) { - *buf[0] = netprot::PACKET_TYPE::CHAT; + *buf[0] = (char)netprot::PACKET_TYPE::CHAT; uint64_t src = chat->src_id; uint8_t src8[sizeof(uint64_t)] = { - (src >> 56) & 0xFF, - (src >> 48) & 0xFF, - (src >> 40) & 0xFF, - (src >> 32) & 0xFF, - (src >> 24) & 0xFF, - (src >> 16) & 0xFF, - (src >> 8) & 0xFF, - src & 0xFF + (uint8_t)((src >> 56) & 0xFF), + (uint8_t)((src >> 48) & 0xFF), + (uint8_t)((src >> 40) & 0xFF), + (uint8_t)((src >> 32) & 0xFF), + (uint8_t)((src >> 24) & 0xFF), + (uint8_t)((src >> 16) & 0xFF), + (uint8_t)((src >> 8) & 0xFF), + (uint8_t)(src & 0xFF) }; memcpy(*buf + 1, src8, sizeof(uint64_t)); uint64_t dst = chat->dest_id; uint8_t dst8[sizeof(uint64_t)] = { - (dst >> 56) & 0xFF, - (dst >> 48) & 0xFF, - (dst >> 40) & 0xFF, - (dst >> 32) & 0xFF, - (dst >> 24) & 0xFF, - (dst >> 16) & 0xFF, - (dst >> 8) & 0xFF, - dst & 0xFF + (uint8_t)((dst >> 56) & 0xFF), + (uint8_t)((dst >> 48) & 0xFF), + (uint8_t)((dst >> 40) & 0xFF), + (uint8_t)((dst >> 32) & 0xFF), + (uint8_t)((dst >> 24) & 0xFF), + (uint8_t)((dst >> 16) & 0xFF), + (uint8_t)((dst >> 8) & 0xFF), + (uint8_t)(dst & 0xFF) }; memcpy(*buf + 1 + sizeof(uint64_t), dst8, sizeof(uint64_t)); uint64_t dstteam = chat->dest_id; uint8_t dstt8[sizeof(uint64_t)] = { - (dstteam >> 56) & 0xFF, - (dstteam >> 48) & 0xFF, - (dstteam >> 40) & 0xFF, - (dstteam >> 32) & 0xFF, - (dstteam >> 24) & 0xFF, - (dstteam >> 16) & 0xFF, - (dstteam >> 8) & 0xFF, - dstteam & 0xFF + (uint8_t)((dstteam >> 56) & 0xFF), + (uint8_t)((dstteam >> 48) & 0xFF), + (uint8_t)((dstteam >> 40) & 0xFF), + (uint8_t)((dstteam >> 32) & 0xFF), + (uint8_t)((dstteam >> 24) & 0xFF), + (uint8_t)((dstteam >> 16) & 0xFF), + (uint8_t)((dstteam >> 8) & 0xFF), + (uint8_t)(dstteam & 0xFF) }; - + memcpy(*buf + 1 + sizeof(uint64_t) * 2, dstt8, sizeof(uint64_t)); size_t messize = std::strlen(chat->mess) + 1; - memcpy(*buf + 1 + sizeof(uint64_t) * 3, &chat->mess, messize); + strcpy(*buf + 1 + sizeof(uint64_t) * 3, messize, chat->mess); *buflen = messize + sizeof(uint64_t) * 3 + 2; } +void netprot::Serialize(ChunkMod* chmod, char* buf[], uint32_t* buflen) { + *buf[0] = (char)netprot::PACKET_TYPE::CHUNKMOD; + + uint32_t vec[3]; + memcpy(vec, &chmod->pos, sizeof(Vector3f)); // Pour d�naturer les floats. + + uint8_t vec8[3 * sizeof(uint32_t)] = { + (uint8_t)((vec[0] >> 24) & 0xFF), + (uint8_t)((vec[0] >> 16) & 0xFF), + (uint8_t)((vec[0] >> 8) & 0xFF), + (uint8_t)(vec[0] & 0xFF), + (uint8_t)((vec[1] >> 24) & 0xFF), + (uint8_t)((vec[1] >> 16) & 0xFF), + (uint8_t)((vec[1] >> 8) & 0xFF), + (uint8_t)(vec[1] & 0xFF), + (uint8_t)((vec[2] >> 24) & 0xFF), + (uint8_t)((vec[2] >> 16) & 0xFF), + (uint8_t)((vec[2] >> 8) & 0xFF), + (uint8_t)(vec[2] & 0xFF) }; + + memcpy(*buf + 1, vec8, sizeof(uint32_t) * 3); + + memcpy(*buf + sizeof(uint32_t) * 3 + 1, &chmod->b_type, sizeof(BlockType)); + memcpy(*buf + sizeof(uint32_t) * 3 + 2, &chmod->old_b_type, sizeof(BlockType)); + + *buflen = sizeof(uint32_t) * 3 + 3; +} + +void netprot::Serialize(BulletAdd* bull, char* buf[], uint32_t* buflen) { + *buf[0] = (char)netprot::PACKET_TYPE::BULLET; + + uint64_t tstamp = bull->tstamp; + uint8_t ts8[sizeof(uint64_t)] = { + (uint8_t)((tstamp >> 56) & 0xFF), + (uint8_t)((tstamp >> 48) & 0xFF), + (uint8_t)((tstamp >> 40) & 0xFF), + (uint8_t)((tstamp >> 32) & 0xFF), + (uint8_t)((tstamp >> 24) & 0xFF), + (uint8_t)((tstamp >> 16) & 0xFF), + (uint8_t)((tstamp >> 8) & 0xFF), + (uint8_t)(tstamp & 0xFF) + }; + + memcpy(*buf + 1, ts8, sizeof(uint64_t)); + + uint64_t tid = bull->id; + uint8_t tid8[sizeof(uint64_t)] = { + (uint8_t)((tid >> 56) & 0xFF), + (uint8_t)((tid >> 48) & 0xFF), + (uint8_t)((tid >> 40) & 0xFF), + (uint8_t)((tid >> 32) & 0xFF), + (uint8_t)((tid >> 24) & 0xFF), + (uint8_t)((tid >> 16) & 0xFF), + (uint8_t)((tid >> 8) & 0xFF), + (uint8_t)(tid & 0xFF) + }; + + memcpy(*buf + 1 + sizeof(uint64_t), tid8, sizeof(uint64_t)); + + uint32_t vec[3]; + memcpy(vec, &bull->pos, sizeof(Vector3f)); // Pour d�naturer les floats. + + uint8_t vec8[3 * sizeof(uint32_t)] = { + (uint8_t)((vec[0] >> 24) & 0xFF), + (uint8_t)((vec[0] >> 16) & 0xFF), + (uint8_t)((vec[0] >> 8) & 0xFF), + (uint8_t)(vec[0] & 0xFF), + (uint8_t)((vec[1] >> 24) & 0xFF), + (uint8_t)((vec[1] >> 16) & 0xFF), + (uint8_t)((vec[1] >> 8) & 0xFF), + (uint8_t)(vec[1] & 0xFF), + (uint8_t)((vec[2] >> 24) & 0xFF), + (uint8_t)((vec[2] >> 16) & 0xFF), + (uint8_t)((vec[2] >> 8) & 0xFF), + (uint8_t)(vec[2] & 0xFF) }; + + memcpy(*buf + 1 + sizeof(uint64_t) * 2, vec8, sizeof(uint32_t) * 3); + + memcpy(vec, &bull->dir, sizeof(Vector3f)); // Pour d�naturer les floats. + + uint8_t dir8[3 * sizeof(uint32_t)] = { + (uint8_t)((vec[0] >> 24) & 0xFF), + (uint8_t)((vec[0] >> 16) & 0xFF), + (uint8_t)((vec[0] >> 8) & 0xFF), + (uint8_t)(vec[0] & 0xFF), + (uint8_t)((vec[1] >> 24) & 0xFF), + (uint8_t)((vec[1] >> 16) & 0xFF), + (uint8_t)((vec[1] >> 8) & 0xFF), + (uint8_t)(vec[1] & 0xFF), + (uint8_t)((vec[2] >> 24) & 0xFF), + (uint8_t)((vec[2] >> 16) & 0xFF), + (uint8_t)((vec[2] >> 8) & 0xFF), + (uint8_t)(vec[2] & 0xFF) }; + + memcpy(*buf + 1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 3, dir8, sizeof(uint32_t) * 3); + + *buflen = 1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 6; +} + void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) { - *buf[0] = netprot::PACKET_TYPE::ERRLOG; + *buf[0] = (char)netprot::PACKET_TYPE::ERRLOG; size_t messize = std::strlen(errlog->mess) + 1; @@ -280,20 +528,221 @@ void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) { -bool netprot::Deserialize(Input* in, char* buf, const uint32_t buflen) { - return false; +bool netprot::Deserialize(Input* in, char* buf, uint32_t* buflen) { + if (*buflen <= sizeof(Input)) + return false; + + uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; + memcpy(diff, &buf[1], sizeof(uint64_t)); + in->timestamp = + (uint64_t)diff[0] << 56 | + (uint64_t)diff[1] << 48 | + (uint64_t)diff[2] << 40 | + (uint64_t)diff[3] << 32 | + (uint64_t)diff[4] << 24 | + (uint64_t)diff[5] << 16 | + (uint64_t)diff[6] << 8 | + (uint64_t)diff[7]; + + memcpy(diff, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t)); + in->sid = + (uint64_t)diff[0] << 56 | + (uint64_t)diff[1] << 48 | + (uint64_t)diff[2] << 40 | + (uint64_t)diff[3] << 32 | + (uint64_t)diff[4] << 24 | + (uint64_t)diff[5] << 16 | + (uint64_t)diff[6] << 8 | + (uint64_t)diff[7]; + + uint8_t keys = 0; + memcpy(&keys, &buf[1 + sizeof(uint64_t) * 2], sizeof(uint8_t)); + in->keys.forward = keys & 0b10000000; + in->keys.backward = keys & 0b01000000; + in->keys.left = keys & 0b00100000; + in->keys.right = keys & 0b00010000; + in->keys.jump = keys & 0b00001000; + in->keys.shoot = keys & 0b00000100; + in->keys.block = keys & 0b00000010; + + uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 }; + memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2], sizeof(uint8_t) * 12); + uint32_t vec[3] = { + (uint32_t)subvec[0] << 24 | + (uint32_t)subvec[1] << 16 | + (uint32_t)subvec[2] << 8 | + (uint32_t)subvec[3], + (uint32_t)subvec[4] << 24 | + (uint32_t)subvec[5] << 16 | + (uint32_t)subvec[6] << 8 | + (uint32_t)subvec[7], + (uint32_t)subvec[8] << 24 | + (uint32_t)subvec[9] << 16 | + (uint32_t)subvec[10] << 8 | + (uint32_t)subvec[11] }; + + memcpy(&in->direction, vec, sizeof(uint32_t) * 3); + + *buflen = sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 3; + + return true; } -bool netprot::Deserialize(Output* out, char* buf, const uint32_t buflen) { - return false; +bool netprot::Deserialize(Output* out, char* buf, uint32_t* buflen) { + if (*buflen <= sizeof(Output)) + return false; + + uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; + memcpy(diff, &buf[1], sizeof(uint64_t)); + out->timestamp = + (uint64_t)diff[0] << 56 | + (uint64_t)diff[1] << 48 | + (uint64_t)diff[2] << 40 | + (uint64_t)diff[3] << 32 | + (uint64_t)diff[4] << 24 | + (uint64_t)diff[5] << 16 | + (uint64_t)diff[6] << 8 | + (uint64_t)diff[7]; + + memcpy(diff, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t)); + out->id = + (uint64_t)diff[0] << 56 | + (uint64_t)diff[1] << 48 | + (uint64_t)diff[2] << 40 | + (uint64_t)diff[3] << 32 | + (uint64_t)diff[4] << 24 | + (uint64_t)diff[5] << 16 | + (uint64_t)diff[6] << 8 | + (uint64_t)diff[7]; + + uint8_t states = 0; + memcpy(&states, &buf[1 + sizeof(uint64_t) * 2], sizeof(uint8_t)); + out->states.jumping = states & 0b10000000; + out->states.shooting = states & 0b01000000; + out->states.hit = states & 0b00100000; + out->states.powerup = states & 0b00010000; + out->states.dead = states & 0b00001000; + out->states.still = states & 0b00000100; + out->states.jumpshot = states & 0b00000010; + out->states.running = states & 0b00000001; + + + uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 }; + memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2], sizeof(uint8_t) * 12); + uint32_t vec[3] = { + (uint32_t)subvec[0] << 24 | + (uint32_t)subvec[1] << 16 | + (uint32_t)subvec[2] << 8 | + (uint32_t)subvec[3], + (uint32_t)subvec[4] << 24 | + (uint32_t)subvec[5] << 16 | + (uint32_t)subvec[6] << 8 | + (uint32_t)subvec[7], + (uint32_t)subvec[8] << 24 | + (uint32_t)subvec[9] << 16 | + (uint32_t)subvec[10] << 8 | + (uint32_t)subvec[11] }; + + memcpy(&out->direction, vec, sizeof(uint32_t) * 3); + + memcpy(subvec, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 3], sizeof(uint8_t) * 12); + uint32_t vec2[3] = { + (uint32_t)subvec[0] << 24 | + (uint32_t)subvec[1] << 16 | + (uint32_t)subvec[2] << 8 | + (uint32_t)subvec[3], + (uint32_t)subvec[4] << 24 | + (uint32_t)subvec[5] << 16 | + (uint32_t)subvec[6] << 8 | + (uint32_t)subvec[7], + (uint32_t)subvec[8] << 24 | + (uint32_t)subvec[9] << 16 | + (uint32_t)subvec[10] << 8 | + (uint32_t)subvec[11] }; + + memcpy(&out->position, vec2, sizeof(uint32_t) * 3); + + *buflen = sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 6; + + return true; } -bool netprot::Deserialize(Sync* sync, char* buf, const uint32_t buflen) { - return false; +bool netprot::Deserialize(Sync* sync, char* buf, uint32_t* buflen) { + if (*buflen <= sizeof(Sync)) + return false; + + uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; + memcpy(diff, &buf[1], sizeof(uint64_t)); + sync->timestamp = + (uint64_t)diff[0] << 56 | + (uint64_t)diff[1] << 48 | + (uint64_t)diff[2] << 40 | + (uint64_t)diff[3] << 32 | + (uint64_t)diff[4] << 24 | + (uint64_t)diff[5] << 16 | + (uint64_t)diff[6] << 8 | + (uint64_t)diff[7]; + + memcpy(diff, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t)); + sync->sid = + (uint64_t)diff[0] << 56 | + (uint64_t)diff[1] << 48 | + (uint64_t)diff[2] << 40 | + (uint64_t)diff[3] << 32 | + (uint64_t)diff[4] << 24 | + (uint64_t)diff[5] << 16 | + (uint64_t)diff[6] << 8 | + (uint64_t)diff[7]; + + memcpy(diff, &buf[1 + sizeof(uint64_t) * 2], sizeof(uint32_t)); + sync->timer = + (uint32_t)diff[0] << 24 | + (uint32_t)diff[1] << 16 | + (uint32_t)diff[2] << 8 | + (uint32_t)diff[3]; + + memcpy(diff, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint32_t)], sizeof(uint16_t)); + sync->ammo = + (uint16_t)diff[0] << 8 | + (uint16_t)diff[1]; + + + uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 }; + memcpy(subvec, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) + sizeof(uint16_t)], sizeof(uint8_t) * 12); + uint32_t vec[3] = { + (uint32_t)subvec[0] << 24 | + (uint32_t)subvec[1] << 16 | + (uint32_t)subvec[2] << 8 | + (uint32_t)subvec[3], + (uint32_t)subvec[4] << 24 | + (uint32_t)subvec[5] << 16 | + (uint32_t)subvec[6] << 8 | + (uint32_t)subvec[7], + (uint32_t)subvec[8] << 24 | + (uint32_t)subvec[9] << 16 | + (uint32_t)subvec[10] << 8 | + (uint32_t)subvec[11] }; + + memcpy(&sync->position, vec, sizeof(uint32_t) * 3); + + uint8_t hp8[4]; + + memcpy(&hp8, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t)], sizeof(uint32_t)); + + uint32_t hp = (uint32_t)hp8[0] << 24 | + (uint32_t)hp8[1] << 16 | + (uint32_t)hp8[2] << 8 | + (uint32_t)hp8[3]; + + memcpy(&sync->hp, &hp, sizeof(float)); + + *buflen = 1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float); + + return true; } -bool netprot::Deserialize(TeamInfo* tinfo, char* buf, const uint32_t buflen) { - if (buflen <= sizeof(LoginInfo)) +bool netprot::Deserialize(TeamInfo* tinfo, char* buf, uint32_t* buflen) { + if (*buflen <= sizeof(LoginInfo)) return false; size_t namesize = std::strlen(buf) + 1; @@ -301,7 +750,7 @@ bool netprot::Deserialize(TeamInfo* tinfo, char* buf, const uint32_t buflen) { if (namesize > 32) return false; - memcpy(&tinfo->name, &buf[1], namesize); + strcpy(tinfo->name, namesize, &buf[1]); uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; memcpy(diff, &buf[namesize + 1], sizeof(uint64_t)); @@ -315,11 +764,13 @@ bool netprot::Deserialize(TeamInfo* tinfo, char* buf, const uint32_t buflen) { (uint64_t)diff[6] << 8 | (uint64_t)diff[7]; + *buflen = namesize + sizeof(uint64_t) + 2; + return true; } -bool netprot::Deserialize(LoginInfo* linfo, char* buf, const uint32_t buflen) { - if (buflen <= sizeof(LoginInfo)) +bool netprot::Deserialize(LoginInfo* linfo, char* buf, uint32_t* buflen) { + if (*buflen <= sizeof(LoginInfo)) return false; size_t namesize = std::strlen(buf) + 1; @@ -327,7 +778,7 @@ bool netprot::Deserialize(LoginInfo* linfo, char* buf, const uint32_t buflen) { if (namesize > 32) return false; - memcpy(&linfo->name, &buf[1], namesize); + strcpy(linfo->name, namesize, &buf[1]); uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; memcpy(diff, &buf[namesize + 1], sizeof(uint64_t)); @@ -352,11 +803,13 @@ bool netprot::Deserialize(LoginInfo* linfo, char* buf, const uint32_t buflen) { (uint64_t)diff[6] << 8 | (uint64_t)diff[7]; + *buflen = namesize + sizeof(uint64_t) * 2 + 2; + return true; } -bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, const uint32_t buflen) { - if (buflen <= sizeof(PlayerInfo)) +bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, uint32_t* buflen) { + if (*buflen <= sizeof(PlayerInfo)) return false; size_t namesize = std::strlen(buf) + 1; @@ -364,7 +817,7 @@ bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, const uint32_t buflen) { if (namesize > 32) return false; - memcpy(&pinfo->name, &buf[1], namesize); + strcpy(pinfo->name, namesize, &buf[1]); uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; memcpy(diff, &buf[namesize + 1], sizeof(uint64_t)); @@ -389,11 +842,13 @@ bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, const uint32_t buflen) { (uint64_t)diff[6] << 8 | (uint64_t)diff[7]; + *buflen = namesize + sizeof(uint64_t) * 2 + 2; + return true; } -bool netprot::Deserialize(GameInfo* ginfo, char* buf, const uint32_t buflen) { - if (buflen <= sizeof(GameInfo)) +bool netprot::Deserialize(GameInfo* ginfo, char* buf, uint32_t* buflen) { + if (*buflen <= sizeof(GameInfo)) return false; uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; @@ -430,11 +885,13 @@ bool netprot::Deserialize(GameInfo* ginfo, char* buf, const uint32_t buflen) { (uint64_t)diff[6] << 8 | (uint64_t)diff[7]; + *buflen = sizeof(uint64_t) * 3 + 1; + return true; } -bool netprot::Deserialize(Chat* chat, char* buf, const uint32_t buflen) { - if (buflen <= sizeof(Chat)) +bool netprot::Deserialize(Chat* chat, char* buf, uint32_t* buflen) { + if (*buflen <= sizeof(Chat)) return false; uint8_t src[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; @@ -473,17 +930,120 @@ bool netprot::Deserialize(Chat* chat, char* buf, const uint32_t buflen) { (uint64_t)dstt[6] << 8 | (uint64_t)dstt[7]; - size_t messsize = std::strlen(buf + sizeof(uint64_t) * 3) + 1; + size_t messsize = std::strlen(&buf[sizeof(uint64_t) * 3]) + 1; if (messsize > 140) return false; - memcpy(&chat->mess, &buf[1 + sizeof(uint64_t) * 3], messsize); + char* ciboire = &buf[1 + sizeof(uint64_t) * 3]; + + strcpy(chat->mess, 140, ciboire); + + //*buflen = messsize + sizeof(uint64_t) * 3 + 1; + return true; } -bool netprot::Deserialize(ErrorLog* errlog, char* buf, const uint32_t buflen) { - if (buflen <= sizeof(ErrorLog)) +bool netprot::Deserialize(ChunkMod* chmod, char* buf, uint32_t* buflen) { + if (*buflen <= sizeof(ChunkMod)) + return false; + + uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 }; + memcpy(subvec, &buf[1], sizeof(uint8_t) * 12); + uint32_t vec[3] = { + (uint32_t)subvec[0] << 24 | + (uint32_t)subvec[1] << 16 | + (uint32_t)subvec[2] << 8 | + (uint32_t)subvec[3], + (uint32_t)subvec[4] << 24 | + (uint32_t)subvec[5] << 16 | + (uint32_t)subvec[6] << 8 | + (uint32_t)subvec[7], + (uint32_t)subvec[8] << 24 | + (uint32_t)subvec[9] << 16 | + (uint32_t)subvec[10] << 8 | + (uint32_t)subvec[11] }; + + memcpy(&chmod->pos, vec, sizeof(uint32_t) * 3); + + memcpy(&chmod->b_type, &buf[1 + sizeof(uint8_t) * 12], sizeof(BlockType)); + memcpy(&chmod->old_b_type, &buf[2 + sizeof(uint8_t) * 12], sizeof(BlockType)); + + *buflen = sizeof(uint32_t) * 3 + 3; + + return true; +} + +bool netprot::Deserialize(BulletAdd* bull, char* buf, uint32_t* buflen) { + if (*buflen <= sizeof(BulletAdd)) + return false; + + uint8_t tst[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; + memcpy(tst, &buf[1], sizeof(uint64_t)); + bull->tstamp = + (uint64_t)tst[0] << 56 | + (uint64_t)tst[1] << 48 | + (uint64_t)tst[2] << 40 | + (uint64_t)tst[3] << 32 | + (uint64_t)tst[4] << 24 | + (uint64_t)tst[5] << 16 | + (uint64_t)tst[6] << 8 | + (uint64_t)tst[7]; + + memcpy(tst, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t)); + bull->id = + (uint64_t)tst[0] << 56 | + (uint64_t)tst[1] << 48 | + (uint64_t)tst[2] << 40 | + (uint64_t)tst[3] << 32 | + (uint64_t)tst[4] << 24 | + (uint64_t)tst[5] << 16 | + (uint64_t)tst[6] << 8 | + (uint64_t)tst[7]; + + uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 }; + memcpy(subvec, &buf[1 + sizeof(uint64_t) * 2], sizeof(uint8_t) * 12); + uint32_t vec[3] = { + (uint32_t)subvec[0] << 24 | + (uint32_t)subvec[1] << 16 | + (uint32_t)subvec[2] << 8 | + (uint32_t)subvec[3], + (uint32_t)subvec[4] << 24 | + (uint32_t)subvec[5] << 16 | + (uint32_t)subvec[6] << 8 | + (uint32_t)subvec[7], + (uint32_t)subvec[8] << 24 | + (uint32_t)subvec[9] << 16 | + (uint32_t)subvec[10] << 8 | + (uint32_t)subvec[11] }; + + memcpy(&bull->pos, vec, sizeof(uint32_t) * 3); + + memcpy(subvec, &buf[1 + sizeof(uint64_t) * 2 + sizeof(uint8_t) * 12], sizeof(uint8_t) * 12); + + uint32_t dir[3] = { + (uint32_t)subvec[0] << 24 | + (uint32_t)subvec[1] << 16 | + (uint32_t)subvec[2] << 8 | + (uint32_t)subvec[3], + (uint32_t)subvec[4] << 24 | + (uint32_t)subvec[5] << 16 | + (uint32_t)subvec[6] << 8 | + (uint32_t)subvec[7], + (uint32_t)subvec[8] << 24 | + (uint32_t)subvec[9] << 16 | + (uint32_t)subvec[10] << 8 | + (uint32_t)subvec[11] }; + + memcpy(&bull->dir, dir, sizeof(uint32_t) * 3); + + *buflen = 1 + sizeof(uint64_t) * 2 + sizeof(uint8_t) * 24; + + return true; +} + +bool netprot::Deserialize(ErrorLog* errlog, char* buf, uint32_t* buflen) { + if (*buflen <= sizeof(ErrorLog)) return false; size_t messsize = std::strlen(buf) + 1; @@ -494,13 +1054,346 @@ bool netprot::Deserialize(ErrorLog* errlog, char* buf, const uint32_t buflen) { memcpy(&errlog->mess, &buf[1], messsize); memcpy(&errlog->is_fatal, &buf[1 + messsize], sizeof(bool)); + *buflen = messsize + sizeof(uint64_t) * 3 + 2; + return true; } -netprot::PacketType netprot::getType(char* buf, const uint32_t buflen) { - if (buflen < 1 || - buf[0] >= netprot::PACKET_TYPE::LAST_PACK || - buf[0] <= netprot::PACKET_TYPE::ERR) + + +netprot::PACKET_TYPE netprot::getType(char* buf, const uint32_t buflen) { + if (buflen < 1 || + buf[0] >= (char)netprot::PACKET_TYPE::LAST_PACK || + buf[0] <= (char)netprot::PACKET_TYPE::ERR) return netprot::PACKET_TYPE::ERR; - return buf[0]; + return (netprot::PACKET_TYPE)buf[0]; +} + +netprot::Packet netprot::getPack(char* buf, uint32_t* buflen) { + Packet pck = { nullptr, PACKET_TYPE::ERR }; + Input* in = nullptr; + Output* out = nullptr; + Sync* sync = nullptr; + Chat* chat = nullptr; + GameInfo* ginfo = nullptr; + ErrorLog* errlog = nullptr; + LoginInfo* loginf = nullptr; + + switch (getType(buf, *buflen)) { + case PACKET_TYPE::INPUT: + in = new Input(); + if (netprot::Deserialize(in, buf, buflen)) { + pck.type = PACKET_TYPE::INPUT; + pck.ptr = (void*)in; + } + break; + case PACKET_TYPE::OUTPUT: + out = new Output(); + if (netprot::Deserialize(out, buf, buflen)) { + pck.type = PACKET_TYPE::OUTPUT; + pck.ptr = (void*)out; + } + break; + case PACKET_TYPE::SYNC: + sync = new Sync(); + if (netprot::Deserialize(sync, buf, buflen)) { + pck.type = PACKET_TYPE::SYNC; + pck.ptr = (void*)sync; + } + break; + case PACKET_TYPE::CHAT: + chat = new Chat(); + if (netprot::Deserialize(chat, buf, buflen)) { + pck.type = PACKET_TYPE::CHAT; + pck.ptr = (void*)chat; + } + break; + case PACKET_TYPE::GAMEINFO: + ginfo = new GameInfo(); + if (netprot::Deserialize(ginfo, buf, buflen)) { + pck.type = PACKET_TYPE::GAMEINFO; + pck.ptr = (void*)ginfo; + } + break; + case PACKET_TYPE::ERRLOG: + errlog = new ErrorLog(); + if (netprot::Deserialize(errlog, buf, buflen)) { + pck.type = PACKET_TYPE::ERRLOG; + pck.ptr = (void*)errlog; + } + break; + case PACKET_TYPE::LOGINF: + loginf = new LoginInfo(); + if (netprot::Deserialize(loginf, buf, buflen)) { + pck.type = PACKET_TYPE::LOGINF; + pck.ptr = (void*)loginf; + } + break; + default: + break; + } + return pck; +} + +netprot::Packet netprot::getPack(netprot::Buffer* buf) { return netprot::getPack(buf->ptr, &buf->len); } + +bool netprot::emptyPack(netprot::Packet pck) { + switch (pck.type) { + case PACKET_TYPE::INPUT: + delete (Input*)pck.ptr; + return true; + case PACKET_TYPE::OUTPUT: + delete (Output*)pck.ptr; + return true; + case PACKET_TYPE::SYNC: + delete (Sync*)pck.ptr; + return true; + case PACKET_TYPE::CHAT: + delete (Chat*)pck.ptr; + return true; + case PACKET_TYPE::GAMEINFO: + delete (GameInfo*)pck.ptr; + return true; + case PACKET_TYPE::ERRLOG: + delete (ErrorLog*)pck.ptr; + return true; + case PACKET_TYPE::LOGINF: + delete (LoginInfo*)pck.ptr; + return true; + default: + return false; + } +} + +netprot::Packet netprot::makePack(void* ptr, PACKET_TYPE type) { + Packet pck; + pck.ptr = ptr; + pck.type = type; + return pck; +} + +void netprot::recvPacks(SOCKET sock, Buffer* buf, std::vector* lsPck) { + int len = 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; + bool ended = true; + struct pollfd fds[1]; + + fds[0].fd = sock; + fds[0].events = POLLIN; + + while (true) { + if (!poll(fds, 1, 0)) { + if (ended) + buf->tmp = nullptr; + return; + } + + int bytes = recv(sock, &buf->ptr[len], buf->len - len, 0); + if (bytes <= 0) { // si recv() retourne -1 ou 0; ça veut dire qu'il y a plus rien a lire qui n'a pas déjà été traité. + if (ended) + buf->tmp = nullptr; + return; + } + len += bytes; + end = len; + + ended = false; + + while (true) { + int cmp = 0; + + if (cursor) + end -= (cursor - buf->ptr); + + if (end < 0) + break; + + cursor = (char*)memchr(next, '\r', end); + + if (cursor) { + next = cursor; + cursor--; + + cmp = memcmp(cursor, Footer, sizeof(uint32_t)); + if (cmp == 0) { + lsPck->push_back(last); + cursor += sizeof(uint32_t); + last = cursor; + next = cursor + 1; + } + } + else { + buf->tmp = last; + cursor = &buf->ptr[len]; + next = cursor + 1; + break; + }; + } + } +} + +void netprot::recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from, std::vector* lsPck) { + int len = 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; + bool ended = true; + struct pollfd fds[1]; + sockaddr_in sockad = from; + addrlen_t socklen = sizeof(sockad); + + fds[0].fd = sock; + fds[0].events = POLLIN; + + while (true) { + if (!poll(fds, 1, 0)) { + if (ended) + buf->tmp = nullptr; + return; + } + + int bytes = recvfrom(sock, &buf->ptr[len], buf->len - len, 0, (sockaddr*)&sockad, &socklen); + if (bytes <= 0) { // si recv() retourne -1 ou 0; ça veut dire qu'il y a plus rien a lire qui n'a pas déjà été traité. + if (ended) + buf->tmp = nullptr; + return; + } + len += bytes; + end = len; + + ended = false; + + while (true) { + int cmp = 0; + + if (cursor) + end -= (cursor - buf->ptr); + + if (end < 0) + break; + + cursor = (char*)memchr(next, '\r', end); + + if (cursor) { + next = cursor; + cursor--; + + cmp = memcmp(cursor, Footer, sizeof(uint32_t)); + if (cmp == 0) { + lsPck->push_back(last); + cursor += sizeof(uint32_t); + last = cursor; + next = cursor + 1; + } + } + else { + buf->tmp = last; + cursor = &buf->ptr[len]; + next = cursor + 1; + break; + }; + } + } +} + +template <> +void netprot::sendPack(SOCKET sock, Packet* pack, Buffer* buf) { + switch (pack->type) { + case PACKET_TYPE::INPUT: + sendPack(sock, (Input*)pack->ptr, buf); + return; + case PACKET_TYPE::OUTPUT: + sendPack(sock, (Output*)pack->ptr, buf); + return; + case PACKET_TYPE::SYNC: + sendPack(sock, (Sync*)pack->ptr, buf); + return; + case PACKET_TYPE::TEAMINF: + sendPack(sock, (TeamInfo*)pack->ptr, buf); + return; + case PACKET_TYPE::PLAYINF: + sendPack(sock, (PlayerInfo*)pack->ptr, buf); + return; + case PACKET_TYPE::LOGINF: + sendPack(sock, (LoginInfo*)pack->ptr, buf); + return; + case PACKET_TYPE::CHUNKMOD: + //sendPack(sock, (ChunkMod*)pack->ptr, buf); + return; + case PACKET_TYPE::PLAYERMOD: + //sendPack(sock, (PlayerMod*)pack->ptr, buf); + return; + case PACKET_TYPE::PICKUPMOD: + //sendPack(sock, (PickupMod*)pack->ptr, buf); + return; + case PACKET_TYPE::GAMEINFO: + sendPack(sock, (GameInfo*)pack->ptr, buf); + return; + case PACKET_TYPE::ENDINFO: + //sendPack(sock, (EndInfo*)pack->ptr, buf); + return; + case PACKET_TYPE::CHAT: + sendPack(sock, (Chat*)pack->ptr, buf); + return; + case PACKET_TYPE::ERRLOG: + sendPack(sock, (ErrorLog*)pack->ptr, buf); + return; + case PACKET_TYPE::LAST_PACK: [[fallthrough]]; + case PACKET_TYPE::ERR: [[fallthrough]]; + default: + return; + } +} + +template <> +void netprot::sendPackTo(SOCKET sock, Packet* pack, Buffer* buf, sockaddr_in* sockad) { + switch (pack->type) { + case PACKET_TYPE::INPUT: + sendPackTo(sock, (Input*)pack->ptr, buf, sockad); + return; + case PACKET_TYPE::OUTPUT: + sendPackTo(sock, (Output*)pack->ptr, buf, sockad); + return; + case PACKET_TYPE::SYNC: + sendPackTo(sock, (Sync*)pack->ptr, buf, sockad); + return; + case PACKET_TYPE::TEAMINF: + sendPackTo(sock, (TeamInfo*)pack->ptr, buf, sockad); + return; + case PACKET_TYPE::PLAYINF: + sendPackTo(sock, (PlayerInfo*)pack->ptr, buf, sockad); + return; + case PACKET_TYPE::LOGINF: + sendPackTo(sock, (LoginInfo*)pack->ptr, buf, sockad); + return; + case PACKET_TYPE::CHUNKMOD: + //sendPackTo(sock, (ChunkMod*)pack->ptr, buf, sockad); + return; + case PACKET_TYPE::PLAYERMOD: + //sendPackTo(sock, (PlayerMod*)pack->ptr, buf, sockad); + return; + case PACKET_TYPE::PICKUPMOD: + //sendPackTo(sock, (PickupMod*)pack->ptr, buf, sockad); + return; + case PACKET_TYPE::GAMEINFO: + sendPackTo(sock, (GameInfo*)pack->ptr, buf, sockad); + return; + case PACKET_TYPE::ENDINFO: + //sendPackTo(sock, (EndInfo*)pack->ptr, buf, sockad); + return; + case PACKET_TYPE::CHAT: + sendPackTo(sock, (Chat*)pack->ptr, buf, sockad); + return; + case PACKET_TYPE::ERRLOG: + sendPackTo(sock, (ErrorLog*)pack->ptr, buf, sockad); + return; + case PACKET_TYPE::LAST_PACK: [[fallthrough]]; + case PACKET_TYPE::ERR: [[fallthrough]]; + default: + return; + } } diff --git a/SQCSim-common/netprotocol.h b/SQCSim-common/netprotocol.h index d7c7a93..6171bcf 100644 --- a/SQCSim-common/netprotocol.h +++ b/SQCSim-common/netprotocol.h @@ -1,41 +1,65 @@ #ifndef NETPROTOCOL_H__ #define NETPROTOCOL_H__ -#include "define.h" #include +#include "define.h" #include "vector3.h" -/* Protocole Particulier de Partie à Plusieurs Personnes (PPPPP) */ - -// Packet: packet[0] = PacketType, packet[1..n-1] = {packet} +/* Protocole Particulier de Partie a Plusieurs Personnes (PPPPP) */ namespace netprot { - typedef uint8_t PacketType; - enum PACKET_TYPE { + enum class PACKET_TYPE: uint8_t { ERR, INPUT, OUTPUT, SYNC, TEAMINF, SELFINF, PLAYINF, LOGINF, CHUNKMOD, PLAYERMOD, PICKUPMOD, - GAMEINFO, ENDINFO , CHAT, ERRLOG, - LAST_PACK + GAMEINFO, ENDINFO , BULLET, + CHAT, ERRLOG, LAST_PACK }; + /* Structures */ + + struct Buffer { // Pour pouvoir rendre l'utilisation des buffers plus clean. + char *ptr = new char[BUFFER_LENGTH] { 1 }, *tmp = nullptr; + uint32_t len = BUFFER_LENGTH; + + ~Buffer() { delete[] ptr; } + void rstLen() { len = BUFFER_LENGTH; } + }; + + struct Packet { // Pour pouvoir recevoir les paquets du recv() sans avoir à les aiguiller dans la même thread. + void *ptr = nullptr; // Notez que le pointeur doit être supprimé séparément lorsqu'il n'est plus utile. + PACKET_TYPE type = PACKET_TYPE::ERR; + }; + + /* Constantes */ + + inline const char Footer[sizeof(uint32_t)] = { '\0', '\r', '\0', '\n' }; // constante de footer qui est ajoutée à chaque paquet envoyé. + + /* Sous-structures */ + struct Keys { - bool forward, - backward, - left, - right, - jump, - shoot, - block; + bool forward = false, + backward = false, + left = false, + right = false, + jump = false, + shoot = false, + block = false; }; struct States { - bool jumping, - shooting, - hit, - powerup; + bool jumping = false, + shooting = false, + hit = false, + powerup = false, + dead = false, + still = false, + jumpshot = false, + running = false; }; + /* Structures de paquets */ + struct Input { // cli -> srv UDP ~frame Timestamp timestamp; uint64_t sid = 0; @@ -51,50 +75,83 @@ namespace netprot { States states; // 0bJSH_____ bit-packing de bool. }; - struct Sync { // srv -> cli TCP ~second + struct Sync { // srv -> cli TCP ~second - un premier sync démarre la partie. Timestamp timestamp; uint64_t sid = 0; uint32_t timer = 0; uint16_t ammo = 0; - uint8_t hp = 0; + float hp = 0; Vector3f position; + Sync() {} + Sync(Sync* sync) : timestamp(sync->timestamp), sid(sync->sid), timer(sync->timer), ammo(sync->ammo), hp(sync->hp), position(sync->position) {} }; struct TeamInfo { // cli <-> srv TCP once - char name[32]; + char *name = new char[32]; uint64_t id = 0; + TeamInfo() {} + TeamInfo(TeamInfo* tem) : id(tem->id) { strcpy(name, 32, tem->name); } + ~TeamInfo() { delete[] name; } }; struct LoginInfo { // cli <-> srv TCP once - char name[32]; + char *name = new char[32]; uint64_t sid = 0, tid = 0; + LoginInfo() {} + LoginInfo(LoginInfo* log): sid(log->sid), tid(log->tid) { strcpy(name, 32, log->name); } + ~LoginInfo() { delete[] name; } }; struct PlayerInfo { // cli <-> srv TCP once - char name[32]; + char *name = new char[32]; uint64_t id = 0, tid = 0; + PlayerInfo() {} + PlayerInfo(PlayerInfo* ply) : id(ply->id), tid(ply->tid) { strcpy(name, 32, ply->name); }; + PlayerInfo(int id, int tid, std::string strname) : id(id), tid(tid) { strcpy(name, 32, strname.c_str()); } + ~PlayerInfo() { delete[] name; } }; struct GameInfo { // cli <-> srv TCP event (before game start)/ once uint64_t seed; uint32_t countdown; - uint8_t gameType; // TOOD: enum. + uint8_t gameType; // TODD: enum. + GameInfo() {} + GameInfo(GameInfo* gam) : seed(gam->seed), countdown(gam->countdown), gameType(gam->gameType) {} }; struct Chat { // cli <-> srv TCP event uint64_t src_id = 0, dest_id = 0, dest_team_id = 0; - char mess[140]; // Good 'nough for twitr, good 'nough for me. + char *mess = new char[140]; // Good 'nough for twitr, good 'nough for me. + Chat() {} + Chat(Chat* cha) : src_id(cha->src_id), dest_id(cha->dest_id), dest_team_id(cha->dest_team_id) { strcpy(mess, 140, cha->mess); } + ~Chat() { delete[] mess; } + }; + + struct ChunkMod { + Vector3f pos; + BlockType b_type, old_b_type; + }; + + struct BulletAdd { + Timestamp tstamp; + Vector3f pos, dir; + uint64_t id; }; struct ErrorLog { // srv -> cli TCP event - char mess[140]; - bool is_fatal; + char *mess = new char[140]; + bool is_fatal = false; + ErrorLog() {}; + ErrorLog(ErrorLog* err) : is_fatal(err->is_fatal) { strcpy(mess, 140, err->mess); } + ~ErrorLog() { delete[] mess; } }; + /* Fonctions */ + void Serialize(Input* in, char* buf[], uint32_t* buflen); // cli void Serialize(Output* out, char* buf[], uint32_t* buflen); // srv void Serialize(Sync* sync, char* buf[], uint32_t* buflen); // srv @@ -103,18 +160,84 @@ namespace netprot { void Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen); // srv void Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen); // cli/srv void Serialize(Chat* chat, char* buf[], uint32_t* buflen); // cli/srv + void Serialize(ChunkMod* chmod, char* buf[], uint32_t* buflen); // srv + void Serialize(BulletAdd* bull, char* buf[], uint32_t* buflen); // srv void Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen); // srv - bool Deserialize(Input* in, char* buf, const uint32_t buflen); // srv - bool Deserialize(Output* out, char* buf, const uint32_t buflen); // cli - bool Deserialize(Sync* sync, char* buf, const uint32_t buflen); // cli - bool Deserialize(TeamInfo* tinfo, char* buf, const uint32_t buflen); // cli/srv - bool Deserialize(LoginInfo* linfo, char* buf, const uint32_t buflen); // cli/srv - bool Deserialize(PlayerInfo* pinfo, char* buf, const uint32_t buflen); // cli - bool Deserialize(GameInfo* ginfo, char* buf, const uint32_t buflen); // cli - bool Deserialize(Chat* chat, char* buf, const uint32_t buflen); // srv/cli - bool Deserialize(ErrorLog* errlog, char* buf, const uint32_t buflen); // srv + bool Deserialize(Input* in, char* buf, uint32_t* buflen); // srv + bool Deserialize(Output* out, char* buf, uint32_t* buflen); // cli + bool Deserialize(Sync* sync, char* buf, uint32_t* buflen); // cli + bool Deserialize(TeamInfo* tinfo, char* buf, uint32_t* buflen); // cli/srv + bool Deserialize(LoginInfo* linfo, char* buf, uint32_t* buflen); // cli/srv + bool Deserialize(PlayerInfo* pinfo, char* buf, uint32_t* buflen); // cli + bool Deserialize(GameInfo* ginfo, char* buf, uint32_t* buflen); // cli + bool Deserialize(Chat* chat, char* buf, uint32_t* buflen); // srv/cli + bool Deserialize(ChunkMod* chmod, char* buf, uint32_t* buflen); // cli + bool Deserialize(BulletAdd* bull, char* buf, uint32_t* buflen); // cli + bool Deserialize(ErrorLog* errlog, char* buf, uint32_t* buflen); // srv - PacketType getType(char* buf, uint32_t buflen); // srv/cli -} + PACKET_TYPE getType(char* buf, uint32_t buflen); + + Packet getPack(char* buf, uint32_t *buflen); + Packet getPack(Buffer* buf); + + bool emptyPack(Packet pck); + + Packet makePack(void* ptr, PACKET_TYPE type); // Pour pouvoir faire une liste de stock a supprimer sans avoir a en faire une pour chaque type. + + template T copyPack(Packet* pck); + + template void sendPack(SOCKET sock, T* pack, char** buf, uint32_t* buflen); + template void sendPackTo(SOCKET sock, T* pack, char** buf, uint32_t* buflen, sockaddr_in* sockad); + + template void sendPack(SOCKET sock, T* pack, Buffer* buf); + template void sendPackTo(SOCKET sock, T* pack, Buffer* buf, sockaddr_in* sockad); + + void recvPacks(SOCKET sock, Buffer* buf, std::vector* lsPck); + void recvPacksFrom(SOCKET sock, Buffer* buf, sockaddr_in from, std::vector* lsPck); + + /* Templates */ + + template + T copyPack(Packet* pck) { return T((T*)pck->ptr); } + + template + void sendPack(SOCKET sock, T* pack, char** buf, uint32_t* buflen) { + netprot::Serialize(pack, buf, buflen); + memcpy(*buf + *buflen, Footer, sizeof(uint32_t)); + *buflen += sizeof(Footer); + send(sock, *buf, *buflen, 0); + *buflen = BUFFER_LENGTH; + } + + template + void sendPackTo(SOCKET sock, T* pack, char** buf, uint32_t* buflen, sockaddr_in* sockad) { + const sockaddr_in addr = *sockad; + netprot::Serialize(pack, buf, buflen); + memcpy(*buf + *buflen, Footer, sizeof(uint32_t)); + *buflen += sizeof(Footer); + sendto(sock, *buf, *buflen, 0, (sockaddr*)&addr, sizeof(addr)); + *buflen = BUFFER_LENGTH; + } + + template + void sendPack(SOCKET sock, T* pack, Buffer* buf) { + netprot::Serialize(pack, &buf->ptr, &buf->len); + memcpy(&buf->ptr[buf->len], Footer, sizeof(uint32_t)); + buf->len += sizeof(Footer); + send(sock, buf->ptr, buf->len, 0); + buf->rstLen(); + } + + template + void sendPackTo(SOCKET sock, T* pack, Buffer* buf, sockaddr_in* sockad) { + const sockaddr_in addr = *sockad; + netprot::Serialize(pack, &buf->ptr, &buf->len); + memcpy(&buf->ptr[buf->len], Footer, sizeof(uint32_t)); + buf->len += sizeof(Footer); + sendto(sock, buf->ptr, buf->len, 0, (sockaddr*)&addr, sizeof(addr)); + buf->rstLen(); + } + +}; #endif diff --git a/SQCSim-common/player.cpp b/SQCSim-common/player.cpp index 9fe810c..85df138 100644 --- a/SQCSim-common/player.cpp +++ b/SQCSim-common/player.cpp @@ -4,51 +4,63 @@ 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_airborne = true; - m_hp = 0.75f; //TODO: Remettre à 1.0f + m_hp = 1.0f; //TODO: Remettre � 1.0f m_username = "Zelda Bee-Bop56"; } +Player::~Player() {} + void Player::TurnLeftRight(float value) { m_rotY += value; if (m_rotY > 360) m_rotY = 0; else if (m_rotY < -360) m_rotY = 0; + + float yrotrad = (m_rotY / 57.2957795056f); // 180/Pi = 57.295... + float xrotrad = (m_rotX / 57.2957795056f); + + m_direction = Vector3f(cos(xrotrad) * sin(yrotrad), + -sin(xrotrad), + cos(xrotrad) * -cos(yrotrad)); + + m_direction.Normalize(); } void Player::TurnTopBottom(float value) { m_rotX += value; if (m_rotX > 80) m_rotX = 80; else if (m_rotX < -80) m_rotX = -80; -} - -Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jump, bool shoot, float elapsedTime) { - - Vector3f delta = Vector3f(0, 0, 0); float yrotrad = (m_rotY / 57.2957795056f); // 180/Pi = 57.295... float xrotrad = (m_rotX / 57.2957795056f); m_direction = Vector3f(cos(xrotrad) * sin(yrotrad), - -sin(xrotrad), - cos(xrotrad) * -cos(yrotrad)); + -sin(xrotrad), + cos(xrotrad) * -cos(yrotrad)); m_direction.Normalize(); +} + +Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jump, bool shoot, float elapsedTime) { + Vector3f delta = Vector3f(0, 0, 0); + + Vector3f dir = m_direction; + + dir.y = 0; if (front) { - delta.x += float(sin(yrotrad)) * elapsedTime * 10.f; - delta.z += float(-cos(yrotrad)) * elapsedTime * 10.f; + delta += dir; } else if (back) { - delta.x += float(-sin(yrotrad)) * elapsedTime * 10.f; - delta.z += float(cos(yrotrad)) * elapsedTime * 10.f; + delta -= dir; } if (left) { - delta.x += float(-cos(yrotrad)) * elapsedTime * 10.f; - delta.z += float(-sin(yrotrad)) * elapsedTime * 10.f; + delta.x += dir.z; + delta.z += -dir.x; } else if (right) { - delta.x += float(cos(yrotrad)) * elapsedTime * 10.f; - delta.z += float(sin(yrotrad)) * elapsedTime * 10.f; + delta.x -= dir.z; + delta.z -= -dir.x; } delta.Normalize(); @@ -59,6 +71,11 @@ Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jum delta.y += jump? .32f: shoot? .1f : 0.f; m_airborne = true; } + if (boostspeed) + { + delta.x += STRENGTH_SPEED_BOOST / 100 * delta.x; + delta.z += STRENGTH_SPEED_BOOST / 100 * delta.z; + } if (shoot) // Recoil! TurnTopBottom(-1); @@ -165,7 +182,7 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi m_position += m_velocity; - static float bobbingtime = 0; // Gestion de la caméra + static float bobbingtime = 0; // Gestion de la cam�ra static bool leftright = false; static bool isStep = false; if (bobbingtime <= 360.f) @@ -180,18 +197,71 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi else isStep = false; m_POV = m_position.y; m_POV += m_airborne ? 0 : (sin(bobbingtime) - 0.5f) * (abs(m_velocity.x) + abs(m_velocity.z)) * .2f; - + RemoveBooster(elapsedTime); return snd; } -void Player::ApplyTransformation(Transformation& transformation, bool rel) const { +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) +{ + if (boosttype == SPEED) + { + boostspeed = true; + timeboostspeed = 0; + } + if (boosttype == HEAL) + { + m_hp = 100; + } + if (boosttype == DAMAGE) + { + boostdamage = true; + timeboostdamage = 0; + } + if (boosttype == INVINCIBLE) + { + boostinvincible = true; + boostinvincible = 0; + } +} +void Player::RemoveBooster(float elapsedtime) +{ + if (boostspeed) + { + timeboostspeed += elapsedtime; + if (timeboostspeed >= TIME_SPEED_BOOST) + boostspeed = false; + } + if (boostdamage) + { + timeboostdamage += elapsedtime; + if (timeboostdamage >= TIME_DAMAGE_BOOST) + boostdamage = false; + } + if (boostinvincible) + { + timeboostinvincible += elapsedtime; + if (timeboostinvincible >= TIME_INVINCIBLE_BOOST) + boostinvincible = false; + } +} +void Player::SetDirection(Vector3f dir) { m_direction = dir; } + +void Player::Move(Vector3f diff) { m_position -= diff; } + Vector3f Player::GetPosition() const { return Vector3f(m_position.x + CHUNK_SIZE_X * WORLD_SIZE_X / 2, m_position.y, m_position.z + CHUNK_SIZE_Z * WORLD_SIZE_Y / 2); } +Vector3f Player::GetPositionAbs() const { return m_position; } + Vector3f Player::GetVelocity() const { return m_velocity; } Vector3f Player::GetPOV() const { return Vector3f(GetPosition().x, m_POV, GetPosition().z); } @@ -206,3 +276,27 @@ void Player::Teleport(int& x, int& z) { m_position.x -= x * CHUNK_SIZE_X; m_position.z -= z * CHUNK_SIZE_Z; } +bool Player::GetIsAirborne() const { return m_airborne; } + +bool Player::AmIDead() { return m_hp <= 0; } + +void Player::InflictDamage(float hitPoints) { + m_hp -= hitPoints; + + if (m_hp < 0) + m_hp == 0; + //if (AmIDead()) + //{ // Quand le joueur est mort. + //} +} + +int Player::getScore() const { return m_score; } + +void Player::addPoint() { ++m_score; } + + +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(); +} diff --git a/SQCSim-common/player.h b/SQCSim-common/player.h index e439fa2..6117605 100644 --- a/SQCSim-common/player.h +++ b/SQCSim-common/player.h @@ -5,20 +5,29 @@ #include "transformation.h" #include "vector3.h" + class World; class Player { public: enum Sound { NOSOUND, STEP, FALL }; + enum Booster { SPEED, HEAL, DAMAGE, INVINCIBLE }; 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); Sound ApplyPhysics(Vector3f input, World* world, float elapsedTime); - void ApplyTransformation(Transformation& transformation, bool rel = true) const; + void GetBooster(Booster boosttype); + void RemoveBooster(float elapsedtime); + void ApplyTransformation(Transformation& transformation, bool rel = true, bool rot = true) const; + void SetDirection(Vector3f dir); + void Move(Vector3f diff); Vector3f GetPosition() const; + Vector3f GetPositionAbs() const; Vector3f GetDirection() const; Vector3f GetVelocity() const; Vector3f GetPOV() const; @@ -26,20 +35,43 @@ public: float GetHP() const; void Teleport(int& x, int& z); + bool GetIsAirborne() const; + bool AmIDead(); + void InflictDamage(float hitPoints); + int getScore() const; + void addPoint(); + uint64_t Killer = 0; + std::string m_username; + bool m_hit = false; + private: + uint64_t getId() const; + +protected: Vector3f m_position; Vector3f m_velocity; Vector3f m_direction; - std::string m_username; + uint64_t id = 0; + int m_score = 0; float m_rotX = 0; float m_rotY = 0; float m_POV; + float timeboostspeed; + float timeboostdamage; + float timeboostinvincible; float m_hp; bool m_airborne; + bool boostspeed; + bool boostdamage; + bool boostinvincible; + + + + Vector3f InterpolatePosition(const Vector3f& vec1, const Vector3f& vec2, const Timestamp& tim1, const Timestamp& tim2, const Timestamp& now); }; #endif //_PLAYER_H__ diff --git a/SQCSim-common/world.cpp b/SQCSim-common/world.cpp index 1be12e7..2791ca1 100644 --- a/SQCSim-common/world.cpp +++ b/SQCSim-common/world.cpp @@ -6,10 +6,19 @@ World::~World() {} Array2d& World::GetChunks() { return m_chunks; } +void World::BuildWorld() { + for (int x = 0; x < WORLD_SIZE_X; ++x) + for (int y = 0; y < WORLD_SIZE_Y; ++y) + m_chunks.Set(x, y, new Chunk(x + m_center[0], y + m_center[1], m_seed)); +} + void World::SetSeed(uint64_t seed) { m_seed = seed; } + + + Chunk* World::ChunkAt(float x, float y, float z) const { int cx = (int)x / CHUNK_SIZE_X; int cz = (int)z / CHUNK_SIZE_Z; @@ -25,6 +34,32 @@ Chunk* World::ChunkAt(float x, float y, float z) const { Chunk* World::ChunkAt(const Vector3f& pos) const { return ChunkAt(pos.x, pos.y, pos.z); } +void World::RemoveChunk(int nbReduit) +{ + for (int x = 0; x < WORLD_SIZE_X; ++x) + for (int y = 0; y < WORLD_SIZE_Y; ++y) + { + Chunk* chk = nullptr; + if (x < nbReduit) + chk = m_chunks.Remove(x, y); + if (y < nbReduit) + chk = m_chunks.Remove(x, y); + if (y > WORLD_SIZE_Y - nbReduit) + chk = m_chunks.Remove(x, y); + if (x > WORLD_SIZE_X - nbReduit) + chk = m_chunks.Remove(x, y); + + // TODO: MakeDirty() les voisins pour qu'ils se redessinent. + + if (!chk) + continue; + + m_tbDeleted.emplace_back(chk); + } + + +} + BlockType World::BlockAt(float x, float y, float z, BlockType defaultBlockType) const { Chunk* c = ChunkAt(x, y, z); @@ -134,31 +169,26 @@ void World::Update(Bullet* bullets[MAX_BULLETS], const Vector3f& player_pos, Blo UpdateWorld(player_pos, blockinfo); //TransposeWorld(player_pos, bullets); } -// -//void World::UpdateChunk(int& updates, unsigned int chx, unsigned int chy, BlockInfo* blockinfo[BTYPE_LAST]) { -// if (updates == 0 && ChunkAt(chx, 1, chy) && -// ChunkAt(chx, 1, chy)->IsDirty()) { -// ChunkAt(chx, 1, chy)->Update(blockinfo, this); -// updates = FRAMES_UPDATE_CHUNKS; -// } -// -//} -void World::ChangeBlockAtCursor(BlockType blockType, const Vector3f& player_pos, const Vector3f& player_dir, bool& block) { +netprot::ChunkMod* World::ChangeBlockAtCursor(BlockType blockType, const Vector3f& player_pos, const Vector3f& player_dir, bool& block, bool net) { Vector3f currentPos = player_pos; Vector3f currentBlock = currentPos; Vector3f ray = player_dir; + BlockType oldbtype; + netprot::ChunkMod* cmod = nullptr; bool found = false; - if (block) return; + if (block) return cmod; while ((currentPos - currentBlock).Length() <= MAX_SELECTION_DISTANCE && !found) { currentBlock += ray / 10.f; BlockType bt = BlockAt(currentBlock); - if (bt != BTYPE_AIR) + if (bt != BTYPE_AIR) { found = true; + oldbtype = bt; + } } if (found) @@ -184,21 +214,30 @@ void World::ChangeBlockAtCursor(BlockType blockType, const Vector3f& player_pos, (By == PyA || By == PyB || By == PyC) && - Bz == Pz)) + Bz == Pz)) { found = true; + oldbtype = bt; + } } } } if (found && (int)currentBlock.y < CHUNK_SIZE_Y) { + if (net) { + cmod = new netprot::ChunkMod(); + cmod->old_b_type = oldbtype; + cmod->b_type = blockType; + cmod->pos = currentBlock; + } int bx = (int)currentBlock.x % CHUNK_SIZE_X; int by = (int)currentBlock.y % CHUNK_SIZE_Y; int bz = (int)currentBlock.z % CHUNK_SIZE_Z; - ChunkAt(currentBlock)->SetBlock(bx, by, bz, blockType, this); ChunkAt(currentBlock)->MakeModified(); block = true; } + + return cmod; } void World::ChangeBlockAtPosition(BlockType blockType, Vector3f pos) { @@ -220,7 +259,7 @@ void World::UpdateWorld(const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST] int threads = 0; std::future genThList[THREADS_GENERATE_CHUNKS]; //std::future delThList[THREADS_DELETE_CHUNKS]; - + if (frameGenerate > 0) --frameGenerate; if (frameUpdate > 0) --frameUpdate; if (frameDelete > 0) --frameDelete; diff --git a/SQCSim-common/world.h b/SQCSim-common/world.h index 0cc628d..06c513b 100644 --- a/SQCSim-common/world.h +++ b/SQCSim-common/world.h @@ -11,6 +11,7 @@ #include "array2d.h" #include "bullet.h" #include "chunk.h" +#include "netprotocol.h" class Chunk; class Bullet; @@ -21,12 +22,15 @@ public: ~World(); Array2d& GetChunks(); + void BuildWorld(); void SetSeed(uint64_t seed); Chunk* ChunkAt(float x, float y, float z) const; Chunk* ChunkAt(const Vector3f& pos) const; + void RemoveChunk(int nbReduit); + BlockType BlockAt(float x, float y, float z, BlockType defaultBlockType = BTYPE_AIR) const; BlockType BlockAt(const Vector3f& pos, BlockType defaultBlockType = BTYPE_AIR) const; @@ -34,7 +38,7 @@ public: void GetScope(unsigned int& x, unsigned int& y); - void ChangeBlockAtCursor(BlockType blockType, const Vector3f& player_pos, const Vector3f& player_dir, bool& block); + netprot::ChunkMod* ChangeBlockAtCursor(BlockType blockType, const Vector3f& player_pos, const Vector3f& player_dir, bool& block, bool net); void ChangeBlockAtPosition(BlockType blockType, Vector3f pos); void CleanUpWorld(int& deleteframes, bool clear); int GettbDeleted() const; @@ -45,7 +49,7 @@ private: unsigned int m_center[2] = { UINT16_MAX / 2 - WORLD_SIZE_X, UINT16_MAX / 2 - WORLD_SIZE_Y }; - void UpdateChunk(int& updates, unsigned int chx, unsigned int chy, BlockInfo* blockinfo[BTYPE_LAST]); + //void UpdateChunk(int& updates, unsigned int chx, unsigned int chy, BlockInfo* blockinfo[BTYPE_LAST]); void UpdateWorld(const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]); void TransposeWorld(Vector3f& player, Bullet* bullets[MAX_BULLETS]); diff --git a/SQCSim-srv/SQCSim-srv.vcxproj b/SQCSim-srv/SQCSim-srv.vcxproj index 525fc03..b0dcd9c 100644 --- a/SQCSim-srv/SQCSim-srv.vcxproj +++ b/SQCSim-srv/SQCSim-srv.vcxproj @@ -48,7 +48,7 @@ Application false - v143 + ClangCL true Unicode @@ -76,6 +76,7 @@ true WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + stdcpp20 Console @@ -90,7 +91,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true - Default + stdcpp20 Console @@ -105,6 +106,7 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + stdcpp20 Console @@ -119,6 +121,7 @@ true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + stdcpp20 Console diff --git a/SQCSim-srv/cmake/CMakeLists.txt b/SQCSim-srv/cmake/CMakeLists.txt index 4a1f624..ef8f3f2 100644 --- a/SQCSim-srv/cmake/CMakeLists.txt +++ b/SQCSim-srv/cmake/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.18.4) project(SQCSim-Server VERSION 0.1) add_compile_options("-Wno-narrowing") -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_STANDARD_REQUIRED True) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../out") diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp index 356396f..669ae8f 100644 --- a/SQCSim-srv/connection.cpp +++ b/SQCSim-srv/connection.cpp @@ -2,40 +2,38 @@ -Connection::Connection(SOCKET sock, - sockaddr_in sockaddr, - netprot::LoginInfo log, - netprot::PlayerInfo play): - m_sock(sock), - m_addr(sockaddr), - m_loginfo(log), - m_playinfo(play) { +Connection::Connection(SOCKET sock, + sockaddr_in sockaddr, + LoginInfo *log, + PlayerInfo *play) : + m_sock(sock), + m_addr(sockaddr), + m_loginfo(*log), + m_playinfo(*play) { } -Connection::~Connection() { - closesocket(m_sock); -} +Connection::~Connection() { + delete player; + closesocket(m_sock); } -uint64_t Connection::GetHash(bool self) const { return self? m_loginfo.sid: m_playinfo.id; } +uint64_t Connection::GetHash(bool self) const { return self ? m_loginfo.sid : m_playinfo.id; } uint64_t Connection::GetTeamHash() const { return m_loginfo.tid; } std::string Connection::GetName() const { return m_loginfo.name; } -void Connection::AddInput(netprot::Input in) { - m_input_manifest.insert({ in.timestamp, in }); -} +void Connection::AddInput(Input in) { m_input_manifest.insert({ in.timestamp, in }); m_input_vector.push_back(in); } -netprot::Output* Connection::getOutput(Timestamp time) { +Output* Connection::getOutput(Timestamp time) { auto out = m_output_manifest.find(time); if (out != m_output_manifest.end()) return &out->second; return nullptr; } -netprot::Sync Connection::getSync(Timestamp time) { - netprot::Sync sync; +Sync Connection::getSync(Timestamp time) { + Sync sync; auto out = m_output_manifest.find(time); if (out != m_output_manifest.end()) { sync.timestamp = out->second.timestamp; @@ -45,10 +43,166 @@ netprot::Sync Connection::getSync(Timestamp time) { return sync; } -void Connection::CleanInputManifest(Timestamp time) { - auto wat = m_input_manifest.find(time); +SOCKET Connection::getSock() const { return m_sock; } - while (wat != m_input_manifest.begin()) - m_input_manifest.erase(wat--); - +PlayerInfo* Connection::getInfo() const { return (PlayerInfo*)&m_playinfo; } + +sockaddr_in* Connection::getAddr() const { return (sockaddr_in*)&m_addr; } + +void Connection::getPacks(SOCKET sock) { + std::vector lsPck; + Input in; + Sync sync; + recvPacksFrom(sock, &m_buf, m_addr, &lsPck); + for (auto& pck : lsPck) { + uint32_t bsize = m_buf.len - (pck - m_buf.ptr); + switch (netprot::getType(pck, 1)) { + using enum netprot::PACKET_TYPE; + case INPUT: + if (Deserialize(&in, pck, &bsize)) { + m_input_manifest[in.timestamp] = in; + m_input_vector.push_back(in); + } + break; + case SYNC: + if (Deserialize(&sync, pck, &bsize)) + m_nsync = true; + break; + default: break; + } + } + lsPck.clear(); } + +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; + sendPackTo(sock, &out, &m_bufout, conn->getAddr()); + } + ++outs; + + [[unlikely]] if (last == 0) // ! + last = out.timestamp; + + outs += out.timestamp + last; + + if (outs >= 1000) { + outs -= 1000; + Sync sync; + sync.hp = player->GetHP(); + sync.timestamp = out.timestamp; + sync.position = out.position; + sync.sid = m_loginfo.sid; + sync.timer = timer; + sync.timestamp = out.timestamp; + sync.ammo = -1; + sendPackTo(sock, &sync, &m_bufout, &m_addr); + } + + m_output_vector.pop_front(); + } +} + +Timestamp Connection::Run(World* world) { + Input in, last; + Output out; + Timestamp tstamp = 0; + float el; + + 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); + + 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, + in.keys.backward, + in.keys.left, + in.keys.right, + in.keys.jump, false, el), world, el); + + if (player->GetPosition().y < -20.) { + player->InflictDamage(9000.); + player->Killer = GetHash(true); + } + + out.states.jumping = player->GetIsAirborne(); + out.states.running = player->GetVelocity().Length() > .5f; + out.states.still = !out.states.running && !out.states.jumping; + out.states.hit = player->m_hit; + player->m_hit = false; + + if (player->AmIDead()) { + in.keys.shoot = false; + in.keys.block = false; + out.states.dead = true; + } + + static bool toggle = false; + if (in.keys.block) { + if (!toggle) { + toggle = true; + bool block = false; + ChunkMod* cmod = world->ChangeBlockAtCursor(BLOCK_TYPE::BTYPE_METAL, + player->GetPosition(), + player->GetDirection(), + block, true); + if (cmod) + ChunkDiffs.push_back(std::move(cmod)); + } + } + else toggle = false; + + out.states.shooting = in.keys.shoot; + + if (out.states.jumping && out.states.shooting) + out.states.jumpshot = true; + 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)))); + m_shoot_acc = BULLET_TIME; + } + + out.position = player->GetPositionAbs(); + out.direction = in.direction; + out.timestamp = in.timestamp; + out.id = m_playinfo.id; + m_output_manifest[out.timestamp] = out; + m_output_vector.push_back(out); + tstamp = out.timestamp; + + ++m_last_in; + } + + return tstamp; +} + +void Connection::CleanInputManifest(Timestamp time) { + // auto wat = m_input_manifest.find(time); + + // while (wat != m_input_manifest.begin()) + // m_input_manifest.erase(wat--); +} + +Timestamp Connection::GetTStamp() const { return m_tstamp; } diff --git a/SQCSim-srv/connection.h b/SQCSim-srv/connection.h index 6dee988..3c5ac23 100644 --- a/SQCSim-srv/connection.h +++ b/SQCSim-srv/connection.h @@ -2,19 +2,22 @@ #define CONNECTION_H__ #include -#include +#include #include "../SQCSim-common/player.h" #include "../SQCSim-common/vector3.h" #include "../SQCSim-common/netprotocol.h" +#include "../SQCSim-common/world.h" #include "define.h" +using namespace netprot; + class Connection { public: Connection( SOCKET sock, sockaddr_in sockaddr, - netprot::LoginInfo log, - netprot::PlayerInfo play); + LoginInfo *log, + PlayerInfo *play); ~Connection(); Player* player = nullptr; @@ -23,20 +26,47 @@ public: uint64_t GetTeamHash() const; std::string GetName() const; - void AddInput(netprot::Input in); - netprot::Output* getOutput(Timestamp time); - netprot::Sync getSync(Timestamp time); + void AddInput(Input in); + Output* getOutput(Timestamp time); + Sync getSync(Timestamp time); + SOCKET getSock() const; + PlayerInfo* getInfo() const; + sockaddr_in* getAddr() const; + + void getPacks(SOCKET sock); + void sendPacks(SOCKET sock, std::unordered_map conns, const uint32_t timer); + + Timestamp Run(World* world); void CleanInputManifest(Timestamp time); + + bool m_nsync = true; + + std::vector Bullets; + std::vector ChunkDiffs; + + Timestamp GetTStamp() const; + private: - std::map m_input_manifest; - std::map m_output_manifest; - std::map m_chatlog; + std::unordered_map m_input_manifest; + std::vector m_input_vector; + std::unordered_map m_output_manifest; + std::deque m_output_vector; + std::unordered_map m_chatlog; + + float m_shoot_acc = 0; + Timestamp m_tstamp = 0; SOCKET m_sock; sockaddr_in m_addr; - netprot::LoginInfo m_loginfo; - netprot::PlayerInfo m_playinfo; + LoginInfo m_loginfo; + PlayerInfo m_playinfo; + Timestamp m_startsync; + + uint64_t m_last_in = 0, + m_last_out = 0; + Buffer m_buf, + m_bufout; }; -#endif \ No newline at end of file +#endif diff --git a/SQCSim-srv/define.h b/SQCSim-srv/define.h index 626a26a..a334446 100644 --- a/SQCSim-srv/define.h +++ b/SQCSim-srv/define.h @@ -9,9 +9,22 @@ #define MAX_CONNECTIONS 16 #define ID_LIST_SIZE 127 -#define BUFFER_LENGTH 150 +#define SRV_MANUAL_SETUP true -typedef unsigned char LogDest; -enum LOG_DEST { CONSOLE, LOGFILE, LOG_LAST }; +// @ = Dead guy, $ = Killer. +const std::vector DEATHMESSAGES = { "@ has gone to meet their maker.", + "@ has bit the dust, if you know what I mean.", + "@ has ceased to be.", + "@ is no more.", + "@ is like, super dead.", + "Requiescat In Pace, @.", + "So long, @, and thanks for all the lols!", + "@ has a bad case of being dead.", + "@ has finally seen the light!", + "Thought @ was hot; guess what? He's not. He is dead, dead, dead.", + "@ did not want to live forever.", + "$ made @ die for their country.", + "$ has become death, destroyer of @.", + "$ did not make @ feel lucky." }; #endif diff --git a/SQCSim-srv/main.cpp b/SQCSim-srv/main.cpp index a1e104d..74c28e1 100644 --- a/SQCSim-srv/main.cpp +++ b/SQCSim-srv/main.cpp @@ -1,9 +1,13 @@ #include "server.h" int main() { - Server* server = new Server(); + std::unique_ptr server = std::make_unique(); if (server->Init() == 0) - if (server->Ready() == 0) + while (server->Ready() == 0) { server->Run(); - delete server; + if (!server->NewGameRequested()) + break; + server->Cleanup(); + } + server->DeInit(); } \ No newline at end of file diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index cbda844..edf740c 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -1,6 +1,6 @@ #include "server.h" -Server::Server(LogDest log) { +Server::Server(LOG_DEST log) { m_log = log; if (log == LOG_DEST::LOGFILE) { m_logfile = std::ofstream("server.log", std::ofstream::out); @@ -18,6 +18,10 @@ Server::~Server() { closesocket(m_sock_udp); if (m_sock_tcp) closesocket(m_sock_tcp); + for (const auto& [key, player] : m_conns) + closesocket(player->getSock()); + m_conns.clear(); + delete m_world; #ifdef _WIN32 WSACleanup(); #endif @@ -65,85 +69,354 @@ int Server::Init() { } int Server::Ready() { + int nbrjoueurs = 0, + nbrconn = 0; + bool readystart = false; + do { + Log("Entrez la duree de la partie: ", false, false); + std::cin.getline(m_buf.ptr, BUFFER_LENGTH); + try { + m_game.countdown = std::stoi(m_buf.ptr); + } + catch (const std::exception& e) { + Log(e.what(), true, false); + m_game.countdown = 0; + } + } while (m_game.countdown < 1); + m_game.seed = 9370707; + /*do { + Log("Entrez le seed de la partie: ", false, false); + std::cin.getline(m_buf.ptr, BUFFER_LENGTH); + try { + std::stoi(m_buf.ptr); + } + catch (const std::exception& e) { + Log(e.what(), true, false); + m_game.seed = 0; + } + } while (m_game.seed < 1);*/ + do { + Log("Entrez le nombre de joueurs: ", false, false); + std::cin.getline(m_buf.ptr, BUFFER_LENGTH); + try { + nbrjoueurs = std::stoi(m_buf.ptr); + } + catch (const std::exception& e) { + Log(e.what(), true, false); + nbrjoueurs = 0; + } + if (nbrjoueurs <= 0 || nbrjoueurs > MAX_CONNECTIONS) + Log("Nombre de joueurs invalide.", true, false); + } while (nbrjoueurs <= 0 || nbrjoueurs > MAX_CONNECTIONS); + + m_game.gameType = 1; + if (listen(m_sock_tcp, MAX_CONNECTIONS) < 0) { - Log("Écoute sur le port TCP.", true, true); + Log("Ecoute sur le port TCP.", true, true); return 1; } - char* buf = new char[150]; - uint32_t buflen = 150; - bool readystart = false; - srand(time(NULL)); - - Log("À l'écoute sur le port: " + std::to_string(SRV_PORT), false, false); - buildIdList(ID_LIST_SIZE); - m_game.countdown = 360; - m_game.gameType = 1; - m_game.seed = 9370707; + Log("A l'ecoute sur le port: " + std::to_string(SRV_PORT), false, false); while (!readystart) { sockaddr_in sockad; - unsigned int addrlen = sizeof(sockad); + addrlen_t addrlen = sizeof(sockad); SOCKET sock = accept(m_sock_tcp, (sockaddr*)&sockad, &addrlen); if (sock < 0) Log("Erreur de connexion", true, false); else if (sock > 0) { - std::string str = "Nouvelle connection provenant de: "; - char* strbuf = new char[BUFFER_LENGTH]; - uint32_t strbuflen = BUFFER_LENGTH; + std::string str = "Nouvelle connexion provenant de: "; + str.append(inet_ntop(AF_INET, &sockad.sin_addr, m_buf.ptr, m_buf.len)).append(": ").append(std::to_string(sockad.sin_port)); - str.append(inet_ntop(AF_INET, &sockad.sin_addr, strbuf, strbuflen)).append(": ").append(std::to_string(sockad.sin_port)); + if (recv(sock, m_buf.ptr, m_buf.len, 0) > 0) { + PlayerInfo* play = new PlayerInfo(); - if (recv(sock, buf, buflen, 0) > 0) { - netprot::LoginInfo log; - netprot::PlayerInfo play; - if (netprot::Deserialize(&log, buf, buflen)) { - log.sid = getUniqueId(); - - log.tid = 0; - - str.append(" Nom: ").append(log.name); - Log(str, false, false); - str = ""; - - str.append(log.name).append(" SID: [").append(std::to_string(log.sid).append("]")); - Log(str, false, false); - - //netprot::Serialize(&log, &buf, &buflen); - //send(sock, buf, buflen, 0); - //buflen = 150; - sendPack(sock, &log, &buf, &buflen); - - play.id = getUniqueId(); - memcpy(play.name, log.name, std::strlen(log.name) + 1); - play.tid = log.tid; - - //netprot::Serialize(&m_game, &buf, &buflen); - //send(sock, buf, buflen, 0); - sendPack(sock, &m_game, &buf, &buflen); - Connection* conn = new Connection(sock, sockad, log, play); - - m_players[log.sid] = conn; - readystart = true; + m_buf.len = BUFFER_LENGTH; + Packet pck = getPack(&m_buf); + if (pck.type != PACKET_TYPE::LOGINF) { + Log("Paquet invalide.", true, false); + if (pck.type != PACKET_TYPE::ERR) + netprot::emptyPack(pck); + continue; // Passer au prochain appel si c'est pas un LoginInfo ou un LoginInfo invalide qui rentre. } + LoginInfo* log = (LoginInfo*)pck.ptr; + + log->sid = getUniqueId(); + log->tid = 1145389380; // TODO: À changer si on implemente un mode en equipe. + + Log(str.append(" Nom: ").append(log->name), false, false); + str.clear(); + + + sendPackTo(m_sock_udp, log, &m_buf, &sockad); + + play->id = getUniqueId(); + play->tid = log->tid; + strcpy(play->name, 32, log->name); + + Log(str.append(play->name).append(" SID: [").append(std::to_string(log->sid)).append("]") + .append(" ID: [").append(std::to_string(play->id)).append("]") + .append(" TID: [").append(std::to_string(play->tid)).append("]"), false, false); + play->tid = log->tid; + + sendPackTo(m_sock_udp, &m_game, &m_buf, &sockad); + Connection* conn = new Connection(sock, sockad, log, play); + + m_conns[log->sid] = conn; + + if (++nbrconn >= nbrjoueurs) + readystart = true; } } } + for (auto& [keyin, playin] : m_conns) // Not pretty, but it works. + for (auto& [keyout, playout] : m_conns) { + if (keyin == keyout) + continue; + sendPackTo(m_sock_udp, playout->getInfo(), &m_buf, playin->getAddr()); // et envoyer les infos des joueurs distants au nouveau joueur. + } + return 0; } void Server::Run() { + bool endgame = false; + Input in; + sockaddr_in sockad; + addrlen_t socklen = sizeof(sockad); - Log("Partie en cours...", false, false); + Log("Debut de la partie...", false, false); + + int players = m_conns.size(); + + m_world = new World(); + m_world->SetSeed(m_game.seed); + m_world->GetChunks().Reset(nullptr); + m_world->BuildWorld(); + + for (auto& [key, conn] : m_conns) { // Creation des instances de joueurs et premier sync. + if (!conn) { + 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; + 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; + Sync sync; + sync.position = conn->player->GetPositionAbs(); + sync.hp = conn->player->GetHP(); + sync.sid = key; + sync.ammo = 0; + sync.timestamp = 0; + sync.timer = m_game.countdown; + sendPackTo(m_sock_udp, &sync, &m_buf, conn->getAddr()); + } + + int timer = m_game.countdown, sync_acc = 0, deadplayers = 0; + std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now(); + Timestamp last = 0; + std::vector chatlog; + std::vector chunkdiffs; + std::vector bullets; + std::vector::iterator> bullit; + std::vector netbull; + std::vector lsPck; + + Chat* startchat = new Chat(); + startchat->src_id = 0; + char startmess[] = "How would -YOU- like to die today, motherf-words?"; + + strcpy(startchat->mess, 140, startmess); + + chatlog.emplace_back(startchat); + + while (!endgame) { + using namespace std::chrono; + Timestamp tstamp = duration_cast(high_resolution_clock::now() - start).count(); + + if (last == 0) + last = tstamp; + sync_acc += tstamp - last; + if (sync_acc >= 1000) { + while (sync_acc >= 1000) + sync_acc -= 1000; + --timer; + std::string str = "Timer: "; + Log(str.append(std::to_string(timer)), false, false); + } + last = tstamp; + + + for (auto& [key, conn] : m_conns) { + + /* In */ + + Input in; Sync sync; + + recvPacks(m_sock_udp, &m_buf, &lsPck); + for (auto& pck : lsPck) { + uint32_t bsize = m_buf.len - (pck - m_buf.ptr); + switch (netprot::getType(pck, 1)) { + using enum netprot::PACKET_TYPE; + case INPUT: + if (Deserialize(&in, pck, &bsize)) { + if (m_conns.count(in.sid)) + m_conns[in.sid]->AddInput(in); + } + break; + case SYNC: + if (Deserialize(&sync, pck, &bsize)) {} + break; + default: break; + } + } + lsPck.clear(); + + /* Process */ + + if (conn->m_nsync) { + 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; + + std::string killer = m_conns.at(conn->player->Killer)->player->GetUsername(); + + std::string mess = getDeathMessage(conn->player->GetUsername(), killer); + + strcpy(chat->mess, 140, mess.c_str()); + chatlog.emplace_back(chat); + ++deadplayers; + conn->m_nsync = false; + } + else { + for (auto& chmo : conn->ChunkDiffs) + chunkdiffs.emplace_back(std::move(chmo)); + conn->ChunkDiffs.clear(); + + 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(); + nbul->id = key; + nbul->tstamp = tstamp; + + netbull.emplace_back(std::move(nbul)); + } + conn->Bullets.clear(); + } + + /* Out */ + + conn->sendPacks(m_sock_udp, m_conns, timer); + } + if ((deadplayers == players - 1 && deadplayers != 0) || timer <= 0) + endgame = true; + } + + for (auto& bull : netbull) { + for (auto& [key, conn] : m_conns) + if (bull->id != conn->GetHash(false)) // Pour pas repitcher au joueur sa propre balle. + sendPackTo(m_sock_udp, bull, &m_buf, conn->getAddr()); + delete bull; + } + netbull.clear(); + + 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 (cmod) + chunkdiffs.emplace_back(cmod); + bullit.push_back(bull); + delete bullet; + } + } + for (auto& bull: bullit) + bullets.erase(bull); + bullit.clear(); + + for (auto& chat : chatlog) { + Log(chat->mess, false, false); + for (auto& [key, conn] : m_conns) + sendPackTo(m_sock_udp, chat, &m_buf, conn->getAddr()); + delete chat; + } + 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(); + } + + Chat end; + end.src_id = 0; + char endmess[] = "Game over, man. Game over."; + strcpy(end.mess, 140, endmess); + + for (auto& [key, conn] : m_conns) { + std::string str = conn->player->GetUsername(); + Log(str.append(" ").append(std::to_string(conn->player->GetHP())), false, false); + + } + + for (auto& [key, conn] : m_conns) + sendPackTo(m_sock_udp, &end, &m_buf, conn->getAddr()); + + // TODO: Gérer les 2-3 secondes post-game avant le billboard pour pas avoir un whiplash à la fin de la game. + + char* ch = new char[2]; + std::cout << "Nouvelle partie? [o/N] "; + std::cin.getline(ch, 2); + std::cout << std::endl; + + m_exit = true; + if (ch[0] == 'o' || ch[0] == 'O') + m_exit = false; + + delete[] ch; } +void Server::Cleanup() { + for (auto& [key, conn] : m_conns) + delete conn; + + m_conns.clear(); + m_players.clear(); + delete m_world; + m_world = nullptr; +} + +void Server::DeInit() { + if (m_logfile.is_open()) + m_logfile.close(); + if (m_sock_udp) + closesocket(m_sock_udp); + if (m_sock_tcp) + closesocket(m_sock_tcp); + +#ifdef _WIN32 + WSACleanup(); +#endif +} + +bool Server::NewGameRequested() const { return !m_exit; } + inline std::string Server::LogTimestamp() { time_t rawtime; - struct tm timeinfo; - char buffer[80]; + tm timeinfo; + char buffer[50]; time(&rawtime); @@ -161,32 +434,42 @@ inline std::string Server::LogTimestamp() { void Server::Log(std::string str, bool is_error = false, bool is_fatal = false) { switch (m_log) { - case LOG_DEST::LOGFILE: + using enum LOG_DEST; // C++20! + case LOGFILE: m_logfile << LogTimestamp() << (is_fatal ? "FATAL " : "") << (is_error ? "ERROR " : "") << str << std::endl; break; - case LOG_DEST::CONSOLE: + case CONSOLE: [[fallthrough]]; // Pour dire que c'est voulu que ça traverse vers le case en dessous (C++17!) default: std::cout << LogTimestamp() << (is_fatal ? "FATAL " : "") << (is_error ? "ERROR " : "") << str << std::endl; break; } if (is_fatal) { + if (m_logfile.is_open()) + m_logfile.close(); if (m_sock_udp) closesocket(m_sock_udp); if (m_sock_tcp) closesocket(m_sock_tcp); + for (const auto& [key, player] : m_conns) + closesocket(player->getSock()); + + delete m_world; + m_conns.clear(); #ifdef _WIN32 WSACleanup(); #endif + exit(-1); } } void Server::buildIdList(size_t size) { std::set lst; - do lst.insert(((uint64_t)rand() << 25) % 8675309); // EIGHT SIX SEVENFIVE THREE AUGHT NIIIIIIiIIiiIiINE! + srand(time(NULL)); + do lst.insert(((uint64_t)rand() << 32 | rand())); while (lst.size() < size); - + m_ids = std::vector(lst.begin(), lst.end()); } @@ -196,132 +479,33 @@ uint64_t Server::getUniqueId() { return id; } -// Test serialize/deserialize: -/* - netprot::LoginInfo log, log2; - std::cout << "Nom? "; - std::cin.getline(log.name, 32); // NO! STD::CIN >> VARIABLE;! EVEEEEEERRRR!!! - log.sid = 12345; - char* buf = new char[150]; - uint32_t buflen = 150; +std::string Server::getDeathMessage(std::string username, std::string killer) const { + std::string mess; + std::string temp = DEATHMESSAGES.at(rand() % DEATHMESSAGES.size()); + size_t ind = temp.find('@'); + size_t indk = temp.find('$'); + bool bypass = false; - netprot::Serialize(&log, &buf, &buflen); + if (indk == std::string::npos) + bypass = true; - bool is_work = netprot::Deserialize(&log2, buf, buflen); + if (ind < indk || bypass) { + mess.append(temp.substr(0, ind)); + mess.append(username); + if (!bypass) { + mess.append(temp.substr(ind + 1, indk - 1)); + mess.append(killer); + mess.append(temp.substr(indk + 1)); + } + else mess.append(temp.substr(ind + 1)); + } + else { + mess.append(temp.substr(0, indk)); + mess.append(killer); + mess.append(temp.substr(indk + 1, ind - 1)); + mess.append(username); + mess.append(temp.substr(ind + 1)); + } - std::string str; - str.append(is_work ? "Y " : "N ").append(log2.name).append(": ").append(std::to_string(log2.sid)); - - Log(str, false, false); -*/ - - -///* Recevoir paquet */ -//while (true) { -// char buffer[2048]; -// sockaddr_in client; -// -//#ifdef _WIN32 // Mais pourquoi? -// int clen = sizeof(client); -//#else -// unsigned int clen = sizeof(client); -//#endif -// -// int count = recvfrom(socket_udp, buffer, sizeof(buffer) - 1, 0, (sockaddr*)&client, &clen); -// -// if (count < 0) { -// Log("Erreur de reception de paquet.", socket_udp); -// return 4; -// } -// -// buffer[count] = '\0'; -// -// /* Gérer le paquet reçu */ -// std::string commande(buffer); -// -// if (commande.find("echo ") == 0) { /* ECHO */ -// std::string::size_type pos = commande.find(' '); -// std::string parametres = commande.substr(pos + 1); -// -// sendto(socket_udp, parametres.c_str(), parametres.length(), 0, (const sockaddr*)&client, sizeof(client)); -// } -// else if (commande.find("date ") == 0) { /* DATE */ -// time_t rawtime; -// struct tm* timeinfo = new tm(); -// char tbuffer[80]; -// -// time(&rawtime); -// -//#ifdef _WIN32 -// localtime_s(timeinfo, &rawtime); -//#else -// localtime_r(&rawtime, timeinfo); -//#endif -// -// strftime(tbuffer, 80, "%a %b %e %T %G", timeinfo); -// -// sendto(socket_udp, tbuffer, sizeof(tbuffer), 0, (const sockaddr*)&client, sizeof(client)); -// delete timeinfo; -// } -// else if (commande.find("ping ") == 0) { /* PING */ -// sendto(socket_udp, "pong", sizeof("pong"), 0, (const sockaddr*)&client, sizeof(client)); -// } -// else if (commande.find("usager ") == 0) { /* USAGER */ -// std::string user; -// -//#ifdef _WIN32 -// wchar_t userbuf[30]; -// DWORD usersize = 30; -// -// GetUserNameW(userbuf, &usersize); -// -// std::wstring wuser = userbuf; -// user = std::string(wuser.begin(), wuser.end()); -//#else -// char ptr[30]; -// getlogin_r(ptr, sizeof(ptr) - 1); -// user = std::string(ptr); -//#endif -// -// sendto(socket_udp, user.c_str(), user.length(), 0, (const sockaddr*)&client, sizeof(client)); -// } -// else if (commande.find("exec ") == 0) { /* EXEC */ -// std::string::size_type pos = commande.find(' '); -// std::string parametres = commande.substr(pos + 1); -// -// FILE* pipe = nullptr; -// char buffer[301]; // 300 caractères + '\0' -// std::string reponse; -// -// pipe = popen(parametres.c_str(), "r"); -// -// if (!pipe) -// reponse = "Erreur de commande!"; -// else while (!feof(pipe)) { -// if (fgets(buffer, sizeof(buffer) - 1, pipe)) -// reponse += buffer; -// } -// -// if (pipe) -// pclose(pipe); -// -// if (reponse.length() > 300) -// reponse = reponse.substr(0, 300); -// else if (reponse.length() < 1) -// reponse = "OK!"; -// -// sendto(socket_udp, reponse.c_str(), reponse.length(), 0, (const sockaddr*)&client, sizeof(client)); -// } -// else if (commande.find("bye ") == 0) { /* BYE */ -// Log("", 0); // Message d'erreur pas de message d'erreur! -// return 0; -// } -// else sendto(socket_udp, "huh?", sizeof("huh?"), 0, (const sockaddr*)&client, sizeof(client)); /* DEFAULT */ -//} -// -///* Ce bout de code ne devrait theoriquement jamais etre atteint, mais au cas. */ -//Log("", 0); -//return 0; -//return false; -//} -// + return mess; +} diff --git a/SQCSim-srv/server.h b/SQCSim-srv/server.h index 6c77038..c70a457 100644 --- a/SQCSim-srv/server.h +++ b/SQCSim-srv/server.h @@ -1,54 +1,61 @@ #ifndef SERVER_H__ #define SERVER_H__ +#include #include #include #include #include +#include #include "../SQCSim-common/world.h" #include "../SQCSim-common/netprotocol.h" #include "define.h" #include "connection.h" +using namespace netprot; + class Server { public: - Server(LogDest log = LOG_DEST::CONSOLE); + enum LOG_DEST: unsigned char { CONSOLE, LOGFILE, LOG_LAST }; + + Server(LOG_DEST log = LOG_DEST::CONSOLE); ~Server(); int Init(); int Ready(); void Run(); + void Cleanup(); + void DeInit(); + bool NewGameRequested() const; private: + #ifdef _WIN32 WSADATA m_wsaData; #endif SOCKET m_sock_udp = 0, m_sock_tcp = 0; - LogDest m_log; + LOG_DEST m_log; std::ofstream m_logfile; - std::map m_players; - std::map m_chatlog; + Buffer m_buf; + + std::unordered_map m_players; + std::unordered_map m_conns; + std::unordered_map m_chatlog; std::vector m_ids; - netprot::GameInfo m_game; + GameInfo m_game; World* m_world = nullptr; + bool m_exit = true; std::string LogTimestamp(); void Log(std::string str, bool is_error, bool is_fatal); void buildIdList(size_t size); - uint64_t getUniqueId(); - template void sendPack(SOCKET sock, T* pack, char** buf, uint32_t* buflen); + uint64_t getUniqueId(); + std::string getDeathMessage(std::string username, std::string killer) const; }; -template -void Server::sendPack(SOCKET sock, T* pack, char** buf, uint32_t* buflen) { - netprot::Serialize(pack, buf, buflen); - send(sock, *buf, *buflen, 0); - *buflen = BUFFER_LENGTH; -} - #endif diff --git a/SQCSim2021/SQCSim2021.vcxproj b/SQCSim2021/SQCSim2021.vcxproj index d120d7b..cda35f7 100644 --- a/SQCSim2021/SQCSim2021.vcxproj +++ b/SQCSim2021/SQCSim2021.vcxproj @@ -20,33 +20,39 @@ + + + - + + + + - + @@ -85,7 +91,7 @@ false true Unicode - v143 + ClangCL @@ -130,7 +136,7 @@ Level3 Disabled WIN32;_DEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions) - stdcpp17 + stdcpp20 Console @@ -145,7 +151,7 @@ Level3 Disabled WIN32;_DEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions) - stdcpp17 + stdcpp20 Console @@ -162,13 +168,13 @@ true true WIN32;NDEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions) - stdcpp17 + stdcpp20 AnySuitable Speed Fast - Windows + Console false true true @@ -184,13 +190,13 @@ true true WIN32;NDEBUG;_CONSOLE;NOMINMAX;%(PreprocessorDefinitions) - stdcpp17 + stdcpp20 AnySuitable Speed Fast - Windows + Console false true true diff --git a/SQCSim2021/SQCSim2021.vcxproj.filters b/SQCSim2021/SQCSim2021.vcxproj.filters index 3bf0928..417ba37 100644 --- a/SQCSim2021/SQCSim2021.vcxproj.filters +++ b/SQCSim2021/SQCSim2021.vcxproj.filters @@ -47,7 +47,16 @@ Fichiers d%27en-tête - + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + Fichiers d%27en-tête @@ -88,7 +97,16 @@ Fichiers sources - + + Fichiers sources + + + Fichiers sources + + + Fichiers sources + + Fichiers sources diff --git a/SQCSim2021/audio.cpp b/SQCSim2021/audio.cpp index e849c6f..fda7368 100644 --- a/SQCSim2021/audio.cpp +++ b/SQCSim2021/audio.cpp @@ -14,7 +14,7 @@ Audio::Audio(const char * music) { m_engine->setRolloffFactor(2); m_engine->setDefault3DSoundMinDistance(.1); m_engine->setDefault3DSoundMaxDistance(1000); - m_music = m_engine->play2D(music, false, true, true, irrklang::ESM_STREAMING); + m_music = m_engine->play2D(music, true, true, true, irrklang::ESM_STREAMING); } Audio::~Audio() { @@ -48,3 +48,7 @@ void Audio::Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& v void Audio::ToggleMusicState() { m_music->setIsPaused(!m_music->getIsPaused()); } void Audio::PauseEngine() { m_engine->setAllSoundsPaused(); } + +float Audio::GetMusicVolume() const { + return m_music->getVolume(); +} diff --git a/SQCSim2021/audio.h b/SQCSim2021/audio.h index 775f316..f19682a 100644 --- a/SQCSim2021/audio.h +++ b/SQCSim2021/audio.h @@ -33,6 +33,8 @@ public: void ToggleMusicState(); void PauseEngine(); + + float GetMusicVolume() const; }; #endif // AUDIO_H__ diff --git a/SQCSim2021/booster.cpp b/SQCSim2021/booster.cpp new file mode 100644 index 0000000..4e7417f --- /dev/null +++ b/SQCSim2021/booster.cpp @@ -0,0 +1,46 @@ +#include "booster.h" + +void Booster::RenderBillboard(const Vector3f pos, TextureAtlas& textureAtlas, Shader& shader, Transformation tran) +{ + // + //Vector3f playerToQuad = m_player.GetPosition() - m_position; + //playerToQuad.Normalize(); + //Vector3f targetPosition = m_player.GetPosition() + playerToQuad * 10.0f; + //Matrix4f rotationMatrix; + //rotationMatrix.SetLookAt(m_position, targetPosition, Vector3f(0, 1, 0)); + //glMultMatrixf(rotationMatrix.GetInternalValues()); + float x = pos.x; + float y = pos.y; + float z = pos.z; + float width = 1.0f; + float height = 1.0f; + //Pt override les collisions.. a ce point la je sais pas quoi faire + + //Matrix4 mat4 = tran.GetMatrix(); + //mat4 VP = pMatrix * vMatrix; + //Vector3f CameraRight = Vector3f(mat4.Get11(), mat4.Get21(), mat4.Get31()); + //Vector3f CameraUp = Vector3f(mat4.Get12(), mat4.Get22(), mat4.Get32()); + + //Vector3f v1 = (m_position + CameraRight * 0.5 * width + CameraUp * -0.5 * width); + //Vector3f v2 = (m_position + CameraRight * 0.5 * width + CameraUp * 0.5 * width); + //Vector3f v4 = (m_position + CameraRight * -0.5 * width + CameraUp * -0.5 * width); + //Vector3f v3 = (m_position + CameraRight * -0.5 * width + CameraUp * 0.5 * width); + + //tran.ApplyTranslation(m_position); + float u, v, w, h; + //glDisable(GL_DEPTH_TEST); + shader.Use(); + textureAtlas.Bind(); + textureAtlas.TextureIndexToCoord(8, u, v, w, h); + //glLoadIdentity(); + glLoadMatrixf(tran.GetMatrix().GetInternalValues()); + glBegin(GL_QUADS); + glTexCoord2f(u, v); glVertex3f(x - width / 2., y - height, z); //glVertex3f(v4.x, v4.y, v4.z);//glVertex3f(0, 50, 0); + glTexCoord2f(u + w, v); glVertex3f(x + width / 2., y - height, z); //glVertex3f(v3.x, v3.y, v3.z); //glVertex3f(50,50, 0); + glTexCoord2f(u + w, v + h); glVertex3f(x + width / 2., y, z); //glVertex3f(v2.x, v2.y, v2.z); //glVertex3f(50, 0, 0); + glTexCoord2f(u, v + h); glVertex3f(x - width / 2., y, z); //glVertex3f(v1.x, v1.y, v1.z);// glVertex3f(0, 0, 0); + glEnd(); + shader.Disable(); + //tran.ApplyTranslation(-m_position); + //glEnable(GL_DEPTH_TEST); +} diff --git a/SQCSim2021/booster.h b/SQCSim2021/booster.h new file mode 100644 index 0000000..e06f2b4 --- /dev/null +++ b/SQCSim2021/booster.h @@ -0,0 +1,14 @@ +#ifndef BOOSTER_H__ +#define BOOSTER_H__ +#include "define.h" +#include "textureatlas.h" +#include "shader.h" +#include "../SQCSim-common/vector3.h" +#include "../SQCSim-common/transformation.h" + + +class Booster { +public: + void RenderBillboard(const Vector3f pos, TextureAtlas& textureAtlas, Shader& shader, Transformation tran); +}; +#endif diff --git a/SQCSim2021/cmake/CMakeLists.txt b/SQCSim2021/cmake/CMakeLists.txt index fbe850f..d9ccd33 100644 --- a/SQCSim2021/cmake/CMakeLists.txt +++ b/SQCSim2021/cmake/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.18.4) project(SQCSim-Client VERSION 0.8) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_STANDARD_REQUIRED True) set(CMAKE_BUILD_DIRECTORY "./build") @@ -28,6 +28,7 @@ include_directories( add_library(SQCSim-common + "${SQCSIM_COMMON_DIR}boostinfo.cpp" "${SQCSIM_COMMON_DIR}blockinfo.cpp" "${SQCSIM_COMMON_DIR}bullet.cpp" "${SQCSIM_COMMON_DIR}chunk.cpp" @@ -40,6 +41,7 @@ add_library(SQCSim-common add_executable(SQCSim-client "../audio.cpp" + "../booster.cpp" "../connector.cpp" "../engine.cpp" "../mesh.cpp" @@ -50,7 +52,8 @@ add_executable(SQCSim-client "../textureatlas.cpp" "../tool.cpp" "../vertexbuffer.cpp" - "../worldrenderer.cpp" + "../renderer.cpp" + "../remoteplayer.cpp" "../main.cpp" ) diff --git a/SQCSim2021/connector.cpp b/SQCSim2021/connector.cpp index 31e1b81..bcde34e 100644 --- a/SQCSim2021/connector.cpp +++ b/SQCSim2021/connector.cpp @@ -42,7 +42,7 @@ int Connector::Init() { return 0; } -int Connector::Connect(char* srv_addr, std::string name) { +int Connector::Connect(const char* srv_addr, std::string name) { sockaddr_in add; m_srvsockaddr.sin_family = AF_INET; m_srvsockaddr.sin_port = htons(SRV_PORT); @@ -54,44 +54,65 @@ int Connector::Connect(char* srv_addr, std::string name) { if (connect(m_sock_tcp, (sockaddr*)&m_srvsockaddr, sizeof(m_srvsockaddr)) < 0) { std::cout << "Échec de la connexion." << std::endl; + return 2; } - char* buf = new char[150]; - uint32_t buflen = 150; + flag_t flag = 1; + if (ioctl(m_sock_tcp, SOCK_NONBLOCK, &flag) < 0) { + std::cout << "Impossible de mettre le socket en mode non-bloquant." << std::endl; + return 3; + } + + netprot::Buffer bf; netprot::LoginInfo log; - memcpy(&log.name, name.c_str(), name.size() + 1); + strcpy(log.name, 32, name.c_str()); - netprot::Serialize(&log, &buf, &buflen); + netprot::sendPack(m_sock_tcp, &log, &bf); - int se = send(m_sock_tcp, buf, buflen, 0); + bool ready = false; + int errors = 0; + std::vector lsPck; + while (!ready) { + netprot::recvPacks(m_sock_udp, &bf, &lsPck); - delete[] buf; - buf = new char[150] {0}; - buflen = 150; - int rpack = 0; - - while (rpack < 2) { - recv(m_sock_tcp, buf, buflen, 0); - - switch (netprot::getType(buf, buflen)) { - case netprot::PACKET_TYPE::LOGINF: - if (!netprot::Deserialize(&m_loginfo, buf, buflen)) { - std::cout << "Packet LoginInfo invalide." << std::endl; - return 2; + for (auto& pck : lsPck) { + uint32_t bsize = bf.len - (pck - bf.ptr); + netprot::PlayerInfo* pl = nullptr; + switch (netprot::getType(pck, 1)) { + using enum netprot::PACKET_TYPE; + case LOGINF: + if (!netprot::Deserialize(&m_loginfo, pck, &bsize)) + ++errors; + break; + case GAMEINFO: + if (!netprot::Deserialize(&m_gameinfo, pck, &bsize)) + ++errors; + break; + case PLAYINF: + pl = new netprot::PlayerInfo(); + if (!netprot::Deserialize(pl, pck, &bsize)) + ++errors; + else { + m_players[pl->id] = pl; + std::cout << "A challenger appears! " << pl->name << std::endl; + } + break; + case TEAMINF: + // TODO: Faire dequoi avec TeamInfo si on fini par avoir des teams. + break; + case SYNC: + if (!netprot::Deserialize(&m_origin, pck, &bsize)) + ++errors; + ready = true; + break; + default: + errors++; + break; } - ++rpack; - break; - case netprot::PACKET_TYPE::GAMEINFO: - if (!netprot::Deserialize(&m_gameinfo, buf, buflen)) { - std::cout << "Packet GameInfo invalide." << std::endl; - return 3; - } - ++rpack; - break; - default: - std::cout << "Packet invalide." << std::endl; - break; } + lsPck.clear(); + if (errors > 1000) + return 4; } return 0; } @@ -99,3 +120,5 @@ int Connector::Connect(char* srv_addr, std::string name) { uint64_t Connector::getId() const { return m_loginfo.sid; } unsigned int Connector::getSeed() const { return m_gameinfo.seed; } + +netprot::Sync Connector::getOrigin() const { return m_origin; } diff --git a/SQCSim2021/connector.h b/SQCSim2021/connector.h index 297be6f..c5361ac 100644 --- a/SQCSim2021/connector.h +++ b/SQCSim2021/connector.h @@ -2,6 +2,7 @@ #define CONNECTOR_H__ #include +#include #include "../SQCSim-common/netprotocol.h" #include "define.h" @@ -11,26 +12,32 @@ public: ~Connector(); int Init(); - int Connect(char* srv_addr, std::string name); + int Connect(const char* srv_addr, std::string name); uint64_t getId() const; unsigned int getSeed() const; + netprot::Sync getOrigin() const; + //void SendInput(); //int Sync(); + + SOCKET m_sock_udp = 0, + m_sock_tcp = 0; + sockaddr_in m_srvsockaddr; + + // void updateRemotePlayers(std::map rplayers); + + std::unordered_map m_players; private: #ifdef _WIN32 WSADATA m_wsaData; #endif - std::map m_inputmanifest; - std::map m_players; - std::map m_teams; + std::unordered_map m_inputmanifest; + std::unordered_map m_teams; netprot::LoginInfo m_loginfo; netprot::GameInfo m_gameinfo; - - sockaddr_in m_srvsockaddr; - SOCKET m_sock_udp = 0, - m_sock_tcp = 0; + netprot::Sync m_origin; }; #endif diff --git a/SQCSim2021/define.h b/SQCSim2021/define.h index 67c49c3..e457c33 100644 --- a/SQCSim2021/define.h +++ b/SQCSim2021/define.h @@ -20,7 +20,6 @@ #include #endif -#define NETWORK_TEST false #define SRV_ADDR "127.0.0.1" #define COUNTDOWN 300 @@ -30,10 +29,37 @@ #define BASE_HEIGHT 480 +#define ANIME_PATH_JUMP "./media/textures/AssetOtherPlayer/FinalPNGJumping/" +#define ANIME_PATH_STILL "./media/textures/AssetOtherPlayer/FinalPNGStanding/" + +//1 = jump shoot sans anim, 2 = jump shoot avec anim +#define ANIM_PATH_JSHOOT1 "./media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/" +#define ANIM_PATH_JSHOOT2 "./media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/" +//1 = shoot sans anim, 2 = shoot avec anim +#define ANIM_PATH_SSHOOT1 "./media/textures/AssetOtherPlayer/FinalPNGShooting/" +#define ANIM_PATH_SSHOOT2 "./media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/" + #define TEXTURE_PATH "./media/textures/" #define SHADER_PATH "./media/shaders/" #define AUDIO_PATH "./media/audio/" #define CHUNK_PATH "./media/chunks/" -#define MENU_ITEM_PATH "./media/menu_items/" +#define BOOSTER_TEXTURE_PATH "./media/textures/Booster/" + +enum GameState { + MAIN_MENU, + SPLASH, + LOBBY, + OPTIONS, + QUIT, + PLAY, + PAUSE +}; + +enum Resolution { + HD = 0, // 1280x720 (High Definition) + FHD, // 1920x1080 (Full HD) + QHD, // 2560x1440 (Quad HD) + UHD // 3840x2160 (Ultra HD) +}; #endif // DEFINE_H__ diff --git a/SQCSim2021/docs/doc_dev.docx b/SQCSim2021/docs/doc_dev.docx new file mode 100644 index 0000000..341b68a Binary files /dev/null and b/SQCSim2021/docs/doc_dev.docx differ diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 0a91a89..bf78ee5 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -1,5 +1,7 @@ #include "engine.h" - +#include +#include +#include #include #include #include @@ -26,253 +28,29 @@ Engine::~Engine() { m_world.GetChunks().Get(x, y)->~Chunk(); } -void Engine::DrawSplachScreen() -{ - glDisable(GL_LIGHTING); - glDisable(GL_DEPTH_TEST); - glDisable(GL_STENCIL_TEST); - - // Définir la matrice de projection en mode orthographique - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glOrtho(-Width() / 2, Width() / 2, -Height() / 2, Height() / 2, -1, 1); - - // Définir la matrice de modèle-vue - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - - // L'image sera centrée autour de l'origine (0, 0, 0) - int imageWidth = Width(); // Remplacez par la largeur de votre image - int imageHeight = Height(); // Remplacez par la hauteur de votre image - - // Texture - SplachScreenTexture.Bind(); - - // Dessiner un quadrilatère centré - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(-imageWidth / 2, -imageHeight / 2); - glTexCoord2f(1, 0); - glVertex2i(imageWidth / 2, -imageHeight / 2); - glTexCoord2f(1, 1); - glVertex2i(imageWidth / 2, imageHeight / 2); - glTexCoord2f(0, 1); - glVertex2i(-imageWidth / 2, imageHeight / 2); - glEnd(); - - // Activer la transparence - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBlendEquation(GL_FUNC_ADD); - glEnable(GL_BLEND); - - // Restaurer les matrices précédentes - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); -} - - - -void Engine::DrawMenu() -{ - static const int sTitle = 400; - static const int sButton = 225; - - glDisable(GL_LIGHTING); - - - glDisable(GL_DEPTH_TEST); - glDisable(GL_STENCIL_TEST); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glOrtho(0, Width(), 0, Height(), -1, 1); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - - MenuBGTexture.Bind(); - glLoadIdentity(); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 0); - glTexCoord2f(1, 0); - glVertex2i(800, 0); - glTexCoord2f(1, 1); - glVertex2i(800, 600); - glTexCoord2f(0, 1); - glVertex2i(0, 600); - glEnd(); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBlendEquation(GL_FUNC_ADD); - glEnable(GL_BLEND); - - if (m_gamestate != GameState::OPTIONS) - { - MenuTitleTexture.Bind(); - glTranslated(200, 300, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 200); - glTexCoord2f(1, 0); - glVertex2i(sTitle, 200); - glTexCoord2f(1, 1); - glVertex2i(sTitle, 300); - glTexCoord2f(0, 1); - glVertex2i(0, 300); - glEnd(); - - MenuStartTexture.Bind(); - glTranslated(80, -225, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 100); - glTexCoord2f(1, 0); - glVertex2i(sButton, 100); - glTexCoord2f(1, 1); - glVertex2i(sButton, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd(); - - /*MenuResumeTexture.Bind(); - glTranslated(0, -100, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 125); - glTexCoord2f(1, 0); - glVertex2i(sButton, 125); - glTexCoord2f(1, 1); - glVertex2i(sButton, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd();*/ - - /*MenuOptionsTexture.Bind(); - glTranslated(0, -100, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 125); - glTexCoord2f(1, 0); - glVertex2i(sButton, 125); - glTexCoord2f(1, 1); - glVertex2i(sButton, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd();*/ - - MenuQuitTexture.Bind(); - glTranslated(0, -100, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 100); - glTexCoord2f(1, 0); - glVertex2i(sButton, 100); - glTexCoord2f(1, 1); - glVertex2i(sButton, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd(); - - } - else - { - /*MenuOptionsTexture.Bind(); - glTranslated(200, 0, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 0); - glTexCoord2f(1, 0); - glVertex2i(sTitle, 0); - glTexCoord2f(1, 1); - glVertex2i(sTitle, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd(); - - WireFrameTexture.Bind(); - glTranslated(0, 300, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 125); - glTexCoord2f(1, 0); - glVertex2i(sButton, 125); - glTexCoord2f(1, 1); - glVertex2i(sButton, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd(); - - OnOffBtnTexture.Bind(); - glTranslated(200, 0, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 125); - glTexCoord2f(1, 0); - glVertex2i(sButton, 125); - glTexCoord2f(1, 1); - glVertex2i(sButton, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd(); - glTranslated(-400, -300, 0); - - MusicTexture.Bind(); - glTranslated(200, 200, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 125); - glTexCoord2f(1, 0); - glVertex2i(sButton, 125); - glTexCoord2f(1, 1); - glVertex2i(sButton, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd(); - - OnOffBtnTexture.Bind(); - glTranslated(200, 0, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 125); - glTexCoord2f(1, 0); - glVertex2i(sButton, 125); - glTexCoord2f(1, 1); - glVertex2i(sButton, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd(); - - BackBtnTexture.Bind(); - glTranslated(-375, 175, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 140); - glTexCoord2f(1, 0); - glVertex2i(sButton, 140); - glTexCoord2f(1, 1); - glVertex2i(sButton, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd();*/ - } - - //glEnable(GL_LIGHTING); - glDisable(GL_BLEND); - glEnable(GL_DEPTH_TEST); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - ShowCursor(); -} - void Engine::Init() { + if (m_istarted) + return; + else m_istarted = true; + // Objet de skybox avec sa propre texture et son propre shader! + m_skybox.Init(0.2f); + // Objet de musique! + //m_menuaudio.ToggleMusicState(); + + // Array pour les balles. + for (int x = 0; x < MAX_BULLETS; ++x) { + m_bullets[x] = nullptr; + m_whoosh[x] = nullptr; + } + m_world.GetChunks().Reset(nullptr); + m_world.SetSeed(SEED); +} + +void Engine::DeInit() {} + +void Engine::LoadResource() { GLenum glewErr = glewInit(); if (glewErr != GLEW_OK) { std::cerr << " ERREUR GLEW : " << glewGetErrorString(glewErr) << std::endl; @@ -280,7 +58,7 @@ void Engine::Init() { } glDisable(GL_FRAMEBUFFER_SRGB); - glEnable(GL_DEPTH_TEST); + glEnable(GL_DEPTH_TEST); glEnable(GL_STENCIL_TEST); glEnable(GL_POINT_SMOOTH); glEnable(GL_BLEND); @@ -297,68 +75,130 @@ void Engine::Init() { glDisable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_FUNC_SUBTRACT); - - // - // Objet de skybox avec sa propre texture et son propre shader! - m_skybox.Init(0.2f); - // Objet de musique! - //m_audio.ToggleMusicState(); - - // Array pour les balles. - for (int x = 0; x < MAX_BULLETS; ++x) { - m_bullets[x] = nullptr; - m_whoosh[x] = nullptr; // = m_audio.m_engine.m_audio.m_engine->addSoundSourceFromFile(AUDIO_PATH "noise.ogg", irrklang::ESM_AUTO_DETECT, false); - } - - uint64_t seed = SEED; - std::string playname = "La Chienne � Jacques"; - if (NETWORK_TEST) { // Test connexion r�seau. - if (!m_conn.Init()) { - if (!m_conn.Connect(SRV_ADDR, playname)) { - // setup jeu en r�seau. - std::cout << "ID re�u du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl; - std::cout << "Seed re�u du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl; - seed = m_conn.getSeed(); - } - else std::cout << "Erreur de connexion." << std::endl; - } - else std::cout << "Erreur de cr�ation de socket." << std::endl; - } - - m_world.SetSeed(seed); - - // Init Chunks - m_world.GetChunks().Reset(nullptr); - - - - // Gestion de souris. - CenterMouse(); - HideCursor(); -} - -void Engine::DeInit() {} - -void Engine::LoadResource() { LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png", true); LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp", true); LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp", true); LoadTexture(m_textureGun, TEXTURE_PATH "gun01.png", false); LoadTexture(m_texturePovGun, TEXTURE_PATH "GUN.png", false); - LoadTexture(m_textureSoloMultiMenu, TEXTURE_PATH "single_multi.png", false); - LoadTexture(m_textureTitle, TEXTURE_PATH "title.png", false); - LoadTexture(MenuTitleTexture, MENU_ITEM_PATH "test.png"); - LoadTexture(MenuBGTexture, MENU_ITEM_PATH "test.png"); - LoadTexture(SplachScreenTexture, TEXTURE_PATH "sc2.png"); - LoadTexture(MenuQuitTexture, MENU_ITEM_PATH "BasicQuit.png"); - LoadTexture(MenuOptionsTexture, MENU_ITEM_PATH "test.png"); - LoadTexture(MenuStartTexture, MENU_ITEM_PATH "BasicPlay.png"); - TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png"); - TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png"); + LoadTexture(m_textureLobbyMenu, TEXTURE_PATH "menus/backgrounds/bgLobby.png", false); + LoadTexture(m_textureMainMenu, TEXTURE_PATH "menus/backgrounds/bgMainMenu.png", false); + //LoadTexture(m_texturePauseMenu, TEXTURE_PATH "menus/backgrounds/bgPause.png", false); + LoadTexture(m_textureOptionsMenu, TEXTURE_PATH "menus/backgrounds/bgOptions.png", false); + LoadTexture(m_textureSplashScreen, TEXTURE_PATH "menus/backgrounds/bgSplash.png", false); + + LoadTexture(m_textureCheck, TEXTURE_PATH "menus/others/check.png", false); + LoadTexture(m_textureChecked, TEXTURE_PATH "menus/others/checked.png", false); + + LoadTexture(m_textureOptAudio, TEXTURE_PATH "menus/buttons/options/optAudio.png", false); + LoadTexture(m_textureOptBack, TEXTURE_PATH "menus/buttons/options/optBack.png", false); + LoadTexture(m_textureOptGameplay, TEXTURE_PATH "menus/buttons/options/optGameplay.png", false); + LoadTexture(m_textureOptGraphics, TEXTURE_PATH "menus/buttons/options/optGraphics.png", false); + LoadTexture(m_textureOptMain, TEXTURE_PATH "menus/buttons/options/optMain.png", false); + LoadTexture(m_textureOptMusic, TEXTURE_PATH "menus/buttons/options/optMusic.png", false); + LoadTexture(m_textureOptOptions, TEXTURE_PATH "menus/buttons/options/optOptions.png", false); + LoadTexture(m_textureOptResolution, TEXTURE_PATH "menus/buttons/options/optResolution.png", false); + LoadTexture(m_textureOptSensitivity, TEXTURE_PATH "menus/buttons/options/optSensitivity.png", false); + LoadTexture(m_textureOptSfx, TEXTURE_PATH "menus/buttons/options/optSfx.png", false); + + LoadTexture(m_textureLobbyServer, TEXTURE_PATH "menus/labels/labelServer.png", false); + LoadTexture(m_textureLobbyIdentify, TEXTURE_PATH "menus/labels/labelIdentify.png", false); + LoadTexture(m_textureHd, TEXTURE_PATH "menus/labels/labelHd.png", false); + LoadTexture(m_textureHd, TEXTURE_PATH "menus/labels/labelHd.png", false); + LoadTexture(m_textureFhd, TEXTURE_PATH "menus/labels/labelFhd.png", false); + LoadTexture(m_textureQhd, TEXTURE_PATH "menus/labels/labelQhd.png", false); + LoadTexture(m_textureUhd, TEXTURE_PATH "menus/labels/labelUhd.png", false); + LoadTexture(m_textureMenuTitle, TEXTURE_PATH "menus/labels/labelTitle.png", false); + + LoadTexture(m_textureMenuBack, TEXTURE_PATH "menus/buttons/main/mainBack.png", false); + LoadTexture(m_textureMenuMulti, TEXTURE_PATH "menus/buttons/main/mainMulti.png", false); + LoadTexture(m_textureMenuOptions, TEXTURE_PATH "menus/buttons/main/mainOptions.png", false); + LoadTexture(m_textureMenuPlay, TEXTURE_PATH "menus/buttons/main/mainPlay.png", false); + LoadTexture(m_textureMenuQuit, TEXTURE_PATH "menus/buttons/main/mainQuit.png", false); + LoadTexture(m_textureMenuSingle, TEXTURE_PATH "menus/buttons/main/mainSingle.png", false); + + TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png"); + TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png"); TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png"); TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dirt.png"); + TextureAtlas::TextureIndex texGreenGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "greengrass.png"); + TextureAtlas::TextureIndex texBoostHeal = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterVert.png"); + TextureAtlas::TextureIndex texBoostDmg = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterRouge.png"); + TextureAtlas::TextureIndex texBoostSpd = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterBleu.png"); + TextureAtlas::TextureIndex texBoostInv = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterJaune.png"); + + //AJOUTER LES TEXTURES DANS L'ORDRE DE L'ÉNUM + + //STILL//STANDING + TextureAtlas::TextureIndex StillFront = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueFrontRight.png"); //0 + TextureAtlas::TextureIndex StillQuarterFrontLeft = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueLeft.png"); //1 + TextureAtlas::TextureIndex StillQuarterFrontRight = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueRight.png"); //2 + TextureAtlas::TextureIndex StillProfiltLeft = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueProfilLeft.png"); //3 + TextureAtlas::TextureIndex StillProfiltRight = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueProfilRight.png"); //4 + TextureAtlas::TextureIndex StillQuarterBackLeft = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueLeftBack.png"); //5 + TextureAtlas::TextureIndex StillQuarterBackRight = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueRightBack.png"); //6 + TextureAtlas::TextureIndex StillBack = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueBackRight.png"); //7 + + //SHOOTINGSTILL SANS TIRER + TextureAtlas::TextureIndex StillFrontShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueFrontRightShootingRight.png"); ////9 + TextureAtlas::TextureIndex StillQuarterFrontLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueFrontRightShootingRight.png"); ////10 + TextureAtlas::TextureIndex StillQuarterFrontRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueRightShootingRight.png"); ////11 + TextureAtlas::TextureIndex StillProfiltLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueProfilShootingLeft.png"); ////12 + TextureAtlas::TextureIndex StillProfiltRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueProfilShootingRight.png"); ////13 + TextureAtlas::TextureIndex StillQuarterBackLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueBackLeftShootingLeft.png"); ////14 + TextureAtlas::TextureIndex StillQuarterBackRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueBackRightShootingRight.png"); ////15 + TextureAtlas::TextureIndex StillBackShoot = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT1 "BlueShootingBackRight.png"); ////16 + + //SHOOTINGSTILL TIRER + TextureAtlas::TextureIndex StillFrontShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueFrontRightShootingRightShoot1.png"); ////17 + TextureAtlas::TextureIndex StillQuarterFrontLeftFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueLeftShootingLeftShoot1.png"); ////18 + TextureAtlas::TextureIndex StillQuarterFrontRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueRightShootingRightShoot1.png"); ////19 + TextureAtlas::TextureIndex StillProfiltLeftShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueProfilShootingLeftShoot1.png"); ////20 + TextureAtlas::TextureIndex StillProfiltRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueProfilShootingRightShoot1.png"); ////21 + TextureAtlas::TextureIndex StillQuarterBackLeftShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueBackLeftShootingLeftShoot1.png"); ////22 + TextureAtlas::TextureIndex StillQuarterBackRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueBackRightShootingRightShoot1.png"); ////23 + TextureAtlas::TextureIndex StillBackShootFire = m_animeAtlas.AddTexture(ANIM_PATH_SSHOOT2 "BlueShootingBackRightShoot1.png"); ////24 + + + //JUMP + TextureAtlas::TextureIndex JumpFront = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueFrontJumpRight.png"); ////25 + TextureAtlas::TextureIndex JumpQuarterFrontLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueLeftFrontJumpLeft.png"); ////26 + TextureAtlas::TextureIndex JumpQuarterFrontRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueRightFrontJumpRight.png"); ////27 + TextureAtlas::TextureIndex JumpProfiltLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueProfilJumpLeft.png"); ////28 + TextureAtlas::TextureIndex JumpProfiltRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueProfilJumpRight.png"); ////29 + TextureAtlas::TextureIndex JumpQuarterBackLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueLeftBackJumpLeft.png"); ////30 + TextureAtlas::TextureIndex JumpQuarterBackRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueRightBackJumpRight.png"); ////31 + TextureAtlas::TextureIndex JumpBack = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueBackJumpRight.png"); ////32 + + + //SHOOTINGJUMP SANS TIRER + TextureAtlas::TextureIndex JumpFrontShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueFrontJumpRightShootingRight.png"); ////33 + TextureAtlas::TextureIndex JumpQuarterFrontLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueFrontLeftJumpLeftShootingLeft.png"); ////34 + TextureAtlas::TextureIndex JumpQuarterFrontRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueFrontRightJumpRightShootingRight.png"); ////35 + TextureAtlas::TextureIndex JumpProfiltLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueProfilLeftJumpLeftShootingLeft.png"); ////36 + TextureAtlas::TextureIndex JumpProfiltRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BluerProfilRightJumprightShootingRight.png"); ////37 + TextureAtlas::TextureIndex JumpQuarterBackLeftShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueBackLeftJumpLeftShootingLeft.png"); ////38 + TextureAtlas::TextureIndex JumpQuarterBackRightShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueBackRightJumpRightShootingRight.png"); ////39 + TextureAtlas::TextureIndex JumpBackShoot = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT1 "BlueBackJumpRightShootingRight.png"); ////40 + + + //SHOOTINGJUMP TIRER + TextureAtlas::TextureIndex JumpFrontShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueFrontJumpRightShootingRightShoot1.png"); ////41 + TextureAtlas::TextureIndex JumpQuarterFrontLeftShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueFrontLeftJumpLeftShootingLeftShoot1.png"); ////42 + TextureAtlas::TextureIndex JumpQuarterFrontRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueFrontRightJumpRightShootingRightShoot1.png"); ////43 + TextureAtlas::TextureIndex JumpProfiltLeftShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueProfilLeftJumpLeftShootingLeftShoot1.png"); ////44 + TextureAtlas::TextureIndex JumpProfiltRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BluerProfilRightJumprightShootingRightShoot1.png"); ////45 + TextureAtlas::TextureIndex JumpQuarterBackLeftShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueBackLeftJumpLeftShootingLeftShoot1.png"); ////46 + TextureAtlas::TextureIndex JumpQuarterBackRightShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueBackRightJumpRightShootingRightShoot1.png"); ////47 + TextureAtlas::TextureIndex JumpBackShootFire = m_animeAtlas.AddTexture(ANIM_PATH_JSHOOT2 "BlueBackJumpRightShootingRightShoot1.png"); ////48 + + + + if (!m_animeAtlas.Generate(TEXTURE_SIZE, false)) { + std::cout << " Unable to generate texture atlas ..." << std::endl; + abort(); + } if (!m_textureAtlas.Generate(TEXTURE_SIZE, false)) { std::cout << " Unable to generate texture atlas ..." << std::endl; @@ -374,6 +214,18 @@ void Engine::LoadResource() { m_blockinfo[BTYPE_METAL] = new BlockInfo(BTYPE_METAL, "Metal", u, v, s, 1); m_textureAtlas.TextureIndexToCoord(texIceIndex, u, v, s, s); m_blockinfo[BTYPE_ICE] = new BlockInfo(BTYPE_ICE, "Ice", u, v, s, 1); + m_textureAtlas.TextureIndexToCoord(texGreenGrassIndex, u, v, s, s); + m_blockinfo[BTYPE_GREENGRASS] = new BlockInfo(BTYPE_GREENGRASS, "GreenGrass", u, v, s, 1); + m_textureAtlas.TextureIndexToCoord(texBoostHeal, u, v, s, s); + m_boostinfo[BTYPE_HEAL] = new BoostInfo(BTYPE_HEAL, "Heal", u, v, s, 1); + m_textureAtlas.TextureIndexToCoord(texBoostDmg, u, v, s, s); + m_boostinfo[BTYPE_DAMAGE] = new BoostInfo(BTYPE_DAMAGE, "Dmg", u, v, s, 1); + m_textureAtlas.TextureIndexToCoord(texBoostSpd, u, v, s, s); + m_boostinfo[BTYPE_SPEED] = new BoostInfo(BTYPE_SPEED, "Spd", u, v, s, 1); + m_textureAtlas.TextureIndexToCoord(texIceIndex, u, v, s, s); + m_boostinfo[BTYPE_INVINCIBLE] = new BoostInfo(BTYPE_INVINCIBLE, "Inv", u, v, s, 1); + + m_animeAtlas.TextureIndexToCoord(0, u, v, s, s); std::cout << " Loading and compiling shaders ..." << std::endl; if (!m_shader01.Load(SHADER_PATH "shader01.vert", SHADER_PATH "shader01.frag", true)) { @@ -389,6 +241,13 @@ void Engine::LoadResource() { void Engine::UnloadResource() {} + + +void Engine::InstantDamage() { + m_player.InflictDamage(0.10f); + m_damage = false; +} + void Engine::SystemNotification(std::string systemLog) { std::string message = ""; @@ -396,6 +255,7 @@ void Engine::SystemNotification(std::string systemLog) { DisplayNotification(message); } + void Engine::KillNotification(Player killer, Player killed) { std::string message = ""; @@ -424,16 +284,13 @@ void Engine::ProcessNotificationQueue() { //float fPosY = Height() - (Height() * 0.05) * scaleY; m_textureFont.Bind(); - - auto [scaleX, scaleY] = GetScale(); - - float xOffset = (Width() / 1.5f) * scaleX; - float yOffset = (Height() / 1.2f) * scaleY; + float xOffset = Width() * 0.66f; + float yOffset = Height() * 0.83f; for (auto it = notifications.begin(); it != notifications.end(); ) { float timeSinceDisplay = m_time - it->displayStartTime; - float y = yOffset - (20.0f * scaleX * (it - notifications.begin())); + float y = yOffset - (20.0f * (it - notifications.begin())); glDisable(GL_STENCIL_TEST); glDisable(GL_DEPTH_TEST); @@ -489,108 +346,64 @@ void Engine::DisplayCrosshair() { glEnd(); } -void Engine::DisplayPovGun() { - // Setter le blend function, tout ce qui sera noir sera transparent - glDisable(GL_STENCIL_TEST); - glDisable(GL_DEPTH_TEST); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBlendEquation(GL_FUNC_ADD); - - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - - glLoadIdentity(); - glOrtho(0, Width(), 0, Height(), -1, 1); - - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - - float scaleX = (Width()) / BASE_WIDTH; - float scaleY = (Height()) / BASE_HEIGHT; - float baseXOffset = 0.4958 * BASE_WIDTH; - float baseWidth = 0.4688 * BASE_WIDTH; - float baseHeight = 0.5787 * BASE_HEIGHT; - float xTranslation = baseXOffset * scaleX; - float quadWidth = baseWidth * scaleX; - float quadHeight = baseHeight * scaleY; - - m_texturePovGun.Bind(); - glLoadIdentity(); - glTranslated(xTranslation, 0, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 0); - glTexCoord2f(1, 0); - glVertex2i(quadWidth, 0); - glTexCoord2f(1, 1); - glVertex2i(quadWidth, quadHeight); - glTexCoord2f(0, 1); - glVertex2i(0, quadHeight); - glEnd(); - - // Reset du blend function - glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); - glBlendEquation(GL_FUNC_SUBTRACT); - - glEnable(GL_STENCIL_TEST); - glEnable(GL_DEPTH_TEST); - - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); -} - -void Engine::DisplayCurrentItem() { -} - +void Engine::DisplayCurrentItem() {} void Engine::DisplayHud(int timer) { glBindTexture(GL_TEXTURE_2D, 0); glLoadIdentity(); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - auto [scaleX, scaleY] = GetScale(); + glClear(GL_STENCIL_BUFFER_BIT); - float fBackPosX = (Width() / 25.0f) * scaleX; - float fBackPosY = (Height() - (Height() * 0.815) * scaleY); - float fBackWidth = (Width() / 4.0f) * scaleX; - float fBackHeight = (Height() / 5.5f) * scaleY; + float itemBackgroundWidthProportion = 0.25f; + float itemBackgroundHeightProportion = 0.175f; + float itemBackgroundWidth = Width() * itemBackgroundWidthProportion; + float itemBackgroundHeight = Height() * itemBackgroundHeightProportion; + float itemBackgroundXOffset = Width() * 0.05f; + float itemBackgroundYOffset = Height() * 0.6f; + float itemBackgroundXPos = itemBackgroundXOffset; + float itemBackgroundYPos = Height() - itemBackgroundHeight - itemBackgroundYOffset; + // Selected item background glColor4f(1.0f, 1.0f, 1.0f, 0.2f); glBegin(GL_QUADS); - glVertex2f(fBackPosX, fBackPosY); - glVertex2f(fBackPosX + fBackWidth, fBackPosY); - glVertex2f(fBackPosX + fBackWidth, fBackPosY + fBackHeight); - glVertex2f(fBackPosX, fBackPosY + fBackHeight); + glVertex2f(itemBackgroundXPos, itemBackgroundYPos); + glVertex2f(itemBackgroundXPos + itemBackgroundWidth, itemBackgroundYPos); + glVertex2f(itemBackgroundXPos + itemBackgroundWidth, itemBackgroundYPos + itemBackgroundHeight); + glVertex2f(itemBackgroundXPos, itemBackgroundYPos + itemBackgroundHeight); glEnd(); // HP Bar - float fBarWidth = (Width() / 4.0f) * scaleX; - float fBarHeight = (Height() / 25.0f) * scaleY; - float fPosX = (Width() / 25.0f) * scaleX; - float fBarPosY = (Height() - (Height() * 0.775) * scaleY); - float playerHp = m_player.GetHP(); + if (playerHp < 0.) + playerHp == 0; float facteurOmbrage = m_displayInfo ? 0.5f : 1.0f; + float hpBarWidthProportion = 0.25f; + float hpBarHeightProportion = 0.045f; + float hpBarWidth = Width() * hpBarWidthProportion; + float hpBarHeight = Height() * hpBarHeightProportion; + float hpBarXOffset = Width() * 0.05f; + float hpBarYOffset = Height() * 0.7f; + float hpBarYPos = Height() - hpBarHeight - hpBarYOffset; + // HP Bar Background glColor3f(1.0f * facteurOmbrage, 1.0f * facteurOmbrage, 1.0f * facteurOmbrage); glBegin(GL_QUADS); - glVertex2f(fPosX, fBarPosY - fBarHeight); - glVertex2f(fPosX + fBarWidth, fBarPosY - fBarHeight); - glVertex2f(fPosX + fBarWidth, fBarPosY); - glVertex2f(fPosX, fBarPosY); + glVertex2f(itemBackgroundXPos, hpBarYPos - hpBarHeight); + glVertex2f(itemBackgroundXPos + itemBackgroundWidth, hpBarYPos - hpBarHeight); + glVertex2f(itemBackgroundXPos + itemBackgroundWidth, hpBarYPos); + glVertex2f(itemBackgroundXPos, hpBarYPos); glEnd(); - // Current HP + //TODO: Associer avec mechanique de vie du joueur + + // Barre HP glColor3f(0.0f * facteurOmbrage, 1.0f * facteurOmbrage, 0.0f * facteurOmbrage); glBegin(GL_QUADS); - glVertex2f(fPosX, fBarPosY - fBarHeight); - glVertex2f(fPosX + fBarWidth * playerHp, fBarPosY - fBarHeight); - glVertex2f(fPosX + fBarWidth * playerHp, fBarPosY); - glVertex2f(fPosX, fBarPosY); + glVertex2f(itemBackgroundXPos, hpBarYPos - hpBarHeight); + glVertex2f(itemBackgroundXPos + itemBackgroundWidth * playerHp, hpBarYPos - hpBarHeight); + glVertex2f(itemBackgroundXPos + itemBackgroundWidth * playerHp, hpBarYPos); + glVertex2f(itemBackgroundXPos, hpBarYPos); glEnd(); // Equip Bar @@ -598,22 +411,23 @@ void Engine::DisplayHud(int timer) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor3f(1.0f * facteurOmbrage, 1.0f * facteurOmbrage, 1.0f * facteurOmbrage); - float fEquipWidth = (Width() * 0.175f) * scaleX; - float fEquipHeight = (fEquipWidth / 2.5) * scaleY; - float fEquipPosY = (Height() - (Height() * 0.765) * scaleY); + float equipWidthProportion = 0.8f; + float equipHeightProportion = 0.7f; + float equipWidth = itemBackgroundWidth * equipWidthProportion; + float equipHeight = itemBackgroundHeight * equipHeightProportion; + float equipXOffset = itemBackgroundXPos + (itemBackgroundWidth - equipWidth) * 0.1f; + float equipYOffset = itemBackgroundYPos + (itemBackgroundHeight - equipHeight) * 0.75f; - glTranslatef(fPosX, fEquipPosY, 0); + glTranslatef(equipXOffset, equipYOffset, 0); m_textureGun.Bind(); glBegin(GL_QUADS); - glTexCoord2f(0, 0); glVertex2i(0, 0); - glTexCoord2f(1, 0); glVertex2i(fEquipWidth, 0); - glTexCoord2f(1, 1); glVertex2i(fEquipWidth, fEquipHeight); - glTexCoord2f(0, 1); glVertex2i(0, fEquipHeight); + glTexCoord2f(0, 0); glVertex2f(0, 0); + glTexCoord2f(1, 0); glVertex2f(equipWidth, 0); + glTexCoord2f(1, 1); glVertex2f(equipWidth, equipHeight); + glTexCoord2f(0, 1); glVertex2f(0, equipHeight); glEnd(); - //glDisable(GL_BLEND); - // Username glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); @@ -621,157 +435,25 @@ void Engine::DisplayHud(int timer) { m_textureFont.Bind(); std::ostringstream ss; - float fUsernamePosY = fBarPosY - (fBarHeight * 2) * scaleY; + float fUsernamePosY = hpBarYPos - (hpBarHeight * 2); ss.str(""); ss << m_player.GetUsername(); - PrintText(fPosX, fUsernamePosY, ss.str(), 1.5f); + PrintText(itemBackgroundXPos, fUsernamePosY, ss.str(), 1.5f); ss.str(""); ss << m_player.GetHP() * 100 << "%"; - PrintText(fPosX * 6.25, fUsernamePosY, ss.str(), 1.5f); + PrintText(itemBackgroundXPos * 5.25f, fUsernamePosY, ss.str(), 1.5f); + + float countdownXOffset = Width() * 0.2f; + float countdownYOffset = Height() * 0.1f; + float countdownXPos = Width() - countdownXOffset; + float countdownYPos = Height() - countdownYOffset; // Countdown ss.str(""); ss << "Time: " << (int)(timer / 60) << ":" << std::setw(2) << std::setfill('0') << timer % 60; - PrintText(Width() - (Width() * 0.2f) * scaleX, Height() - (Height() * 0.1) * scaleY, ss.str(), 2.0f); -} - -void Engine::DisplayInfo(float elapsedTime, BlockType bloc) { - m_textureFont.Bind(); - std::ostringstream ss; - - auto [scaleX, scaleY] = GetScale(); - - float fPosX = (Width() / 100.0f) * scaleX; - float fPosY = Height() - (Height() * 0.05) * scaleY; - float charSize = 20 + (24 - 20) * (Width() - 1600) / (1920 - 1600); - - ss << " Fps : " << GetFps(elapsedTime); - PrintText(fPosX, fPosY, ss.str()); - ss.str(""); - fPosY -= charSize; - - ss << " Rendered Chunks : " << m_renderCount; - PrintText(fPosX, fPosY, ss.str()); - ss.str(""); - fPosY -= charSize; - - ss << " To-Be-Deleted Chunks : " << m_world.GettbDeleted(); - PrintText(fPosX, fPosY, ss.str()); - ss.str(""); - fPosY -= charSize; - - float fPosYJump = ((Height() - (Height() * 0.9f)) * scaleY); - fPosY = fPosYJump; - fPosY -= charSize; - - ss << " Velocity : " << m_player.GetVelocity(); - PrintText(fPosX, fPosY, ss.str()); - ss.str(""); - fPosY -= charSize; - - ss << " Direction : " << m_player.GetDirection(); - PrintText(fPosX, fPosY, ss.str()); - ss.str(""); - fPosY -= charSize; - - ss << " Position : " << m_player.GetPosition(); - PrintText(fPosX, fPosY, ss.str()); - ss.str(""); - fPosY -= charSize; - - ss << " Block : "; - if (bloc == BTYPE_LAST) - ss << "Weapon"; - else - ss << (int)bloc; - PrintText(fPosX, fPosYJump, ss.str()); -} - -void Engine::DisplaySingleOrMultiplayerMenu() { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBlendEquation(GL_FUNC_ADD); - - glDisable(GL_STENCIL_TEST); - glDisable(GL_DEPTH_TEST); - - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - - glLoadIdentity(); - glOrtho(0, Width(), 0, Height(), -1, 1); - - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - - auto [scaleX, scaleY] = GetScale(); - float fBackPosX = 0.0f; - float fBackPosY = 0.0f; - float fBackWidth = Width(); - float fBackHeight = Height(); - - m_textureSoloMultiMenu.Bind(); - glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.0f); glVertex2f(fBackPosX, fBackPosY); - glTexCoord2f(1.0f, 0.0f); glVertex2f(fBackWidth, fBackPosY); - glTexCoord2f(1.0f, 1.0f); glVertex2f(fBackWidth, fBackHeight); - glTexCoord2f(0.0f, 1.0f); glVertex2f(fBackPosX, fBackHeight); - glEnd(); - - float centerX = (Width() / 2.0f); - float centerY = (Height() / 2.0f); - float titleWidth = (centerX * 1.85f) * scaleX; - float titleHeight = (centerY * 1.85f) * scaleY; - - // Solo game indicator - m_textureTitle.Bind(); - glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX, centerY); - glTexCoord2f(1.0f, 0.0f); glVertex2f(titleWidth, centerY); - glTexCoord2f(1.0f, 1.0f); glVertex2f(titleWidth, titleHeight); - glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX, titleHeight); - glEnd(); - - glBindTexture(GL_TEXTURE_2D, 0); - - // Solo game indicator - float fPosX = (centerX * 1.1f) * scaleX; - float fPosXWidth = (centerX * 1.75f) * scaleX; - float soloPosY = (centerY * 0.75f) * scaleY; - float soloHeight = (centerY * 0.9f) * scaleY; - - glColor4f(1.0f, 1.0f, 1.0f, 0.5f); - glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.0f); glVertex2f(fPosX, soloPosY); - glTexCoord2f(1.0f, 0.0f); glVertex2f(fPosXWidth, soloPosY); - glTexCoord2f(1.0f, 1.0f); glVertex2f(fPosXWidth, soloHeight); - glTexCoord2f(0.0f, 1.0f); glVertex2f(fPosX, soloHeight); - glEnd(); - - // Multiplayer game indicator - float multiPosY = (centerY * 0.5f) * scaleY; - float multiHeight = (centerY * 0.65f) * scaleY; - - glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.0f); glVertex2f(fPosX, multiPosY); - glTexCoord2f(1.0f, 0.0f); glVertex2f(fPosXWidth, multiPosY); - glTexCoord2f(1.0f, 1.0f); glVertex2f(fPosXWidth, multiHeight); - glTexCoord2f(0.0f, 1.0f); glVertex2f(fPosX, multiHeight); - glEnd(); - - // TODO: Add SOLO / MULTIPLAYER text with font - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - - glEnable(GL_STENCIL_TEST); - glEnable(GL_DEPTH_TEST); - - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); + PrintText(countdownXPos, countdownYPos, ss.str(), 2.0f); } void Engine::DrawHud(float elapsedTime, BlockType bloc) { @@ -793,7 +475,12 @@ void Engine::DrawHud(float elapsedTime, BlockType bloc) { glPushMatrix(); int timer = GetCountdown(elapsedTime); - + /*for (int i = 1; i < WORLD_SIZE_X; i++) { + if (timer <= COUNTDOWN - m_timerReductionChunk * i) { + m_world.RemoveChunk(m_nbReductionChunk * i); + m_renderer.RemoveChunk(m_nbReductionChunk * i); + } + }*/ if (m_keyK) { SystemNotification(m_messageNotification); m_keyK = false; @@ -829,13 +516,65 @@ void Engine::DrawHud(float elapsedTime, BlockType bloc) { glPopMatrix(); } -void Engine::PrintText(float x, float y, const std::string& t, float charSizeMultiplier) { - auto [scaleX, scaleY] = GetScale(); - float scale = std::min(scaleX, scaleY); +void Engine::DisplayPovGun() { + // Setter le blend function, tout ce qui sera noir sera transparent + glDisable(GL_STENCIL_TEST); + glDisable(GL_DEPTH_TEST); - float baseCharSize = 20 + (24 - 20) * (Width() - 1600) / (1920 - 1600); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + + glLoadIdentity(); + glOrtho(0, Width(), 0, Height(), -1, 1); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + + float baseXOffsetPercentage = 0.4958; + float baseWidthPercentage = 0.4688; + float baseHeightPercentage = 0.5787; + + float xTranslation = baseXOffsetPercentage * Width(); + float quadWidth = baseWidthPercentage * Width(); + float quadHeight = baseHeightPercentage * Height(); + + m_texturePovGun.Bind(); + glLoadIdentity(); + glTranslated(xTranslation, 0, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(0, 0); + glTexCoord2f(1, 0); glVertex2i(quadWidth, 0); + glTexCoord2f(1, 1); glVertex2i(quadWidth, quadHeight); + glTexCoord2f(0, 1); glVertex2i(0, quadHeight); + glEnd(); + + // Reset du blend function + glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); + glBlendEquation(GL_FUNC_SUBTRACT); + + glEnable(GL_STENCIL_TEST); + glEnable(GL_DEPTH_TEST); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); +} + +void Engine::PrintText(float x, float y, const std::string& t, float charSizeMultiplier) { + float windowWidth = static_cast(Width()); + float windowHeight = static_cast(Height()); + + float posX = x * windowWidth; + float posY = y * windowHeight; + + float baseCharSize = 20 + (24 - 20) * (windowWidth - 1600) / (1920 - 1600); float charSize = baseCharSize * charSizeMultiplier; + glPushMatrix(); glLoadIdentity(); glTranslated(x, y, 0); @@ -846,47 +585,673 @@ void Engine::PrintText(float x, float y, const std::string& t, float charSizeMul glBegin(GL_QUADS); glTexCoord2f(left, 1.f - top - .0625f); glVertex2f(0, 0); - glTexCoord2f(left + .0625f, 1.f - top - .0625f); glVertex2f(charSize * scale, 0); - glTexCoord2f(left + .0625f, 1.f - top); glVertex2f(charSize * scale, charSize * scale); - glTexCoord2f(left, 1.f - top); glVertex2f(0, charSize * scale); + glTexCoord2f(left + .0625f, 1.f - top - .0625f); glVertex2f(charSize, 0); + glTexCoord2f(left + .0625f, 1.f - top); glVertex2f(charSize, charSize); + glTexCoord2f(left, 1.f - top); glVertex2f(0, charSize); glEnd(); - glTranslated(0.5555f * charSize * scale, 0, 0); + glTranslated(0.5555f * charSize, 0, 0); } -} - -std::pair Engine::GetScale() const { - float widthRatio = static_cast(Width()) / BASE_WIDTH; - float heightRatio = static_cast(Height()) / BASE_HEIGHT; - return { widthRatio, heightRatio }; + glPopMatrix(); } int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; } + int Engine::GetCountdown(float elapsedTime) { - if (m_resetcountdown) - { - m_countdown = m_time + COUNTDOWN; - m_resetcountdown = false; + return m_countdown; +} + +int Engine::GetOptionsChoice() { + return m_selectedOption; +} + +bool Engine::StartMultiplayerGame() { + bool ok = true; + if (!m_conn.Init()) { + if (!m_conn.Connect(m_serverAddr.c_str(), m_username)) { + // setup jeu en reseau. + std::cout << "ID recu du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl; + std::cout << "Seed recu du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl; + m_player = Player(m_conn.getOrigin().position); + + for (auto& [key, player] : m_conn.m_players) + m_players[key] = new RemotePlayer(player); + + //m_world.SetSeed(m_conn.getSeed()); + m_world.SetSeed(9370707); + m_networkgame = true; + } + else { + std::cout << "Erreur de connexion." << std::endl; + ok = false; + } } - if (m_countdown < m_time) - Stop(); - if (!m_stopcountdown) - m_time += elapsedTime; - return m_countdown - (int)m_time; + else { + std::cout << "Erreur de creation de socket." << std::endl; + ok = false; + } + return ok; +} + +void Engine::DisplayInfo(float elapsedTime, BlockType bloc) { + m_textureFont.Bind(); + std::ostringstream ss; + + float marginX = Width() * 0.01; + float marginY = Height() * 0.05; + + float fPosX = marginX; + float fPosY = Height() - marginY; + + float charSize = 20 + (24 - 20) * (Width() - 1600) / (1920 - 1600); + + ss << " Fps : " << GetFps(elapsedTime); + PrintText(fPosX, fPosY, ss.str()); + ss.str(""); + fPosY -= charSize; + + ss << " Rendered Chunks : " << m_renderCount; + PrintText(fPosX, fPosY, ss.str()); + ss.str(""); + fPosY -= charSize; + + ss << " To-Be-Deleted Chunks : " << m_world.GettbDeleted(); + PrintText(fPosX, fPosY, ss.str()); + ss.str(""); + fPosY -= charSize; + + float fPosYJump = Height() * 0.09; + fPosY = fPosYJump; + fPosY -= charSize; + + ss << " Velocity : " << m_player.GetVelocity(); + PrintText(fPosX, fPosY, ss.str()); + ss.str(""); + fPosY -= charSize; + + ss << " Player Position : " << m_player.GetPosition(); + PrintText(fPosX, fPosY, ss.str()); + ss.str(""); + fPosY -= charSize; + + ss << " Remote Position : " << m_otherplayerpos; + PrintText(fPosX, fPosY, ss.str()); + ss.str(""); + fPosY -= charSize; + + //ss << " Block : "; + //if (bloc == BTYPE_LAST) + // ss << "Weapon"; + //else + // ss << (int)bloc; + PrintText(fPosX, fPosYJump, ss.str()); +} + +void Engine::DisplaySplashScreen() { + glDisable(GL_LIGHTING); + glDisable(GL_DEPTH_TEST); + glDisable(GL_STENCIL_TEST); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(-Width() / 2, Width() / 2, -Height() / 2, Height() / 2, -1, 1); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + int imageWidth = Width(); + int imageHeight = Height(); + + m_textureSplashScreen.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(-imageWidth / 2, -imageHeight / 2); + glTexCoord2f(1, 0); glVertex2i(imageWidth / 2, -imageHeight / 2); + glTexCoord2f(1, 1); glVertex2i(imageWidth / 2, imageHeight / 2); + glTexCoord2f(0, 1); glVertex2i(-imageWidth / 2, imageHeight / 2); + glEnd(); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); +} + +void Engine::DisplayLobbyMenu(float elapsedTime) { + + GLint viewport[4]; + glGetIntegerv(GL_VIEWPORT, viewport); + + glDisable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + + glLoadIdentity(); + glOrtho(0, Width(), 0, Height(), -1, 1); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + + m_textureLobbyMenu.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(0, 0); + glTexCoord2f(1, 0); glVertex2i(Width(), 0); + glTexCoord2f(1, 1); glVertex2i(Width(), Height()); + glTexCoord2f(0, 1); glVertex2i(0, Height()); + glEnd(); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + + if (m_settingUsername) { + SetPlayerUsername(elapsedTime); + } + else if (m_settingServer) { + SetServerAddress(elapsedTime); + } + + glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); + + glEnable(GL_DEPTH_TEST); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); +} + +void Engine::SetPlayerUsername(float elapsedTime) { + m_textureLobbyIdentify.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(Width() * 0.6, Height() * 0.75); + glTexCoord2f(1, 0); glVertex2i(Width() * 0.975, Height() * 0.75); + glTexCoord2f(1, 1); glVertex2i(Width() * 0.975, Height() * 0.95); + glTexCoord2f(0, 1); glVertex2i(Width() * 0.6, Height() * 0.95); + glEnd(); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + HandlePlayerInput(elapsedTime); + glDisable(GL_BLEND); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); +} + +void Engine::SetServerAddress(float elapsedTime) { + m_textureLobbyServer.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(Width() * 0.6, Height() * 0.75); + glTexCoord2f(1, 0); glVertex2i(Width() * 0.975, Height() * 0.75); + glTexCoord2f(1, 1); glVertex2i(Width() * 0.975, Height() * 0.95); + glTexCoord2f(0, 1); glVertex2i(Width() * 0.6, Height() * 0.95); + glEnd(); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + HandlePlayerInput(elapsedTime); + glDisable(GL_BLEND); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); +} + +void Engine::DisplayMainMenu() { + GLint viewport[4]; + glGetIntegerv(GL_VIEWPORT, viewport); + + glDisable(GL_STENCIL_TEST); + glDisable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + + glLoadIdentity(); + glOrtho(0, Width(), 0, Height(), -1, 1); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + + // Background + m_textureMainMenu.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); + glTexCoord2f(1.0f, 0.0f); glVertex2f(Width(), 0.0f); + glTexCoord2f(1.0f, 1.0f); glVertex2f(Width(), Height()); + glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, Height()); + glEnd(); + + // Title + float centerX = Width() * 0.5f; + float centerY = Height() * 0.5f; + + glColor4f(1.0f, 0.5f, 0.0f, 1.0f); + m_textureMenuTitle.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX + Width() * 0.05, centerY + Height() * 0.05); + glTexCoord2f(1.0f, 0.0f); glVertex2f(centerX + Width() * 0.45, centerY + Height() * 0.05); + glTexCoord2f(1.0f, 1.0f); glVertex2f(centerX + Width() * 0.45, centerY + Height() * 0.45); + glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX + Width() * 0.05, centerY + Height() * 0.45); + glEnd(); + + DrawButtonBackgrounds(centerX, centerY, 3); + + if (m_gamestate == GameState::MAIN_MENU) { + if (m_selectedPlayOptions) { + DrawSingleMultiButtons(centerX, centerY); + } + else { + DrawMainMenuButtons(centerX, centerY); + } + } + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + + glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); + + glEnable(GL_STENCIL_TEST); + glEnable(GL_DEPTH_TEST); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + + ShowCursor(); +} + +void Engine::DrawMainMenuButtons(float centerX, float centerY) { + m_textureMenuPlay.Bind(); + glColor4f(0.75f, 0.05f, 0.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX + Width() * 0.16, centerY - Height() * 0.065); + glTexCoord2f(1.0f, 0.0f); glVertex2f(centerX + Width() * 0.34, centerY - Height() * 0.065); + glTexCoord2f(1.0f, 1.0f); glVertex2f(centerX + Width() * 0.34, centerY - Height() * 0.01); + glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX + Width() * 0.16, centerY - Height() * 0.01); + glEnd(); + + m_textureMenuOptions.Bind(); + glColor4f(0.75f, 0.05f, 0.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX + Width() * 0.08, centerY - Height() * 0.165); + glTexCoord2f(1.0f, 0.0f); glVertex2f(centerX + Width() * 0.42, centerY - Height() * 0.165); + glTexCoord2f(1.0f, 1.0f); glVertex2f(centerX + Width() * 0.42, centerY - Height() * 0.11); + glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX + Width() * 0.08, centerY - Height() * 0.11); + glEnd(); + + m_textureMenuQuit.Bind(); + glColor4f(0.75f, 0.05f, 0.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX + Width() * 0.16, centerY - Height() * 0.265); + glTexCoord2f(1.0f, 0.0f); glVertex2f(centerX + Width() * 0.34, centerY - Height() * 0.265); + glTexCoord2f(1.0f, 1.0f); glVertex2f(centerX + Width() * 0.34, centerY - Height() * 0.21); + glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX + Width() * 0.16, centerY - Height() * 0.21); + glEnd(); +} + +void Engine::DrawSingleMultiButtons(float centerX, float centerY) { + m_textureMenuSingle.Bind(); + glColor4f(0.75f, 0.05f, 0.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX + Width() * 0.06, centerY - Height() * 0.065); + glTexCoord2f(1.0f, 0.0f); glVertex2f(centerX + Width() * 0.44, centerY - Height() * 0.065); + glTexCoord2f(1.0f, 1.0f); glVertex2f(centerX + Width() * 0.44, centerY - Height() * 0.01); + glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX + Width() * 0.06, centerY - Height() * 0.01); + glEnd(); + + m_textureMenuMulti.Bind(); + glColor4f(0.75f, 0.05f, 0.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX + Width() * 0.08, centerY - Height() * 0.165); + glTexCoord2f(1.0f, 0.0f); glVertex2f(centerX + Width() * 0.42, centerY - Height() * 0.165); + glTexCoord2f(1.0f, 1.0f); glVertex2f(centerX + Width() * 0.42, centerY - Height() * 0.11); + glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX + Width() * 0.08, centerY - Height() * 0.11); + glEnd(); + + m_textureMenuBack.Bind(); + glColor4f(0.75f, 0.05f, 0.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX + Width() * 0.16, centerY - Height() * 0.265); + glTexCoord2f(1.0f, 0.0f); glVertex2f(centerX + Width() * 0.34, centerY - Height() * 0.265); + glTexCoord2f(1.0f, 1.0f); glVertex2f(centerX + Width() * 0.34, centerY - Height() * 0.21); + glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX + Width() * 0.16, centerY - Height() * 0.21); + glEnd(); +} + +void Engine::DrawButtonBackgrounds(float centerX, float centerY, int iterations) { + glColor4f(1.0f, 1.0f, 1.0f, 0.5f); + glBindTexture(GL_TEXTURE_2D, 0); + + float bottomOffset = 0.075f; + float topOffset = 0.0f; + float distanceBetween = 0.1f; + + for (int i = 0; i < iterations; i++) { + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX + Width() * 0.05, centerY - Height() * bottomOffset); + glTexCoord2f(1.0f, 0.0f); glVertex2f(centerX + Width() * 0.45, centerY - Height() * bottomOffset); + glTexCoord2f(1.0f, 1.0f); glVertex2f(centerX + Width() * 0.45, centerY - Height() * topOffset); + glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX + Width() * 0.05, centerY - Height() * topOffset); + glEnd(); + + bottomOffset += distanceBetween; + topOffset += distanceBetween; + } +} + +void Engine::DisplayOptionsMenu() { + static const int sTitle = 400; + static const int sButton = 225; + + float centerX = Width() * 0.5f; + float centerY = Height() * 0.5f; + + GLint viewport[4]; + glGetIntegerv(GL_VIEWPORT, viewport); + + glDisable(GL_STENCIL_TEST); + glDisable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0, Width(), 0, Height(), -1, 1); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + + m_textureOptionsMenu.Bind(); + glLoadIdentity(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(0, 0); + glTexCoord2f(1, 0); glVertex2i(Width(), 0); + glTexCoord2f(1, 1); glVertex2i(Width(), Height()); + glTexCoord2f(0, 1); glVertex2i(0, Height()); + glEnd(); + + glColor4f(1.0f, 0.0f, 1.0f, 1.0f); + m_textureOptOptions.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.175, centerY + Height() * 0.35); + glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.175, centerY + Height() * 0.35); + glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.175, centerY + Height() * 0.45); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.175, centerY + Height() * 0.45); + glEnd(); + + if (m_selectedOption == 0) { + glColor4f(0.5f, 1.0f, 0.0f, 1.0f); + } + m_textureOptAudio.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.35, centerY + Height() * 0.2); + glTexCoord2f(1, 0); glVertex2i(centerX - Width() * 0.2, centerY + Height() * 0.2); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.2, centerY + Height() * 0.25); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.35, centerY + Height() * 0.25); + glEnd(); + + glColor4f(1.0f, 0.0f, 1.0f, 1.0f); + if (m_selectedOption == 1) { + glColor4f(0.5f, 1.0f, 0.0f, 1.0f); + } + m_textureOptGraphics.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.4, centerY + Height() * 0.05); + glTexCoord2f(1, 0); glVertex2i(centerX - Width() * 0.2, centerY + Height() * 0.05); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.2, centerY + Height() * 0.1); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.4, centerY + Height() * 0.1); + glEnd(); + + glColor4f(1.0f, 0.0f, 1.0f, 1.0f); + if (m_selectedOption == 2) { + glColor4f(0.5f, 1.0f, 0.0f, 1.0f); + } + m_textureOptGameplay.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.375, centerY - Height() * 0.1); + glTexCoord2f(1, 0); glVertex2i(centerX - Width() * 0.2, centerY - Height() * 0.1); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.2, centerY - Height() * 0.05); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.375, centerY - Height() * 0.05); + glEnd(); + + // Séparateur + glColor4f(0.0f, 0.0f, 0.0f, 1.0f); + glBindTexture(GL_TEXTURE_2D, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.175, centerY - Height() * 0.1); + glTexCoord2f(1, 0); glVertex2i(centerX - Width() * 0.18, centerY - Height() * 0.1); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.18, centerY + Height() * 0.25); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.175, centerY + Height() * 0.25); + glEnd(); + + glColor4f(1.0f, 0.0f, 1.0f, 1.0f); + m_textureOptBack.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.075, centerY - Height() * 0.25); + glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.075, centerY - Height() * 0.25); + glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.075, centerY - Height() * 0.2); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.075, centerY - Height() * 0.2); + glEnd(); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + + if (m_selectedOption == 0) { + DisplayAudioMenu(centerX, centerY); + } + else if (m_selectedOption == 1) { + DisplayGraphicsMenu(centerX, centerY); + } + else if (m_selectedOption == 2) { + DisplayGameplayMenu(centerX, centerY); + } + + glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); + + glEnable(GL_STENCIL_TEST); + glEnable(GL_DEPTH_TEST); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); +} + +void Engine::DisplayAudioMenu(float centerX, float centerY) { + float minBar = centerX - Width() * 0.15; + float maxBar = centerX + Width() * 0.3; + float percentPosX = centerX + Width() * 0.31f; + + glColor4f(1.0f, 1.0f, 0.0f, 1.0f); + m_textureOptMain.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.215); + glTexCoord2f(1, 0); glVertex2i(centerX - Width() * 0.075, centerY + Height() * 0.215); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.075, centerY + Height() * 0.25); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.25); + glEnd(); + + float principalBottom = centerY + Height() * 0.165f; + float principalTop = centerY + Height() * 0.2f; + + DrawSliderBackground(centerX, centerY, minBar, maxBar, principalBottom, principalTop); + DrawSlider(centerX, centerY, m_volPrincipal, minBar, maxBar, principalBottom, principalTop); + DisplayBarPercentValue(centerX, centerY, percentPosX, principalBottom, minBar, maxBar, m_volPrincipal); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); + + glColor4f(1.0f, 1.0f, 0.0f, 1.0f); + m_textureOptMusic.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.09); + glTexCoord2f(1, 0); glVertex2i(centerX - Width() * 0.05, centerY + Height() * 0.09); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.05, centerY + Height() * 0.125); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.125); + glEnd(); + + float musiqueBottom = centerY + Height() * 0.04f; + float musiqueTop = centerY + Height() * 0.075f; + + DrawSliderBackground(centerX, centerY, minBar, maxBar, musiqueBottom, musiqueTop); + DrawSlider(centerX, centerY, m_volMusique, minBar, maxBar, musiqueBottom, musiqueTop); + DisplayBarPercentValue(centerX, centerY, percentPosX, musiqueBottom, minBar, maxBar, m_volMusique); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); + + glColor4f(1.0f, 1.0f, 0.0f, 1.0f); + m_textureOptSfx.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY - Height() * 0.035); + glTexCoord2f(1, 0); glVertex2i(centerX - Width() * 0.075, centerY - Height() * 0.035); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.075, centerY - Height() * 0.00001); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY - Height() * 0.00001); + glEnd(); + + float effectsBottom = centerY - Height() * 0.085f; + float effectsTop = centerY - Height() * 0.05f; + + DrawSliderBackground(centerX, centerY, minBar, maxBar, effectsBottom, effectsTop); + DrawSlider(centerX, centerY, m_volEffets, minBar, maxBar, effectsBottom, effectsTop); + DisplayBarPercentValue(centerX, centerY, percentPosX, effectsBottom, minBar, maxBar, m_volEffets); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); +} + +void Engine::DisplayGraphicsMenu(float centerX, float centerY) { + glColor4f(1.0f, 1.0f, 0.0f, 1.0f); + m_textureOptResolution.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.215); + glTexCoord2f(1, 0); glVertex2i(centerX, centerY + Height() * 0.215); + glTexCoord2f(1, 1); glVertex2i(centerX, centerY + Height() * 0.25); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.25); + glEnd(); + + glColor4f(1.0f, 1.0f, 1.0f, 0.5f); + glBindTexture(GL_TEXTURE_2D, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.16, centerY + Height() * 0.165); + glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.1, centerY + Height() * 0.165); + glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.1, centerY - Height() * 0.04); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.16, centerY - Height() * 0.04); + glEnd(); + + glColor4f(0.0f, 0.0f, 0.0f, 1.0f); + m_textureHd.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.125); + glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.05, centerY + Height() * 0.125); + glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.05, centerY + Height() * 0.15); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.15); + glEnd(); + + m_textureFhd.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.075); + glTexCoord2f(1, 0); glVertex2i(centerX, centerY + Height() * 0.075); + glTexCoord2f(1, 1); glVertex2i(centerX, centerY + Height() * 0.1); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.1); + glEnd(); + + m_textureQhd.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.025); + glTexCoord2f(1, 0); glVertex2i(centerX, centerY + Height() * 0.025); + glTexCoord2f(1, 1); glVertex2i(centerX, centerY + Height() * 0.05); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.05); + glEnd(); + + m_textureUhd.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY - Height() * 0.025); + glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.015, centerY - Height() * 0.025); + glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.015, centerY); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY); + glEnd(); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + + float heightRatioBottom = 0.125f; + float heightRatioTop = 0.15; + + // Checkboxes + for (int i = 0; i < 4; i++) { + if (static_cast(m_resolution) == i) { + m_textureChecked.Bind(); + } + else { + m_textureCheck.Bind(); + } + + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX + Width() * 0.075, centerY + Height() * heightRatioBottom); + glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.09, centerY + Height() * heightRatioBottom); + glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.09, centerY + Height() * heightRatioTop); + glTexCoord2f(0, 1); glVertex2i(centerX + Width() * 0.075, centerY + Height() * heightRatioTop); + glEnd(); + + heightRatioBottom -= 0.05f; + heightRatioTop -= 0.05f; + } + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); } void Engine::Render(float elapsedTime) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - m_time_SplashScreen += elapsedTime; - if(m_time_SplashScreen < 2) - DrawSplachScreen(); - else if (m_gamestate == GameState::PLAY) - { - HideCursor(); - CenterMouse(); //D�placement de centermouse dans l'action de jouer + if (m_gamestate == GameState::SPLASH) { + if (m_splashTime > 0.0f) { + DisplaySplashScreen(); + } + else { + m_gamestate = GameState::MAIN_MENU; + } + + m_splashTime -= elapsedTime; + return; + } + + if (m_gamestate == GameState::MAIN_MENU) { + DisplayMainMenu(); + return; + } + + if (m_gamestate == GameState::OPTIONS) { + DisplayOptionsMenu(); + return; + } + + if (m_gamestate == GameState::LOBBY) { + DisplayLobbyMenu(elapsedTime); + if (m_multiReady) { + if (StartMultiplayerGame()) { + std::cout << "Starting multiplayer game reached" << std::endl; + m_gamestate = GameState::PLAY; + //m_menuaudio.ToggleMusicState(); + m_audio.ToggleMusicState(); + m_startTime = std::chrono::high_resolution_clock::now(); + } + else { + std::cout << "Cannot reach server." << std::endl; + m_gamestate = GameState::MAIN_MENU; + } + } + return; + } + + if (m_gamestate == GameState::PLAY) { + HideCursor(); + CenterMouse(); - //static float gameTime = elapsedTime; static irrklang::ISound* step; // Pour les sons de pas. static float pollTime = 0; static float bulletTime = 0; @@ -894,11 +1259,12 @@ void Engine::Render(float elapsedTime) { if (elapsedTime > 0.1f) return; - //gameTime += elapsedTime; pollTime += elapsedTime; Transformation all; Transformation skybox; + Transformation remotePlayer; + Vector3f vstep; // Transformations initiales @@ -916,16 +1282,16 @@ void Engine::Render(float elapsedTime) { if (leftright) vstep = Vector3f(m_player.GetPosition().x + m_player.GetDirection().z, m_player.GetPosition().y - 1.7f, m_player.GetPosition().z + m_player.GetDirection().x); else vstep = Vector3f(m_player.GetPosition().x - m_player.GetDirection().z, m_player.GetPosition().y - 1.7f, m_player.GetPosition().z - m_player.GetDirection().x); - m_audio.Create3DAudioObj(step, AUDIO_PATH "step.wav", vstep, m_player.GetVelocity(), false,.8f); + m_audio.Create3DAudioObj(step, AUDIO_PATH "step.wav", vstep, m_player.GetVelocity(), false, .8f); leftright = !leftright; break; case Player::Sound::FALL: - m_audio.Create3DAudioObj(step, AUDIO_PATH "hit.wav", m_player.GetPosition(), m_player.GetVelocity(), false,1.f); + m_audio.Create3DAudioObj(step, AUDIO_PATH "hit.wav", m_player.GetPosition(), m_player.GetVelocity(), false, 1.f); break; default: break; } - m_audio.Update3DAudio(m_player.GetPOV(), m_player.GetDirection(), m_player.GetVelocity()); // Ajustement du positionnement 3D avec les coordonn�es du joueur et - // son vecteur de v�locit� (pour l'effet Doppler) + m_audio.Update3DAudio(m_player.GetPOV(), m_player.GetDirection(), m_player.GetVelocity()); // Ajustement du positionnement 3D avec les coordonnees du joueur et + // son vecteur de velocite (pour l'effet Doppler) pollTime = 0; } @@ -934,78 +1300,350 @@ void Engine::Render(float elapsedTime) { m_player.ApplyTransformation(skybox, false); // Version d'ApplyTransformation qui ne tient compte que de la rotation // (donc l'objet ne bouge pas relativement au joueur, ce qui est pratique pour une skybox!). - if (m_mouseWU) bloc++; - else if (m_mouseWD) bloc--; - if (bloc == BTYPE_LAST + 1) bloc = BTYPE_AIR + 1; - else if (bloc == BTYPE_AIR) bloc = BTYPE_LAST; // La selection de BTYPE_LAST �quipe l'arme. - m_mouseWU = m_mouseWD = false; + m_player.ApplyTransformation(remotePlayer, true, false); - if (m_mouseL) { - if (bloc != BTYPE_LAST) - m_world.ChangeBlockAtCursor(bloc, m_player.GetPosition(), m_player.GetDirection(), m_block); - else if (bulletTime <= 0.f) { + m_mouseWU = m_mouseWD = m_key1 = m_key2 = false; + netprot::ChunkMod* cmod = nullptr; + if (!m_player.AmIDead() && m_mouseL) { + 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.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. + 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.GetPOV() + m_player.GetDirection(), m_player.GetDirection()); } - } - } - else if (m_mouseR) - m_world.ChangeBlockAtCursor(BTYPE_AIR, m_player.GetPosition(), m_player.GetDirection(), m_block); - - for (int x = 0; x < MAX_BULLETS; ++x) { // Array de bullets en jeu. - if (m_bullets[x]) { - for (int b = 0; b < BULLET_UPDATES_PER_FRAME; ++b) - if (m_bullets[x]->Update(&m_world, elapsedTime, BULLET_UPDATES_PER_FRAME)) { - m_bullets[x]->~Bullet(); - if (m_whoosh[x]) - m_whoosh[x]->drop(); - m_bullets[x] = nullptr; - m_whoosh[x] = nullptr; - break; + bulletTime = BULLET_TIME; + m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", m_player.GetPOV(), m_player.GetDirection() * 10, false, .5f); + if (m_flash) { // Coupe le rendering et affiche un frame blanc, pour simuler un flash. + glClearColor(.8f, .8f, .8f, 1.f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + glClearColor(0.f, 0.f, 0.f, 1.f); + return; } - 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 m_audio.Render3DAudioObj(m_whoosh[x], m_bullets[x]->getPos(), m_bullets[x]->getVel(), 5 - (m_bullets[x]->getPos() - m_player.GetPosition()).Length()); + } + } + else if (m_mouseR) + cmod = m_world.ChangeBlockAtCursor(BTYPE_METAL, m_player.GetPosition(), m_player.GetDirection(), m_block, m_networkgame); + + static netprot::ChunkMod** wat = &m_chunkmod; + for (int x = 0; x < MAX_BULLETS; ++x) { // Array de bullets en jeu. + if (m_bullets[x]) { + for (int b = 0; b < BULLET_UPDATES_PER_FRAME; ++b) { + if (m_bullets[x]->Update(&m_world, elapsedTime, BULLET_UPDATES_PER_FRAME, m_players, m_networkgame ? wat : nullptr)) { + m_bullets[x]->~Bullet(); + + if (m_chunkmod) { + m_chunkmod_manifest.push_back(std::move(m_chunkmod)); + m_chunkmod = nullptr; + } + m_bullets[x] = nullptr; + //if (m_whoosh[x]) + // m_whoosh[x]->drop(); + //m_whoosh[x] = nullptr; + break; + } + // 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, 5 - (m_bullets[x]->getPos() - m_player.GetPosition()).Length()); + // } + } + } } - } - m_wrenderer.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); + m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas); if (m_isSkybox) m_skybox.Render(skybox); + ProcessNotificationQueue(); + if (m_damage) { + InstantDamage(); + } + static bool died = false; + 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, 1.f); + 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()); + } + + m_time += elapsedTime; + + if (m_networkgame) { // Pour se gerer le paquet. + static bool has_synced = false; + using namespace std::chrono; + using namespace netprot; + Timestamp tstamp = duration_cast(high_resolution_clock::now() - m_startTime).count(); + static Timestamp last = 0; + Input input; + Sync sync; + uint64_t id = m_conn.getId(); + static std::vector lsPck; + static int sync_acc = 0, cmod_acc = 0; + + if (cmod) + m_chunkmod_manifest.emplace_back(cmod); + + if (last == 0) + last = tstamp; + + sync_acc += tstamp - last; + cmod_acc += tstamp - last; + last = tstamp; + + if (sync_acc >= 1000) { + sync_acc -= 1000; + sync.sid = id; + sync.timestamp = tstamp; + sync.position = m_player.GetPositionAbs(); + sync.hp = m_player.GetHP(); + if (!has_synced) { + has_synced = true; + sendPackTo(m_conn.m_sock_udp, &sync, &m_bufout, &m_conn.m_srvsockaddr); + } + m_syncs[sync.timestamp] = sync; + } + + if (cmod_acc >= 3000) { + while (cmod_acc >= 3000) + cmod_acc -= 3000; + if (!m_chunkmod_manifest.empty()) { + ChunkMod* cmod = m_chunkmod_manifest.front(); + m_chunkmod_manifest.pop_front(); + m_world.ChangeBlockAtPosition(cmod->old_b_type, cmod->pos); + delete cmod; + } + } + + input.sid = id; + input.direction = m_player.GetDirection(); + input.timestamp = tstamp; + input.keys.forward = m_keyW; + input.keys.backward = m_keyS; + input.keys.left = m_keyA; + input.keys.right = m_keyD; + input.keys.jump = m_keySpace; + input.keys.block = m_mouseR; + input.keys.shoot = m_mouseL; + + sendPackTo(m_conn.m_sock_udp, &input, &m_bufout, &m_conn.m_srvsockaddr); + + recvPacks(m_conn.m_sock_udp, &m_buf, &lsPck); + char* prevptr = nullptr; + Chat chat; + for (auto& pck : lsPck) { // We could make a few threads out of this. + Sync sync; Output out; ChunkMod cmod; BulletAdd bull; + if (!prevptr) + prevptr = m_buf.ptr; + uint32_t bsize = m_buf.len - (pck - prevptr); + prevptr = pck; + switch (getType(pck, 1)) { + using enum PACKET_TYPE; + case SYNC: + if (Deserialize(&sync, pck, &bsize)) { + if (sync.sid != m_conn.getId()) { + SystemNotification("syncsid be no good."); + break; + } + if (m_syncs.count(sync.timestamp)) { + Sync comp = m_syncs[sync.timestamp]; + + std::cout << sync.hp << std::endl; + + m_player.InflictDamage(sync.hp - comp.hp); + + Vector3f diff = sync.position - comp.position; + + if (diff.y < 1.) + diff.y = 0; + + if (diff.Length() > 1.5) { + diff.Normalize(); + m_player.Move(-diff); + } + + m_countdown = sync.timer; + + m_syncs.erase(sync.timestamp); + } + } + break; + case OUTPUT: + if (Deserialize(&out, pck, &bsize)) { + if (!m_players.contains(out.id)) { + SystemNotification(std::to_string(out.id).append(" is id no good.")); + break; + } + RemotePlayer* rt = static_cast(m_players[out.id]); + rt->Feed(out); + if (rt->AmIDead()) { + m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false, 1.f); + } + } + break; + case CHUNKMOD: + if (Deserialize(&cmod, pck, &bsize)) { + if (!std::erase_if(m_chunkmod_manifest, // Efface le chunkmod du manifeste s'il est dedans et reset le countdown, sinon fait la modification. + [cmod](ChunkMod* c) { + return cmod.pos == c->pos && + cmod.b_type == c->b_type && + cmod.old_b_type == c->old_b_type; + })) + m_world.ChangeBlockAtPosition(cmod.b_type, cmod.pos); + else cmod_acc = 0; + } + else SystemNotification("cmod iznogoud."); + break; + case BULLET: + if (Deserialize(&bull, pck, &bsize)) { + Bullet* bult = new Bullet(bull.pos, bull.dir); + 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; + 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] = bult; + break; + } + m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", bull.pos, bull.dir, false, 1.f); + } + else SystemNotification("Bullet is kraput."); + break; + case CHAT: + if (Deserialize(&chat, pck, &bsize)) + SystemNotification(chat.mess); + else SystemNotification("Chat iznogoud."); + break; + default: + SystemNotification("packet be no good."); + break; + } + } + lsPck.clear(); + + + glDisable(GL_CULL_FACE); + for (auto& [key, player] : m_players) { + RemotePlayer* rt = static_cast(player); + glClear(GL_STENCIL_BUFFER_BIT); + rt->Render(m_animeAtlas, m_shader01, all, elapsedTime, m_player); + } + glEnable(GL_CULL_FACE); + } + else { + if (m_resetcountdown) { + m_nbReductionChunk = 4; + m_timerReductionChunk = 30; + m_countdown = m_time + COUNTDOWN; + m_resetcountdown = false; + } + if (!m_stopcountdown) + m_countdown -= (int)m_time; + } + DrawHud(elapsedTime, bloc); DisplayPovGun(); - ProcessNotificationQueue(); - - static bool fell = false; - if (m_player.GetPosition().y < 1.7f && !fell) { - m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false,1.f); - fell = true; - } - else if (m_player.GetPosition().y < -20.f) { - m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); // Respawn si le bonho- joueur tombe en bas du monde. - fell = false; - } } - else if (m_gamestate == GameState::MAIN_MENU || m_gamestate == GameState::OPTIONS) - { - DrawMenu(); +} + +void Engine::DisplayGameplayMenu(float centerX, float centerY) { + float minBar = centerX - Width() * 0.15; + float maxBar = centerX + Width() * 0.3; + float percentPosX = centerX + Width() * 0.31f; + + glColor4f(1.0f, 1.0f, 0.0f, 1.0f); + m_textureOptSensitivity.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.215); + glTexCoord2f(1, 0); glVertex2i(centerX, centerY + Height() * 0.215); + glTexCoord2f(1, 1); glVertex2i(centerX, centerY + Height() * 0.25); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.25); + glEnd(); + + float sensibleBottom = centerY + Height() * 0.165f; + float sensibleTop = centerY + Height() * 0.2f; + + DrawSliderBackground(centerX, centerY, minBar, maxBar, sensibleBottom, sensibleTop); + DrawSlider(centerX, centerY, m_volSensible, minBar, maxBar, sensibleBottom, sensibleTop); + DisplayBarPercentValue(centerX, centerY, percentPosX, sensibleBottom, minBar, maxBar, m_volSensible); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); +} + +void Engine::DrawSliderBackground(float centerX, float centerY, float minVal, float maxVal, float bottomSideValue, float topSideValue) { + glColor4f(0.0f, 0.0f, 0.0f, 1.0f); + glBindTexture(GL_TEXTURE_2D, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(minVal, bottomSideValue); + glTexCoord2f(1, 0); glVertex2i(maxVal, bottomSideValue); + glTexCoord2f(1, 1); glVertex2i(maxVal, topSideValue); + glTexCoord2f(0, 1); glVertex2i(minVal, topSideValue); + glEnd(); +} + +void Engine::DisplayBarPercentValue(float centerX, float centerY, float posX, float posY, float minVal, float maxVal, float value) { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + + float percentage = (value / (maxVal - minVal)) * 100; + + if (percentage < 0.0f) { + percentage = 0.0f; + } + else if (percentage > 100.0f) { + percentage = 100.0f; + } + + m_textureFont.Bind(); + std::ostringstream ss; + ss.str(""); + ss << std::fixed << std::setprecision(2); + ss << percentage << "%"; + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + PrintText(posX, posY, ss.str(), 2.0f); + + glDisable(GL_BLEND); +} + +void Engine::DrawSlider(float centerX, float centerY, float value, float minVal, float maxVal, float bottomSideValue, float topSideValue) { + if (value < 0.0f) { + value = 0.0f; + } + else if (value > (maxVal - minVal)) { + value = (maxVal - minVal); + } + + if (value >= 0.0f && value <= (maxVal - minVal)) { + glColor4f(0.0f, 1.0f, 0.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(minVal, bottomSideValue); + glTexCoord2f(1, 0); glVertex2i(minVal + value, bottomSideValue); + glTexCoord2f(1, 1); glVertex2i(minVal + value, topSideValue); + glTexCoord2f(0, 1); glVertex2i(minVal, topSideValue); + glEnd(); } - else if (m_gamestate == GameState::QUIT) - Stop(); } void Engine::KeyPressEvent(unsigned char key) { + if (m_gamestate == LOBBY) { + m_inputChar = SimulateKeyboard(key); + return; + } switch (key) { case 0: // A - Gauche if (!m_keyA) { @@ -1028,8 +1666,16 @@ void Engine::KeyPressEvent(unsigned char key) { } break; case 36: // ESC - Quitter - m_gamestate = GameState::MAIN_MENU; - //Stop(); + if (m_networkgame) + Stop(); + if (m_gamestate == GameState::PLAY) { + m_gamestate = GameState::PAUSE; + } + else if (m_gamestate == GameState::PAUSE) { + m_gamestate = GameState::PLAY; + } + //m_menuaudio.ToggleMusicState(); + m_audio.ToggleMusicState(); break; case 57: // Space - Sauter if (!m_keySpace) { @@ -1046,7 +1692,7 @@ void Engine::KeyPressEvent(unsigned char key) { break; case 10: // K - Debugging DisplayNotification() m_keyK = true; - m_messageNotification = "notifications systeme peuvent �tre affich�"; + m_messageNotification = "notifications systeme peuvent etre affichees"; break; case 11: // L - Debugging DisplayNotification() m_keyL = true; @@ -1059,6 +1705,8 @@ void Engine::KeyPressEvent(unsigned char key) { break; case 8: // I - Ignorer break; + case 9: // J - InstantDamage + m_damage = true; case 15: // P - Ignorer break; case 17: // R - Ignorer @@ -1067,6 +1715,10 @@ void Engine::KeyPressEvent(unsigned char key) { break; case 24: // Y - Ignorer break; + case 27: // 1 + break; + case 28: // 2 + break; case 255: // Fn - Ignorer break; default: @@ -1075,13 +1727,18 @@ void Engine::KeyPressEvent(unsigned char key) { } void Engine::KeyReleaseEvent(unsigned char key) { + if (m_gamestate == LOBBY) { + if (key == 38) { + m_keyShift = false; + } + return; + } switch (key) { case 0: // A - Stop gauche m_keyA = false; break; case 2: // C - Toggle crosshair m_displayCrosshair = !m_displayCrosshair; - std::cout << "DISPLAY CROSSHAIR " << (m_displayCrosshair ? "enabled" : "disabled") << std::endl; break; case 3: // D - Stop droite m_keyD = false; @@ -1108,12 +1765,12 @@ void Engine::KeyReleaseEvent(unsigned char key) { m_keyL = false; break; case 12: // M - Toggle music - m_audio.ToggleMusicState(); + //m_audio.ToggleMusicState(); break; case 15: 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.GetPOV() - Vector3f(1.f, 0.f, 1.f), Vector3f(1.f,0.f,1.f)); + m_bullets[x] = new Bullet(m_player.GetPOV() - Vector3f(1.f, 0.f, 1.f), Vector3f(1.f, 0.f, 1.f)); 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. @@ -1141,32 +1798,314 @@ void Engine::KeyReleaseEvent(unsigned char key) { else glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); break; + case 27: // 1 + m_key1 = true; + break; + case 28: // 2 + m_key2 = true; + break; + case 38: // Shift + m_keyShift = false; + break; case 57: // Espace - Stop sauter m_keySpace = false; break; + case 58: // Enter - comfirm input + m_keyEnter = false; + break; + case 59: // backspace - remove char + m_keyBackspace = false; + break; } } +char Engine::SimulateKeyboard(unsigned char key) { + switch (key) { + case 0: // A + if (!m_keyShift) { m_inputChar = 'a'; } + else { m_inputChar = 'A'; } + break; + case 1: // B + if (!m_keyShift) { m_inputChar = 'b'; } + else { m_inputChar = 'B'; } + break; + case 2: // C + if (!m_keyShift) { m_inputChar = 'c'; } + else { m_inputChar = 'C'; } + break; + case 3: // D + if (!m_keyShift) { m_inputChar = 'd'; } + else { m_inputChar = 'D'; } + break; + case 4: // E + if (!m_keyShift) { m_inputChar = 'e'; } + else { m_inputChar = 'E'; } + break; + case 5: // F + if (!m_keyShift) { m_inputChar = 'f'; } + else { m_inputChar = 'F'; } + break; + case 6: // G + if (!m_keyShift) { m_inputChar = 'g'; } + else { m_inputChar = 'G'; } + break; + case 7: // H + if (!m_keyShift) { m_inputChar = 'h'; } + else { m_inputChar = 'H'; } + break; + case 8: // I + if (!m_keyShift) { m_inputChar = 'i'; } + else { m_inputChar = 'I'; } + break; + case 9: // J + if (!m_keyShift) { m_inputChar = 'j'; } + else { m_inputChar = 'J'; } + break; + case 10: // K + if (!m_keyShift) { m_inputChar = 'k'; } + else { m_inputChar = 'K'; } + break; + case 11: // L + if (!m_keyShift) { m_inputChar = 'l'; } + else { m_inputChar = 'L'; } + break; + case 12: // M + if (!m_keyShift) { m_inputChar = 'm'; } + else { m_inputChar = 'M'; } + break; + case 13: // N + if (!m_keyShift) { m_inputChar = 'n'; } + else { m_inputChar = 'N'; } + break; + case 14: // O + if (!m_keyShift) { m_inputChar = 'o'; } + else { m_inputChar = 'O'; } + break; + case 15: // P + if (!m_keyShift) { m_inputChar = 'p'; } + else { m_inputChar = 'P'; } + break; + case 16: // Q + if (!m_keyShift) { m_inputChar = 'q'; } + else { m_inputChar = 'Q'; } + break; + case 17: // R + if (!m_keyShift) { m_inputChar = 'r'; } + else { m_inputChar = 'R'; } + break; + case 18: // S + if (!m_keyShift) { m_inputChar = 's'; } + else { m_inputChar = 'S'; } + break; + case 19: // T + if (!m_keyShift) { m_inputChar = 't'; } + else { m_inputChar = 'T'; } + break; + case 20: // U + if (!m_keyShift) { m_inputChar = 'u'; } + else { m_inputChar = 'U'; } + break; + case 21: // V + if (!m_keyShift) { m_inputChar = 'v'; } + else { m_inputChar = 'V'; } + break; + case 22: // W + if (!m_keyShift) { m_inputChar = 'w'; } + else { m_inputChar = 'W'; } + break; + case 23: // X + if (!m_keyShift) { m_inputChar = 'x'; } + else { m_inputChar = 'X'; } + break; + case 24: // Y + if (!m_keyShift) { m_inputChar = 'y'; } + else { m_inputChar = 'Y'; } + break; + case 25: // Z + if (!m_keyShift) { m_inputChar = 'z'; } + else { m_inputChar = 'Z'; } + break; + case 26: // 0 + if (!m_keyShift) { m_inputChar = '0'; } + else { m_inputChar = ')'; } + break; + case 27: // 1 + if (!m_keyShift) { m_inputChar = '1'; } + else { m_inputChar = '!'; } + break; + case 28: // 2 + if (!m_keyShift) { m_inputChar = '2'; } + else { m_inputChar = '\"'; } + break; + case 29: // 3 + if (!m_keyShift) { m_inputChar = '3'; } + else { m_inputChar = '/'; } + break; + case 30: // 4 + if (!m_keyShift) { m_inputChar = '4'; } + else { m_inputChar = '$'; } + break; + case 31: // 5 + if (!m_keyShift) { m_inputChar = '5'; } + else { m_inputChar = '%'; } + break; + case 32: // 6 + if (!m_keyShift) { m_inputChar = '6'; } + else { m_inputChar = '?'; } + break; + case 33: // 7 + if (!m_keyShift) { m_inputChar = '7'; } + else { m_inputChar = '&'; } + break; + case 34: // 8 + if (!m_keyShift) { m_inputChar = '8'; } + else { m_inputChar = '*'; } + break; + case 35: // 9 + if (!m_keyShift) { m_inputChar = '9'; } + else { m_inputChar = ')'; } + break; + case 38: // SHIFT + m_keyShift = true; + break; + case 50: // . (Period) + m_inputChar = '.'; + break; + case 56: // _ (Underscore) + if (!m_keyShift) { m_inputChar = '-'; } + else { m_inputChar = '_'; } + break; + case 57: // SPACE + m_inputChar = ' '; + break; + case 58: // ENTER + m_keyEnter = true; + break; + case 59: // BACKSPACE + m_keyBackspace = true; + break; + default: + m_invalidChar = true; + break; + } + + if ((int)key != 38 && !m_invalidChar) { + m_charChanged = true; + std::cout << "Key pressed: " << (int)key << " (" << m_inputChar << ")" << std::endl; + } + + m_invalidChar = false; + return m_inputChar; +} + +void Engine::HandlePlayerInput(float elapsedTime) { + static float lobbyTime = 0.0f; + lobbyTime += elapsedTime; + float onInterval = 0.5f; + float offInterval = 1.0f; + + m_textureFont.Bind(); + std::ostringstream ss; + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + + if (m_charChanged) { + if (m_keyBackspace) { + if (!m_currentInputString.empty()) { + m_currentInputString.pop_back(); + } + m_keyBackspace = false; + } + else if (m_keyEnter) { + if (m_settingUsername) { + if (!m_currentInputString.empty() && + m_currentInputString.size() > 1 && + m_currentInputString.size() < 26) { + m_username = m_currentInputString; + m_currentInputString = ""; + m_settingUsername = false; + m_settingServer = true; + } + } + else if (m_settingServer) { + if (!m_currentInputString.empty()) { + m_serverAddr = m_currentInputString; + m_currentInputString = ""; + m_settingServer = false; + m_multiReady = true; + } + } + m_keyEnter = false; + } + else if (m_settingUsername && m_currentInputString.size() < 26) { + m_currentInputString += m_inputChar; + } + else if (m_settingServer && m_currentInputString.size() < 15) { + m_currentInputString += m_inputChar; + } + } + + ss << m_currentInputString; + m_charChanged = false; + + if (lobbyTime < onInterval) { + ss << "_"; + } + else if (lobbyTime > onInterval && lobbyTime < offInterval) { + ss << " "; + } + else { + lobbyTime = 0.0f; + } + + PrintText(Width() * 0.6f, Height() * 0.4f, ss.str(), 2.0f); +} + + void Engine::MouseMoveEvent(int x, int y) { - m_player.TurnLeftRight(x - (Width() / 2)); - m_player.TurnTopBottom(y - (Height() / 2)); + if (m_gamestate == GameState::PLAY) { + m_player.TurnLeftRight(x - (Width() / 2)); + m_player.TurnTopBottom(y - (Height() / 2)); - // Centrer la souris seulement si elle n'est pas d�j� centr�e - // Il est n�cessaire de faire la v�rification pour �viter de tomber - // dans une boucle infinie o� l'appel � CenterMouse g�n�re un - // MouseMoveEvent, qui rapelle CenterMouse qui rapelle un autre - // MouseMoveEvent, etc - if (x == (Width() / 2) && y == (Height() / 2)) - return; + // Centrer la souris seulement si elle n'est pas d�j� centr�e + // Il est n�cessaire de faire la v�rification pour �viter de tomber + // dans une boucle infinie o� l'appel � CenterMouse g�n�re un + // MouseMoveEvent, qui rapelle CenterMouse qui rapelle un autre + // MouseMoveEvent, etc + if (x == (Width() / 2) && y == (Height() / 2)) + return; + } + else if (m_gamestate == GameState::MAIN_MENU) { + DisplayMainMenu(); + } + else if (m_gamestate == GameState::OPTIONS) { + float centerX = Width() * 0.5f; + float centerY = Height() * 0.5f; + float leftBar = centerX - Width() * 0.15f; + float rightBar = centerX + Width() * 0.3f; + if (m_selectedOption == 0 && m_selectedOptAudioMainBar) { + m_volPrincipal = x - leftBar; + } + else if (m_selectedOption == 0 && m_selectedOptAudioMusicBar) { + m_volMusique = x - leftBar; + } + else if (m_selectedOption == 0 && m_selectedOptAudioSfxBar) { + m_volEffets = x - leftBar; + } + else if (m_selectedOption == 2 && m_selectedGameplaySensitivityBar) { + m_volSensible = x - leftBar; + } + } } void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) { m_mousemx = x; m_mousemy = y; + float centerX = Width() * 0.5f; + float centerY = Height() * 0.5f; - if (m_gamestate == GameState::PLAY) - { + if (m_gamestate == GameState::PLAY) { switch (button) { case MOUSE_BUTTON_LEFT: m_mouseL = true; @@ -1186,12 +2125,140 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) { case MOUSE_BUTTON_NONE: break; } } - else if (m_gamestate == GameState::MAIN_MENU) - { - if ((m_mousemx >= 285 && m_mousemx <= 490) && (m_mousemy >= 150 && m_mousemy <= 250)) - m_gamestate = GameState::PLAY; - if ((m_mousemx >= 305 && m_mousemx <= 450) && (m_mousemy >= 300 && m_mousemy <= 400)) - m_gamestate = GameState::QUIT; + else if (m_gamestate == GameState::MAIN_MENU) { + + float leftButton = centerX + Width() * 0.045f; + float rightButton = centerX + Width() * 0.4455f; + + float topFirst = centerY + Height() * 0.073f; + float bottomFirst = centerY; + + float topSecond = centerY + Height() * 0.177f; + float bottomSecond = centerY + Height() * 0.105f; + + float topThird = centerY + Height() * 0.275f; + float bottomThird = centerY + Height() * 0.198f; + + if (x > leftButton && x < rightButton && y > bottomFirst && y < topFirst) { + if (m_selectedPlayOptions) { + m_gamestate = GameState::PLAY; + } + else { + m_selectedPlayOptions = true; + } + } + else if (x > leftButton && x < rightButton && y > bottomSecond && y < topSecond) { + if (m_selectedPlayOptions) { + m_gamestate = GameState::LOBBY; + m_settingUsername = true; + } + else { + m_gamestate = GameState::OPTIONS; + } + } + else if (x > leftButton && x < rightButton && y > bottomThird && y < topThird) { + if (m_selectedPlayOptions) { + m_selectedPlayOptions = false; + } + else { + m_gamestate = GameState::QUIT; + } + } + } + else if (m_gamestate == GameState::OPTIONS) { + float leftAudio = centerX - Width() * 0.35f; + float rightAudio = centerX - Width() * 0.2f; + float topAudio = (Height() * 0.25f) + ((Height() * 0.25f) - (Height() * 0.2f)); + float bottomAudio = (Height() * 0.2f) + ((Height() * 0.25f) - (Height() * 0.2f)); + + float leftGraph = centerX - Width() * 0.4f; + float rightGraph = centerX - Width() * 0.2f; + float topGraph = centerY - Height() * 0.05f; + float bottomGraph = centerY - Height() * 0.1f; + + float leftGameplay = centerX - Width() * 0.375f; + float rightGameplay = centerX - Width() * 0.2f; + float topGameplay = centerY + Height() * 0.1f; + float bottomGameplay = centerY + Height() * 0.05f; + + float leftBack = centerX - Width() * 0.075f; + float rightBack = centerX + Width() * 0.075f; + float topBack = centerY + Height() * 0.25f; + float bottomBack = centerY + Height() * 0.2f; + + if (x > leftAudio && x < rightAudio && y > bottomAudio && y < topAudio) { + m_selectedOption = 0; // Volume + } + else if (x > leftGraph && x < rightGraph && y > bottomGraph && y < topGraph) { + m_selectedOption = 1; // Graphics + } + else if (x > leftGameplay && x < rightGameplay && y > bottomGameplay && y < topGameplay) { + m_selectedOption = 2; // Gameplay + } + else if (x > leftBack && x < rightBack && y > bottomBack && y < topBack) { + m_gamestate = GameState::MAIN_MENU; + } + + // Audio + float leftBar = centerX - Width() * 0.15f; + float rightBar = centerX + Width() * 0.3f; + + float topBarPrincipal = centerY - Height() * 0.165f; + float bottomBarPrincipal = centerY - Height() * 0.2f; + + float topBarMusique = centerY - Height() * 0.0415f; + float bottomBarMusique = centerY - Height() * 0.075f; + + float topBarEffets = centerY + Height() * 0.085f; + float bottomBarEffets = centerY + Height() * 0.05f; + + if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarPrincipal && y < topBarPrincipal) { + m_volPrincipal = x - leftBar; + m_selectedOptAudioMainBar = true; + } + else if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarMusique && y < topBarMusique) { + m_volMusique = x - leftBar; + m_selectedOptAudioMusicBar = true; + } + else if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarEffets && y < topBarEffets) { + m_volEffets = x - leftBar; + m_selectedOptAudioSfxBar = true; + } + + // Resolution + float leftChk = centerX + Width() * 0.075f; + float rightChk = centerX + Width() * 0.09f; + + float topChkHD = centerY - Height() * 0.125f; + float bottomChkHD = centerY - Height() * 0.155f; + + float topChkFHD = centerY - Height() * 0.0725f; + float bottomChkFHD = centerY - Height() * 0.1f; + + float topChkQHD = centerY - Height() * 0.025f; + float bottomChkQHD = centerY - Height() * 0.05f; + + float topChkUHD = centerY + Height() * 0.025f; + float bottomChkUHD = centerY; + + if (m_selectedOption == 1 && leftChk && x < rightChk && y > bottomChkHD && y < topChkHD) { + m_resolution = HD; + } + else if (m_selectedOption == 1 && x > leftChk && x < rightChk && y > bottomChkFHD && y < topChkFHD) { + m_resolution = FHD; + } + else if (m_selectedOption == 1 && x > leftChk && x < rightChk && y > bottomChkQHD && y < topChkQHD) { + m_resolution = QHD; + } + else if (m_selectedOption == 1 && x > leftChk && x < rightChk && y > bottomChkUHD && y < topChkUHD) { + m_resolution = UHD; + } + + // Gameplay + if (m_selectedOption == 2 && x > leftBar && x < rightBar && y > bottomBarPrincipal && y < topBarPrincipal) { + m_volSensible = x - leftBar; + m_selectedGameplaySensitivityBar = true; + } } } @@ -1200,6 +2267,10 @@ void Engine::MouseReleaseEvent(const MOUSE_BUTTON& button, int x, int y) { case MOUSE_BUTTON_LEFT: m_mouseL = false; m_block = false; + m_selectedOptAudioMainBar = false; + m_selectedOptAudioMusicBar = false; + m_selectedOptAudioSfxBar = false; + m_selectedGameplaySensitivityBar = false; break; case MOUSE_BUTTON_RIGHT: m_mouseR = false; @@ -1230,3 +2301,5 @@ bool Engine::LoadTexture(Texture& texture, const std::string& filename, bool use return true; } + + diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index 0ed8b39..8ca3894 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -2,9 +2,13 @@ #define ENGINE_H__ #include +#include #include +#include +#include #include "../SQCSim-common/array2d.h" #include "../SQCSim-common/blockinfo.h" +#include "../SQCSim-common/boostinfo.h" #include "../SQCSim-common/bullet.h" #include "../SQCSim-common/chunk.h" #include "../SQCSim-common/world.h" @@ -18,14 +22,15 @@ #include "audio.h" #include "textureatlas.h" #include "connector.h" -#include "worldrenderer.h" +#include "renderer.h" +#include "remoteplayer.h" +#include "booster.h" +#include "settings.h" class Engine : public OpenglContext { public: Engine(); virtual ~Engine(); - virtual void DrawMenu(); - virtual void DrawSplachScreen(); virtual void Init(); virtual void DeInit(); virtual void LoadResource(); @@ -38,71 +43,148 @@ public: virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y); private: - std::pair GetScale() const; - int GetFps(float elapsedTime) const; int GetCountdown(float elapsedTime); + int GetOptionsChoice(); + bool StartMultiplayerGame(); bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true); + void InstantDamage(); void SystemNotification(std::string systemLog); void KillNotification(Player killer, Player killed); + void DisplayNotification(std::string message); - void ProcessNotificationQueue(); void DisplayCrosshair(); void DisplayPovGun(); void DisplayCurrentItem(); void DisplayHud(int timer); - void DisplayInfo(float elapsedTime, BlockType bloc); - void DisplaySingleOrMultiplayerMenu(); void DrawHud(float elapsedTime, BlockType bloc); - void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f); + void DisplayInfo(float elapsedTime, BlockType bloc); - Connector m_conn; - Shader m_shader01; - BlockInfo* m_blockinfo[BTYPE_LAST]; - TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST); + void DisplaySplashScreen(); + + void DisplayMainMenu(); + void DrawButtonBackgrounds(float centerX, float centerY, int iterations); + void DrawMainMenuButtons(float centerX, float centerY); + void DrawSingleMultiButtons(float centerX, float centerY); + + void DisplayLobbyMenu(float elapsedTime); + void SetPlayerUsername(float elapsedTime); + void SetServerAddress(float elapsedTime); + + void DisplayOptionsMenu(); + void DisplayAudioMenu(float centerX, float centerY); + void DisplayGraphicsMenu(float centerX, float centerY); + void DisplayGameplayMenu(float centerX, float centerY); + void DrawSliderBackground(float centerX, float centerY, float minVal, float maxVal, float bottomSideValue, float topSideValue); + void DisplayBarPercentValue(float centerX, float centerY, float posX, float posY, float minVal, float maxVal, float value); + void DrawSlider(float centerX, float centerY, float value, float minVal, float maxVal, float bottomSideValue, float topSideValue); + + void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f); + void ProcessNotificationQueue(); + char SimulateKeyboard(unsigned char key); + void HandlePlayerInput(float elapsedTime); + + //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_whoosh[MAX_BULLETS]; + + Bullet* m_bullets[MAX_BULLETS]; + + //Menu + Vector3f m_otherplayerpos = Vector3f(999, 999, 999); World m_world = World(); - WorldRenderer m_wrenderer = WorldRenderer(); + Player m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); + + Renderer m_renderer = Renderer(); + + Booster m_booster = Booster(); + BlockInfo* m_blockinfo[BTYPE_LAST]; + BoostInfo* m_boostinfo[BTYPE_BOOST_LAST]; + + GameState m_gamestate = GameState::SPLASH; + + Shader m_shader01; + + Skybox m_skybox; + + TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST); + TextureAtlas m_animeAtlas = TextureAtlas(TYPE_LAST + POS_LAST); + + TextureAtlas::TextureIndex texBoostHeal; Texture m_textureCrosshair; Texture m_textureFont; Texture m_textureGun; Texture m_texturePovGun; Texture m_textureSkybox; - Texture m_textureSoloMultiMenu; - Texture m_textureTitle; - Skybox m_skybox; - Audio m_audio = Audio(AUDIO_PATH "start.wav"); + Texture m_textureLobbyMenu; + Texture m_textureMainMenu; + Texture m_textureOptionsMenu; + Texture m_texturePauseMenu; + Texture m_textureSplashScreen; - irrklang::ISound* m_powpow, - * m_scream; - irrklang::ISound *m_whoosh[MAX_BULLETS]; + Texture m_textureHd; + Texture m_textureFhd; + Texture m_textureQhd; + Texture m_textureUhd; - Player m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); - - Bullet* m_bullets[MAX_BULLETS]; + Texture m_textureLobbyServer; + Texture m_textureLobbyIdentify; + Texture m_textureCheck; + Texture m_textureChecked; - //Menu - enum class GameState { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY }; - GameState m_gamestate = GameState::MAIN_MENU; - Texture MenuTitleTexture; - Texture MenuBGTexture; - Texture MenuStartTexture; - Texture MenuQuitTexture; - Texture MenuOptionsTexture; - Texture SplachScreenTexture; + Texture m_textureOptAudio; + Texture m_textureOptBack; + Texture m_textureOptGameplay; + Texture m_textureOptGraphics; + Texture m_textureOptMain; + Texture m_textureOptMusic; + Texture m_textureOptOptions; + Texture m_textureOptResolution; + Texture m_textureOptSensitivity; + Texture m_textureOptSfx; + Texture m_textureMenuBack; + Texture m_textureMenuMulti; + Texture m_textureMenuOptions; + Texture m_textureMenuPlay; + Texture m_textureMenuQuit; + Texture m_textureMenuSingle; + Texture m_textureMenuTitle; + + Settings m_options = Settings(m_audio); + + Resolution m_resolution = HD; + + float m_splashTime = 2.0f; float m_scale; float m_time = 0; - float m_time_SplashScreen = 0; - float m_Width = 0; - float m_Height = 0; + float m_titleX = 0; + float m_titleY = 0; int m_renderCount = 0; int m_countdown = COUNTDOWN; + int m_nbReductionChunk = 4; + int m_timerReductionChunk = 30; + + float m_volPrincipal = 0.0f; + float m_volMusique = 0.0f; + float m_volEffets = 0.0f; + float m_volSensible = 0.0f; + + int m_selectedOption = 0; + + bool m_selectedOptAudioMainBar = false; + bool m_selectedOptAudioMusicBar = false; + bool m_selectedOptAudioSfxBar = false; + bool m_selectedGameplaySensitivityBar = false; + + bool m_damage = false; bool m_wireframe = false; bool m_isSkybox = true; @@ -110,27 +192,57 @@ private: bool m_flash = true; bool m_displayCrosshair = true; bool m_displayHud = true; - bool m_displayInfo = false; + bool m_displayInfo = true; bool m_resetcountdown = false; - bool m_soloMultiChoiceMade = true; + bool m_soloMultiChoiceMade = false; bool m_stopcountdown = false; + + bool m_selectedPlayOptions = false; + bool m_selectedOptions = false; + bool m_selectedQuit = false; + + std::string m_currentInputString; + std::string m_username; + std::string m_serverAddr; + char m_inputChar = 0; + bool m_invalidChar = false; + bool m_charChanged = false; + bool m_settingUsername = false; + bool m_settingServer = false; + bool m_multiReady = false; + bool m_key1 = false; + bool m_key2 = false; bool m_keyK = false; bool m_keyL = false; bool m_keyW = false; bool m_keyA = false; bool m_keyS = false; bool m_keyD = false; + bool m_keyEnter = false; bool m_keySpace = false; + bool m_keyShift = false; + bool m_keyBackspace = false; + bool m_mouseL = false; bool m_mouseR = false; bool m_mouseC = false; bool m_mouseWU = false; bool m_mouseWD = false; - //Pour trouver ou est la souris + float m_mousemx = 0; float m_mousemy = 0; + bool m_networkgame = false; + + Connector m_conn; + std::deque m_chunkmod_manifest; + std::chrono::high_resolution_clock::time_point m_startTime; + std::unordered_map m_players; + netprot::Buffer m_buf, m_bufout; + netprot::ChunkMod* m_chunkmod = nullptr; + + std::unordered_map m_syncs; std::string m_messageNotification = ""; }; diff --git a/SQCSim2021/media/audio/whitenoise.ogg b/SQCSim2021/media/audio/whitenoise.ogg new file mode 100644 index 0000000..7443756 Binary files /dev/null and b/SQCSim2021/media/audio/whitenoise.ogg differ diff --git a/SQCSim2021/media/shaders/shader01.frag b/SQCSim2021/media/shaders/shader01.frag index 8adf697..99b1d70 100644 --- a/SQCSim2021/media/shaders/shader01.frag +++ b/SQCSim2021/media/shaders/shader01.frag @@ -7,7 +7,7 @@ void main() texel = texture2D(tex,gl_TexCoord[0].st); texel *= light; - texel.a = 255.; + gl_FragColor = texel; } diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueBackJumpLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueBackJumpLeft.png deleted file mode 100644 index 09283ba..0000000 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueBackJumpLeft.png and /dev/null differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueBackJumpRight.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueBackJumpRight.png index 73935c1..dcd7109 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueBackJumpRight.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueBackJumpRight.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueFrontJumpLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueFrontJumpLeft.png deleted file mode 100644 index 08420cf..0000000 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueFrontJumpLeft.png and /dev/null differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueFrontJumpRight.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueFrontJumpRight.png index 940581c..74ee547 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueFrontJumpRight.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueFrontJumpRight.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueLeftBackJumpLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueLeftBackJumpLeft.png index ecf6195..4b4d6db 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueLeftBackJumpLeft.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueLeftBackJumpLeft.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueLeftFrontJumpLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueLeftFrontJumpLeft.png index b0f3100..23e61ec 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueLeftFrontJumpLeft.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueLeftFrontJumpLeft.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueRightBackJumpRight.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueRightBackJumpRight.png index ffbea70..5c7047b 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueRightBackJumpRight.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueRightBackJumpRight.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueRightFrontJumpRight.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueRightFrontJumpRight.png index 3766095..77506b8 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueRightFrontJumpRight.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumping/BlueRightFrontJumpRight.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueBackJumpLeftShootingLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueBackJumpLeftShootingLeft.png index d2d9827..8c25fc0 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueBackJumpLeftShootingLeft.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueBackJumpLeftShootingLeft.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueBackJumpRightShootingRight.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueBackJumpRightShootingRight.png index 729f5a2..42d6ffd 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueBackJumpRightShootingRight.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueBackJumpRightShootingRight.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueBackLeftJumpLeftShootingLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueBackLeftJumpLeftShootingLeft.png index b12ab88..85657f1 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueBackLeftJumpLeftShootingLeft.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueBackLeftJumpLeftShootingLeft.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueBackRightJumpRightShootingRight.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueBackRightJumpRightShootingRight.png index 8f035fe..5399cee 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueBackRightJumpRightShootingRight.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueBackRightJumpRightShootingRight.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueFrontJumpLeftShootingLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueFrontJumpLeftShootingLeft.png index a2560db..7a188ea 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueFrontJumpLeftShootingLeft.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueFrontJumpLeftShootingLeft.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueFrontJumpRightShootingRight.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueFrontJumpRightShootingRight.png index a5d3b76..46f7ce9 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueFrontJumpRightShootingRight.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueFrontJumpRightShootingRight.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueFrontLeftJumpLeftShootingLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueFrontLeftJumpLeftShootingLeft.png index db2a3b7..636c6c4 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueFrontLeftJumpLeftShootingLeft.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueFrontLeftJumpLeftShootingLeft.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueFrontRightJumpRightShootingRight.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueFrontRightJumpRightShootingRight.png index 6bf9ebd..5944785 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueFrontRightJumpRightShootingRight.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueFrontRightJumpRightShootingRight.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueProfilLeftJumpLeftShootingLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueProfilLeftJumpLeftShootingLeft.png index 8ff7a91..375894c 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueProfilLeftJumpLeftShootingLeft.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BlueProfilLeftJumpLeftShootingLeft.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BluerProfilRightJumprightShootingRight.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BluerProfilRightJumprightShootingRight.png index 1e86cbf..ddc2913 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BluerProfilRightJumprightShootingRight.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/BluerProfilRightJumprightShootingRight.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpLeftShootingLeftShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpLeftShootingLeftShoot1.png index e7b53c8..af6713c 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpLeftShootingLeftShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpLeftShootingLeftShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpLeftShootingLeftShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpLeftShootingLeftShoot2.png index f6abe72..76034b6 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpLeftShootingLeftShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpLeftShootingLeftShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpLeftShootingLeftShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpLeftShootingLeftShoot3.png index c93e3b9..8c11253 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpLeftShootingLeftShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpLeftShootingLeftShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpRightShootingRightShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpRightShootingRightShoot1.png index fa1b9aa..9402e58 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpRightShootingRightShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpRightShootingRightShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpRightShootingRightShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpRightShootingRightShoot2.png index feaa0fa..c4352fb 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpRightShootingRightShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpRightShootingRightShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpRightShootingRightShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpRightShootingRightShoot3.png index a9d8731..b34731a 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpRightShootingRightShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackJumpRightShootingRightShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackLeftJumpLeftShootingLeftShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackLeftJumpLeftShootingLeftShoot1.png index eaa2fbe..97b4154 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackLeftJumpLeftShootingLeftShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackLeftJumpLeftShootingLeftShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackLeftJumpLeftShootingLeftShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackLeftJumpLeftShootingLeftShoot2.png index bf2ff7e..24e2aa7 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackLeftJumpLeftShootingLeftShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackLeftJumpLeftShootingLeftShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackLeftJumpLeftShootingLeftShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackLeftJumpLeftShootingLeftShoot3.png index d4a390b..5c79715 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackLeftJumpLeftShootingLeftShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackLeftJumpLeftShootingLeftShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackRightJumpRightShootingRightShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackRightJumpRightShootingRightShoot1.png index d728b29..ebea87f 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackRightJumpRightShootingRightShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackRightJumpRightShootingRightShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackRightJumpRightShootingRightShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackRightJumpRightShootingRightShoot2.png index cb9a181..872a578 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackRightJumpRightShootingRightShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackRightJumpRightShootingRightShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackRightJumpRightShootingRightShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackRightJumpRightShootingRightShoot3.png index f8b9cbc..04b952b 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackRightJumpRightShootingRightShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueBackRightJumpRightShootingRightShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpLeftShootingLeftShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpLeftShootingLeftShoot1.png index d9b56e8..5264479 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpLeftShootingLeftShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpLeftShootingLeftShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpLeftShootingLeftShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpLeftShootingLeftShoot2.png index 17ca3d6..1be545e 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpLeftShootingLeftShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpLeftShootingLeftShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpLeftShootingLeftShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpLeftShootingLeftShoot3.png index fd7c64e..73c4660 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpLeftShootingLeftShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpLeftShootingLeftShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpRightShootingRightShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpRightShootingRightShoot1.png index 05e0658..180df1a 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpRightShootingRightShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpRightShootingRightShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpRightShootingRightShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpRightShootingRightShoot2.png index c7da648..f7b4715 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpRightShootingRightShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpRightShootingRightShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpRightShootingRightShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpRightShootingRightShoot3.png index 0ffaae2..a71cc5d 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpRightShootingRightShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontJumpRightShootingRightShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontLeftJumpLeftShootingLeftShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontLeftJumpLeftShootingLeftShoot1.png index 2924904..7c3606e 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontLeftJumpLeftShootingLeftShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontLeftJumpLeftShootingLeftShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontLeftJumpLeftShootingLeftShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontLeftJumpLeftShootingLeftShoot2.png index 1afde54..c75b037 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontLeftJumpLeftShootingLeftShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontLeftJumpLeftShootingLeftShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontLeftJumpLeftShootingLeftShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontLeftJumpLeftShootingLeftShoot3.png index abb3ccb..a0440f6 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontLeftJumpLeftShootingLeftShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontLeftJumpLeftShootingLeftShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontRightJumpRightShootingRightShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontRightJumpRightShootingRightShoot1.png index 9e170c9..9320112 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontRightJumpRightShootingRightShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontRightJumpRightShootingRightShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontRightJumpRightShootingRightShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontRightJumpRightShootingRightShoot2.png index c844481..37a678b 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontRightJumpRightShootingRightShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontRightJumpRightShootingRightShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontRightJumpRightShootingRightShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontRightJumpRightShootingRightShoot3.png index 90e0c73..a117be2 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontRightJumpRightShootingRightShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueFrontRightJumpRightShootingRightShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueProfilLeftJumpLeftShootingLeftShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueProfilLeftJumpLeftShootingLeftShoot1.png index 3a3a354..54a421f 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueProfilLeftJumpLeftShootingLeftShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueProfilLeftJumpLeftShootingLeftShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueProfilLeftJumpLeftShootingLeftShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueProfilLeftJumpLeftShootingLeftShoot2.png index b2aa174..09352ab 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueProfilLeftJumpLeftShootingLeftShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueProfilLeftJumpLeftShootingLeftShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueProfilLeftJumpLeftShootingLeftShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueProfilLeftJumpLeftShootingLeftShoot3.png index 1834bb0..bba70d6 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueProfilLeftJumpLeftShootingLeftShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BlueProfilLeftJumpLeftShootingLeftShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BluerProfilRightJumprightShootingRightShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BluerProfilRightJumprightShootingRightShoot1.png index c24be96..6ef6a7c 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BluerProfilRightJumprightShootingRightShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BluerProfilRightJumprightShootingRightShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BluerProfilRightJumprightShootingRightShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BluerProfilRightJumprightShootingRightShoot2.png index a94919f..c6f96b8 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BluerProfilRightJumprightShootingRightShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BluerProfilRightJumprightShootingRightShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BluerProfilRightJumprightShootingRightShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BluerProfilRightJumprightShootingRightShoot3.png index 8f932ee..66ab97f 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BluerProfilRightJumprightShootingRightShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGJumpingShooting/ShootingJump/BluerProfilRightJumprightShootingRightShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueBackLeftShootingLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueBackLeftShootingLeft.png index 0842f01..885e6c7 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueBackLeftShootingLeft.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueBackLeftShootingLeft.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueBackRightShootingRight.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueBackRightShootingRight.png index 91b2684..3e76747 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueBackRightShootingRight.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueBackRightShootingRight.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueFrontLeftShootingLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueFrontLeftShootingLeft.png index 56865bf..58f5bd6 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueFrontLeftShootingLeft.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueFrontLeftShootingLeft.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueFrontRightShootingRight.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueFrontRightShootingRight.png index 1ead66b..970ca2a 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueFrontRightShootingRight.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueFrontRightShootingRight.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueLeftShootingLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueLeftShootingLeft.png index 7d8f578..253d24a 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueLeftShootingLeft.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueLeftShootingLeft.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueProfilShootingLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueProfilShootingLeft.png index 306e94e..c97f569 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueProfilShootingLeft.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueProfilShootingLeft.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueProfilShootingRight.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueProfilShootingRight.png index 43b7817..e1499cd 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueProfilShootingRight.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueProfilShootingRight.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueRightShootingRight.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueRightShootingRight.png index def4afb..ab5a315 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueRightShootingRight.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueRightShootingRight.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueShootingBackLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueShootingBackLeft.png index 3ca0714..0befc0d 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueShootingBackLeft.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueShootingBackLeft.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueShootingBackRight.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueShootingBackRight.png index 7ea7d9e..271da83 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueShootingBackRight.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/BlueShootingBackRight.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackLeftShootingLeftShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackLeftShootingLeftShoot1.png index 5d552d0..47be7a1 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackLeftShootingLeftShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackLeftShootingLeftShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackLeftShootingLeftShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackLeftShootingLeftShoot2.png index 6fb898c..33a5e19 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackLeftShootingLeftShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackLeftShootingLeftShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackLeftShootingLeftShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackLeftShootingLeftShoot3.png index 5597961..79598e2 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackLeftShootingLeftShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackLeftShootingLeftShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackRightShootingRightShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackRightShootingRightShoot1.png index 74c9f18..94108dc 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackRightShootingRightShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackRightShootingRightShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackRightShootingRightShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackRightShootingRightShoot2.png index 7c033ec..0487033 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackRightShootingRightShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackRightShootingRightShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackRightShootingRightShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackRightShootingRightShoot3.png index fcb900b..f8e267e 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackRightShootingRightShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueBackRightShootingRightShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontLeftShootingLeftShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontLeftShootingLeftShoot1.png index 5902c40..4b91cf1 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontLeftShootingLeftShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontLeftShootingLeftShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontLeftShootingLeftShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontLeftShootingLeftShoot2.png index 5f85afe..7119eae 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontLeftShootingLeftShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontLeftShootingLeftShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontLeftShootingLeftShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontLeftShootingLeftShoot3.png index 61792ed..c830274 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontLeftShootingLeftShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontLeftShootingLeftShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontRightShootingRightShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontRightShootingRightShoot1.png index d6b8aed..fdb48a1 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontRightShootingRightShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontRightShootingRightShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontRightShootingRightShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontRightShootingRightShoot2.png index 7175d87..7a7fb71 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontRightShootingRightShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontRightShootingRightShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontRightShootingRightShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontRightShootingRightShoot3.png index ba991bd..aa161b1 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontRightShootingRightShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueFrontRightShootingRightShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueLeftShootingLeftShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueLeftShootingLeftShoot1.png index 517a261..2a1018d 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueLeftShootingLeftShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueLeftShootingLeftShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueLeftShootingLeftShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueLeftShootingLeftShoot2.png index 60c44b9..9b8082c 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueLeftShootingLeftShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueLeftShootingLeftShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueLeftShootingLeftShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueLeftShootingLeftShoot3.png index eb3a984..851451b 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueLeftShootingLeftShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueLeftShootingLeftShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingLeftShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingLeftShoot1.png index d1f51ab..2d24097 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingLeftShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingLeftShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingLeftShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingLeftShoot2.png index aae48a8..a281dae 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingLeftShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingLeftShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingLeftShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingLeftShoot3.png index eb72cb8..af357b7 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingLeftShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingLeftShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingRightShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingRightShoot1.png index 5a84914..53f57fb 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingRightShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingRightShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingRightShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingRightShoot2.png index baeb4eb..c73b3d6 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingRightShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingRightShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingRightShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingRightShoot3.png index 8e1f794..c9f30ea 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingRightShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueProfilShootingRightShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueRightShootingRightShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueRightShootingRightShoot1.png index 0c80ebc..acec7d3 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueRightShootingRightShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueRightShootingRightShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueRightShootingRightShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueRightShootingRightShoot2.png index 4e40664..276722b 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueRightShootingRightShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueRightShootingRightShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueRightShootingRightShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueRightShootingRightShoot3.png index d174798..d446c80 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueRightShootingRightShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueRightShootingRightShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackLeftShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackLeftShoot1.png index 3a26f64..e5b6580 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackLeftShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackLeftShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackLeftShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackLeftShoot2.png index 5958dec..e70cd33 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackLeftShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackLeftShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackLeftShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackLeftShoot3.png index 55b416a..729b637 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackLeftShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackLeftShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackRightShoot1.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackRightShoot1.png index 88af064..14dbf49 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackRightShoot1.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackRightShoot1.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackRightShoot2.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackRightShoot2.png index 3005b9f..cbdb64a 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackRightShoot2.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackRightShoot2.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackRightShoot3.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackRightShoot3.png index 1ba9e13..bfd0541 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackRightShoot3.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGShooting/Shooting/BlueShootingBackRightShoot3.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueBackLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueBackLeft.png deleted file mode 100644 index 79fbcdd..0000000 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueBackLeft.png and /dev/null differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueBackRight.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueBackRight.png index 10bf254..b99b838 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueBackRight.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueBackRight.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueFrontLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueFrontLeft.png deleted file mode 100644 index c66ec21..0000000 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueFrontLeft.png and /dev/null differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueFrontRight.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueFrontRight.png index 6957dc8..9ac44e6 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueFrontRight.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueFrontRight.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueLeft.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueLeft.png index decb952..88e12c1 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueLeft.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueLeft.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueLeftBack.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueLeftBack.png index e6efc82..fb165d2 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueLeftBack.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueLeftBack.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueRight.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueRight.png index abb089e..610f547 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueRight.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueRight.png differ diff --git a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueRightBack.png b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueRightBack.png index 16349c8..f7b7664 100644 Binary files a/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueRightBack.png and b/SQCSim2021/media/textures/AssetOtherPlayer/FinalPNGStanding/BlueRightBack.png differ diff --git a/SQCSim2021/media/textures/Booster/BoosterVert.png b/SQCSim2021/media/textures/Booster/BoosterVert.png new file mode 100644 index 0000000..b731b74 Binary files /dev/null and b/SQCSim2021/media/textures/Booster/BoosterVert.png differ diff --git a/SQCSim2021/media/textures/Bouton/BasicPlay.png b/SQCSim2021/media/textures/Bouton/BasicPlay.png deleted file mode 100644 index 109f65a..0000000 Binary files a/SQCSim2021/media/textures/Bouton/BasicPlay.png and /dev/null differ diff --git a/SQCSim2021/media/textures/Bouton/BasicQuit.png b/SQCSim2021/media/textures/Bouton/BasicQuit.png deleted file mode 100644 index db7ad29..0000000 Binary files a/SQCSim2021/media/textures/Bouton/BasicQuit.png and /dev/null differ diff --git a/SQCSim2021/media/textures/BrouillonbackgroundMenu.png b/SQCSim2021/media/textures/BrouillonbackgroundMenu.png deleted file mode 100644 index ba8631c..0000000 Binary files a/SQCSim2021/media/textures/BrouillonbackgroundMenu.png and /dev/null differ diff --git a/SQCSim2021/media/textures/greengrass.png b/SQCSim2021/media/textures/greengrass.png new file mode 100644 index 0000000..71350e6 Binary files /dev/null and b/SQCSim2021/media/textures/greengrass.png differ diff --git a/SQCSim2021/media/textures/menus/backgrounds/bgLobby.png b/SQCSim2021/media/textures/menus/backgrounds/bgLobby.png new file mode 100644 index 0000000..fab6550 Binary files /dev/null and b/SQCSim2021/media/textures/menus/backgrounds/bgLobby.png differ diff --git a/SQCSim2021/media/textures/single_multi.png b/SQCSim2021/media/textures/menus/backgrounds/bgMainMenu.png similarity index 100% rename from SQCSim2021/media/textures/single_multi.png rename to SQCSim2021/media/textures/menus/backgrounds/bgMainMenu.png diff --git a/SQCSim2021/media/textures/menus/backgrounds/bgOptions.png b/SQCSim2021/media/textures/menus/backgrounds/bgOptions.png new file mode 100644 index 0000000..3a8dc45 Binary files /dev/null and b/SQCSim2021/media/textures/menus/backgrounds/bgOptions.png differ diff --git a/SQCSim2021/media/textures/menus/backgrounds/bgPause.png b/SQCSim2021/media/textures/menus/backgrounds/bgPause.png new file mode 100644 index 0000000..c236e26 Binary files /dev/null and b/SQCSim2021/media/textures/menus/backgrounds/bgPause.png differ diff --git a/SQCSim2021/media/textures/sc2.png b/SQCSim2021/media/textures/menus/backgrounds/bgSplash.png similarity index 100% rename from SQCSim2021/media/textures/sc2.png rename to SQCSim2021/media/textures/menus/backgrounds/bgSplash.png diff --git a/SQCSim2021/media/textures/menus/buttons/main/mainBack.png b/SQCSim2021/media/textures/menus/buttons/main/mainBack.png new file mode 100644 index 0000000..8a0e568 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/main/mainBack.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/main/mainMulti.png b/SQCSim2021/media/textures/menus/buttons/main/mainMulti.png new file mode 100644 index 0000000..502891a Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/main/mainMulti.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/main/mainOptions.png b/SQCSim2021/media/textures/menus/buttons/main/mainOptions.png new file mode 100644 index 0000000..8984ca6 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/main/mainOptions.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/main/mainPlay.png b/SQCSim2021/media/textures/menus/buttons/main/mainPlay.png new file mode 100644 index 0000000..0cfbb14 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/main/mainPlay.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/main/mainQuit.png b/SQCSim2021/media/textures/menus/buttons/main/mainQuit.png new file mode 100644 index 0000000..0c61ab4 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/main/mainQuit.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/main/mainSingle.png b/SQCSim2021/media/textures/menus/buttons/main/mainSingle.png new file mode 100644 index 0000000..6fe2074 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/main/mainSingle.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optAudio.png b/SQCSim2021/media/textures/menus/buttons/options/optAudio.png new file mode 100644 index 0000000..de3bbf4 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optAudio.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optBack.png b/SQCSim2021/media/textures/menus/buttons/options/optBack.png new file mode 100644 index 0000000..03e2563 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optBack.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optGameplay.png b/SQCSim2021/media/textures/menus/buttons/options/optGameplay.png new file mode 100644 index 0000000..687c857 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optGameplay.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optGraphics.png b/SQCSim2021/media/textures/menus/buttons/options/optGraphics.png new file mode 100644 index 0000000..8aa8b66 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optGraphics.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optMain.png b/SQCSim2021/media/textures/menus/buttons/options/optMain.png new file mode 100644 index 0000000..c9e1098 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optMain.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optMusic.png b/SQCSim2021/media/textures/menus/buttons/options/optMusic.png new file mode 100644 index 0000000..c6f4d57 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optMusic.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optOptions.png b/SQCSim2021/media/textures/menus/buttons/options/optOptions.png new file mode 100644 index 0000000..5c15729 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optOptions.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optResolution.png b/SQCSim2021/media/textures/menus/buttons/options/optResolution.png new file mode 100644 index 0000000..8003a75 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optResolution.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optSensitivity.png b/SQCSim2021/media/textures/menus/buttons/options/optSensitivity.png new file mode 100644 index 0000000..b8af10f Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optSensitivity.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optSfx.png b/SQCSim2021/media/textures/menus/buttons/options/optSfx.png new file mode 100644 index 0000000..43babb6 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optSfx.png differ diff --git a/SQCSim2021/media/textures/menus/labels/labelFhd.png b/SQCSim2021/media/textures/menus/labels/labelFhd.png new file mode 100644 index 0000000..0e78428 Binary files /dev/null and b/SQCSim2021/media/textures/menus/labels/labelFhd.png differ diff --git a/SQCSim2021/media/textures/menus/labels/labelHd.png b/SQCSim2021/media/textures/menus/labels/labelHd.png new file mode 100644 index 0000000..9594d91 Binary files /dev/null and b/SQCSim2021/media/textures/menus/labels/labelHd.png differ diff --git a/SQCSim2021/media/textures/menus/labels/labelIdentify.png b/SQCSim2021/media/textures/menus/labels/labelIdentify.png new file mode 100644 index 0000000..6656fd9 Binary files /dev/null and b/SQCSim2021/media/textures/menus/labels/labelIdentify.png differ diff --git a/SQCSim2021/media/textures/menus/labels/labelQhd.png b/SQCSim2021/media/textures/menus/labels/labelQhd.png new file mode 100644 index 0000000..1da6626 Binary files /dev/null and b/SQCSim2021/media/textures/menus/labels/labelQhd.png differ diff --git a/SQCSim2021/media/textures/menus/labels/labelServer.png b/SQCSim2021/media/textures/menus/labels/labelServer.png new file mode 100644 index 0000000..33c0652 Binary files /dev/null and b/SQCSim2021/media/textures/menus/labels/labelServer.png differ diff --git a/SQCSim2021/media/textures/title.png b/SQCSim2021/media/textures/menus/labels/labelTitle.png similarity index 100% rename from SQCSim2021/media/textures/title.png rename to SQCSim2021/media/textures/menus/labels/labelTitle.png diff --git a/SQCSim2021/media/textures/menus/labels/labelUhd.png b/SQCSim2021/media/textures/menus/labels/labelUhd.png new file mode 100644 index 0000000..696a558 Binary files /dev/null and b/SQCSim2021/media/textures/menus/labels/labelUhd.png differ diff --git a/SQCSim2021/media/textures/menus/others/check.png b/SQCSim2021/media/textures/menus/others/check.png new file mode 100644 index 0000000..9b3968b Binary files /dev/null and b/SQCSim2021/media/textures/menus/others/check.png differ diff --git a/SQCSim2021/media/textures/menus/others/checked.png b/SQCSim2021/media/textures/menus/others/checked.png new file mode 100644 index 0000000..2debe55 Binary files /dev/null and b/SQCSim2021/media/textures/menus/others/checked.png differ diff --git a/SQCSim2021/mesh.h b/SQCSim2021/mesh.h index 0a070ff..138d0e2 100644 --- a/SQCSim2021/mesh.h +++ b/SQCSim2021/mesh.h @@ -15,7 +15,7 @@ private: Chunk* m_chunk; // NE PAS DÉTRUIRE ICI. void AddBlockToMesh(VertexBuffer::VertexData* vd, int& count, BlockType bt, int x, int y, int z, float u, float v, float s, World* world); - + void RemoveChunk(int nbReduit); public: Mesh(Chunk* chunk); ~Mesh(); diff --git a/SQCSim2021/openglcontext.cpp b/SQCSim2021/openglcontext.cpp index 7a61b07..f0263cd 100644 --- a/SQCSim2021/openglcontext.cpp +++ b/SQCSim2021/openglcontext.cpp @@ -15,9 +15,9 @@ bool OpenglContext::Start(const std::string& title, int width, int height, bool m_title = title; m_fullscreen = fullscreen; InitWindow(width, height); - - Init(); + LoadResource(); + Init(); sf::Clock clock; diff --git a/SQCSim2021/openglcontext.h b/SQCSim2021/openglcontext.h index 3825b26..2718540 100644 --- a/SQCSim2021/openglcontext.h +++ b/SQCSim2021/openglcontext.h @@ -52,6 +52,8 @@ protected: void HideCursor(); void ShowCrossCursor() const; + bool m_istarted = false; + private: void InitWindow(int width, int height); MOUSE_BUTTON ConvertMouseButton(sf::Mouse::Button button) const; diff --git a/SQCSim2021/remoteplayer.cpp b/SQCSim2021/remoteplayer.cpp new file mode 100644 index 0000000..47bd809 --- /dev/null +++ b/SQCSim2021/remoteplayer.cpp @@ -0,0 +1,339 @@ +#include "remoteplayer.h" +#include +#include + +#include +#include + + + + +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() +{ + +} + +void RemotePlayer::Init() +{ + +} + +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; +} + + + + +void RemotePlayer::Render(TextureAtlas& atlas, Shader& shader, Transformation tran, float elapsedTime, Player& camera) +{ + + float width = 1.f; + float height = 1.7f; + + Vector3f DiffCam = GetPosition() - camera.GetPosition(); + Vector3f UpCam = Vector3f(0.f, 1.f, 0.f); + + Vector3f CrossA = DiffCam.Cross(UpCam); + Vector3f CrossB = DiffCam.Cross(CrossA); + + CrossA.Normalize(); + CrossB.Normalize(); + + Vector3f playerPosition = GetPosition() + Vector3f(0.f, -.75f, 0.f); + + Vector3f v2 = (playerPosition + CrossA * 0.5 * width + CrossB * 0.5 * height); + Vector3f v1 = (playerPosition - CrossA * 0.5 * width + CrossB * 0.5 * height); + Vector3f v3 = (playerPosition + CrossA * 0.5 * width - CrossB * 0.5 * height); + Vector3f v4 = (playerPosition - CrossA * 0.5 * width - CrossB * 0.5 * height); + + Vector3f angleRemote = GetDirection(); + Vector3f angleCam = (v1 - v2).Cross(v3 - v2); + + angleCam.y = 0; + angleRemote.y = 0; + angleCam.Normalize(); + angleRemote.Normalize(); + + float angle = angleRemote.Dot(angleCam); + int index = 0; + angle = -angle; + Vector3f side = angleRemote.Cross(angleCam); + + static float time = 0.f; + static bool Shooting = false; + bool isLeft = side.y > 0; + + time += elapsedTime; + if (time >= 200) + { + time -= 200; + if (!current.states.shooting) + Shooting = false; + else + Shooting = !Shooting; + } + + + + if (angle >= 0.75) //Face - side positif + { + if(current.states.shooting){ + if (Shooting) + index = 17; + else + index = 9; + } + else if (current.states.jumpshot) { + if (Shooting) + index = 41; + else + index = 33; + } + else if (current.states.jumping) + index = 25; + else if (current.states.running && current.states.still) + index = 0; + + } + else if (angle >= 0.25 && isLeft) //Frontleft + { + if (current.states.shooting) { + if (Shooting) + index = 18; + else + index = 10; + } + else if (current.states.jumpshot) { + if (Shooting) + index = 42; + else + index = 34; + } + else if (current.states.jumping ) + index = 26; + else if (current.states.running && current.states.still) + index = 1; + + } + else if (angle >= -0.25 && isLeft) //ProfileLeft + { + if (current.states.shooting) { + if (Shooting) + index = 20; + else + index = 12; + } + else if (current.states.jumpshot ) { + if (Shooting) + index = 44; + else + index = 36; + } + else if (current.states.jumping ) + index = 28; + else if (current.states.running && current.states.still) + index = 3; + + } + else if (angle >= -0.75 && isLeft) //BackLeft + { + if (current.states.shooting) { + if (Shooting) + index = 22; + else + index = 14; + } + else if (current.states.jumpshot) { + if (Shooting) + index = 46; + else + index = 38; + } + else if (current.states.jumping) + index = 30; + else if (current.states.running && current.states.still) + index = 5; + } + else if (angle < -0.75) //Dos - side négatif + { + if (current.states.shooting) { + if (Shooting) + index = 24; + else + index = 16; + } + else if (current.states.jumpshot) { + if (Shooting) + index = 48; + else + index = 40; + } + else if (current.states.jumping ) + index = 32; + else if (current.states.running && current.states.still) + index = 7; + + } + else if (angle >= 0.25 && !isLeft) //FrontRight + { + if (current.states.shooting) { + if (Shooting) + index = 19; + else + index = 11; + } + else if (current.states.jumpshot) { + if (Shooting) + index = 43; + else + index = 35; + } + else if (current.states.jumping) + index = 27; + else if (current.states.running && current.states.still) + index = 2; + + } + else if (angle >= -0.25 && !isLeft) //ProfileRight + { + if (current.states.shooting) { + if (Shooting) + index = 21; + else + index = 13; + } + else if (current.states.jumpshot) { + if (Shooting) + index = 45; + else + index = 37; + } + else if (current.states.jumping) + index = 29; + else if (current.states.running && current.states.still) + index = 4; + + } + else if (angle >= -0.75 && !isLeft) //BackRight + { + if (current.states.shooting) { + if (Shooting) + index = 23; + else + index = 15; + } + else if (current.states.jumpshot) { + if (Shooting) + index = 47; + else + index = 39; + } + else if (current.states.jumping) + index = 31; + else if (current.states.running && current.states.still) + index = 6; + + } + + + + float u, v, w, h; + + shader.Use(); + atlas.Bind(); + atlas.TextureIndexToCoord(index, u, v, w, h); + + glEnable(GL_BLEND); + 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); + glTexCoord2f(u + w, v); glVertex3f(v2.x, v2.y, v2.z); + glTexCoord2f(u + w, v + h); glVertex3f(v3.x, v3.y, v3.z); + glTexCoord2f(u, v + h); glVertex3f(v4.x, v4.y, v4.z); + + glEnd(); + + glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); + glBlendEquation(GL_FUNC_SUBTRACT); + glDisable(GL_BLEND); + + shader.Disable(); + +} + +bool RemotePlayer::LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps, bool stopOnError) +{ + texture.Load(filename, useMipmaps); + if (!texture.IsValid()) { + std::cerr << "Unable to load texture (" << filename << ")" << std::endl; + if (stopOnError) + return false; + + return false; + } + + return true; +} diff --git a/SQCSim2021/remoteplayer.h b/SQCSim2021/remoteplayer.h new file mode 100644 index 0000000..fcd5626 --- /dev/null +++ b/SQCSim2021/remoteplayer.h @@ -0,0 +1,42 @@ +#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" +#include "texture.h" +#include "openglcontext.h" +#include "vertexbuffer.h" +#include "../SQCSim-common/matrix4.h" + +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(); + + + void Init(); + void Feed(const netprot::Output out); + void Render(TextureAtlas& atlas, Shader& shader, Transformation tran, float elapsedTime, Player& camera); + bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps, bool stopOnError); + + void SetPosition(Vector3f pos) { m_position = pos; } + +private: + netprot::Output current, previous; + std::map m_outbuf; + netprot::PlayerInfo m_pinfo; + float m_aminacc; + Anim m_animstate; + uint64_t m_team_id; + Texture m_texture_front; + + + + +}; +#endif \ No newline at end of file diff --git a/SQCSim2021/worldrenderer.cpp b/SQCSim2021/renderer.cpp similarity index 72% rename from SQCSim2021/worldrenderer.cpp rename to SQCSim2021/renderer.cpp index e4e0333..3e5fc97 100644 --- a/SQCSim2021/worldrenderer.cpp +++ b/SQCSim2021/renderer.cpp @@ -1,13 +1,44 @@ -#include "worldrenderer.h" +#include "renderer.h" +#include +#include -WorldRenderer::WorldRenderer() { +#include +#include + +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::RemoveChunk(int nbReduit) +{ + for (int x = 0; x < WORLD_SIZE_X; ++x) + for (int y = 0; y < WORLD_SIZE_Y; ++y) + { + Mesh* chk = nullptr; + if (x < nbReduit) + chk = m_meshes.Remove(x, y); + if (y < nbReduit) + chk = m_meshes.Remove(x, y); + if (y > WORLD_SIZE_Y - nbReduit) + chk = m_meshes.Remove(x, y); + if (x > WORLD_SIZE_X - nbReduit) + chk = m_meshes.Remove(x, y); + + // TODO: MakeDirty() les voisins pour qu'ils se redessinent. + + if (!chk) + continue; + + delete chk; + } + + +} + +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; @@ -18,7 +49,7 @@ void WorldRenderer::RenderWorld(World* origin, int& rendercount, const Vector3f& direct.Normalize(); pos.y = 1; - static Vector3 renderManifest[VIEW_DISTANCE * 8]; // Nombre de Chunks maximal à être rendus. + static Vector3 renderManifest[VIEW_DISTANCE * 8]; // Nombre de Chunks maximal � �tre rendus. //for (int dist = VIEW_DISTANCE; dist >= 0; dist -= CHUNK_SIZE_X) { for (int dist = 0; dist <= VIEW_DISTANCE; dist += CHUNK_SIZE_X) { @@ -27,18 +58,18 @@ void WorldRenderer::RenderWorld(World* origin, int& rendercount, const Vector3f& int echantillons; if (dist > VIEW_DISTANCE * .1f) { - sinus = .00872653549f; // sin(1/2 degré) - cosinus = .99996192306; // cos(1/2 degré) + sinus = .00872653549f; // sin(1/2 degr�) + cosinus = .99996192306; // cos(1/2 degr�) echantillons = 180; } //else {//if (dist > VIEW_DISTANCE * .3f) { - // sinus = .01151891831f; // sin(2/3 degré) - // cosinus = .99993365506; // cos(2/3 degré) + // sinus = .01151891831f; // sin(2/3 degr�) + // cosinus = .99993365506; // cos(2/3 degr�) // echantillons = 120; //} //else if (dist > VIEW_DISTANCE * .2f) { - // sinus = .01745240643; // sin(1 degré) - // cosinus = .99984769515; // cos(1 degré) + // sinus = .01745240643; // sin(1 degr�) + // cosinus = .99984769515; // cos(1 degr�) // echantillons = 90; //} //else if (dist > VIEW_DISTANCE * .1f) { @@ -72,7 +103,7 @@ void WorldRenderer::RenderWorld(World* origin, int& rendercount, const Vector3f& bool valide = true; unsigned int chx, chy; origin->ChunkAt(cursor)->GetPosition(chx, chy); - for (int index = 0; index < rendercount; ++index) // Permet de vérifier seulement contre celles ajoutées dans la frame, et ne pas avoir à refaire l'array à chaque frame. + for (int index = 0; index < rendercount; ++index) // Permet de v�rifier seulement contre celles ajout�es dans la frame, et ne pas avoir � refaire l'array � chaque frame. if (renderManifest[index].x == chx && renderManifest[index].z == chy) valide = false; @@ -105,9 +136,10 @@ void WorldRenderer::RenderWorld(World* origin, int& rendercount, const Vector3f& } shader.Disable(); 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; @@ -212,3 +244,34 @@ void WorldRenderer::UpdateWorld(World* origin, const Vector3f& player, BlockInfo } } +void Renderer::RenderBillboard(const Vector3f pos, TextureAtlas textureAtlas, TextureAtlas::TextureIndex idx, Shader& shader, Transformation tran) +{ + //float x = pos.x; + //float y = pos.y; + //float z = pos.z; + //float width = 1.0f; + //float height = 1.0f; + + //float u, v, w, h; + //shader.Use(); + //textureAtlas.Bind(); + //textureAtlas.TextureIndexToCoord(idx, u, v, w, h); + + //glLoadMatrixf(tran.GetMatrix().GetInternalValues()); + //glBegin(GL_QUADS); + //glTexCoord2f(u, v); glVertex3f(x - width / 2., y - height, z); //glVertex3f(v4.x, v4.y, v4.z);//glVertex3f(0, 50, 0); + //glTexCoord2f(u + w, v); glVertex3f(x + width / 2., y - height, z); //glVertex3f(v3.x, v3.y, v3.z); //glVertex3f(50,50, 0); + //glTexCoord2f(u + w, v + h); glVertex3f(x + width / 2., y, z); //glVertex3f(v2.x, v2.y, v2.z); //glVertex3f(50, 0, 0); + //glTexCoord2f(u, v + h); glVertex3f(x - width / 2., y, z); //glVertex3f(v1.x, v1.y, v1.z);// glVertex3f(0, 0, 0); + //glEnd(); + //shader.Disable(); +} + + + +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..5a13709 --- /dev/null +++ b/SQCSim2021/renderer.h @@ -0,0 +1,38 @@ +#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" +#include "openglcontext.h" +#include "vertexbuffer.h" +#include "../SQCSim-common/matrix4.h" + +class Renderer { +private: + Array2d m_meshes = Array2d(WORLD_SIZE_X, WORLD_SIZE_Y); + + TextureAtlas* m_playertext = nullptr; + Shader* m_playershader = nullptr; + bool test = true; + +public: + Renderer(); + ~Renderer(); + + void RemoveChunk(int nbReduit); + + void UpdateMesh(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]); + + void RenderBillboard(const Vector3f pos, TextureAtlas textureAtlas, TextureAtlas::TextureIndex idx, Shader& shader, Transformation tran); + + 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/settings.cpp b/SQCSim2021/settings.cpp new file mode 100644 index 0000000..b84effc --- /dev/null +++ b/SQCSim2021/settings.cpp @@ -0,0 +1,146 @@ +#include "settings.h" + +Settings::Settings(Audio& audio) + : m_audio(audio), + m_mainVolume(0.5f), + m_musicVolume(0.5f), + m_sfxVolume(0.5f), + m_resolution(FHD), + m_fullscreen(false), + m_brightness(0.5f), + m_contrast(0.5f), + m_mouseSensitivity(0.5f) { + ApplyResolution(m_resolution); +} + +void Settings::SaveFile(const std::string& filename) { + std::ofstream file(filename); + if (!file.is_open()) { + std::cerr << "Failed to open file for saving parameters" << std::endl; + return; + } + + file << m_mainVolume << '\n'; + file << m_musicVolume << '\n'; + file << m_sfxVolume << '\n'; + + file << static_cast(m_resolution) << '\n'; + file << m_fullscreen << '\n'; + file << m_brightness << '\n'; + file << m_contrast << '\n'; + + file << m_mouseSensitivity << '\n'; + + file.close(); +} + +void Settings::LoadFile(const std::string& filename) { + std::ifstream file(filename); + if (!file.is_open()) { + std::cerr << "Failed to open file for loading parameters" << std::endl; + return; + } + + file >> m_mainVolume; + file >> m_musicVolume; + file >> m_sfxVolume; + + int resolutionValue; + file >> resolutionValue; + m_resolution = static_cast(resolutionValue); + + file >> m_fullscreen; + file >> m_brightness; + file >> m_contrast; + + file >> m_mouseSensitivity; + + file.close(); +} + +float Settings::GetMainVolume() const { + return m_mainVolume; +} + +void Settings::SetMainVolume(float volume) { + m_mainVolume = volume; +} + +void Settings::GetMusicVolume() { + m_musicVolume = m_audio.GetMusicVolume(); +} + +void Settings::SetMusicVolume(float volume) { + m_musicVolume = volume; +} + +float Settings::GetSfxVolume() const { + return m_sfxVolume; +} + +void Settings::SetSfxVolume(float volume) { + m_sfxVolume = volume; +} + +float Settings::GetBrightness() const { + return m_brightness; +} + +void Settings::SetBrightness(float brightness) { + m_brightness = brightness; +} + +float Settings::GetContrast() const { + return m_contrast; +} + +void Settings::SetContrast(float contrast) { + m_contrast = contrast; +} + +bool Settings::GetFullscreen() const { + return m_fullscreen; +} + +void Settings::SetFullscreen(bool fullscreen) { + m_fullscreen = fullscreen; +} + +const Resolution& Settings::GetResolution() const { + return m_resolution; +} + +void Settings::SetResolution(const Resolution& resolution) { + m_resolution = resolution; +} + +float Settings::GetMouseSensitivity() const { + return m_mouseSensitivity; +} + +void Settings::SetMouseSensitivity(float sensitivity) { + m_mouseSensitivity = sensitivity; +} + +void Settings::ApplyResolution(Resolution resolution) { + switch (resolution) { + case HD: + m_rezWidth = 1280; + m_rezHeight = 720; + break; + case FHD: + m_rezWidth = 1920; + m_rezHeight = 1080; + break; + case QHD: + m_rezWidth = 2560; + m_rezHeight = 1440; + break; + case UHD: + m_rezWidth = 3840; + m_rezHeight = 2160; + break; + default: + break; + } +} diff --git a/SQCSim2021/settings.h b/SQCSim2021/settings.h new file mode 100644 index 0000000..e871529 --- /dev/null +++ b/SQCSim2021/settings.h @@ -0,0 +1,70 @@ +#ifndef SETTINGS_H__ +#define SETTINGS_H__ + +#include +#include +#include +#include +#include + +#include "define.h" +#include "audio.h" + +class Settings { +public: + Settings(Audio& audio); + + void SaveFile(const std::string& filename); + void LoadFile(const std::string& filename); + + // Audio + float GetMainVolume() const; + void SetMainVolume(float volume); + + void GetMusicVolume(); + void SetMusicVolume(float volume); + + float GetSfxVolume() const; + void SetSfxVolume(float volume); + + // Graphic + float GetBrightness() const; + void SetBrightness(float brightness); + + float GetContrast() const; + void SetContrast(float contrast); + + bool GetFullscreen() const; + void SetFullscreen(bool fullscreen); + + const Resolution& GetResolution() const; + void SetResolution(const Resolution& resolution); + + // Gameplay + float GetMouseSensitivity() const; + void SetMouseSensitivity(float sensitivity); + + void ApplyResolution(Resolution resolution); + +private: + + Audio& m_audio; + // Audio + float m_mainVolume; + float m_musicVolume; + float m_sfxVolume; + + // Graphic + Resolution m_resolution; + bool m_fullscreen; + int m_rezWidth; + int m_rezHeight; + float m_brightness; + float m_contrast; + + // Gameplay + float m_mouseSensitivity; +}; + + +#endif // PARAMETERS_H \ No newline at end of file diff --git a/SQCSim2021/textureatlas.cpp b/SQCSim2021/textureatlas.cpp index d293c84..ccefd2c 100644 --- a/SQCSim2021/textureatlas.cpp +++ b/SQCSim2021/textureatlas.cpp @@ -40,6 +40,9 @@ TextureAtlas::TextureIndex TextureAtlas::AddTexture(const std::string& fname) { } bool TextureAtlas::Generate(int textureSize, bool mipmap) { + + + // TODO mipmap pas encore 100% parfait... assert(!mipmap); @@ -66,6 +69,8 @@ bool TextureAtlas::Generate(int textureSize, bool mipmap) { ilOriginFunc(IL_ORIGIN_LOWER_LEFT); ilEnable(IL_ORIGIN_SET); + ilEnable(IL_ALPHA); + ilEnable(IL_BLIT_BLEND); if (!ilLoadImage((const ILstring)it->first.c_str())) return false; @@ -170,8 +175,10 @@ bool TextureAtlas::Generate(int textureSize, bool mipmap) { mipmapSize /= 2; } + m_isValid = true; return true; + } 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