Support basic linked elements
This commit is contained in:
56
include/PSX/GPU/Primitives/linked_elements.hpp
Normal file
56
include/PSX/GPU/Primitives/linked_elements.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef __JABYENGINE_LINKED_ELEMENTS_HPP__
|
||||
#define __JABYENGINE_LINKED_ELEMENTS_HPP__
|
||||
#include "../../Auxiliary/bits.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace GPU {
|
||||
struct Link {
|
||||
static constexpr auto AdrRange = BitRange::from_to(0, 23);
|
||||
static constexpr auto SizeRange = BitRange::from_to(24, 31);
|
||||
|
||||
static constexpr uint32_t TerminationValue = 0x00FFFFFF;
|
||||
|
||||
uint32_t value = TerminationValue;
|
||||
|
||||
constexpr Link() = default;
|
||||
constexpr Link(size_t size) : value(SizeRange.as_value(size >> 2) | TerminationValue) {
|
||||
}
|
||||
|
||||
//void add
|
||||
|
||||
constexpr void terminate() {
|
||||
this->value |= TerminationValue;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct LinkedElement : public Link {
|
||||
T element;
|
||||
|
||||
constexpr LinkedElement() : Link(sizeof(T)), element() {
|
||||
}
|
||||
|
||||
constexpr LinkedElement(const T& element) : Link(sizeof(T)), element(element) {
|
||||
}
|
||||
|
||||
constexpr const T* operator->() const {
|
||||
return &this->element;
|
||||
}
|
||||
|
||||
constexpr T* operator->() {
|
||||
return &this->element;
|
||||
}
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
template<typename T>
|
||||
struct LinkedElementCreator {
|
||||
constexpr LinkedElement<T> linked() {
|
||||
return LinkedElement<T>(*static_cast<T*>(this));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !__JABYENGINE_LINKED_ELEMENTS_HPP__
|
@@ -1,5 +1,6 @@
|
||||
#ifndef __JABYENGINE_PRIMITIVE_RECTANGLE_TYPES_HPP__
|
||||
#define __JABYENGINE_PRIMITIVE_RECTANGLE_TYPES_HPP__
|
||||
#include "linked_elements.hpp"
|
||||
#include "primitive_support_types.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
@@ -67,21 +68,21 @@ namespace JabyEngine {
|
||||
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> {
|
||||
Vertex position_bottom_right;
|
||||
SizeI16 size;
|
||||
|
||||
constexpr TILE() = default;
|
||||
constexpr TILE(const AreaI16& area, const Color24& color) : RECT_F(area.position, color), position_bottom_right(area.get_bottom_left()) {
|
||||
constexpr TILE(const AreaI16& area, const Color24& color) : RECT_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> {
|
||||
Vertex position_bottom_right;
|
||||
struct SPRT : public internal::RECT_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), position_bottom_right(area.get_bottom_left()) {
|
||||
constexpr SPRT(const AreaI16& area, const PagePositionClut& page, const Color24& color = Color24::Grey()) : RECT_T(area.position, page, color), size(area.size) {
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -52,13 +52,6 @@ namespace JabyEngine {
|
||||
}
|
||||
};
|
||||
|
||||
// Concept for now
|
||||
template<typename T>
|
||||
struct Hooked {
|
||||
uint32_t hook;
|
||||
T primitive;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct is_render_primitive {
|
||||
static constexpr bool value = false;
|
||||
|
@@ -38,6 +38,12 @@ namespace JabyEngine {
|
||||
|
||||
namespace internal {
|
||||
void render(const uint32_t* data, size_t words);
|
||||
void render_dma(const uint32_t* data);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static void render(const LinkedElement<T>& linked_primitives) {
|
||||
internal::render_dma(&linked_primitives.value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@@ -15,6 +15,10 @@ namespace JabyEngine {
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
|
||||
constexpr T add(S dx, S dy) const {
|
||||
return T(static_cast<const T*>(this)->x, static_cast<const T*>(this)->y).add(dx, dy);
|
||||
}
|
||||
|
||||
constexpr T& sub(S dx, S dy) {
|
||||
static_cast<T*>(this)->x -= dx;
|
||||
static_cast<T*>(this)->y -= dy;
|
||||
@@ -22,6 +26,10 @@ namespace JabyEngine {
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
|
||||
constexpr T sub(S dx, S dy) const {
|
||||
return T(static_cast<const T*>(this)->x, static_cast<const T*>(this)->y).sub(dx, dy);
|
||||
}
|
||||
|
||||
constexpr T& move(S dx, S dy) {
|
||||
return this->add(dx, dy);
|
||||
}
|
||||
@@ -156,6 +164,10 @@ namespace JabyEngine {
|
||||
constexpr Area(T position_x, T position_y, T size_width, T size_height) : position{position_x, position_y}, size{size_width, size_height} {
|
||||
}
|
||||
|
||||
constexpr Area centered() const {
|
||||
return Area(this->position.sub(this->size.width/2, this->size.height/2), this->size);
|
||||
}
|
||||
|
||||
constexpr Position<T> get_bottom_left() const {
|
||||
return this->position.move(this->size.width, this->size.height);
|
||||
}
|
||||
|
@@ -68,6 +68,10 @@ namespace JabyEngine {
|
||||
return Self{0x01000201};
|
||||
}
|
||||
|
||||
static constexpr Self StartGPULinked() {
|
||||
return Self{0x01000401};
|
||||
}
|
||||
|
||||
static constexpr Self StartCDROM() {
|
||||
return Self{0x11000000};
|
||||
}
|
||||
|
Reference in New Issue
Block a user