1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/********************************************************************
*
*	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