Change to object orientated design

This commit is contained in:
jaby 2023-11-30 20:55:36 -05:00
parent c7e43a0210
commit 90731c1e52
3 changed files with 60 additions and 77 deletions

View File

@ -14,12 +14,13 @@ using NewFontWriter = ::JabyEngine::FontWriter;
static object::Paco paco; static object::Paco paco;
static FontPrimitive font_buffer[2][256]; static FontPrimitive font_buffer[2][256];
static NewFontWriter new_font_writer;
static void setup() { static void setup() {
static constexpr auto FontTIM = SimpleTIM(320, 0, 320, DefaultFont::Info.VRAMSize.height); static constexpr auto FontTIM = SimpleTIM(320, 0, 320, DefaultFont::Info.VRAMSize.height);
DefaultFont::load(&__heap_start, FontTIM); DefaultFont::load(&__heap_start, FontTIM);
NewFontWriter::setup(FontBufferInfo::from(font_buffer), FontTIM, DefaultFont::Info); new_font_writer.setup(FontBufferInfo::from(font_buffer), FontTIM, DefaultFont::Info);
Assets::load_for_main(); Assets::load_for_main();
FontWriter::FontWriter::setup(); FontWriter::FontWriter::setup();
@ -29,13 +30,11 @@ static void setup() {
static void update() { static void update() {
FontWriter::FontWriter cursor; 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!!!"); 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:"); cursor.write(end_pos, "\x1b[0;7;7mJaby was\nhere c:");
new_cursor.write("0"); new_font_writer.write(Make::PositionI16(8, 8), "012345");
paco.update(); paco.update();
} }
@ -43,7 +42,7 @@ static void render() {
GPU::swap_buffers_vsync(1); GPU::swap_buffers_vsync(1);
FontWriter::FontWriter::render(); FontWriter::FontWriter::render();
paco.render(); paco.render();
NewFontWriter::render(); new_font_writer.render();
} }
void main() { void main() {

View File

@ -2,15 +2,29 @@
#include "Type/types.hpp" #include "Type/types.hpp"
namespace JabyEngine { namespace JabyEngine {
struct FontWriter { class FontWriter {
struct Cursor { private:
GPU::PositionI16 pos; GPU::TexPage::Linked tex_page;
FontBufferInfo prim_buffer;
FontPrimitive* cur_primitive;
void write(const char* str); void setup(const FontBufferInfo& buffer_info, const SimpleTIM& vram_dst, const GPU::SizeI16& font_size);
};
static void setup(const FontBufferInfo& buffer_info, const SimpleTIM& vram_dst, const FontInfo& font_info); public:
static Cursor start(const GPU::PositionI16& pos); static constexpr FontWriter empty() {
static void render(); FontWriter instance;
instance.tex_page = {0};
instance.prim_buffer = FontBufferInfo::empty();
instance.cur_primitive = nullptr;
return instance;
}
void setup(const FontBufferInfo& buffer_info, const SimpleTIM& vram_dst, const FontInfo& font_info) {
FontWriter::setup(buffer_info, vram_dst, Make::SizeI16(font_info.FontSize.width, font_info.FontSize.height));
}
void write(GPU::PositionI16 pos, const char* str);
void render();
}; };
} }

View File

@ -3,79 +3,49 @@
#include <FontWriter/font_writer.hpp> #include <FontWriter/font_writer.hpp>
#include <stdio.h> #include <stdio.h>
#include <PSX/Auxiliary/mem_dump.hpp>
namespace JabyEngine { namespace JabyEngine {
struct DoubleBuffer { void FontWriter :: setup(const FontBufferInfo& buffer_info, const SimpleTIM& vram_dst, const GPU::SizeI16& font_size) {
GPU::TexPage::Linked tex_page; this->tex_page = Make::TexPage(vram_dst.get_texture_position(), GPU::TexturePageColor::$4bit).linked();
FontBufferInfo prim_buffer; this->prim_buffer = buffer_info;
FontPrimitive* cur_primitive; this->cur_primitive = buffer_info.double_buffer[GPU::Display::current_id];
static constexpr DoubleBuffer 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) { for(size_t buffer_id = 0; buffer_id < 2; buffer_id++) {
this->tex_page = Make::TexPage(vram_dst.get_texture_position(), GPU::TexturePageColor::$4bit).linked(); for(size_t buffer_element_id = 0; buffer_element_id < buffer_info.single_buffer_length; buffer_element_id++) {
this->prim_buffer = buffer_info; this->prim_buffer.double_buffer[buffer_id][buffer_element_id] = Make::SPRT(
this->cur_primitive = buffer_info.double_buffer[GPU::Display::current_id]; Make::AreaI16(Make::PositionI16(0, 0), font_size),
Make::OffsetPageWithClut(Make::PageOffset(0, 0), Make::PageClut(vram_dst.get_clut_position()))
for(size_t buffer_id = 0; buffer_id < 2; buffer_id++) { ).linked();
for(size_t buffer_element_id = 0; buffer_element_id < buffer_info.single_buffer_length; buffer_element_id++) {
this->prim_buffer.double_buffer[buffer_id][buffer_element_id] = Make::SPRT(
Make::AreaI16(Make::PositionI16(0, 0), font_size),
Make::OffsetPageWithClut(Make::PageOffset(0, 0), Make::PageClut(vram_dst.get_clut_position()))
).linked();
}
} }
} }
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::Cursor :: write(const char* str) {
double_buffer.write(this->pos, str);
} }
void FontWriter :: setup(const FontBufferInfo& buffer_info, const SimpleTIM& vram_dst, const FontInfo& font_info) { void FontWriter :: write(GPU::PositionI16 pos, const char* str) {
double_buffer.setup(buffer_info, vram_dst, Make::SizeI16(font_info.FontSize.width, font_info.FontSize.height)); const auto* primitive_end = &this->prim_buffer.double_buffer[GPU::Display::current_id][this->prim_buffer.single_buffer_length];
}
FontWriter::Cursor FontWriter :: start(const GPU::PositionI16& pos) { while(this->cur_primitive < primitive_end && *str != '\0') {
return Cursor{.pos = pos}; auto& primitive = *this->cur_primitive;
this->cur_primitive++;
str++;
primitive->position = pos;
primitive.concat(*this->cur_primitive);
pos.move(primitive->size.width, 0);
}
} }
void FontWriter :: render() { void FontWriter :: render() {
double_buffer.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];
} }
} }