Skip to content

Commit

Permalink
Added environmental flag and broke up execution into chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauge committed Nov 30, 2024
1 parent 3c8f264 commit 0e2951e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 42 deletions.
31 changes: 17 additions & 14 deletions ThermalDynamics/Data/Scripts/Thermodynamics/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ public class Settings
public static Settings Instance;

public static readonly MyStringHash DefaultSubtypeId = MyStringHash.GetOrCompute("DefaultThermodynamics");
public static readonly MyStringHash DefaultLowMassSubtypeId = MyStringHash.GetOrCompute("DefaultLowMassThermodynamics");

[ProtoMember(1)]
public int Version;

[ProtoMember(3)]
public bool EnableEnvironment;

[ProtoMember(5)]
public bool EnableSolarHeat;

Expand All @@ -45,18 +49,18 @@ public class Settings
[ProtoMember(16)]
public float SimulationSpeed;

/// <summary>
/// the temperature in kelven for space
/// </summary>
[ProtoMember(30)]
public float VacuumTemperature;

/// <summary>
/// SolarEnergy = watts/m^2
/// </summary>
[ProtoMember(110)]
[ProtoMember(40)]
public float SolarEnergy;

[ProtoMember(120)]
public float EnvironmentalRaycastDistance;

[ProtoMember(130)]
public float VaccumeRadiationStrength;

[ProtoMember(140)]
public float PresurizedAtmoConductivity;

Expand All @@ -74,20 +78,19 @@ public static Settings GetDefaults()
{
Settings s = new Settings {
Version = 1,
EnableSolarHeat = true, //atm includes all external heat source
EnableEnvironment = true,
EnableSolarHeat = false,
EnableDamage = true,
Frequency = 1,
SimulationSpeed = 10,
SolarEnergy = 0f,
EnvironmentalRaycastDistance = 5000f,
VaccumeRadiationStrength = 0.05f,
SimulationSpeed = 1,
VacuumTemperature = 2.7f,
SolarEnergy = 0f,
PresurizedAtmoConductivity = 0.026f,
PresurizedAtmoSpecificHeat = 1005,
};

s.Init();
return s;

return s;
}

private void Init() {
Expand Down
7 changes: 6 additions & 1 deletion ThermalDynamics/Data/Scripts/Thermodynamics/ThermalCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,12 @@ private void UpdateFrameAndLastTemperature()
private float CalculateTotalRadiation()
{
float temperatureSquared = Temperature * Temperature;
float totalRadiation = Boltzmann * Definition.Emissivity * (temperatureSquared * temperatureSquared) - Grid.FrameAmbientTempratureP4;
float totalRadiation = 0;

if (Settings.Instance.EnableEnvironment)
{
totalRadiation = Boltzmann * Definition.Emissivity * (temperatureSquared * temperatureSquared) - Grid.FrameAmbientTempratureP4;
}

if (Settings.Instance.EnableSolarHeat && !Grid.FrameSolarOccluded)
{
Expand Down
65 changes: 38 additions & 27 deletions ThermalDynamics/Data/Scripts/Thermodynamics/ThermalGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public partial class ThermalGrid : MyGameLogicComponent

public float FrameAmbientTemprature;
public float FrameAmbientTempratureP4;
public float FrameSolarDecay;
//public float FrameSolarDecay;
public bool FrameSolarOccluded;

public override void Init(MyObjectBuilder_EntityBase objectBuilder)
Expand Down Expand Up @@ -403,40 +403,49 @@ private void PrepareNextSimulationStep()
{

Vector3D position = Grid.PositionComp.WorldAABB.Center;
PrepareEnvironmentTemprature(ref position);
PrepareSolarEnvironment(ref position);
PrepareEnvironmentTemprature(ref position);
}

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


bool isUnderground = false;
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);
private void PrepareEnvironmentTemprature(ref Vector3D position) {

if (!Settings.Instance.EnableEnvironment) return;

float ambient = def.UndergroundTemperature;
if (!isUnderground)
PlanetManager.Planet planet = PlanetManager.GetClosestPlanet(position);
float frameAmbiSquared;
if (planet == null)
{
float dot = (float)Vector3D.Dot(Vector3D.Normalize(local), FrameSolarDirection);
ambient = def.NightTemperature + ((dot + 1f) * 0.5f * (def.DayTemperature - def.NightTemperature));
FrameAmbientTemprature = Settings.Instance.VacuumTemperature;
frameAmbiSquared = FrameAmbientTemprature * FrameAmbientTemprature;
FrameAmbientTempratureP4 = frameAmbiSquared * frameAmbiSquared;
}
else
else
{
FrameSolarOccluded = true;
}
bool isUnderground = false;
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);

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;
}

FrameAmbientTemprature = Math.Max(Settings.Instance.VacuumTemperature, ambient * airDensity);
frameAmbiSquared = FrameAmbientTemprature * FrameAmbientTemprature;
FrameAmbientTempratureP4 = frameAmbiSquared * frameAmbiSquared;
//FrameSolarDecay = 1 - def.SolarDecay * airDensity;
}

//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);
Expand All @@ -446,12 +455,14 @@ private void PrepareEnvironmentTemprature(ref Vector3D position)

private void PrepareSolarEnvironment(ref Vector3D position)
{

FrameSolarDirection = MyVisualScriptLogicProvider.GetSunDirection();

if (!Settings.Instance.EnableSolarHeat) return;

SolarRadiationNode.Update();

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

LineD line = new LineD(position, position + (FrameSolarDirection * 15000000));
Expand Down

0 comments on commit 0e2951e

Please sign in to comment.