diff --git a/include/Engine/Network/Client.h b/include/Engine/Network/Client.h index f79feb8d..a4c2e229 100644 --- a/include/Engine/Network/Client.h +++ b/include/Engine/Network/Client.h @@ -36,6 +36,7 @@ #include "Network/ESearchForServers.h" #include "Network/EInterpolate.h" #include "Network/SnapshotFilter.h" +#include "Core/EWin.h" class Client : public Network { @@ -107,6 +108,7 @@ private: void parseAmmoPickup(Packet& packet); void parseRemoveWorld(Packet& packet); void parseKDEvent(Packet& packet); + void parseWin(Packet& packet); void InterpolateFields(Packet& packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType); void parseSnapshot(Packet& packet); void identifyPacketLoss(); diff --git a/include/Engine/Network/MessageType.h b/include/Engine/Network/MessageType.h index 53821084..d69b468b 100644 --- a/include/Engine/Network/MessageType.h +++ b/include/Engine/Network/MessageType.h @@ -25,6 +25,7 @@ enum class MessageType AmmoPickup, RemoveWorld, KD, + Win, Invalid }; diff --git a/include/Engine/Sound/SoundManager.h b/include/Engine/Sound/SoundManager.h index 894ed5bf..30e51e1b 100644 --- a/include/Engine/Sound/SoundManager.h +++ b/include/Engine/Sound/SoundManager.h @@ -81,6 +81,7 @@ private: void setSoundProperties(Source* source, ComponentWrapper* soundComponent); float getDurationSeconds(Source* source); float getTimeOffsetSeconds(Source* source); + void setTimeOffsetSeconds(Source* source, float timeOffset); // Specific logic void playSound(Source* source); diff --git a/src/Engine/Network/Client.cpp b/src/Engine/Network/Client.cpp index 381c606d..637ffe8b 100644 --- a/src/Engine/Network/Client.cpp +++ b/src/Engine/Network/Client.cpp @@ -176,6 +176,9 @@ void Client::parseMessageType(Packet& packet) case MessageType::KD: parseKDEvent(packet); break; + case MessageType::Win: + parseWin(packet); + break; default: break; } @@ -376,6 +379,13 @@ void Client::parseKDEvent(Packet & packet) m_EventBroker->Publish(e); } +void Client::parseWin(Packet& packet) +{ + Events::Win e; + e.TeamThatWon = packet.ReadPrimitive(); + m_EventBroker->Publish(e); +} + void Client::updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID) { for (auto field : componentInfo.FieldsInOrder) { diff --git a/src/Engine/Network/Server.cpp b/src/Engine/Network/Server.cpp index dbaf4752..3ec73969 100644 --- a/src/Engine/Network/Server.cpp +++ b/src/Engine/Network/Server.cpp @@ -609,6 +609,9 @@ bool Server::OnWin(const Events::Win & e) { // Postpone the gameover reset m_GameIsOver = true; + Packet winPacket = Packet(MessageType::Win); + winPacket.WritePrimitive(e.TeamThatWon); + reliableBroadcast(winPacket); return true; } diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index edc96cb7..8db7e7d3 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -75,7 +75,7 @@ void Renderer::InitializeWindow() //glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); //glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); glfwWindowHint(GLFW_DECORATED, false); - glfwWindowHint(GLFW_AUTO_ICONIFY, false); + //glfwWindowHint(GLFW_AUTO_ICONIFY, false); } //glfwWindowHint(GLFW_SAMPLES, 8); @@ -167,17 +167,21 @@ void Renderer::Draw(RenderFrame& frame) { GLERROR("PRE"); glBindFramebuffer(GL_FRAMEBUFFER, 0); +#ifdef DEBUG ImGui::Combo("Draw textures", &m_DebugTextureToDraw, "Final\0Scene\0Bloom\0Gaussian\0Picking\0Ambient Occlusion\0Combined Scene Texture\0Full Blurred Texture"); ImGui::Combo("CubeMap", &m_CubeMapTexture, "Nevada(512)\0Sky(1024)"); +#endif if(m_CubeMapTexture == 0) { m_CubeMapPass->LoadTextures("Nevada"); } else if (m_CubeMapTexture == 1) { m_CubeMapPass->LoadTextures("Sky"); } +#ifdef DEBUG ImGui::SliderInt("SSAO Quality", &m_SSAO_Quality, 0, 3); ImGui::SliderInt("Glow Quality", &m_GLOW_Quality, 0, 3); ImGui::SliderInt("MSAA Level", (int*)&m_MSAA_Level, 0, 16); +#endif m_SSAOPass->ChangeQuality(m_SSAO_Quality); m_DrawBloomPass->ChangeQuality(m_GLOW_Quality); m_DrawFinalPass->setMSAA(m_MSAA_Level); diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index bfd2a863..9aff0266 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -25,11 +25,13 @@ ShadowPass::~ShadowPass() void ShadowPass::DebugGUI() { +#ifdef DEBUG ImGui::Checkbox("EnableShadows", &m_EnableShadows); ImGui::DragFloat2("ShadowMapNearFar", m_NearFarPlane, 1.f, -1000.f, 1000.f); ImGui::DragFloat("ShadowClippingWeight", &m_SplitWeight, 0.001f, 0.f, 1.f); ImGui::Checkbox("ShadowTransparentObjects", &m_TransparentObjects); ImGui::Checkbox("ShadowOnTextureAlphas", &m_TexturedShadows); +#endif } void ShadowPass::InitializeCameras(RenderScene & scene) diff --git a/src/Engine/Sound/SoundManager.cpp b/src/Engine/Sound/SoundManager.cpp index 803aadf2..a8161f5d 100644 --- a/src/Engine/Sound/SoundManager.cpp +++ b/src/Engine/Sound/SoundManager.cpp @@ -417,6 +417,14 @@ bool SoundManager::OnSetCamera(const Events::SetCamera& e) alSourcei(m_CurrentBGMCombo->ALsource, AL_LOOPING, 1); setGain(m_CurrentBGMCombo, 0); playSound(m_CurrentBGMCombo); + } else if (m_World->HasComponent(e.CameraEntity.ID, "EndScreen")) { + float timeOffset = getTimeOffsetSeconds(m_CurrentBGM); + stopSound(m_CurrentBGM); + m_CurrentBGM = createSource("Audio/BGM/Layer3.wav"); + m_CurrentBGM->Type = SoundType::BGM; + alSourcei(m_CurrentBGM->ALsource, AL_LOOPING, 1); + playSound(m_CurrentBGM); + setTimeOffsetSeconds(m_CurrentBGM, timeOffset); } } @@ -477,6 +485,11 @@ float SoundManager::getTimeOffsetSeconds(Source* source) return time; } +void SoundManager::setTimeOffsetSeconds(Source * source, float timeOffset) +{ + alSourcef(source->ALsource, AL_SEC_OFFSET, timeOffset); +} + void SoundManager::initOpenAL() { // Initialize OpenAL diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index d2a8594a..1f5050e2 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -202,12 +202,18 @@ void PlayerMovementSystem::updateMovementControllers(double dt) if (addSpeed > 0) { static float accel = 15.f; +#ifdef DEBUG ImGui::InputFloat("accel", &accel); +#endif static float airAccel = 0.5f; +#ifdef DEBUG ImGui::InputFloat("airAccel", &airAccel); +#endif float actualAccel = isOnGround ? accel : airAccel; static float surfaceFriction = 5.f; +#ifdef DEBUG ImGui::InputFloat("surfaceFriction", &surfaceFriction); +#endif float accelerationSpeed = actualAccel * (float)dt * wishSpeed * surfaceFriction; //if doubleTapped do Assault Dash - but only boost maximum 50.0f float doubleTapDashBoost = controller->AssaultDashDoubleTapped() ? 40.0f : 1.0f; @@ -220,7 +226,9 @@ void PlayerMovementSystem::updateMovementControllers(double dt) accelerationSpeed *= (double)player["SprintAbility"]["StrengthOfEffect"]; } velocity += accelerationSpeed * (glm::vec3)wishDirection; +#ifdef DEBUG ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x(), velocity.y(), velocity.z(), glm::length((glm::vec3)velocity)); +#endif } if (isOnGround) { @@ -336,10 +344,14 @@ void PlayerMovementSystem::updateVelocity(EntityWrapper player, double dt) // Ground friction float speed = glm::length((glm::vec3)velocity); static float groundFriction = 7.f; +#ifdef DEBUG ImGui::InputFloat("groundFriction", &groundFriction); +#endif static float airFriction = 2.f; +#ifdef DEBUG ImGui::InputFloat("airFriction", &airFriction); +#endif float friction = isOnGround ? groundFriction : airFriction; if (speed > 0) { float drop = speed * friction * (float)dt; diff --git a/src/Game/Systems/SoundSystem.cpp b/src/Game/Systems/SoundSystem.cpp index 999e1fc9..6db01305 100644 --- a/src/Game/Systems/SoundSystem.cpp +++ b/src/Game/Systems/SoundSystem.cpp @@ -87,6 +87,9 @@ bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e) if (!e.Victim.Valid() || !e.Inflictor.Valid()) { return false; } + if (e.Victim.ID != LocalPlayer.ID) { + return false; + } auto victimTeam = m_World->GetComponent(e.Victim.ID, "Team"); auto inflictorTeam = m_World->GetComponent(e.Inflictor.ID, "Team"); if ((int)victimTeam["Team"] == (int)inflictorTeam["Team"]) { diff --git a/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp b/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp index d6293bca..5a334369 100644 --- a/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp +++ b/src/Game/Systems/Weapon/AssaultWeaponBehaviour.cpp @@ -14,7 +14,19 @@ void AssaultWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& // Start reloading automatically if at 0 mag ammo Field magAmmo = cWeapon["MagazineAmmo"]; if (m_ConfigAutoReload && magAmmo <= 0) { - OnReload(cWeapon, wi); + //OnReload(cWeapon, wi); + // Send an input command instead of reloading immediately so the server + // has a chance to catch up. + if (IsClient) { + Events::InputCommand e; + e.Player = wi.Player; + e.PlayerID = -1; + e.Command = "Reload"; + e.Value = 1; + m_EventBroker->Publish(e); + e.Value = 0; + m_EventBroker->Publish(e); + } } // Only start reloading once we're done firing