diff --git a/include/rd7.hpp b/include/rd7.hpp index 3bc3159..21acc21 100644 --- a/include/rd7.hpp +++ b/include/rd7.hpp @@ -3,4 +3,5 @@ #include #include #include -#include \ No newline at end of file +#include +#include \ No newline at end of file diff --git a/include/renderd7/Ovl.hpp b/include/renderd7/Ovl.hpp index 6078d07..e7a5f7c 100644 --- a/include/renderd7/Ovl.hpp +++ b/include/renderd7/Ovl.hpp @@ -24,7 +24,4 @@ private: /// @brief Add an Overlay to the Screen /// @param scene Overlay to push to Screen void AddOvl(std::unique_ptr scene); -/// @brief Add an Overlay to the Toast Stack -/// @param scene Overlay to push to Toast Stack -void AddToast(std::unique_ptr scene); } // namespace RenderD7 \ No newline at end of file diff --git a/include/renderd7/Toast.hpp b/include/renderd7/Toast.hpp deleted file mode 100644 index 7130d18..0000000 --- a/include/renderd7/Toast.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include - -namespace RenderD7 { -/// @brief Toast Class -class Toast : public RenderD7::Ovl { -public: - /// @brief Constructor - /// @param head Displayed String in Head - /// @param msg Displayed String in Message Box - Toast(std::string head, std::string msg); - /// @brief Override for Draw - void Draw(void) const override; - /// @brief Override for Logic - void Logic() override; - -private: - /// @param head The Header Text - /// @param nsg The Message-Box Text - std::string head, msg; - /// @param msgposy Position Y of The Toast - int msgposy = 240; - /// @param delay Delay of the Toast - int delay = 0; -}; -} // namespace RenderD7 \ No newline at end of file diff --git a/include/renderd7/ToastsV2.hpp b/include/renderd7/ToastsV2.hpp new file mode 100644 index 0000000..5158a79 --- /dev/null +++ b/include/renderd7/ToastsV2.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include + +namespace RenderD7 { + struct Message { + Message(std::string t, std::string m) { + title = t; + message = m; + animationframe = 0; + } + + std::string title; + std::string message; + int animationframe; + }; + + void ProcessMessages(); + void PushMessage(const Message& msg); + // Config + void SetIdleStartFrame(int frame); + void SetTotalAnimationFrames(int total_frames); + void SetFadeOutStartFrame(int frame); +} \ No newline at end of file diff --git a/include/renderd7/renderd7.hpp b/include/renderd7/renderd7.hpp index 0186122..e33efb8 100644 --- a/include/renderd7/renderd7.hpp +++ b/include/renderd7/renderd7.hpp @@ -40,7 +40,6 @@ #include #include #include -#include #include #include #include @@ -52,7 +51,8 @@ #define RENDERD7VSTRING "0.9.5" #define CHANGELOG \ - "0.9.5: Remove Npi Intro and NVID Api\n" \ + "0.9.5: Remove Npi Intro and NVID Api\nReplace Toasts System with " \ + "ToastsV2\n aka MessageHandler\nLots of Optimisations\n" \ "0.9.4: Implement new Security System\n To prevent from crashes\nImplement " \ "Functiontrace for better\nTiming Tests\nImplement MemAlloc Tracker (only " \ "size)\nAdd some new Overlays (not functional yet)\nComplete Rewrite of " \ @@ -225,23 +225,6 @@ public: /// @brief Show Up the RenderD7-Settings Menu void LoadSettings(); -/// @brief DspNotFound Error Toast (Deprectated) -class DSP_NF : public RenderD7::Ovl { -public: - /// @brief Constructor - DSP_NF(); - /// @brief Override for Draw - void Draw(void) const override; - /// @brief Override for Logic - void Logic() override; - -private: - /// @param msgposy Y Position of Toast - int msgposy = 240; - /// @param delay Delay of Toast - int delay = 0; -}; - /// @brief Get A Rendom Int /// @param b From /// @param e To diff --git a/rd7tf/source/main.cpp b/rd7tf/source/main.cpp index 6069968..2c0a9f5 100644 --- a/rd7tf/source/main.cpp +++ b/rd7tf/source/main.cpp @@ -10,11 +10,15 @@ int main() { RenderD7::Ftrace::End("app", f2s(RenderD7::LoadSettings)); sound snd("romfs:/thesound.wav", 0); snd.play(); + RenderD7::PushMessage(RenderD7::Message(std::string("RenderD7 ") + RENDERD7VSTRING, "Testing the ToastsV2")); RenderD7::Ftrace::End("app", "app_init"); while (RenderD7::MainLoop()) { RenderD7::Ftrace::Beg("app", "app_mainloop"); if (d7_hDown & KEY_START) RenderD7::ExitApp(); + if(d7_hDown & KEY_A) { + RenderD7::PushMessage(RenderD7::Message(std::string("RenderD7 ") + RENDERD7VSTRING, "Testing the ToastsV2\nPressed A")); + } RenderD7::FrameEnd(); RenderD7::Ftrace::End("app", "app_mainloop"); } diff --git a/source/BitmapPrinter.cpp b/source/BitmapPrinter.cpp index ef22e14..e8597a9 100644 --- a/source/BitmapPrinter.cpp +++ b/source/BitmapPrinter.cpp @@ -1,8 +1,8 @@ #include -#include -#include +#include #include + extern bool shouldbe_disabled; extern std::string csvpc; @@ -22,7 +22,7 @@ bool RenderD7::BitmapPrinter::DecodeFile(std::string file) { unsigned error = bitmap.read(file.c_str()); if (error) { - RenderD7::AddOvl(std::make_unique( + RenderD7::PushMessage(RenderD7::Message( "BitmapPrinter", "Error Code: " + std::to_string(error))); return false; } @@ -34,7 +34,7 @@ void RenderD7::BitmapPrinter::DrawPixel(int x, int y, u8 b, u8 g, u8 r, u8 a) { unsigned error = bitmap.set_pixel(x, bitmap.bmp_info_header.height - y, b, g, r, a); if (error) { - RenderD7::AddOvl(std::make_unique( + RenderD7::PushMessage(RenderD7::Message( "BitmapPrinter->Pixel", "Error Code: " + std::to_string(error))); } } @@ -43,7 +43,7 @@ void RenderD7::BitmapPrinter::DrawRect(int x, int y, int w, int h, u8 line_w, unsigned error = bitmap.draw_rectangle( x, bitmap.bmp_info_header.height - y - h, w, h, b, g, r, a, line_w); if (error) { - RenderD7::AddOvl(std::make_unique( + RenderD7::PushMessage(RenderD7::Message( "BitmapPrinter->Rect", "Error Code: " + std::to_string(error))); } } @@ -53,7 +53,7 @@ void RenderD7::BitmapPrinter::DrawRectFilled(int x, int y, int w, int h, u8 b, unsigned error = bitmap.fill_region(x, bitmap.bmp_info_header.height - h - y, w, h, b, g, r, a); if (error) { - RenderD7::AddOvl(std::make_unique( + RenderD7::PushMessage(RenderD7::Message( "BitmapPrinter->RectF", "Error Code: " + std::to_string(error))); } } @@ -236,8 +236,8 @@ void RenderD7::BitmapPrinter::Benchmark() { std::string outname = csvpc + "/benchmark_" + RenderD7::GetTimeStr() + ".png"; this->SavePng(outname); - RenderD7::AddOvl(std::make_unique( - "Benchmark", "Saved to: \n" + outname)); + RenderD7::PushMessage( + RenderD7::Message("Benchmark", "Saved to: \n" + outname)); benchmark = false; } uint64_t currentTime = svcGetSystemTick(); diff --git a/source/FileSystem.cpp b/source/FileSystem.cpp index bc4db98..38b24d2 100644 --- a/source/FileSystem.cpp +++ b/source/FileSystem.cpp @@ -3,8 +3,6 @@ #include // Debugging #include -#include -#include #include #include diff --git a/source/Image.cpp b/source/Image.cpp index c8bd19d..f59dc83 100644 --- a/source/Image.cpp +++ b/source/Image.cpp @@ -1,7 +1,5 @@ #include -#include -#include - +#include #include extern bool usedbgmsg; @@ -278,8 +276,8 @@ void RenderD7::Image::LoadFromBitmap(BMP bitmap) { if (error) { std::cout << "BMP decoding error " << error << std::endl; - RenderD7::AddOvl(std::make_unique( - "Bmp - Error", "Code: " + std::to_string(error))); + RenderD7::PushMessage( + RenderD7::Message("Bmp - Error", "Code: " + std::to_string(error))); } } diff --git a/source/Toast.cpp b/source/Toast.cpp deleted file mode 100644 index db29c01..0000000 --- a/source/Toast.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include - -RenderD7::Toast::Toast(std::string head, std::string msg) { - this->head = head; - this->msg = msg; -} - -void RenderD7::Toast::Draw(void) const { - RenderD7::OnScreen(Top); - RenderD7::Draw::Rect(0, msgposy, 400, 70, RenderD7::Color::Hex("#111111")); - RenderD7::Draw::Rect(0, msgposy, 400, 25, RenderD7::Color::Hex("#222222")); - RenderD7::Draw::Text(2, msgposy + 3, 0.7f, RenderD7::Color::Hex("#ffffff"), - head); - RenderD7::Draw::Text(2, msgposy + 30, 0.6f, RenderD7::Color::Hex("#ffffff"), - msg); -} - -void RenderD7::Toast::Logic() { - this->delay++ /*=1*(int)RenderD7::GetDeltaTime()*/; - if (msgposy > 170 && delay < 2 * 60) - msgposy-- /*=(int)RenderD7::GetDeltaTime()*/; - - if (delay >= 5 * 60) { - msgposy++ /*=(int)RenderD7::GetDeltaTime*/; - if (msgposy > 400) - this->Kill(); - } -} \ No newline at end of file diff --git a/source/ToastsV2.cpp b/source/ToastsV2.cpp new file mode 100644 index 0000000..9fccf11 --- /dev/null +++ b/source/ToastsV2.cpp @@ -0,0 +1,93 @@ +#include +#include +#include +#include + +#include +#include +#include + +extern bool rd7_debugging; + +std::vector> msg_lst; +int fade_outs = 200; // Start of fadeout +int idles = 60; // start of Idle +int anim_len = 300; // Full Length of Animation + +std::pair MakePos(int frame, int entry) { + float fol = anim_len - fade_outs; + if (frame > fade_outs) + return std::make_pair(5, 240 - ((entry + 1) * 55) - 5 + + (float)((frame - fade_outs) / fol) * -20); + if (frame > idles) + return std::make_pair(5, 240 - ((entry + 1) * 55) - 5); + return std::make_pair(-150 + ((float)(frame / (float)idles) * 155), + 240 - ((entry + 1) * 55) - 5); +} + +namespace RenderD7 { +float GetDeltaTime(); // Extern from renderd7.cpp + +void ProcessMessages() { + // Draw in ovl mode + RenderD7::OnScreen(Top); + float fol = anim_len - fade_outs; + std::reverse(msg_lst.begin(), msg_lst.end()); + for (size_t i = 0; i < msg_lst.size(); i++) { + std::pair pos = MakePos(msg_lst[i]->animationframe, i); + if ((pos.second + 150) < 0) { + // Dont Render Out of Screen + // And as thay aren't relevant anymore + // Thay get deleted! + msg_lst.erase(msg_lst.begin() + i); + } else { + + int new_alpha = 200; + if (msg_lst[i]->animationframe > fade_outs) { + new_alpha = + 200 - (float(msg_lst[i]->animationframe - fade_outs) / fol) * 200; + } + u32 txtcol = RenderD7::Color::Hex("#ffffff", new_alpha); + RenderD7::Draw::Rect(pos.first, pos.second, 150, 50, + RenderD7::Color::Hex("#333333", new_alpha)); + RenderD7::Draw::Text(pos.first + 5, pos.second + 1, 0.4f, txtcol, + msg_lst[i]->title); + RenderD7::Draw::Text(pos.first + 5, pos.second + 17, 0.4f, txtcol, + msg_lst[i]->message); + if (rd7_debugging) + RenderD7::Draw::Text(pos.first + 160, pos.second + 1, 0.5f, + RenderD7::Color::Hex("#000000"), + std::to_string(msg_lst[i]->animationframe)); + // Why Frameadd? because Message uses int as frame and + // It seems that lower 0.5 will be rounded to 0 + // Why not replace int with float ? + // cause of buggy positions (seen in Flappy Bird 3ds for example) + float frameadd = 60.f * RenderD7::GetDeltaTime(); + // 60fps animation * delta to not slowdown + // Oh and fix for Startup lol + // Todo: Only do this on AppStart + if (msg_lst[i]->animationframe == 0) { + msg_lst[i]->animationframe += 1; + } else { + msg_lst[i]->animationframe += (frameadd < 1.f ? 1.f : frameadd); + } + if (msg_lst[i]->animationframe > anim_len) { + msg_lst.erase(msg_lst.begin() + i); + } + } + } + // ReReverse ?? lol + // Cause otherwise the Toasts will swap + std::reverse(msg_lst.begin(), msg_lst.end()); +} + +void PushMessage(const Message &msg) { + msg_lst.push_back(std::make_shared(msg)); +} + +void SetIdleStartFrame(int frame) { idles = frame; } + +void SetTotalAnimationFrames(int total_frames) { anim_len = total_frames; } + +void SetFadeOutStartFrame(int frame) { fade_outs = frame; } +} // namespace RenderD7 \ No newline at end of file diff --git a/source/renderd7.cpp b/source/renderd7.cpp index 24ea779..4ef422e 100644 --- a/source/renderd7.cpp +++ b/source/renderd7.cpp @@ -2,10 +2,12 @@ #include #include #include +#include #define D7_NOTHING 0x00000000 #define CFGVER "6" +// Lot of internal stuff here bool isndspinit = false; bool running = true; std::stack> RenderD7::Scene::scenes; @@ -13,7 +15,6 @@ std::unique_ptr tmpFadeS; /// @brief Supports Multiple Overlays std::vector> overlays; /// @brief Displays Overlays step by step from first 2 last -std::vector> toast_overlays; std::string dspststus = "Not Initialisized!"; int cobj___; @@ -79,6 +80,8 @@ u64 delta_time; u64 last_tm; float dtm; +bool rd7_debugging = false; + // Lets define them to prevent from red lines in vscode lol #ifndef V_TIME #define V_TIME "0" @@ -203,7 +206,7 @@ void RenderD7::Init::NdspFirm() { dspststus = "Initialisized success!"; } else { dspststus = "Not found: dspfirm.cdc"; - RenderD7::AddToast(std::make_unique()); + RenderD7::PushMessage(RenderD7::Message("RenderD7", "dspfirm.cdc not found!\nUnable to play sounds!")); } } @@ -743,40 +746,7 @@ void RenderD7::DrawMetrikOvl() { RenderD7::Draw::Text(0, infoy, mt_txtSize, mt_txtcolor, info); } -RenderD7::DSP_NF::DSP_NF() {} - -void RenderD7::DSP_NF::Draw(void) const { - RenderD7::OnScreen(Top); - RenderD7::Draw::Rect(0, msgposy, 400, 70, RenderD7::Color::Hex("#111111")); - RenderD7::Draw::Rect(0, msgposy, 400, 25, RenderD7::Color::Hex("#222222")); - RenderD7::Draw::Text(2, msgposy + 3, 0.7f, RenderD7::Color::Hex("#ffffff"), - "RenderD7: Warning!"); - RenderD7::Draw::Text(2, msgposy + 30, 0.6f, RenderD7::Color::Hex("#ffffff"), - "You can't use Sound effects because the " - "file\n<> was not found!"); -} - -void RenderD7::DSP_NF::Logic() { - this->delay++ /*=(int)RenderD7::GetDeltaTime()*/; - if (msgposy > 170 && delay < 5 * 60) - msgposy-- /*=(int)RenderD7::GetDeltaTime()*/; - - if (delay >= 5 * 60) { - msgposy++ /*=(int)RenderD7::GetDeltaTime*/; - if (msgposy > 400) - this->Kill(); - } -} - void OvlHandler() { - for (size_t i = 0; i < toast_overlays.size(); i++) { - if (toast_overlays[i]->IsKilled()) - toast_overlays.erase(toast_overlays.begin() + i); - } - if ((int)toast_overlays.size() > 0) { - toast_overlays[0]->Draw(); - toast_overlays[0]->Logic(); - } for (size_t i = 0; i < overlays.size(); i++) { overlays[i]->Draw(); overlays[i]->Logic(); @@ -787,9 +757,9 @@ void OvlHandler() { void RenderD7::FrameEnd() { C3D_FrameBegin(2); - if (metrikd) + //if (metrikd) RenderD7::DrawMetrikOvl(); - + RenderD7::ProcessMessages(); RenderD7::Ftrace::Beg("rd7oh", f2s(OvlHandler)); OvlHandler(); RenderD7::Ftrace::End("rd7oh", f2s(OvlHandler)); @@ -834,6 +804,8 @@ void RenderD7::RSettings::Draw(void) const { RenderD7::Draw::Text( 0, 70, 0.7f, DSEVENBLACK, "Current: " + std::to_string(RenderD7::Memory::GetCurrent()) + "b"); + RenderD7::Draw::Text(0, 90, 0.7f, DSEVENBLACK, + "Delta: " + std::to_string(RenderD7::GetDeltaTime())); RenderD7::OnScreen(Bottom); std::string verc = "Config Version: "; verc += CFGVER; @@ -1074,10 +1046,6 @@ void RenderD7::AddOvl(std::unique_ptr overlay) { overlays.push_back(std::move(overlay)); } -void RenderD7::AddToast(std::unique_ptr overlay) { - toast_overlays.push_back(std::move(overlay)); -} - void RenderD7::FadeOut() { if (!waitFade) { fadein = true;