Start refactor of FontWriter
This commit is contained in:
@@ -3,33 +3,47 @@
|
||||
#include <PSX/GPU/gpu.hpp>
|
||||
#include <PSX/GPU/gpu_primitives.hpp>
|
||||
|
||||
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<const char*, GPU::Color24> {
|
||||
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<uint8_t>((char_id & 0xF) << 4), static_cast<uint8_t>((char_id >> 4) << 4)};
|
||||
(*TextPtr)->color = font_color;
|
||||
(*Pool::text_ptr)->page = {static_cast<uint8_t>((char_id & 0xF) << 4), static_cast<uint8_t>((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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user