Remove all old code
This commit is contained in:
95
examples/PoolBox/application/old/FontWriter/font_writer.cpp
Normal file
95
examples/PoolBox/application/old/FontWriter/font_writer.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
#include "../assets.hpp"
|
||||
#include "font_writer.hpp"
|
||||
#include <PSX/GPU/gpu.hpp>
|
||||
#include <PSX/GPU/gpu_primitives.hpp>
|
||||
|
||||
namespace FontWriter {
|
||||
using namespace JabyEngine;
|
||||
|
||||
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 FontWriter::Pool::Buffer :: setup() {
|
||||
this->page = GPU::TexPage::create(GPU::PositionU16::create(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::create(Assets::FontTIM.get_clut_x(), Assets::FontTIM.get_clut_y());
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
if(text[0] != '[' || text[2] != ';' || text[4] != ';' || text[6] != 'm') {
|
||||
return {text, color};
|
||||
}
|
||||
|
||||
return {text + 7, GPU::Color24::from_rgb(char_to_color(text[1]), char_to_color(text[3]), char_to_color(text[5]))};
|
||||
};
|
||||
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(Pool::text_ptr < cur_text_end) {
|
||||
const char cur_char = *text;
|
||||
text++;
|
||||
|
||||
(*Pool::text_ptr)->position = pos;
|
||||
switch(cur_char) {
|
||||
case '\0':
|
||||
goto end;
|
||||
|
||||
case '\n':
|
||||
pos.y += 16;
|
||||
pos.x = org_x;
|
||||
continue;
|
||||
|
||||
case '\x1b':
|
||||
tie(text, font_color) = parse_esc(text, font_color);
|
||||
continue;
|
||||
|
||||
case 'i':
|
||||
case '!':
|
||||
pos.x += 12;
|
||||
break;
|
||||
|
||||
default:
|
||||
pos.x += 16;
|
||||
}
|
||||
|
||||
const uint8_t char_id = cur_char - '!';
|
||||
(*Pool::text_ptr)->tex_offset = GPU::PageOffset::create(((char_id & 0xF) << 4), ((char_id >> 4) << 4));
|
||||
(*Pool::text_ptr)->color = font_color;
|
||||
|
||||
Pool::last_link = &Pool::last_link->concat(*Pool::text_ptr);
|
||||
Pool::text_ptr++;
|
||||
}
|
||||
|
||||
end:
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
48
examples/PoolBox/application/old/FontWriter/font_writer.hpp
Normal file
48
examples/PoolBox/application/old/FontWriter/font_writer.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
#include "../assets.hpp"
|
||||
#include <PSX/GPU/gpu.hpp>
|
||||
#include <stdint.h>
|
||||
|
||||
#pragma GCC warning "Remove this namespace and integrate to \"Objects\" folder?"
|
||||
namespace FontWriter {
|
||||
using namespace JabyEngine;
|
||||
using Position = JabyEngine::GPU::PositionI16;
|
||||
|
||||
class FontWriter {
|
||||
private:
|
||||
class Pool {
|
||||
private:
|
||||
struct Buffer {
|
||||
static constexpr auto BufferSize = 1024;
|
||||
|
||||
GPU::TexPage::Linked page;
|
||||
GPU::SPRT_16::Linked text_buffer[BufferSize];
|
||||
|
||||
void setup();
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user