From 28770c1580fafdb4d54fa3bc46354a6061cfa221 Mon Sep 17 00:00:00 2001 From: Nick Renieris Date: Mon, 6 Jan 2020 19:56:17 +0200 Subject: [PATCH] overlays: Move vertex & vector utility classes to new file --- rpcs3/Emu/RSX/Overlays/overlay_animation.h | 59 +------- rpcs3/Emu/RSX/Overlays/overlay_controls.h | 73 +--------- rpcs3/Emu/RSX/Overlays/overlay_utils.h | 148 +++++++++++++++++++++ rpcs3/emucore.vcxproj | 3 +- rpcs3/emucore.vcxproj.filters | 5 +- 5 files changed, 156 insertions(+), 132 deletions(-) create mode 100644 rpcs3/Emu/RSX/Overlays/overlay_utils.h diff --git a/rpcs3/Emu/RSX/Overlays/overlay_animation.h b/rpcs3/Emu/RSX/Overlays/overlay_animation.h index f411a499f..5170fb5e8 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_animation.h +++ b/rpcs3/Emu/RSX/Overlays/overlay_animation.h @@ -1,67 +1,10 @@ #pragma once #include "Utilities/types.h" #include "Utilities/geometry.h" +#include "overlay_utils.h" namespace rsx { - template - struct vector3_base : public position3_base - { - using position3_base::position3_base; - - vector3_base(T x, T y, T z) - { - this->x = x; - this->y = y; - this->z = z; - } - - vector3_base(const position3_base& other) - { - this->x = other.x; - this->y = other.y; - this->z = other.z; - } - - vector3_base operator * (const vector3_base& rhs) const - { - return { this->x * rhs.x, this->y * rhs.y, this->z * rhs.z }; - } - - vector3_base operator * (T rhs) const - { - return { this->x * rhs, this->y * rhs, this->z * rhs }; - } - - void operator *= (const vector3_base& rhs) - { - this->x *= rhs.x; - this->y *= rhs.y; - this->z *= rhs.z; - } - - void operator *= (T rhs) - { - this->x *= rhs; - this->y *= rhs; - this->z *= rhs; - } - - T dot(const vector3_base& rhs) const - { - return (this->x * rhs.x) + (this->y * rhs.y) + (this->z * rhs.z); - } - - T distance(const vector3_base& rhs) const - { - const vector3_base d = *this - rhs; - return d.dot(d); - } - }; - - using vector3i = vector3_base; - using vector3f = vector3_base; - namespace overlays { struct compiled_resource; diff --git a/rpcs3/Emu/RSX/Overlays/overlay_controls.h b/rpcs3/Emu/RSX/Overlays/overlay_controls.h index d1eb4d1ae..815ad3853 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_controls.h +++ b/rpcs3/Emu/RSX/Overlays/overlay_controls.h @@ -2,6 +2,7 @@ #include "Utilities/types.h" #include "Utilities/geometry.h" #include "Utilities/File.h" +#include "overlay_utils.h" #include "Emu/System.h" #include @@ -51,78 +52,6 @@ namespace rsx line_strip = 3 }; - struct vertex - { - float values[4]; - - vertex() = default; - - vertex(float x, float y) - { - vec2(x, y); - } - - vertex(float x, float y, float z) - { - vec3(x, y, z); - } - - vertex(float x, float y, float z, float w) - { - vec4(x, y, z, w); - } - - vertex(int x, int y, int z, int w) - { - vec4(static_cast(x), static_cast(y), static_cast(z), static_cast(w)); - } - - float& operator[](int index) - { - return values[index]; - } - - void vec2(float x, float y) - { - values[0] = x; - values[1] = y; - values[2] = 0.f; - values[3] = 1.f; - } - - void vec3(float x, float y, float z) - { - values[0] = x; - values[1] = y; - values[2] = z; - values[3] = 1.f; - } - - void vec4(float x, float y, float z, float w) - { - values[0] = x; - values[1] = y; - values[2] = z; - values[3] = w; - } - - void operator += (const vertex& other) - { - values[0] += other.values[0]; - values[1] += other.values[1]; - values[2] += other.values[2]; - values[3] += other.values[3]; - } - - void operator -= (const vertex& other) - { - values[0] -= other.values[0]; - values[1] -= other.values[1]; - values[2] -= other.values[2]; - values[3] -= other.values[3]; - } - }; - struct font { const u32 width = 1024; diff --git a/rpcs3/Emu/RSX/Overlays/overlay_utils.h b/rpcs3/Emu/RSX/Overlays/overlay_utils.h new file mode 100644 index 000000000..9a64eb012 --- /dev/null +++ b/rpcs3/Emu/RSX/Overlays/overlay_utils.h @@ -0,0 +1,148 @@ +#pragma once + +struct vertex +{ + float values[4]; + + vertex() = default; + + vertex(float x, float y) + { + vec2(x, y); + } + + vertex(float x, float y, float z) + { + vec3(x, y, z); + } + + vertex(float x, float y, float z, float w) + { + vec4(x, y, z, w); + } + + vertex(int x, int y, int z, int w) + { + vec4(static_cast(x), static_cast(y), static_cast(z), static_cast(w)); + } + + float& operator[](int index) + { + return values[index]; + } + + void vec2(float x, float y) + { + values[0] = x; + values[1] = y; + values[2] = 0.f; + values[3] = 1.f; + } + + void vec3(float x, float y, float z) + { + values[0] = x; + values[1] = y; + values[2] = z; + values[3] = 1.f; + } + + void vec4(float x, float y, float z, float w) + { + values[0] = x; + values[1] = y; + values[2] = z; + values[3] = w; + } + + void operator += (const vertex& other) + { + values[0] += other.values[0]; + values[1] += other.values[1]; + values[2] += other.values[2]; + values[3] += other.values[3]; + } + + void operator -= (const vertex& other) + { + values[0] -= other.values[0]; + values[1] -= other.values[1]; + values[2] -= other.values[2]; + values[3] -= other.values[3]; + } +}; + + +template +struct vector3_base : public position3_base +{ + using position3_base::position3_base; + + vector3_base(T x, T y, T z) + { + this->x = x; + this->y = y; + this->z = z; + } + + vector3_base(const position3_base& other) + { + this->x = other.x; + this->y = other.y; + this->z = other.z; + } + + T dot(const vector3_base& rhs) const + { + return (this->x * rhs.x) + (this->y * rhs.y) + (this->z * rhs.z); + } + + T distance(const vector3_base& rhs) const + { + const vector3_base d = *this - rhs; + return d.dot(d); + } +}; + +template +vector3_base operator * (const vector3_base& lhs, const vector3_base& rhs) +{ + return { lhs.x * rhs.x, lhs.y * rhs.y, lhs.z * rhs.z }; +} + +template +vector3_base operator * (const vector3_base& lhs, T rhs) +{ + return { lhs.x * rhs, lhs.y * rhs, lhs.z * rhs }; +} + +template +vector3_base operator * (T lhs, const vector3_base& rhs) +{ + return { lhs * rhs.x, lhs * rhs.y, lhs * rhs.z }; +} + +template +void operator *= (const vector3_base& lhs, const vector3_base& rhs) +{ + lhs.x *= rhs.x; + lhs.y *= rhs.y; + lhs.z *= rhs.z; +} + +template +void operator *= (const vector3_base& lhs, T rhs) +{ + lhs.x *= rhs; + lhs.y *= rhs; + lhs.z *= rhs; +} + +template +void operator < (const vector3_base& lhs, T rhs) +{ + return lhs.x < rhs.x && lhs.y < rhs.y && lhs.z < rhs.z; +} + +using vector3i = vector3_base; +using vector3f = vector3_base; diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index d8305315d..fdf596a7f 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -398,6 +398,7 @@ + @@ -657,4 +658,4 @@ - + \ No newline at end of file diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index 7bb610a82..3af181330 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -1606,5 +1606,8 @@ Emu\GPU\RSX\Overlays\Shaders + + Header Files + - + \ No newline at end of file