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
25 changes: 0 additions & 25 deletions src/Box2D.NET.Samples/Primitives/CustomUserData.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void CreateScene()
float jointFriction = 0.05f;
float jointHertz = 5.0f;
float jointDamping = 0.5f;
CreateHuman(ref m_humans[index], m_worldId, bodyDef.position, scale, jointFriction, jointHertz, jointDamping, index + 1, null, false);
CreateHuman(ref m_humans[index], m_worldId, bodyDef.position, scale, jointFriction, jointHertz, jointDamping, index + 1, B2UserData.Empty, false);
}

index += 1;
Expand Down
10 changes: 5 additions & 5 deletions src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public BenchmarkSensor(SampleContext context) : base(context)
B2ShapeDef shapeDef = b2DefaultShapeDef();
shapeDef.isSensor = true;
shapeDef.enableSensorEvents = true;
shapeDef.userData = m_activeSensor;
shapeDef.userData = B2UserData.Ref(m_activeSensor);

float y = 0.0f;
float x = -40.0f * gridSize;
Expand Down Expand Up @@ -90,7 +90,7 @@ public BenchmarkSensor(SampleContext context) : base(context)
m_passiveSensors[j] = new ShapeUserData();
m_passiveSensors[j].row = j;
m_passiveSensors[j].active = false;
shapeDef.userData = m_passiveSensors[j];
shapeDef.userData = B2UserData.Ref(m_passiveSensors[j]);

if (j == m_filterRow)
{
Expand Down Expand Up @@ -148,11 +148,11 @@ private bool Filter(in B2ShapeId idA, in B2ShapeId idB)
ShapeUserData userData = null;
if (b2Shape_IsSensor(idA))
{
userData = b2Shape_GetUserData(idA) as ShapeUserData;
userData = b2Shape_GetUserData(idA).GetRef<ShapeUserData>();
}
else if (b2Shape_IsSensor(idB))
{
userData = b2Shape_GetUserData(idB) as ShapeUserData;
userData = b2Shape_GetUserData(idB).GetRef<ShapeUserData>();
}

if (userData != null)
Expand Down Expand Up @@ -186,7 +186,7 @@ public override void Step()
ref B2SensorBeginTouchEvent @event = ref events.beginEvents[i];

// shapes on begin touch are always valid
ShapeUserData userData = (ShapeUserData)b2Shape_GetUserData(@event.sensorShapeId);
ShapeUserData userData = b2Shape_GetUserData(@event.sensorShapeId).GetRef<ShapeUserData>();
if (userData.active)
{
zombies.Add(b2Shape_GetBody(@event.visitorShapeId));
Expand Down
2 changes: 1 addition & 1 deletion src/Box2D.NET.Samples/Samples/Car.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public struct Car
public B2JointId m_frontAxleId;
public bool m_isSpawned;

public void Spawn(B2WorldId worldId, B2Vec2 position, float scale, float hertz, float dampingRatio, float torque, object userData)
public void Spawn(B2WorldId worldId, B2Vec2 position, float scale, float hertz, float dampingRatio, float torque, B2UserData userData)
{
B2_ASSERT(m_isSpawned == false);

Expand Down
6 changes: 3 additions & 3 deletions src/Box2D.NET.Samples/Samples/Characters/Mover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
m_friendlyShape.clipVelocity = false;

shapeDef.filter = new B2Filter(MoverBit, AllBits, 0);
shapeDef.userData = m_friendlyShape;
shapeDef.userData = B2UserData.Ref(m_friendlyShape);
B2BodyId bodyId = b2CreateBody(m_worldId, bodyDef);
b2CreateCapsuleShape(bodyId, shapeDef, m_capsule);
}
Expand Down Expand Up @@ -262,7 +262,7 @@
};
B2ShapeDef shapeDef = b2DefaultShapeDef();
shapeDef.filter = new B2Filter(DynamicBit, AllBits, 0);
shapeDef.userData = m_elevatorShape;
shapeDef.userData = B2UserData.Ref(m_elevatorShape);

B2Polygon box = b2MakeBox(2.0f, 0.1f);
b2CreatePolygonShape(m_elevatorId, shapeDef, box);
Expand Down Expand Up @@ -307,7 +307,7 @@
desiredSpeed = m_maxSpeed;
}

float noWalkSteer = 0.0f;

Check warning on line 310 in src/Box2D.NET.Samples/Samples/Characters/Mover.cs

View workflow job for this annotation

GitHub Actions / test-ubuntu-latest-10

The variable 'noWalkSteer' is assigned but its value is never used

Check warning on line 310 in src/Box2D.NET.Samples/Samples/Characters/Mover.cs

View workflow job for this annotation

GitHub Actions / test-macos-latest-9

The variable 'noWalkSteer' is assigned but its value is never used

Check warning on line 310 in src/Box2D.NET.Samples/Samples/Characters/Mover.cs

View workflow job for this annotation

GitHub Actions / test-ubuntu-latest-8

The variable 'noWalkSteer' is assigned but its value is never used

Check warning on line 310 in src/Box2D.NET.Samples/Samples/Characters/Mover.cs

View workflow job for this annotation

GitHub Actions / test-macos-latest-10

The variable 'noWalkSteer' is assigned but its value is never used

Check warning on line 310 in src/Box2D.NET.Samples/Samples/Characters/Mover.cs

View workflow job for this annotation

GitHub Actions / test-windows-latest-8

The variable 'noWalkSteer' is assigned but its value is never used

Check warning on line 310 in src/Box2D.NET.Samples/Samples/Characters/Mover.cs

View workflow job for this annotation

GitHub Actions / test-macos-latest-8

The variable 'noWalkSteer' is assigned but its value is never used

Check warning on line 310 in src/Box2D.NET.Samples/Samples/Characters/Mover.cs

View workflow job for this annotation

GitHub Actions / test-windows-latest-9

The variable 'noWalkSteer' is assigned but its value is never used

Check warning on line 310 in src/Box2D.NET.Samples/Samples/Characters/Mover.cs

View workflow job for this annotation

GitHub Actions / test-windows-latest-10

The variable 'noWalkSteer' is assigned but its value is never used
if (m_onGround)
{
m_velocity.Y = 0.0f;
Expand Down Expand Up @@ -504,7 +504,7 @@
Mover self = (Mover)context;
float maxPush = float.MaxValue;
bool clipVelocity = true;
ShapeUserData userData = (ShapeUserData)b2Shape_GetUserData(shapeId);
ShapeUserData userData = b2Shape_GetUserData(shapeId).GetRef<ShapeUserData>();
if (userData != null)
{
maxPush = userData.maxPush;
Expand Down
10 changes: 5 additions & 5 deletions src/Box2D.NET.Samples/Samples/Collisions/CastWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void Create(int index)
m_bodyIds[m_bodyIndex] = b2CreateBody(m_worldId, bodyDef);

B2ShapeDef shapeDef = b2DefaultShapeDef();
shapeDef.userData = m_userData[m_bodyIndex];
shapeDef.userData = B2UserData.Ref(m_userData[m_bodyIndex]);
m_userData[m_bodyIndex].ignore = false;
if (m_bodyIndex == m_ignoreIndex)
{
Expand Down Expand Up @@ -560,7 +560,7 @@ static float RayCastClosestCallback(in B2ShapeId shapeId, B2Vec2 point, B2Vec2 n
{
CastContext rayContext = (CastContext)context;

ShapeUserData userData = (ShapeUserData)b2Shape_GetUserData(shapeId);
ShapeUserData userData = b2Shape_GetUserData(shapeId).GetRef<ShapeUserData>();

// Ignore a specific shape. Also ignore initial overlap.
if ((userData != null && userData.ignore) || fraction == 0.0f)
Expand Down Expand Up @@ -588,7 +588,7 @@ static float RayCastAnyCallback(in B2ShapeId shapeId, B2Vec2 point, B2Vec2 norma
{
CastContext rayContext = (CastContext)context;

ShapeUserData userData = (ShapeUserData)b2Shape_GetUserData(shapeId);
ShapeUserData userData = b2Shape_GetUserData(shapeId).GetRef<ShapeUserData>();

// Ignore a specific shape. Also ignore initial overlap.
if ((userData != null && userData.ignore) || fraction == 0.0f)
Expand Down Expand Up @@ -618,7 +618,7 @@ static float RayCastMultipleCallback(in B2ShapeId shapeId, B2Vec2 point, B2Vec2
{
CastContext rayContext = (CastContext)context;

ShapeUserData userData = (ShapeUserData)b2Shape_GetUserData(shapeId);
ShapeUserData userData = b2Shape_GetUserData(shapeId).GetRef<ShapeUserData>();

// Ignore a specific shape. Also ignore initial overlap.
if ((userData != null && userData.ignore) || fraction == 0.0f)
Expand Down Expand Up @@ -652,7 +652,7 @@ static float RayCastSortedCallback(in B2ShapeId shapeId, B2Vec2 point, B2Vec2 no
{
CastContext rayContext = (CastContext)context;

ShapeUserData userData = (ShapeUserData)b2Shape_GetUserData(shapeId);
ShapeUserData userData = b2Shape_GetUserData(shapeId).GetRef<ShapeUserData>();

// Ignore a specific shape. Also ignore initial overlap.
if ((userData != null && userData.ignore) || fraction == 0.0f)
Expand Down
6 changes: 3 additions & 3 deletions src/Box2D.NET.Samples/Samples/Collisions/OverlapWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
private int m_doomCount;

private int m_shapeType;
private B2Transform m_transform;

Check warning on line 48 in src/Box2D.NET.Samples/Samples/Collisions/OverlapWorld.cs

View workflow job for this annotation

GitHub Actions / test-ubuntu-latest-10

The field 'OverlapWorld.m_transform' is never used

Check warning on line 48 in src/Box2D.NET.Samples/Samples/Collisions/OverlapWorld.cs

View workflow job for this annotation

GitHub Actions / test-windows-latest-10

The field 'OverlapWorld.m_transform' is never used

private B2Vec2 m_startPosition;

Expand All @@ -66,7 +66,7 @@

static bool OverlapResultFcn(in B2ShapeId shapeId, object context)
{
ShapeUserData userData = (ShapeUserData)b2Shape_GetUserData(shapeId);
ShapeUserData userData = b2Shape_GetUserData(shapeId).GetRef<ShapeUserData>();
if (userData != null && userData.ignore)
{
// continue the query
Expand Down Expand Up @@ -177,7 +177,7 @@
m_bodyIds[m_bodyIndex] = b2CreateBody(m_worldId, bodyDef);

B2ShapeDef shapeDef = b2DefaultShapeDef();
shapeDef.userData = m_userData[m_bodyIndex];
shapeDef.userData = B2UserData.Ref(m_userData[m_bodyIndex]);
m_userData[m_bodyIndex].index = m_bodyIndex;
m_userData[m_bodyIndex].ignore = false;
if (m_bodyIndex == m_ignoreIndex)
Expand Down Expand Up @@ -373,7 +373,7 @@
for (int i = 0; i < m_doomCount; ++i)
{
B2ShapeId shapeId = m_doomIds[i];
ShapeUserData userData = (ShapeUserData)b2Shape_GetUserData(shapeId);
ShapeUserData userData = b2Shape_GetUserData(shapeId).GetRef<ShapeUserData>();
if (userData == null)
{
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/Box2D.NET.Samples/Samples/Continuous/BounceHumans.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public override void Step()
float jointDampingRatio = 0.1f;

CreateHuman(ref m_humans[m_humanCount], m_worldId, new B2Vec2(0.0f, 5.0f), 1.0f, jointFrictionTorque, jointHertz,
jointDampingRatio, 1, null, true);
jointDampingRatio, 1, B2UserData.Empty, true);
// Human_SetVelocity( m_humans + m_humanCount, { 10.0f - 5.0f * m_humanCount, -20.0f + 5.0f * m_humanCount } );

m_countDown = 2.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/Box2D.NET.Samples/Samples/Continuous/Drop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void Scene3()
float jointHertz = 1.0f;
float jointDampingRatio = 0.5f;

CreateHuman(ref m_human, m_worldId, new B2Vec2(0.0f, 40.0f), 1.0f, jointFrictionTorque, jointHertz, jointDampingRatio, 1, null, true);
CreateHuman(ref m_human, m_worldId, new B2Vec2(0.0f, 40.0f), 1.0f, jointFrictionTorque, jointHertz, jointDampingRatio, 1, B2UserData.Empty, true);

m_frameCount = 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Box2D.NET.Samples/Samples/Donut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Donut()
B2_ASSERT(m_sides == B2FixedArray7<B2JointId>.Size);
}

public void Create(B2WorldId worldId, B2Vec2 position, float scale, int groupIndex, bool enableSensorEvents, object userData)
public void Create(B2WorldId worldId, B2Vec2 position, float scale, int groupIndex, bool enableSensorEvents, B2UserData userData)
{
B2_ASSERT(m_isSpawned == false);

Expand Down
8 changes: 4 additions & 4 deletions src/Box2D.NET.Samples/Samples/Events/BodyMove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void CreateBodies()
{
bodyDef.position = new B2Vec2(x, y);
bodyDef.isBullet = (m_count % 12 == 0);
bodyDef.userData = CustomUserData.Create(m_count);
bodyDef.userData = B2UserData.Signed(m_count);
m_bodyIds[m_count] = b2CreateBody(m_worldId, bodyDef);
m_sleeping[m_count] = false;

Expand Down Expand Up @@ -140,7 +140,7 @@ public override void Step()
{
ref readonly B2BodyMoveEvent @event = ref events.moveEvents[i];

if (@event.userData == null)
if (@event.userData.IsEmpty())
{
// The mouse joint body has no user data
continue;
Expand All @@ -157,9 +157,9 @@ public override void Step()

// this shows a somewhat contrived way to track body sleeping
//B2BodyId bodyId = (B2BodyId)@event.userData; // todo: @ikpil check struct casting
var diff = (CustomUserData<int>)@event.userData;
var diff = @event.userData.GetSigned(-1);
//ptrdiff_t diff = bodyId - m_bodyIds;
ref bool sleeping = ref m_sleeping[diff.Value];
ref bool sleeping = ref m_sleeping[diff];

if (@event.fellAsleep)
{
Expand Down
16 changes: 8 additions & 8 deletions src/Box2D.NET.Samples/Samples/Events/ContactEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ContactEvent : Sample
private B2BodyId m_playerId;
private B2ShapeId m_coreShapeId;
private B2BodyId[] m_debrisIds = new B2BodyId[e_count];
private CustomUserData<int>[] m_bodyUserData = new CustomUserData<int>[e_count];
private B2UserData[] m_bodyUserData = new B2UserData[e_count];
private float m_force;
private float m_wait;

Expand Down Expand Up @@ -86,7 +86,7 @@ public ContactEvent(SampleContext context) : base(context)
for (int i = 0; i < e_count; ++i)
{
m_debrisIds[i] = b2_nullBodyId;
m_bodyUserData[i] = CustomUserData.Create(i);
m_bodyUserData[i] = B2UserData.Signed(i);
}

m_wait = 0.5f;
Expand Down Expand Up @@ -273,8 +273,8 @@ public override void Step()

if (B2_ID_EQUALS(bodyIdA, m_playerId))
{
CustomUserData<int> userDataB = b2Body_GetUserData(bodyIdB) as CustomUserData<int>;
if (userDataB == null)
var userDataB = b2Body_GetUserData(bodyIdB);
if (userDataB.IsEmpty())
{
if (B2_ID_EQUALS(@event.shapeIdA, m_coreShapeId) == false && destroyCount < e_count)
{
Expand All @@ -300,16 +300,16 @@ public override void Step()
}
else if (attachCount < e_count)
{
debrisToAttach[attachCount] = userDataB.Value;
debrisToAttach[attachCount] = (int)userDataB.GetSigned(-1);
attachCount += 1;
}
}
else
{
// Only expect events for the player
B2_ASSERT(B2_ID_EQUALS(bodyIdB, m_playerId));
CustomUserData<int> userDataA = b2Body_GetUserData(bodyIdA) as CustomUserData<int>;
if (userDataA == null)
var userDataA = b2Body_GetUserData(bodyIdA);
if (userDataA.IsEmpty())
{
if (B2_ID_EQUALS(@event.shapeIdB, m_coreShapeId) == false && destroyCount < e_count)
{
Expand All @@ -335,7 +335,7 @@ public override void Step()
}
else if (attachCount < e_count)
{
debrisToAttach[attachCount] = userDataA.Value;
debrisToAttach[attachCount] = (int)userDataA.GetSigned(-1);
attachCount += 1;
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/Box2D.NET.Samples/Samples/Events/JointEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public JointEvent(SampleContext context) : base(context)
jointDef.@base.forceThreshold = forceThreshold;
jointDef.@base.torqueThreshold = torqueThreshold;
jointDef.@base.collideConnected = true;
jointDef.@base.userData = CustomUserData.Create(index);
jointDef.@base.userData = B2UserData.Signed(index);
m_jointIds[index] = b2CreateDistanceJoint(m_worldId, jointDef);
}

Expand All @@ -104,7 +104,7 @@ public JointEvent(SampleContext context) : base(context)
jointDef.@base.forceThreshold = forceThreshold;
jointDef.@base.torqueThreshold = torqueThreshold;
jointDef.@base.collideConnected = true;
jointDef.@base.userData = CustomUserData.Create(index);
jointDef.@base.userData = B2UserData.Signed(index);
m_jointIds[index] = b2CreateMotorJoint(m_worldId, jointDef);
}

Expand All @@ -128,7 +128,7 @@ public JointEvent(SampleContext context) : base(context)
jointDef.@base.forceThreshold = forceThreshold;
jointDef.@base.torqueThreshold = torqueThreshold;
jointDef.@base.collideConnected = true;
jointDef.@base.userData = CustomUserData.Create(index);
jointDef.@base.userData = B2UserData.Signed(index);
m_jointIds[index] = b2CreatePrismaticJoint(m_worldId, jointDef);
}

Expand All @@ -152,7 +152,7 @@ public JointEvent(SampleContext context) : base(context)
jointDef.@base.forceThreshold = forceThreshold;
jointDef.@base.torqueThreshold = torqueThreshold;
jointDef.@base.collideConnected = true;
jointDef.@base.userData = CustomUserData.Create(index);
jointDef.@base.userData = B2UserData.Signed(index);
m_jointIds[index] = b2CreateRevoluteJoint(m_worldId, jointDef);
}

Expand All @@ -178,7 +178,7 @@ public JointEvent(SampleContext context) : base(context)
jointDef.@base.forceThreshold = forceThreshold;
jointDef.@base.torqueThreshold = torqueThreshold;
jointDef.@base.collideConnected = true;
jointDef.@base.userData = CustomUserData.Create(index);
jointDef.@base.userData = B2UserData.Signed(index);
m_jointIds[index] = b2CreateWeldJoint(m_worldId, jointDef);
}

Expand Down Expand Up @@ -210,7 +210,7 @@ public JointEvent(SampleContext context) : base(context)
jointDef.@base.forceThreshold = forceThreshold;
jointDef.@base.torqueThreshold = torqueThreshold;
jointDef.@base.collideConnected = true;
jointDef.@base.userData = CustomUserData.Create(index);
jointDef.@base.userData = B2UserData.Signed(index);
m_jointIds[index] = b2CreateWheelJoint(m_worldId, jointDef);
}

Expand All @@ -231,8 +231,8 @@ public override void Step()

if (b2Joint_IsValid(@event.jointId))
{
CustomUserData<int> userData = @event.userData as CustomUserData<int>;
int index = userData?.Value ?? -1;
var userData = @event.userData.GetSigned(-1);
var index = userData;
B2_ASSERT(0 <= index && index < e_count);
b2DestroyJoint(@event.jointId, true);
m_jointIds[index] = b2_nullJointId;
Expand Down
Loading
Loading