Skip to content

Commit 1962ba3

Browse files
committed
wip
1 parent 472ab51 commit 1962ba3

12 files changed

Lines changed: 38 additions & 24 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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() as ShapeUserData;
152152
}
153153
else if (b2Shape_IsSensor(idB))
154154
{
155-
userData = b2Shape_GetUserData(idB) as ShapeUserData;
155+
userData = b2Shape_GetUserData(idB).GetRef() as 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 = (ShapeUserData)b2Shape_GetUserData(@event.sensorShapeId).GetRef();
190190
if (userData.active)
191191
{
192192
zombies.Add(b2Shape_GetBody(@event.visitorShapeId));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 = (ShapeUserData)b2Shape_GetUserData(shapeId).GetRef();
508508
if (userData != null)
509509
{
510510
maxPush = userData.maxPush;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = (ShapeUserData)b2Shape_GetUserData(shapeId).GetRef();
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 = (ShapeUserData)b2Shape_GetUserData(shapeId).GetRef();
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 = (ShapeUserData)b2Shape_GetUserData(shapeId).GetRef();
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 = (ShapeUserData)b2Shape_GetUserData(shapeId).GetRef();
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: 2 additions & 2 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 = (ShapeUserData)b2Shape_GetUserData(shapeId).GetRef();
7070
if (userData != null && userData.ignore)
7171
{
7272
// continue the query
@@ -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 = (ShapeUserData)b2Shape_GetUserData(shapeId).GetRef();
377377
if (userData == null)
378378
{
379379
continue;

src/Box2D.NET.Samples/Samples/Events/BodyMove.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public override void Step()
157157

158158
// this shows a somewhat contrived way to track body sleeping
159159
//B2BodyId bodyId = (B2BodyId)@event.userData; // todo: @ikpil check struct casting
160-
var diff = @event.userData.GetInteger(-1);
160+
var diff = @event.userData.GetInt(-1);
161161
//ptrdiff_t diff = bodyId - m_bodyIds;
162162
ref bool sleeping = ref m_sleeping[diff];
163163

src/Box2D.NET.Samples/Samples/Events/ContactEvent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public override void Step()
300300
}
301301
else if (attachCount < e_count)
302302
{
303-
debrisToAttach[attachCount] = (int)userDataB.GetInteger(-1);
303+
debrisToAttach[attachCount] = (int)userDataB.GetInt(-1);
304304
attachCount += 1;
305305
}
306306
}
@@ -335,7 +335,7 @@ public override void Step()
335335
}
336336
else if (attachCount < e_count)
337337
{
338-
debrisToAttach[attachCount] = (int)userDataA.GetInteger(-1);
338+
debrisToAttach[attachCount] = (int)userDataA.GetInt(-1);
339339
attachCount += 1;
340340
}
341341
}

src/Box2D.NET.Samples/Samples/Events/JointEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public override void Step()
231231

232232
if (b2Joint_IsValid(@event.jointId))
233233
{
234-
var userData = @event.userData.GetInteger(-1);
234+
var userData = @event.userData.GetInt(-1);
235235
var index = userData;
236236
B2_ASSERT(0 <= index && index < e_count);
237237
b2DestroyJoint(@event.jointId, true);

src/Box2D.NET.Samples/Samples/Events/SensorFunnel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public override void Step()
311311
var donut = b2Body_GetUserData(bodyId);
312312
if (!donut.IsEmpty())
313313
{
314-
var index = donut.GetInteger(-1);
314+
var index = donut.GetInt(-1);
315315
B2_ASSERT(0 <= index && index < (int)e_count);
316316

317317
// Defer destruction to avoid double destruction and event invalidation (orphaned shape ids)
@@ -323,7 +323,7 @@ public override void Step()
323323
var human = b2Body_GetUserData(bodyId);
324324
if (!human.IsEmpty())
325325
{
326-
var index = human.GetInteger(-1);
326+
var index = human.GetInt(-1);
327327
B2_ASSERT(0 <= index && index < (int)e_count);
328328

329329
// Defer destruction to avoid double destruction and event invalidation (orphaned shape ids)

src/Box2D.NET.Samples/Samples/Shapes/CustomFilter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ bool ShouldCollide(in B2ShapeId shapeIdA, in B2ShapeId shapeIdB)
7878
var userDataA = b2Shape_GetUserData(shapeIdA);
7979
var userDataB = b2Shape_GetUserData(shapeIdB);
8080

81-
if (userDataA == null || userDataB == null)
81+
if (userDataA.IsEmpty() || userDataB.IsEmpty())
8282
{
8383
return true;
8484
}
8585

86-
int indexA = (int)userDataA;
87-
int indexB = (int)userDataB;
86+
int indexA = (int)userDataA.GetInt(-1);
87+
int indexB = (int)userDataB.GetInt(-1);
8888

8989
return ((indexA & 1) + (indexB & 1)) != 1;
9090
}

src/Box2D.NET.Samples/Samples/Stackings/CircleStack.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public override void Draw()
9999

100100
var userDataA = b2Shape_GetUserData(@event.shapeIdA);
101101
var userDataB = b2Shape_GetUserData(@event.shapeIdB);
102-
int indexA = (int)userDataA;
103-
int indexB = (int)userDataB;
102+
int indexA = (int)userDataA.GetInt(-1);
103+
int indexB = (int)userDataB.GetInt(-1);
104104

105105
DrawPoint(m_draw, @event.point, 10.0f, B2HexColor.b2_colorWhite);
106106

0 commit comments

Comments
 (0)