Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions BepuPhysics/Collidables/BoundingBoxBatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

namespace BepuPhysics
{
public struct BoundsContinuation
public readonly struct BoundsContinuation
{
//Bits 0-30: body index
//Bit 31: compound flag; if set, the continuation should merge into the target slot rather than merely setting it.
uint packed;
readonly uint packed;

/// <summary>
/// Gets the index of the body associated with this continuation.
Expand All @@ -39,16 +39,20 @@ public bool CompoundChild
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private BoundsContinuation(uint packed)
{
this.packed = packed;
}

/// <summary>
/// Creates a bounding box calculation continuation for a given noncompound body.
/// </summary>
/// <param name="bodyIndex">Index of the body to set the bounding box of.</param>
public static BoundsContinuation CreateContinuation(int bodyIndex)
{
Debug.Assert(bodyIndex >= 0);
BoundsContinuation toReturn;
toReturn.packed = (uint)bodyIndex;
return toReturn;
return new BoundsContinuation((uint)bodyIndex);
}
/// <summary>
/// Creates a bounding box calculation continuation for a given compound body.
Expand All @@ -57,9 +61,7 @@ public static BoundsContinuation CreateContinuation(int bodyIndex)
public static BoundsContinuation CreateCompoundChildContinuation(int compoundBodyIndex)
{
Debug.Assert(compoundBodyIndex >= 0);
BoundsContinuation toReturn;
toReturn.packed = (1u << 31) | (uint)compoundBodyIndex;
return toReturn;
return new BoundsContinuation((1u << 31) | (uint)compoundBodyIndex);
}
}

Expand Down
4 changes: 2 additions & 2 deletions BepuPhysics/Collidables/CollidableReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public enum CollidableMobility
/// Uses a bitpacked representation to refer to a body or static collidable.
/// </summary>
[StructLayout(LayoutKind.Sequential, Size = 4)]
public struct CollidableReference : IEquatable<CollidableReference>
public readonly struct CollidableReference : IEquatable<CollidableReference>
{
/// <summary>
/// Bitpacked representation of the collidable reference.
/// </summary>
public uint Packed;
public readonly uint Packed;

/// <summary>
/// Gets the mobility state of the owner of this collidable.
Expand Down
8 changes: 4 additions & 4 deletions BepuPhysics/Collidables/TypedIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace BepuPhysics.Collidables
/// <summary>
/// Represents an index with an associated type packed into a single integer.
/// </summary>
public struct TypedIndex : IEquatable<TypedIndex>
public readonly struct TypedIndex : IEquatable<TypedIndex>
{
/// <summary>
/// Bit packed representation of the typed index.
/// </summary>
public uint Packed;
public readonly uint Packed;

/// <summary>
/// Gets the type index of the object.
Expand All @@ -38,7 +38,7 @@ public int Index
public bool Exists
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return (Packed & (1 << 31)) > 0; }
get { return (Packed & (1u << 31)) > 0; }
}

public TypedIndex(int type, int index)
Expand All @@ -48,7 +48,7 @@ public TypedIndex(int type, int index)
//Note the inclusion of a set bit in the most significant slot.
//This encodes that the index was explicitly constructed, so it is a 'real' reference.
//A default constructed TypeIndex will have a 0 in the MSB, so we can use the default constructor for empty references.
Packed = (uint)((type << 24) | index | (1u << 31));
Packed = ((uint)type << 24) | (uint)index | (1u << 31);
}

public override string ToString()
Expand Down
10 changes: 5 additions & 5 deletions BepuPhysics/CollisionDetection/CollisionBatcherContinuations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ public enum CollisionContinuationType : byte

}

public struct PairContinuation
public readonly struct PairContinuation
{
public int PairId;
public int ChildA;
public int ChildB;
public uint Packed;
public readonly int PairId;
public readonly int ChildA;
public readonly int ChildB;
public readonly uint Packed;

/// <summary>
/// Covers bits [0, 20) in the packed representation. Refers to the child pair index in a subtask generating collision task that generated this continuation.
Expand Down
8 changes: 4 additions & 4 deletions BepuPhysics/CollisionDetection/ContinuationIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace BepuPhysics.CollisionDetection
{
public struct CCDContinuationIndex
public readonly struct CCDContinuationIndex
{
public uint Packed;
public readonly uint Packed;

//From least to most significant: 30 bits index, 1 bit type, 1 bit 'exists' flag.

Expand Down Expand Up @@ -33,7 +33,7 @@ public int Type
public bool Exists
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return (Packed & (1 << 31)) > 0; }
get { return (Packed & (1u << 31)) > 0; }
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand All @@ -44,7 +44,7 @@ public CCDContinuationIndex(int type, int index)
//Note the inclusion of a set bit in the most significant slot.
//This encodes that the index was explicitly constructed, so it is a 'real' reference.
//A default constructed TypeIndex will have a 0 in the MSB, so we can use the default constructor for empty references.
Packed = (uint)((type << 30) | index | (1u << 31));
Packed = ((uint)type << 30) | (uint)index | (1u << 31);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public CCDContinuationIndex(int packed)
Expand Down
4 changes: 2 additions & 2 deletions BepuPhysics/Trees/Leaf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace BepuPhysics.Trees
/// Pointer to a leaf's tree location.
/// </summary>
/// <remarks>The identity of a leaf is implicit in its position within the leaf array.</remarks>
public struct Leaf
public readonly struct Leaf
{
/// <summary>
/// Gets the index of the node that the leaf is directly held by.
Expand All @@ -26,7 +26,7 @@ public int ChildIndex
get { return (int)((packed & 0x80000000) >> 31); }
}

uint packed;
readonly uint packed;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Leaf(int nodeIndex, int childIndex)
Expand Down
Loading