Change to object orientated design
This commit is contained in:
parent
c7e43a0210
commit
90731c1e52
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
}
|
|
@ -3,19 +3,8 @@
|
|||
#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;
|
||||
|
||||
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) {
|
||||
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];
|
||||
|
@ -30,7 +19,7 @@ namespace JabyEngine {
|
|||
}
|
||||
}
|
||||
|
||||
void write(GPU::PositionI16 pos, const char* str) {
|
||||
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];
|
||||
|
||||
while(this->cur_primitive < primitive_end && *str != '\0') {
|
||||
|
@ -45,7 +34,7 @@ namespace JabyEngine {
|
|||
}
|
||||
}
|
||||
|
||||
void render() {
|
||||
void FontWriter :: render() {
|
||||
const auto update_id = GPU::Display::current_id;
|
||||
const auto render_id = update_id ^ 1;
|
||||
|
||||
|
@ -59,23 +48,4 @@ namespace JabyEngine {
|
|||
|
||||
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));
|
||||
}
|
||||
|
||||
FontWriter::Cursor FontWriter :: start(const GPU::PositionI16& pos) {
|
||||
return Cursor{.pos = pos};
|
||||
}
|
||||
|
||||
void FontWriter :: render() {
|
||||
double_buffer.render();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue