Asteroid Belts

Sector renderer is now also rendering asteroid belts. All gravity calculations have been moved out of monobehaviors.
This commit is contained in:
Reinier Vens 2020-11-29 22:50:12 +00:00
commit a981a46170
76 changed files with 25027 additions and 2016 deletions

View file

@ -2,7 +2,9 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Cinemachine;
using MessagePack;
using UniRx;
using UnityEngine;
using Unity.Mathematics;
using static Unity.Mathematics.math;
@ -10,27 +12,34 @@ using float2 = Unity.Mathematics.float2;
public class ActionGameManager : MonoBehaviour
{
public SectorRenderer SectorRenderer;
public CinemachineVirtualCamera TopDownCamera;
public CinemachineVirtualCamera FollowCamera;
private DirectoryInfo _filePath;
private bool _editMode;
private float _time;
public DatabaseCache Cache { get; private set; }
public GameContext Context { get; private set; }
public Zone CurrentZone { get; private set; }
public event EventHandler<ZoneChangeEventArgs> ZoneChanged;
public Zone Zone { get; private set; }
void Start()
{
var filePath = new DirectoryInfo(Application.dataPath).Parent;
ConsoleController.MessageReceiver = this;
_filePath = new DirectoryInfo(Application.dataPath).Parent.CreateSubdirectory("GameData");
Cache = new DatabaseCache();
Cache.Load(filePath.FullName);
Cache.Load(_filePath.FullName);
Context = new GameContext(Cache, Debug.Log);
var zoneFile = Path.Combine(filePath.FullName, "Home.msgpack");
var zoneFile = Path.Combine(_filePath.FullName, "Home.zone");
// If the game has already been run, there will be a Home file containing a ZonePack; if not, generate one
var zonePack = File.Exists(zoneFile) ?
MessagePackSerializer.Deserialize<ZonePack>(File.ReadAllBytes(zoneFile)) :
ZoneGenerator.GenerateZone(
context: Context,
name: "Home",
name: Guid.NewGuid().ToString().Substring(0,8),
position: float2.zero,
mapLayers: Context.MapLayers.Values,
resources: Context.Resources,
@ -38,26 +47,33 @@ public class ActionGameManager : MonoBehaviour
radius: 1500
);
//var oldZone = CurrentZone;
CurrentZone = Context.GetZone(zonePack);
//ZoneChanged?.Invoke(this, new ZoneChangeEventArgs(oldZone, CurrentZone));
Zone = Context.GetZone(zonePack);
SectorRenderer.Context = Context;
SectorRenderer.LoadZone(Zone);
ConsoleController.AddCommand("editmode", _ => ToggleEditMode());
// ConsoleController.AddCommand("savezone", args =>
// {
// if (args.Length > 0)
// Zone.Value.Data.Name = args[0];
// SaveZone();
// });
}
public void ToggleEditMode()
{
_editMode = !_editMode;
FollowCamera.gameObject.SetActive(!_editMode);
TopDownCamera.gameObject.SetActive(_editMode);
}
void Update()
{
Context.Time = Time.time;
if(!_editMode)
{
_time += Time.deltaTime;
Context.Time = Time.time;
}
Context.Update();
}
}
public class ZoneChangeEventArgs : EventArgs
{
public Zone OldZone { get; set; }
public Zone NewZone { get; set; }
public ZoneChangeEventArgs(Zone oldZone, Zone newZone)
{
OldZone = oldZone;
NewZone = newZone;
}
}