Some work on the mess that is this power code.

Jesus.

Tons of fixes, refactors and other things.
The powernet's code is still awful though.
This commit is contained in:
Pieter-Jan Briers
2018-05-27 16:44:50 +02:00
parent f1ec10e3e1
commit 147aad5064
24 changed files with 444 additions and 172 deletions

View File

@@ -1,5 +1,7 @@
using Content.Server.GameObjects.Components.Power;
using SS14.Shared.GameObjects.System;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.IoC;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -12,6 +14,21 @@ namespace Content.Shared.GameObjects.EntitySystems
{
public List<Powernet> Powernets = new List<Powernet>();
private IComponentManager componentManager;
private int _lastUid = 0;
public override void Initialize()
{
base.Initialize();
componentManager = IoCManager.Resolve<IComponentManager>();
}
public int NewUid()
{
return ++_lastUid;
}
public override void Update(float frametime)
{
for (int i = 0; i < Powernets.Count; i++)
@@ -20,12 +37,12 @@ namespace Content.Shared.GameObjects.EntitySystems
if (powernet.Dirty)
{
//Tell all the wires of this net to be prepared to create/join new powernets
foreach (var wire in powernet.Wirelist)
foreach (var wire in powernet.WireList)
{
wire.Regenerating = true;
}
foreach (var wire in powernet.Wirelist)
foreach (var wire in powernet.WireList)
{
//Only a few wires should pass this if check since each will create and take all the others into its powernet
if (wire.Regenerating)
@@ -38,10 +55,16 @@ namespace Content.Shared.GameObjects.EntitySystems
}
}
foreach(var powernet in Powernets)
foreach (var powernet in Powernets)
{
powernet.Update(frametime);
}
// Draw power for devices not connected to anything.
foreach (var device in componentManager.GetComponents<PowerDeviceComponent>())
{
device.ProcessInternalPower(frametime);
}
}
}
}