Start refactor of FontWriter
This commit is contained in:
parent
56486e5c3c
commit
86e1d76733
|
@ -3,33 +3,47 @@
|
||||||
#include <PSX/GPU/gpu.hpp>
|
#include <PSX/GPU/gpu.hpp>
|
||||||
#include <PSX/GPU/gpu_primitives.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 {
|
namespace FontWriter {
|
||||||
using namespace JabyEngine;
|
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() {
|
FontWriter::Pool::Buffer FontWriter::Pool :: buffer[2];
|
||||||
TextLink = &CharTexPage[GPU::Display::current_id];
|
GPU::Link* FontWriter::Pool :: last_link = nullptr;
|
||||||
TextPtr = TextBuffer[GPU::Display::current_id];
|
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() {
|
void FontWriter::Pool::Buffer :: setup() {
|
||||||
reset_links();
|
this->page = GPU::TexPage({Assets::FontTIM.get_texture_x(), Assets::FontTIM.get_texture_y()}, GPU::TexturePageColor::$4bit).linked();
|
||||||
for(auto& char_array : TextBuffer) {
|
for(auto& single_char : this->text_buffer) {
|
||||||
for(auto& single_char : char_array) {
|
single_char.set_link_identitiy();
|
||||||
single_char.set_link_identitiy();
|
single_char->set_identitiy();
|
||||||
single_char->set_identitiy();
|
single_char->clut = GPU::PageClut(Assets::FontTIM.get_clut_x(), Assets::FontTIM.get_clut_y());
|
||||||
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 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 {
|
static const auto char_to_color = [](char number) constexpr -> uint8_t {
|
||||||
return (1 << (number - '0')) - 1;
|
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]))};
|
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;
|
const auto org_x = pos.x;
|
||||||
auto font_color = GPU::Color24::Grey();
|
auto font_color = GPU::Color24::Grey();
|
||||||
|
|
||||||
while(TextPtr < cur_text_end) {
|
while(Pool::text_ptr < cur_text_end) {
|
||||||
const char cur_char = *text;
|
const char cur_char = *text;
|
||||||
text++;
|
text++;
|
||||||
|
|
||||||
(*TextPtr)->position = pos;
|
(*Pool::text_ptr)->position = pos;
|
||||||
switch(cur_char) {
|
switch(cur_char) {
|
||||||
case '\0':
|
case '\0':
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -72,22 +86,14 @@ namespace FontWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t char_id = cur_char - '!';
|
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)};
|
(*Pool::text_ptr)->page = {static_cast<uint8_t>((char_id & 0xF) << 4), static_cast<uint8_t>((char_id >> 4) << 4)};
|
||||||
(*TextPtr)->color = font_color;
|
(*Pool::text_ptr)->color = font_color;
|
||||||
|
|
||||||
TextLink = &TextLink->concat(*TextPtr);
|
Pool::last_link = &Pool::last_link->concat(*Pool::text_ptr);
|
||||||
TextPtr++;
|
Pool::text_ptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void render() {
|
|
||||||
const auto render_id = GPU::Display::current_id ^ 1;
|
|
||||||
|
|
||||||
TextLink->terminate();
|
|
||||||
GPU::render(CharTexPage[render_id]);
|
|
||||||
reset_links();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,51 @@
|
||||||
#ifndef __FONT_WRITER_HPP__
|
#ifndef __FONT_WRITER_HPP__
|
||||||
#define __FONT_WRITER_HPP__
|
#define __FONT_WRITER_HPP__
|
||||||
#include <PSX/GPU/gpu_types.hpp>
|
#include "../assets.hpp"
|
||||||
|
#include <PSX/GPU/gpu.hpp>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#pragma GCC warning "Remove this namespace and integrate to \"Objects\" folder?"
|
||||||
namespace FontWriter {
|
namespace FontWriter {
|
||||||
|
using namespace JabyEngine;
|
||||||
using Position = JabyEngine::GPU::PositionI16;
|
using Position = JabyEngine::GPU::PositionI16;
|
||||||
|
|
||||||
static constexpr auto TextBufferSize = 1024;
|
class FontWriter {
|
||||||
|
private:
|
||||||
|
class Pool {
|
||||||
|
private:
|
||||||
|
struct Buffer {
|
||||||
|
static constexpr auto BufferSize = 1024;
|
||||||
|
|
||||||
void setup();
|
GPU::TexPage::Linked page;
|
||||||
|
GPU::SPRT_16::Linked text_buffer[BufferSize];
|
||||||
|
|
||||||
Position write(Position pos, const char* text);
|
void setup();
|
||||||
void render();
|
};
|
||||||
|
|
||||||
|
static Buffer buffer[2];
|
||||||
|
static GPU::Link* last_link;
|
||||||
|
static GPU::SPRT_16::Linked* text_ptr;
|
||||||
|
|
||||||
|
static void reset_links();
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void setup();
|
||||||
|
static void render();
|
||||||
|
|
||||||
|
friend class FontWriter;
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void setup() {
|
||||||
|
Pool::setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void render() {
|
||||||
|
Pool::render();
|
||||||
|
}
|
||||||
|
|
||||||
|
Position write(Position pos, const char* text);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //!__FONT_WRITER_HPP__
|
#endif //!__FONT_WRITER_HPP__
|
|
@ -24,7 +24,7 @@ namespace object {
|
||||||
{TIM.get_texture_x(), TIM.get_texture_y()},
|
{TIM.get_texture_x(), TIM.get_texture_y()},
|
||||||
GPU::TexturePageColor::$4bit).linked()),
|
GPU::TexturePageColor::$4bit).linked()),
|
||||||
sprite(GPU::SPRT(
|
sprite(GPU::SPRT(
|
||||||
// This pic used to be 122px (file size) and every tool would except it - however the display would be corrupt. Try it!!
|
#pragma GCC warning "This pic used to be 122px (file size) and every tool would except it - however the display would be corrupt"
|
||||||
GPU::AreaI16({0, 100}, {120, 128}),
|
GPU::AreaI16({0, 100}, {120, 128}),
|
||||||
GPU::PagePositionClut({0, 0}, GPU::PageClut(TIM.get_clut_x(), TIM.get_clut_y())),
|
GPU::PagePositionClut({0, 0}, GPU::PageClut(TIM.get_clut_x(), TIM.get_clut_y())),
|
||||||
GPU::Color24::Blue()).linked()),
|
GPU::Color24::Blue()).linked()),
|
||||||
|
|
|
@ -12,21 +12,23 @@ static object::Paco paco;
|
||||||
|
|
||||||
static void setup() {
|
static void setup() {
|
||||||
Assets::load_for_main();
|
Assets::load_for_main();
|
||||||
FontWriter::setup();
|
FontWriter::FontWriter::setup();
|
||||||
|
|
||||||
paco.setup();
|
paco.setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update() {
|
static void update() {
|
||||||
const auto end_pos = FontWriter::write({0, 32}, "Cody is cute\n&\na \x1b[8;0;0mBAAAAABY!!!");
|
FontWriter::FontWriter cursor;
|
||||||
FontWriter::write(end_pos, "\x1b[0;7;7mJaby was\nhere c:");
|
|
||||||
|
const auto end_pos = cursor.write({0, 32}, "Cody is cute\n&\na \x1b[8;0;0mBAAAAABY!!!");
|
||||||
|
cursor.write(end_pos, "\x1b[0;7;7mJaby was\nhere c:");
|
||||||
|
|
||||||
paco.update();
|
paco.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void render() {
|
static void render() {
|
||||||
GPU::swap_buffers_vsync(1);
|
GPU::swap_buffers_vsync(1);
|
||||||
FontWriter::render();
|
FontWriter::FontWriter::render();
|
||||||
paco.render();
|
paco.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,8 +61,7 @@ namespace JabyEngine {
|
||||||
struct LinkedElement : public Link {
|
struct LinkedElement : public Link {
|
||||||
T element;
|
T element;
|
||||||
|
|
||||||
constexpr LinkedElement() : Link(sizeof(T)), element() {
|
constexpr LinkedElement() = default;
|
||||||
}
|
|
||||||
|
|
||||||
constexpr LinkedElement(const T& element) : Link(sizeof(T)), element(element) {
|
constexpr LinkedElement(const T& element) : Link(sizeof(T)), element(element) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ namespace JabyEngine {
|
||||||
|
|
||||||
GPU_IO::GP0_t value;
|
GPU_IO::GP0_t value;
|
||||||
|
|
||||||
|
constexpr TexPage() = default;
|
||||||
constexpr TexPage(const PositionU16& tex_pos, TexturePageColor tex_color, SemiTransparency transparency = SemiTransparency::B_Half_add_F_Half, bool dither = false) : value{
|
constexpr TexPage(const PositionU16& tex_pos, TexturePageColor tex_color, SemiTransparency transparency = SemiTransparency::B_Half_add_F_Half, bool dither = false) : value{
|
||||||
GPU_IO::Command::TexPage(tex_pos, transparency, tex_color, dither, false)} {}
|
GPU_IO::Command::TexPage(tex_pos, transparency, tex_color, dither, false)} {}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue