From 833bc560d0a10092a7c06705d0c0770a8b690838 Mon Sep 17 00:00:00 2001 From: jaby Date: Fri, 1 Dec 2023 15:25:36 -0500 Subject: [PATCH] Wiggle experiments --- examples/PoolBox/application/src/Objects/paco.cpp | 5 ++++- examples/PoolBox/application/src/Objects/paco.hpp | 2 +- examples/PoolBox/application/src/main.cpp | 7 +++++-- support/include/FontWriter/font_writer.hpp | 2 +- support/src/FontWriter/src/font_writer.cpp | 11 +++++++---- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/examples/PoolBox/application/src/Objects/paco.cpp b/examples/PoolBox/application/src/Objects/paco.cpp index c3637f0e..f5a8e91d 100644 --- a/examples/PoolBox/application/src/Objects/paco.cpp +++ b/examples/PoolBox/application/src/Objects/paco.cpp @@ -9,13 +9,16 @@ namespace object { this->tex_page.concat(this->sprite); } - void Paco :: update() { + bool Paco :: update() { if(this->timer.is_expired_for(325_ms)) { static constexpr uint8_t LastIDX = (sizeof(Paco::Colors)/sizeof(Paco::Colors[0])) - 1; this->color_idx = (this->color_idx == LastIDX) ? 0 : this->color_idx + 1; this->timer.reset(); + return true; } + + return false; } void Paco :: render() { diff --git a/examples/PoolBox/application/src/Objects/paco.hpp b/examples/PoolBox/application/src/Objects/paco.hpp index 6e3e42ed..960bb20e 100644 --- a/examples/PoolBox/application/src/Objects/paco.hpp +++ b/examples/PoolBox/application/src/Objects/paco.hpp @@ -30,7 +30,7 @@ namespace object { color_idx(0) {} void setup(); - void update(); + bool update(); void render(); }; } \ No newline at end of file diff --git a/examples/PoolBox/application/src/main.cpp b/examples/PoolBox/application/src/main.cpp index 28901902..c02a702b 100644 --- a/examples/PoolBox/application/src/main.cpp +++ b/examples/PoolBox/application/src/main.cpp @@ -15,6 +15,7 @@ using NewFontWriter = ::JabyEngine::FontWriter; static object::Paco paco; static FontPrimitive font_buffer[2][256]; static NewFontWriter new_font_writer; +static uint8_t wiggle_count = 0; static void setup() { static constexpr auto FontTIM = SimpleTIM(320, 0, 320, DefaultFont::Info.VRAMSize.height); @@ -34,8 +35,10 @@ 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"); - paco.update(); + new_font_writer.write(Make::PositionI16(8, 8), "012345 ABCDEFGHIJKL\nabcedfghijkl", GPU::Color24::Blue(), wiggle_count); + if(paco.update()) { + wiggle_count++; + }wiggle_count++; } static void render() { diff --git a/support/include/FontWriter/font_writer.hpp b/support/include/FontWriter/font_writer.hpp index 74381022..5853cf3b 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.FontSize.width, font_info.FontSize.height)); } - GPU::PositionI16 write(GPU::PositionI16 pos, const char* str); + GPU::PositionI16 write(GPU::PositionI16 pos, const char* str, GPU::Color24 color = GPU::Color24::Grey(), uint8_t wiggle_count = 0); 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 4204e2c3..13330c92 100644 --- a/support/src/FontWriter/src/font_writer.cpp +++ b/support/src/FontWriter/src/font_writer.cpp @@ -4,11 +4,13 @@ #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(); this->cur_primitive = buffer_info.double_buffer[GPU::Display::current_id]; - + for(size_t buffer_id = 0; buffer_id < 2; buffer_id++) { for(size_t buffer_element_id = 0; buffer_element_id < buffer_info.single_buffer_length; buffer_element_id++) { this->prim_buffer.double_buffer[buffer_id][buffer_element_id] = Make::SPRT( @@ -19,7 +21,7 @@ namespace JabyEngine { } } - GPU::PositionI16 FontWriter :: write(GPU::PositionI16 pos, const char* str) { + GPU::PositionI16 FontWriter :: write(GPU::PositionI16 pos, const char* str, GPU::Color24 color, uint8_t wiggle_count) { 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; @@ -41,13 +43,14 @@ namespace JabyEngine { auto& primitive = *this->cur_primitive++; primitive->position = pos; + primitive->position.move(0, -WiggleValues[wiggle_count&0b111]); primitive->tex_offset = GPU::PageOffset::from_tile_id(cur_char - '!', row_count, font_size); - primitive->color = GPU::Color24::Grey(); + primitive->color = color; primitive.concat(*this->cur_primitive); pos.move(primitive->size.width, 0); + wiggle_count++; } - return pos; }