Support linking primitives
This commit is contained in:
parent
c705c3627c
commit
b2886dfdac
|
@ -121,7 +121,8 @@ static constexpr const auto rect6 = GPU::SPRT_16({0, GPU::Display::Height - 16
|
|||
static constexpr const auto rect7 = GPU::SPRT_8({0, GPU::Display::Height - 8}, {{0, 0}, TriangleClut}, GPU::Color24::Yellow());
|
||||
static constexpr const auto rect8 = GPU::SPRT_1({0, GPU::Display::Height - 1}, {{0, 0}, TriangleClut}, GPU::Color24::Red());
|
||||
|
||||
static constexpr const auto rect9 = GPU::SPRT(GPU::AreaI16({GPU::Display::Width/2, GPU::Display::Height/2}, {32, 32}).centered(), {{0, 0}, TriangleClut}, GPU::Color24::Grey()).linked();
|
||||
static auto rect9 = GPU::SPRT(GPU::AreaI16({GPU::Display::Width/2, GPU::Display::Height/2}, {32, 32}).centered(), {{0, 0}, TriangleClut}, GPU::Color24::Grey()).linked();
|
||||
static auto rect10 = GPU::SPRT(GPU::AreaI16({GPU::Display::Width/2, GPU::Display::Height/2 - 32}, {32, 32}).centered(), {{0, 0}, TriangleClut}, GPU::Color24::Grey()).linked();
|
||||
|
||||
static void load_assets() {
|
||||
static const CDFile Assets[] = {
|
||||
|
@ -155,6 +156,8 @@ static void load_assets() {
|
|||
void main() {
|
||||
load_assets();
|
||||
|
||||
rect9.concat(rect10);
|
||||
|
||||
while(true) {
|
||||
GPU::render(triangle1);
|
||||
GPU::render(triangle2);
|
||||
|
|
|
@ -16,7 +16,28 @@ namespace JabyEngine {
|
|||
constexpr Link(size_t size) : value(SizeRange.as_value(size >> 2) | TerminationValue) {
|
||||
}
|
||||
|
||||
//void add
|
||||
void set_adr(const void* adr) {
|
||||
this->value = bit::value::set_normalized(this->value, AdrRange.with(reinterpret_cast<uint32_t>(adr)));
|
||||
}
|
||||
|
||||
void* get_adr() const {
|
||||
return reinterpret_cast<void*>(bit::value::get_normalized(this->value, AdrRange));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T& insert_after(T& obj) {
|
||||
const auto adr = Link::get_adr();
|
||||
|
||||
Link::set_adr(&obj);
|
||||
obj.set_adr(adr);
|
||||
return obj;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T& concat(const T& obj) {
|
||||
Link::set_adr(&obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
constexpr void terminate() {
|
||||
this->value |= TerminationValue;
|
||||
|
@ -45,6 +66,8 @@ namespace JabyEngine {
|
|||
namespace internal {
|
||||
template<typename T>
|
||||
struct LinkedElementCreator {
|
||||
typedef LinkedElement<T> Linked;
|
||||
|
||||
constexpr LinkedElement<T> linked() {
|
||||
return LinkedElement<T>(*static_cast<T*>(this));
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#ifndef __JABYENGINE_PRIMITIVE_GPU_COMMANDS_HPP__
|
||||
#define __JABYENGINE_PRIMITIVE_GPU_COMMANDS_HPP__
|
||||
#include "../../System/IOPorts/gpu_io.hpp"
|
||||
#include "linked_elements.hpp"
|
||||
#include "primitive_support_types.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace GPU {
|
||||
struct TexPage {
|
||||
struct TexPage : public internal::LinkedElementCreator<TexPage> {
|
||||
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{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#ifndef __JABYENGINE_PRIMITIVE_LINE_TYPES_HPP__
|
||||
#define __JABYENGINE_PRIMITIVE_LINE_TYPES_HPP__
|
||||
#include "linked_elements.hpp"
|
||||
#include "primitive_support_types.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
|
@ -53,14 +54,14 @@ namespace JabyEngine {
|
|||
};
|
||||
|
||||
template<typename Body>
|
||||
struct SingleLine : public LineCodeInterface<SingleLine<Body>> {
|
||||
struct SingleLine : public LineCodeInterface<SingleLine<Body>>, public internal::LinkedElementCreator<SingleLine<Body>> {
|
||||
LineHead head;
|
||||
Vertex start_point;
|
||||
Body end_point;
|
||||
};
|
||||
|
||||
template<typename Body, size_t N>
|
||||
struct MultiLine : public LineCodeInterface<MultiLine<Body, N>> {
|
||||
struct MultiLine : public LineCodeInterface<MultiLine<Body, N>>, public internal::LinkedElementCreator<MultiLine<Body, N>> {
|
||||
LineHead head;
|
||||
Vertex start_point;
|
||||
Body points[N];
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#ifndef __JABYENGINE_PRIMITIVE_POLY_TYPES_HPP__
|
||||
#define __JABYENGINE_PRIMITIVE_POLY_TYPES_HPP__
|
||||
#include "linked_elements.hpp"
|
||||
#include "primitive_support_types.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
|
@ -35,7 +36,7 @@ namespace JabyEngine {
|
|||
/ \
|
||||
3 - 2
|
||||
*/
|
||||
struct POLY_F3 : public internal::PolyCodeInterface<POLY_F3> {
|
||||
struct POLY_F3 : public internal::PolyCodeInterface<POLY_F3>, public internal::LinkedElementCreator<POLY_F3> {
|
||||
static constexpr auto IdentityCode = Code().set(Code::FlatShading).set(Code::TriVertics).set(Code::Untextured).set(Code::NonTransparent);
|
||||
|
||||
Color24 color; // a
|
||||
|
@ -53,7 +54,7 @@ namespace JabyEngine {
|
|||
}
|
||||
};
|
||||
|
||||
struct POLY_FT3 : public internal::PolyCodeInterface<POLY_FT3> {
|
||||
struct POLY_FT3 : public internal::PolyCodeInterface<POLY_FT3>, public internal::LinkedElementCreator<POLY_FT3> {
|
||||
struct VertexEx {
|
||||
Vertex position;
|
||||
PagePosition page;
|
||||
|
@ -84,7 +85,7 @@ namespace JabyEngine {
|
|||
vertex2(vertices_ex[2].position), page2(vertices_ex[2].page), padded2(0) {}
|
||||
};
|
||||
|
||||
struct POLY_G3 : public internal::PolyCodeInterface<POLY_G3> {
|
||||
struct POLY_G3 : public internal::PolyCodeInterface<POLY_G3>, public internal::LinkedElementCreator<POLY_G3> {
|
||||
static constexpr auto IdentityCode = Code(POLY_F3::IdentityCode).set(Code::GouraudShading);
|
||||
|
||||
Color24 color0; // a
|
||||
|
@ -108,7 +109,7 @@ namespace JabyEngine {
|
|||
color2(verticies_ex[2].color), pad2(0), vertex2(verticies_ex[2].position) {}
|
||||
};
|
||||
|
||||
struct POLY_GT3 : public internal::PolyCodeInterface<POLY_GT3> {
|
||||
struct POLY_GT3 : public internal::PolyCodeInterface<POLY_GT3>, public internal::LinkedElementCreator<POLY_GT3> {
|
||||
struct VertexEx {
|
||||
Vertex position;
|
||||
PagePosition page;
|
||||
|
@ -148,7 +149,7 @@ namespace JabyEngine {
|
|||
| |
|
||||
3 - 4
|
||||
*/
|
||||
struct POLY_F4 : public internal::PolyCodeInterface<POLY_F4> {
|
||||
struct POLY_F4 : public internal::PolyCodeInterface<POLY_F4>, public internal::LinkedElementCreator<POLY_F4> {
|
||||
static constexpr auto IdentityCode = Code(POLY_F3::IdentityCode).set(Code::QuadVertics);
|
||||
|
||||
Color24 color; // a
|
||||
|
@ -173,7 +174,7 @@ namespace JabyEngine {
|
|||
color) {}
|
||||
};
|
||||
|
||||
struct POLY_FT4 : public internal::PolyCodeInterface<POLY_FT4> {
|
||||
struct POLY_FT4 : public internal::PolyCodeInterface<POLY_FT4>, public internal::LinkedElementCreator<POLY_FT4> {
|
||||
typedef POLY_FT3::VertexEx VertexEx;
|
||||
static constexpr auto IdentityCode = Code(POLY_FT3::IdentityCode).set(Code::QuadVertics);
|
||||
|
||||
|
@ -213,7 +214,7 @@ namespace JabyEngine {
|
|||
) {}
|
||||
};
|
||||
|
||||
struct POLY_G4 : public internal::PolyCodeInterface<POLY_G4> {
|
||||
struct POLY_G4 : public internal::PolyCodeInterface<POLY_G4>, public internal::LinkedElementCreator<POLY_G4> {
|
||||
static constexpr auto IdentityCode = Code(POLY_G3::IdentityCode).set(Code::QuadVertics);
|
||||
|
||||
Color24 color0; // a
|
||||
|
@ -249,7 +250,7 @@ namespace JabyEngine {
|
|||
) {}
|
||||
};
|
||||
|
||||
struct POLY_GT4 : public internal::PolyCodeInterface<POLY_GT4> {
|
||||
struct POLY_GT4 : public internal::PolyCodeInterface<POLY_GT4>, public internal::LinkedElementCreator<POLY_GT4> {
|
||||
typedef POLY_GT3::VertexEx VertexEx;
|
||||
static constexpr auto IdentityCode = Code(POLY_GT3::IdentityCode).set(Code::QuadVertics);
|
||||
|
||||
|
|
|
@ -34,23 +34,23 @@ namespace JabyEngine {
|
|||
};
|
||||
|
||||
template<typename RectCode::Size Size>
|
||||
struct RECT_F : public RectCodeInterface<RECT_F<Size>> {
|
||||
typedef RECT_F<Size>::Code Code;
|
||||
struct RECT_BASE_F : public RectCodeInterface<RECT_BASE_F<Size>> {
|
||||
typedef RECT_BASE_F<Size>::Code Code;
|
||||
static constexpr auto IdentityCode = Code().set(Code::Size.with(static_cast<uint8_t>(Size))).set(Code::Untextured).set(Code::NonTransparent);
|
||||
|
||||
Color24 color;
|
||||
Code code;
|
||||
Vertex position;
|
||||
|
||||
constexpr RECT_F() = default;
|
||||
constexpr RECT_F(const Vertex& position, const Color24& color) : color(color), code(IdentityCode), position(position) {
|
||||
constexpr RECT_BASE_F() = default;
|
||||
constexpr RECT_BASE_F(const Vertex& position, const Color24& color) : color(color), code(IdentityCode), position(position) {
|
||||
}
|
||||
};
|
||||
|
||||
template<typename RectCode::Size Size>
|
||||
struct RECT_T : public RectCodeInterface<RECT_T<Size>> {
|
||||
typedef RECT_T<Size>::Code Code;
|
||||
static constexpr auto IdentityCode = Code(RECT_F<Size>::IdentityCode).set(Code::Textured);
|
||||
struct RECT_BASE_T : public RectCodeInterface<RECT_BASE_T<Size>> {
|
||||
typedef RECT_BASE_T<Size>::Code Code;
|
||||
static constexpr auto IdentityCode = Code(RECT_BASE_F<Size>::IdentityCode).set(Code::Textured);
|
||||
|
||||
Color24 color;
|
||||
Code code;
|
||||
|
@ -58,31 +58,41 @@ namespace JabyEngine {
|
|||
PagePosition page;
|
||||
PageClut clut;
|
||||
|
||||
constexpr RECT_T() = default;
|
||||
constexpr RECT_T(const Vertex& position, const PagePositionClut& page, const Color24& color = Color24::Grey()) : color(color), code(IdentityCode), position(position), page(page.page), clut(page.clut) {
|
||||
constexpr RECT_BASE_T() = default;
|
||||
constexpr RECT_BASE_T(const Vertex& position, const PagePositionClut& page, const Color24& color = Color24::Grey()) : color(color), code(IdentityCode), position(position), page(page.page), clut(page.clut) {
|
||||
}
|
||||
};
|
||||
|
||||
template<typename RectCode::Size Size>
|
||||
struct RECT_F : public RECT_BASE_F<Size>, public internal::LinkedElementCreator<RECT_F<Size>> {
|
||||
using RECT_BASE_F<Size>::RECT_BASE_F;
|
||||
};
|
||||
|
||||
template<typename RectCode::Size Size>
|
||||
struct RECT_T : public RECT_BASE_T<Size>, public internal::LinkedElementCreator<RECT_T<Size>> {
|
||||
using RECT_BASE_T<Size>::RECT_BASE_T;
|
||||
};
|
||||
}
|
||||
|
||||
typedef internal::RECT_F<internal::RectCode::Size::Pixel1x1> TILE_1;
|
||||
typedef internal::RECT_F<internal::RectCode::Size::Sprite8x8> TILE_8;
|
||||
typedef internal::RECT_F<internal::RectCode::Size::Sprite16x16> TILE_16;
|
||||
struct TILE : public internal::RECT_F<internal::RectCode::Size::Variable> {
|
||||
struct TILE : public internal::RECT_BASE_F<internal::RectCode::Size::Variable>, public internal::LinkedElementCreator<TILE> {
|
||||
SizeI16 size;
|
||||
|
||||
constexpr TILE() = default;
|
||||
constexpr TILE(const AreaI16& area, const Color24& color) : RECT_F(area.position, color), size(area.size) {
|
||||
constexpr TILE(const AreaI16& area, const Color24& color) : RECT_BASE_F(area.position, color), size(area.size) {
|
||||
}
|
||||
};
|
||||
|
||||
typedef internal::RECT_T<internal::RectCode::Size::Pixel1x1> SPRT_1;
|
||||
typedef internal::RECT_T<internal::RectCode::Size::Sprite8x8> SPRT_8;
|
||||
typedef internal::RECT_T<internal::RectCode::Size::Sprite16x16> SPRT_16;
|
||||
struct SPRT : public internal::RECT_T<internal::RectCode::Size::Variable>, public internal::LinkedElementCreator<SPRT> {
|
||||
struct SPRT : public internal::RECT_BASE_T<internal::RectCode::Size::Variable>, public internal::LinkedElementCreator<SPRT> {
|
||||
SizeI16 size;
|
||||
|
||||
constexpr SPRT() = default;
|
||||
constexpr SPRT(const AreaI16& area, const PagePositionClut& page, const Color24& color = Color24::Grey()) : RECT_T(area.position, page, color), size(area.size) {
|
||||
constexpr SPRT(const AreaI16& area, const PagePositionClut& page, const Color24& color = Color24::Grey()) : RECT_BASE_T(area.position, page, color), size(area.size) {
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue