dimmingconfig.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. class DimmingConfig
  2. {
  3. //randomization
  4. float m_DimBrigthnessMin = 0.1;
  5. float m_DimBrigthnessMax = 1;
  6. float m_DimSpeedMin = 0.1;
  7. float m_DimSpeedMax = 1;
  8. float m_DimBrigthnessDurationMin = 0.1;
  9. float m_DimBrigthnessDurationMax = 1;
  10. float m_BrightenSpeedMin = 0.1;
  11. float m_BrightenSpeedMax = 1;
  12. float m_DimBrigthnessPauseMin = 1;
  13. float m_DimBrigthnessPauseMax = 4;
  14. // patterns
  15. bool m_UsePatterns;
  16. int m_PatternRepeatCount = -1; // -1 = infinite
  17. int m_CurrentPatternID;
  18. int m_PatternCount;
  19. int m_CurrentEntryID;
  20. ref array<ref array<int>> m_BrightnessPatterns = new array<ref array<int>>();
  21. ref array<ref array<float>> m_DimSpeedPatterns = new array<ref array<float>>();
  22. ref array<ref array<float>> m_DurationPatterns = new array<ref array<float>>();
  23. ref array<ref array<float>> m_BrightenSpeedPatterns = new array<ref array<float>>();
  24. ref array<ref array<float>> m_PausePatterns = new array<ref array<float>>();
  25. // Percentage of base brightness, how strong can the dim be
  26. void SetRandomBrigthnessLimits(float min, float max)
  27. {
  28. min = Math.Clamp(min, 0, 100);
  29. max = Math.Clamp(max, 0, 100);
  30. m_DimBrigthnessMin = min * 0.01;
  31. m_DimBrigthnessMax = max * 0.01;
  32. }
  33. // Speed limits of of random dimming
  34. void SetRandomDimSpeedLimits(float min, float max)
  35. {
  36. min = Math.Clamp(min, 0.01, 10);
  37. max = Math.Clamp(max, 0.01, 10);
  38. m_DimSpeedMin = min;
  39. m_DimSpeedMax = max;
  40. }
  41. // Duration of paused dimmed state
  42. void SetRandomDurationLimits(float min, float max)
  43. {
  44. min = Math.Clamp(min, 0.01, 100);
  45. max = Math.Clamp(max, 0.01, 100);
  46. m_DimBrigthnessDurationMin = min;
  47. m_DimBrigthnessDurationMax = max;
  48. }
  49. // Speed limits of of random brightening
  50. void SetRandomBrightenSpeedLimits(float min, float max)
  51. {
  52. min = Math.Clamp(min, 0.01, 10);
  53. max = Math.Clamp(max, 0.01, 10);
  54. m_BrightenSpeedMin = min;
  55. m_BrightenSpeedMax = max;
  56. }
  57. // Duration of paused state without dimming in seconds
  58. void SetRandomPauseDurationLimits(float min, float max)
  59. {
  60. min = Math.Clamp(min, 0.01, 100);
  61. max = Math.Clamp(max, 0.01, 100);
  62. m_DimBrigthnessPauseMin = min;
  63. m_DimBrigthnessPauseMax = max;
  64. }
  65. // Adding a pattern will disable randomized dimming
  66. void AddDimmingPattern(array<int> brightnessTarget, array<float> dimSpeed, array<float> dimDuration, array<float> brightenSpeed, array<float> pause)
  67. {
  68. int count = brightnessTarget.Count();
  69. if ( count != dimSpeed.Count() || count != dimDuration.Count() || count != brightenSpeed.Count() || count != pause.Count())
  70. {
  71. ErrorEx(this.ToString() + ": Invalid dimming pattern");
  72. return;
  73. }
  74. m_UsePatterns = true;
  75. m_BrightnessPatterns.Insert(brightnessTarget);
  76. m_DimSpeedPatterns.Insert(dimSpeed);
  77. m_DurationPatterns.Insert(dimDuration);
  78. m_BrightenSpeedPatterns.Insert(brightenSpeed);
  79. m_PausePatterns.Insert(pause);
  80. m_PatternCount++;
  81. }
  82. // Set how many times should the patterns repeat before stopping, default -1 = infinite repeat
  83. void SetPatternQueueRepeat(int val)
  84. {
  85. m_PatternRepeatCount = val;
  86. }
  87. }