#include "stdafx.h" #include "SGameSceneGroup.h" #include "SGameSceneManager.h" #include "SGameScenePlayer.h" #include "KViewport.h" using namespace rp; SGameSceneGroup::SGameSceneGroup( SGameSceneManager& sceneMgr , SGameScene* parent , const char* sceneName ) : SGameScene( sceneMgr, parent, sceneName ) { } SGameSceneGroup::~SGameSceneGroup() { } void SGameSceneGroup::onEnter() { std::for_each( mChildren.begin(), mChildren.end(), std::mem_fun( &SGameScene::onEnter ) ); } void SGameSceneGroup::onLeave() { std::for_each( mChildren.begin(), mChildren.end(), std::mem_fun( &SGameScene::onLeave ) ); } void SGameSceneGroup::onActivate() { std::for_each( mChildren.begin(), mChildren.end(), std::mem_fun( &SGameScene::onActivate ) ); } void SGameSceneGroup::onDeactivate() { std::for_each( mChildren.begin(), mChildren.end(), std::mem_fun( &SGameScene::onDeactivate ) ); } void SGameSceneGroup::onTick() { SGameScene::onTick(); updateVisibility(); children_t::iterator it = mChildren.begin(), end = mChildren.end(); for( ; it != end; ++it ) { SGameSceneIPtr Scene = *it; if( Scene->isActivated() ) Scene->onTick(); } } void SGameSceneGroup::onRender( KViewportObject* viewport ) { children_t::iterator it = mChildren.begin(), end = mChildren.end(); for( ; it != end; ++it ) { SGameSceneIPtr Scene = *it; if( Scene->isActivated() && Scene->isVisible() ) Scene->onRender( viewport ); } } void SGameSceneGroup::addChild( SGameScene* scene ) { mChildren.push_back( scene ); } void SGameSceneGroup::removeChild( SGameScene* scene ) { children_t::iterator found = std::find( mChildren.begin(), mChildren.end(), scene ); if( found != mChildren.end() ) { mChildren.erase( found ); } } SGameScene* SGameSceneGroup::getChildByName( const char* sceneName ) { children_t::iterator found = std::find_if( mChildren.begin(), mChildren.end(), SceneFinder( sceneName ) ); if( found != mChildren.end() ) { return *found; } return 0; } SGameScene* SGameSceneGroup::getChildByIndex( unsigned int index ) { if( index >= 0 && index < getSize() ) return mChildren.at( index ); return 0; } unsigned int SGameSceneGroup::getSize() const { return mChildren.size(); } bool SGameSceneGroup::isEmpty() const { return mChildren.empty(); }