mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 20:48:24 +01:00
90 lines
3.5 KiB
C#
90 lines
3.5 KiB
C#
// <auto-generated/>
|
|
// Generated by Brutal.Jolt.Generate; do not edit by hand.
|
|
#nullable enable
|
|
|
|
using System.Runtime.CompilerServices;
|
|
using Brutal.Interop;
|
|
using Brutal.Numerics;
|
|
|
|
namespace Brutal.JoltApi
|
|
{
|
|
/// <summary>
|
|
/// <para>
|
|
/// A body lock takes a body ID and locks the underlying body so that other threads cannot access its members
|
|
/// </para>
|
|
/// <para>
|
|
/// C++:
|
|
/// <see href="https://github.com/jrouwe/JoltPhysics/blob/e77f175595e64cb44218cc9d9d56fc365ad0e36a/Jolt/Physics/Body/BodyLock.h#L100">Jolt/Physics/Body/BodyLock.h:100</see>
|
|
/// <br/>
|
|
/// <c>class BodyLockRead : public BodyLockBase<false, const Body></c>
|
|
/// </para>
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <code>
|
|
/// A body lock takes a body ID and locks the underlying body so that other threads cannot access its members
|
|
///
|
|
/// The common usage pattern is:
|
|
///
|
|
/// BodyLockInterface lock_interface = physics_system.GetBodyLockInterface(); // Or non-locking interface if the lock is already taken
|
|
/// BodyID body_id = ...; // Obtain ID to body
|
|
///
|
|
/// // Scoped lock
|
|
/// {
|
|
/// BodyLockRead lock(lock_interface, body_id);
|
|
/// if (lock.Succeeded()) // body_id may no longer be valid
|
|
/// {
|
|
/// const Body &body = lock.GetBody();
|
|
///
|
|
/// // Do something with body
|
|
/// ...
|
|
/// }
|
|
/// }
|
|
/// </code>
|
|
/// </remarks>
|
|
[InteropHandle]
|
|
public readonly partial struct BodyLockRead : IDisposable
|
|
{
|
|
/// <summary>
|
|
/// <para>
|
|
/// Takes the read lock on one body, held until Dispose (or ReleaseLock). An ID that no longer names a body
|
|
/// still returns a lock, whose Succeeded() is false. Through PhysicsSystem.GetBodyLockInterface() this
|
|
/// really locks; through GetBodyLockInterfaceNoLock() it doesn't, for code that already runs where no other
|
|
/// thread can touch the body.
|
|
/// </para>
|
|
/// </summary>
|
|
public static BodyLockRead Create(BodyLockInterface lockInterface, uint bodyID) =>
|
|
Jolt.PInvoke.BodyLockRead_Create(lockInterface, bodyID);
|
|
|
|
/// <summary>
|
|
/// <para>
|
|
/// Whether the ID named a body, so GetBody() has one.
|
|
/// </para>
|
|
/// </summary>
|
|
public bool Succeeded() => Jolt.PInvoke.BodyLockRead_Succeeded(this);
|
|
|
|
/// <summary>
|
|
/// <para>
|
|
/// Whether the ID named a body that is also in the broad phase (added to the physics system).
|
|
/// </para>
|
|
/// </summary>
|
|
public bool SucceededAndIsInBroadPhase() => Jolt.PInvoke.BodyLockRead_SucceededAndIsInBroadPhase(this);
|
|
|
|
/// <summary>
|
|
/// <para>
|
|
/// The locked body, or a null handle when Succeeded() is false (where Jolt itself would assert). It is
|
|
/// borrowed and only safe to use while the lock is held. A read lock means read only: don't call anything
|
|
/// that changes the body.
|
|
/// </para>
|
|
/// </summary>
|
|
public Body GetBody() => Jolt.PInvoke.BodyLockRead_GetBody(this);
|
|
|
|
/// <summary>
|
|
/// <para>
|
|
/// Releases the lock early; Dispose is still needed to free the lock object. GetBody() is null afterwards.
|
|
/// </para>
|
|
/// </summary>
|
|
public void ReleaseLock() => Jolt.PInvoke.BodyLockRead_ReleaseLock(this);
|
|
|
|
public void Dispose() => Jolt.PInvoke.BodyLockRead_Destroy(this);
|
|
}
|
|
}
|