69 lines
2.1 KiB
C#
69 lines
2.1 KiB
C#
using System;
|
|
using System.Timers;
|
|
using Godot;
|
|
|
|
public partial class GameManager : Node
|
|
{
|
|
private System.Timers.Timer TickTimer;
|
|
private bool IsTickProcessing = false;
|
|
private bool IsThrottlingTicks = false;
|
|
|
|
public GameState GameState { get; private set; }
|
|
public Generator Generator { get; private set; }
|
|
public Controller Controller { get; private set; }
|
|
|
|
public Ship PlayerShip { get; private set; }
|
|
|
|
public override void _Ready()
|
|
{
|
|
base._Ready();
|
|
|
|
GeneratorSettings generatorSettings = new GeneratorSettings()
|
|
{
|
|
SpaceSize = new CoordinateVector(Helpers.GetCoordinateFromLY(5000000000), Helpers.GetCoordinateFromLY(5000000000)),
|
|
GalaxySizeMultiplier = new CoordinateVector(0.1M, 0.1M),
|
|
Galaxies = 10,
|
|
MaxNebulasPerGalaxy = 100,
|
|
MaxStarsPerGalaxy = 20000,
|
|
MaxPlanetsPerStar = 10,
|
|
MaxMoonsPerPlanet = 3,
|
|
};
|
|
this.Generator = new Generator(generatorSettings);
|
|
|
|
Universe generatedUniverse = this.Generator.GenerateUniverse();
|
|
|
|
this.GameState = new GameState();
|
|
this.GameState.New(generatedUniverse);
|
|
|
|
this.Controller = GetNode<Controller>("../");
|
|
|
|
Galaxy playerGalaxy = generatedUniverse.GameObjects[0] as Galaxy;
|
|
this.PlayerShip = this.Generator.GeneratePlayer(playerGalaxy);
|
|
playerGalaxy.GameObjects.Add(this.PlayerShip);
|
|
|
|
this.Controller.UpdatePlayerShip(this.PlayerShip);
|
|
|
|
this.TickTimer = new System.Timers.Timer(1000);
|
|
this.TickTimer.AutoReset = true;
|
|
this.TickTimer.Elapsed += OnTick;
|
|
this.TickTimer.Start();
|
|
}
|
|
|
|
private void OnTick(Object source, ElapsedEventArgs e)
|
|
{
|
|
if (this.IsTickProcessing)
|
|
{
|
|
this.IsThrottlingTicks = true;
|
|
return;
|
|
}
|
|
this.IsTickProcessing = true;
|
|
|
|
bool ticksThrottled = this.IsThrottlingTicks;
|
|
this.IsThrottlingTicks = false;
|
|
|
|
decimal currentTick = this.GameState.Universe.SimulateTick();
|
|
this.Controller.OnTick(currentTick, ticksThrottled);
|
|
|
|
this.IsTickProcessing = false;
|
|
}
|
|
}
|