Path: blob/master/modules/jolt_physics/spaces/jolt_space_3d.h
10278 views
/**************************************************************************/1/* jolt_space_3d.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "servers/physics_server_3d.h"3334#include "Jolt/Jolt.h"3536#include "Jolt/Core/JobSystem.h"37#include "Jolt/Core/TempAllocator.h"38#include "Jolt/Physics/Body/BodyInterface.h"39#include "Jolt/Physics/Collision/BroadPhase/BroadPhaseQuery.h"40#include "Jolt/Physics/Collision/NarrowPhaseQuery.h"41#include "Jolt/Physics/Constraints/Constraint.h"42#include "Jolt/Physics/PhysicsSystem.h"4344class JoltArea3D;45class JoltBody3D;46class JoltBodyActivationListener3D;47class JoltContactListener3D;48class JoltJoint3D;49class JoltLayers;50class JoltObject3D;51class JoltPhysicsDirectSpaceState3D;52class JoltShapedObject3D;53class JoltSoftBody3D;5455class JoltSpace3D {56Mutex pending_objects_mutex;57Mutex body_call_queries_mutex;5859SelfList<JoltBody3D>::List body_call_queries_list;60SelfList<JoltArea3D>::List area_call_queries_list;61SelfList<JoltShapedObject3D>::List shapes_changed_list;62SelfList<JoltShapedObject3D>::List needs_optimization_list;6364LocalVector<JPH::BodyID> pending_objects_sleeping;65LocalVector<JPH::BodyID> pending_objects_awake;6667RID rid;6869JPH::JobSystem *job_system = nullptr;70JPH::TempAllocator *temp_allocator = nullptr;71JoltLayers *layers = nullptr;72JoltContactListener3D *contact_listener = nullptr;73JoltBodyActivationListener3D *body_activation_listener = nullptr;74JPH::PhysicsSystem *physics_system = nullptr;75JoltPhysicsDirectSpaceState3D *direct_state = nullptr;76JoltArea3D *default_area = nullptr;7778float last_step = 0.0f;7980bool active = false;81bool stepping = false;8283void _pre_step(float p_step);84void _post_step(float p_step);8586public:87explicit JoltSpace3D(JPH::JobSystem *p_job_system);88~JoltSpace3D();8990void step(float p_step);9192void call_queries();9394RID get_rid() const { return rid; }95void set_rid(const RID &p_rid) { rid = p_rid; }9697bool is_active() const { return active; }98void set_active(bool p_active) { active = p_active; }99100bool is_stepping() const { return stepping; }101102double get_param(PhysicsServer3D::SpaceParameter p_param) const;103void set_param(PhysicsServer3D::SpaceParameter p_param, double p_value);104105JPH::PhysicsSystem &get_physics_system() const { return *physics_system; }106107JPH::TempAllocator &get_temp_allocator() const { return *temp_allocator; }108109JPH::BodyInterface &get_body_iface();110const JPH::BodyInterface &get_body_iface() const;111const JPH::BodyLockInterface &get_lock_iface() const;112113const JPH::BroadPhaseQuery &get_broad_phase_query() const;114const JPH::NarrowPhaseQuery &get_narrow_phase_query() const;115116JPH::ObjectLayer map_to_object_layer(JPH::BroadPhaseLayer p_broad_phase_layer, uint32_t p_collision_layer, uint32_t p_collision_mask);117void map_from_object_layer(JPH::ObjectLayer p_object_layer, JPH::BroadPhaseLayer &r_broad_phase_layer, uint32_t &r_collision_layer, uint32_t &r_collision_mask) const;118119JPH::Body *try_get_jolt_body(const JPH::BodyID &p_body_id) const;120JoltObject3D *try_get_object(const JPH::BodyID &p_body_id) const;121JoltShapedObject3D *try_get_shaped(const JPH::BodyID &p_body_id) const;122JoltBody3D *try_get_body(const JPH::BodyID &p_body_id) const;123JoltArea3D *try_get_area(const JPH::BodyID &p_body_id) const;124JoltSoftBody3D *try_get_soft_body(const JPH::BodyID &p_body_id) const;125126JoltPhysicsDirectSpaceState3D *get_direct_state();127128JoltArea3D *get_default_area() const { return default_area; }129void set_default_area(JoltArea3D *p_area);130131float get_last_step() const { return last_step; }132133JPH::Body *add_object(const JoltObject3D &p_object, const JPH::BodyCreationSettings &p_settings, bool p_sleeping = false);134JPH::Body *add_object(const JoltObject3D &p_object, const JPH::SoftBodyCreationSettings &p_settings, bool p_sleeping = false);135void remove_object(const JPH::BodyID &p_jolt_id);136void flush_pending_objects();137138void set_is_object_sleeping(const JPH::BodyID &p_jolt_id, bool p_enable);139140void enqueue_call_queries(SelfList<JoltBody3D> *p_body);141void enqueue_call_queries(SelfList<JoltArea3D> *p_area);142void dequeue_call_queries(SelfList<JoltBody3D> *p_body);143void dequeue_call_queries(SelfList<JoltArea3D> *p_area);144145void enqueue_shapes_changed(SelfList<JoltShapedObject3D> *p_object);146void dequeue_shapes_changed(SelfList<JoltShapedObject3D> *p_object);147148void enqueue_needs_optimization(SelfList<JoltShapedObject3D> *p_object);149void dequeue_needs_optimization(SelfList<JoltShapedObject3D> *p_object);150151void add_joint(JPH::Constraint *p_jolt_ref);152void add_joint(JoltJoint3D *p_joint);153void remove_joint(JPH::Constraint *p_jolt_ref);154void remove_joint(JoltJoint3D *p_joint);155156#ifdef DEBUG_ENABLED157void dump_debug_snapshot(const String &p_dir);158const PackedVector3Array &get_debug_contacts() const;159int get_debug_contact_count() const;160int get_max_debug_contacts() const;161void set_max_debug_contacts(int p_count);162#endif163};164165166