diff --git a/examples/PoolBox/application/src/FontWriter/font_writer.cpp b/examples/PoolBox/application/src/FontWriter/font_writer.cpp index 9f0705b3..e13fab6e 100644 --- a/examples/PoolBox/application/src/FontWriter/font_writer.cpp +++ b/examples/PoolBox/application/src/FontWriter/font_writer.cpp @@ -3,33 +3,47 @@ #include #include +extern "C" void memset() { + #pragma GCC warning "Declared to make code compile because of current GLOBAL_sub bug" +} + namespace FontWriter { using namespace JabyEngine; - static GPU::TexPage::Linked CharTexPage[2] = { - GPU::TexPage({Assets::FontTIM.get_texture_x(), Assets::FontTIM.get_texture_y()}, GPU::TexturePageColor::$4bit).linked(), - GPU::TexPage({Assets::FontTIM.get_texture_x(), Assets::FontTIM.get_texture_y()}, GPU::TexturePageColor::$4bit).linked() - }; - static GPU::SPRT_16::Linked TextBuffer[2][TextBufferSize]; - static GPU::Link* TextLink; - static GPU::SPRT_16::Linked* TextPtr; - static void reset_links() { - TextLink = &CharTexPage[GPU::Display::current_id]; - TextPtr = TextBuffer[GPU::Display::current_id]; + FontWriter::Pool::Buffer FontWriter::Pool :: buffer[2]; + GPU::Link* FontWriter::Pool :: last_link = nullptr; + GPU::SPRT_16::Linked* FontWriter::Pool :: text_ptr = nullptr; + + void FontWriter::Pool :: reset_links() { + Pool::last_link = &Pool::buffer[GPU::Display::current_id].page; + Pool::text_ptr = Pool::buffer[GPU::Display::current_id].text_buffer; } - void setup() { - reset_links(); - for(auto& char_array : TextBuffer) { - for(auto& single_char : char_array) { - single_char.set_link_identitiy(); - single_char->set_identitiy(); - single_char->clut = GPU::PageClut(Assets::FontTIM.get_clut_x(), Assets::FontTIM.get_clut_y()); - } + void FontWriter::Pool::Buffer :: setup() { + this->page = GPU::TexPage({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(); + single_char->clut = GPU::PageClut(Assets::FontTIM.get_clut_x(), Assets::FontTIM.get_clut_y()); } } - Position write(Position pos, const char* text) { + void FontWriter::Pool :: setup() { + Pool::reset_links(); + for(auto& buffer : Pool::buffer) { + buffer.setup(); + } + } + + void FontWriter::Pool :: render() { + const auto render_id = GPU::Display::current_id ^ 1; + + Pool::last_link->terminate(); + GPU::render(Pool::buffer[render_id].page); + reset_links(); + } + + Position FontWriter :: write(Position pos, const char* text) { static const auto parse_esc = [](const char* text, const GPU::Color24& color) -> pair { static const auto char_to_color = [](char number) constexpr -> uint8_t { return (1 << (number - '0')) - 1; @@ -40,15 +54,15 @@ namespace FontWriter { return {text + 7, GPU::Color24(char_to_color(text[1]), char_to_color(text[3]), char_to_color(text[5]))}; }; - const auto* cur_text_end = &TextBuffer[GPU::Display::current_id][TextBufferSize]; + const auto* cur_text_end = &Pool::buffer[GPU::Display::current_id].text_buffer[Pool::Buffer::BufferSize]; const auto org_x = pos.x; auto font_color = GPU::Color24::Grey(); - while(TextPtr < cur_text_end) { + while(Pool::text_ptr < cur_text_end) { const char cur_char = *text; text++; - (*TextPtr)->position = pos; + (*Pool::text_ptr)->position = pos; switch(cur_char) { case '\0': goto end; @@ -72,22 +86,14 @@ namespace FontWriter { } const uint8_t char_id = cur_char - '!'; - (*TextPtr)->page = {static_cast((char_id & 0xF) << 4), static_cast((char_id >> 4) << 4)}; - (*TextPtr)->color = font_color; + (*Pool::text_ptr)->page = {static_cast((char_id & 0xF) << 4), static_cast((char_id >> 4) << 4)}; + (*Pool::text_ptr)->color = font_color; - TextLink = &TextLink->concat(*TextPtr); - TextPtr++; + Pool::last_link = &Pool::last_link->concat(*Pool::text_ptr); + Pool::text_ptr++; } end: return pos; } - - void render() { - const auto render_id = GPU::Display::current_id ^ 1; - - TextLink->terminate(); - GPU::render(CharTexPage[render_id]); - reset_links(); - } } diff --git a/examples/PoolBox/application/src/FontWriter/font_writer.hpp b/examples/PoolBox/application/src/FontWriter/font_writer.hpp index 8df03c4e..2be42eab 100644 --- a/examples/PoolBox/application/src/FontWriter/font_writer.hpp +++ b/examples/PoolBox/application/src/FontWriter/font_writer.hpp @@ -1,17 +1,51 @@ #ifndef __FONT_WRITER_HPP__ #define __FONT_WRITER_HPP__ -#include +#include "../assets.hpp" +#include #include +#pragma GCC warning "Remove this namespace and integrate to \"Objects\" folder?" namespace FontWriter { + using namespace JabyEngine; using Position = JabyEngine::GPU::PositionI16; - static constexpr auto TextBufferSize = 1024; + class FontWriter { + private: + class Pool { + private: + struct Buffer { + static constexpr auto BufferSize = 1024; - void setup(); + GPU::TexPage::Linked page; + GPU::SPRT_16::Linked text_buffer[BufferSize]; - Position write(Position pos, const char* text); - void render(); + void setup(); + }; + + static Buffer buffer[2]; + static GPU::Link* last_link; + static GPU::SPRT_16::Linked* text_ptr; + + static void reset_links(); + + public: + static void setup(); + static void render(); + + friend class FontWriter; + }; + + public: + static void setup() { + Pool::setup(); + } + + static void render() { + Pool::render(); + } + + Position write(Position pos, const char* text); + }; } #endif //!__FONT_WRITER_HPP__ \ No newline at end of file diff --git a/examples/PoolBox/application/src/Objects/paco.hpp b/examples/PoolBox/application/src/Objects/paco.hpp index b2e0cf3c..af262767 100644 --- a/examples/PoolBox/application/src/Objects/paco.hpp +++ b/examples/PoolBox/application/src/Objects/paco.hpp @@ -24,7 +24,7 @@ namespace object { {TIM.get_texture_x(), TIM.get_texture_y()}, GPU::TexturePageColor::$4bit).linked()), sprite(GPU::SPRT( - // This pic used to be 122px (file size) and every tool would except it - however the display would be corrupt. Try it!! + #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(TIM.get_clut_x(), TIM.get_clut_y())), GPU::Color24::Blue()).linked()), diff --git a/examples/PoolBox/application/src/main.cpp b/examples/PoolBox/application/src/main.cpp index 2d04a7ac..9a9b503b 100644 --- a/examples/PoolBox/application/src/main.cpp +++ b/examples/PoolBox/application/src/main.cpp @@ -12,21 +12,23 @@ static object::Paco paco; static void setup() { Assets::load_for_main(); - FontWriter::setup(); + FontWriter::FontWriter::setup(); paco.setup(); } static void update() { - const auto end_pos = FontWriter::write({0, 32}, "Cody is cute\n&\na \x1b[8;0;0mBAAAAABY!!!"); - FontWriter::write(end_pos, "\x1b[0;7;7mJaby was\nhere c:"); + FontWriter::FontWriter cursor; + + const auto end_pos = cursor.write({0, 32}, "Cody is cute\n&\na \x1b[8;0;0mBAAAAABY!!!"); + cursor.write(end_pos, "\x1b[0;7;7mJaby was\nhere c:"); paco.update(); } static void render() { GPU::swap_buffers_vsync(1); - FontWriter::render(); + FontWriter::FontWriter::render(); paco.render(); } diff --git a/include/PSX/GPU/Primitives/linked_elements.hpp b/include/PSX/GPU/Primitives/linked_elements.hpp index b9bb661a..75f0e222 100644 --- a/include/PSX/GPU/Primitives/linked_elements.hpp +++ b/include/PSX/GPU/Primitives/linked_elements.hpp @@ -61,8 +61,7 @@ namespace JabyEngine { struct LinkedElement : public Link { T element; - constexpr LinkedElement() : Link(sizeof(T)), element() { - } + constexpr LinkedElement() = default; constexpr LinkedElement(const T& element) : Link(sizeof(T)), element(element) { } diff --git a/include/PSX/GPU/Primitives/primitive_gpu_commands.hpp b/include/PSX/GPU/Primitives/primitive_gpu_commands.hpp index d2bad645..95af6a99 100644 --- a/include/PSX/GPU/Primitives/primitive_gpu_commands.hpp +++ b/include/PSX/GPU/Primitives/primitive_gpu_commands.hpp @@ -11,6 +11,7 @@ namespace JabyEngine { GPU_IO::GP0_t value; + constexpr TexPage() = default; 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)} {} };