Skip to content

Commit

Permalink
Trimmed characterIndex out of AllocateCharacter parameter list since …
Browse files Browse the repository at this point in the history
…it's rarely used and trivial to get otherwise. Added a little extra documentation.
  • Loading branch information
RossNordby committed May 25, 2019
1 parent 3d1fde6 commit 6ffc66c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Demos/Demos/CharacterDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public CharacterInput(CharacterControllers characters, Vector3 initialPosition,
var shapeIndex = characters.Simulation.Shapes.Add(shape);

bodyHandle = characters.Simulation.Bodies.Add(BodyDescription.CreateDynamic(initialPosition, new BodyInertia { InverseMass = 1f / mass }, new CollidableDescription(shapeIndex, speculativeMargin), new BodyActivityDescription(shape.Radius * 0.02f)));
ref var character = ref characters.AllocateCharacter(bodyHandle, out var characterIndex);
ref var character = ref characters.AllocateCharacter(bodyHandle);
character.LocalUp = new Vector3(0, 1, 0);
character.CosMaximumSlope = MathF.Cos(maximumSlope);
character.JumpVelocity = jumpVelocity;
Expand Down
21 changes: 16 additions & 5 deletions Demos/Demos/Characters/CharacterControllers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,41 +140,52 @@ private void ResizeBodyHandleCapacity(int bodyHandleCapacity)
}

/// <summary>
/// Gets the current index of a character using its associated body handle.
/// Gets the current memory slot index of a character using its associated body handle.
/// </summary>
/// <param name="bodyHandle">Body handle associated with the character to look up the index of.</param>
/// <returns>Index of the character associated with the body handle.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int GetCharacterIndexForHandle(int bodyHandle)
public int GetCharacterIndexForBodyHandle(int bodyHandle)
{
Debug.Assert(bodyHandle >= 0 && bodyHandle < bodyHandleToCharacterIndex.Length && bodyHandleToCharacterIndex[bodyHandle] >= 0, "Can only look up indices for body handles associated with characters in this CharacterControllers instance.");
return bodyHandleToCharacterIndex[bodyHandle];
}

/// <summary>
/// Gets a reference to the character at the given memory slot index.
/// </summary>
/// <param name="index">Index of the character to retrieve.</param>
/// <returns>Reference to the character at the given memory slot index.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref CharacterController GetCharacterByIndex(int index)
{
return ref characters[index];
}

/// <summary>
/// Gets a reference to the character using the handle of the character's body.
/// </summary>
/// <param name="bodyHandle">Body handle of the character to look up.</param>
/// <returns>Reference to the character associated with the given body handle.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref CharacterController GetCharacterByBodyHandle(int bodyHandle)
{
Debug.Assert(bodyHandle >= 0 && bodyHandle < bodyHandleToCharacterIndex.Length && bodyHandleToCharacterIndex[bodyHandle] >= 0, "Can only look up indices for body handles associated with characters in this CharacterControllers instance.");
return ref characters[bodyHandleToCharacterIndex[bodyHandle]];
}

/// <summary>
/// Allocates a character.
/// </summary>
/// <param name="bodyHandle">Body handle associated with the character.</param>
/// <param name="characterIndex">Index of the allocated character.</param>
/// <returns>Reference to the allocated character.</returns>
public ref CharacterController AllocateCharacter(int bodyHandle, out int characterIndex)
public ref CharacterController AllocateCharacter(int bodyHandle)
{
Debug.Assert(bodyHandle >= 0 && (bodyHandle >= bodyHandleToCharacterIndex.Length || bodyHandleToCharacterIndex[bodyHandle] == -1),
"Cannot allocate more than one character for the same body handle.");
if (bodyHandle >= bodyHandleToCharacterIndex.Length)
ResizeBodyHandleCapacity(Math.Max(bodyHandle + 1, bodyHandleToCharacterIndex.Length * 2));
characterIndex = characters.Count;
var characterIndex = characters.Count;
ref var character = ref characters.Allocate(pool);
character = default;
character.BodyHandle = bodyHandle;
Expand Down
3 changes: 1 addition & 2 deletions Demos/SpecializedTests/CharacterTestDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public unsafe override void Initialize(ContentArchive content, Camera camera)
BodyDescription.CreateDynamic(
new Vector3(250 * (float)random.NextDouble() - 125, 2, 250 * (float)random.NextDouble() - 125), new BodyInertia { InverseMass = 1 },
new CollidableDescription(Simulation.Shapes.Add(new Capsule(0.5f, 1f)), 0.1f),
new BodyActivityDescription(-1))),
out var characterIndex);
new BodyActivityDescription(-1))));

character.CosMaximumSlope = .707f;
character.LocalUp = Vector3.UnitY;
Expand Down

0 comments on commit 6ffc66c

Please sign in to comment.