diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index 211c50b7..3bebbfbd 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -51,7 +51,6 @@ namespace SHADE , referencedMatInstances { std::move(rhs.referencedMatInstances) } , matBufferDirty { std::move(rhs.matBufferDirty) } , subBatches { std::move(rhs.subBatches) } - , isDirty { std::move(rhs.isDirty) } , drawData { std::move(rhs.drawData) } , transformData { std::move(rhs.transformData) } , instancedIntegerData { std::move(rhs.instancedIntegerData) } @@ -83,7 +82,6 @@ namespace SHADE referencedMatInstances = std::move(rhs.referencedMatInstances); matBufferDirty = std::move(rhs.matBufferDirty) ; subBatches = std::move(rhs.subBatches) ; - isDirty = std::move(rhs.isDirty) ; drawData = std::move(rhs.drawData) ; transformData = std::move(rhs.transformData) ; instancedIntegerData = std::move(rhs.instancedIntegerData) ; @@ -440,17 +438,14 @@ namespace SHADE { // Create command const uint32_t CURR_INSTANCES = static_cast(subBatch.Renderables.size()); - if (CURR_INSTANCES > 0) - { - drawData.emplace_back(vk::DrawIndexedIndirectCommand - { - .indexCount = subBatch.Mesh->IndexCount, - .instanceCount = CURR_INSTANCES, - .firstIndex = subBatch.Mesh->FirstIndex, - .vertexOffset = subBatch.Mesh->FirstVertex, - .firstInstance = nextInstanceIndex - }); - } + drawData.emplace_back(vk::DrawIndexedIndirectCommand + { + .indexCount = subBatch.Mesh->IndexCount, + .instanceCount = CURR_INSTANCES, + .firstIndex = subBatch.Mesh->FirstIndex, + .vertexOffset = subBatch.Mesh->FirstVertex, + .firstInstance = nextInstanceIndex + }); nextInstanceIndex += CURR_INSTANCES; // Fill in buffers (CPU) diff --git a/SHADE_Engine/src/Physics/Collision/SHCollisionListener.cpp b/SHADE_Engine/src/Physics/Collision/SHCollisionListener.cpp index f16303f4..11a3f754 100644 --- a/SHADE_Engine/src/Physics/Collision/SHCollisionListener.cpp +++ b/SHADE_Engine/src/Physics/Collision/SHCollisionListener.cpp @@ -14,6 +14,7 @@ #include "SHCollisionListener.h" // Project Headers +#include "ECS_Base/Managers/SHEntityManager.h" #include "Physics/PhysicsObject/SHPhysicsObject.h" #include "Physics/System/SHPhysicsSystem.h" #include "Scene/SHSceneManager.h" @@ -83,13 +84,11 @@ namespace SHADE { const SHCollisionInfo& C_INFO = *eventIter; - const bool CLEAR_EVENT = C_INFO.GetCollisionState() == SHCollisionInfo::State::EXIT - || C_INFO.GetCollisionState() == SHCollisionInfo::State::INVALID; + const bool CLEAR_EVENT = C_INFO.GetCollisionState() == SHCollisionInfo::State::EXIT || C_INFO.GetCollisionState() == SHCollisionInfo::State::INVALID; + const bool INVALID_ENTITY = !SHEntityManager::IsValidEID(C_INFO.GetEntityA()) || !SHEntityManager::IsValidEID(C_INFO.GetEntityB()); + const bool INACTIVE_OBJECT = !SHSceneManager::CheckNodeAndComponentsActive(C_INFO.GetEntityA()) || !SHSceneManager::CheckNodeAndComponentsActive(C_INFO.GetEntityB()); - const bool INACTIVE_OBJECT = !SHSceneManager::CheckNodeAndComponentsActive(C_INFO.GetEntityA()) - || !SHSceneManager::CheckNodeAndComponentsActive(C_INFO.GetEntityB()); - - if (CLEAR_EVENT || INACTIVE_OBJECT) + if (CLEAR_EVENT || INVALID_ENTITY || INACTIVE_OBJECT) eventIter = container.erase(eventIter); else ++eventIter; diff --git a/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.cpp b/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.cpp index 4fddc892..330c3abe 100644 --- a/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.cpp +++ b/SHADE_Engine/src/Physics/Interface/SHRigidBodyComponent.cpp @@ -380,6 +380,11 @@ namespace SHADE } auto* physicsObject = system->GetPhysicsObject(GetEID()); + if (!physicsObject) + { + SHLOGV_ERROR("Unable to retrieve physics object of Entity {}", GetEID()) + return; + } physicsObject->GetRigidBody()->setLinearVelocity(newLinearVelocity); } @@ -394,6 +399,11 @@ namespace SHADE } auto* physicsObject = system->GetPhysicsObject(GetEID()); + if (!physicsObject) + { + SHLOGV_ERROR("Unable to retrieve physics object of Entity {}", GetEID()) + return; + } physicsObject->GetRigidBody()->setAngularVelocity(newAngularVelocity); } diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp index 061b7b26..a9e5a9e9 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp @@ -148,7 +148,14 @@ namespace SHADE objectManager.AddRigidBody(EID); if (SHComponentManager::HasComponent(EID)) + { objectManager.AddCollider(EID); + + auto* COLLIDER = SHComponentManager::GetComponent(EID); + for (size_t i = 0; i < COLLIDER->GetCollisionShapes().size(); ++i) + objectManager.AddCollisionShape(EID, i); + } + }; //////////////////////////////// @@ -156,6 +163,8 @@ namespace SHADE // Destroy an existing world if (worldState.world != nullptr) { + + objectManager.RemoveAllObjects(); objectManager.SetWorld(nullptr); diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystemInterface.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystemInterface.cpp index a028ffb5..1fb11274 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystemInterface.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystemInterface.cpp @@ -55,7 +55,7 @@ namespace SHADE auto phySystem = SHSystemManager::GetSystem(); if (phySystem) { - return phySystem->GetFixedUpdateRate(); + return 1.0 / phySystem->GetFixedUpdateRate(); } SHLOGV_WARNING("Failed to get fixed delta time. 0.0 returned instead."); diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp index a30c5279..be1d968e 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystemRoutines.cpp @@ -140,9 +140,10 @@ namespace SHADE } const double FIXED_DT = physicsSystem->fixedDT; - //to be remove ======================================================= + // HACK: Clamp DT here to prevent a ridiculous amount of updates. This limits updates from large dt to 2. + // HACK: This should be done by the FRC and not here for predictable behaviour. + dt = std::clamp(dt, 0.0, 1.0 / 30.0); - //to be remove ======================================================= accumulatedTime += dt; //testFunction(); @@ -394,13 +395,13 @@ void testFunction() if (rb) { if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::W)) - rb->AddForce(-SHVec3::UnitZ * forceModifier); + rb->AddForce(SHVec3::UnitZ * forceModifier); if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::A)) rb->AddForce(-SHVec3::UnitX * forceModifier); if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::S)) - rb->AddForce(SHVec3::UnitZ * forceModifier); + rb->AddForce(-SHVec3::UnitZ * forceModifier); if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::D)) rb->AddForce(SHVec3::UnitX * forceModifier);