Restore the stable legacy Unity project
This commit is contained in:
parent
56a156ee87
commit
7006a6b0dd
2070 changed files with 180490 additions and 169303 deletions
|
|
@ -2,84 +2,93 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using static CultMath.math;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class RadiatorData : BehaviorData
|
||||
{
|
||||
[Inspectable, JsonProperty("emissivity"), Key(1), RuntimeInspectable]
|
||||
public PerformanceStat Emissivity = new PerformanceStat();
|
||||
|
||||
[Inspectable, JsonProperty("pumpedHeat"), Key(2), RuntimeInspectable]
|
||||
public PerformanceStat PumpedHeat = new PerformanceStat();
|
||||
|
||||
[InspectableTemperature, JsonProperty("temperatureFloor"), Key(3), RuntimeInspectable]
|
||||
public float TemperatureFloor;
|
||||
|
||||
[Inspectable, JsonProperty("wasteHeat"), Key(4), RuntimeInspectable]
|
||||
public PerformanceStat WasteHeat = new PerformanceStat();
|
||||
|
||||
[Inspectable, JsonProperty("energyUsage"), Key(5), RuntimeInspectable]
|
||||
public PerformanceStat EnergyUsage = new PerformanceStat();
|
||||
|
||||
[Inspectable, JsonProperty("thermalMass"), Key(6), RuntimeInspectable]
|
||||
public PerformanceStat ThermalMass = new PerformanceStat();
|
||||
|
||||
public override Behavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Radiator(this, item);
|
||||
}
|
||||
|
||||
public override Behavior CreateInstance(ConsumableItemEffect item)
|
||||
{
|
||||
return new Radiator(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Radiator : Behavior, IAlwaysUpdatedBehavior, IInitializableBehavior
|
||||
{
|
||||
public float RadiatorTemperature { get; private set; }
|
||||
|
||||
|
||||
public float Emissivity { get; private set; }
|
||||
public float PumpedHeat { get; private set; }
|
||||
public float WasteHeat { get; private set; }
|
||||
public float EnergyUsage { get; private set; }
|
||||
|
||||
private RadiatorData _data;
|
||||
|
||||
private readonly PerformanceStat _emissivity;
|
||||
private readonly PerformanceStat _pumpedHeat;
|
||||
private readonly float _temperatureFloor;
|
||||
private readonly PerformanceStat _wasteHeat;
|
||||
private readonly PerformanceStat _energyUsage;
|
||||
private readonly PerformanceStat _thermalMass;
|
||||
|
||||
public Radiator(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
|
||||
public Radiator(RadiatorData data, EquippedItem item) : base(data, item)
|
||||
{
|
||||
_emissivity = definition.PerformanceStat(1, new PerformanceStat());
|
||||
_pumpedHeat = definition.PerformanceStat(2, new PerformanceStat());
|
||||
_temperatureFloor = definition.Float(3);
|
||||
_wasteHeat = definition.PerformanceStat(4, new PerformanceStat());
|
||||
_energyUsage = definition.PerformanceStat(5, new PerformanceStat());
|
||||
_thermalMass = definition.PerformanceStat(6, new PerformanceStat());
|
||||
RegisterPerformanceStat(nameof(Emissivity), _emissivity);
|
||||
RegisterPerformanceStat(nameof(PumpedHeat), _pumpedHeat);
|
||||
RegisterPerformanceStat(nameof(WasteHeat), _wasteHeat);
|
||||
RegisterPerformanceStat(nameof(EnergyUsage), _energyUsage);
|
||||
RegisterPerformanceStat("ThermalMass", _thermalMass);
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public Radiator(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
|
||||
public Radiator(RadiatorData data, ConsumableItemEffect item) : base(data, item)
|
||||
{
|
||||
_emissivity = definition.PerformanceStat(1, new PerformanceStat());
|
||||
_pumpedHeat = definition.PerformanceStat(2, new PerformanceStat());
|
||||
_temperatureFloor = definition.Float(3);
|
||||
_wasteHeat = definition.PerformanceStat(4, new PerformanceStat());
|
||||
_energyUsage = definition.PerformanceStat(5, new PerformanceStat());
|
||||
_thermalMass = definition.PerformanceStat(6, new PerformanceStat());
|
||||
RegisterPerformanceStat(nameof(Emissivity), _emissivity);
|
||||
RegisterPerformanceStat(nameof(PumpedHeat), _pumpedHeat);
|
||||
RegisterPerformanceStat(nameof(WasteHeat), _wasteHeat);
|
||||
RegisterPerformanceStat(nameof(EnergyUsage), _energyUsage);
|
||||
RegisterPerformanceStat("ThermalMass", _thermalMass);
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public override bool Execute(float dt)
|
||||
{
|
||||
PumpedHeat = Evaluate(_pumpedHeat);
|
||||
WasteHeat = Evaluate(_wasteHeat);
|
||||
EnergyUsage = Evaluate(_energyUsage);
|
||||
PumpedHeat = Evaluate(_data.PumpedHeat);
|
||||
WasteHeat = Evaluate(_data.WasteHeat);
|
||||
EnergyUsage = Evaluate(_data.EnergyUsage);
|
||||
|
||||
var itemTemperature = Temperature;
|
||||
var tempRatio = max(RadiatorTemperature / itemTemperature, 1);
|
||||
|
||||
|
||||
// Temperature ratio would cause more waste heat than pump capacity, stop executing
|
||||
if (tempRatio > PumpedHeat / WasteHeat) return true;
|
||||
|
||||
if (!Entity.TryConsumeEnergy(EnergyUsage * tempRatio * dt)) return false;
|
||||
|
||||
var pumpedHeat = PumpedHeat * max(itemTemperature - _temperatureFloor, 0);
|
||||
|
||||
|
||||
var pumpedHeat = PumpedHeat * max(itemTemperature - _data.TemperatureFloor, 0);
|
||||
|
||||
// Radiator temperature is below temperature floor, stop executing
|
||||
if (pumpedHeat < 0.01f) return true;
|
||||
|
||||
|
||||
var wasteHeat = WasteHeat * tempRatio;
|
||||
|
||||
|
||||
AddHeat((wasteHeat - pumpedHeat) * dt);
|
||||
RadiatorTemperature += pumpedHeat / Evaluate(_thermalMass) * dt;
|
||||
RadiatorTemperature += pumpedHeat / Evaluate(_data.ThermalMass) * dt;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
{
|
||||
Emissivity = Evaluate(_emissivity);
|
||||
Emissivity = Evaluate(_data.Emissivity);
|
||||
var rad = pow(RadiatorTemperature, ItemManager.GameplaySettings.HeatRadiationExponent) * ItemManager.GameplaySettings.HeatRadiationMultiplier * Emissivity;
|
||||
RadiatorTemperature -= rad * delta;
|
||||
Entity.VisibilitySources[this] = rad;
|
||||
|
|
@ -89,18 +98,4 @@ public class Radiator : Behavior, IAlwaysUpdatedBehavior, IInitializableBehavior
|
|||
{
|
||||
RadiatorTemperature = Temperature;
|
||||
}
|
||||
|
||||
public void RestoreRuntimeState(
|
||||
float radiatorTemperature,
|
||||
float emissivity,
|
||||
float pumpedHeat,
|
||||
float wasteHeat,
|
||||
float energyUsage)
|
||||
{
|
||||
RadiatorTemperature = radiatorTemperature;
|
||||
Emissivity = emissivity;
|
||||
PumpedHeat = pumpedHeat;
|
||||
WasteHeat = wasteHeat;
|
||||
EnergyUsage = energyUsage;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue