From d86469c2f51aa93760b70ad16dd872365f78ff72 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Fri, 9 Oct 2015 19:04:03 +0200 Subject: [PATCH] Add Utilities/types.h --- Utilities/types.h | 1099 +++++++++++++++++++++++++++++++++ rpcs3/Emu/RSX/RSXThread.cpp | 1 + rpcs3/emucore.vcxproj | 1 + rpcs3/emucore.vcxproj.filters | 3 + 4 files changed, 1104 insertions(+) create mode 100644 Utilities/types.h diff --git a/Utilities/types.h b/Utilities/types.h new file mode 100644 index 0000000000..d509e3ad76 --- /dev/null +++ b/Utilities/types.h @@ -0,0 +1,1099 @@ +#pragma once +#include +#include +#include +#include + +using uchar = unsigned char; +using ushort = unsigned short; +using uint = unsigned int; +using ulong = unsigned long; +using ullong = unsigned long long; + +using llong = long long; + +using u8 = uint8_t; +using u16 = uint16_t; +using u32 = uint32_t; +using u64 = uint64_t; + +using s8 = int8_t; +using s16 = int16_t; +using s32 = int32_t; +using s64 = int64_t; + +union alignas(2) f16 +{ + u16 _u16; + u8 _u8[2]; +}; + +using f32 = float; +using f64 = double; + +#include "BEType.h" + +template +class pi_t +{ +public: + static constexpr T value = T(3.141592653589793238462643383279502884197169399375105820974944592307816406286); +}; + +template +using pi = pi_t; + +struct ignore +{ + template + ignore(T) + { + } +}; + +template +struct size2_base +{ + T width, height; + + constexpr size2_base() : width{}, height{} + { + } + + constexpr size2_base(T width, T height) : width{ width }, height{ height } + { + } + + constexpr size2_base(const size2_base& rhs) : width{ rhs.width }, height{ rhs.height } + { + } + + constexpr size2_base operator -(const size2_base& rhs) const + { + return{ width - rhs.width, height - rhs.height }; + } + constexpr size2_base operator -(T rhs) const + { + return{ width - rhs, height - rhs }; + } + constexpr size2_base operator +(const size2_base& rhs) const + { + return{ width + rhs.width, height + rhs.height }; + } + constexpr size2_base operator +(T rhs) const + { + return{ width + rhs, height + rhs }; + } + constexpr size2_base operator /(const size2_base& rhs) const + { + return{ width / rhs.width, height / rhs.height }; + } + constexpr size2_base operator /(T rhs) const + { + return{ width / rhs, height / rhs }; + } + constexpr size2_base operator *(const size2_base& rhs) const + { + return{ width * rhs.width, height * rhs.height }; + } + constexpr size2_base operator *(T rhs) const + { + return{ width * rhs, height * rhs }; + } + + size2_base& operator -=(const size2_base& rhs) + { + width -= rhs.width; + height -= rhs.height; + return *this; + } + size2_base& operator -=(T rhs) + { + width -= rhs; + height -= rhs; + return *this; + } + size2_base& operator +=(const size2_base& rhs) + { + width += rhs.width; + height += rhs.height; + return *this; + } + size2_base& operator +=(T rhs) + { + width += rhs; + height += rhs; + return *this; + } + size2_base& operator /=(const size2_base& rhs) + { + width /= rhs.width; + height /= rhs.height; + return *this; + } + size2_base& operator /=(T rhs) + { + width /= rhs; + height /= rhs; + return *this; + } + size2_base& operator *=(const size2_base& rhs) + { + width *= rhs.width; + height *= rhs.height; + return *this; + } + size2_base& operator *=(T rhs) + { + width *= rhs; + height *= rhs; + return *this; + } + + constexpr bool operator == (const size2_base& rhs) const + { + return width == rhs.width && height == rhs.height; + } + + constexpr bool operator != (const size2_base& rhs) const + { + return width != rhs.width || height != rhs.height; + } + + template + constexpr operator size2_base() const + { + return{ (NT)width, (NT)height }; + } +}; + +template +struct position1_base +{ + T x; + + position1_base operator -(const position1_base& rhs) const + { + return{ x - rhs.x }; + } + position1_base operator -(T rhs) const + { + return{ x - rhs }; + } + position1_base operator +(const position1_base& rhs) const + { + return{ x + rhs.x }; + } + position1_base operator +(T rhs) const + { + return{ x + rhs }; + } + template + position1_base operator *(RhsT rhs) const + { + return{ T(x * rhs) }; + } + position1_base operator *(const position1_base& rhs) const + { + return{ T(x * rhs.x) }; + } + template + position1_base operator /(RhsT rhs) const + { + return{ x / rhs }; + } + position1_base operator /(const position1_base& rhs) const + { + return{ x / rhs.x }; + } + + position1_base& operator -=(const position1_base& rhs) + { + x -= rhs.x; + return *this; + } + position1_base& operator -=(T rhs) + { + x -= rhs; + return *this; + } + position1_base& operator +=(const position1_base& rhs) + { + x += rhs.x; + return *this; + } + position1_base& operator +=(T rhs) + { + x += rhs; + return *this; + } + + template + position1_base& operator *=(RhsT rhs) const + { + x *= rhs; + return *this; + } + position1_base& operator *=(const position1_base& rhs) const + { + x *= rhs.x; + return *this; + } + template + position1_base& operator /=(RhsT rhs) const + { + x /= rhs; + return *this; + } + position1_base& operator /=(const position1_base& rhs) const + { + x /= rhs.x; + return *this; + } + + bool operator ==(const position1_base& rhs) const + { + return x == rhs.x; + } + + bool operator ==(T rhs) const + { + return x == rhs; + } + + bool operator !=(const position1_base& rhs) const + { + return !(*this == rhs); + } + + bool operator !=(T rhs) const + { + return !(*this == rhs); + } + + template + operator position1_base() const + { + return{ (NT)x }; + } + + double distance(const position1_base& to) + { + return abs(x - to.x); + } +}; + +template +struct position2_base +{ + T x, y; + + constexpr position2_base() : x{}, y{} + { + } + + constexpr position2_base(T x, T y) : x{ x }, y{ y } + { + } + + constexpr position2_base(const position2_base& rhs) : x{ rhs.x }, y{ rhs.y } + { + } + + constexpr bool operator >(const position2_base& rhs) const + { + return x > rhs.x && y > rhs.y; + } + constexpr bool operator >(T rhs) const + { + return x > rhs && y > rhs; + } + constexpr bool operator <(const position2_base& rhs) const + { + return x < rhs.x && y < rhs.y; + } + constexpr bool operator <(T rhs) const + { + return x < rhs && y < rhs; + } + constexpr bool operator >=(const position2_base& rhs) const + { + return x >= rhs.x && y >= rhs.y; + } + constexpr bool operator >=(T rhs) const + { + return x >= rhs && y >= rhs; + } + constexpr bool operator <=(const position2_base& rhs) const + { + return x <= rhs.x && y <= rhs.y; + } + constexpr bool operator <=(T rhs) const + { + return x <= rhs && y <= rhs; + } + + constexpr position2_base operator -(const position2_base& rhs) const + { + return{ x - rhs.x, y - rhs.y }; + } + constexpr position2_base operator -(T rhs) const + { + return{ x - rhs, y - rhs }; + } + constexpr position2_base operator +(const position2_base& rhs) const + { + return{ x + rhs.x, y + rhs.y }; + } + constexpr position2_base operator +(T rhs) const + { + return{ x + rhs, y + rhs }; + } + template + constexpr position2_base operator *(RhsT rhs) const + { + return{ T(x * rhs), T(y * rhs) }; + } + constexpr position2_base operator *(const position2_base& rhs) const + { + return{ T(x * rhs.x), T(y * rhs.y) }; + } + template + constexpr position2_base operator /(RhsT rhs) const + { + return{ x / rhs, y / rhs }; + } + constexpr position2_base operator /(const position2_base& rhs) const + { + return{ x / rhs.x, y / rhs.y }; + } + constexpr position2_base operator /(const size2_base& rhs) const + { + return{ x / rhs.width, y / rhs.height }; + } + + position2_base& operator -=(const position2_base& rhs) + { + x -= rhs.x; + y -= rhs.y; + return *this; + } + position2_base& operator -=(T rhs) + { + x -= rhs; + y -= rhs; + return *this; + } + position2_base& operator +=(const position2_base& rhs) + { + x += rhs.x; + y += rhs.y; + return *this; + } + position2_base& operator +=(T rhs) + { + x += rhs; + y += rhs; + return *this; + } + + template + position2_base& operator *=(RhsT rhs) + { + x *= rhs; + y *= rhs; + return *this; + } + position2_base& operator *=(const position2_base& rhs) + { + x *= rhs.x; + y *= rhs.y; + return *this; + } + template + position2_base& operator /=(RhsT rhs) + { + x /= rhs; + y /= rhs; + return *this; + } + position2_base& operator /=(const position2_base& rhs) + { + x /= rhs.x; + y /= rhs.y; + return *this; + } + + constexpr bool operator ==(const position2_base& rhs) const + { + return x == rhs.x && y == rhs.y; + } + + constexpr bool operator ==(T rhs) const + { + return x == rhs && y == rhs; + } + + constexpr bool operator !=(const position2_base& rhs) const + { + return !(*this == rhs); + } + + constexpr bool operator !=(T rhs) const + { + return !(*this == rhs); + } + + template + constexpr operator position2_base() const + { + return{ (NT)x, (NT)y }; + } + + double distance(const position2_base& to) const + { + return std::sqrt(double((x - to.x) * (x - to.x) + (y - to.y) * (y - to.y))); + } +}; + +template +struct position3_base +{ + T x, y, z; + /* + position3_base() : x{}, y{}, z{} + { + } + + position3_base(T x, T y, T z) : x{ x }, y{ y }, z{ z } + { + } + */ + + position3_base operator -(const position3_base& rhs) const + { + return{ x - rhs.x, y - rhs.y, z - rhs.z }; + } + position3_base operator -(T rhs) const + { + return{ x - rhs, y - rhs, z - rhs }; + } + position3_base operator +(const position3_base& rhs) const + { + return{ x + rhs.x, y + rhs.y, z + rhs.z }; + } + position3_base operator +(T rhs) const + { + return{ x + rhs, y + rhs, z + rhs }; + } + + position3_base& operator -=(const position3_base& rhs) + { + x -= rhs.x; + y -= rhs.y; + z -= rhs.z; + return *this; + } + position3_base& operator -=(T rhs) + { + x -= rhs; + y -= rhs; + z -= rhs; + return *this; + } + position3_base& operator +=(const position3_base& rhs) + { + x += rhs.x; + y += rhs.y; + z += rhs.z; + return *this; + } + position3_base& operator +=(T rhs) + { + x += rhs; + y += rhs; + z += rhs; + return *this; + } + + bool operator ==(const position3_base& rhs) const + { + return x == rhs.x && y == rhs.y && z == rhs.z; + } + + bool operator ==(T rhs) const + { + return x == rhs && y == rhs && z == rhs; + } + + bool operator !=(const position3_base& rhs) const + { + return !(*this == rhs); + } + + bool operator !=(T rhs) const + { + return !(*this == rhs); + } + + template + operator position3_base() const + { + return{ (NT)x, (NT)y, (NT)z }; + } +}; + +template +struct position4_base +{ + T x, y, z, w; + + constexpr position4_base() : x{}, y{}, z{}, w{} + { + } + + constexpr position4_base(T x, T y = {}, T z = {}, T w = {T(1)}) : x{ x }, y{ y }, z{ z }, w{ w } + { + } + + constexpr position4_base operator -(const position4_base& rhs) const + { + return{ x - rhs.x, y - rhs.y, z - rhs.z, w - rhs.w }; + } + constexpr position4_base operator -(T rhs) const + { + return{ x - rhs, y - rhs, z - rhs, w - rhs }; + } + constexpr position4_base operator +(const position4_base& rhs) const + { + return{ x + rhs.x, y + rhs.y, z + rhs.z, w + rhs.w }; + } + constexpr position4_base operator +(T rhs) const + { + return{ x + rhs, y + rhs, z + rhs, w + rhs }; + } + + position4_base& operator -=(const position4_base& rhs) + { + x -= rhs.x; + y -= rhs.y; + z -= rhs.z; + w -= rhs.w; + return *this; + } + position4_base& operator -=(T rhs) + { + x -= rhs; + y -= rhs; + z -= rhs; + w -= rhs; + return *this; + } + position4_base& operator +=(const position4_base& rhs) + { + x += rhs.x; + y += rhs.y; + z += rhs.z; + w += rhs.w; + return *this; + } + position4_base& operator +=(T rhs) + { + x += rhs; + y += rhs; + z += rhs; + w += rhs; + return *this; + } + + constexpr bool operator ==(const position4_base& rhs) const + { + return x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w; + } + + constexpr bool operator ==(T rhs) const + { + return x == rhs && y == rhs && z == rhs && w == rhs; + } + + constexpr bool operator !=(const position4_base& rhs) const + { + return !(*this == rhs); + } + + constexpr bool operator !=(T rhs) const + { + return !(*this == rhs); + } + + template + constexpr operator position4_base() const + { + return{ (NT)x, (NT)y, (NT)z, (NT)w }; + } +}; + +template +using position_base = position2_base; + +template +struct coord_base +{ + union + { + position_base position; + struct { T x, y; }; + }; + + union + { + size2_base size; + struct { T width, height; }; + }; + + constexpr coord_base() : position{}, size{} +#ifdef _MSC_VER + //compiler error + , x{}, y{}, width{}, height{} +#endif + { + } + + constexpr coord_base(const position_base& position, const size2_base& size) + : position{ position }, size{ size } +#ifdef _MSC_VER + , x{ position.x }, y{ position.y }, width{ size.width }, height{ size.height } +#endif + { + } + + constexpr coord_base(T x, T y, T width, T height) : x{ x }, y{ y }, width{ width }, height{ height } + { + } + + constexpr bool test(const position_base& position) const + { + if (position.x < x || position.x >= x + width) + return false; + + if (position.y < y || position.y >= y + height) + return false; + + return true; + } + + constexpr bool operator == (const coord_base& rhs) const + { + return position == rhs.position && size == rhs.size; + } + + constexpr bool operator != (const coord_base& rhs) const + { + return position != rhs.position || size != rhs.size; + } + + template + constexpr operator coord_base() const + { + return{ (NT)x, (NT)y, (NT)width, (NT)height }; + } +}; + +template +struct area_base +{ + T x1, x2; + T y1, y2; + + constexpr area_base() : x1{}, x2{}, y1{}, y2{} + { + } + + constexpr area_base(T x1, T y1, T x2, T y2) : x1{ x1 }, x2{ x2 }, y1{ y1 }, y2{ y2 } + { + } + + constexpr area_base(const coord_base& coord) : x1{ coord.x }, x2{ coord.x + coord.width }, y1{ coord.y }, y2{ coord.y + coord.height } + { + } + + constexpr operator coord_base() const + { + return{ x1, y1, x2 - x1, y2 - y1 }; + } + + void flip_vertical() + { + std::swap(y1, y2); + } + + void flip_horizontal() + { + std::swap(x1, x2); + } + + constexpr area_base flipped_vertical() const + { + return{ x1, y2, x2, y1 }; + } + + constexpr area_base flipped_horizontal() const + { + return{ x2, y1, x1, y2 }; + } + + constexpr bool operator == (const area_base& rhs) const + { + return x1 == rhs.x1 && x2 == rhs.x2 && y1 == rhs.y1 && y2 == rhs.y2; + } + + constexpr bool operator != (const area_base& rhs) const + { + return !(*this == rhs); + } + + constexpr area_base operator - (const size2_base& size) const + { + return{ x1 - size.width, y1 - size.height, x2 - size.width, y2 - size.height }; + } + constexpr area_base operator - (const T& value) const + { + return{ x1 - value, y1 - value, x2 - value, y2 - value }; + } + constexpr area_base operator + (const size2_base& size) const + { + return{ x1 + size.width, y1 + size.height, x2 + size.width, y2 + size.height }; + } + constexpr area_base operator + (const T& value) const + { + return{ x1 + value, y1 + value, x2 + value, y2 + value }; + } + constexpr area_base operator / (const size2_base& size) const + { + return{ x1 / size.width, y1 / size.height, x2 / size.width, y2 / size.height }; + } + constexpr area_base operator / (const T& value) const + { + return{ x1 / value, y1 / value, x2 / value, y2 / value }; + } + constexpr area_base operator * (const size2_base& size) const + { + return{ x1 * size.width, y1 * size.height, x2 * size.width, y2 * size.height }; + } + constexpr area_base operator * (const T& value) const + { + return{ x1 * value, y1 * value, x2 * value, y2 * value }; + } + + template + constexpr operator area_base() const + { + return{(NT)x1, (NT)y1, (NT)x2, (NT)y2}; + } +}; + +template +struct size3_base +{ + T width, height, depth; + /* + size3_base() : width{}, height{}, depth{} + { + } + + size3_base(T width, T height, T depth) : width{ width }, height{ height }, depth{ depth } + { + } + */ +}; + +template +struct coord3_base +{ + union + { + position3_base position; + struct { T x, y, z; }; + }; + + union + { + size3_base size; + struct { T width, height, depth; }; + }; + + constexpr coord3_base() : position{}, size{} + { + } + + constexpr coord3_base(const position3_base& position, const size3_base& size) : position{ position }, size{ size } + { + } + + constexpr coord3_base(T x, T y, T z, T width, T height, T depth) : x{ x }, y{ y }, z{ z }, width{ width }, height{ height }, depth{ depth } + { + } + + constexpr bool test(const position3_base& position) const + { + if (position.x < x || position.x >= x + width) + return false; + + if (position.y < y || position.y >= y + height) + return false; + + if (position.z < z || position.z >= z + depth) + return false; + + return true; + } + + template + constexpr operator coord3_base() const + { + return{ (NT)x, (NT)y, (NT)z, (NT)width, (NT)height, (NT)depth }; + } +}; + + +template +struct color4_base +{ + union + { + struct + { + T r, g, b, a; + }; + + struct + { + T x, y, z, w; + }; + + T rgba[4]; + T xyzw[4]; + }; + + color4_base() + : x{} + , y{} + , z{} + , w{ T(1) } + { + } + + color4_base(T x, T y = {}, T z = {}, T w = {}) + : x(x) + , y(y) + , z(z) + , w(w) + { + } + + bool operator == (const color4_base& rhs) const + { + return r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a; + } + + bool operator != (const color4_base& rhs) const + { + return !(*this == rhs); + } + + template + operator color4_base() const + { + return{ (NT)x, (NT)y, (NT)z, (NT)w }; + } +}; + +template +struct color3_base +{ + union + { + struct + { + T r, g, b; + }; + + struct + { + T x, y, z; + }; + + T rgb[3]; + T xyz[3]; + }; + + constexpr color3_base(T x = {}, T y = {}, T z = {}) + : x(x) + , y(y) + , z(z) + { + } + + constexpr bool operator == (const color3_base& rhs) const + { + return r == rhs.r && g == rhs.g && b == rhs.b; + } + + constexpr bool operator != (const color3_base& rhs) const + { + return !(*this == rhs); + } + + template + constexpr operator color3_base() const + { + return{ (NT)x, (NT)y, (NT)z }; + } +}; + +template +struct color2_base +{ + union + { + struct + { + T r, g; + }; + + struct + { + T x, y; + }; + + T rg[2]; + T xy[2]; + }; + + constexpr color2_base(T x = {}, T y = {}) + : x(x) + , y(y) + { + } + + constexpr bool operator == (const color2_base& rhs) const + { + return r == rhs.r && g == rhs.g; + } + + constexpr bool operator != (const color2_base& rhs) const + { + return !(*this == rhs); + } + + template + constexpr operator color2_base() const + { + return{ (NT)x, (NT)y }; + } +}; + +template +struct color1_base +{ + union + { + T r; + T x; + }; + + constexpr color1_base(T x = {}) + : x(x) + { + } + + constexpr bool operator == (const color1_base& rhs) const + { + return r == rhs.r; + } + + constexpr bool operator != (const color1_base& rhs) const + { + return !(*this == rhs); + } + + template + constexpr operator color1_base() const + { + return{ (NT)x }; + } +}; + +//specializations +using positioni = position_base; +using positionf = position_base; +using positiond = position_base; + +using coordi = coord_base; +using coordf = coord_base; +using coordd = coord_base; + +using areai = area_base; +using areaf = area_base; +using aread = area_base; + +using position1i = position1_base; +using position1f = position1_base; +using position1d = position1_base; + +using position2i = position2_base; +using position2f = position2_base; +using position2d = position2_base; + +using position3i = position3_base; +using position3f = position3_base; +using position3d = position3_base; + +using position4i = position4_base; +using position4f = position4_base; +using position4d = position4_base; + +using size2i = size2_base; +using size2f = size2_base; +using size2d = size2_base; + +using sizei = size2i; +using sizef = size2f; +using sized = size2d; + +using size3i = size3_base; +using size3f = size3_base; +using size3d = size3_base; + +using coord3i = coord3_base; +using coord3f = coord3_base; +using coord3d = coord3_base; + +using color4i = color4_base; +using color4f = color4_base; +using color4d = color4_base; + +using color3i = color3_base; +using color3f = color3_base; +using color3d = color3_base; + +using color2i = color2_base; +using color2f = color2_base; +using color2d = color2_base; + +using color1i = color1_base; +using color1f = color1_base; +using color1d = color1_base; + +namespace std +{ + template<> + class hash + { + public: + size_t operator()(const position2i& position) const + { + return ((size_t)position.x << 32) | position.y; + } + }; +} diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index 623b342b4e..13b392b138 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -7,6 +7,7 @@ #include "Emu/RSX/GSRender.h" #include "Emu/SysCalls/Modules/cellVideoOut.h" #include "RSXThread.h" +#include "Utilities/types.h" #include "Emu/SysCalls/Callback.h" #include "Emu/SysCalls/CB_FUNC.h" diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index d89cf351c9..0ee67bc0a2 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -393,6 +393,7 @@ + diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index c7734ec744..0f90e5604e 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -1894,5 +1894,8 @@ Emu\GPU\RSX\Common + + Utilities + \ No newline at end of file