Merge branch 'master' into SQC-31
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "engine.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
@@ -11,12 +13,13 @@ struct Notification {
|
||||
float displayStartTime = 0.0f;
|
||||
};
|
||||
|
||||
|
||||
// Use a queue to manage notifications
|
||||
//std::queue<Notification> notificationQueue;
|
||||
// Use a vector to manage notifications
|
||||
std::vector<Notification> notifications;
|
||||
|
||||
Engine::Engine() {}
|
||||
Engine::Engine() : m_remotePlayer(&m_pinfo), m_pinfo(){}
|
||||
|
||||
Engine::~Engine() {
|
||||
m_world.CleanUpWorld(m_renderCount, true);
|
||||
@@ -322,6 +325,17 @@ void Engine::DrawOption()
|
||||
void Engine::Init() {
|
||||
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
ShowCursor();
|
||||
}
|
||||
|
||||
void Engine::Init() {
|
||||
|
||||
GLenum glewErr = glewInit();
|
||||
if (glewErr != GLEW_OK) {
|
||||
std::cerr << " ERREUR GLEW : " << glewGetErrorString(glewErr) << std::endl;
|
||||
@@ -329,14 +343,13 @@ void Engine::Init() {
|
||||
}
|
||||
|
||||
uint64_t seed = SEED;
|
||||
char ch;
|
||||
|
||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glEnable(GL_POINT_SMOOTH);
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_CULL_FACE);
|
||||
//glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
@@ -349,11 +362,15 @@ void Engine::Init() {
|
||||
glDisable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBlendEquation(GL_FUNC_SUBTRACT);
|
||||
|
||||
|
||||
if (m_istarted)
|
||||
return;
|
||||
else m_istarted = true;
|
||||
|
||||
//
|
||||
// Objet de skybox avec sa propre texture et son propre shader!
|
||||
m_skybox.Init(0.2f);
|
||||
|
||||
//m_skybox2.Init(1.f);
|
||||
// Objet de musique!
|
||||
//m_audio.ToggleMusicState();
|
||||
|
||||
@@ -363,56 +380,61 @@ void Engine::Init() {
|
||||
m_whoosh[x] = nullptr;
|
||||
}
|
||||
|
||||
std::cout << "Jouer en ligne? [o/N] ";
|
||||
std::cin >> ch;
|
||||
std::cout << std::endl;
|
||||
char* ch = new char[2];
|
||||
|
||||
if (ch == 'o' || ch == 'O') {
|
||||
char* input = new char[32];
|
||||
std::string playname, srvname;
|
||||
std::cout << "Jouer en ligne? [o/N] ";
|
||||
std::cin.getline(ch, 2);
|
||||
std::cout << std::endl;
|
||||
|
||||
while (playname.size() < 1) {
|
||||
std::cout << "Veuillez entrer un nom de joueur: ";
|
||||
std::cin.ignore();
|
||||
std::cin.getline(input, 32);
|
||||
std::cout << std::endl;
|
||||
playname = input;
|
||||
if (playname.size() < 1 || playname.size() > 32)
|
||||
std::puts("Nom invalide.");
|
||||
}
|
||||
while (srvname.size() < 1) {
|
||||
std::cout << "Veuillez entrer une adresse de serveur: ";
|
||||
std::cin.getline(input, 32);
|
||||
std::cout << std::endl;
|
||||
srvname = input;
|
||||
if (srvname.size() < 1 || srvname.size() > 32)
|
||||
std::puts("Adresse serveur invalide.");
|
||||
}
|
||||
delete[] input;
|
||||
if (*ch == 'o' || *ch == 'O') {
|
||||
char* input = new char[32];
|
||||
std::string playname, srvname;
|
||||
|
||||
if (!m_conn.Init()) {
|
||||
if (!m_conn.Connect(srvname.c_str(), playname)) {
|
||||
// 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);
|
||||
|
||||
seed = m_conn.getSeed();
|
||||
m_networkgame = true;
|
||||
}
|
||||
else std::cout << "Erreur de connexion." << std::endl;
|
||||
}
|
||||
else std::cout << "Erreur de creation de socket." << std::endl;
|
||||
while (playname.size() < 1) {
|
||||
std::cout << "Veuillez entrer un nom de joueur: ";
|
||||
std::cin.getline(input, 32);
|
||||
std::cout << std::endl;
|
||||
playname = input;
|
||||
if (playname.size() < 1 || playname.size() > 32)
|
||||
std::puts("Nom invalide.");
|
||||
}
|
||||
while (srvname.size() < 1) {
|
||||
std::cout << "Veuillez entrer une adresse de serveur: ";
|
||||
std::cin.getline(input, 32);
|
||||
std::cout << std::endl;
|
||||
srvname = input;
|
||||
if (srvname.size() < 1 || srvname.size() > 32)
|
||||
std::puts("Adresse serveur invalide.");
|
||||
}
|
||||
delete[] input;
|
||||
|
||||
if (!m_conn.Init()) {
|
||||
if (!m_conn.Connect(srvname.c_str(), playname)) {
|
||||
// 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);
|
||||
|
||||
seed = m_conn.getSeed();
|
||||
m_networkgame = true;
|
||||
}
|
||||
else std::cout << "Erreur de connexion." << std::endl;
|
||||
}
|
||||
else std::cout << "Erreur de creation de socket." << std::endl;
|
||||
}
|
||||
delete[] ch;
|
||||
|
||||
m_world.SetSeed(seed);
|
||||
|
||||
// Init Chunks
|
||||
m_world.GetChunks().Reset(nullptr);
|
||||
|
||||
m_startTime = std::chrono::high_resolution_clock::now();
|
||||
|
||||
m_remotePlayer.SetPosition(Vector3f(.5,CHUNK_SIZE_Y + 10., .5));
|
||||
// Gestion de souris.
|
||||
CenterMouse();
|
||||
HideCursor();
|
||||
@@ -422,6 +444,7 @@ void Engine::DeInit() {}
|
||||
|
||||
void Engine::LoadResource() {
|
||||
LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png", true);
|
||||
//LoadTexture(m_skybox2.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);
|
||||
@@ -434,15 +457,54 @@ void Engine::LoadResource() {
|
||||
|
||||
LoadTexture(MenuTitleTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png");
|
||||
LoadTexture(MenuBGTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png");
|
||||
|
||||
LoadTexture(MenuBGOptionTexture, TEXTURE_PATH "BrouillonbackgroundMenu.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");
|
||||
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
|
||||
|
||||
//JUMP
|
||||
//TextureAtlas::TextureIndex JumpBack = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueBackJumpRight.png");
|
||||
//TextureAtlas::TextureIndex JumpFront = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueFrontJumpRight.png");
|
||||
//TextureAtlas::TextureIndex JumpQuarterBackLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueLeftBackJumpLeft.png");
|
||||
//TextureAtlas::TextureIndex JumpQuarterBackRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueRightBackJumpRight.png");
|
||||
//TextureAtlas::TextureIndex JumpProfiltLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueProfilJumpLeft.png");
|
||||
//TextureAtlas::TextureIndex JumpProfiltRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueProfilJumpRight.png");
|
||||
//TextureAtlas::TextureIndex JumpQuarterFrontLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueLeftFrontJumpLeft.png");
|
||||
//TextureAtlas::TextureIndex JumpQuarterFrontRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueRightFrontJumpRight.png");
|
||||
|
||||
//STILL
|
||||
//TextureAtlas::TextureIndex StillBack = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueBackRight.png");
|
||||
TextureAtlas::TextureIndex StillFront = m_animeAtlas.AddTexture(ANIME_PATH_STILL "BlueFrontRight.png");
|
||||
//TextureAtlas::TextureIndex StillQuarterBackLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueLeftBack.png");
|
||||
//TextureAtlas::TextureIndex StillQuarterBackRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueRightBack.png");
|
||||
//TextureAtlas::TextureIndex StillProfiltLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueProfilLeft.png");
|
||||
//TextureAtlas::TextureIndex StillProfiltRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueProfilRight.png");
|
||||
//TextureAtlas::TextureIndex StillQuarterFrontLeft = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueLeft.png");
|
||||
//TextureAtlas::TextureIndex StillQuarterFrontRight = m_animeAtlas.AddTexture(ANIME_PATH_JUMP "BlueRight.png");
|
||||
|
||||
//SHOOTINGSTILL
|
||||
//SHOOTINGJUMP
|
||||
|
||||
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;
|
||||
@@ -458,6 +520,20 @@ 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)) {
|
||||
@@ -486,6 +562,7 @@ void Engine::SystemNotification(std::string systemLog) {
|
||||
|
||||
DisplayNotification(message);
|
||||
}
|
||||
|
||||
void Engine::KillNotification(Player killer, Player killed) {
|
||||
std::string message = "";
|
||||
|
||||
@@ -768,17 +845,17 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
|
||||
fPosY = fPosYJump;
|
||||
fPosY -= charSize;
|
||||
|
||||
ss << " Velocity : " << m_player.GetVelocity();
|
||||
ss << " Velocity : " << m_remotePlayer.GetVelocity();
|
||||
PrintText(fPosX, fPosY, ss.str());
|
||||
ss.str("");
|
||||
fPosY -= charSize;
|
||||
|
||||
ss << " Direction : " << m_player.GetDirection();
|
||||
ss << " Player Position : " << m_player.GetPosition();
|
||||
PrintText(fPosX, fPosY, ss.str());
|
||||
ss.str("");
|
||||
fPosY -= charSize;
|
||||
|
||||
ss << " Position : " << m_player.GetPosition();
|
||||
ss << " Remote Position : " << m_remotePlayer.GetPosition();//m_player.GetPosition();
|
||||
PrintText(fPosX, fPosY, ss.str());
|
||||
ss.str("");
|
||||
fPosY -= charSize;
|
||||
@@ -841,6 +918,7 @@ void Engine::DisplaySingleOrMultiplayerMenu() {
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
|
||||
// Single Player and Multiplayer button background quads
|
||||
float buttonWidthProportion = 0.4f;
|
||||
float buttonHeightProportion = 0.075f;
|
||||
@@ -928,7 +1006,13 @@ 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;
|
||||
@@ -998,6 +1082,8 @@ int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; }
|
||||
int Engine::GetCountdown(float elapsedTime) {
|
||||
if (m_resetcountdown)
|
||||
{
|
||||
m_nbReductionChunk = 4;
|
||||
m_timerReductionChunk = 30;
|
||||
m_countdown = m_time + COUNTDOWN;
|
||||
m_resetcountdown = false;
|
||||
}
|
||||
@@ -1024,6 +1110,7 @@ void Engine::Render(float elapsedTime) {
|
||||
static irrklang::ISound* step; // Pour les sons de pas.
|
||||
static float pollTime = 0;
|
||||
static float bulletTime = 0;
|
||||
static float gameTime = 0;
|
||||
static BlockType bloc = 1;
|
||||
|
||||
if (elapsedTime > 0.1f) return;
|
||||
@@ -1033,6 +1120,8 @@ void Engine::Render(float elapsedTime) {
|
||||
|
||||
Transformation all;
|
||||
Transformation skybox;
|
||||
Transformation remotePlayer;
|
||||
|
||||
Vector3f vstep;
|
||||
|
||||
// Transformations initiales
|
||||
@@ -1050,11 +1139,11 @@ 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;
|
||||
}
|
||||
@@ -1067,12 +1156,17 @@ 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!).
|
||||
|
||||
m_player.ApplyTransformation(remotePlayer, true, false);
|
||||
|
||||
if (m_key1) bloc++;
|
||||
else if (m_key2) bloc--;
|
||||
|
||||
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 <20>quipe l'arme.
|
||||
m_mouseWU = m_mouseWD = false;
|
||||
m_mouseWU = m_mouseWD = m_key1 = m_key2 = false;
|
||||
|
||||
if (m_mouseL) {
|
||||
if (bloc != BTYPE_LAST)
|
||||
@@ -1095,36 +1189,49 @@ void Engine::Render(float elapsedTime) {
|
||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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_players)) {
|
||||
m_bullets[x]->~Bullet();
|
||||
if (m_whoosh[x])
|
||||
m_whoosh[x]->drop();
|
||||
m_bullets[x] = nullptr;
|
||||
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());
|
||||
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_players)) {
|
||||
m_bullets[x]->~Bullet();
|
||||
if (m_whoosh[x])
|
||||
m_whoosh[x]->drop();
|
||||
m_bullets[x] = nullptr;
|
||||
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_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
|
||||
gameTime += elapsedTime * 10;
|
||||
|
||||
Vector3f dance = Vector3f(sin(gameTime), 0, cos(-gameTime));
|
||||
dance.Normalize();
|
||||
m_remotePlayer.ApplyPhysics(dance, &m_world, elapsedTime);
|
||||
m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo);
|
||||
m_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo);
|
||||
m_remotePlayer.Render(m_animeAtlas, m_shader01, all, elapsedTime);
|
||||
m_booster.RenderBillboard({ 195,16,195 }, m_textureAtlas, m_shader01, all);
|
||||
|
||||
if (m_isSkybox) m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
|
||||
|
||||
//glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
//m_remotePlayer.Render(m_textureAtlas, m_shader01, all, elapsedTime);
|
||||
|
||||
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);
|
||||
|
||||
@@ -1137,7 +1244,7 @@ void Engine::Render(float elapsedTime) {
|
||||
}
|
||||
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);
|
||||
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) {
|
||||
@@ -1145,15 +1252,26 @@ void Engine::Render(float elapsedTime) {
|
||||
fell = false;
|
||||
}
|
||||
|
||||
if (m_networkgame) {
|
||||
static char* buf = new char[BUFFER_LENGTH];
|
||||
uint32_t buflen = BUFFER_LENGTH;
|
||||
netprot::Input input;
|
||||
//sockaddr_in addr = m_conn.m_srvsockaddr;
|
||||
if (m_networkgame) { // Pour se gerer le paquet.
|
||||
using namespace std::chrono;
|
||||
using namespace netprot;
|
||||
Timestamp tstamp = duration_cast<milliseconds>(high_resolution_clock::now() - m_startTime).count();
|
||||
Input input;
|
||||
Sync sync;
|
||||
uint64_t id = m_conn.getId();
|
||||
static std::vector<char*> lsPck;
|
||||
|
||||
if (false) { // TODO: Faire un checkup pour chaque ~1000ms.
|
||||
sync.sid = id;
|
||||
sync.timestamp = tstamp;
|
||||
sync.position = m_player.GetPosition();
|
||||
sync.hp = m_player.GetHP();
|
||||
// TODO: Garrocher ca quelque-part.
|
||||
}
|
||||
|
||||
input.sid = id;
|
||||
input.direction = m_player.GetDirection();
|
||||
input.sid = m_conn.getId();
|
||||
input.timestamp = 12345;
|
||||
input.timestamp = tstamp;
|
||||
input.keys.forward = m_keyW;
|
||||
input.keys.backward = m_keyS;
|
||||
input.keys.left = m_keyA;
|
||||
@@ -1162,10 +1280,37 @@ void Engine::Render(float elapsedTime) {
|
||||
input.keys.block = m_mouseR;
|
||||
input.keys.shoot = m_mouseL;
|
||||
|
||||
//netprot::Serialize(&input, &buf, &buflen);
|
||||
//sendto(m_conn.m_sock_udp, buf, buflen, 0, (sockaddr*)&addr, sizeof(addr));
|
||||
sendPackTo<Input>(m_conn.m_sock_udp, &input, &m_bufout, &m_conn.m_srvsockaddr);
|
||||
|
||||
netprot::sendPackTo<netprot::Input>(m_conn.m_sock_udp, &input, &buf, &buflen, &m_conn.m_srvsockaddr);
|
||||
lsPck = recvPacks(m_conn.m_sock_udp, &m_buf);
|
||||
char* prevptr = nullptr;
|
||||
for (auto& pck : lsPck) { // We could make a few threads out of this.
|
||||
Sync sync;
|
||||
Output out;
|
||||
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())
|
||||
break;
|
||||
// TODO: Vérifier si les positions concordent au sync local.
|
||||
}
|
||||
break;
|
||||
case OUTPUT:
|
||||
if (Deserialize(&out, pck, &bsize)) {
|
||||
RemotePlayer* r = (RemotePlayer*)m_players[out.id];
|
||||
r->Feed(out);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
lsPck.clear();
|
||||
}
|
||||
}
|
||||
else if (m_gamestate == GameState::MAIN_MENU)
|
||||
@@ -1178,6 +1323,10 @@ void Engine::Render(float elapsedTime) {
|
||||
{
|
||||
DrawOption();
|
||||
}
|
||||
else if (m_gamestate == GameState::PAUSE)
|
||||
{
|
||||
DrawPause();
|
||||
}
|
||||
else if (m_gamestate == GameState::QUIT)
|
||||
Stop();
|
||||
}
|
||||
@@ -1205,7 +1354,14 @@ void Engine::KeyPressEvent(unsigned char key) {
|
||||
}
|
||||
break;
|
||||
case 36: // ESC - Quitter
|
||||
m_gamestate = GameState::MAIN_MENU;
|
||||
if (m_gamestate == GameState::PLAY)
|
||||
{
|
||||
m_gamestate = GameState::PAUSE;
|
||||
}
|
||||
else if (m_gamestate == GameState::PAUSE)
|
||||
{
|
||||
m_gamestate = GameState::PLAY;
|
||||
}
|
||||
//Stop();
|
||||
break;
|
||||
case 57: // Space - Sauter
|
||||
@@ -1246,6 +1402,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:
|
||||
@@ -1292,7 +1452,7 @@ void Engine::KeyReleaseEvent(unsigned char key) {
|
||||
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<6D>re balle de l'array.
|
||||
@@ -1320,6 +1480,12 @@ 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 57: // Espace - Stop sauter
|
||||
m_keySpace = false;
|
||||
break;
|
||||
@@ -1442,3 +1608,5 @@ bool Engine::LoadTexture(Texture& texture, const std::string& filename, bool use
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user