Etterna 0.74.4
Loading...
Searching...
No Matches
RageTypes.h
1/* RageTypes - vector and matrix types. */
2
3#ifndef RAGETYPES_H
4#define RAGETYPES_H
5
6#include "Etterna/Models/Misc/EnumHelper.h"
7
8enum BlendMode
9{
10 BLEND_NORMAL,
11 BLEND_ADD,
12 BLEND_SUBTRACT,
13 BLEND_MODULATE,
14 BLEND_COPY_SRC,
15 BLEND_ALPHA_MASK,
16 BLEND_ALPHA_KNOCK_OUT,
17 BLEND_ALPHA_MULTIPLY,
18 BLEND_WEIGHTED_MULTIPLY,
19 BLEND_INVERT_DEST,
20 BLEND_NO_EFFECT,
21 NUM_BlendMode,
22 BlendMode_Invalid
23};
24LuaDeclareType(BlendMode);
25
26enum TextureMode
27{
28 // Affects one texture stage. Texture is modulated with the diffuse color.
29 TextureMode_Modulate,
30
31 /* Affects one texture stage. Color is replaced with white, leaving alpha.
32 * Used with BLEND_ADD to add glow. */
33 TextureMode_Glow,
34
35 // Affects one texture stage. Color is added to the previous texture stage.
36 TextureMode_Add,
37
38 NUM_TextureMode,
39 TextureMode_Invalid
40};
41LuaDeclareType(TextureMode);
42
43enum EffectMode
44{
45 EffectMode_Normal,
46 EffectMode_Unpremultiply,
47 EffectMode_ColorBurn,
48 EffectMode_ColorDodge,
49 EffectMode_VividLight,
50 EffectMode_HardMix,
51 EffectMode_Overlay,
52 EffectMode_Screen,
53 EffectMode_YUYV422,
54 NUM_EffectMode,
55 EffectMode_Invalid
56};
57LuaDeclareType(EffectMode);
58
59enum CullMode
60{
61 CULL_BACK,
62 CULL_FRONT,
63 CULL_NONE,
64 NUM_CullMode,
65 CullMode_Invalid
66};
67LuaDeclareType(CullMode);
68
69enum ZTestMode
70{
71 ZTEST_OFF,
72 ZTEST_WRITE_ON_PASS,
73 ZTEST_WRITE_ON_FAIL,
74 NUM_ZTestMode,
75 ZTestMode_Invalid
76};
77LuaDeclareType(ZTestMode);
78
79enum PolygonMode
80{
81 POLYGON_FILL,
82 POLYGON_LINE,
83 NUM_PolygonMode,
84 PolygonMode_Invalid
85};
86LuaDeclareType(PolygonMode);
87
88enum TextGlowMode
89{
90 TextGlowMode_Inner,
91 TextGlowMode_Stroke,
92 TextGlowMode_Both,
93 NUM_TextGlowMode,
94 TextGlowMode_Invalid
95};
96LuaDeclareType(TextGlowMode);
97
98struct lua_State;
99
101{
102 public:
103 RageVector2() = default;
104 RageVector2(const float* f)
105 : x(f[0])
106 , y(f[1])
107 {
108 }
109 RageVector2(float x1, float y1)
110 : x(x1)
111 , y(y1)
112 {
113 }
114
115 // casting
116 operator float*() { return &x; };
117 operator const float*() const { return &x; };
118
119 // assignment operators
120 auto operator+=(const RageVector2& other) -> RageVector2&
121 {
122 x += other.x;
123 y += other.y;
124 return *this;
125 }
126 auto operator-=(const RageVector2& other) -> RageVector2&
127 {
128 x -= other.x;
129 y -= other.y;
130 return *this;
131 }
132 auto operator*=(float f) -> RageVector2&
133 {
134 x *= f;
135 y *= f;
136 return *this;
137 }
138 auto operator/=(float f) -> RageVector2&
139 {
140 x /= f;
141 y /= f;
142 return *this;
143 }
144
145 // binary operators
146 auto operator+(const RageVector2& other) const -> RageVector2
147 {
148 return RageVector2(x + other.x, y + other.y);
149 }
150 auto operator-(const RageVector2& other) const -> RageVector2
151 {
152 return RageVector2(x - other.x, y - other.y);
153 }
154 auto operator*(float f) const -> RageVector2
155 {
156 return RageVector2(x * f, y * f);
157 }
158 auto operator/(float f) const -> RageVector2
159 {
160 return RageVector2(x / f, y / f);
161 }
162
163 friend auto operator*(float f, const RageVector2& other) -> RageVector2
164 {
165 return other * f;
166 }
167
168 float x{ 0 }, y{ 0 };
169};
170
172{
173 public:
174 RageVector3() = default;
175 RageVector3(const float* f)
176 : x(f[0])
177 , y(f[1])
178 , z(f[2])
179 {
180 }
181 RageVector3(float x1, float y1, float z1)
182 : x(x1)
183 , y(y1)
184 , z(z1)
185 {
186 }
187
188 // casting
189 operator float*() { return &x; };
190 operator const float*() const { return &x; };
191
192 // assignment operators
193 auto operator+=(const RageVector3& other) -> RageVector3&
194 {
195 x += other.x;
196 y += other.y;
197 z += other.z;
198 return *this;
199 }
200 auto operator-=(const RageVector3& other) -> RageVector3&
201 {
202 x -= other.x;
203 y -= other.y;
204 z -= other.z;
205 return *this;
206 }
207 auto operator*=(float f) -> RageVector3&
208 {
209 x *= f;
210 y *= f;
211 z *= f;
212 return *this;
213 }
214 auto operator/=(float f) -> RageVector3&
215 {
216 x /= f;
217 y /= f;
218 z /= f;
219 return *this;
220 }
221
222 // binary operators
223 auto operator+(const RageVector3& other) const -> RageVector3
224 {
225 return RageVector3(x + other.x, y + other.y, z + other.z);
226 }
227 auto operator-(const RageVector3& other) const -> RageVector3
228 {
229 return RageVector3(x - other.x, y - other.y, z - other.z);
230 }
231 auto operator*(float f) const -> RageVector3
232 {
233 return RageVector3(x * f, y * f, z * f);
234 }
235 auto operator/(float f) const -> RageVector3
236 {
237 return RageVector3(x / f, y / f, z / f);
238 }
239
240 friend auto operator*(float f, const RageVector3& other) -> RageVector3
241 {
242 return other * f;
243 }
244
245 float x{ 0 }, y{ 0 }, z{ 0 };
246};
247
249{
250 public:
251 RageVector4() = default;
252 RageVector4(const float* f)
253 : x(f[0])
254 , y(f[1])
255 , z(f[2])
256 , w(f[3])
257 {
258 }
259 RageVector4(float x1, float y1, float z1, float w1)
260 : x(x1)
261 , y(y1)
262 , z(z1)
263 , w(w1)
264 {
265 }
266
267 // casting
268 operator float*() { return &x; };
269 operator const float*() const { return &x; };
270
271 // assignment operators
272 auto operator+=(const RageVector4& other) -> RageVector4&
273 {
274 x += other.x;
275 y += other.y;
276 z += other.z;
277 w += other.w;
278 return *this;
279 }
280 auto operator-=(const RageVector4& other) -> RageVector4&
281 {
282 x -= other.x;
283 y -= other.y;
284 z -= other.z;
285 w -= other.w;
286 return *this;
287 }
288 auto operator*=(float f) -> RageVector4&
289 {
290 x *= f;
291 y *= f;
292 z *= f;
293 w *= f;
294 return *this;
295 }
296 auto operator/=(float f) -> RageVector4&
297 {
298 x /= f;
299 y /= f;
300 z /= f;
301 w /= f;
302 return *this;
303 }
304
305 // binary operators
306 auto operator+(const RageVector4& other) const -> RageVector4
307 {
308 return RageVector4(x + other.x, y + other.y, z + other.z, w + other.w);
309 }
310 auto operator-(const RageVector4& other) const -> RageVector4
311 {
312 return RageVector4(x - other.x, y - other.y, z - other.z, w - other.w);
313 }
314 auto operator*(float f) const -> RageVector4
315 {
316 return RageVector4(x * f, y * f, z * f, w * f);
317 }
318 auto operator/(float f) const -> RageVector4
319 {
320 return RageVector4(x / f, y / f, z / f, w / f);
321 }
322
323 friend auto operator*(float f, const RageVector4& other) -> RageVector4
324 {
325 return other * f;
326 }
327
328 float x{ 0 }, y{ 0 }, z{ 0 }, w{ 0 };
329};
330
332{
333 public:
334 RageColor() = default;
335 explicit RageColor(const float* f)
336 : r(f[0])
337 , g(f[1])
338 , b(f[2])
339 , a(f[3])
340 {
341 }
342 RageColor(float r1, float g1, float b1, float a1)
343 : r(r1)
344 , g(g1)
345 , b(b1)
346 , a(a1)
347 {
348 }
349
350 // Input should be in range 0-360
351 static RageColor FromHue(float hue);
352
353 static RageColor Lerp(RageColor const& a, RageColor const& b, float t);
354
355 // casting
356 operator float*() { return &r; };
357 operator const float*() const { return &r; };
358
359 // assignment operators
360 auto operator+=(const RageColor& other) -> RageColor&
361 {
362 r += other.r;
363 g += other.g;
364 b += other.b;
365 a += other.a;
366 return *this;
367 }
368 auto operator-=(const RageColor& other) -> RageColor&
369 {
370 r -= other.r;
371 g -= other.g;
372 b -= other.b;
373 a -= other.a;
374 return *this;
375 }
376 auto operator*=(const RageColor& other) -> RageColor&
377 {
378 r *= other.r;
379 g *= other.g;
380 b *= other.b;
381 a *= other.a;
382 return *this;
383 }
384 auto operator*=(float f) -> RageColor&
385 {
386 r *= f;
387 g *= f;
388 b *= f;
389 a *= f;
390 return *this;
391 }
392 /* Divide is rarely useful: you can always use multiplication, and you don't
393 * have to worry about div/0. */
394 // RageColor& operator /= ( float f ) { r/=f; g/=f; b/=f; a/=f;
395 // return *this; }
396
397 // binary operators
398 auto operator+(const RageColor& other) const -> RageColor
399 {
400 return RageColor(r + other.r, g + other.g, b + other.b, a + other.a);
401 }
402 auto operator-(const RageColor& other) const -> RageColor
403 {
404 return RageColor(r - other.r, g - other.g, b - other.b, a - other.a);
405 }
406 auto operator*(const RageColor& other) const -> RageColor
407 {
408 return RageColor(r * other.r, g * other.g, b * other.b, a * other.a);
409 }
410 auto operator*(float f) const -> RageColor
411 {
412 return RageColor(r * f, g * f, b * f, a * f);
413 }
414 // Divide is useful for using with the SCALE macro
415 auto operator/(float f) const -> RageColor
416 {
417 return RageColor(r / f, g / f, b / f, a / f);
418 }
419
420 friend auto operator*(float f, const RageColor& other) -> RageColor
421 {
422 return other * f;
423 } // What is this for? Did I add this? -Chris
424
425 auto operator==(const RageColor& other) const -> bool
426 {
427 return r == other.r && g == other.g && b == other.b && a == other.a;
428 }
429 auto operator!=(const RageColor& other) const -> bool
430 {
431 return !operator==(other);
432 }
433
434 auto FromString(const std::string& str) -> bool
435 {
436 int result = sscanf(str.c_str(), "%f,%f,%f,%f", &r, &g, &b, &a);
437 if (result == 3) {
438 a = 1;
439 return true;
440 }
441 if (result == 4) {
442 return true;
443 }
444
445 int ir = 255;
446 int ib = 255;
447 int ig = 255;
448 int ia = 255;
449 result = sscanf(str.c_str(), "#%2x%2x%2x%2x", &ir, &ig, &ib, &ia);
450 if (result >= 3) {
451 r = ir / 255.0F;
452 g = ig / 255.0F;
453 b = ib / 255.0F;
454 if (result == 4) {
455 a = ia / 255.0F;
456 } else {
457 a = 1;
458 }
459 return true;
460 }
461
462 r = 1;
463 b = 1;
464 g = 1;
465 a = 1;
466 return false;
467 }
468
469 [[nodiscard]] auto ToString() const -> std::string;
470 static auto NormalizeColorString(const std::string& sColor) -> std::string;
471
472 void PushTable(lua_State* L) const;
473 void FromStack(lua_State* L, int iPos);
474 void FromStackCompat(lua_State* L, int iPos);
475
476 float r{ 0 }, g{ 0 }, b{ 0 }, a{ 0 };
477};
478
479static auto
480FTOC(float a) -> unsigned char
481{
482 auto ret = static_cast<int>(a * 256.F);
483 CLAMP(ret, 0, 255);
484 return static_cast<unsigned char>(ret);
485}
486
487/* Color type used only in vertex lists. OpenGL expects colors in
488 * r, g, b, a order, independent of endianness, so storing them this
489 * way avoids endianness problems. Don't try to manipulate this; only
490 * manip RageColors. */
492{
493 public:
494 uint8_t b{ 0 }, g{ 0 }, r{ 0 },
495 a{ 0 }; // specific ordering required by Direct3D
496 RageVColor() = default;
497 RageVColor(const RageColor& rc)
498 {
499 r = FTOC(rc.r);
500 g = FTOC(rc.g);
501 b = FTOC(rc.b);
502 a = FTOC(rc.a);
503 }
504};
505
506namespace StepMania {
507template<class T>
508class Rect
509{
510 public:
511 Rect()
512 : left(0)
513 , top(0)
514 , right(0)
515 , bottom(0)
516 {
517 }
518 Rect(T l, T t, T r, T b)
519 : left(l)
520 , top(t)
521 , right(r)
522 , bottom(b)
523 {
524 }
525
526 [[nodiscard]] auto GetWidth() const -> T { return right - left; };
527 [[nodiscard]] auto GetHeight() const -> T { return bottom - top; };
528 [[nodiscard]] auto GetCenterX() const -> T { return (left + right) / 2; };
529 [[nodiscard]] auto GetCenterY() const -> T { return (top + bottom) / 2; };
530
531 auto operator==(const Rect& other) const -> bool
532 {
533#define COMPARE(x) \
534 if ((x) != other.x) \
535 return false
536 COMPARE(left);
537 COMPARE(top);
538 COMPARE(right);
539 COMPARE(bottom);
540#undef COMPARE
541 return true;
542 }
543 auto operator!=(const Rect& other) const -> bool
544 {
545 return !operator==(other);
546 }
547
548 T left, top, right, bottom;
549};
550} // namespace StepMania
553
554/* Structure for our custom vertex type. Note that these data structes
555 * have the same layout that D3D expects. */
556struct RageSpriteVertex // has color
557{
558 RageVector3 p; // position
559 RageVector3 n; // normal
560 RageVColor c; // diffuse color
561 RageVector2 t; // texture coordinates
562};
563
564void
565lerp_rage_color(RageColor& out,
566 RageColor const& a,
567 RageColor const& b,
568 float t);
569void
570WeightedAvergeOfRSVs(RageSpriteVertex& average_out,
571 RageSpriteVertex const& rsv1,
572 RageSpriteVertex const& rsv2,
573 float percent_between);
574
575struct RageModelVertex // doesn't have color. Relies on material color
576{
577 /* Zero out by default. */
579 : p(0, 0, 0)
580 , n(0, 0, 0)
581 , t(0, 0)
582 , TextureMatrixScale(1, 1)
583 {
584 }
585 RageVector3 p; // position
586 RageVector3 n; // normal
587 RageVector2 t; // texture coordinates
588 int8_t bone{ 0 };
589 RageVector2 TextureMatrixScale; // usually 1,1
590};
591
592// RageMatrix elements are specified in row-major order. This
593// means that the translate terms are located in the fourth row and the
594// projection terms in the fourth column. This is consistent with the way
595// MAX, Direct3D, and OpenGL all handle matrices. Even though the OpenGL
596// documentation is in column-major form, the OpenGL code is designed to
597// handle matrix operations in row-major form.
599{
600 public:
601 RageMatrix() = default;
602 RageMatrix(const float* f)
603 {
604 for (int i = 0; i < 4; i++) {
605 for (int j = 0; j < 4; j++) {
606 m[j][i] = f[j * 4 + i];
607 }
608 }
609 }
610 RageMatrix(const RageMatrix& other)
611 {
612 for (int i = 0; i < 4; i++) {
613 for (int j = 0; j < 4; j++) {
614 m[j][i] = other.m[j][i];
615 }
616 }
617 }
618 RageMatrix(float v00,
619 float v01,
620 float v02,
621 float v03,
622 float v10,
623 float v11,
624 float v12,
625 float v13,
626 float v20,
627 float v21,
628 float v22,
629 float v23,
630 float v30,
631 float v31,
632 float v32,
633 float v33);
634
635 // access grants
636 auto operator()(int iRow, int iCol) -> float& { return m[iCol][iRow]; }
637 auto operator()(int iRow, int iCol) const -> float { return m[iCol][iRow]; }
638
639 // casting operators
640 operator float*() { return m[0]; }
641 operator const float*() const { return m[0]; }
642
643 [[nodiscard]] auto GetTranspose() const -> RageMatrix;
644
645 float m[4][4]{};
646};
647
648#endif
Definition RageTypes.h:492
Definition RageTypes.h:509
Utility functions for controlling the whole game.
Definition StepMania.h:11
Definition RageTypes.h:332
Definition RageTypes.h:599
Definition RageTypes.h:576
Definition RageTypes.h:557
Definition RageTypes.h:101
Definition RageTypes.h:172
Definition RageTypes.h:249