Skip to content

Commit

Permalink
Prelim work for galactic map.
Browse files Browse the repository at this point in the history
  • Loading branch information
se5a committed Feb 2, 2019
1 parent 06d34d7 commit 42fd8c5
Show file tree
Hide file tree
Showing 19 changed files with 348 additions and 146 deletions.
13 changes: 9 additions & 4 deletions Pulsar4X/Pulsar4X.ECSLib/Entity/EntityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ public class EntityManager : ISerializable

internal List<AEntityChangeListner> EntityListners = new List<AEntityChangeListner>();

public Dictionary<Guid, SystemSensorContacts> FactionSensorContacts = new Dictionary<Guid, SystemSensorContacts>();

internal Dictionary<Guid, SystemSensorContacts> FactionSensorContacts = new Dictionary<Guid, SystemSensorContacts>();
public SystemSensorContacts GetSensorContacts(Guid factionGuid)
{
if (!FactionSensorContacts.ContainsKey(factionGuid))
return new SystemSensorContacts(this, GetGlobalEntityByGuid(factionGuid));
return FactionSensorContacts[factionGuid];
}
Dictionary<Guid, List<Entity>> EntitesByFaction = new Dictionary<Guid, List<Entity>>();
public List<Entity> GetEntitiesByFaction(Guid factionGuid)
{
Expand Down Expand Up @@ -396,7 +401,7 @@ private void UpdateListners(Entity entity, BaseDataBlob db, EntityChangeType cha
/// </summary>
/// <exception cref="KeyNotFoundException">Thrown when T is not derived from BaseDataBlob.</exception>
[NotNull]
internal List<Entity> GetAllEntitiesWithDataBlob<T>() where T : BaseDataBlob
public List<Entity> GetAllEntitiesWithDataBlob<T>() where T : BaseDataBlob
{
int typeIndex = GetTypeIndex<T>();

Expand Down Expand Up @@ -540,7 +545,7 @@ internal virtual List<Entity> GetAllEntitiesWithOUTDataBlobs([NotNull] Comparabl
/// </summary>
/// <exception cref="KeyNotFoundException">Thrown when T is not derived from BaseDataBlob.</exception>
[NotNull]
internal Entity GetFirstEntityWithDataBlob<T>() where T : BaseDataBlob
public Entity GetFirstEntityWithDataBlob<T>() where T : BaseDataBlob
{
return GetFirstEntityWithDataBlob(GetTypeIndex<T>());
}
Expand Down
12 changes: 6 additions & 6 deletions Pulsar4X/Pulsar4X.ECSLib/Faction/FactionInfoDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class FactionInfoDB : BaseDataBlob, IGetValuesHash
{

[JsonProperty]
public List<Entity> Species { get; internal set; }
public List<Entity> Species { get; internal set; } = new List<Entity>();


[JsonProperty]
public List<Guid> KnownSystems { get; internal set; }
public List<Guid> KnownSystems { get; internal set; } = new List<Guid>();


public ReadOnlyDictionary<Guid, List<Entity>> KnownJumpPoints => new ReadOnlyDictionary<Guid, List<Entity>>(InternalKnownJumpPoints);
Expand All @@ -23,15 +23,15 @@ public class FactionInfoDB : BaseDataBlob, IGetValuesHash


[JsonProperty]
public List<Entity> KnownFactions { get; internal set; }
public List<Entity> KnownFactions { get; internal set; } = new List<Entity>();


[PublicAPI]
[JsonProperty]
public List<Entity> Colonies { get; internal set; }
public List<Entity> Colonies { get; internal set; } = new List<Entity>();

[JsonProperty]
public List<Entity> ShipClasses { get; internal set; }
public List<Entity> ShipClasses { get; internal set; } = new List<Entity>();


public ReadOnlyDictionary<Guid, Entity> ComponentDesigns => new ReadOnlyDictionary<Guid, Entity>(InternalComponentDesigns);
Expand All @@ -51,7 +51,7 @@ public class FactionInfoDB : BaseDataBlob, IGetValuesHash
internal Dictionary<Guid, SensorContact> SensorContacts = new Dictionary<Guid, SensorContact>();


public FactionInfoDB() : this(new List<Entity>(), new List<Guid>(), new List<Entity>(), new List<Entity>() ) { }
public FactionInfoDB() { }

public FactionInfoDB(
List<Entity> species,
Expand Down
4 changes: 2 additions & 2 deletions Pulsar4X/Pulsar4X.ECSLib/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public DateTime CurrentDateTime
}

internal ProcessorManager ProcessorManager;

/// <summary>
/// List of StarSystems currently in the game.
/// </summary>
[JsonProperty]
internal Dictionary<Guid, StarSystem> Systems { get; private set; } = new Dictionary<Guid, StarSystem>();
public Dictionary<Guid, StarSystem> Systems { get; private set; } = new Dictionary<Guid, StarSystem>();

[JsonProperty]
public readonly EntityManager GlobalManager;
Expand Down
18 changes: 9 additions & 9 deletions Pulsar4X/Pulsar4X.ImGuiNetUI/DebugWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal static DebugWindow GetInstance()
instance._selectedEntityState = _state.LastClickedEntity;
}
instance._selectedEntityState = _state.LastClickedEntity;
instance._systemState = _state.StarSystemStates[_state.ActiveSystem.Guid];
instance._systemState = _state.StarSystemStates[_state.PrimarySystem.Guid];
return instance;
}

Expand All @@ -58,7 +58,7 @@ internal void SetGameEvents()
if (_state.Game != null)
{
_state.Game.GameLoop.GameGlobalDateChangedEvent += GameLoop_GameGlobalDateChangedEvent;
_state.MapRendering.SysMap.SystemSubpulse.SystemDateChangedEvent += SystemSubpulse_SystemDateChangedEvent;
_state.PrimarySystem.ManagerSubpulses.SystemDateChangedEvent += SystemSubpulse_SystemDateChangedEvent;
_state.EntityClickedEvent += _state_EntityClicked;
}
}
Expand Down Expand Up @@ -138,7 +138,7 @@ internal override void Display()
SetFrameRateArray();
if (ImGui.Begin("debug", ref IsActive))
{
ImGui.Text(_state.CurrentSystemDateTime.ToString());
ImGui.Text(_state.PrimarySystemDateTime.ToString());
ImGui.Text("Cursor World Coordinate:");
var mouseWorldCoord = _state.Camera.MouseWorldCoordinate();
ImGui.Text("x" + mouseWorldCoord.X);
Expand Down Expand Up @@ -173,7 +173,7 @@ internal override void Display()
if (ImGui.CollapsingHeader("Entity List"))
{

List<Entity> factionOwnedEntites = _state.ActiveSystem.GetEntitiesByFaction(_state.Faction.Guid);
List<Entity> factionOwnedEntites = _state.PrimarySystem.GetEntitiesByFaction(_state.Faction.Guid);
List<string> entityNames = new List<string>();
foreach (var entity in factionOwnedEntites)
{
Expand Down Expand Up @@ -226,9 +226,9 @@ internal override void Display()

//if (_state.CurrentSystemDateTime != lastDate)
//{
pos = OrbitProcessor.GetAbsolutePosition_AU(orbitDB, _state.CurrentSystemDateTime);
truAnomoly = OrbitProcessor.GetTrueAnomaly(orbitDB, _state.CurrentSystemDateTime);
lastDate = _state.CurrentSystemDateTime;
pos = OrbitProcessor.GetAbsolutePosition_AU(orbitDB, _state.PrimarySystemDateTime);
truAnomoly = OrbitProcessor.GetTrueAnomaly(orbitDB, _state.PrimarySystemDateTime);
lastDate = _state.PrimarySystemDateTime;
//}

ImGui.Text("x: " + pos.X);
Expand Down Expand Up @@ -314,7 +314,7 @@ internal override void Display()
ImGui.SameLine();
double distancekm = Distance.AuToKm(distance);
ImGui.Text(distancekm.ToString() + " KM");
var timeToTarget = db.PredictedExitTime - _state.CurrentSystemDateTime;
var timeToTarget = db.PredictedExitTime - _state.PrimarySystemDateTime;
ImGui.Text("Remaining TTT " + timeToTarget);
var totalTime = db.PredictedExitTime - db.EntryDateTime;
ImGui.Text("Total TTT " + totalTime);
Expand All @@ -323,7 +323,7 @@ internal override void Display()
ImGui.Text("LastDateTime: ");
ImGui.Text(db.LastProcessDateTime.ToString());
ImGui.Text("Time Since Last: ");
var timelen = _state.CurrentSystemDateTime - db.LastProcessDateTime;
var timelen = _state.PrimarySystemDateTime - db.LastProcessDateTime;
ImGui.Text(timelen.ToString());

}
Expand Down
2 changes: 1 addition & 1 deletion Pulsar4X/Pulsar4X.ImGuiNetUI/EntityContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public EntityContextMenu(GlobalUIState state, Guid entityGuid)
_state = state;
//_state.OpenWindows.Add(this);
//IsActive = true;
_entityState = state.StarSystemStates[state.ActiveSystem.Guid].EntityStates[entityGuid];
_entityState = state.StarSystemStates[state.PrimarySystem.Guid].EntityStates[entityGuid];

}

Expand Down
44 changes: 37 additions & 7 deletions Pulsar4X/Pulsar4X.ImGuiNetUI/GlobalUIState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class GlobalUIState
internal FactionVM FactionUIState;
internal bool IsGameLoaded { get { return Game != null; } }
internal Entity Faction { get { return FactionUIState.FactionEntity; } }
internal StarSystem ActiveSystem;
internal bool ShowMetrixWindow;
internal bool ShowImgDbg;
internal bool ShowDemoWindow;
Expand All @@ -25,7 +24,12 @@ public class GlobalUIState
//internal MainMenuItems MainMenu { get; }
//internal NewGameOptions NewGameOptions { get; }
//internal SettingsWindow SettingsWindow { get; }
internal SystemMapRendering MapRendering { get; set; }
internal GalacticMapRender GalacticMap;

internal StarSystem PrimarySystem;
internal SystemMapRendering PrimaryMapRender { get { return GalacticMap.PrimarySysMap; } }
internal DateTime PrimarySystemDateTime; //= new DateTime();

internal EntityContextMenu ContextMenu { get; set; }
//internal IOrderWindow ActiveOrderWidow { get; set; }
//internal DebugWindow Debug { get; set; }
Expand All @@ -47,7 +51,7 @@ public class GlobalUIState
internal EntityState LastClickedEntity;
internal ECSLib.Vector4 LastWorldPointClicked;

internal DateTime CurrentSystemDateTime; //= new DateTime();


internal SpaceMasterVM SpaceMasterVM;

Expand Down Expand Up @@ -93,6 +97,32 @@ internal void LoadImg(string name, string path)
SDLImageDictionary.Add(name, sdltexture);
}

internal void SetFaction(Entity factionEntity)
{
FactionInfoDB factionInfo = factionEntity.GetDataBlob<FactionInfoDB>();
StarSystemStates = new Dictionary<Guid, SystemState>();
foreach (var guid in factionInfo.KnownSystems)
{
StarSystemStates[guid] = new SystemState(Game.Systems[guid], factionEntity);
}
GalacticMap.SetFaction();
}

internal void SetActiveSystem(Guid activeSysID)
{
PrimarySystem = StarSystemStates[activeSysID].StarSystem;
PrimarySystemDateTime = PrimarySystem.ManagerSubpulses.SystemLocalDateTime;
GalacticMap.PrimarySysMap = GalacticMap.RenderedMaps[activeSysID];
}

internal void EnableGameMaster()
{
StarSystemStates = new Dictionary<Guid, SystemState>();
foreach (var system in Game.Systems)
{
StarSystemStates[system.Key] = SystemState.GetMasterState(system.Value);
}
}

internal void MapClicked(ECSLib.Vector4 worldCoord, MouseButtons button)
{
Expand All @@ -105,21 +135,21 @@ internal void MapClicked(ECSLib.Vector4 worldCoord, MouseButtons button)
internal void EntityClicked(Guid entityGuid, MouseButtons button)
{

LastClickedEntity = StarSystemStates[ActiveSystem.Guid].EntityStates[entityGuid];
LastClickedEntity = StarSystemStates[PrimarySystem.Guid].EntityStates[entityGuid];

EntityClickedEvent?.Invoke(LastClickedEntity, button);

if (ActiveWindow != null)
ActiveWindow.EntityClicked(StarSystemStates[ActiveSystem.Guid].EntityStates[entityGuid], button);
ActiveWindow.EntityClicked(StarSystemStates[PrimarySystem.Guid].EntityStates[entityGuid], button);
OnEntitySelected();
}

void OnEntitySelected()
{
MapRendering.SelectedEntityExtras = new List<IDrawData>();
PrimaryMapRender.SelectedEntityExtras = new List<IDrawData>();
if(LastClickedEntity.DebugOrbitOrder != null)
{
MapRendering.SelectedEntityExtras.Add(LastClickedEntity.DebugOrbitOrder);
PrimaryMapRender.SelectedEntityExtras.Add(LastClickedEntity.DebugOrbitOrder);
}
}

Expand Down
63 changes: 63 additions & 0 deletions Pulsar4X/Pulsar4X.ImGuiNetUI/MapRendering/GalacticMapRender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using ImGuiSDL2CS;

namespace Pulsar4X.SDL2UI
{
public class GalacticMapRender
{
GlobalUIState _state;
List<SystemState> SystemStates = new List<SystemState>();
internal Dictionary<Guid,SystemMapRendering> RenderedMaps = new Dictionary<Guid, SystemMapRendering>();
ImGuiSDL2CSWindow _window;
internal SystemMapRendering PrimarySysMap { get; set; }

public GalacticMapRender(ImGuiSDL2CSWindow window, GlobalUIState state)
{
_state = state;
_window = window;

}

internal void SetFaction()
{
int i = 0;
double startangle = Math.PI * 0.5;
float angleIncrease = 0.01f;
int startR = 32;
int radInc = 5;
foreach (var item in _state.StarSystemStates)
{

SystemMapRendering map = new SystemMapRendering(_window, _state);
map.SetSystem(item.Value.StarSystem);
RenderedMaps[item.Key] = map;
var x = (startR + radInc * i) * Math.Sin(startangle - angleIncrease * i);
var y = (startR + radInc * i) * Math.Cos(startangle - angleIncrease * i);
map.GalacticMapPosition.X = x;
map.GalacticMapPosition.Y = y;
i++;
}
}

internal void DrawNameIcons()
{
foreach (var kvp in RenderedMaps)
{
var sysid = kvp.Key;
var sysmap = kvp.Value;
sysmap.DrawNameIcons();
}
}

internal void Draw()
{
foreach (var kvp in RenderedMaps)
{
var sysid = kvp.Key;
var sysmap = kvp.Value;
sysmap.Draw();
}
}
}
}
Loading

0 comments on commit 42fd8c5

Please sign in to comment.