From aeb1cd57dab9ccdff016a4fccb0baa86bece1a0c Mon Sep 17 00:00:00 2001 From: jaby Date: Wed, 3 Jan 2024 15:18:44 -0600 Subject: [PATCH] Implement Wiggle Title Text --- .../PoolBox/application/src/application.cpp | 11 ++++++ .../PoolBox/application/src/font_writer.cpp | 35 +++++++++++++++++++ .../application/src/include/font_writer.hpp | 14 ++++++++ .../PoolBox/application/src/include/paco.hpp | 3 +- examples/PoolBox/application/src/paco.cpp | 9 ----- support/include/FontWriter/font_writer.hpp | 4 +-- support/src/FontWriter/Makefile | 2 +- support/src/FontWriter/src/font_writer.cpp | 2 +- 8 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 examples/PoolBox/application/src/font_writer.cpp create mode 100644 examples/PoolBox/application/src/include/font_writer.hpp diff --git a/examples/PoolBox/application/src/application.cpp b/examples/PoolBox/application/src/application.cpp index 8948810a..2aeed044 100644 --- a/examples/PoolBox/application/src/application.cpp +++ b/examples/PoolBox/application/src/application.cpp @@ -1,5 +1,8 @@ #include "../include/asset_mgr.hpp" +#include "include/font_writer.hpp" #include "include/paco.hpp" +#include +#include #include using namespace JabyEngine; @@ -10,14 +13,22 @@ static object::Paco paco; static void setup() { Assets::Main::load(); + FontWriter::setup(); paco.setup(); } static void update() { + static const char Title[] = "Pool Box"; + static constexpr auto TitleLength = (sizeof(Title) - 1)*DefaultFont::Info.font_size.width; + + auto cursor = FontWriter::update(JabyEngine::Make::PositionI16((GPU::Display::Width-TitleLength)/2, 16)); paco.update(); + + FontWriter::new_font_writer.write(cursor, Title, GPU::Color24::Yellow(), &FontWriter::wiggle); } static void render() { + FontWriter::new_font_writer.render(); paco.render(); } diff --git a/examples/PoolBox/application/src/font_writer.cpp b/examples/PoolBox/application/src/font_writer.cpp new file mode 100644 index 00000000..de74b02d --- /dev/null +++ b/examples/PoolBox/application/src/font_writer.cpp @@ -0,0 +1,35 @@ +#include "include/font_writer.hpp" +#include +#include //< only for __heap_start D: +#include + +namespace FontWriter { + using namespace JabyEngine; + + static constexpr auto LibraryFontTIM = SimpleTIM(320, 0, 320, DefaultFont::Info.texture_size.height); + + static FontPrimitive font_buffer[2*256]; + 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)}; + JabyEngine::FontWriter new_font_writer = JabyEngine::FontWriter::empty(); + JabyEngine::FontWriter bios_font_writer = JabyEngine::FontWriter::empty(); + static SimpleTimer timer; + uint8_t wiggle_count = 0; + + void setup() { + JabyEngine::DefaultFont::load(&__heap_start, LibraryFontTIM); + JabyEngine::GlobalFontPrimitivePool::setup(font_buffer); + + new_font_writer.setup(LibraryFontTIM, JabyEngine::DefaultFont::Info); + bios_font_writer.setup(JabyEngine::BIOSFont::TIM, JabyEngine::BIOSFont::Info); + timer.reset(); + } + + State update(const GPU::PositionI16& start) { + if(timer.is_expired_for(50_ms)) { + timer.reset(); + wiggle_count++; + } + + return State::create(start, wiggle_count); + } +} \ No newline at end of file diff --git a/examples/PoolBox/application/src/include/font_writer.hpp b/examples/PoolBox/application/src/include/font_writer.hpp new file mode 100644 index 00000000..21324c21 --- /dev/null +++ b/examples/PoolBox/application/src/include/font_writer.hpp @@ -0,0 +1,14 @@ +#pragma once +#include +#include + +namespace FontWriter { + using namespace JabyEngine; + + extern Wiggle wiggle; + extern JabyEngine::FontWriter new_font_writer; + extern JabyEngine::FontWriter bios_font_writer; + + void setup(); + State update(const GPU::PositionI16& start); +} \ No newline at end of file diff --git a/examples/PoolBox/application/src/include/paco.hpp b/examples/PoolBox/application/src/include/paco.hpp index b39e6668..052dc8c6 100644 --- a/examples/PoolBox/application/src/include/paco.hpp +++ b/examples/PoolBox/application/src/include/paco.hpp @@ -8,6 +8,7 @@ namespace object { class Paco { private: + static constexpr auto Size = Make::SizeI16(120, 128); static const GPU::Color24 Colors[]; GPU::TexPage::Linked tex_page; @@ -21,7 +22,7 @@ namespace object { Assets::Main::PacoTIM.get_texture_x(), Assets::Main::PacoTIM.get_texture_y()), GPU::TexturePageColor::$4bit).linked()), sprite(Make::SPRT( - Make::AreaI16(Make::PositionI16(0, 100), Make::SizeI16(120, 128)), + Make::AreaI16(Make::PositionI16(GPU::Display::Width - Size.width, GPU::Display::Height - Size.height), Size), Make::OffsetPageWithClut(Make::PageOffset(0, 0), Make::PageClut(Assets::Main::PacoTIM.get_clut_x(), Assets::Main::PacoTIM.get_clut_y())), GPU::Color24::Blue()).linked()), timer(), diff --git a/examples/PoolBox/application/src/paco.cpp b/examples/PoolBox/application/src/paco.cpp index f1f19eb8..24862d24 100644 --- a/examples/PoolBox/application/src/paco.cpp +++ b/examples/PoolBox/application/src/paco.cpp @@ -4,15 +4,6 @@ namespace object { const GPU::Color24 Paco :: Colors[] = {GPU::Color24::Red(), GPU::Color24::Green(), GPU::Color24::Blue(), GPU::Color24::Yellow()}; void Paco :: setup() { - /*this->tex_page = Make::TexPage(Make::PositionU16( - Assets::Main::PacoTIM.get_texture_x(), Assets::Main::PacoTIM.get_texture_y()), - GPU::TexturePageColor::$4bit).linked(); - - this->sprite = Make::SPRT( - Make::AreaI16(Make::PositionI16(0, 100), Make::SizeI16(120, 128)), - Make::OffsetPageWithClut(Make::PageOffset(0, 0), Make::PageClut(Assets::Main::PacoTIM.get_clut_x(), Assets::Main::PacoTIM.get_clut_y())), - GPU::Color24::Blue()).linked();*/ - this->timer.reset(); this->tex_page.concat(this->sprite); } diff --git a/support/include/FontWriter/font_writer.hpp b/support/include/FontWriter/font_writer.hpp index b176b076..5f924b44 100644 --- a/support/include/FontWriter/font_writer.hpp +++ b/support/include/FontWriter/font_writer.hpp @@ -40,10 +40,10 @@ namespace JabyEngine { void write(State& state, const char* str, GPU::Color24 color, ...) { __write_impl(color, color, nullptr); } - void write(State& state, const char* str, GPU::Color24 color, Wiggle* wiggle, ...) { + void write(State& state, const char* str, GPU::Color24 color, const Wiggle* wiggle, ...) { __write_impl(wiggle, color, wiggle); } - void write(State& state, const char* str, GPU::Color24 color, Wiggle* wiggle, va_list list); + void write(State& state, const char* str, GPU::Color24 color, const Wiggle* wiggle, va_list list); void render(); #undef __write_impl diff --git a/support/src/FontWriter/Makefile b/support/src/FontWriter/Makefile index 9d394b62..9db8758f 100644 --- a/support/src/FontWriter/Makefile +++ b/support/src/FontWriter/Makefile @@ -21,7 +21,7 @@ LIB_OBJS = $(filter-out $(MAIN_BOOT_OBJ) $(OVERLAY_BOOT_OBJ),$(OBJS)) #$(info $$var2 is [${LIB_OBJS}]) $(DEFAULT_FONT_IMAGE): ressources/DefaultFont.png - jaby_engine_fconv --lz4 $< simple-tim clut4 --color-trans | cpp_out --name default_font_data -o $@ + jaby_engine_fconv --lz4 $< simple-tim clut4 --semi-trans --color-trans | cpp_out --name default_font_data -o $@ #Linking rule $(TARGET).a: $(LIB_OBJS) diff --git a/support/src/FontWriter/src/font_writer.cpp b/support/src/FontWriter/src/font_writer.cpp index c8eaeadd..975dd083 100644 --- a/support/src/FontWriter/src/font_writer.cpp +++ b/support/src/FontWriter/src/font_writer.cpp @@ -63,7 +63,7 @@ namespace JabyEngine { this->last_primitive = nullptr; } - void FontWriter :: write(State& state, const char* str, GPU::Color24 color, Wiggle* wiggle, va_list list) { + void FontWriter :: write(State& state, const char* str, GPU::Color24 color, const Wiggle* wiggle, va_list list) { static const auto exchang_str = [](const char* str, const char* new_str) -> pair { return {str + 1, new_str}; };