From 5d5b1ae6dedfe8c1b3ad63329f50df923da164e2 Mon Sep 17 00:00:00 2001 From: Jaby Date: Fri, 1 Dec 2023 22:24:00 -0500 Subject: [PATCH] New wiggle approach --- examples/PoolBox/application/src/main.cpp | 8 +++++--- include/PSX/GPU/gpu_primitives.hpp | 18 +++++++++++++++++ include/PSX/GPU/gpu_types.hpp | 6 ++++-- support/include/FontWriter/Type/types.hpp | 20 +++++++++++++++++++ support/include/FontWriter/font_writer.hpp | 4 ++-- support/src/FontWriter/src/font_writer.cpp | 23 +++++++++++----------- 6 files changed, 60 insertions(+), 19 deletions(-) diff --git a/examples/PoolBox/application/src/main.cpp b/examples/PoolBox/application/src/main.cpp index c02a702b..ea35df81 100644 --- a/examples/PoolBox/application/src/main.cpp +++ b/examples/PoolBox/application/src/main.cpp @@ -15,10 +15,11 @@ using NewFontWriter = ::JabyEngine::FontWriter; static object::Paco paco; static FontPrimitive font_buffer[2][256]; static NewFontWriter new_font_writer; +static Wiggle wiggle = {Make::PositionI8(0, 0), Make::PositionI8(1, -2), Make::PositionI8(0, -4), Make::PositionI8(-1, -2), Make::PositionI8(0, 0), Make::PositionI8(1, 2), Make::PositionI8(0, 4), Make::PositionI8(-1, 2)}; static uint8_t wiggle_count = 0; static void setup() { - static constexpr auto FontTIM = SimpleTIM(320, 0, 320, DefaultFont::Info.VRAMSize.height); + static constexpr auto FontTIM = SimpleTIM(320, 0, 320, DefaultFont::Info.texture_size.height); DefaultFont::load(&__heap_start, FontTIM); new_font_writer.setup(FontBufferInfo::from(font_buffer), FontTIM, DefaultFont::Info); @@ -35,10 +36,11 @@ static void update() { 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_font_writer.write(Make::PositionI16(8, 8), "012345 ABCDEFGHIJKL\nabcedfghijkl", GPU::Color24::Blue(), wiggle_count); + auto state = State::create(Make::PositionI16(8, 8), wiggle_count); + new_font_writer.write(state, "012345 ABCDEFGHIJKL\nabcedfghijkl", GPU::Color24::Blue(), &wiggle); if(paco.update()) { wiggle_count++; - }wiggle_count++; + } } static void render() { diff --git a/include/PSX/GPU/gpu_primitives.hpp b/include/PSX/GPU/gpu_primitives.hpp index 8de6f036..f7b14774 100644 --- a/include/PSX/GPU/gpu_primitives.hpp +++ b/include/PSX/GPU/gpu_primitives.hpp @@ -32,6 +32,24 @@ namespace JabyEngine { static constexpr GPU::SizeU16 SizeU16(uint16_t x, uint16_t y) { return creator_template(x, y); } + + // ################################################################### + + static constexpr GPU::PositionI8 PositionI8() { + return creator_template(0_i8, 0_i8); + } + static constexpr GPU::PositionI8 PositionI8(int8_t x, int8_t y) { + return creator_template(x, y); + } + + // ################################################################### + + static constexpr GPU::PositionU8 PositionU8() { + return creator_template(0_u8, 0_u8); + } + static constexpr GPU::PositionU8 PositionU8(int8_t x, int8_t y) { + return creator_template(x, y); + } // ################################################################### diff --git a/include/PSX/GPU/gpu_types.hpp b/include/PSX/GPU/gpu_types.hpp index e86e96f7..639f2819 100644 --- a/include/PSX/GPU/gpu_types.hpp +++ b/include/PSX/GPU/gpu_types.hpp @@ -141,8 +141,10 @@ namespace JabyEngine { return Position{.x = x, .y = y}; } }; - typedef Position PositionI16; - typedef Position PositionU16; + using PositionI8 = Position; + using PositionU8 = Position; + using PositionI16 = Position; + using PositionU16 = Position; template struct Size { diff --git a/support/include/FontWriter/Type/types.hpp b/support/include/FontWriter/Type/types.hpp index 771b8902..b1b7f5ba 100644 --- a/support/include/FontWriter/Type/types.hpp +++ b/support/include/FontWriter/Type/types.hpp @@ -11,6 +11,15 @@ namespace JabyEngine { GPU::SizeU16 font_size; }; + struct State { + GPU::PositionI16 pos; + uint8_t wiggle_count; + + static constexpr State create(GPU::PositionI16 pos, uint8_t wiggle_count = 0) { + return State{.pos = pos, .wiggle_count = wiggle_count}; + } + }; + struct FontBufferInfo { FontPrimitive* double_buffer[2]; size_t single_buffer_length; @@ -24,4 +33,15 @@ namespace JabyEngine { return FontBufferInfo{.double_buffer = {buffer[0], buffer[1]}, .single_buffer_length = N}; } }; + + using Wiggle = GPU::PositionI8[8]; + + /*struct Wiggle { + GPU::PositionI8 offset[8]; + uint8_t count; + + GPU::PositionI8 next() { + return this->offset[(this->count++)&0x7]; + } + };*/ } diff --git a/support/include/FontWriter/font_writer.hpp b/support/include/FontWriter/font_writer.hpp index fc9ae0bc..8d472766 100644 --- a/support/include/FontWriter/font_writer.hpp +++ b/support/include/FontWriter/font_writer.hpp @@ -24,7 +24,7 @@ namespace JabyEngine { FontWriter::setup(buffer_info, vram_dst, Make::SizeI16(font_info.font_size.width, font_info.font_size.height)); } - GPU::PositionI16 write(GPU::PositionI16 pos, const char* str, GPU::Color24 color = GPU::Color24::Grey(), uint8_t wiggle_count = 0); - void render(); + void write(State& state, const char* str, GPU::Color24 color = GPU::Color24::Grey(), Wiggle* wiggle = nullptr); + void render(); }; } \ No newline at end of file diff --git a/support/src/FontWriter/src/font_writer.cpp b/support/src/FontWriter/src/font_writer.cpp index 13330c92..57e8fb77 100644 --- a/support/src/FontWriter/src/font_writer.cpp +++ b/support/src/FontWriter/src/font_writer.cpp @@ -4,8 +4,6 @@ #include namespace JabyEngine { - static constexpr int8_t WiggleValues[] = {0, 3, 5, 1, -2, -5, -4, 1};//{0, 2, 6, 2, 0, -2, -6, -2}; - void FontWriter :: setup(const FontBufferInfo& buffer_info, const SimpleTIM& vram_dst, const GPU::SizeI16& font_size) { this->prim_buffer = buffer_info; this->tex_page = Make::TexPage(vram_dst.get_texture_position(), GPU::TexturePageColor::$4bit).linked(); @@ -21,37 +19,38 @@ namespace JabyEngine { } } - GPU::PositionI16 FontWriter :: write(GPU::PositionI16 pos, const char* str, GPU::Color24 color, uint8_t wiggle_count) { + void FontWriter :: write(State& state, const char* str, GPU::Color24 color, Wiggle* wiggle) { const auto* primitive_end = &this->prim_buffer.double_buffer[GPU::Display::current_id][this->prim_buffer.single_buffer_length]; const auto font_size = this->prim_buffer.double_buffer[0][0]->size; const auto row_count = 256/font_size.width; - const auto old_x = pos.x; + const auto old_x = state.pos.x; while(this->cur_primitive < primitive_end && *str != '\0') { const auto cur_char = *str++; if(cur_char == '\n') { - pos.x = old_x; - pos.y += font_size.height; + state.pos.x = old_x; + state.pos.y += font_size.height; continue; } if(cur_char == ' ') { - pos.x += font_size.width; + state.pos.x += font_size.width; continue; } auto& primitive = *this->cur_primitive++; - primitive->position = pos; - primitive->position.move(0, -WiggleValues[wiggle_count&0b111]); + primitive->position = state.pos; + if(wiggle) { + const auto [off_x, off_y] = (*wiggle)[(state.wiggle_count++)&0x7]; + primitive->position.move(off_x, off_y); + } primitive->tex_offset = GPU::PageOffset::from_tile_id(cur_char - '!', row_count, font_size); primitive->color = color; primitive.concat(*this->cur_primitive); - pos.move(primitive->size.width, 0); - wiggle_count++; + state.pos.move(primitive->size.width, 0); } - return pos; } void FontWriter :: render() {