Skip to content

Commit

Permalink
Coolant loops now save
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauge committed Dec 7, 2024
1 parent 482f3e8 commit 2ab2ba6
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 20 deletions.
8 changes: 4 additions & 4 deletions ThermalDynamics/Data/Cubes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Group Name="ThermalBlockProperties">
<Bool Name="IgnoreThermals" Value="false" />
<Decimal Name="Conductivity" Value="0.70" />
<Decimal Name="SpecificHeat" Value="1.0" />
<Decimal Name="SpecificHeat" Value="1" />
<Decimal Name="Emissivity" Value="0.125" />
<Decimal Name="SurfaceAreaScaler" Value ="1" />
<Decimal Name="ProducerWasteEnergy" Value="0.05" />
Expand All @@ -32,11 +32,11 @@
<Bool Name="IgnoreThermals" Value="false" />
<Decimal Name="Conductivity" Value="1" />
<Decimal Name="SpecificHeat" Value="2" />
<Decimal Name="Emissivity" Value="0.25" />
<Decimal Name="Emissivity" Value="0.15" />
<Decimal Name="SurfaceAreaScaler" Value ="1" />
<Decimal Name="ProducerWasteEnergy" Value="0" />
<Decimal Name="ConsumerWasteEnergy" Value="0.25" />
<Decimal Name="CriticalTemperature" Value="1200" />
<Decimal Name="CriticalTemperature" Value="1050" />
<Decimal Name="CriticalTemperatureScaler" Value="0.25"/>
</Group>
</ModExtensions>
Expand All @@ -56,7 +56,7 @@
<Decimal Name="SurfaceAreaScaler" Value ="1" />
<Decimal Name="ProducerWasteEnergy" Value="0" />
<Decimal Name="ConsumerWasteEnergy" Value="0.25" />
<Decimal Name="CriticalTemperature" Value="1500" />
<Decimal Name="CriticalTemperature" Value="1200" />
<Decimal Name="CriticalTemperatureScaler" Value="0.25"/>
</Group>
</ModExtensions>
Expand Down
23 changes: 12 additions & 11 deletions ThermalDynamics/Data/EntityComponents.sbc
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<Definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<EntityComponents>
<EntityComponent xsi:type="MyObjectBuilder_ModStorageComponentDefinition">
<Id>
<TypeId>ModStorageComponent</TypeId>
<SubtypeId>ThermalDynamics</SubtypeId>
</Id>
<RegisteredStorageGuids>
<guid>f7cd64ae-9cd8-41f3-8e5d-3db992619343</guid>
</RegisteredStorageGuids>
</EntityComponent>
</EntityComponents>
<EntityComponents>
<EntityComponent xsi:type="MyObjectBuilder_ModStorageComponentDefinition">
<Id>
<TypeId>ModStorageComponent</TypeId>
<SubtypeId>ThermalDynamics</SubtypeId>
</Id>
<RegisteredStorageGuids>
<guid>f7cd64ae-9cd8-41f3-8e5d-3db992619343</guid>
<guid>f7cd64ae-9cd8-41f3-8e5d-3db992619344</guid>
</RegisteredStorageGuids>
</EntityComponent>
</EntityComponents>
</Definitions>
4 changes: 2 additions & 2 deletions ThermalDynamics/Data/Scripts/Thermodynamics/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ public static Settings GetDefaults()
Debug = true,
DebugBlockColors = true,
EnableEnvironment = true,
EnableSolarHeat = false,
EnableSolarHeat = true,
EnablePlanets = true,
EnableDamage = true,
Frequency = 3,
Frequency = 2,
SimulationSpeed = 1,
VacuumTemperature = 2.7f,
SolarEnergy = 500f,
Expand Down
70 changes: 67 additions & 3 deletions ThermalDynamics/Data/Scripts/Thermodynamics/ThermalGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public partial class ThermalGrid : MyGameLogicComponent
{

private static readonly Guid StorageGuid = new Guid("f7cd64ae-9cd8-41f3-8e5d-3db992619343");

private static readonly Guid StorageGuidLoops = new Guid("f7cd64ae-9cd8-41f3-8e5d-3db992619344");

public MyCubeGrid Grid;
public Dictionary<int, int> PositionToIndex = new Dictionary<int, int>();
public MyFreeList<ThermalCell> Thermals = new MyFreeList<ThermalCell>();
Expand Down Expand Up @@ -153,21 +154,69 @@ private void Unpack(string data)
int f = bytes[i + 4];
f |= bytes[i + 5] << 8;

MyLog.Default.Info($"[{Settings.Name}] [Unpack] {id} {PositionToIndex[id]} {Thermals.ItemArray[PositionToIndex[id]].Block.BlockDefinition.Id} - T: {f}");

Thermals.ItemArray[PositionToIndex[id]].Temperature = f;
}

//MyLog.Default.Info($"[{Settings.Name}] [Unpack] {id} {PositionToIndex[id]} {Thermals.list[PositionToIndex[id]].Block.BlockDefinition.Id} - T: {f}");

}
catch { }
}

private string PackLoops()
{
byte[] bytes = new byte[ThermalLoops.Count * 3];

int bi = 0;
for (int i = 0; i < ThermalLoops.Count; i++)
{
ThermalLoop l = ThermalLoops[i];
if (l == null) continue;

bytes[bi] = (byte)i;
short t = (short)(l.Temperature);
bytes[bi + 1] = (byte)t;
bytes[bi + 2] = (byte)(t >> 8);

bi += 3;

//TODO: keep track of this. it might cause weird behaivor.
l.Temperature = t;
}

return Convert.ToBase64String(bytes);
}

private void UnpackLoops(string data)
{
try
{
byte[] bytes = Convert.FromBase64String(data);

for (int i = 0; i < bytes.Length; i += 3)
{
int id = bytes[i];

int f = bytes[i+1];
f |= bytes[i+2] << 8;

MyLog.Default.Info($"[{Settings.Name}] [UnpackLoops] {id} - T: {f}");

ThermalLoops[id].Temperature = f;
}
}
catch { }
}


private void Save()
{
//Stopwatch sw = Stopwatch.StartNew();

string data = Pack();
string loopdata = PackLoops();

//string data = Convert.ToBase64String(MyAPIGateway.Utilities.SerializeToBinary(PackGridInfo()));

MyModStorageComponentBase storage = Entity.Storage;
if (storage.ContainsKey(StorageGuid))
Expand All @@ -178,6 +227,16 @@ private void Save()
{
storage.Add(StorageGuid, data);
}

if (storage.ContainsKey(StorageGuidLoops))
{
storage[StorageGuidLoops] = loopdata;
}
else
{
storage.Add(StorageGuidLoops, loopdata);
}

//sw.Stop();
//MyLog.Default.Info($"[{Settings.Name}] [SAVE] {Grid.DisplayName} ({Grid.EntityId}) t-{((float)sw.ElapsedTicks / TimeSpan.TicksPerMillisecond).ToString("n8")}ms, size: {data.Length}");
}
Expand All @@ -191,6 +250,11 @@ private void Load()
Unpack(Entity.Storage[StorageGuid]);
}

if (Entity.Storage.ContainsKey(StorageGuidLoops))
{
UnpackLoops(Entity.Storage[StorageGuidLoops]);
}

//sw.Stop();
//MyLog.Default.Info($"[{Settings.Name}] [LOAD] {Grid.DisplayName} ({Grid.EntityId}) t-{((float)sw.ElapsedTicks / TimeSpan.TicksPerMillisecond).ToString("n8")}ms");
}
Expand Down

0 comments on commit 2ab2ba6

Please sign in to comment.