NoSloppy

Untitled

Oct 3rd, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.07 KB | None | 0 0
  1. #ifndef STYLES_LOCKUP_H
  2. #define STYLES_LOCKUP_H
  3.  
  4. #include "../functions/smoothstep.h"
  5. #include "../functions/islessthan.h"
  6. #include "../functions/layer_functions.h"
  7. #include "../functions/scale.h"
  8. #include "../functions/brown_noise.h"
  9.  
  10.  
  11. HandledFeature FeatureForLockupType(SaberBase::LockupType t) {
  12. switch (t) {
  13. default:
  14. return HANDLED_FEATURE_NONE;
  15. case SaberBase::LOCKUP_DRAG:
  16. return HANDLED_FEATURE_DRAG;
  17. case SaberBase::LOCKUP_LIGHTNING_BLOCK:
  18. return HANDLED_FEATURE_LIGHTNING_BLOCK;
  19. case SaberBase::LOCKUP_MELT:
  20. return HANDLED_FEATURE_MELT;
  21. }
  22. }
  23.  
  24. // Usage: Lockup<BASE, LOCKUP, DRAG_COLOR, LOCKUP_SHAPE, DRAG_SHAPE>
  25. // Or: LockupL<LOCKUP, DRAG_COLOR, LOCKUP_SHAPE, DRAG_SHAPE, LB_SHAPE>
  26. // BASE, LOCKUP: COLOR
  27. // DRAG_COLOR: COLOR (defaults to the LOCKUP color)
  28. // LOCKUP_SHAPE: FUNCTION (defaults to Int<32768>)
  29. // DRAG_SHAPE: FUNCTION (defaults to SmoothStep<Int<28671>, Int<4096>>)
  30. // LB_SHAPE: FUNCTION (defaults to a suitable function)
  31. // return value: COLOR
  32. // Shows LOCKUP if the lockup state is true, otherwise BASE.
  33. // Also handles Drag, Melt and Lightning Block lockup types unless those
  34. // are handled elsewhere in the same style.
  35. template< // BC Use LockupL for chambers and accent stuff. Full blade shape
  36. class LOCKUP, class DRAG_COLOR = LOCKUP,
  37. class LOCKUP_SHAPE = Int<32768>,// *ALT ANIMATED LOCKUP //Bump<Sin<Int<27>,Int<14000>,Int<18000>>,Int<14000>>,
  38. class DRAG_SHAPE = Int<32768>,//SmoothStep<Int<28671>, Int<4096>>,
  39. class LB_SHAPE = Int<32768>>
  40. // LayerFunctions<Bump<Scale<SlowNoise<Int<2000>>,Int<3000>,Int<16000>>,
  41. // Scale<BrownNoiseF<Int<10>>,Int<14000>,Int<8000>>>,
  42. // Bump<Scale<SlowNoise<Int<2300>>,Int<26000>,Int<8000>>,
  43. // Scale<NoisySoundLevel,Int<5000>,Int<10000>>>,
  44. // Bump<Scale<SlowNoise<Int<2300>>,Int<20000>,Int<30000>>,
  45. // Scale<IsLessThan<SlowNoise<Int<1500>>,Int<8000>>,Scale<NoisySoundLevel,Int<5000>,Int<0>>,Int<0>>>> >
  46. class LockupL {
  47. public:
  48. void run(BladeBase* blade) {
  49. single_pixel_ = blade->num_leds() == 1;
  50. lockup_.run(blade);
  51. if (!is_same_type<DRAG_COLOR, LOCKUP>::value)
  52. drag_.run(blade);
  53. lockup_shape_.run(blade);
  54. drag_shape_.run(blade);
  55. lb_shape_.run(blade);
  56. handled_ = blade->current_style()->IsHandled(FeatureForLockupType(SaberBase::Lockup()));
  57. }
  58. private:
  59. bool handled_;
  60. bool single_pixel_;
  61. LOCKUP lockup_;
  62. DRAG_COLOR drag_;
  63. LOCKUP_SHAPE lockup_shape_;
  64. DRAG_SHAPE drag_shape_;
  65. LB_SHAPE lb_shape_;
  66. public:
  67. auto getColor(int led) -> decltype(lockup_.getColor(led) * 1) {
  68. // transparent
  69. int blend = 0;
  70. if (handled_) return RGBA_um_nod::Transparent();
  71. switch (SaberBase::Lockup()) {
  72. case SaberBase::LOCKUP_MELT:
  73. // TODO: Better default for MELT?
  74. case SaberBase::LOCKUP_DRAG: {
  75. blend = single_pixel_ ? 32768 : drag_shape_.getInteger(led);
  76. if (!is_same_type<DRAG_COLOR, LOCKUP>::value) {
  77. return drag_.getColor(led) * blend;
  78. }
  79. break;
  80. }
  81. case SaberBase::LOCKUP_LIGHTNING_BLOCK:
  82. blend = lb_shape_.getInteger(led);
  83. break;
  84. case SaberBase::LOCKUP_NORMAL:
  85. case SaberBase::LOCKUP_ARMED:
  86. case SaberBase::LOCKUP_AUTOFIRE:
  87. blend = lockup_shape_.getInteger(led);
  88. break;
  89. case SaberBase::LOCKUP_NONE:
  90. return RGBA_um_nod::Transparent();
  91. }
  92. return lockup_.getColor(led) * blend;
  93. }
  94. };
  95.  
  96. template<class BASE,
  97. class LOCKUP, class DRAG_COLOR = LOCKUP,
  98. class LOCKUP_SHAPE = Int<32768>, class DRAG_SHAPE = SmoothStep<Int<28671>, Int<4096>> >
  99. using Lockup = Layers<BASE, LockupL<LOCKUP, DRAG_COLOR, LOCKUP_SHAPE, DRAG_SHAPE>>;
  100.  
  101.  
  102. // Usage: LockupTr<BASE, COLOR, BeginTr, EndTr, LOCKUP_TYPE>
  103. // Or: LockupTrL<COLOR, BeginTr, EndTr, LOCKUP_TYPE>
  104. // COLOR; COLOR or LAYER
  105. // BeginTr, EndTr: TRANSITION
  106. // LOCKUP_TYPE: a SaberBase::LockupType
  107. // Return type: LAYER
  108. // This layer creates a complete lockup effect.
  109. // When lockup is initiated, BeginTr is used to transition from transparent
  110. // to COLOR. When lockup ends, EndTr is used to transition from COLOR to
  111. // transparent again. If you wish to for your lockup to have a shape, you
  112. // can have COLOR be partially transparent to make the base layer show through.
  113. template<class COLOR,
  114. class BeginTr,
  115. class EndTr,
  116. SaberBase::LockupType LOCKUP_TYPE>
  117. class LockupTrL {
  118. public:
  119. LockupTrL() {
  120. BladeBase::HandleFeature(FeatureForLockupType(LOCKUP_TYPE));
  121. }
  122. void run(BladeBase* blade) {
  123. color_.run(blade);
  124. if (active_ != (SaberBase::Lockup() == LOCKUP_TYPE)) {
  125. if ((active_ = (SaberBase::Lockup() == LOCKUP_TYPE))) {
  126. begin_tr_.begin();
  127. begin_active_ = true;
  128. } else {
  129. end_tr_.begin();
  130. end_active_ = true;
  131. }
  132. }
  133.  
  134. if (begin_active_) {
  135. begin_tr_.run(blade);
  136. if (begin_tr_.done()) begin_active_ = false;
  137. }
  138. if (end_active_) {
  139. end_tr_.run(blade);
  140. if (end_tr_.done()) end_active_ = false;
  141. }
  142. }
  143.  
  144. RGBA runBegin(RGBA a, RGBA b, int led) {
  145. if (begin_active_) {
  146. return begin_tr_.getColor(a, b, led);
  147. } else {
  148. return b;
  149. }
  150. }
  151. RGBA runEnd(RGBA a, RGBA b, int led) {
  152. if (end_active_) {
  153. return end_tr_.getColor(a, b, led);
  154. } else {
  155. return b;
  156. }
  157. }
  158. RGBA getColor(int led) {
  159. SCOPED_PROFILER();
  160. RGBA off_color = RGBA_um_nod::Transparent();
  161. if (!begin_active_ && !end_active_) {
  162. if (active_) {
  163. return color_.getColor(led);
  164. } else {
  165. return off_color;
  166. }
  167. } else {
  168. RGBA on_color = color_.getColor(led);
  169. if (active_) {
  170. return runBegin(runEnd(on_color, off_color, led), on_color, led);
  171. } else {
  172. return runEnd(runBegin(off_color, on_color, led), off_color, led);
  173. }
  174. }
  175. }
  176. private:
  177. bool active_;
  178. COLOR color_;
  179. bool begin_active_;
  180. bool end_active_;
  181. BeginTr begin_tr_;
  182. EndTr end_tr_;
  183. };
  184.  
  185. template<
  186. class BASE,
  187. class COLOR,
  188. class BeginTr,
  189. class EndTr,
  190. SaberBase::LockupType LOCKUP_TYPE>
  191. using LockupTr = Layers<BASE, LockupTrL<COLOR, BeginTr, EndTr, LOCKUP_TYPE>>;
  192.  
  193.  
  194. #endif
  195.  
Advertisement
Add Comment
Please, Sign In to add comment