diff --git a/examples/PoolBox/application/include/font_writer.hpp b/examples/PoolBox/application/include/font_writer.hpp new file mode 100644 index 00000000..79829223 --- /dev/null +++ b/examples/PoolBox/application/include/font_writer.hpp @@ -0,0 +1,6 @@ +#pragma once +#include + +void font_writer_setup(); +void font_writer_update(); +void font_writer_render(); \ No newline at end of file diff --git a/examples/PoolBox/application/src/Objects/paco.cpp b/examples/PoolBox/application/src/Objects/paco.cpp index f5a8e91d..c3637f0e 100644 --- a/examples/PoolBox/application/src/Objects/paco.cpp +++ b/examples/PoolBox/application/src/Objects/paco.cpp @@ -9,16 +9,13 @@ namespace object { this->tex_page.concat(this->sprite); } - bool Paco :: update() { + void 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 960bb20e..6e3e42ed 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(); - bool update(); + void update(); void render(); }; } \ No newline at end of file diff --git a/examples/PoolBox/application/src/font_writer.cpp b/examples/PoolBox/application/src/font_writer.cpp new file mode 100644 index 00000000..c6044082 --- /dev/null +++ b/examples/PoolBox/application/src/font_writer.cpp @@ -0,0 +1,35 @@ +#include "../include/font_writer.hpp" +#include +#include +#include +#include + +using JabyEngine::Make::PositionI8; + +static constexpr auto FontWriterTIM = JabyEngine::SimpleTIM(320, 0, 320, JabyEngine::DefaultFont::Info.texture_size.height); + +static JabyEngine::FontPrimitive font_buffer[2][256]; +static JabyEngine::Wiggle wiggle = {PositionI8(0, 0), PositionI8(1, -2), PositionI8(0, -4), PositionI8(-1, -2), PositionI8(0, 0), PositionI8(1, 2), PositionI8(0, 4), PositionI8(-1, 2)}; +static JabyEngine::FontWriter new_font_writer = JabyEngine::FontWriter::empty(); +static JabyEngine::SimpleTimer timer; +static uint8_t wiggle_count = 0; + +void font_writer_setup() { + JabyEngine::DefaultFont::load(&__heap_start, FontWriterTIM); + new_font_writer.setup(JabyEngine::FontBufferInfo::from(font_buffer), FontWriterTIM, JabyEngine::DefaultFont::Info); + timer.reset(); +} + +void font_writer_update() { + auto state = JabyEngine::State::create(JabyEngine::Make::PositionI16(8, 8), wiggle_count); + new_font_writer.write(state, "012345 ABCDEFGHIJKL\nabcedfghijkl", JabyEngine::GPU::Color24::Blue(), &wiggle); + + if(timer.is_expired_for(250_ms)) { + timer.reset(); + wiggle_count++; + } +} + +void font_writer_render() { + new_font_writer.render(); +} \ No newline at end of file diff --git a/examples/PoolBox/application/src/main.cpp b/examples/PoolBox/application/src/main.cpp index 27e3b831..f9f35972 100644 --- a/examples/PoolBox/application/src/main.cpp +++ b/examples/PoolBox/application/src/main.cpp @@ -1,3 +1,4 @@ +#include "../include/font_writer.hpp" #include "FontWriter/font_writer.hpp" #include "Objects/paco.hpp" #include "Overlay/Overlay.hpp" @@ -5,25 +6,15 @@ #include #include #include -#include -#include #include using namespace JabyEngine; 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.texture_size.height); - - DefaultFont::load(&__heap_start, FontTIM); - new_font_writer.setup(FontBufferInfo::from(font_buffer), FontTIM, DefaultFont::Info); - + font_writer_setup(); Assets::load_for_main(); FontWriter::FontWriter::setup(); @@ -36,18 +27,15 @@ 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:"); - 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++; - } + font_writer_update(); + paco.update(); } static void render() { GPU::swap_buffers_vsync(1); FontWriter::FontWriter::render(); paco.render(); - new_font_writer.render(); + font_writer_render(); } void main() { diff --git a/support/include/FontWriter/Type/types.hpp b/support/include/FontWriter/Type/types.hpp index b1b7f5ba..f6f65e89 100644 --- a/support/include/FontWriter/Type/types.hpp +++ b/support/include/FontWriter/Type/types.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include #include +#include namespace JabyEngine { using FontPrimitive = GPU::SPRT::Linked;