diff --git a/libstarlight/source/starlight/Application.cpp b/libstarlight/source/starlight/Application.cpp index 1fe9a50..b595960 100644 --- a/libstarlight/source/starlight/Application.cpp +++ b/libstarlight/source/starlight/Application.cpp @@ -30,6 +30,7 @@ using starlight::Application; //////////////////// Application* Application::_currentApp = nullptr; +unsigned long long Application::ftime = 0; bool Application::Quit() { if (_currentApp == nullptr) return false; @@ -124,6 +125,8 @@ void Application::_mainLoop() { } // update step + ftime = osGetTime(); + InputManager::Update(); Update(); { // update loop for forms, guarded from snap-outs diff --git a/libstarlight/source/starlight/Application.h b/libstarlight/source/starlight/Application.h index 6a07719..78ebc4d 100644 --- a/libstarlight/source/starlight/Application.h +++ b/libstarlight/source/starlight/Application.h @@ -22,12 +22,14 @@ namespace starlight { //////////////////// private: static Application* _currentApp; + static unsigned long long ftime; public: static bool Quit(); static Config& GetConfig(const std::string& path); static std::string AppName(); static inline Application* Current() { return _currentApp; } + static inline unsigned long long GetTime() { return ftime; } ////////////////////// // INSTANCE MEMBERS // diff --git a/libstarlight/source/starlight/InputManager.h b/libstarlight/source/starlight/InputManager.h index ab901c5..1616025 100644 --- a/libstarlight/source/starlight/InputManager.h +++ b/libstarlight/source/starlight/InputManager.h @@ -43,6 +43,9 @@ enum class Keys : unsigned int { Right = DPadRight | CPadRight, ///< D-Pad Right or Circle Pad Right }; +inline constexpr unsigned int operator*(Keys k) { return static_cast(k); } +inline constexpr Keys operator|(Keys k1, Keys k2) { return static_cast(*k1 | *k2); } + namespace starlight { // forward declare this for OpenKeyboard namespace dialog { @@ -94,11 +97,11 @@ namespace starlight { static Vector2 CStick(); static bool Held(unsigned int mask); - static inline bool Held(Keys mask) { return Held(static_cast(mask)); } + static inline bool Held(Keys mask) { return Held(*mask); } static bool Pressed(unsigned int mask); - static inline bool Pressed(Keys mask) { return Pressed(static_cast(mask)); } + static inline bool Pressed(Keys mask) { return Pressed(*mask); } static bool Released(unsigned int mask); - static inline bool Released(Keys mask) { return Released(static_cast(mask)); } + static inline bool Released(Keys mask) { return Released(*mask); } static Vector2 TouchPos(); static Vector2 TouchDelta(); diff --git a/libstarlight/source/starlight/ThemeManager.cpp b/libstarlight/source/starlight/ThemeManager.cpp index e53c7ad..ed5ac47 100644 --- a/libstarlight/source/starlight/ThemeManager.cpp +++ b/libstarlight/source/starlight/ThemeManager.cpp @@ -179,6 +179,14 @@ void ThemeManager::End() { } +void ThemeManager::GC() { + constexpr const int keepCycles = 5; // how many gc sweeps a drawable gets to stay loaded without being used + // WIP + for (auto& d : drawables) { + if (++d.second.lastAccess > keepCycles) d.second.Unload(); + } +} + ThemeRef ThemeManager::GetAsset(const std::string& name) { auto const& itr = drawables.find(name); if (itr == drawables.end()) { @@ -195,10 +203,10 @@ ThemeRef ThemeManager::GetFont(const std::string& name) { void ThemeManager::Fulfill(ThemeRefContainer& ref) { string path = ResolveAssetPath(ref.name); - ref.ptr = LoadAsset(path); + ref.ptr = LoadAsset(path, ref); } -shared_ptr ThemeManager::LoadAsset(string& path) { +shared_ptr ThemeManager::LoadAsset(string& path, ThemeRefContainer& ref) { static shared_ptr nulldrw = make_shared(); string ext = FindExtension(path); @@ -225,9 +233,8 @@ shared_ptr ThemeManager::LoadAsset(string& path) { // else if (type == "") { } else if (type == "link") { string npath = ResolveAssetPath(j["path"]); - //return LoadAsset(npath); - return GetAsset(npath).GetShared(); // I guess this works; may need to be altered for asynchronity if I do that later - // (perhaps by--wait no, making it the same ThemeRefContainer would require a full rearchitecture of this part @.@) + ref.redir = const_cast*>(GetAsset(npath).cptr); // link containers directly + return nulldrw; // doesn't really matter what's inside, it'll never get used } return nulldrw; } diff --git a/libstarlight/source/starlight/ThemeManager.h b/libstarlight/source/starlight/ThemeManager.h index 8c0ca7d..9c18142 100644 --- a/libstarlight/source/starlight/ThemeManager.h +++ b/libstarlight/source/starlight/ThemeManager.h @@ -48,13 +48,15 @@ namespace starlight { static void Fulfill(gfx::ThemeRefContainer& ref); static void Fulfill(gfx::ThemeRefContainer& ref); - static std::shared_ptr LoadAsset(std::string& path); + static std::shared_ptr LoadAsset(std::string& path, gfx::ThemeRefContainer& ref); public: ThemeManager() = delete; // "static" class static void Init(); static void End(); + static void GC(); + static gfx::ThemeRef GetAsset(const std::string& name); static gfx::ThemeRef GetFont(const std::string& name); diff --git a/libstarlight/source/starlight/datatypes/Optional.h b/libstarlight/source/starlight/datatypes/Optional.h index 00c921c..b57e6d4 100644 --- a/libstarlight/source/starlight/datatypes/Optional.h +++ b/libstarlight/source/starlight/datatypes/Optional.h @@ -29,7 +29,7 @@ namespace starlight { getdef = o.getdef; } - Optional& operator=(const nullptr_t&) { p.reset(); } + Optional& operator=(const nullptr_t&) { p.reset(); return *this; } Optional& operator=(const T& o) { // assign by type's assignment operator if passed a "value" if (!p) p = std::make_unique(); *p = o; diff --git a/libstarlight/source/starlight/dialog/OSK.cpp b/libstarlight/source/starlight/dialog/OSK.cpp index e8234fa..881c485 100644 --- a/libstarlight/source/starlight/dialog/OSK.cpp +++ b/libstarlight/source/starlight/dialog/OSK.cpp @@ -37,6 +37,10 @@ namespace { return tc; } + inline bool ShiftScroll(Keys k) { + return InputManager::Pressed(k) || (InputManager::Held(Keys::L | Keys::R) && InputManager::Held(k)); + } + const constexpr float textHang = 4; } @@ -44,14 +48,13 @@ OSK::OSK(osk::InputHandler* handler) : Form(true), handler(handler) { priority = 1000; // probably don't want all that much displaying above the keyboard handler->parent = this; - auto cover = std::make_shared(touchScreen->rect, "decorations/osk.background"); + auto cover = touchScreen->AddNew(touchScreen->rect, "decorations/osk.background"); cover->blockTouch = true; - touchScreen->Add(cover); - // wip + // build keyboard - setContainer = std::make_shared(VRect::touchScreen); - touchScreen->Add(setContainer); + //setContainer = touchScreen->AddNew(VRect::touchScreen); // kept as a test case + setContainer = touchScreen->AddNew(VRect::touchScreen); // but this is much more efficient auto actSym = [this](Button& key){ this->handler->InputSymbol(key.label); @@ -74,18 +77,16 @@ OSK::OSK(osk::InputHandler* handler) : Form(true), handler(handler) { bpen = bpstart + Vector2(linestart[line] * bs.x, bs.y * line); } else { // lower - auto key = std::make_shared