@@ -152,53 +152,6 @@ class RigidBody {
152152 [[nodiscard]] virtual bool IsKinematic () const = 0;
153153};
154154
155- /* *
156- * @brief Structure for GPU physics data.
157- */
158- struct GPUPhysicsData {
159- glm::vec4 position; // xyz = position, w = inverse mass
160- glm::vec4 rotation; // quaternion
161- glm::vec4 linearVelocity; // xyz = velocity, w = restitution
162- glm::vec4 angularVelocity; // xyz = angular velocity, w = friction
163- glm::vec4 force; // xyz = force, w = is kinematic (0 or 1)
164- glm::vec4 torque; // xyz = torque, w = use gravity (0 or 1)
165- glm::vec4 colliderData; // type-specific data (e.g., radius for spheres)
166- glm::vec4 colliderData2; // additional collider data (e.g., box half extents)
167- };
168-
169- /* *
170- * @brief Structure for GPU collision data.
171- */
172- struct GPUCollisionData {
173- uint32_t bodyA;
174- uint32_t bodyB;
175- glm::vec4 contactNormal; // xyz = normal, w = penetration depth
176- glm::vec4 contactPoint; // xyz = contact point, w = unused
177- };
178-
179- /* *
180- * @brief Structure for physics simulation parameters.
181- */
182- struct PhysicsParams {
183- float deltaTime; // Time step - 4 bytes
184- uint32_t numBodies; // Number of rigid bodies - 4 bytes
185- uint32_t maxCollisions; // Maximum number of collisions - 4 bytes
186- float padding; // Explicit padding to align gravity to 16-byte boundary - 4 bytes
187- glm::vec4 gravity; // Gravity vector (xyz) + padding (w) - 16 bytes
188- // Total: 32 bytes (aligned to 16-byte boundaries for std140 layout)
189- };
190-
191- /* *
192- * @brief Structure to store collision prediction data for a ray-based collision system.
193- */
194- struct CollisionPrediction {
195- float collisionTime = -1 .0f ; // Time within deltaTime when the collision occurs (-1 = no collision)
196- glm::vec3 collisionPoint; // World position where collision occurs
197- glm::vec3 collisionNormal; // Surface normal at collision point
198- glm::vec3 newVelocity; // Predicted velocity after bounce
199- Entity* hitEntity = nullptr ; // Entity that was hit
200- bool isValid = false ; // Whether this prediction is valid
201- };
202155
203156/* *
204157 * @brief Class for managing physics simulation.
@@ -212,12 +165,12 @@ class PhysicsSystem {
212165 /* *
213166 * @brief Default constructor.
214167 */
215- PhysicsSystem () = default ;
216-
217- // Constructor-based initialization replacing separate Initialize/Set* calls
218- explicit PhysicsSystem (Renderer* _renderer, bool enableGPU = true ) {
219- SetRenderer (_renderer);
220- SetGPUAccelerationEnabled (enableGPU);
168+ /* *
169+ * @brief Constructor.
170+ * @param _renderer Optional renderer (unused in Jolt implementation).
171+ * @param _enableGPU Optional GPU flag (unused in Jolt implementation).
172+ */
173+ explicit PhysicsSystem (Renderer* _renderer = nullptr , bool _enableGPU = true ) {
221174 if (!Initialize ()) {
222175 throw std::runtime_error (" PhysicsSystem: initialization failed" );
223176 }
@@ -279,39 +232,6 @@ class PhysicsSystem {
279232 glm::vec3* hitNormal,
280233 Entity** hitEntity) const ;
281234
282- /* *
283- * @brief Enable or disable GPU acceleration.
284- * @param enabled Whether GPU acceleration is enabled.
285- */
286- void SetGPUAccelerationEnabled (bool enabled) {
287- // Enforce GPU-only policy: disabling GPU acceleration is not allowed in this project.
288- // Ignore attempts to disable and keep GPU acceleration enabled.
289- gpuAccelerationEnabled = true ;
290- }
291-
292- /* *
293- * @brief Check if GPU acceleration is enabled.
294- * @return True, if GPU acceleration is enabled, false otherwise.
295- */
296- [[nodiscard]] bool IsGPUAccelerationEnabled () const {
297- return gpuAccelerationEnabled;
298- }
299-
300- /* *
301- * @brief Set the maximum number of objects that can be simulated on the GPU.
302- * @param maxObjects The maximum number of objects.
303- */
304- void SetMaxGPUObjects (uint32_t maxObjects) {
305- maxGPUObjects = maxObjects;
306- }
307-
308- /* *
309- * @brief Set the renderer to use during GPU acceleration.
310- * @param _renderer The renderer.
311- */
312- void SetRenderer (Renderer* _renderer) {
313- renderer = _renderer;
314- }
315235
316236 /* *
317237 * @brief Set the current camera position for geometry-relative ball checking.
@@ -342,20 +262,6 @@ class PhysicsSystem {
342262 */
343263 void CleanupMarkedBodies ();
344264
345- /* *
346- * @brief Helper function to create a mapped buffer with memory allocation.
347- * @param size The size of the buffer in bytes.
348- * @param usage The buffer usage flags.
349- * @param buffer Reference to the buffer RAII object.
350- * @param memory Reference to the memory RAII object.
351- * @param errorPrefix Prefix for error messages.
352- */
353- void CreateMappedBuffer (vk::DeviceSize size,
354- vk::BufferUsageFlags usage,
355- vk::raii::Buffer& buffer,
356- vk::raii::DeviceMemory& memory,
357- const std::string& errorPrefix);
358-
359265 // Pending rigid body creations queued from background threads
360266 struct PendingCreation {
361267 Entity* entity;
@@ -419,73 +325,7 @@ class PhysicsSystem {
419325 // Whether the physics system is initialized
420326 bool initialized = false ;
421327
422- // GPU acceleration
423- bool gpuAccelerationEnabled = false ;
424- uint32_t maxGPUObjects = 1024 ;
425- uint32_t maxGPUCollisions = 4096 ;
426- Renderer* renderer = nullptr ;
427-
428328 // Camera position for geometry-relative ball checking
429329 mutable std::mutex cameraPositionMutex;
430330 glm::vec3 cameraPosition = glm::vec3(0 .0f , 0 .0f , 0 .0f );
431-
432- // Vulkan resources for physics simulation
433- struct VulkanResources {
434- // Shader modules
435- vk::raii::ShaderModule integrateShaderModule = nullptr ;
436- vk::raii::ShaderModule broadPhaseShaderModule = nullptr ;
437- vk::raii::ShaderModule narrowPhaseShaderModule = nullptr ;
438- vk::raii::ShaderModule resolveShaderModule = nullptr ;
439-
440- // Pipeline layouts and compute pipelines
441- vk::raii::DescriptorSetLayout descriptorSetLayout = nullptr ;
442- vk::raii::PipelineLayout pipelineLayout = nullptr ;
443- vk::raii::Pipeline integratePipeline = nullptr ;
444- vk::raii::Pipeline broadPhasePipeline = nullptr ;
445- vk::raii::Pipeline narrowPhasePipeline = nullptr ;
446- vk::raii::Pipeline resolvePipeline = nullptr ;
447-
448- // Descriptor pool and sets
449- vk::raii::DescriptorPool descriptorPool = nullptr ;
450- std::vector<vk::raii::DescriptorSet> descriptorSets;
451-
452- // Buffers for physics data
453- vk::raii::Buffer physicsBuffer = nullptr ;
454- vk::raii::DeviceMemory physicsBufferMemory = nullptr ;
455- vk::raii::Buffer collisionBuffer = nullptr ;
456- vk::raii::DeviceMemory collisionBufferMemory = nullptr ;
457- vk::raii::Buffer pairBuffer = nullptr ;
458- vk::raii::DeviceMemory pairBufferMemory = nullptr ;
459- vk::raii::Buffer counterBuffer = nullptr ;
460- vk::raii::DeviceMemory counterBufferMemory = nullptr ;
461- vk::raii::Buffer paramsBuffer = nullptr ;
462- vk::raii::DeviceMemory paramsBufferMemory = nullptr ;
463-
464- // Persistent mapped memory pointers for improved performance
465- void * persistentPhysicsMemory = nullptr ;
466- void * persistentCounterMemory = nullptr ;
467- void * persistentParamsMemory = nullptr ;
468-
469- // Command buffer for compute operations
470- vk::raii::CommandPool commandPool = nullptr ;
471- vk::raii::CommandBuffer commandBuffer = nullptr ;
472-
473- // Dedicated fence for compute synchronization
474- vk::raii::Fence computeFence = nullptr ;
475- };
476-
477- VulkanResources vulkanResources;
478-
479- // Initialize Vulkan resources for physics simulation
480- bool InitializeVulkanResources ();
481- void CleanupVulkanResources ();
482-
483- // Update physics data on the GPU
484- void UpdateGPUPhysicsData (std::chrono::milliseconds deltaTime) const ;
485-
486- // Read back physics data from the GPU
487- void ReadbackGPUPhysicsData () const ;
488-
489- // Perform GPU-accelerated physics simulation
490- void SimulatePhysicsOnGPU (std::chrono::milliseconds deltaTime) const ;
491331};
0 commit comments