From 5486c03db467a58b8b368d83975c356dc4de4682 Mon Sep 17 00:00:00 2001 From: ravi688 Date: Wed, 4 Sep 2024 03:24:32 +0530 Subject: [PATCH] [SUTK] Container is now Activatable and Optimized input event handler objects --- sutk/include/sutk/Container.hpp | 3 ++- sutk/include/sutk/InputEventHandlerObject.hpp | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/sutk/include/sutk/Container.hpp b/sutk/include/sutk/Container.hpp index 9d0a34ee..af401a39 100644 --- a/sutk/include/sutk/Container.hpp +++ b/sutk/include/sutk/Container.hpp @@ -6,6 +6,7 @@ #include // for SUTK::IDebuggable class #include // for SUTK::AnchorRect class +#include // for SUTK::Activatable class namespace SUTK { @@ -24,7 +25,7 @@ namespace SUTK class RenderRectOutline; class RenderableContainer; - class Container : public UIDriverObject, public IDebuggable + class Container : public UIDriverObject, public IDebuggable, public Activatable { private: std::vector m_containers; diff --git a/sutk/include/sutk/InputEventHandlerObject.hpp b/sutk/include/sutk/InputEventHandlerObject.hpp index 6d174767..8d6a8705 100644 --- a/sutk/include/sutk/InputEventHandlerObject.hpp +++ b/sutk/include/sutk/InputEventHandlerObject.hpp @@ -59,7 +59,22 @@ namespace SUTK protected: TInputEventHandlerContainerObject(InputEventType& event) noexcept : TInputEventHandlerObject(event), m_container(NULL) { } - TInputEventHandlerContainerObject(InputEventType& event, Container* container) noexcept : TInputEventHandlerObject(event), m_container(container) { } + TInputEventHandlerContainerObject(InputEventType& event, Container* container) noexcept : TInputEventHandlerObject(event), m_container(container) + { + if(m_container != NULL) + { + // If the container has been deactivated then sleep the subscription, + // Or if the container has been activated then awake the subscription + // This saves CPU cycles + m_container->getOnActiveEvent().subscribe([this](Activatable* _, bool isActive) + { + if(isActive) + this->awake(); + else + this->sleep(); + }); + } + } bool isInside(Vec2Df point) const noexcept { return (m_container != NULL) ? m_container->containsGlobalCoords(point) : true;