Skip to content

Commit

Permalink
Fixed surface area calculation
Browse files Browse the repository at this point in the history
Fixed an issue where surface area was not being calculated accurately between blocks.

Improved the system for identifying airtightness/exposed surfaces
  • Loading branch information
Gauge committed Nov 27, 2024
1 parent d036b90 commit 985c4b9
Show file tree
Hide file tree
Showing 5 changed files with 446 additions and 337 deletions.
18 changes: 9 additions & 9 deletions ThermalDynamics/Data/Scripts/Thermodynamics/MyFreeList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Thermodynamics
{
public class MyFreeList<TItem>
{
public TItem[] list;
public TItem[] ItemArray;

private int m_size;

Expand All @@ -24,11 +24,11 @@ public class MyFreeList<TItem>
/// </summary>
public int Count => m_size - m_freePositions.Count;

public int Capacity => list.Length;
public int Capacity => ItemArray.Length;

public MyFreeList(int capacity = 16, TItem defaultValue = default(TItem))
{
list = new TItem[16];
ItemArray = new TItem[16];
m_freePositions = new Queue<int>(capacity / 2);
m_default = defaultValue;
}
Expand All @@ -39,23 +39,23 @@ public int Allocate()
{
return m_freePositions.Dequeue();
}
if (m_size == list.Length)
if (m_size == ItemArray.Length)
{
Array.Resize(ref list, list.Length << 1);
Array.Resize(ref ItemArray, ItemArray.Length << 1);
}
return m_size++;
}

public int Allocate(TItem value)
{
int num = Allocate();
list[num] = value;
ItemArray[num] = value;
return num;
}

public void Free(int position)
{
list[position] = m_default;
ItemArray[position] = m_default;
if (position == m_size)
{
m_size--;
Expand All @@ -68,7 +68,7 @@ public void Free(int position)

public TItem[] GetInternalArray()
{
return list;
return ItemArray;
}

public bool KeyValid(int key)
Expand All @@ -80,7 +80,7 @@ public void Clear()
{
for (int i = 0; i < m_size; i++)
{
list[i] = default(TItem);
ItemArray[i] = default(TItem);
}
m_size = 0;
m_freePositions.Clear();
Expand Down
28 changes: 14 additions & 14 deletions ThermalDynamics/Data/Scripts/Thermodynamics/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using VRage.Game.ModAPI;
using VRage.Utils;
using VRageMath;
using static VRageRender.MyBillboard;

namespace Thermodynamics
{
Expand Down Expand Up @@ -99,7 +98,8 @@ public override void Simulate()
$"T: {c.Temperature.ToString("n4")} " +
$"dT: {c.DeltaTemperature.ToString("n6")} " +
$"Gen: {c.HeatGeneration.ToString("n4")} " +
$"ext: {c.ExposedSurfaces.ToString("n4")} ", 1, "White");
$"ext: {c.ExposedSurfaces.ToString("n4")} " +
$"kA: {string.Join(", ", c.kA)}", 1, "White");

MyAPIGateway.Utilities.ShowNotification(
$"[Calc] m: {c.Mass.ToString("n0")} " +
Expand All @@ -108,28 +108,28 @@ public override void Simulate()
$"em {c.Definition.Emissivity} " +
$"pwe: {c.Definition.ProducerWasteEnergy} " +
$"cwe: {c.Definition.ConsumerWasteEnergy} " +
$"kA: {(c.Definition.Conductivity * c.Area).ToString("n0")} " +
$"tm: {(c.Definition.SpecificHeat * c.Mass).ToString("n0")} " +
$"c: {c.C.ToString("n4")} " +
$"r: {c.Radiation.ToString("n2")} " +
$"rdt: {(c.Radiation * c.ThermalMassInv).ToString("n4")} " +
$"prod: {c.EnergyProduction} " +
$"cons: {(c.EnergyConsumption + c.ThrustEnergyConsumption)} ", 1, "White");

//MyAPIGateway.Utilities.ShowNotification($"[Solar] {c.SolarIntensity.ToString("n3")} Average: {g.AverageSolarHeat[0].ToString("n3")}, {tGrid.AverageSolarHeat[1].ToString("n3")}, {tGrid.AverageSolarHeat[2].ToString("n3")}, {tGrid.AverageSolarHeat[3].ToString("n3")}, {tGrid.AverageSolarHeat[4].ToString("n3")}, {tGrid.AverageSolarHeat[5].ToString("n3")}", 1, "White");

//Grid.AverageSolarHeat[directionIndex])

//MyAPIGateway.Utilities.ShowNotification($"[Grid] Exposed: {tGrid.ExposedNodes.Count} {tGrid.ExposedSurface.Count} inside: {tGrid.InsideNodes.Count} {tGrid.InsideSurface.Count} Rooms: {tGrid.Rooms.Count}", 1, "White");
//MyAPIGateway.Utilities.ShowNotification($"[Cell] Exposed: {cell.Exposed.Count} {cell.ExposedSurface.Count} Inside: {cell.Inside.Count} {cell.InsideSurface.Count} SurfaceArea: {cell.ExposedSurfaceArea}", 1, "White");

int value = g.NodeSurfaces[position];
MyAPIGateway.Utilities.ShowNotification(
$"[Grid] Exterior: {g.ExteriorNodes.Count} " +
$"Nodes: {g.NodeSurfaces.Count} " +
$"RNodes: {g.Rooms.Count} " +
$"sq: {g.SolidQueue.Count} " +
$"rq: {g.RoomQueue.Count} " +
$"CrawlDone: {g.ThermalCellUpdateComplete} " +
$"sbn: {string.Join(", ", c.TouchingSerfacesByNeighbor)}", 1, "White");

//MyAPIGateway.Utilities.ShowNotification($"[Cell] Input: {cell.PowerInput} heat: {cell.PowerInput * cell.ConsumerGeneration} heatPerWatt: {cell.ConsumerGeneration}", 1, "White");
//MyAPIGateway.Utilities.ShowNotification($"[Cell] Output: {cell.PowerOutput} heat: {cell.PowerOutput * cell.ProducerGeneration} heatPerWatt: {cell.ProducerGeneration}", 1, "White");
MyAPIGateway.Utilities.ShowNotification(
$"[Cell] Airtight out: {((value & 1 << 0) != 0 ? 1:0)}, {((value & 1 << 1) != 0 ? 1:0)}, {((value & 1 << 2) != 0?1:0)}, {((value & 1 << 3) != 0?1:0)}, {((value & 1 << 4) != 0?1:0)}, {((value & 1 << 5) != 0 ? 1 : 0)}, " +
$"in: {((value & 1 << 6) != 0?1:0)}, {((value & 1 << 7) != 0 ? 1 : 0)}, {((value & 1 << 8) != 0 ? 1 : 0)}, {((value & 1 << 9) != 0 ? 1 : 0)}, {((value & 1 << 10) != 0?1:0)}, {((value & 1 << 11) != 0?1:0)}", 1, "White");


//MyAPIGateway.Utilities.ShowNotification($"[Cell] Exposed: {cell.Exposed.Count} Inside: {cell.Inside.Count} SurfaceArea: {cell.ExposedSurfaceArea}", 1, "White");
//MyAPIGateway.Utilities.ShowNotification($"[External] {tGrid.Mapper.Blocks.Count} EComplete: {tGrid.Mapper.ExternalRoomUpdateComplete} BComplete: {tGrid.ThermalCellUpdateComplete}", 1, "White");
}
}

Expand Down
Loading

0 comments on commit 985c4b9

Please sign in to comment.