TheAtlasEngine
 
Loading...
Searching...
No Matches
jolt_context.hpp
1#pragma once
2#include <map>
3#include <core/core.hpp>
4#include <physics/physics_context.hpp>
5#include <drivers/jolt-cpp/jolt_components.hpp>
6#include <physics/components.hpp>
7#include <drivers/jolt-cpp/jolt_contact_listener.hpp>
8#include <drivers/jolt-cpp/jolt_broad_phase.hpp>
9
10namespace atlas::physics {
20 public:
30 jolt_context(const jolt_settings& p_settings, event::event_bus& p_bus);
31 ~jolt_context() override = default;
32
33 private:
37 void destroy_bodies() override;
38
39 void prepare_and_finalize() override;
40
41 void update_simulation(float p_delta_time) override;
42
43 protected:
44 void emplace_box_collider(uint32_t p_entity_id,
45 const transform* p_transform,
46 const physics_body* p_body,
47 const box_collider* p_collider) override;
48
49 void emplace_sphere_collider(
50 uint32_t p_entity_id,
51 const transform* p_transform,
52 const physics_body* p_body,
53 const sphere_collider* p_collider) override;
54
55 void emplace_capsule_collider(
56 uint32_t p_entity_id,
57 const transform* p_transform,
58 const physics_body* p_body,
59 const capsule_collider* p_collider) override;
60
61 // void set_position_rotation(flecs::entity p_entity, const
62 // physics_body* p_body, const box_collider* p_collider, const
63 // transform* p_transform) override;
64 transform context_read_transform(uint32_t p_id) override;
65
66 physics_body context_read_physics_body(uint32_t p_id) override;
67
68 void linear_velocity(uint64_t p_id,
69 const glm::vec3& p_linear_velocity) override;
70
71 void angular_velocity(uint64_t p_id,
72 const glm::vec3& p_angular_velocity) override;
73
74 void force(uint64_t p_id, const glm::vec3& p_cumulative_force) override;
75
76 void add_force_and_torque(uint64_t p_id,
77 const glm::vec3& p_force,
78 const glm::vec3& p_torque) override;
79
80 void add_impulse(uint64_t p_id, const glm::vec3& p_impulse) override;
81
82 private:
85 jolt_settings m_settings;
86
91 ref<JPH::TempAllocatorImpl> m_temp_allocator;
92
98 scope<JPH::JobSystemThreadPool> m_thread_system;
99
104 ref<broad_phase_layer_interface> m_broad_phase_layer_interface;
105
110 ref<object_vs_broadphase_layer> m_object_vs_broadphase_filter;
111
116 ref<object_layer_pair_filter> m_object_layer_pair_filter;
117
122 // ref<contact_listener> m_contact_listener;
123 contact_listener m_contact_listener;
124
132 ref<JPH::PhysicsSystem> m_physics_system;
133
134 std::map<uint32_t, JPH::BodyID> m_cached_body_ids;
135 };
136};
Event bus that holds the responsibility to reroute events to the subscribers of those particular even...
Definition event_bus.hpp:13
implementation of Jolt's contact listener for collisions
Definition jolt_contact_listener.hpp:16
jolt_context is the backend implementation of physics context
Definition jolt_context.hpp:19
void emplace_box_collider(uint32_t p_entity_id, const transform *p_transform, const physics_body *p_body, const box_collider *p_collider) override
Any emplace_* specific function are specific collider implementation-specific to the backend (context...
void destroy_bodies() override
Performs any specific cleanup needed by Jolt.
jolt_context(const jolt_settings &p_settings, event::event_bus &p_bus)
construct a new physics context with jolt implemented as its backend
The context is the way to interact with specific backend context implementation such as JoltPhysics a...
Definition physics_context.hpp:20
Types are still be filled out. When this is completed to_jph() can be removed.
Definition jolt_broad_phase.hpp:5
Definition components.hpp:59
Definition components.hpp:63
Jolt-specific context configurations These are going to be internally integrated to jolt_context.
Definition jolt_components.hpp:53
physics body data-driven representative
Definition components.hpp:34
Definition components.hpp:68
Definition components.hpp:10