Skip to content

Commit

Permalink
Bugfix: Asteroids now generate at larger distances.
Browse files Browse the repository at this point in the history
Therer was an integer overflow happening, which caused asteroids not to generate at large distances from the center.
  • Loading branch information
8vogt committed Mar 18, 2021
1 parent fa37202 commit 64a740c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ public void MarkToLoadCellsInBounds(BoundingSphereD bounds)
{
if (m_toLoadCells.Contains(cellId)) continue;

//MyPluginLog.Debug("Mark Loading cell " + cellId);

BoundingBoxD cellBounds = new BoundingBoxD(cellId * m_cellSize, (cellId + 1) * m_cellSize);
if (bounds.Contains(cellBounds) == ContainmentType.Disjoint) continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class MyProceduralAsteroidsModule : MyAbstractProceduralCellModule
/// <summary>
/// Cell size parameters
/// </summary>
private const int OBJECT_SIZE_MAX = 1024;
private const int CELL_SIZE = OBJECT_SIZE_MAX * 10;
private const double OBJECT_SIZE_MAX = 1024;
private const double CELL_SIZE = OBJECT_SIZE_MAX * 10;

/// <summary>
/// Reflexion of asteroid creation method of SE
Expand Down Expand Up @@ -257,8 +257,8 @@ protected override MyProceduralCell GenerateCellSeeds(Vector3I cellId)
MyProceduralCell cell = new MyProceduralCell(cellId, CELL_SIZE);
int cellSeed = CalculateCellSeed(cellId);
int index = 0;
int subCellSize = (int)(OBJECT_SIZE_MAX * 1.5f / settings.AsteroidDensity);
int subcells = CELL_SIZE / subCellSize;
double subCellSize = OBJECT_SIZE_MAX * 1.5f / settings.AsteroidDensity;
int subcells = (int)(CELL_SIZE / subCellSize);

using (MyRandom.Instance.PushSeed(cellSeed))
{
Expand All @@ -270,7 +270,7 @@ protected override MyProceduralCell GenerateCellSeeds(Vector3I cellId)
Vector3D position = new Vector3D(MyRandom.Instance.NextDouble(), MyRandom.Instance.NextDouble(), MyRandom.Instance.NextDouble());
position += (Vector3D)subcellId;
position *= subCellSize;
position += cellId * CELL_SIZE;
position += ((Vector3D)cellId) * CELL_SIZE;

if (!MyEntities.IsInsideWorld(position) || (settings.WorldSize >= 0 && position.Length() > settings.WorldSize)) continue;

Expand All @@ -285,6 +285,8 @@ protected override MyProceduralCell GenerateCellSeeds(Vector3I cellId)
cellObjectSeed.Params.GeneratorSeed = m_definition.UseGeneratorSeed ? MyRandom.Instance.Next() : 0;

cell.AddObject(cellObjectSeed);

MyPluginLog.Debug("Adding seed");
}
}

Expand Down

0 comments on commit 64a740c

Please sign in to comment.