Skip to content

Commit 7a21701

Browse files
committed
wip #80
1 parent 5b540a7 commit 7a21701

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+228
-133
lines changed

src/Box2D.NET.Samples/Primitives/CustomUserData.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkBarrel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ void CreateScene()
298298
float jointFriction = 0.05f;
299299
float jointHertz = 5.0f;
300300
float jointDamping = 0.5f;
301-
CreateHuman(ref m_humans[index], m_worldId, bodyDef.position, scale, jointFriction, jointHertz, jointDamping, index + 1, null, false);
301+
CreateHuman(ref m_humans[index], m_worldId, bodyDef.position, scale, jointFriction, jointHertz, jointDamping, index + 1, B2UserData.Empty, false);
302302
}
303303

304304
index += 1;

src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSensor.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public BenchmarkSensor(SampleContext context) : base(context)
6060
B2ShapeDef shapeDef = b2DefaultShapeDef();
6161
shapeDef.isSensor = true;
6262
shapeDef.enableSensorEvents = true;
63-
shapeDef.userData = m_activeSensor;
63+
shapeDef.userData = B2UserData.Ref(m_activeSensor);
6464

6565
float y = 0.0f;
6666
float x = -40.0f * gridSize;
@@ -90,7 +90,7 @@ public BenchmarkSensor(SampleContext context) : base(context)
9090
m_passiveSensors[j] = new ShapeUserData();
9191
m_passiveSensors[j].row = j;
9292
m_passiveSensors[j].active = false;
93-
shapeDef.userData = m_passiveSensors[j];
93+
shapeDef.userData = B2UserData.Ref(m_passiveSensors[j]);
9494

9595
if (j == m_filterRow)
9696
{
@@ -148,11 +148,11 @@ private bool Filter(in B2ShapeId idA, in B2ShapeId idB)
148148
ShapeUserData userData = null;
149149
if (b2Shape_IsSensor(idA))
150150
{
151-
userData = b2Shape_GetUserData(idA) as ShapeUserData;
151+
userData = b2Shape_GetUserData(idA).GetRef<ShapeUserData>();
152152
}
153153
else if (b2Shape_IsSensor(idB))
154154
{
155-
userData = b2Shape_GetUserData(idB) as ShapeUserData;
155+
userData = b2Shape_GetUserData(idB).GetRef<ShapeUserData>();
156156
}
157157

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

188188
// shapes on begin touch are always valid
189-
ShapeUserData userData = (ShapeUserData)b2Shape_GetUserData(@event.sensorShapeId);
189+
ShapeUserData userData = b2Shape_GetUserData(@event.sensorShapeId).GetRef<ShapeUserData>();
190190
if (userData.active)
191191
{
192192
zombies.Add(b2Shape_GetBody(@event.visitorShapeId));

src/Box2D.NET.Samples/Samples/Car.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public struct Car
2424
public B2JointId m_frontAxleId;
2525
public bool m_isSpawned;
2626

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

src/Box2D.NET.Samples/Samples/Characters/Mover.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public Mover(SampleContext context) : base(context)
229229
m_friendlyShape.clipVelocity = false;
230230

231231
shapeDef.filter = new B2Filter(MoverBit, AllBits, 0);
232-
shapeDef.userData = m_friendlyShape;
232+
shapeDef.userData = B2UserData.Ref(m_friendlyShape);
233233
B2BodyId bodyId = b2CreateBody(m_worldId, bodyDef);
234234
b2CreateCapsuleShape(bodyId, shapeDef, m_capsule);
235235
}
@@ -262,7 +262,7 @@ public Mover(SampleContext context) : base(context)
262262
};
263263
B2ShapeDef shapeDef = b2DefaultShapeDef();
264264
shapeDef.filter = new B2Filter(DynamicBit, AllBits, 0);
265-
shapeDef.userData = m_elevatorShape;
265+
shapeDef.userData = B2UserData.Ref(m_elevatorShape);
266266

267267
B2Polygon box = b2MakeBox(2.0f, 0.1f);
268268
b2CreatePolygonShape(m_elevatorId, shapeDef, box);
@@ -504,7 +504,7 @@ static bool PlaneResultFcn(in B2ShapeId shapeId, ref B2PlaneResult planeResult,
504504
Mover self = (Mover)context;
505505
float maxPush = float.MaxValue;
506506
bool clipVelocity = true;
507-
ShapeUserData userData = (ShapeUserData)b2Shape_GetUserData(shapeId);
507+
ShapeUserData userData = b2Shape_GetUserData(shapeId).GetRef<ShapeUserData>();
508508
if (userData != null)
509509
{
510510
maxPush = userData.maxPush;

src/Box2D.NET.Samples/Samples/Collisions/CastWorld.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ void Create(int index)
194194
m_bodyIds[m_bodyIndex] = b2CreateBody(m_worldId, bodyDef);
195195

196196
B2ShapeDef shapeDef = b2DefaultShapeDef();
197-
shapeDef.userData = m_userData[m_bodyIndex];
197+
shapeDef.userData = B2UserData.Ref(m_userData[m_bodyIndex]);
198198
m_userData[m_bodyIndex].ignore = false;
199199
if (m_bodyIndex == m_ignoreIndex)
200200
{
@@ -560,7 +560,7 @@ static float RayCastClosestCallback(in B2ShapeId shapeId, B2Vec2 point, B2Vec2 n
560560
{
561561
CastContext rayContext = (CastContext)context;
562562

563-
ShapeUserData userData = (ShapeUserData)b2Shape_GetUserData(shapeId);
563+
ShapeUserData userData = b2Shape_GetUserData(shapeId).GetRef<ShapeUserData>();
564564

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

591-
ShapeUserData userData = (ShapeUserData)b2Shape_GetUserData(shapeId);
591+
ShapeUserData userData = b2Shape_GetUserData(shapeId).GetRef<ShapeUserData>();
592592

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

621-
ShapeUserData userData = (ShapeUserData)b2Shape_GetUserData(shapeId);
621+
ShapeUserData userData = b2Shape_GetUserData(shapeId).GetRef<ShapeUserData>();
622622

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

655-
ShapeUserData userData = (ShapeUserData)b2Shape_GetUserData(shapeId);
655+
ShapeUserData userData = b2Shape_GetUserData(shapeId).GetRef<ShapeUserData>();
656656

657657
// Ignore a specific shape. Also ignore initial overlap.
658658
if ((userData != null && userData.ignore) || fraction == 0.0f)

src/Box2D.NET.Samples/Samples/Collisions/OverlapWorld.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private static Sample Create(SampleContext context)
6666

6767
static bool OverlapResultFcn(in B2ShapeId shapeId, object context)
6868
{
69-
ShapeUserData userData = (ShapeUserData)b2Shape_GetUserData(shapeId);
69+
ShapeUserData userData = b2Shape_GetUserData(shapeId).GetRef<ShapeUserData>();
7070
if (userData != null && userData.ignore)
7171
{
7272
// continue the query
@@ -177,7 +177,7 @@ void Create(int index)
177177
m_bodyIds[m_bodyIndex] = b2CreateBody(m_worldId, bodyDef);
178178

179179
B2ShapeDef shapeDef = b2DefaultShapeDef();
180-
shapeDef.userData = m_userData[m_bodyIndex];
180+
shapeDef.userData = B2UserData.Ref(m_userData[m_bodyIndex]);
181181
m_userData[m_bodyIndex].index = m_bodyIndex;
182182
m_userData[m_bodyIndex].ignore = false;
183183
if (m_bodyIndex == m_ignoreIndex)
@@ -373,7 +373,7 @@ public override void Step()
373373
for (int i = 0; i < m_doomCount; ++i)
374374
{
375375
B2ShapeId shapeId = m_doomIds[i];
376-
ShapeUserData userData = (ShapeUserData)b2Shape_GetUserData(shapeId);
376+
ShapeUserData userData = b2Shape_GetUserData(shapeId).GetRef<ShapeUserData>();
377377
if (userData == null)
378378
{
379379
continue;

src/Box2D.NET.Samples/Samples/Continuous/BounceHumans.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public override void Step()
8585
float jointDampingRatio = 0.1f;
8686

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

9191
m_countDown = 2.0f;

src/Box2D.NET.Samples/Samples/Continuous/Drop.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void Scene3()
216216
float jointHertz = 1.0f;
217217
float jointDampingRatio = 0.5f;
218218

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

221221
m_frameCount = 1;
222222
}

src/Box2D.NET.Samples/Samples/Donut.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public Donut()
2727
B2_ASSERT(m_sides == B2FixedArray7<B2JointId>.Size);
2828
}
2929

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

0 commit comments

Comments
 (0)