Basic universe management, generation and simulation flow

This commit is contained in:
Aslan 2026-01-26 10:19:40 -05:00
parent 4c078dbede
commit 78fceeb95e
29 changed files with 664 additions and 29 deletions

View file

@ -0,0 +1,134 @@
using System;
using System.Threading.Tasks;
using Godot;
public class TestGenerator : IGenerator
{
public static Vector3I UNIVERSE_SIZE = new(3, 3, 3);
public static Vector3 SECTOR_SIZE_EACH_DIRECTION = new(1000, 1000, 1000);
public static int STARS_PER_SECTOR = 5;
public static int STARS_PER_SECTOR_VARIANCE = 2;
public static int SHIPS_PER_SECTOR = 0;
public static int SHIPS_PER_SECTOR_VARIANCE = 0;
public static int STATIONS_PER_SECTOR = 0;
public static int STATIONS_PER_SECTOR_VARIANCE = 0;
private RandomNumberGenerator rng;
public Vector3I GetUniverseSize()
{
return UNIVERSE_SIZE;
}
public Vector3 GetSectorSizeEachDirection()
{
return SECTOR_SIZE_EACH_DIRECTION;
}
public async Task GenerateUniverse(Action<Universe> callback)
{
rng = new();
Universe universe = new(UNIVERSE_SIZE);
for (int x = 0; x < UNIVERSE_SIZE.X; x++)
{
for (int y = 0; y < UNIVERSE_SIZE.Y; y++)
{
for (int z = 0; z < UNIVERSE_SIZE.Z; z++)
{
universe.Sectors[x, y, z] = GenerateSector(new(x, y, z));
}
}
}
callback(universe);
}
public Sector GenerateSector(Vector3I coordinates)
{
Sector sector = new(coordinates, SECTOR_SIZE_EACH_DIRECTION);
int starCount = rng.RandiRange(
STARS_PER_SECTOR - STARS_PER_SECTOR_VARIANCE,
STARS_PER_SECTOR + STARS_PER_SECTOR_VARIANCE
);
starCount = Mathf.Clamp(starCount, 0, int.MaxValue);
for (int i = 0; i < starCount; i++)
{
Vector3 localCoordinates = GenerateLocalCoordinates();
Star star = GenerateStar(sector, localCoordinates);
sector.GameObjects.Add(star);
}
int shipCount = rng.RandiRange(
SHIPS_PER_SECTOR - SHIPS_PER_SECTOR_VARIANCE,
SHIPS_PER_SECTOR + SHIPS_PER_SECTOR_VARIANCE
);
shipCount = Mathf.Clamp(shipCount, 0, int.MaxValue);
for (int i = 0; i < shipCount; i++)
{
Vector3 localCoordinates = GenerateLocalCoordinates();
Vessel ship = GenerateShip(sector, localCoordinates);
sector.GameObjects.Add(ship);
}
int stationCount = rng.RandiRange(
STATIONS_PER_SECTOR - STATIONS_PER_SECTOR_VARIANCE,
STATIONS_PER_SECTOR + STATIONS_PER_SECTOR_VARIANCE
);
stationCount = Mathf.Clamp(stationCount, 0, int.MaxValue);
for (int i = 0; i < stationCount; i++)
{
Vector3 localCoordinates = GenerateLocalCoordinates();
Vessel station = GenerateStation(sector, localCoordinates);
sector.GameObjects.Add(station);
}
return sector;
}
public Star GenerateStar(Sector sector, Vector3 localCoordinates)
{
return new Star(sector, localCoordinates);
}
public Star GenerateStar(Sector sector)
{
return GenerateStar(sector, GenerateLocalCoordinates());
}
public Vessel GenerateShip(Sector sector, Vector3 localCoordinates)
{
return new Vessel(sector, localCoordinates);
}
public Vessel GenerateShip(Sector sector)
{
return GenerateShip(sector, GenerateLocalCoordinates());
}
public Vessel GenerateStation(Sector sector, Vector3 localCoordinates)
{
return new Vessel(sector, localCoordinates);
}
public Vessel GenerateStation(Sector sector)
{
return GenerateStation(sector, GenerateLocalCoordinates());
}
public Vector3 GenerateLocalCoordinates()
{
double x = rng.Randf() * SECTOR_SIZE_EACH_DIRECTION.X;
double y = rng.Randf() * SECTOR_SIZE_EACH_DIRECTION.Y;
double z = rng.Randf() * SECTOR_SIZE_EACH_DIRECTION.Z;
return new(x, y, z);
}
}