temperaturedata.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. class TemperatureData
  2. {
  3. ETemperatureAccessTypes m_AccessType;
  4. bool m_UseGlobalCooling;
  5. float m_Value; //target or increment, depends on context!
  6. float m_AdjustedTarget; //actual target of the operation (can be adjusted via over-time interpolation, not necessarily the original target value!)
  7. float m_UpdateTimeInfo; //if the temperature change was accumulated over some time, pass this info to temperature subsystems
  8. float m_UpdateTimeCoef; //multiplies the time
  9. float m_HeatPermeabilityCoef; //permeability multiplier (modifies change speed).
  10. float m_InterpolatedStepSize; //only useful for interpolated temperature values
  11. float m_InterpolatedFraction; //only useful for interpolated temperature values
  12. void TemperatureData(float val, ETemperatureAccessTypes accessType = ETemperatureAccessTypes.ACCESS_UNKNOWN, float time = -1, float timeCoef = 1, float heatPermCoef = 1)
  13. {
  14. m_Value = val;
  15. m_AdjustedTarget = val;
  16. m_AccessType = accessType;
  17. m_UpdateTimeInfo = time;
  18. m_UpdateTimeCoef = timeCoef;
  19. m_HeatPermeabilityCoef = heatPermCoef;
  20. Init();
  21. }
  22. protected void Init()
  23. {
  24. m_UseGlobalCooling = true;
  25. m_InterpolatedFraction = 0.0;
  26. }
  27. }
  28. class TemperatureDataInterpolated : TemperatureData
  29. {
  30. void InterpolateTemperatureDelta(float start)
  31. {
  32. m_InterpolatedStepSize = -1;
  33. float target = m_Value;
  34. m_AdjustedTarget = start;
  35. if (start != target)
  36. {
  37. float diffAbs = Math.Max(start,target) - Math.Min(start,target);
  38. m_InterpolatedFraction = Math.Clamp(Math.InverseLerp(GameConstants.TEMPERATURE_INTERPOLATION_THRESHOLD_MIN_ABS,GameConstants.TEMPERATURE_INTERPOLATION_THRESHOLD_MAX_ABS,diffAbs),0,1);
  39. m_InterpolatedStepSize = Math.Lerp(GameConstants.TEMPERATURE_RATE_AVERAGE_ABS,GameConstants.TEMPERATURE_RATE_MAX_ABS,m_InterpolatedFraction);
  40. float coef = m_UpdateTimeCoef;
  41. float absBaseTempChange = m_UpdateTimeInfo * m_InterpolatedStepSize;
  42. if (start > target)
  43. {
  44. absBaseTempChange *= -1;
  45. if (m_UseGlobalCooling)
  46. coef = GameConstants.TEMP_COEF_COOLING_GLOBAL;
  47. }
  48. coef *= m_HeatPermeabilityCoef;
  49. absBaseTempChange *= coef;
  50. m_AdjustedTarget = start + Math.Clamp(absBaseTempChange,-diffAbs,diffAbs);
  51. }
  52. }
  53. }