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 FontPrimitive font_buffer[2][256];
static NewFontWriter new_font_writer;
static void setup() {
static constexpr auto FontTIM = SimpleTIM(320, 0, 320, DefaultFont::Info.VRAMSize.height);
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();
FontWriter::FontWriter::setup();
@ -29,13 +30,11 @@ 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");
new_font_writer.write(Make::PositionI16(8, 8), "012345");
paco.update();
}
@ -43,7 +42,7 @@ static void render() {
GPU::swap_buffers_vsync(1);
FontWriter::FontWriter::render();
paco.render();
NewFontWriter::render();
new_font_writer.render();
}
void main() {

View File

@ -2,15 +2,29 @@
#include "Type/types.hpp"
namespace JabyEngine {
struct FontWriter {
struct Cursor {
GPU::PositionI16 pos;
class FontWriter {
private:
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);
static Cursor start(const GPU::PositionI16& pos);
static void render();
public:
static constexpr FontWriter empty() {
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 <stdio.h>
#include <PSX/Auxiliary/mem_dump.hpp>
namespace JabyEngine {
struct DoubleBuffer {
GPU::TexPage::Linked tex_page;
FontBufferInfo prim_buffer;
FontPrimitive* cur_primitive;
void FontWriter :: 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->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) {
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++) {
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();
}
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++) {
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) {
double_buffer.setup(buffer_info, vram_dst, Make::SizeI16(font_info.FontSize.width, font_info.FontSize.height));
}
void FontWriter :: 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];
FontWriter::Cursor FontWriter :: start(const GPU::PositionI16& pos) {
return Cursor{.pos = pos};
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 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];
}
}