Skip to content

Commit

Permalink
Broke out heat simulation prep calc
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauge committed Jul 27, 2024
1 parent 383e41f commit 39b5cac
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 35 deletions.
4 changes: 2 additions & 2 deletions ThermalDynamics/Data/Scripts/Thermodynamics/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Settings
public const string Filename = "ThermodynamicsConfig.cfg";
public const string Name = "Thermodynamics";
public const bool Debug = true;
public const bool DebugBlockColors = true;
public const bool DebugBlockColors = false;

public static Settings Instance;

Expand Down Expand Up @@ -77,7 +77,7 @@ public static Settings GetDefaults()
EnableDamage = true,
Frequency = 60,
SimulationSpeed = 1,
SolarEnergy = 40000f,
SolarEnergy = 1000f,
EnvironmentalRaycastDistance = 5000f,
VaccumeRadiationStrength = 0.05f,
PresurizedAtmoConductivity = 0.026f,
Expand Down
8 changes: 7 additions & 1 deletion ThermalDynamics/Data/Scripts/Thermodynamics/ThermalCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@ private void UpdateHeat()
/// </summary>
internal void Update()
{
// TODO: wind/liquid convective cooling
//float viscosity =
//float windIntensity = DirectionalRadiationIntensity(ref Grid.FrameWindDirection, ref Grid.WindNode);
//float v = Grid.FrameWindDirection.Length();
//float hc = 10.45f - v + 10f * (float)Math.Sqrt(v);

UpdateFrameAndLastTemperature();
float totalRadiation = CalculateTotalRadiation();
float deltaTemperature = CalculateDeltaTemperature();
Expand Down Expand Up @@ -463,7 +469,7 @@ private void HandleCriticalTemperature()

private void UpdateDebugVisuals()
{
if (Settings.Debug && MyAPIGateway.Session.IsServer)
if (Settings.DebugBlockColors && MyAPIGateway.Session.IsServer)
{
Vector3 color = Tools.GetTemperatureColor(Temperature);
if (Block.ColorMaskHSV != color)
Expand Down
73 changes: 41 additions & 32 deletions ThermalDynamics/Data/Scripts/Thermodynamics/ThermalGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,48 +390,58 @@ public override void UpdateBeforeSimulation()

private void PrepareNextSimulationStep()
{
SolarRadiationNode.Update();

FrameSolarOccluded = false;
FrameSolarDirection = MyVisualScriptLogicProvider.GetSunDirection();
FrameMatrix = Grid.WorldMatrix;

Vector3D position = Grid.PositionComp.WorldAABB.Center;
PlanetManager.Planet p = PlanetManager.GetClosestPlanet(position);
PrepareEnvironmentTemprature(ref position);
PrepareSolarEnvironment(ref position);
}

private void PrepareEnvironmentTemprature(ref Vector3D position)
{
PlanetManager.Planet planet = PlanetManager.GetClosestPlanet(position);
if (planet == null) return;


bool isUnderground = false;
if (p != null)
PlanetDefinition def = planet.Definition();
Vector3 local = position - planet.Position;
Vector3D surfacePointLocal = planet.Entity.GetClosestSurfacePointLocal(ref local);
isUnderground = local.LengthSquared() < surfacePointLocal.LengthSquared();
float airDensity = planet.Entity.GetAirDensity(position);
float windSpeed = planet.Entity.GetWindSpeed(position);


float ambient = def.UndergroundTemperature;
if (!isUnderground)
{
float dot = (float)Vector3D.Dot(Vector3D.Normalize(local), FrameSolarDirection);
ambient = def.NightTemperature + ((dot + 1f) * 0.5f * (def.DayTemperature - def.NightTemperature));
}
else
{
PlanetDefinition def = p.Definition();
Vector3 local = position - p.Position;
Vector3D surfacePointLocal = p.Entity.GetClosestSurfacePointLocal(ref local);
isUnderground = local.LengthSquared() < surfacePointLocal.LengthSquared();
float airDensity = p.Entity.GetAirDensity(position);
float windSpeed = p.Entity.GetWindSpeed(position);
FrameSolarOccluded = true;
}

FrameAmbientTemprature = Math.Max(2.7f, ambient * airDensity);
float frameAmbiSquared = FrameAmbientTemprature * FrameAmbientTemprature;
FrameAmbientTempratureP4 = frameAmbiSquared * frameAmbiSquared;
FrameSolarDecay = 1 - def.SolarDecay * airDensity;

float ambient = def.UndergroundTemperature;
if (!isUnderground)
{
float dot = (float)Vector3D.Dot(Vector3D.Normalize(local), FrameSolarDirection);
ambient = def.NightTemperature + ((dot + 1f) * 0.5f * (def.DayTemperature - def.NightTemperature));
}
else
{
FrameSolarOccluded = true;
}
//FrameWindDirection = Vector3.Cross(planet.GravityComponent.GetWorldGravityNormalized(position), planet.Entity.WorldMatrix.Forward).Normalized() * windSpeed;
//MySimpleObjectDraw.DrawLine(position, position + FrameWindDirection, MyStringId.GetOrCompute("Square"), ref color2, 0.1f);

FrameAmbientTemprature = Math.Max(2.7f, ambient * airDensity);
float frameAmbiSquared = FrameAmbientTemprature * FrameAmbientTemprature;
FrameAmbientTempratureP4 = frameAmbiSquared * frameAmbiSquared;
FrameSolarDecay = 1 - def.SolarDecay * airDensity;
//TODO: implement underground core temparatures
}

FrameWindDirection = Vector3.Cross(p.GravityComponent.GetWorldGravityNormalized(position), p.Entity.WorldMatrix.Forward).Normalized() * windSpeed;
private void PrepareSolarEnvironment(ref Vector3D position)
{
if (!Settings.Instance.EnableSolarHeat) return;

SolarRadiationNode.Update();

//TODO: implement underground core temparatures
}
if (FrameSolarOccluded) return;
FrameSolarOccluded = false;
FrameSolarDirection = MyVisualScriptLogicProvider.GetSunDirection();
FrameMatrix = Grid.WorldMatrix;

LineD line = new LineD(position, position + (FrameSolarDirection * 15000000));
List<MyLineSegmentOverlapResult<MyEntity>> results = new List<MyLineSegmentOverlapResult<MyEntity>>();
Expand Down Expand Up @@ -520,7 +530,6 @@ private void PrepareNextSimulationStep()
var color = (FrameSolarOccluded) ? Color.Red.ToVector4() : Color.White.ToVector4();
var color2 = Color.LightGoldenrodYellow.ToVector4();
MySimpleObjectDraw.DrawLine(position, position + (FrameSolarDirection * 15000000), MyStringId.GetOrCompute("Square"), ref color, 0.1f);
MySimpleObjectDraw.DrawLine(position, position + FrameWindDirection, MyStringId.GetOrCompute("Square"), ref color2, 0.1f);
}
}

Expand Down

0 comments on commit 39b5cac

Please sign in to comment.