//
// 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
{
///
///
/// Implementation of the StateRecorder class that uses a stringstream as underlying store and that implements
/// checking if the state doesn't change upon reading
///
///
/// C++:
/// Jolt/Physics/StateRecorderImpl.h:12
///
/// class StateRecorderImpl final : public StateRecorder
///
///
[InteropHandle]
public readonly partial struct StateRecorderImpl : IDisposable
{
///
///
/// Constructor
///
///
/// C++:
/// Jolt/Physics/StateRecorderImpl.h:16
///
/// StateRecorderImpl() = default
///
///
public static StateRecorderImpl Create() => Jolt.PInvoke.StateRecorderImpl_Create();
///
public unsafe void WriteBytes(Ptr data, ByteSize numBytes) => ((StreamOut)this).WriteBytes(data, numBytes);
///
///
/// Rewind the stream for reading
///
///
/// C++:
/// Jolt/Physics/StateRecorderImpl.h:23
///
/// void Rewind()
///
///
///
///
/// Resets only the read position; it does not discard previously written data. To reuse a recorder for a
/// fresh save, call Clear() before writing to it, not Rewind().
///
///
public void Rewind() => Jolt.PInvoke.StateRecorderImpl_Rewind(this);
///
///
/// Clear the stream for reuse
///
///
/// C++:
/// Jolt/Physics/StateRecorderImpl.h:26
///
/// void Clear()
///
///
///
///
/// Resets both the read and write positions, discarding any previously recorded state. The sequence for
/// reusing a recorder is Clear(), then write the new state, then Rewind(), then RestoreState.
///
///
public void Clear() => Jolt.PInvoke.StateRecorderImpl_Clear(this);
///
public unsafe void ReadBytes(Ptr data, ByteSize numBytes) => ((StreamIn)this).ReadBytes(data, numBytes);
///
public bool IsEOF() => ((StreamIn)this).IsEOF();
///
public bool IsFailed() => ((StreamIn)this).IsFailed();
///
///
/// Compare this state with a reference state and ensure they are the same
///
///
/// C++:
/// Jolt/Physics/StateRecorderImpl.h:38
///
/// bool IsEqual(StateRecorderImpl &inReference)
///
///
public bool IsEqual(StateRecorderImpl reference) => Jolt.PInvoke.StateRecorderImpl_IsEqual(this, reference);
///
///
/// Get size of the binary data in bytes
///
///
/// C++:
/// Jolt/Physics/StateRecorderImpl.h:44
///
/// size_t GetDataSize()
///
///
public nuint GetDataSize() => Jolt.PInvoke.StateRecorderImpl_GetDataSize(this);
///
///
/// Copies the recorded state into buffer and returns the total size of the state. Nothing is copied past
/// the end of the buffer, so a return value larger than buffer.Length means the buffer was too small and
/// the call should be retried with one that size. The recorder is left exactly as it was found - the read
/// position doesn't move - so this is safe to call part-way through a restore.
///
///
public unsafe ByteSize GetData(Span buffer)
{
fixed (byte* buffer_fixed = buffer)
{
return (ByteSize)Jolt.PInvoke.StateRecorderImpl_GetDataBytes(this, buffer_fixed, (nuint)buffer.Length);
}
}
///
///
/// Writes a block of bytes into the stream (this is the load side of GetData). It appends at the current
/// put position, so call Clear() first if the recorder already holds a previous save, then Rewind() before
/// reading the new state back with RestoreState.
///
///
public unsafe void WriteBytes(ReadOnlySpan data)
{
fixed (byte* data_fixed = data)
{
Jolt.PInvoke.StateRecorderImpl_WriteByteSpan(this, data_fixed, (nuint)data.Length);
}
}
public static implicit operator StateRecorder(StateRecorderImpl value) =>
Unsafe.BitCast(value);
public static implicit operator StreamIn(StateRecorderImpl value) =>
Unsafe.BitCast(value);
public static implicit operator StreamOut(StateRecorderImpl value) =>
Jolt.PInvoke.StateRecorderImpl_AsStreamOut(value);
public void Dispose() => Jolt.PInvoke.StateRecorderImpl_Destroy(this);
///
public void SetValidating(bool validating) => ((StateRecorder)this).SetValidating(validating);
///
public bool IsValidating() => ((StateRecorder)this).IsValidating();
///
public void SetIsLastPart(bool isLastPart) => ((StateRecorder)this).SetIsLastPart(isLastPart);
///
public bool IsLastPart() => ((StateRecorder)this).IsLastPart();
///
public void Read(out float3 vec) => ((StreamIn)this).Read(out vec);
///
public void Read(out double3 vec) => ((StreamIn)this).Read(out vec);
///
public void Read(out double4x4 vec) => ((StreamIn)this).Read(out vec);
///
public void Write(float3 vec) => ((StreamOut)this).Write(vec);
///
public void Write(double3 vec) => ((StreamOut)this).Write(vec);
///
public void Write(in double4x4 vec) => ((StreamOut)this).Write(in vec);
}
}