Cherry-picked de2136c (level physicsbody optimization)
This commit is contained in:
@@ -370,27 +370,22 @@ namespace Barotrauma
|
||||
|
||||
public bool OnCollision(Fixture f1, Fixture f2, Contact contact)
|
||||
{
|
||||
Limb limb = f2.Body.UserData as Limb;
|
||||
if (limb != null)
|
||||
if (f2.Body.UserData is Limb limb)
|
||||
{
|
||||
bool collision = CheckLimbCollision(contact, limb);
|
||||
if (collision) HandleLimbCollision(contact, limb);
|
||||
return collision;
|
||||
}
|
||||
|
||||
VoronoiCell cell = f2.Body.UserData as VoronoiCell;
|
||||
if (cell != null)
|
||||
if (f2.UserData is VoronoiCell cell)
|
||||
{
|
||||
HandleLevelCollision(contact, Vector2.Normalize(ConvertUnits.ToDisplayUnits(Body.SimPosition) - cell.Center));
|
||||
return true;
|
||||
}
|
||||
|
||||
Structure structure = f2.Body.UserData as Structure;
|
||||
if (structure != null)
|
||||
if (f2.Body.UserData is Structure structure)
|
||||
{
|
||||
Vector2 normal;
|
||||
FixedArray2<Vector2> points;
|
||||
contact.GetWorldManifold(out normal, out points);
|
||||
contact.GetWorldManifold(out Vector2 normal, out FixedArray2<Vector2> points);
|
||||
if (contact.FixtureA.Body == f1.Body)
|
||||
{
|
||||
normal = -normal;
|
||||
@@ -400,8 +395,7 @@ namespace Barotrauma
|
||||
return true;
|
||||
}
|
||||
|
||||
Submarine otherSub = f2.Body.UserData as Submarine;
|
||||
if (otherSub != null)
|
||||
if (f2.Body.UserData is Submarine otherSub)
|
||||
{
|
||||
HandleSubCollision(contact, otherSub);
|
||||
return true;
|
||||
@@ -486,8 +480,8 @@ namespace Barotrauma
|
||||
levelContact.GetWorldManifold(out contactNormal, out temp);
|
||||
|
||||
//if the contact normal is pointing from the limb towards the level cell it's touching, flip the normal
|
||||
VoronoiCell cell = levelContact.FixtureB.Body.UserData is VoronoiCell ?
|
||||
((VoronoiCell)levelContact.FixtureB.Body.UserData) : ((VoronoiCell)levelContact.FixtureA.Body.UserData);
|
||||
VoronoiCell cell = levelContact.FixtureB.UserData is VoronoiCell ?
|
||||
((VoronoiCell)levelContact.FixtureB.UserData) : ((VoronoiCell)levelContact.FixtureA.UserData);
|
||||
|
||||
var cellDiff = ConvertUnits.ToDisplayUnits(limb.body.SimPosition) - cell.Center;
|
||||
if (Vector2.Dot(contactNormal, cellDiff) < 0)
|
||||
@@ -603,8 +597,8 @@ namespace Barotrauma
|
||||
levelContact.GetWorldManifold(out contactNormal, out temp);
|
||||
|
||||
//if the contact normal is pointing from the sub towards the level cell we collided with, flip the normal
|
||||
VoronoiCell cell = levelContact.FixtureB.Body.UserData is VoronoiCell ?
|
||||
((VoronoiCell)levelContact.FixtureB.Body.UserData) : ((VoronoiCell)levelContact.FixtureA.Body.UserData);
|
||||
VoronoiCell cell = levelContact.FixtureB.UserData is VoronoiCell ?
|
||||
((VoronoiCell)levelContact.FixtureB.UserData) : ((VoronoiCell)levelContact.FixtureA.UserData);
|
||||
|
||||
var cellDiff = ConvertUnits.ToDisplayUnits(Body.SimPosition) - cell.Center;
|
||||
if (Vector2.Dot(contactNormal, cellDiff) < 0)
|
||||
|
||||
Reference in New Issue
Block a user