Skip to content

Commit

Permalink
Granular debug settings and fixed radiation calc
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauge committed Dec 11, 2024
1 parent 8b67555 commit 93a5bab
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 125 deletions.
2 changes: 1 addition & 1 deletion ThermalDynamics/Data/Extinguisher/AmmoMagazines.sbc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<Volume>30</Volume>
<Model>Models\Bottle.mwm</Model>
<PhysicalMaterial>Ammo</PhysicalMaterial>
<Capacity>1</Capacity>
<Capacity>1000</Capacity>
<AmmoDefinitionId Subtype="Bottle" />

<MinimumOfferAmount>50</MinimumOfferAmount>
Expand Down
32 changes: 14 additions & 18 deletions ThermalDynamics/Data/Extinguisher/Ammos.sbc
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,30 @@
<Definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Ammos>


<Ammo xsi:type="MyObjectBuilder_MissileAmmoDefinition">
<Ammo xsi:type="MyObjectBuilder_ProjectileAmmoDefinition">
<Id>
<TypeId>AmmoDefinition</TypeId>
<SubtypeId>Bottle</SubtypeId>
</Id>
<BasicProperties>
<DesiredSpeed>200</DesiredSpeed>
<DesiredSpeed>1</DesiredSpeed>
<SpeedVariance>0</SpeedVariance>
<MaxTrajectory>800</MaxTrajectory>
<IsExplosive>true</IsExplosive>
<MaxTrajectory>0</MaxTrajectory>
<BackkickForce>0</BackkickForce>
<PhysicalMaterial>Missile</PhysicalMaterial>
<PhysicalMaterial>RifleBullet</PhysicalMaterial>
<ExplosiveDamageMultiplier>0</ExplosiveDamageMultiplier>
<DeathMessage>CauseOfDeath_HeavyWeapons</DeathMessage>
<DeathMessage>CauseOfDeath_LightWeapons</DeathMessage>
</BasicProperties>
<MissileProperties>
<MissileMass>1</MissileMass>
<MissileExplosionRadius>4</MissileExplosionRadius>
<MissileModelName>Models\Weapons\Projectile_Missile.mwm</MissileModelName>
<MissileAcceleration>600</MissileAcceleration>
<MissileInitialSpeed>100</MissileInitialSpeed>
<MissileSkipAcceleration>false</MissileSkipAcceleration>
<MissileExplosionDamage>0</MissileExplosionDamage>
<MissileTrailEffect>Smoke_Missile</MissileTrailEffect>
</MissileProperties>
<ExplosionFlags>AFFECT_VOXELS APPLY_FORCE_AND_DAMAGE CREATE_DECALS CREATE_SHRAPNELS APPLY_DEFORMATION FORCE_CUSTOM_END_OF_LIFE_EFFECT</ExplosionFlags>
<ProjectileProperties>
<ProjectileTrailScale>0</ProjectileTrailScale>
<ProjectileHitImpulse>0</ProjectileHitImpulse>
<ProjectileMassDamage>0</ProjectileMassDamage>
<ProjectileHealthDamage>0</ProjectileHealthDamage>
<HeadShot>false</HeadShot>
<ProjectileHeadShotDamage>0</ProjectileHeadShotDamage>
</ProjectileProperties>
</Ammo>


</Ammos>
</Definitions>
24 changes: 24 additions & 0 deletions ThermalDynamics/Data/Extinguisher/Extinguisher.sbc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" ?>
<Definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CubeBlocks>
<Definition>
<Id>
<TypeId>CubeBlock</TypeId>
<SubtypeId>Extinguisher</SubtypeId>
</Id>
<DisplayName>{LOC:DisplayName_Extinguisher}</DisplayName>
<Description>{LOC:Description_Extinguisher}</Description>
<Icon>Textures\GUI\Icons\AstronautBackpack.dds</Icon>
<CubeSize>Large</CubeSize>
<BlockTopology>TriangleMesh</BlockTopology>
<Size x="1" y="1" z="1"/>
<ModelOffset x="0" y="0" z="0"/>
<Model>Models\Extinguisher.mwm</Model>
<Components>
<Component Subtype="SteelPlate" Count="10"/>
</Components>
<CriticalComponent Subtype="SteelPlate" Index="0"/>
<BlockPairName>Extinguisher</BlockPairName>
</Definition>
</CubeBlocks>
</Definitions>
2 changes: 1 addition & 1 deletion ThermalDynamics/Data/Extinguisher/HandItems.sbc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<HandItem xsi:type="MyObjectBuilder_HandItemDefinition">
<Id Type="MyObjectBuilder_AutomaticRifle" Subtype="ExtinguisherGun" />

<WeaponType>RocketLauncher</WeaponType>
<WeaponType>Rifle</WeaponType>

<LeftHandOrientation>
<X>0.324681967</X>
Expand Down
50 changes: 15 additions & 35 deletions ThermalDynamics/Data/Extinguisher/Weapons.sbc
Original file line number Diff line number Diff line change
@@ -1,49 +1,29 @@
<?xml version="1.0"?>
<Definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Weapons>

<Weapon>
<Id>
<TypeId>WeaponDefinition</TypeId>
<SubtypeId>ExtinguisherGun</SubtypeId>
</Id>
<MissileAmmoData RateOfFire="240" ShootSoundName="WepRocketLaunchShot" FlightSoundName="MissileFlightSound" ShotsInBurst="1" />
<NoAmmoSoundName>WepRocketLaunchNoAmmo</NoAmmoSoundName>
<ReloadSoundName>WepRocketLaunchReload</ReloadSoundName>
<DeviateShotAngle>3</DeviateShotAngle>
<DeviateShotAngleAiming>1</DeviateShotAngleAiming>
<ProjectileAmmoData RateOfFire="1000" ShootSoundName="WepPlayRifleNoAmmo" ShotsInBurst="1"/>
<NoAmmoSoundName>WepPlayRifleNoAmmo</NoAmmoSoundName>
<ReloadSoundName>WepRifleReloadShort</ReloadSoundName>
<ReleaseTimeAfterFire>0</ReleaseTimeAfterFire>
<DeviateShotAngle>0</DeviateShotAngle>
<DeviateShotAngleAiming>0</DeviateShotAngleAiming>
<MuzzleFlashLifeSpan>0</MuzzleFlashLifeSpan>
<Effects>
</Effects>
<AmmoMagazines>
<AmmoMagazine Subtype="BottleMag" />
</AmmoMagazines>
<ReloadTime>4000</ReloadTime>
<RecoilJetpackVertical>0</RecoilJetpackVertical>
<RecoilJetpackHorizontal>0</RecoilJetpackHorizontal>
<RecoilGroundVertical>0</RecoilGroundVertical>
<RecoilGroundHorizontal>0</RecoilGroundHorizontal>
<RecoilMultiplierDataNames>
<string>Standing</string>
<string>Walking</string>
<string>Running</string>
<string>Crouching</string>
<string>Aiming</string>
</RecoilMultiplierDataNames>
<RecoilMultiplierDataVerticals>
<float>1</float>
<float>1</float>
<float>1.5</float>
<float>.75</float>
<float>.75</float>
</RecoilMultiplierDataVerticals>
<RecoilMultiplierDataHorizontals>
<float>1</float>
<float>1</float>
<float>1.5</float>
<float>.75</float>
<float>.75</float>
</RecoilMultiplierDataHorizontals>
<ShootDirectionUpdateTime>200</ShootDirectionUpdateTime>
<EquipDuration>0.5</EquipDuration>
<ShakeOnActionPrimary>true</ShakeOnActionPrimary>

<ReloadTime>2000</ReloadTime>

<ShootDirectionUpdateTime>0</ShootDirectionUpdateTime>
<EquipDuration>1</EquipDuration>
<ShakeOnActionPrimary>false</ShakeOnActionPrimary>
<ShakeOnActionSecondary>false</ShakeOnActionSecondary>
<ShakeOnActionTertiary>false</ShakeOnActionTertiary>
</Weapon>
Expand Down
12 changes: 6 additions & 6 deletions ThermalDynamics/Data/Scripts/Thermodynamics/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override void Simulate()
{
if (MyAPIGateway.Utilities.IsDedicated) return;

if (Settings.Instance.Debug)
if (Settings.Instance.DebugTextOnScreen)
{
//MyAPIGateway.Utilities.ShowNotification($"[Grid] Frequency: {Settings.Instance.Frequency}", 1, "White");
MatrixD matrix = MyAPIGateway.Session.Camera.WorldMatrix;
Expand All @@ -75,7 +75,7 @@ public override void Simulate()
return;

MyAPIGateway.Utilities.ShowNotification(
//$"[Cell] {c.Block.Position} " +
$"[Cell] {c.Block.Position} " +
$"T: {c.Temperature.ToString("n3")} " +
$"Gain: {(c.DeltaTemperature + c.HeatGeneration).ToString("n3")} " +
$"dT: {c.DeltaTemperature.ToString("n3")} " +
Expand All @@ -95,11 +95,11 @@ public override void Simulate()
$"prod: {c.EnergyProduction} " +
$"cons: {(c.EnergyConsumption + c.ThrustEnergyConsumption)} ", 1, "White");

MyAPIGateway.Utilities.ShowNotification($"[Solar] {g.FrameAmbientTemprature.ToString("n3")}", 1, "White");
MyAPIGateway.Utilities.ShowNotification($"[Solar] Intensity: {c.IntensityDebug.ToString("n4")} Direction: {g.FrameSolarDirection.ToString("n3")}", 1, "White");

MyAPIGateway.Utilities.ShowNotification($"[Env] Ambiant: {g.FrameAmbientTemprature.ToString("n3")}", 1, "White");

MyAPIGateway.Utilities.ShowNotification($"[Grid] {g.DebugSurfaceStateText(g.Surfaces[position])} ", 1, "White");

MyAPIGateway.Utilities.ShowNotification($"[Grid] {string.Join(" ", c.TouchingSerfacesByNeighbor)}", 1, "White");
MyAPIGateway.Utilities.ShowNotification($"[Surface] {g.DebugSurfaceStateText(g.Surfaces[position])} ", 1, "White");

StringBuilder sb = new StringBuilder();
foreach (var loop in g.ThermalLoops)
Expand Down
18 changes: 13 additions & 5 deletions ThermalDynamics/Data/Scripts/Thermodynamics/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ public class Settings
public int Version;

[ProtoMember(2)]
public bool Debug;
public bool DebugTextOnScreen;

[ProtoMember(3)]
public bool DebugBlockColors;
public bool DebugTemperatureBlockColors;

[ProtoMember(4)]
public bool DebugSolarRadiationBlockColors;

[ProtoMember(5)]
public bool DebugSolarRaycast;

[ProtoMember(8)]
public bool EnableEnvironment;
Expand Down Expand Up @@ -88,13 +94,15 @@ public static Settings GetDefaults()
{
Settings s = new Settings {
Version = 1,
Debug = true,
DebugBlockColors = true,
DebugTextOnScreen = true,
DebugTemperatureBlockColors = true,
DebugSolarRadiationBlockColors = false,
DebugSolarRaycast = false,
EnableEnvironment = true,
EnableSolarHeat = true,
EnablePlanets = true,
EnableDamage = true,
Frequency = 60,
Frequency = 3,
SimulationSpeed = 1,
VacuumTemperature = 2.7f,
SolarEnergy = 1000f,
Expand Down
63 changes: 37 additions & 26 deletions ThermalDynamics/Data/Scripts/Thermodynamics/ThermalCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public class ThermalCell
public float Boltzmann;
public float[] kA;


public float IntensityDebug;


public ThermalGrid Grid;
public IMySlimBlock Block;
public ThermalCellDefinition Definition;
Expand Down Expand Up @@ -450,12 +454,8 @@ internal void Update()
HeatGeneration = ((EnergyProduction * Definition.ProducerWasteEnergy) + ((EnergyConsumption + ThrustEnergyConsumption) * Definition.ConsumerWasteEnergy)) * ThermalMassInv;
Temperature += HeatGeneration;


//TODO: this is only used for debug and can be removed later on
//Radiation = C * totalRadiation * ThermalMassInv;

HandleCriticalTemperature();
DebugDrawColors();
DebugDrawColorsTemperature();
}

private float CalculateTotalRadiation()
Expand All @@ -472,6 +472,8 @@ private float CalculateTotalRadiation()
if (Settings.Instance.EnableSolarHeat && !Grid.FrameSolarOccluded)
{
float intensity = DirectionalRadiationIntensity(ref Grid.FrameSolarDirection, ref Grid.SolarRadiationNode);
IntensityDebug = intensity;
DebugDrawColorsSolar(intensity);
totalRadiation += Settings.Instance.SolarEnergy * Definition.Emissivity * (intensity * ExposedSurfaceArea);
}

Expand Down Expand Up @@ -505,41 +507,50 @@ private void UpdateExposedSurfaceArea()
internal float DirectionalRadiationIntensity(ref Vector3 targetDirection, ref ThermalRadiationNode node)
{
float intensity = 0;
bool isCube = (Block.Max - Block.Min).Volume() <= 1;

for (int i = 0; i < 6; i++)
{
intensity += CalculateDirectionIntensity(i, ExposedSurfacesByDirection[i], ref targetDirection, ref node, isCube);
}
int surfaceCount = ExposedSurfacesByDirection[i];
if (surfaceCount == 0) continue;

Vector3D startDirection = Vector3D.Rotate(ThermalGrid.Directions[i], Grid.FrameMatrix);
float dot = Vector3.Dot(startDirection, targetDirection);

dot = Math.Max(0, dot);

if (surfaceCount > 1)
{
node.Sides[i] += dot * surfaceCount;
node.SideSurfaces[i] += surfaceCount;
intensity += dot;
}
else
{
intensity += Math.Min(dot, node.SideAverages[i]);
}
}
return intensity;
}

private float CalculateDirectionIntensity(int directionIndex, int surfaceCount, ref Vector3 targetDirection, ref ThermalRadiationNode node, bool isCube)
{
Vector3I direction = ThermalGrid.Directions[directionIndex];
Vector3D startDirection = Vector3D.Rotate(direction, Grid.FrameMatrix);
float dot = Vector3.Dot(startDirection, targetDirection);

dot = Math.Max(0, dot);

if (isCube)
{
node.Sides[directionIndex] += dot * surfaceCount;
node.SideSurfaces[directionIndex] += surfaceCount;
return dot;
}
else
private void DebugDrawColorsTemperature()
{
if (Settings.Instance.DebugTemperatureBlockColors && MyAPIGateway.Session.IsServer)
{
return Math.Min(dot, node.SideAverages[directionIndex]);
Vector3 color = Tools.GetTemperatureColor(Temperature);
if (Block.ColorMaskHSV != color)
{
Block.CubeGrid.ColorBlocks(Block.Min, Block.Max, color);
}
}
}

private void DebugDrawColors()
private void DebugDrawColorsSolar(float intensity)
{
if (Settings.Instance.DebugBlockColors && MyAPIGateway.Session.IsServer)

if (Settings.Instance.DebugSolarRadiationBlockColors && MyAPIGateway.Session.IsServer)
{
Vector3 color = Tools.GetTemperatureColor(Temperature);
Vector3 color = Tools.GetTemperatureColor(Math.Abs(intensity), 3, 0.5f, 1.5f);
if (Block.ColorMaskHSV != color)
{
Block.CubeGrid.ColorBlocks(Block.Min, Block.Max, color);
Expand Down
13 changes: 5 additions & 8 deletions ThermalDynamics/Data/Scripts/Thermodynamics/ThermalGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,9 @@ private void SetFrameAmbiantTemperature(float temperature)

private void PrepareSolarEnvironment(ref Vector3D position)
{

FrameSolarDirection = MyVisualScriptLogicProvider.GetSunDirection();

if (!Settings.Instance.EnableSolarHeat) return;

FrameSolarDirection = MyVisualScriptLogicProvider.GetSunDirection();
SolarRadiationNode.Update();

FrameSolarOccluded = false;
Expand Down Expand Up @@ -553,10 +551,10 @@ private void PrepareSolarEnvironment(ref Vector3D position)

voxel.PositionComp.WorldAABB.Intersect(ref line, out subLine);
//Vector3D start = Vector3D.Transform((Vector3D)(Vector3)ExposedSurface[i] * gridSize, matrix);
var green = Color.Green.ToVector4();

if (Settings.Instance.Debug && !MyAPIGateway.Utilities.IsDedicated)
if (Settings.Instance.DebugSolarRaycast && !MyAPIGateway.Utilities.IsDedicated)
{
var green = Color.Green.ToVector4();
MySimpleObjectDraw.DrawLine(subLine.From, subLine.To, MyStringId.GetOrCompute("Square"), ref green, 0.2f);
}

Expand Down Expand Up @@ -585,7 +583,7 @@ private void PrepareSolarEnvironment(ref Vector3D position)

var blue = Color.Blue.ToVector4();

if (Settings.Instance.Debug && !MyAPIGateway.Utilities.IsDedicated)
if (Settings.Instance.DebugSolarRaycast && !MyAPIGateway.Utilities.IsDedicated)
{

MySimpleObjectDraw.DrawLine(subLine.From, subLine.To, MyStringId.GetOrCompute("Square"), ref blue, 0.2f);
Expand All @@ -601,10 +599,9 @@ private void PrepareSolarEnvironment(ref Vector3D position)
}
}

if (Settings.Instance.Debug && !MyAPIGateway.Utilities.IsDedicated)
if (Settings.Instance.DebugSolarRaycast && !MyAPIGateway.Utilities.IsDedicated)
{
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);
}
}
Expand Down
Loading

0 comments on commit 93a5bab

Please sign in to comment.