/********************************************************************
*
* File: fsIScene.h
*
* Purpose: Interface for a scene - container for retained
* mode rendering i.e. scene sprites and text scene
* sprites
*
*********************************************************************/
#ifndef fsIScenehdr
#define fsIScenehdr
#include "fsINode.h"
#include "src/fsCEntity.h"
class fsIScene : public fsCEntity
{
public:
static fsIScene* create(const fsStr& pSceneName);
template <typename TInterface>
std::vector<fsCEntity*> entitiesWithComponentsOfFamilyType() const;
template <typename TInterface>
fsCEntity* firstEntityWithComponentsOfFamilyType() const;
fsCEntity* entityNamed(const fsStr& pName) const;
fsBool emptyGet() const;
void link(fsINode* pChild);
virtual ~fsIScene();<--- Destructor in derived class
protected:
fsIScene(const fsStr& pSceneName);
virtual void linkDo(fsINode* const pChild)
{
}
private:
};
template <typename TInterface>
std::vector<fsCEntity*> fsIScene::entitiesWithComponentsOfFamilyType() const
{
std::vector<fsCEntity*> ents;
for (fsINode* child : mChildren)
{
if (fsCEntity* childEnt = dynamic_cast<fsCEntity*>(child))
{
auto ret = childEnt->childEntitiesWithComponentsOfFamilyType<TInterface>();
ents.insert(ents.end(), ret.begin(), ret.end());
}
}
return ents;
}
template <typename TInterface>
fsCEntity* fsIScene::firstEntityWithComponentsOfFamilyType() const
{
for (fsINode* child : mChildren)
{
if (fsCEntity* childEnt = dynamic_cast<fsCEntity*>(child))
{
if (auto matchEnt = childEnt->firstChildEntityWithComponentsOfFamilyType<TInterface>())
{
return matchEnt;
}
}
}
return nullptr;
}
#endif