diff --git a/include/Engine/Core/ResourceManager.h b/include/Engine/Core/ResourceManager.h index 10529819..b994b5cf 100644 --- a/include/Engine/Core/ResourceManager.h +++ b/include/Engine/Core/ResourceManager.h @@ -200,13 +200,16 @@ static T* ResourceManager::Load(const std::string& resourceName, Resource* paren } //If resource has already been cached and completely loaded. - it = m_ResourceCache.find(cacheKey); - if (it != m_ResourceCache.end()) { - if (it->second != nullptr) { - return static_cast(it->second); - } else { - //Don't return null on failure, exception instead. - throw Resource::FailedLoadingException(); + { + boost::lock_guard guard(m_Mutex); + it = m_ResourceCache.find(cacheKey); + if (it != m_ResourceCache.end()) { + if (it->second != nullptr) { + return static_cast(it->second); + } else { + //Don't return null on failure, exception instead. + throw Resource::FailedLoadingException(); + } } } diff --git a/include/Engine/Input/FirstPersonInputController.h b/include/Engine/Input/FirstPersonInputController.h index d4c9071c..2bbd768d 100644 --- a/include/Engine/Input/FirstPersonInputController.h +++ b/include/Engine/Input/FirstPersonInputController.h @@ -4,6 +4,7 @@ #include "../GLM.h" #include "../Core/InputController.h" #include "../Core/ELockMouse.h" +#include "InputHandler.h" template class FirstPersonInputController : public InputController @@ -25,6 +26,10 @@ public: virtual bool OnCommand(const Events::InputCommand& e) override; virtual void Reset(); + void AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer); + virtual bool AssaultDashDoubleTapped() const { return m_AssaultDashDoubleTapped; } + virtual bool PlayerIsDashing() const { return m_PlayerIsDashing; } + protected: const int m_PlayerID; bool m_MouseLocked = false; @@ -33,6 +38,22 @@ protected: bool m_Jumping = false; bool m_DoubleJumping = false; bool m_Crouching = false; + //assault dash membervariables - needed to calculate the doubletap- and dashlogic + double m_AssaultDashDoubleTapDeltaTime = 0.0; + double m_AssaultDashCoolDownTimer = 0.0; + //i will let m_AssaultDashDoubleTapSensitivityTimer stay hardcoded, its not really a gamevariable (more an inputvariable), + //and its very unlikely that someone wants to change that value + const float m_AssaultDashDoubleTapSensitivityTimer = 0.25f; + std::string m_AssaultDashTapDirection = ""; + std::string m_CurrentDirectionVector = ""; + bool m_AssaultDashDoubleTapped = false; + bool m_PlayerIsDashing = false; + bool m_ShiftDashing = false; + bool m_ValidDoubleTap = false; + + //specialabilitys + bool m_MovementKeyDown = false; + bool m_SpecialAbilityKeyDown = false; EventRelay m_ELockMouse; bool OnLockMouse(const Events::LockMouse& e); @@ -104,6 +125,26 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm } } + if (e.Command == "Forward" || e.Command == "Right") { + if (e.Value != 0) { + m_CurrentDirectionVector = e.Command == "Right" ? (e.Value > 0 ? "Right" : "Left") : (e.Value > 0 ? "Forward" : "Backward"); + } + //if value = 0 then you have just released this key + if (e.Value != 0) { + m_MovementKeyDown = true; + //if you pressed the same key within m_AssaultDashDoubleTapSensitivityTimer then you have doubletapped it + if (m_AssaultDashDoubleTapDeltaTime < m_AssaultDashDoubleTapSensitivityTimer && m_AssaultDashTapDirection == m_CurrentDirectionVector) { + m_ValidDoubleTap = true; + } + } else { + //== 0 + m_MovementKeyDown = false; + //you have just released the key, store what key it was and reset the doubletap-sensitivity-timer + m_AssaultDashTapDirection = m_CurrentDirectionVector; + m_AssaultDashDoubleTapDeltaTime = 0.f; + } + } + if (e.Command == "Jump") { m_Jumping = e.Value > 0; } @@ -112,6 +153,19 @@ bool FirstPersonInputController::OnCommand(const Events::InputComm m_Crouching = e.Value > 0; } + if (e.Command == "SpecialAbility") { + if (e.Value > 0) { + m_SpecialAbilityKeyDown = true; + } else { + m_SpecialAbilityKeyDown = false; + } + } + if (m_SpecialAbilityKeyDown && m_MovementKeyDown) { + m_ShiftDashing = true; + } else { + m_ShiftDashing = false; + } + return true; } @@ -129,4 +183,53 @@ bool FirstPersonInputController::OnLockMouse(const Events::LockMou return true; } +template +void FirstPersonInputController::AssaultDashCheck(double dt, bool isJumping, double assaultDashCoolDownMaxTimer) { + m_AssaultDashDoubleTapDeltaTime += dt; + m_AssaultDashCoolDownTimer -= dt; + //cooldown = assaultDashCoolDownMaxTimer sec, pretend the dash lasts 0.25 sec (for friction to do its work) + if (m_AssaultDashCoolDownTimer > (assaultDashCoolDownMaxTimer - 0.25f)) { + m_PlayerIsDashing = true; + } else { + m_PlayerIsDashing = false; + } + + //dashing with shift + if (m_ShiftDashing && m_AssaultDashCoolDownTimer <= 0.0f && !isJumping) { + //player is dashing with shift + //the wanted-direction is set in playermovement already so we dont need to check what direction we want to dash in! + m_AssaultDashCoolDownTimer = assaultDashCoolDownMaxTimer; + m_AssaultDashDoubleTapped = true; + m_AssaultDashDoubleTapDeltaTime = 0.f; + //moving to the side has priority + return; + } + + //dashing with doubletap - check if doubletap to dash enabled + if (ResourceManager::Load("Input.ini")->Get("Keyboard.DoubleTapToDash", false)) { + return; + } + + //reset the DoubleTapped state in case we recently doubleTapped (doubletap will only happen during 1 frame) + if (m_AssaultDashDoubleTapped) { + m_AssaultDashDoubleTapped = false; + } + + //check if we have received a valid doubletap + if (!m_ValidDoubleTap) { + return; + } + m_ValidDoubleTap = false; + + if (!(m_AssaultDashCoolDownTimer <= 0.0f && !isJumping)) { + //if we cant dash at the moment, then just reset the tap-sensitivity-timer + m_AssaultDashDoubleTapDeltaTime = 0.f; + return; + } + //ok, we have a valid tap, lets do it + m_AssaultDashDoubleTapped = true; + m_AssaultDashDoubleTapDeltaTime = 0.f; + m_AssaultDashCoolDownTimer = assaultDashCoolDownMaxTimer; +} + #endif \ No newline at end of file diff --git a/include/Game/Systems/PlayerMovementSystem.h b/include/Game/Systems/PlayerMovementSystem.h index 4d98990a..395ccce5 100644 --- a/include/Game/Systems/PlayerMovementSystem.h +++ b/include/Game/Systems/PlayerMovementSystem.h @@ -21,4 +21,5 @@ private: EventRelay m_EPlayerSpawned; bool OnPlayerSpawned(Events::PlayerSpawned& e); + }; \ No newline at end of file diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index bb1fd770..265a3cc5 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -30,4 +30,5 @@ + \ No newline at end of file diff --git a/resources/Schema/Components/DashAbility.xml b/resources/Schema/Components/DashAbility.xml new file mode 100644 index 00000000..25b9e19a --- /dev/null +++ b/resources/Schema/Components/DashAbility.xml @@ -0,0 +1,4 @@ + + + 2.0 + \ No newline at end of file diff --git a/resources/Schema/Components/DashAbility.xsd b/resources/Schema/Components/DashAbility.xsd new file mode 100644 index 00000000..4273cc71 --- /dev/null +++ b/resources/Schema/Components/DashAbility.xsd @@ -0,0 +1,18 @@ + + + + + + + + A dash component for one of the classes + + + + + This is the cooldown on dash + + + + + \ No newline at end of file diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index d365c0ee..fe24adcc 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -6,6 +6,9 @@ + + 2.0 + diff --git a/src/Engine/Rendering/DrawColorCorrectionPass.cpp b/src/Engine/Rendering/DrawColorCorrectionPass.cpp index 45401bce..95de26e2 100644 --- a/src/Engine/Rendering/DrawColorCorrectionPass.cpp +++ b/src/Engine/Rendering/DrawColorCorrectionPass.cpp @@ -27,7 +27,7 @@ void DrawColorCorrectionPass::Draw(GLuint sceneTexture, GLuint bloomTexture, GLf DrawScreenQuadPassState state = DrawScreenQuadPassState(); m_ColorCorrectionProgram->Bind(); - //glClear(GL_COLOR_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT); glUniform1f(glGetUniformLocation(m_ColorCorrectionProgram->GetHandle(), "Exposure"), exposure); glUniform1f(glGetUniformLocation(m_ColorCorrectionProgram->GetHandle(), "Gamma"), gamma); diff --git a/src/Game/Systems/PlayerMovementSystem.cpp b/src/Game/Systems/PlayerMovementSystem.cpp index 498c3765..3e4d9e76 100644 --- a/src/Game/Systems/PlayerMovementSystem.cpp +++ b/src/Game/Systems/PlayerMovementSystem.cpp @@ -1,6 +1,6 @@ #include "Systems/PlayerMovementSystem.h" -PlayerMovementSystem::PlayerMovementSystem(World* world, EventBroker* eventBroker) +PlayerMovementSystem::PlayerMovementSystem(World* world, EventBroker* eventBroker) : System(world, eventBroker) , PureSystem("Player") { @@ -41,8 +41,15 @@ void PlayerMovementSystem::Update(double dt) if (player.HasComponent("Physics")) { ComponentWrapper cPhysics = player["Physics"]; - + //Assault Dash Check + if (player.HasComponent("DashAbility")) { + controller->AssaultDashCheck(dt, ((glm::vec3)cPhysics["Velocity"]).y != 0.0f, player["DashAbility"]["CoolDownMaxTimer"]); + } glm::vec3 wishDirection = controller->Movement() * glm::inverse(glm::quat(ori)); + //this makes sure you can only dash in the 4 directions: forw,backw,left,right + if (controller->AssaultDashDoubleTapped() && controller->Movement().z != 0 && controller->Movement().x != 0) { + wishDirection = glm::vec3(controller->Movement().x, 0, 0)* glm::inverse(glm::quat(ori)); + } float wishSpeed; if (controller->Crouching()) { wishSpeed = playerCrouchSpeed; @@ -71,16 +78,18 @@ void PlayerMovementSystem::Update(double dt) static float surfaceFriction = 5.f; ImGui::InputFloat("surfaceFriction", &surfaceFriction); float accelerationSpeed = actualAccel * (float)dt * wishSpeed * surfaceFriction; - accelerationSpeed = glm::min(accelerationSpeed, addSpeed); + //if doubleTapped do Assault Dash - but only boost maximum 50.0f + float doubleTapDashBoost = controller->AssaultDashDoubleTapped() ? 40.0f : 1.0f; + accelerationSpeed = glm::min(doubleTapDashBoost*glm::min(accelerationSpeed, addSpeed), 50.0f); velocity += accelerationSpeed * wishDirection; ImGui::Text("velocity: (%f, %f, %f) |%f|", velocity.x, velocity.y, velocity.z, glm::length(velocity)); } - if (controller->Jumping() && !controller->Crouching() && (velocity.y == 0.f || !controller->DoubleJumping())) { + //you cant jump and dash at the same time - since there is no friction in the air and we would thus dash much further in the air + if (!controller->PlayerIsDashing() && controller->Jumping() && !controller->Crouching() && (velocity.y == 0.f || !controller->DoubleJumping())) { if (velocity.y == 0.f) { controller->SetDoubleJumping(false); - } - else { + } else { controller->SetDoubleJumping(true); Events::DoubleJump e; m_EventBroker->Publish(e); @@ -103,6 +112,7 @@ void PlayerMovementSystem::Update(double dt) ComponentWrapper cAnimation = playerModel["Animation"]; float movementLength = glm::length(groundVelocity); + //TODO: add assault dash animation here if (glm::length(controller->Movement()) > 0.f) { if (controller->Crouching()) { cAnimation["Name"] = "Crouch Walk";