diff --git a/Nuake/Engine.cpp b/Nuake/Engine.cpp index d1caafb7..94f357a6 100644 --- a/Nuake/Engine.cpp +++ b/Nuake/Engine.cpp @@ -50,6 +50,8 @@ namespace Nuake m_TimeStep = m_Time - m_LastFrameTime; m_LastFrameTime = m_Time; + m_TimeStep = std::min((float)m_TimeStep, 0.5f); + // Dont update if no scene is loaded. if (CurrentWindow->GetScene()) { diff --git a/Nuake/src/Core/Physics/DynamicWorld.cpp b/Nuake/src/Core/Physics/DynamicWorld.cpp index a6177d46..13843a78 100644 --- a/Nuake/src/Core/Physics/DynamicWorld.cpp +++ b/Nuake/src/Core/Physics/DynamicWorld.cpp @@ -406,20 +406,36 @@ namespace Nuake const std::string& name = entity.GetComponent().Name; TransformComponent& transformComponent = entity.GetComponent(); - transformComponent.GlobalTransform = transform; - //transformComponent.SetLocalPosition(pos); - //transformComponent.SetLocalRotation(rotation); + //transformComponent.GlobalTransform = transform; + transformComponent.SetLocalPosition(pos); + transformComponent.Dirty = false; + transformComponent.SetLocalRotation(rotation); //transformComponent.SetLocalScale(scale); + + Matrix4 newTransform = Matrix4(1.0f); + newTransform = glm::translate(newTransform, pos); + newTransform = newTransform * glm::toMat4(rotation); + newTransform = glm::scale(newTransform, transformComponent.GetGlobalScale()); + transformComponent.SetLocalTransform(transform); + + const std::string& posStr = "(" + std::to_string(pos.x) + ", " + std::to_string(pos.y) + ", " + std::to_string(pos.z) + ")"; + const std::string& logMsg = "Physics pos: " + name + " at " + posStr; + Logger::Log(logMsg); } // If you take larger steps than 1 / 60th of a second you need to do multiple collision steps in order to keep the simulation stable. Do 1 collision step per 1 / 60th of a second (round up). - const int cCollisionSteps = 1; + int collisionSteps = 1; + const float minStepDuration = 1.0f / 60.0f; + if(ts > minStepDuration) + { + collisionSteps = ts / minStepDuration; + } // If you want more accurate step results you can do multiple sub steps within a collision step. Usually you would set this to 1. const int cIntegrationSubSteps = 1; // Step the world - _JoltPhysicsSystem->Update(ts, cCollisionSteps, cIntegrationSubSteps, new JPH::TempAllocatorMalloc(), _JoltJobSystem); + _JoltPhysicsSystem->Update(ts, collisionSteps, cIntegrationSubSteps, new JPH::TempAllocatorMalloc(), _JoltJobSystem); } void DynamicWorld::Clear() diff --git a/Nuake/src/Scene/Components/BSPBrushComponent.h b/Nuake/src/Scene/Components/BSPBrushComponent.h index 7262653c..c3d046d4 100644 --- a/Nuake/src/Scene/Components/BSPBrushComponent.h +++ b/Nuake/src/Scene/Components/BSPBrushComponent.h @@ -39,7 +39,7 @@ namespace Nuake { { json hullPointsJson; - const size_t hullSize = Hulls[i].size() - 1; + const size_t hullSize = Hulls[i].size(); for (uint32_t j = 0; j < hullSize; j++) { hullPointsJson[j]["x"] = Hulls[i][j].x; @@ -57,7 +57,7 @@ namespace Nuake { { BEGIN_DESERIALIZE(); - if (j.contains("IsSolider")) + if (j.contains("IsSolid")) { IsSolid = j["IsSolid"]; } @@ -72,7 +72,7 @@ namespace Nuake { { Vector3 pointPos; DESERIALIZE_VEC3(point, pointPos); - hull.push_back(std::move(pointPos)); + hull.push_back((pointPos)); } Hulls.push_back(hull); diff --git a/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp b/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp index 9f429964..e927fb08 100644 --- a/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp +++ b/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp @@ -467,7 +467,7 @@ namespace Nuake { { Entity newPEntity = Engine::GetCurrentScene()->CreateEntity("New prefab Entity"); newEntity.AddChild(newPEntity); - PrefabComponent& prefabComponent = newPEntity.AddComponent(); + auto& prefabComponent = newPEntity.AddComponent(); prefabComponent.SetPrefab(Prefab::New(pointEntity.Prefab)); for (auto& e : prefabComponent.PrefabInstance->Entities) { @@ -497,8 +497,8 @@ namespace Nuake { Entity brushEntity = m_Scene->CreateEntity("WorldSpawn"); newEntity.AddChild(brushEntity); - TransformComponent& transformComponent = brushEntity.GetComponent(); - BSPBrushComponent& bsp = brushEntity.AddComponent(); + auto& transformComponent = brushEntity.GetComponent(); + auto& bsp = brushEntity.AddComponent(); bsp.IsSolid = true; bsp.IsTransparent = false;