Support basic linked elements
This commit is contained in:
parent
cc77237150
commit
c705c3627c
|
@ -121,6 +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 void load_assets() {
|
||||
static const CDFile Assets[] = {
|
||||
CDFileBuilder::simple_tim(LBA::FONT, SimpleTIM(320, 0, 320, 511)),
|
||||
|
@ -180,6 +182,8 @@ void main() {
|
|||
GPU::render(line3);
|
||||
GPU::render(line4);
|
||||
|
||||
GPU::render(rect9);
|
||||
|
||||
GPU::swap_buffers_vsync(2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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};
|
||||
}
|
||||
|
|
|
@ -63,6 +63,15 @@ namespace JabyEngine {
|
|||
GPU_IO::GP0 = data[n];
|
||||
}
|
||||
}
|
||||
|
||||
void render_dma(const uint32_t* data) {
|
||||
wait_ready_for_CMD();
|
||||
// DPCR already enabled
|
||||
GPU_IO::GP1 = GPU_IO::Command::DMADirection(GPU_IO::DMADirection::CPU2GPU);
|
||||
DMA_IO::GPU.set_adr(reinterpret_cast<uintptr_t>(data));
|
||||
DMA_IO::GPU.block_ctrl = 0;
|
||||
DMA_IO::GPU.channel_ctrl = DMA_IO::CHCHR_t::StartGPULinked();
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef USE_NO$PSX
|
||||
|
|
Loading…
Reference in New Issue