feat: add tracy / various fixes
This commit is contained in:
@@ -60,6 +60,14 @@ protected:
|
||||
bool resizePending = false;
|
||||
std::chrono::steady_clock::time_point lastResizeTime{};
|
||||
|
||||
bool m_PhysicsPaused = false;
|
||||
bool m_PhysicsStepOnce = false;
|
||||
|
||||
float m_PhysicsTimeScale = 1.0f;
|
||||
int m_PhysicsStepsLastFrame = 0;
|
||||
|
||||
void drawPhysicsPanel(float dt, float fixedDt, float accumulator);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -29,6 +29,13 @@
|
||||
class MeshCache;
|
||||
class ImguiPass;
|
||||
|
||||
#if defined(TRACY_ENABLE)
|
||||
namespace tracy { class VkCtx; }
|
||||
using DestrumTracyVkCtx = tracy::VkCtx*;
|
||||
#else
|
||||
using DestrumTracyVkCtx = void*;
|
||||
#endif
|
||||
|
||||
|
||||
namespace {
|
||||
using ImmediateExecuteFunction = std::function<void(VkCommandBuffer)>;
|
||||
@@ -126,12 +133,16 @@ public:
|
||||
return swapchain.getImageView(imageIndex);
|
||||
}
|
||||
|
||||
DestrumTracyVkCtx getTracyVkCtx() const { return tracyVkCtx; }
|
||||
|
||||
private:
|
||||
vkb::Instance instance;
|
||||
vkb::PhysicalDevice physicalDevice;
|
||||
vkb::Device device;
|
||||
VmaAllocator allocator;
|
||||
|
||||
DestrumTracyVkCtx tracyVkCtx = nullptr;
|
||||
|
||||
std::uint32_t graphicsQueueFamily;
|
||||
VkQueue graphicsQueue;
|
||||
|
||||
@@ -149,6 +160,8 @@ private:
|
||||
|
||||
ImageCache imageCache;
|
||||
|
||||
bool m_vSync = false;
|
||||
|
||||
static uint32_t BytesPerTexel(VkFormat fmt) {
|
||||
switch (fmt) {
|
||||
case VK_FORMAT_R8_UNORM: return 1;
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <destrum/Physics/PhysicsWorld.h>
|
||||
|
||||
class JoltPhysicsWorld final : public PhysicsWorld {
|
||||
public:
|
||||
struct Settings {
|
||||
std::uint32_t maxBodies{65536};
|
||||
std::uint32_t numBodyMutexes{0};
|
||||
std::uint32_t maxBodyPairs{65536};
|
||||
std::uint32_t maxContactConstraints{10240};
|
||||
|
||||
// Jolt recommends a temp allocator for physics update allocations.
|
||||
// 10 MB is the value used in their HelloWorld sample.
|
||||
std::uint32_t tempAllocatorSizeBytes{10u * 1024u * 1024u};
|
||||
|
||||
// 0 means "hardware_concurrency - 1".
|
||||
std::uint32_t workerThreadCount{0};
|
||||
|
||||
glm::vec3 gravity{0.0f, -9.81f, 0.0f};
|
||||
};
|
||||
|
||||
explicit JoltPhysicsWorld(const Settings& settings = Settings{});
|
||||
~JoltPhysicsWorld() override;
|
||||
|
||||
JoltPhysicsWorld(const JoltPhysicsWorld&) = delete;
|
||||
JoltPhysicsWorld(JoltPhysicsWorld&&) noexcept = delete;
|
||||
JoltPhysicsWorld& operator=(const JoltPhysicsWorld&) = delete;
|
||||
JoltPhysicsWorld& operator=(JoltPhysicsWorld&&) noexcept = delete;
|
||||
|
||||
void Step(float fixedDt) override;
|
||||
|
||||
void SyncKinematicBodiesToPhysics() override;
|
||||
void SyncDynamicBodiesToTransforms() override;
|
||||
|
||||
PhysicsBodyHandle CreateBody(const PhysicsBodyDesc& desc) override;
|
||||
void DestroyBody(PhysicsBodyHandle body) override;
|
||||
|
||||
void SetBodyTransform(PhysicsBodyHandle body, const PhysicsTransform& transform) override;
|
||||
PhysicsTransform GetBodyTransform(PhysicsBodyHandle body) const override;
|
||||
|
||||
void SetLinearVelocity(PhysicsBodyHandle body, const glm::vec3& velocity) override;
|
||||
glm::vec3 GetLinearVelocity(PhysicsBodyHandle body) const override;
|
||||
|
||||
void AddForce(PhysicsBodyHandle body, const glm::vec3& force) override;
|
||||
void AddImpulse(PhysicsBodyHandle body, const glm::vec3& impulse) override;
|
||||
|
||||
bool Raycast(const glm::vec3& origin,
|
||||
const glm::vec3& direction,
|
||||
float maxDistance,
|
||||
PhysicsRaycastHit& hit) const override;
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> m_Impl;
|
||||
};
|
||||
@@ -25,8 +25,8 @@ public:
|
||||
|
||||
// - Kinematic: Transform -> physics body before Step()
|
||||
// - Dynamic: physics body -> Transform after Step()
|
||||
void SyncKinematicBodiesToPhysics();
|
||||
void SyncDynamicBodiesToTransforms();
|
||||
virtual void SyncKinematicBodiesToPhysics();
|
||||
virtual void SyncDynamicBodiesToTransforms();
|
||||
|
||||
virtual PhysicsBodyHandle CreateBody(const PhysicsBodyDesc& desc) = 0;
|
||||
virtual void DestroyBody(PhysicsBodyHandle body) = 0;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <destrum/Event.h>
|
||||
#include <destrum/Scene/SceneManager.h>
|
||||
|
||||
#include "destrum/Physics/JoltPhysicsWorld.h"
|
||||
#include "destrum/Physics/PhysicsSceneBridge.h"
|
||||
|
||||
class GameObject;
|
||||
@@ -68,7 +69,7 @@ public:
|
||||
private:
|
||||
explicit Scene(const std::string& name);
|
||||
|
||||
PhysicsSceneBridge m_Physics{std::make_unique<SimplePhysicsWorld>()};
|
||||
PhysicsSceneBridge m_Physics{std::make_unique<JoltPhysicsWorld>()};
|
||||
|
||||
|
||||
std::string m_name;
|
||||
|
||||
Reference in New Issue
Block a user