diff --git a/examples/PoolBox/application/src/main.cpp b/examples/PoolBox/application/src/main.cpp index 15604d58..165dcaa7 100644 --- a/examples/PoolBox/application/src/main.cpp +++ b/examples/PoolBox/application/src/main.cpp @@ -29,10 +29,13 @@ static void setup() { static void update() { FontWriter::FontWriter cursor; + auto new_cursor = NewFontWriter::start(Make::PositionI16(16, 16)); 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:"); + new_cursor.write("0"); + paco.update(); } diff --git a/support/include/FontWriter/font_writer.hpp b/support/include/FontWriter/font_writer.hpp index e63e68d9..d93529d2 100644 --- a/support/include/FontWriter/font_writer.hpp +++ b/support/include/FontWriter/font_writer.hpp @@ -3,7 +3,14 @@ namespace JabyEngine { struct FontWriter { - static void setup(const FontBufferInfo& buffer_info, const SimpleTIM& vram_dst, const FontInfo& font_info); - static void render(); + struct Cursor { + GPU::PositionI16 pos; + + void write(const char* str); + }; + + static void setup(const FontBufferInfo& buffer_info, const SimpleTIM& vram_dst, const FontInfo& font_info); + static Cursor start(const GPU::PositionI16& pos); + static void render(); }; } \ No newline at end of file diff --git a/support/src/FontWriter/src/font_writer.cpp b/support/src/FontWriter/src/font_writer.cpp index eb94d271..f055b8f2 100644 --- a/support/src/FontWriter/src/font_writer.cpp +++ b/support/src/FontWriter/src/font_writer.cpp @@ -8,23 +8,17 @@ namespace JabyEngine { struct DoubleBuffer { GPU::TexPage::Linked tex_page; - GPU::SPRT::Linked* cur_sprt_ptr; FontBufferInfo prim_buffer; - - GPU::SPRT_16::Linked planschi; - + FontPrimitive* cur_primitive; + static constexpr DoubleBuffer empty() { - return DoubleBuffer{.tex_page = {0}, .cur_sprt_ptr = nullptr, .prim_buffer = FontBufferInfo::empty()}; + return DoubleBuffer{.tex_page = {0}, .prim_buffer = FontBufferInfo::empty(), .cur_primitive = nullptr}; } void setup(const FontBufferInfo& buffer_info, const SimpleTIM& vram_dst, const GPU::SizeI16& font_size) { - this->tex_page = Make::TexPage(vram_dst.get_texture_position(), GPU::TexturePageColor::$4bit).linked(); - this->prim_buffer = buffer_info; - - this->planschi = Make::SPRT_16( - Make::PositionI16(0, 0), - Make::OffsetPageWithClut(Make::PageOffset(0, 0), Make::PageClut(vram_dst.get_clut_position())) - ).linked(); + this->tex_page = Make::TexPage(vram_dst.get_texture_position(), GPU::TexturePageColor::$4bit).linked(); + this->prim_buffer = buffer_info; + this->cur_primitive = buffer_info.double_buffer[GPU::Display::current_id]; for(size_t buffer_id = 0; buffer_id < 2; buffer_id++) { for(size_t buffer_element_id = 0; buffer_element_id < buffer_info.single_buffer_length; buffer_element_id++) { @@ -32,26 +26,56 @@ namespace JabyEngine { Make::AreaI16(Make::PositionI16(0, 0), font_size), Make::OffsetPageWithClut(Make::PageOffset(0, 0), Make::PageClut(vram_dst.get_clut_position())) ).linked(); - - this->prim_buffer.double_buffer[buffer_id][buffer_element_id]->set_identitiy(); } } } + + void write(GPU::PositionI16 pos, const char* str) { + const auto* primitive_end = &this->prim_buffer.double_buffer[GPU::Display::current_id][this->prim_buffer.single_buffer_length]; + + while(this->cur_primitive < primitive_end && *str != '\0') { + auto& primitive = *this->cur_primitive; + + this->cur_primitive++; + str++; + primitive->position = pos; + primitive.concat(*this->cur_primitive); + + pos.move(primitive->size.width, 0); + } + } + + void render() { + const auto update_id = GPU::Display::current_id; + const auto render_id = update_id ^ 1; + + this->cur_primitive -= 1; + if(this->cur_primitive >= this->prim_buffer.double_buffer[render_id]) { + this->cur_primitive->terminate(); + this->tex_page.concat(*this->prim_buffer.double_buffer[render_id]); + + GPU::render(this->tex_page); + } + + this->cur_primitive = this->prim_buffer.double_buffer[update_id]; + } }; static auto double_buffer = DoubleBuffer::empty(); - void FontWriter :: setup(const FontBufferInfo& buffer_info, const SimpleTIM& vram_dst, const FontInfo& font_info) { - printf("Hello Planschi c: @0x%p @0x%p\n", buffer_info.double_buffer[0], buffer_info.double_buffer[1]); - double_buffer.setup(buffer_info, vram_dst, Make::SizeI16(font_info.FontSize.width, font_info.FontSize.height)); + void FontWriter::Cursor :: write(const char* str) { + double_buffer.write(this->pos, str); + } - //TMP - double_buffer.prim_buffer.double_buffer[0][0].terminate(); - double_buffer.tex_page.concat(double_buffer.prim_buffer.double_buffer[0][0]); - //TMP-END + void FontWriter :: setup(const FontBufferInfo& buffer_info, const SimpleTIM& vram_dst, const FontInfo& font_info) { + double_buffer.setup(buffer_info, vram_dst, Make::SizeI16(font_info.FontSize.width, font_info.FontSize.height)); + } + + FontWriter::Cursor FontWriter :: start(const GPU::PositionI16& pos) { + return Cursor{.pos = pos}; } void FontWriter :: render() { - GPU::render(double_buffer.tex_page); + double_buffer.render(); } } \ No newline at end of file