Integrate all the progress into master #6
|
@ -0,0 +1,77 @@
|
|||
#include "../assets.hpp"
|
||||
#include "font_writer.hpp"
|
||||
#include <PSX/GPU/gpu.hpp>
|
||||
#include <PSX/GPU/gpu_primitives.hpp>
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
void setup() {
|
||||
reset_links();
|
||||
for(auto& char_array : TextBuffer) {
|
||||
for(auto& single_char : char_array) {
|
||||
single_char->set_identitiy();
|
||||
single_char->clut = GPU::PageClut(Assets::FontTIM.get_clut_x(), Assets::FontTIM.get_clut_y());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void write(int16_t x, int16_t y, const char* text) {
|
||||
const auto* cur_text_end = &TextBuffer[GPU::Display::current_id][TextBufferSize];
|
||||
const auto org_x = x;
|
||||
|
||||
while(TextPtr < cur_text_end) {
|
||||
const char cur_char = *text;
|
||||
text++;
|
||||
|
||||
(*TextPtr)->position = {x, y};
|
||||
switch(cur_char) {
|
||||
case '\0':
|
||||
return;
|
||||
case '\n':
|
||||
y += 16;
|
||||
x = org_x;
|
||||
continue;
|
||||
|
||||
case 'i':
|
||||
case '!':
|
||||
x += 12;
|
||||
break;
|
||||
|
||||
default:
|
||||
x += 16;
|
||||
}
|
||||
|
||||
if(cur_char == '\0') {
|
||||
break;
|
||||
}
|
||||
|
||||
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 = GPU::Color24::Grey();
|
||||
|
||||
TextLink = &TextLink->concat(*TextPtr);
|
||||
TextPtr++;
|
||||
}
|
||||
}
|
||||
|
||||
void render() {
|
||||
const auto render_id = GPU::Display::current_id ^ 1;
|
||||
|
||||
TextLink->terminate();
|
||||
GPU::render(CharTexPage[render_id]);
|
||||
reset_links();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef __FONT_WRITER_HPP__
|
||||
#define __FONT_WRITER_HPP__
|
||||
#include <stdint.h>
|
||||
|
||||
namespace FontWriter {
|
||||
static constexpr auto TextBufferSize = 1024;
|
||||
|
||||
void setup();
|
||||
|
||||
void write(int16_t x, int16_t y, const char* text);
|
||||
void render();
|
||||
}
|
||||
|
||||
#endif //!__FONT_WRITER_HPP__
|
|
@ -1,25 +1,23 @@
|
|||
#include "FontWriter/font_writer.hpp"
|
||||
#include "assets.hpp"
|
||||
#include <PSX/GPU/gpu_primitives.hpp>
|
||||
#include <PSX/GPU/gpu.hpp>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace JabyEngine;
|
||||
static auto FontPage = GPU::TexPage({Assets::FontTIM.get_texture_x(), Assets::FontTIM.get_texture_y()}, GPU::TexturePageColor::$4bit).linked();
|
||||
static auto FontTest = GPU::SPRT(
|
||||
GPU::AreaI16({0, 0}, {256, 96}), {GPU::PagePosition(0, 0), GPU::PageClut(Assets::FontTIM.get_clut_x(), Assets::FontTIM.get_clut_y())},
|
||||
GPU::Color24::Grey()
|
||||
).linked();
|
||||
static auto FontTestColor = GPU::SPRT(
|
||||
GPU::AreaI16({0, 96}, {256, 96}), {GPU::PagePosition(0, 0), GPU::PageClut(Assets::FontTIM.get_clut_x(), Assets::FontTIM.get_clut_y())},
|
||||
GPU::Color24(0x0, 0x0, 0xA0)
|
||||
).linked();
|
||||
|
||||
static void setup() {
|
||||
Assets::load_for_main();
|
||||
FontWriter::setup();
|
||||
}
|
||||
|
||||
void main() {
|
||||
Assets::load_for_main();
|
||||
|
||||
FontPage.concat(FontTest).concat(FontTestColor);
|
||||
setup();
|
||||
|
||||
while(true) {
|
||||
FontWriter::write(0, 32, "Cody is cute\n&\na BAAAAABY!!!");
|
||||
|
||||
GPU::swap_buffers_vsync(1);
|
||||
GPU::render(FontPage);
|
||||
FontWriter::render();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue