From 4726b3c5c0b57d03295e803c1f7242f066495d25 Mon Sep 17 00:00:00 2001 From: Jaby Date: Wed, 21 Jun 2023 21:45:15 +0200 Subject: [PATCH] Use BSS default constructor --- include/PSX/Auxiliary/type_traits.hpp | 23 ++ .../GPU/Primitives/primitive_gpu_commands.hpp | 6 +- .../GPU/Primitives/primitive_line_types.hpp | 22 +- .../GPU/Primitives/primitive_poly_types.hpp | 218 +++++++++--------- .../Primitives/primitive_rectangle_types.hpp | 26 +-- .../Primitives/primitive_support_types.hpp | 22 +- include/PSX/GPU/gpu.hpp | 4 +- 7 files changed, 160 insertions(+), 161 deletions(-) diff --git a/include/PSX/Auxiliary/type_traits.hpp b/include/PSX/Auxiliary/type_traits.hpp index b1a78bb2..255696df 100644 --- a/include/PSX/Auxiliary/type_traits.hpp +++ b/include/PSX/Auxiliary/type_traits.hpp @@ -2,6 +2,27 @@ #define __JABYENGINE_TYPE_TRAITS_HPP__ namespace JabyEngine { + template + struct integral_constant { + static constexpr T value = v; + + typedef T value_type; + typedef integral_constant type; + + constexpr operator T() const { + return v; + } + + constexpr T operator()() const { + return v; + } + }; + + typedef integral_constant true_type; + typedef integral_constant false_type; + + // ############################################# + template struct enable_if {}; @@ -53,6 +74,8 @@ namespace JabyEngine { template using variadic_force_same = enable_if...>::value>::type; + + // ############################################# } #endif //! __JABYENGINE_TYPE_TRAITS_HPP__ \ No newline at end of file diff --git a/include/PSX/GPU/Primitives/primitive_gpu_commands.hpp b/include/PSX/GPU/Primitives/primitive_gpu_commands.hpp index 275d6cc9..d2bad645 100644 --- a/include/PSX/GPU/Primitives/primitive_gpu_commands.hpp +++ b/include/PSX/GPU/Primitives/primitive_gpu_commands.hpp @@ -7,15 +7,13 @@ namespace JabyEngine { namespace GPU { struct TexPage : public internal::LinkedElementCreator { + static constexpr bool is_render_primitive = true; + GPU_IO::GP0_t value; constexpr TexPage(const PositionU16& tex_pos, TexturePageColor tex_color, SemiTransparency transparency = SemiTransparency::B_Half_add_F_Half, bool dither = false) : value{ GPU_IO::Command::TexPage(tex_pos, transparency, tex_color, dither, false)} {} }; - - namespace internal { - __jaby_engine_declare_render_primitive(TexPage); - } } } diff --git a/include/PSX/GPU/Primitives/primitive_line_types.hpp b/include/PSX/GPU/Primitives/primitive_line_types.hpp index 2a8ce37c..c950b155 100644 --- a/include/PSX/GPU/Primitives/primitive_line_types.hpp +++ b/include/PSX/GPU/Primitives/primitive_line_types.hpp @@ -13,6 +13,10 @@ namespace JabyEngine { static constexpr auto FlatShading = !GouraudShading; static constexpr auto PolyLine = Bit(27 - BitCorrection); static constexpr auto SingleLine = !PolyLine; + + static constexpr LineCode create() { + return LineCode(CmdValue); + } }; template @@ -54,14 +58,14 @@ namespace JabyEngine { }; template - struct SingleLine : public LineCodeInterface>, public internal::LinkedElementCreator> { + struct SingleLine : public internal::RenderPrimitive>, public LineCodeInterface>, public internal::LinkedElementCreator> { LineHead head; Vertex start_point; Body end_point; }; template - struct MultiLine : public LineCodeInterface>, public internal::LinkedElementCreator> { + struct MultiLine : public internal::RenderPrimitive>, public LineCodeInterface>, public internal::LinkedElementCreator> { LineHead head; Vertex start_point; Body points[N]; @@ -72,7 +76,7 @@ namespace JabyEngine { struct LINE_F { typedef internal::LineCode Code; - static constexpr auto IdentityCode = Code().set(Code::FlatShading).set(Code::SingleLine).set(Code::NonTransparent); + static constexpr auto IdentityCode = Code::create().set(Code::FlatShading).set(Code::SingleLine).set(Code::NonTransparent); static constexpr internal::SingleLine create(const Color24& color, const Vertex& start_point, const Vertex& end_point) { using namespace internal; @@ -102,18 +106,6 @@ namespace JabyEngine { return {.head = LineHead::create(start_point.color, IdentityCode, true), .start_point = start_point.position, .points = {rest...}, .end = Termination::create()}; } }; - - namespace internal { - template - struct is_render_primitive> { - static constexpr bool value = true; - }; - - template - struct is_render_primitive> { - static constexpr bool value = true; - }; - } } } diff --git a/include/PSX/GPU/Primitives/primitive_poly_types.hpp b/include/PSX/GPU/Primitives/primitive_poly_types.hpp index efbc5a06..57996b6a 100644 --- a/include/PSX/GPU/Primitives/primitive_poly_types.hpp +++ b/include/PSX/GPU/Primitives/primitive_poly_types.hpp @@ -13,6 +13,10 @@ namespace JabyEngine { static constexpr auto FlatShading = !GouraudShading; static constexpr auto QuadVertics = Bit(27 - BitCorrection); static constexpr auto TriVertics = !QuadVertics; + + static constexpr PolyCode create() { + return PolyCode(CmdValue); + } }; template @@ -36,14 +40,14 @@ namespace JabyEngine { / \ 3 - 2 */ - struct POLY_F3 : public internal::PolyCodeInterface, public internal::LinkedElementCreator { - static constexpr auto IdentityCode = Code().set(Code::FlatShading).set(Code::TriVertics).set(Code::Untextured).set(Code::NonTransparent); + struct POLY_F3 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::LinkedElementCreator { + static constexpr auto IdentityCode = Code::create().set(Code::FlatShading).set(Code::TriVertics).set(Code::Untextured).set(Code::NonTransparent); - Color24 color; // a - Code code = IdentityCode; // a - Vertex vertex0; // b - Vertex vertex1; // c - Vertex vertex2; // d + Color24 color; // a + Code code; // a + Vertex vertex0; // b + Vertex vertex1; // c + Vertex vertex2; // d constexpr POLY_F3() = default; constexpr POLY_F3(const Vertex (&verticies)[3], Color24 color) : @@ -54,24 +58,24 @@ namespace JabyEngine { } }; - struct POLY_FT3 : public internal::PolyCodeInterface, public internal::LinkedElementCreator { + struct POLY_FT3 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::LinkedElementCreator { struct VertexEx { Vertex position; PagePosition page; }; static constexpr auto IdentityCode = Code(POLY_F3::IdentityCode).set(Code::Textured); - Color24 color; // a - Code code = IdentityCode; // a - Vertex vertex0; // b - PagePosition page0; // c - PageClut page_clut; // c - Vertex vertex1; // d - PagePosition page1; // e - TPage tpage; // e - Vertex vertex2; // f - PagePosition page2; // g - uint16_t padded2; // g + Color24 color; // a + Code code; // a + Vertex vertex0; // b + PagePosition page0; // c + PageClut page_clut; // c + Vertex vertex1; // d + PagePosition page1; // e + TPage tpage; // e + Vertex vertex2; // f + PagePosition page2; // g + uint16_t padded2; // g constexpr POLY_FT3() = default; constexpr POLY_FT3(const Vertex (&verticies)[3], const PagePosition (&page_pos)[3], TPage tpage, PageClut clut, Color24 color = Color24::Grey()) : POLY_FT3({ @@ -85,18 +89,18 @@ namespace JabyEngine { vertex2(vertices_ex[2].position), page2(vertices_ex[2].page), padded2(0) {} }; - struct POLY_G3 : public internal::PolyCodeInterface, public internal::LinkedElementCreator { + struct POLY_G3 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::LinkedElementCreator { static constexpr auto IdentityCode = Code(POLY_F3::IdentityCode).set(Code::GouraudShading); - Color24 color0; // a - Code code = IdentityCode; // a - Vertex vertex0; // b - Color24 color1; // c - uint8_t pad1; // c - Vertex vertex1; // d - Color24 color2; // e - uint8_t pad2; // e - Vertex vertex2; // f + Color24 color0; // a + Code code; // a + Vertex vertex0; // b + Color24 color1; // c + uint8_t pad1; // c + Vertex vertex1; // d + Color24 color2; // e + uint8_t pad2; // e + Vertex vertex2; // f constexpr POLY_G3() = default; constexpr POLY_G3(const Vertex (&verticies)[3], const Color24 (&color)[3]) : POLY_G3({ @@ -109,7 +113,7 @@ namespace JabyEngine { color2(verticies_ex[2].color), pad2(0), vertex2(verticies_ex[2].position) {} }; - struct POLY_GT3 : public internal::PolyCodeInterface, public internal::LinkedElementCreator { + struct POLY_GT3 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::LinkedElementCreator { struct VertexEx { Vertex position; PagePosition page; @@ -117,21 +121,21 @@ namespace JabyEngine { }; static constexpr auto IdentityCode = Code(POLY_G3::IdentityCode).set(Code::Textured); - Color24 color0; // a - Code code = IdentityCode; // a - Vertex vertex0; // b - PagePosition page0; // c - PageClut page_clut; // c - Color24 color1; // d - uint8_t pad1; // d - Vertex vertex1; // e - PagePosition page1; // f - TPage tpage; // f - Color24 color2; // g - uint8_t pad2; // g - Vertex vertex2; // h - PagePosition page2; // i - uint16_t pad3; // i + Color24 color0; // a + Code code; // a + Vertex vertex0; // b + PagePosition page0; // c + PageClut page_clut; // c + Color24 color1; // d + uint8_t pad1; // d + Vertex vertex1; // e + PagePosition page1; // f + TPage tpage; // f + Color24 color2; // g + uint8_t pad2; // g + Vertex vertex2; // h + PagePosition page2; // i + uint16_t pad3; // i constexpr POLY_GT3() = default; constexpr POLY_GT3(const Vertex (&verticies)[3], const PagePosition (&page_pos)[3], const Color24 (&color)[3], TPage tpage, PageClut clut) : POLY_GT3({ @@ -149,15 +153,15 @@ namespace JabyEngine { | | 3 - 4 */ - struct POLY_F4 : public internal::PolyCodeInterface, public internal::LinkedElementCreator { + struct POLY_F4 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::LinkedElementCreator { static constexpr auto IdentityCode = Code(POLY_F3::IdentityCode).set(Code::QuadVertics); - Color24 color; // a - Code code = IdentityCode; // a - Vertex vertex0; // b - Vertex vertex1; // c - Vertex vertex2; // d - Vertex vertex3; // e + Color24 color; // a + Code code; // a + Vertex vertex0; // b + Vertex vertex1; // c + Vertex vertex2; // d + Vertex vertex3; // e constexpr POLY_F4() = default; constexpr POLY_F4(const Vertex (&verticies)[4], Color24 color) : @@ -174,24 +178,24 @@ namespace JabyEngine { color) {} }; - struct POLY_FT4 : public internal::PolyCodeInterface, public internal::LinkedElementCreator { + struct POLY_FT4 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::LinkedElementCreator { typedef POLY_FT3::VertexEx VertexEx; static constexpr auto IdentityCode = Code(POLY_FT3::IdentityCode).set(Code::QuadVertics); - Color24 color; // a - Code code = IdentityCode; // a - Vertex vertex0; // b - PagePosition page0; // c - PageClut page_clut; // c - Vertex vertex1; // d - PagePosition page1; // e - TPage tpage; // e - Vertex vertex2; // f - PagePosition page2; // g - uint16_t pad2; // g - Vertex vertex3; // h - PagePosition page3; // i - uint16_t pad3; // i + Color24 color; // a + Code code; // a + Vertex vertex0; // b + PagePosition page0; // c + PageClut page_clut; // c + Vertex vertex1; // d + PagePosition page1; // e + TPage tpage; // e + Vertex vertex2; // f + PagePosition page2; // g + uint16_t pad2; // g + Vertex vertex3; // h + PagePosition page3; // i + uint16_t pad3; // i constexpr POLY_FT4() = default; constexpr POLY_FT4(const Vertex (&verticies)[4], const PagePosition (&page_pos)[4], TPage tpage, PageClut clut, Color24 color) : POLY_FT4({ @@ -214,21 +218,21 @@ namespace JabyEngine { ) {} }; - struct POLY_G4 : public internal::PolyCodeInterface, public internal::LinkedElementCreator { + struct POLY_G4 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::LinkedElementCreator { static constexpr auto IdentityCode = Code(POLY_G3::IdentityCode).set(Code::QuadVertics); - Color24 color0; // a - Code code = IdentityCode; // a - Vertex vertex0; // b - Color24 color1; // c - uint8_t pad1; // c - Vertex vertex1; // d - Color24 color2; // e - uint8_t pad2; // e - Vertex vertex2; // f - Color24 color3; // g - uint8_t pad3; // g - Vertex vertex3; // h + Color24 color0; // a + Code code; // a + Vertex vertex0; // b + Color24 color1; // c + uint8_t pad1; // c + Vertex vertex1; // d + Color24 color2; // e + uint8_t pad2; // e + Vertex vertex2; // f + Color24 color3; // g + uint8_t pad3; // g + Vertex vertex3; // h constexpr POLY_G4() = default; constexpr POLY_G4(const Vertex (&verticies)[4], const Color24 (&color)[4]) : POLY_G4({ @@ -250,30 +254,30 @@ namespace JabyEngine { ) {} }; - struct POLY_GT4 : public internal::PolyCodeInterface, public internal::LinkedElementCreator { + struct POLY_GT4 : public internal::RenderPrimitive, public internal::PolyCodeInterface, public internal::LinkedElementCreator { typedef POLY_GT3::VertexEx VertexEx; static constexpr auto IdentityCode = Code(POLY_GT3::IdentityCode).set(Code::QuadVertics); - Color24 color0; // a - Code code = IdentityCode; // a - Vertex vertex0; // b - PagePosition page0; // c - PageClut page_clut; // c - Color24 color1; // d - uint8_t pad1; // d - Vertex vertex1; // e - PagePosition page1; // f - TPage tpage; // f - Color24 color2; // g - uint8_t pad2; // g - Vertex vertex2; // h - PagePosition page2; // i - uint16_t pad3; // i - Color24 color3; // j - uint8_t pad4; // j - Vertex vertex3; // k - PagePosition page3; // l - uint16_t pad5; // l + Color24 color0; // a + Code code; // a + Vertex vertex0; // b + PagePosition page0; // c + PageClut page_clut; // c + Color24 color1; // d + uint8_t pad1; // d + Vertex vertex1; // e + PagePosition page1; // f + TPage tpage; // f + Color24 color2; // g + uint8_t pad2; // g + Vertex vertex2; // h + PagePosition page2; // i + uint16_t pad3; // i + Color24 color3; // j + uint8_t pad4; // j + Vertex vertex3; // k + PagePosition page3; // l + uint16_t pad5; // l constexpr POLY_GT4() = default; constexpr POLY_GT4(const Vertex (&verticies)[4], const PagePosition (&page_pos)[4], const Color24 (&color)[4], TPage tpage, PageClut clut) : POLY_GT4({ @@ -305,18 +309,6 @@ namespace JabyEngine { typedef POLY_G4 GouraudRectangle; typedef POLY_GT4 GouraudTexturedRectangle; - namespace internal { - __jaby_engine_declare_render_primitive(POLY_F3); - __jaby_engine_declare_render_primitive(POLY_FT3); - __jaby_engine_declare_render_primitive(POLY_G3); - __jaby_engine_declare_render_primitive(POLY_GT3); - - __jaby_engine_declare_render_primitive(POLY_F4); - __jaby_engine_declare_render_primitive(POLY_FT4); - __jaby_engine_declare_render_primitive(POLY_G4); - __jaby_engine_declare_render_primitive(POLY_GT4); - } - static_assert(sizeof(POLY_F3) == 16); static_assert(sizeof(POLY_FT3) == 28); static_assert(sizeof(POLY_G3) == 24); diff --git a/include/PSX/GPU/Primitives/primitive_rectangle_types.hpp b/include/PSX/GPU/Primitives/primitive_rectangle_types.hpp index 247ab38e..48547ca7 100644 --- a/include/PSX/GPU/Primitives/primitive_rectangle_types.hpp +++ b/include/PSX/GPU/Primitives/primitive_rectangle_types.hpp @@ -21,6 +21,10 @@ namespace JabyEngine { static constexpr uint8_t CmdValue = 0b011; static constexpr auto Size = BitRange::from_to(27 - BitCorrection, 28 - BitCorrection); + + static constexpr RectCode create() { + return RectCode(CmdValue); + } }; template @@ -36,7 +40,7 @@ namespace JabyEngine { template struct RECT_BASE_F : public RectCodeInterface> { typedef RECT_BASE_F::Code Code; - static constexpr auto IdentityCode = Code().set(Code::Size.with(static_cast(Size))).set(Code::Untextured).set(Code::NonTransparent); + static constexpr auto IdentityCode = Code::create().set(Code::Size.with(static_cast(Size))).set(Code::Untextured).set(Code::NonTransparent); Color24 color; Code code; @@ -64,12 +68,12 @@ namespace JabyEngine { }; template - struct RECT_F : public RECT_BASE_F, public internal::LinkedElementCreator> { + struct RECT_F : public RECT_BASE_F, public internal::RenderPrimitive>, public internal::LinkedElementCreator> { using RECT_BASE_F::RECT_BASE_F; }; template - struct RECT_T : public RECT_BASE_T, public internal::LinkedElementCreator> { + struct RECT_T : public RECT_BASE_T, public internal::RenderPrimitive>, public internal::LinkedElementCreator> { using RECT_BASE_T::RECT_BASE_T; }; } @@ -77,7 +81,7 @@ namespace JabyEngine { typedef internal::RECT_F TILE_1; typedef internal::RECT_F TILE_8; typedef internal::RECT_F TILE_16; - struct TILE : public internal::RECT_BASE_F, public internal::LinkedElementCreator { + struct TILE : public internal::RECT_BASE_F, public internal::RenderPrimitive, public internal::LinkedElementCreator { SizeI16 size; constexpr TILE() = default; @@ -88,25 +92,13 @@ namespace JabyEngine { typedef internal::RECT_T SPRT_1; typedef internal::RECT_T SPRT_8; typedef internal::RECT_T SPRT_16; - struct SPRT : public internal::RECT_BASE_T, public internal::LinkedElementCreator { + struct SPRT : public internal::RECT_BASE_T, public internal::RenderPrimitive, public internal::LinkedElementCreator { SizeI16 size; constexpr SPRT() = default; constexpr SPRT(const AreaI16& area, const PagePositionClut& page, const Color24& color = Color24::Grey()) : RECT_BASE_T(area.position, page, color), size(area.size) { } }; - - namespace internal { - __jaby_engine_declare_render_primitive(TILE_1); - __jaby_engine_declare_render_primitive(TILE_8); - __jaby_engine_declare_render_primitive(TILE_16); - __jaby_engine_declare_render_primitive(TILE); - - __jaby_engine_declare_render_primitive(SPRT_1); - __jaby_engine_declare_render_primitive(SPRT_8); - __jaby_engine_declare_render_primitive(SPRT_16); - __jaby_engine_declare_render_primitive(SPRT); - } } } diff --git a/include/PSX/GPU/Primitives/primitive_support_types.hpp b/include/PSX/GPU/Primitives/primitive_support_types.hpp index da3f3ae7..85a05381 100644 --- a/include/PSX/GPU/Primitives/primitive_support_types.hpp +++ b/include/PSX/GPU/Primitives/primitive_support_types.hpp @@ -1,7 +1,9 @@ #ifndef __JABYENGINE_PRIMITIVE_SUPPORT_TYPES_HPP__ #define __JABYENGINE_PRIMITIVE_SUPPORT_TYPES_HPP__ -#include "../gpu_types.hpp" +#include "../../Auxiliary/type_traits.hpp" #include "../../System/IOPorts/gpu_io.hpp" +#include "../gpu_types.hpp" + namespace JabyEngine { namespace GPU { @@ -11,7 +13,7 @@ namespace JabyEngine { static constexpr auto BitCorrection = 24; static constexpr auto CmdID = BitRange::from_to(29 - BitCorrection, 31 - BitCorrection); - uint8_t value = bit::value::set_normalized(0u, CmdID.with(T::CmdValue)); + uint8_t value; // Common values for all the primitves static constexpr auto Textured = Bit(26 - BitCorrection); @@ -22,6 +24,8 @@ namespace JabyEngine { static constexpr auto BlendTexture = !NoBlendTexture; constexpr CodeBase() = default; + constexpr CodeBase(uint8_t value) : value(bit::value::set_normalized(0u, CmdID.with(value))) { + } constexpr CodeBase(const T& code) : value(code.value) { } @@ -53,15 +57,13 @@ namespace JabyEngine { }; template - struct is_render_primitive { - static constexpr bool value = false; - }; + struct RenderPrimitive { + static constexpr bool is_render_primitive = true; - #define __jaby_engine_declare_render_primitive(type) \ - template<> \ - struct is_render_primitive { \ - static constexpr bool value = true; \ - } + void set_identitiy() { + static_cast(*this).code = T::IdentityCode; + } + }; } struct PageClut { diff --git a/include/PSX/GPU/gpu.hpp b/include/PSX/GPU/gpu.hpp index 62cf6f15..83540ec7 100644 --- a/include/PSX/GPU/gpu.hpp +++ b/include/PSX/GPU/gpu.hpp @@ -47,12 +47,12 @@ namespace JabyEngine { } template - static enable_if::value>::type render(const T& primitive) { + static enable_if::type render(const T& primitive) { internal::render(reinterpret_cast(&primitive), sizeof(T)/sizeof(uint32_t)); } template - static enable_if::value>::type render(const LINE_F (&primitives)[N]) { + static enable_if::type render(const LINE_F (&primitives)[N]) { internal::render(reinterpret_cast(&primitives), (sizeof(T)/sizeof(uint32_t))*N); }