diff --git a/examples/PoolBox/application/src/Objects/paco.cpp b/examples/PoolBox/application/src/Objects/paco.cpp new file mode 100644 index 00000000..c3637f0e --- /dev/null +++ b/examples/PoolBox/application/src/Objects/paco.cpp @@ -0,0 +1,25 @@ +#include "paco.hpp" + +namespace object { + const GPU::Color24 Paco :: Colors[] = {GPU::Color24::Red(), GPU::Color24::Green(), GPU::Color24::Blue(), GPU::Color24::Yellow()}; + + void Paco :: setup() { + this->timer.reset(); + // This should only work on elements that are linkable - but it didn't + this->tex_page.concat(this->sprite); + } + + 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(); + } + } + + void Paco :: render() { + this->sprite->color = Paco::Colors[this->color_idx]; + GPU::render(this->tex_page); + } +} \ No newline at end of file diff --git a/examples/PoolBox/application/src/Objects/paco.hpp b/examples/PoolBox/application/src/Objects/paco.hpp new file mode 100644 index 00000000..b2e0cf3c --- /dev/null +++ b/examples/PoolBox/application/src/Objects/paco.hpp @@ -0,0 +1,40 @@ +#ifndef __PACO_HPP__ +#define __PACO_HPP__ +#include +#include +#include + +namespace object { + using namespace JabyEngine; + + class Paco { + public: + static constexpr auto TIM = SimpleTIM(896, 0, 960, 510); + private: + static const GPU::Color24 Colors[]; + + GPU::TexPage::Linked tex_page; + GPU::SPRT::Linked sprite; + SimpleTimer timer; + uint8_t color_idx; + + public: + constexpr Paco() : + tex_page(GPU::TexPage( + {TIM.get_texture_x(), TIM.get_texture_y()}, + GPU::TexturePageColor::$4bit).linked()), + sprite(GPU::SPRT( + // This pic used to be 122px (file size) and every tool would except it - however the display would be corrupt. Try it!! + GPU::AreaI16({0, 100}, {120, 128}), + GPU::PagePositionClut({0, 0}, GPU::PageClut(TIM.get_clut_x(), TIM.get_clut_y())), + GPU::Color24::Blue()).linked()), + timer(), + color_idx(0) {} + + void setup(); + void update(); + void render(); + }; +} + +#endif //!__PACO_HPP__ \ No newline at end of file diff --git a/examples/PoolBox/application/src/assets.hpp b/examples/PoolBox/application/src/assets.hpp index c70f17dc..a92673eb 100644 --- a/examples/PoolBox/application/src/assets.hpp +++ b/examples/PoolBox/application/src/assets.hpp @@ -6,7 +6,6 @@ namespace Assets { using namespace JabyEngine; static constexpr auto FontTIM = SimpleTIM(960, 0, 960, 511); - static constexpr auto PacoTIM = SimpleTIM(896, 0, 960, 510); void load_for_main(); } diff --git a/examples/PoolBox/application/src/main.cpp b/examples/PoolBox/application/src/main.cpp index 06dd6ddb..2d04a7ac 100644 --- a/examples/PoolBox/application/src/main.cpp +++ b/examples/PoolBox/application/src/main.cpp @@ -1,4 +1,5 @@ #include "FontWriter/font_writer.hpp" +#include "Objects/paco.hpp" #include "assets.hpp" #include #include @@ -7,48 +8,26 @@ using namespace JabyEngine; -static SimpleTimer timer; -static auto paco_texpage = GPU::TexPage( - {Assets::PacoTIM.get_texture_x(), Assets::PacoTIM.get_texture_y()}, - GPU::TexturePageColor::$4bit -).linked(); -static auto paco = GPU::SPRT( - // This pic used to be 122px (file size) and every tool would except it - however the display would be corrupt. Try it!! - GPU::AreaI16({0, 100}, {120, 128}), - GPU::PagePositionClut({0, 0}, GPU::PageClut(Assets::PacoTIM.get_clut_x(), Assets::PacoTIM.get_clut_y())), - GPU::Color24::Blue() -).linked(); - -static const GPU::Color24 paco_color[] = { - GPU::Color24::Red(), GPU::Color24::Green(), GPU::Color24::Blue(), GPU::Color24::Yellow() -}; -static uint8_t color_idx = 0; +static object::Paco paco; static void setup() { Assets::load_for_main(); FontWriter::setup(); - timer.reset(); - paco_texpage.concat(paco); + paco.setup(); } static void update() { const auto end_pos = FontWriter::write({0, 32}, "Cody is cute\n&\na \x1b[8;0;0mBAAAAABY!!!"); FontWriter::write(end_pos, "\x1b[0;7;7mJaby was\nhere c:"); - if(timer.is_expired_for(325_ms)) { - static constexpr uint8_t last_idx = (sizeof(paco_color)/sizeof(paco_color[0])) - 1; - - color_idx = (color_idx == last_idx) ? 0 : color_idx + 1; - timer.reset(); - } + paco.update(); } static void render() { GPU::swap_buffers_vsync(1); - paco->color = paco_color[color_idx]; - GPU::render(paco_texpage); FontWriter::render(); + paco.render(); } void main() { diff --git a/examples/PoolBox/application/src/main_assets.cpp b/examples/PoolBox/application/src/main_assets.cpp index 241d59e1..405f4564 100644 --- a/examples/PoolBox/application/src/main_assets.cpp +++ b/examples/PoolBox/application/src/main_assets.cpp @@ -1,8 +1,11 @@ #include "assets.hpp" +#include "Objects/paco.hpp" #include #include namespace Assets { + using namespace object; + enum LBA { __jabyengine_start_lba_request __jabyengine_request_lba_for(FONT, "ASSETS/MAIN/FONT.BIN"), @@ -15,7 +18,7 @@ namespace Assets { void load_for_main() { static const CDFile Assets[] = { CDFileBuilder::simple_tim(LBA::FONT, FontTIM), - CDFileBuilder::simple_tim(LBA::PACO, PacoTIM), + CDFileBuilder::simple_tim(LBA::PACO, Paco::TIM), }; const auto buffer_cfg = CDFileProcessor::BufferConfiguration::new_default();