Remove last constructor and remove GLOBAL SUB with it

This commit is contained in:
Jaby Blubb 2023-10-03 13:16:46 +02:00
parent 2c4583c8d7
commit 993adc3f26
11 changed files with 86 additions and 89 deletions

View File

@ -3,10 +3,6 @@
#include <PSX/GPU/gpu.hpp>
#include <PSX/GPU/gpu_primitives.hpp>
extern "C" void memset() {
#pragma GCC warning "Declared to make code compile because of current GLOBAL_sub bug (Resolve this by not having any constructors)"
}
namespace FontWriter {
using namespace JabyEngine;
@ -20,7 +16,7 @@ namespace FontWriter {
}
void FontWriter::Pool::Buffer :: setup() {
this->page = GPU::TexPage::create({Assets::FontTIM.get_texture_x(), Assets::FontTIM.get_texture_y()}, GPU::TexturePageColor::$4bit).linked();
this->page = GPU::TexPage::create(GPU::PositionU16::create(Assets::FontTIM.get_texture_x(), Assets::FontTIM.get_texture_y()), GPU::TexturePageColor::$4bit).linked();
for(auto& single_char : this->text_buffer) {
single_char.set_link_identitiy();
single_char->set_identitiy();
@ -86,7 +82,7 @@ namespace FontWriter {
}
const uint8_t char_id = cur_char - '!';
(*Pool::text_ptr)->page = {static_cast<uint8_t>((char_id & 0xF) << 4), static_cast<uint8_t>((char_id >> 4) << 4)};
(*Pool::text_ptr)->page = GPU::PagePosition::create(((char_id & 0xF) << 4), ((char_id >> 4) << 4));
(*Pool::text_ptr)->color = font_color;
Pool::last_link = &Pool::last_link->concat(*Pool::text_ptr);

View File

@ -20,13 +20,13 @@ namespace object {
public:
constexpr Paco() :
tex_page(GPU::TexPage::create(
{TIM.get_texture_x(), TIM.get_texture_y()},
tex_page(GPU::TexPage::create(GPU::PositionU16::create(
TIM.get_texture_x(), TIM.get_texture_y()),
GPU::TexturePageColor::$4bit).linked()),
sprite(GPU::SPRT::create(
#pragma GCC warning "This pic used to be 122px (file size) and every tool would except it - however the display would be corrupt"
GPU::AreaI16({0, 100}, {120, 128}),
GPU::PagePositionClut({0, 0}, GPU::PageClut::create(TIM.get_clut_x(), TIM.get_clut_y())),
GPU::AreaI16::create(GPU::PositionI16::create(0, 100), GPU::SizeI16::create(120, 128)),
GPU::PagePositionClut(GPU::PagePosition::create(0, 0), GPU::PageClut::create(TIM.get_clut_x(), TIM.get_clut_y())),
GPU::Color24::Blue()).linked()),
timer(),
color_idx(0) {}

View File

@ -15,34 +15,33 @@ using namespace JabyEngine;
// Some default values for the objects
static constexpr auto TriangleColor = GPU::Color24(0x0, 0xFF, 0xFF);
static constexpr auto TriangleArea = GPU::AreaI16({0, 0}, {64, 64});
static constexpr auto TriangleArea = GPU::AreaI16::create(GPU::PositionI16::create(0, 0), GPU::SizeI16::create(64, 64));
static constexpr auto TriangleTPage = GPU::TPage::create(320, 0, GPU::SemiTransparency::B_Half_add_F_Half, GPU::TexturePageColor::$4bit);
static constexpr auto TriangleClut = GPU::PageClut::create(320, 511);
static constexpr auto RectangleColor = GPU::Color24(0x80, 0x80, 0xFF);
static constexpr auto RectangleArea = GPU::AreaI16({0, TriangleArea.size.height}, {80, 80});
static constexpr auto RectangleArea = GPU::AreaI16::create(GPU::PositionI16::create(0, TriangleArea.size.height), GPU::SizeI16::create(80, 80));
static constexpr auto RectangleTPage = GPU::TPage::create(320, 256, GPU::SemiTransparency::B_Half_add_F_Half, GPU::TexturePageColor::$4bit);
static constexpr auto RectangleClut = GPU::PageClut::create(320, 510);
static constexpr auto LineColor = GPU::Color24(0xFF, 0x0, 0x0);
static constexpr const auto triangle1 = GPU::POLY_F3::create({
{TriangleArea.position.x, TriangleArea.position.y},
{TriangleArea.size.width, TriangleArea.size.height},
{TriangleArea.position.x, TriangleArea.size.height}},
TriangleColor
GPU::Vertex::create(TriangleArea.position.x, TriangleArea.position.y),
GPU::Vertex::create(TriangleArea.size.width, TriangleArea.size.height),
GPU::Vertex::create(TriangleArea.position.x, TriangleArea.size.height)
}, TriangleColor
);
static constexpr const auto triangle2 = GPU::POLY_FT3::create({
{TriangleArea.position.x, TriangleArea.position.y},
{TriangleArea.size.width, TriangleArea.position.y},
{TriangleArea.size.width, TriangleArea.size.height}},{
GPU::Vertex::create(TriangleArea.position.x, TriangleArea.position.y),
GPU::Vertex::create(TriangleArea.size.width, TriangleArea.position.y),
GPU::Vertex::create(TriangleArea.size.width, TriangleArea.size.height)
},{
// Texture
{TriangleArea.position.x, TriangleArea.position.y},
{TriangleArea.size.width, TriangleArea.position.y},
{TriangleArea.size.width, TriangleArea.size.height}},
TriangleTPage,
TriangleClut,
GPU::Color24::Grey()
GPU::PagePosition::create(TriangleArea.position.x, TriangleArea.position.y),
GPU::PagePosition::create(TriangleArea.size.width, TriangleArea.position.y),
GPU::PagePosition::create(TriangleArea.size.width, TriangleArea.size.height)
}, TriangleTPage, TriangleClut, GPU::Color24::Grey()
);
static constexpr const auto triangle3 = GPU::POLY_G3::create({
{triangle1.vertex0.move(TriangleArea.size.width, 0), GPU::Color24::Red()},
@ -58,8 +57,8 @@ static constexpr const auto triangle4 = GPU::POLY_GT3::create({
);
static constexpr const auto rectangle1 = GPU::POLY_F4::create(RectangleArea, RectangleColor);
static constexpr const auto rectangle2 = GPU::POLY_FT4::create({
RectangleArea.position.move(RectangleArea.size.width, 0), RectangleArea.size}, {0, 0},
static constexpr const auto rectangle2 = GPU::POLY_FT4::create(GPU::AreaI16::create(
RectangleArea.position.move(RectangleArea.size.width, 0), RectangleArea.size), GPU::PagePosition::create(0, 0),
RectangleTPage,
RectangleClut,
GPU::Color24::Grey()
@ -70,8 +69,8 @@ static constexpr const auto rectangle3 = GPU::POLY_G4::create(
GPU::Color24::Blue(),
GPU::Color24::Green(),
GPU::Color24::White()});
static constexpr const auto rectangle4 = GPU::POLY_GT4::create(
{RectangleArea.position.move(RectangleArea.size.width*3, 0), RectangleArea.size}, {0, 0},
static constexpr const auto rectangle4 = GPU::POLY_GT4::create(GPU::AreaI16::create(
RectangleArea.position.move(RectangleArea.size.width*3, 0), RectangleArea.size), GPU::PagePosition::create(0, 0),
RectangleTPage,
RectangleClut, {
GPU::Color24::Red(),
@ -79,8 +78,8 @@ static constexpr const auto rectangle4 = GPU::POLY_GT4::create(
GPU::Color24::Green(),
GPU::Color24::White()}
);
static constexpr const auto rectangle5 = GPU::POLY_GT4::create(
{RectangleArea.position.move(0, RectangleArea.size.height), RectangleArea.size}, {0, 0},
static constexpr const auto rectangle5 = GPU::POLY_GT4::create(GPU::AreaI16::create(
RectangleArea.position.move(0, RectangleArea.size.height), RectangleArea.size), GPU::PagePosition::create(0, 0),
RectangleTPage,
RectangleClut, {
GPU::Color24::Red(),
@ -90,39 +89,39 @@ static constexpr const auto rectangle5 = GPU::POLY_GT4::create(
).set_semi_transparent(true);
static constexpr const auto line1 = GPU::LINE_F::create(LineColor,
{0, 0},
{GPU::Display::Width, GPU::Display::Height}
GPU::Vertex::create(0, 0),
GPU::Vertex::create(GPU::Display::Width, GPU::Display::Height)
);
static constexpr const auto line2 = GPU::LINE_F::create(LineColor.invert(),
GPU::Vertex(0, 0),
GPU::Vertex(16, 0),
GPU::Vertex(16, 16),
GPU::Vertex(0, 0)
GPU::Vertex::create(0, 0),
GPU::Vertex::create(16, 0),
GPU::Vertex::create(16, 16),
GPU::Vertex::create(0, 0)
);
static constexpr const auto line3 = GPU::LINE_G::create(
{LineColor, {GPU::Display::Width, 0}},
{LineColor.invert(), {0, GPU::Display::Height}}
GPU::ColorVertex{LineColor, GPU::Vertex::create(GPU::Display::Width, 0)},
GPU::ColorVertex{LineColor.invert(), GPU::Vertex::create(0, GPU::Display::Height)}
);
static constexpr const auto line4 = GPU::LINE_G::create(
GPU::ColorVertex{GPU::Color24::Red(), {0, 0}},
GPU::ColorVertex{GPU::Color24::Green(), {0, 16}},
GPU::ColorVertex{GPU::Color24::Blue(), {16, 16}},
GPU::ColorVertex{GPU::Color24::White(), {0, 0}}
GPU::ColorVertex{GPU::Color24::Red(), GPU::Vertex::create(0, 0)},
GPU::ColorVertex{GPU::Color24::Green(), GPU::Vertex::create(0, 16)},
GPU::ColorVertex{GPU::Color24::Blue(), GPU::Vertex::create(16, 16)},
GPU::ColorVertex{GPU::Color24::White(), GPU::Vertex::create(0, 0)}
);
static constexpr const auto rect1 = GPU::TILE::create(GPU::AreaI16({GPU::Display::Width - 32, GPU::Display::Height - 32}, {32, 32}), GPU::Color24::Green());
static constexpr const auto rect2 = GPU::TILE_16::create({GPU::Display::Width - 16, GPU::Display::Height - 16}, GPU::Color24::Blue());
static constexpr const auto rect3 = GPU::TILE_8::create({GPU::Display::Width - 8, GPU::Display::Height - 8}, GPU::Color24::Yellow());
static constexpr const auto rect4 = GPU::TILE_1::create({GPU::Display::Width - 1, GPU::Display::Height - 1}, GPU::Color24::Red());
static constexpr const auto rect1 = GPU::TILE::create(GPU::AreaI16::create(GPU::PositionI16::create(GPU::Display::Width - 32, GPU::Display::Height - 32), GPU::SizeI16::create(32, 32)), GPU::Color24::Green());
static constexpr const auto rect2 = GPU::TILE_16::create(GPU::PositionI16::create(GPU::Display::Width - 16, GPU::Display::Height - 16), GPU::Color24::Blue());
static constexpr const auto rect3 = GPU::TILE_8::create(GPU::PositionI16::create(GPU::Display::Width - 8, GPU::Display::Height - 8), GPU::Color24::Yellow());
static constexpr const auto rect4 = GPU::TILE_1::create(GPU::PositionI16::create(GPU::Display::Width - 1, GPU::Display::Height - 1), GPU::Color24::Red());
static constexpr const auto texpage = GPU::TexPage::create({320, 0}, GPU::TexturePageColor::$4bit);
static constexpr const auto rect5 = GPU::SPRT::create(GPU::AreaI16({0, GPU::Display::Height - 32}, {32, 32}), {{0, 0}, TriangleClut}, GPU::Color24::Green());
static constexpr const auto rect6 = GPU::SPRT_16::create({0, GPU::Display::Height - 16}, {{0, 0}, TriangleClut}, GPU::Color24::Blue());
static constexpr const auto rect7 = GPU::SPRT_8::create({0, GPU::Display::Height - 8}, {{0, 0}, TriangleClut}, GPU::Color24::Yellow());
static constexpr const auto rect8 = GPU::SPRT_1::create({0, GPU::Display::Height - 1}, {{0, 0}, TriangleClut}, GPU::Color24::Red());
static constexpr const auto texpage = GPU::TexPage::create(GPU::PositionU16::create(320, 0), GPU::TexturePageColor::$4bit);
static constexpr const auto rect5 = GPU::SPRT::create(GPU::AreaI16(GPU::PositionI16::create(0, GPU::Display::Height - 32), GPU::SizeI16(32, 32)), {GPU::PagePosition::create(0, 0), TriangleClut}, GPU::Color24::Green());
static constexpr const auto rect6 = GPU::SPRT_16::create(GPU::Vertex::create(0, GPU::Display::Height - 16), {GPU::PagePosition::create(0, 0), TriangleClut}, GPU::Color24::Blue());
static constexpr const auto rect7 = GPU::SPRT_8::create(GPU::Vertex::create(0, GPU::Display::Height - 8), {GPU::PagePosition::create(0, 0), TriangleClut}, GPU::Color24::Yellow());
static constexpr const auto rect8 = GPU::SPRT_1::create(GPU::Vertex::create(0, GPU::Display::Height - 1), {GPU::PagePosition::create(0, 0), TriangleClut}, GPU::Color24::Red());
static auto rect9 = GPU::SPRT::create(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::create(GPU::AreaI16({GPU::Display::Width/2, GPU::Display::Height/2 - 32}, {32, 32}).centered(), {{0, 0}, TriangleClut}, GPU::Color24::Grey()).linked();
static auto rect9 = GPU::SPRT::create(GPU::AreaI16(GPU::PositionI16::create(GPU::Display::Width/2, GPU::Display::Height/2), GPU::SizeI16::create(32, 32)).centered(), {GPU::PagePosition::create(0, 0), TriangleClut}, GPU::Color24::Grey()).linked();
static auto rect10 = GPU::SPRT::create(GPU::AreaI16(GPU::PositionI16::create(GPU::Display::Width/2, GPU::Display::Height/2 - 32), GPU::SizeI16::create(32, 32)).centered(), {GPU::PagePosition::create(0, 0), TriangleClut}, GPU::Color24::Grey()).linked();
static void load_assets() {
static const CDFile Assets[] = {

View File

@ -20,7 +20,7 @@ static void setup() {
static void update() {
FontWriter::FontWriter cursor;
const auto end_pos = cursor.write({0, 32}, "Cody is cute\n&\na \x1b[8;0;0mBAAAAABY!!!");
const auto end_pos = cursor.write(FontWriter::Position::create(0, 32), "Cody is cute\n&\na \x1b[8;0;0mBAAAAABY!!!");
cursor.write(end_pos, "\x1b[0;7;7mJaby was\nhere c:");
paco.update();

View File

@ -31,7 +31,7 @@ namespace JabyEngine {
}
constexpr GPU::PositionU16 get_texture_position() const {
return {SimpleTIM::get_texture_x(), SimpleTIM::get_texture_y()};
return GPU::PositionU16::create(SimpleTIM::get_texture_x(), SimpleTIM::get_texture_y());
}
constexpr uint16_t get_clut_x() const {
@ -43,7 +43,7 @@ namespace JabyEngine {
}
constexpr GPU::PositionU16 get_clut_position() const {
return {SimpleTIM::get_clut_x(), SimpleTIM::get_clut_y()};
return GPU::PositionU16::create(SimpleTIM::get_clut_x(), SimpleTIM::get_clut_y());
}
};

View File

@ -53,7 +53,7 @@ namespace JabyEngine {
Vertex value;
static constexpr Termination create() {
return {.value = {static_cast<short>(0x5000), static_cast<short>(0x5000)}};
return {.value = Vertex::create(static_cast<short>(0x5000), static_cast<short>(0x5000))};
}
};

View File

@ -27,7 +27,7 @@ namespace JabyEngine {
}
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);
return T::create(static_cast<const T*>(this)->x, static_cast<const T*>(this)->y).sub(dx, dy);
}
constexpr T& move(S dx, S dy) {
@ -35,7 +35,7 @@ namespace JabyEngine {
}
constexpr T move(S dx, S dy) const {
return T(static_cast<const T*>(this)->x, static_cast<const T*>(this)->y).move(dx, dy);
return T::create(static_cast<const T*>(this)->x, static_cast<const T*>(this)->y).move(dx, dy);
}
};
}
@ -54,12 +54,12 @@ namespace JabyEngine {
};
struct Color24 {
uint8_t red = 0;
uint8_t green = 0;
uint8_t blue = 0;
uint8_t red;
uint8_t green;
uint8_t blue;
constexpr Color24() = default;
constexpr Color24(uint8_t r, uint8_t g, uint8_t b) : blue(b), green(g), red(r) {
static constexpr Color24 from_rgb(uint8_t r, uint8_t g, uint8_t b) {
return Color24{r, g, b};
}
constexpr uint32_t raw() const {
@ -106,7 +106,7 @@ namespace JabyEngine {
static constexpr auto BlueRange = BitRange::from_to(10, 14);
static constexpr auto SemiTransperancyBit = Bit(15);
uint16_t value = 0;
uint16_t value;
public:
static constexpr Color from_rgb(uint8_t r, uint8_t g, uint8_t b) {
@ -135,21 +135,21 @@ namespace JabyEngine {
template<typename T>
struct Position : public internal::XYMovement<Position<T>, T> {
T x = 0;
T y = 0;
T x;
T y;
constexpr Position() = default;
constexpr Position(T x, T y) : x(x), y(y) {
static constexpr Position create(T x, T y) {
return Position{.x = x, .y = y};
}
};
template<typename T>
struct Size {
T width = 0;
T height = 0;
T width;
T height;
constexpr Size() = default;
constexpr Size(T w, T h) : width(w), height(h) {
static constexpr Size create(T w, T h) {
return Size{w, h};
}
};
@ -158,10 +158,12 @@ namespace JabyEngine {
Position<T> position;
Size<T> size;
constexpr Area() = default;
constexpr Area(Position<T> position, Size<T> size) : position(position), size(size) {
static constexpr Area create(Position<T> position, Size<T> size) {
return Area{position, size};
}
constexpr Area(T position_x, T position_y, T size_width, T size_height) : position{position_x, position_y}, size{size_width, size_height} {
static constexpr Area create(T position_x, T position_y, T size_width, T size_height) {
return Area{Position<T>::create(position_x, position_y), Size<T>::create(size_width, size_height)};
}
constexpr Area centered() const {
@ -176,17 +178,17 @@ namespace JabyEngine {
// Type used for primitives
struct PagePosition : public internal::XYMovement<PagePosition, uint8_t> {
union {
uint8_t x = 0;
uint8_t x;
uint8_t u;
};
union {
uint8_t y = 0;
uint8_t y;
uint8_t v;
};
constexpr PagePosition() = default;
constexpr PagePosition(uint8_t u, uint8_t v) : x(u), y(v) { //< Activate x and y to use XYMovement during constexpr
static constexpr PagePosition create(uint8_t u, uint8_t v) {
return PagePosition{.x = u, .y = v}; //< Activate x and y to use XYMovement during constexpr
}
};

View File

@ -10,7 +10,7 @@ namespace JabyEngine {
const uint16_t sub_x = (16*((BitCount - 1) - n));
const uint16_t sub_y = (n&1)*16;
GPU::internal::quick_fill_fast((value & (1 << n)) ? GPU::Color24::Blue() : GPU::Color24::Red(), {{static_cast<uint16_t>(x + sub_x), static_cast<uint16_t>(y + sub_y)}, {16, 16}});
GPU::internal::quick_fill_fast((value & (1 << n)) ? GPU::Color24::Blue() : GPU::Color24::Red(), GPU::AreaU16::create(GPU::PositionU16::create((x + sub_x), (y + sub_y)), GPU::SizeU16::create(16, 16)));
}
}

View File

@ -59,7 +59,7 @@ namespace JabyEngine {
state.process(bytes_ready);
// Duplicate DisplayBuffer content
::JabyEngine::GPU::internal::copy_vram_to_vram({PositionU16(0, Display::Height), SizeU16(Display::Width, Display::Height)}, PositionU16(0, 0));
::JabyEngine::GPU::internal::copy_vram_to_vram({PositionU16::create(0, Display::Height), SizeU16::create(Display::Width, Display::Height)}, PositionU16::create(0, 0));
Display::enable();
}
@ -70,7 +70,7 @@ namespace JabyEngine {
::JabyEngine::GPU::internal::Display::exchange_buffer_and_display();
GPU::internal::wait_ready_for_CMD();
GPU::internal::quick_fill_fast(Color24::Black(), {PositionU16(0, 0), SizeU16(Display::Width, Display::Height)});
GPU::internal::quick_fill_fast(Color24::Black(), {PositionU16::create(0, 0), SizeU16::create(Display::Width, Display::Height)});
__syscall_EnterCriticalSection();
__syscall_SysEnqIntRP(VblankIrq, &::JabyEngine::GPU::internal::callback);

View File

@ -50,7 +50,7 @@ namespace JabyEngine {
static void set_gpu_receive(const uint32_t* src, uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
GPU::internal::DMA::Receive::prepare();
GPU::internal::DMA::Receive::set_dst(PositionU16(x, y), SizeU16(w, h));
GPU::internal::DMA::Receive::set_dst(PositionU16::create(x, y), SizeU16::create(w, h));
GPU::internal::DMA::Receive::set_src(reinterpret_cast<const uintptr_t>(src));
}

View File

@ -43,9 +43,9 @@ namespace JabyEngine {
uint32_t Display :: exchange_buffer_and_display() {
const uint16_t draw_area_y = (PublicDisplay::Height*PublicDisplay::current_id);
GPU::internal::set_draw_area({0, draw_area_y});
GPU::internal::set_draw_area(GPU::PositionU16::create(0, draw_area_y));
PublicDisplay::current_id ^= 1;
GPU_IO::GP1.write(GPU_IO::Command::DisplayArea({0, static_cast<uint16_t>((PublicDisplay::Height*PublicDisplay::current_id))}));
GPU_IO::GP1.write(GPU_IO::Command::DisplayArea(GPU::PositionU16::create(0, static_cast<uint16_t>((PublicDisplay::Height*PublicDisplay::current_id)))));
return draw_area_y;
}
@ -94,9 +94,9 @@ namespace JabyEngine {
internal::wait_vsync(syncs);
const int16_t draw_offset_y = internal::Display::exchange_buffer_and_display();
internal::set_draw_offset({0, draw_offset_y});
internal::set_draw_offset(GPU::PositionI16::create(0, draw_offset_y));
if(clear_screen) {
internal::quick_fill_fast(Color24::Black(), AreaU16{0, static_cast<uint16_t>(draw_offset_y), Display::Width, Display::Height});
internal::quick_fill_fast(Color24::Black(), AreaU16::create(0, static_cast<uint16_t>(draw_offset_y), Display::Width, Display::Height));
}
return Display::current_id;
}