Skip to content

Commit

Permalink
Merge pull request #48 from InvalidArgument3/cores
Browse files Browse the repository at this point in the history
more robustness in despawning, hopefully; TODO: fix multi spawning when re entering range
  • Loading branch information
InvalidArgument3 authored Jun 12, 2024
2 parents 3c8b7f1 + c894e0a commit 556e982
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,5 +343,6 @@ private Vector3D RandVector()
var sinPhi = Math.Sin(phi);
return Math.Pow(MainSession.I.Rand.NextDouble(), 1 / 3d) * new Vector3D(sinPhi * Math.Cos(theta), sinPhi * Math.Sin(theta), Math.Cos(phi));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,7 @@ public void UpdateTick()
if (distanceSquared > AsteroidSettings.AsteroidSpawnRadius * AsteroidSettings.AsteroidSpawnRadius)
{
Log.Info($"Removing asteroid at {asteroid.PositionComp.GetPosition()} due to distance from player");
_despawnedAsteroids.Add(new AsteroidState
{
Position = asteroid.PositionComp.GetPosition(),
Size = asteroid.Size,
Type = asteroid.Type
});
_asteroids.Remove(asteroid);

var removalMessage = new AsteroidNetworkMessage(asteroid.PositionComp.GetPosition(), asteroid.Size, Vector3D.Zero, Vector3D.Zero, asteroid.Type, false, asteroid.EntityId, true, false);
var removalMessageBytes = MyAPIGateway.Utilities.SerializeToBinary(removalMessage);
MyAPIGateway.Multiplayer.SendMessageToOthers(32000, removalMessageBytes);

asteroid.Close();
continue;
RemoveAsteroid(asteroid);
}
}

Expand Down Expand Up @@ -221,6 +208,24 @@ public void UpdateTick()
}
}

private void RemoveAsteroid(AsteroidEntity asteroid)
{
_despawnedAsteroids.Add(new AsteroidState
{
Position = asteroid.PositionComp.GetPosition(),
Size = asteroid.Size,
Type = asteroid.Type
});

var removalMessage = new AsteroidNetworkMessage(asteroid.PositionComp.GetPosition(), asteroid.Size, Vector3D.Zero, Vector3D.Zero, asteroid.Type, false, asteroid.EntityId, true, false);
var removalMessageBytes = MyAPIGateway.Utilities.SerializeToBinary(removalMessage);
MyAPIGateway.Multiplayer.SendMessageToOthers(32000, removalMessageBytes);

_asteroids.Remove(asteroid);
asteroid.Close();
MyEntities.Remove(asteroid);
}

private bool IsNearVanillaAsteroid(Vector3D position)
{
List<IMyVoxelBase> voxelMaps = new List<IMyVoxelBase>();
Expand All @@ -245,5 +250,4 @@ private Vector3D RandVector()
var sinPhi = Math.Sin(phi);
return Math.Pow(rand.NextDouble(), 1 / 3d) * new Vector3D(sinPhi * Math.Cos(theta), sinPhi * Math.Sin(theta), Math.Cos(phi));
}

}

0 comments on commit 556e982

Please sign in to comment.