From 343d386d7a8b4ddb044fee039370e529ab6ad302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Thu, 17 Jan 2019 20:11:42 -0300 Subject: [PATCH] UI Scene Node now uses scheduled update by default. --HG-- branch : dev --- include/eepp/scene/node.hpp | 7 +++++ include/eepp/scene/scenenode.hpp | 10 +++++++ include/eepp/ui/tools/textureatlaseditor.hpp | 3 +-- include/eepp/ui/uiitemcontainer.hpp | 2 ++ src/eepp/maps/mapeditor/uimap.cpp | 6 +++-- src/eepp/maps/mapeditor/uimap.hpp | 2 +- src/eepp/scene/node.cpp | 22 ++++++++++++++++ src/eepp/scene/scenenode.cpp | 26 ++++++++++++++++++- .../tools/textureatlastextureregioneditor.cpp | 5 +--- src/eepp/ui/uiloader.cpp | 5 +--- src/eepp/ui/uiprogressbar.cpp | 5 +--- src/eepp/ui/uiscenenode.cpp | 3 +++ src/eepp/ui/uispinbox.cpp | 5 +--- src/eepp/ui/uisprite.cpp | 6 +---- src/eepp/ui/uitextinput.cpp | 5 +--- src/eepp/ui/uitouchdragablewidget.cpp | 5 +--- src/eepp/ui/uiwindow.cpp | 6 +---- 17 files changed, 83 insertions(+), 40 deletions(-) diff --git a/include/eepp/scene/node.hpp b/include/eepp/scene/node.hpp index af1f0b2c1..ef50f75f7 100644 --- a/include/eepp/scene/node.hpp +++ b/include/eepp/scene/node.hpp @@ -29,6 +29,7 @@ using namespace EE::Scene; namespace EE { namespace Scene { enum NODE_FLAGS_VALUES { + NODE_FLAG_SCHEDULED_UPDATE = (1<<0), NODE_FLAG_VIEW_DIRTY = (1<<1), NODE_FLAG_POSITION_DIRTY = (1<<2), NODE_FLAG_POLYGON_DIRTY = (1<<3), @@ -469,6 +470,12 @@ class EE_API Node : public Transformable { SceneNode * findSceneNode(); void updateDrawInvalidator( bool force = false ); + + void subscribeScheduledUpdate(); + + void unsubscribeScheduledUpdate(); + + bool isSubscribedForScheduledUpdate(); }; }} diff --git a/include/eepp/scene/scenenode.hpp b/include/eepp/scene/scenenode.hpp index 10a4455bd..3507d147a 100644 --- a/include/eepp/scene/scenenode.hpp +++ b/include/eepp/scene/scenenode.hpp @@ -103,6 +103,14 @@ class EE_API SceneNode : public Node { void unsubscribeScheduledUpdate( Node * node ); bool isSubscribedForScheduledUpdate( Node * node ); + + void addMouseOverNode( Node * node ); + + void removeMouseOverNode( Node * node ); + + const bool& getUpdateAllChilds() const; + + void setUpdateAllChilds( const bool& updateAllChilds ); protected: friend class Node; typedef std::list CloseList; @@ -115,6 +123,7 @@ class EE_API SceneNode : public Node { bool mFrameBufferBound; bool mUseInvalidation; bool mUseGlobalCursors; + bool mUpdateAllChilds; Int32 mResizeCb; bool mDrawDebugData; bool mDrawBoxes; @@ -127,6 +136,7 @@ class EE_API SceneNode : public Node { Time mElapsed; std::list mScheduledUpdate; std::list mScheduledUpdateRemove; + std::list mMouseOverNodes; virtual void onSizeChange(); diff --git a/include/eepp/ui/tools/textureatlaseditor.hpp b/include/eepp/ui/tools/textureatlaseditor.hpp index c7a9c5171..3d009a322 100644 --- a/include/eepp/ui/tools/textureatlaseditor.hpp +++ b/include/eepp/ui/tools/textureatlaseditor.hpp @@ -40,11 +40,10 @@ class EE_API TextureAtlasEditor { UINode(), mTGEditor( TGEditor ) { - getSceneNode()->subscribeScheduledUpdate( this ); + subscribeScheduledUpdate(); } ~UITGEUpdater() { - getSceneNode()->unsubscribeScheduledUpdate( this ); } virtual void scheduledUpdate( const Time& ) { mTGEditor->update(); } diff --git a/include/eepp/ui/uiitemcontainer.hpp b/include/eepp/ui/uiitemcontainer.hpp index 6bec87f78..07820b133 100644 --- a/include/eepp/ui/uiitemcontainer.hpp +++ b/include/eepp/ui/uiitemcontainer.hpp @@ -2,6 +2,7 @@ #define EE_UITUIITEMCONTAINER_HPP #include +#include namespace EE { namespace UI { @@ -64,6 +65,7 @@ Node * UIItemContainer::overFind( const Vector2f& Point ) { if ( mWorldBounds.contains( Point ) && mPoly.pointInside( Point ) ) { writeNodeFlag( NODE_FLAG_MOUSEOVER_ME_OR_CHILD, 1 ); + mSceneNode->addMouseOverNode( this ); for ( Uint32 i = tParent->mVisibleFirst; i <= tParent->mVisibleLast; i++ ) { if ( NULL != tParent->mItems[i] ) { diff --git a/src/eepp/maps/mapeditor/uimap.cpp b/src/eepp/maps/mapeditor/uimap.cpp index 50f893eb0..89e0ec9cd 100644 --- a/src/eepp/maps/mapeditor/uimap.cpp +++ b/src/eepp/maps/mapeditor/uimap.cpp @@ -29,6 +29,8 @@ UIMap::UIMap( UITheme * Theme, TileMap * Map ) : mSelPoint( false ), mTileBox( NULL ) { + subscribeScheduledUpdate(); + if ( NULL == Map ) { mMap = eeNew( TileMap, () ); } @@ -99,8 +101,8 @@ void UIMap::updateScreenPos() { } } -void UIMap::update( const Time& time ) { - UIWindow::update( time ); +void UIMap::scheduledUpdate( const Time& time ) { + UIWindow::scheduledUpdate( time ); if ( NULL != mMap ) { invalidate(); diff --git a/src/eepp/maps/mapeditor/uimap.hpp b/src/eepp/maps/mapeditor/uimap.hpp index ecde358eb..d6d640a86 100644 --- a/src/eepp/maps/mapeditor/uimap.hpp +++ b/src/eepp/maps/mapeditor/uimap.hpp @@ -43,7 +43,7 @@ class EE_API UIMap : public UIWindow { virtual void draw(); - virtual void update( const Time& time ); + virtual void scheduledUpdate( const Time& time ); TileMap * Map() const; diff --git a/src/eepp/scene/node.cpp b/src/eepp/scene/node.cpp index 39d5dbfe0..bbe2b75dc 100644 --- a/src/eepp/scene/node.cpp +++ b/src/eepp/scene/node.cpp @@ -35,6 +35,9 @@ Node::~Node() { if ( NULL != mSceneNode && mSceneNode != this && NULL != mSceneNode->getActionManager() ) mSceneNode->getActionManager()->removeAllActionsFromTarget( this ); + if ( NULL != mSceneNode && ( mNodeFlags & NODE_FLAG_SCHEDULED_UPDATE ) ) + mSceneNode->unsubscribeScheduledUpdate( this ); + childDeleteAll(); if ( NULL != mParentCtrl ) @@ -211,6 +214,24 @@ void Node::updateDrawInvalidator( bool force ) { } } +void Node::subscribeScheduledUpdate() { + if ( NULL != mSceneNode ) { + mSceneNode->subscribeScheduledUpdate( this ); + writeNodeFlag( NODE_FLAG_SCHEDULED_UPDATE, 1 ); + } +} + +void Node::unsubscribeScheduledUpdate() { + if ( NULL != mSceneNode ) { + mSceneNode->unsubscribeScheduledUpdate( this ); + writeNodeFlag( NODE_FLAG_SCHEDULED_UPDATE, 0 ); + } +} + +bool Node::isSubscribedForScheduledUpdate() { + return 0 != ( mNodeFlags & NODE_FLAG_SCHEDULED_UPDATE ); +} + Node * Node::setParent( Node * parent ) { eeASSERT( NULL != parent ); @@ -755,6 +776,7 @@ Node * Node::overFind( const Vector2f& Point ) { if ( mWorldBounds.contains( Point ) && mPoly.pointInside( Point ) ) { writeNodeFlag( NODE_FLAG_MOUSEOVER_ME_OR_CHILD, 1 ); + mSceneNode->addMouseOverNode( this ); Node * ChildLoop = mChildLast; diff --git a/src/eepp/scene/scenenode.cpp b/src/eepp/scene/scenenode.cpp index da38a158c..d1d72b282 100644 --- a/src/eepp/scene/scenenode.cpp +++ b/src/eepp/scene/scenenode.cpp @@ -24,6 +24,7 @@ SceneNode::SceneNode( EE::Window::Window * window ) : mFrameBufferBound( false ), mUseInvalidation( false ), mUseGlobalCursors( true ), + mUpdateAllChilds( true ), mResizeCb( -1 ), mDrawDebugData( false ), mDrawBoxes( false ), @@ -143,7 +144,14 @@ void SceneNode::update( const Time& time ) { (*it)->scheduledUpdate( time ); } - Node::update( time ); + if ( mUpdateAllChilds ) { + Node::update( time ); + } else { + for ( auto it = mMouseOverNodes.begin(); it != mMouseOverNodes.end(); ++it ) + (*it)->writeNodeFlag( NODE_FLAG_MOUSEOVER_ME_OR_CHILD, 0 ); + } + + mMouseOverNodes.clear(); } void SceneNode::onSizeChange() { @@ -424,4 +432,20 @@ bool SceneNode::isSubscribedForScheduledUpdate( Node * node ) { return std::find( mScheduledUpdate.begin(), mScheduledUpdate.end(), node ) != mScheduledUpdate.end(); } +void SceneNode::addMouseOverNode( Node * node ) { + mMouseOverNodes.push_back( node ); +} + +void SceneNode::removeMouseOverNode(Node * node) { + mMouseOverNodes.remove( node ); +} + +const bool& SceneNode::getUpdateAllChilds() const { + return mUpdateAllChilds; +} + +void SceneNode::setUpdateAllChilds( const bool& updateAllChilds ) { + mUpdateAllChilds = updateAllChilds; +} + }} diff --git a/src/eepp/ui/tools/textureatlastextureregioneditor.cpp b/src/eepp/ui/tools/textureatlastextureregioneditor.cpp index c945e54f1..fe3376cc4 100644 --- a/src/eepp/ui/tools/textureatlastextureregioneditor.cpp +++ b/src/eepp/ui/tools/textureatlastextureregioneditor.cpp @@ -19,8 +19,7 @@ TextureAtlasTextureRegionEditor::TextureAtlasTextureRegionEditor( TextureAtlasEd return; } - if ( NULL != mSceneNode ) - mSceneNode->subscribeScheduledUpdate( this ); + subscribeScheduledUpdate(); mTheme = UIThemeManager::instance()->getDefaultTheme(); @@ -41,8 +40,6 @@ TextureAtlasTextureRegionEditor::TextureAtlasTextureRegionEditor( TextureAtlasEd } TextureAtlasTextureRegionEditor::~TextureAtlasTextureRegionEditor() { - if ( NULL != mSceneNode ) - mSceneNode->unsubscribeScheduledUpdate( this ); } void TextureAtlasTextureRegionEditor::draw() { diff --git a/src/eepp/ui/uiloader.cpp b/src/eepp/ui/uiloader.cpp index 1798502c4..c5e5ba52f 100644 --- a/src/eepp/ui/uiloader.cpp +++ b/src/eepp/ui/uiloader.cpp @@ -22,8 +22,7 @@ UILoader::UILoader() : mOp(1), mIndeterminate(true) { - if ( NULL != mSceneNode ) - mSceneNode->subscribeScheduledUpdate( this ); + subscribeScheduledUpdate(); mArc.setFillMode( DRAW_FILL ); mCircle.setFillMode( DRAW_FILL ); @@ -31,8 +30,6 @@ UILoader::UILoader() : } UILoader::~UILoader() { - if ( NULL != mSceneNode ) - mSceneNode->unsubscribeScheduledUpdate( this ); } Uint32 UILoader::getType() const { diff --git a/src/eepp/ui/uiprogressbar.cpp b/src/eepp/ui/uiprogressbar.cpp index be9382363..2e7dda385 100644 --- a/src/eepp/ui/uiprogressbar.cpp +++ b/src/eepp/ui/uiprogressbar.cpp @@ -16,8 +16,7 @@ UIProgressBar::UIProgressBar() : mTotalSteps( 100.f ), mFillerSkin( NULL ) { - if ( NULL != mSceneNode ) - mSceneNode->subscribeScheduledUpdate( this ); + subscribeScheduledUpdate(); setFlags( UI_AUTO_PADDING | UI_AUTO_SIZE ); @@ -32,8 +31,6 @@ UIProgressBar::UIProgressBar() : } UIProgressBar::~UIProgressBar() { - if ( NULL != mSceneNode ) - mSceneNode->unsubscribeScheduledUpdate( this ); } Uint32 UIProgressBar::getType() const { diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index 50759882c..74655dbce 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -18,6 +18,9 @@ UISceneNode::UISceneNode( EE::Window::Window * window ) : SceneNode( window ), mIsLoading( false ) { + // Update only UI elements that requires it. + setUpdateAllChilds( false ); + mNodeFlags |= NODE_FLAG_UISCENENODE | NODE_FLAG_OVER_FIND_ALLOWED; setEventDispatcher( UIEventDispatcher::New( this ) ); diff --git a/src/eepp/ui/uispinbox.cpp b/src/eepp/ui/uispinbox.cpp index 7c7d6cf75..1c4a091a5 100644 --- a/src/eepp/ui/uispinbox.cpp +++ b/src/eepp/ui/uispinbox.cpp @@ -16,8 +16,7 @@ UISpinBox::UISpinBox() : mValue( 0 ), mClickStep( 1.f ) { - if ( NULL != mSceneNode ) - mSceneNode->subscribeScheduledUpdate( this ); + subscribeScheduledUpdate(); mInput = UITextInput::NewWithTag( "spinbox::input" ); mInput->setVisible( true ); @@ -46,8 +45,6 @@ UISpinBox::UISpinBox() : } UISpinBox::~UISpinBox() { - if ( NULL != mSceneNode ) - mSceneNode->unsubscribeScheduledUpdate( this ); } Uint32 UISpinBox::getType() const { diff --git a/src/eepp/ui/uisprite.cpp b/src/eepp/ui/uisprite.cpp index 9d3fe3157..64a02a9ab 100644 --- a/src/eepp/ui/uisprite.cpp +++ b/src/eepp/ui/uisprite.cpp @@ -17,14 +17,10 @@ UISprite::UISprite() : mAlignOffset(0,0), mTextureRegionLast(NULL) { - if ( NULL != mSceneNode ) - mSceneNode->subscribeScheduledUpdate( this ); + subscribeScheduledUpdate(); } UISprite::~UISprite() { - if ( NULL != mSceneNode ) - mSceneNode->unsubscribeScheduledUpdate( this ); - if ( deallocSprite() ) eeSAFE_DELETE( mSprite ); } diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index d061358e3..37f8f28ad 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -23,8 +23,7 @@ UITextInput::UITextInput( const std::string& tag ) : mAllowEditing( true ), mShowingWait( true ) { - if ( NULL != mSceneNode ) - mSceneNode->subscribeScheduledUpdate( this ); + subscribeScheduledUpdate(); setFlags( UI_AUTO_PADDING | UI_AUTO_SIZE | UI_TEXT_SELECTION_ENABLED ); clipEnable(); @@ -43,8 +42,6 @@ UITextInput::UITextInput() : {} UITextInput::~UITextInput() { - if ( NULL != mSceneNode ) - mSceneNode->unsubscribeScheduledUpdate( this ); } Uint32 UITextInput::getType() const { diff --git a/src/eepp/ui/uitouchdragablewidget.cpp b/src/eepp/ui/uitouchdragablewidget.cpp index 3dc692b2f..57368d794 100644 --- a/src/eepp/ui/uitouchdragablewidget.cpp +++ b/src/eepp/ui/uitouchdragablewidget.cpp @@ -12,8 +12,7 @@ UITouchDragableWidget::UITouchDragableWidget( const std::string& tag ) : UIWidget( tag ), mTouchDragDeceleration( 5.f, 5.f ) { - if ( NULL != mSceneNode ) - mSceneNode->subscribeScheduledUpdate( this ); + subscribeScheduledUpdate(); } UITouchDragableWidget::UITouchDragableWidget() : @@ -21,8 +20,6 @@ UITouchDragableWidget::UITouchDragableWidget() : {} UITouchDragableWidget::~UITouchDragableWidget() { - if ( NULL != mSceneNode ) - mSceneNode->unsubscribeScheduledUpdate( this ); } Uint32 UITouchDragableWidget::getType() const { diff --git a/src/eepp/ui/uiwindow.cpp b/src/eepp/ui/uiwindow.cpp index 2195d7cbb..eeb0e9001 100644 --- a/src/eepp/ui/uiwindow.cpp +++ b/src/eepp/ui/uiwindow.cpp @@ -44,8 +44,7 @@ UIWindow::UIWindow( UIWindow::WindowBaseContainerType type, const StyleConfig& w mResizeType( RESIZE_NONE ), mFrameBufferBound( false ) { - if ( NULL != mSceneNode ) - mSceneNode->subscribeScheduledUpdate( this ); + subscribeScheduledUpdate(); mNodeFlags |= NODE_FLAG_WINDOW | NODE_FLAG_VIEW_DIRTY; @@ -83,9 +82,6 @@ UIWindow::UIWindow( UIWindow::WindowBaseContainerType type, const StyleConfig& w } UIWindow::~UIWindow() { - if ( NULL != mSceneNode ) - mSceneNode->unsubscribeScheduledUpdate( this ); - if ( NULL != getUISceneNode() && !SceneManager::instance()->isShootingDown() ) { getUISceneNode()->windowRemove( this );