PhysicsStepListener.h 1.2 KB

123456789101112131415161718192021222324252627
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. JPH_NAMESPACE_BEGIN
  6. class PhysicsSystem;
  7. /// A listener class that receives a callback before every physics simulation step
  8. class JPH_EXPORT PhysicsStepListener
  9. {
  10. public:
  11. /// Ensure virtual destructor
  12. virtual ~PhysicsStepListener() = default;
  13. /// Called before every simulation step (received inCollisionSteps times for every PhysicsSystem::Update(...) call)
  14. /// This is called while all body and constraint mutexes are locked. You can read/write bodies and constraints but not add/remove them.
  15. /// Multiple listeners can be executed in parallel and it is the responsibility of the listener to avoid race conditions.
  16. /// The best way to do this is to have each step listener operate on a subset of the bodies and constraints
  17. /// and making sure that these bodies and constraints are not touched by any other step listener.
  18. /// Note that this function is not called if there aren't any active bodies or when the physics system is updated with 0 delta time.
  19. virtual void OnStep(float inDeltaTime, PhysicsSystem &inPhysicsSystem) = 0;
  20. };
  21. JPH_NAMESPACE_END