Skylicht Engine
Loading...
Searching...
No Matches
CContainerObject.h
1/*
2!@
3MIT License
4
5Copyright (c) 2019 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "CGameObject.h"
28
29namespace Skylicht
30{
38 class SKYLICHT_API CContainerObject : public CGameObject
39 {
40 protected:
41 ArrayGameObject m_childs;
42 ArrayGameObject m_add;
43 ArrayGameObject m_remove;
44
45 core::array<CGameObject*> m_arrayChildObjects;
46
49
50 bool m_updateRemoveAdd;
51 bool m_updateListChild;
52
53 int m_lastGenerateID;
54
55 public:
56 CContainerObject(CGameObject* parent, CZone* zone);
57
58 virtual ~CContainerObject();
59
60 CGameObject* createEmptyObject();
61
62 CContainerObject* createContainerObject();
63
64 CGameObject* createObject(CObjectSerializable* data, bool generateNewID);
65
66 void updateAddRemoveObject(bool force = false);
67
68 inline void notifyUpdateListChild()
69 {
70 m_updateListChild = true;
71 }
72
73 int getNumberObjects();
74
75 void updateIndexSearchObject();
76
77 CGameObject* getChildObjectBefore(CGameObject* object);
78
79 void bringToNext(CGameObject* object, CGameObject* target, bool behind);
80
81 void bringToChild(CGameObject* object);
82
83 void sortChildsByTemplateOrder(std::vector<std::string>& order);
84
85 virtual void setTemplateChanged(bool b);
86
87 virtual CGameObject* searchObject(const wchar_t* objectName);
88
89 virtual CGameObject* searchObjectInChild(const wchar_t* objectName);
90
91 virtual CGameObject* searchObjectByID(const char* id);
92
93 virtual CGameObject* searchObjectInChildByID(const char* id);
94
95 virtual CGameObject* searchObjectInChildByTemplateObjId(const char* id);
96
97 virtual u32 searchObjectByCullingLayer(ArrayGameObject& result, u32 mask);
98
99 virtual void setCullingLayerForChild(u32 mask);
100
101 virtual void setCullingOnOffForChild(u32 value, bool on);
102
103 virtual CEntity* searchEntityByID(const char* id);
104
105 virtual CEntity* searchEntityInChildByID(const char* id);
106
107 virtual bool testConflictName(const wchar_t* objectName);
108
109 std::string generateObjectName(const char* objTemplate);
110
111 void registerObjectInSearchList(CGameObject* obj);
112
113 void removeObject(CGameObject* pObj);
114
115 void addChild(CGameObject* p);
116
117 inline ArrayGameObject* getChilds()
118 {
119 return &m_childs;
120 }
121
122 void removeAllObject(bool force = false);
123
124 template<typename T>
125 void getListObjectType(ArrayGameObject& listObjs, T type);
126
127 template<typename T>
128 std::vector<T*> getComponentsInChild(bool addThis);
129
130 core::array<CGameObject*>& getArrayChilds(bool addThis);
131
132 bool haveChild(CGameObject* gameObject);
133
134 DECLARE_GETTYPENAME(CContainerObject)
135 };
136
137 template<typename T>
138 std::vector<T*> CContainerObject::getComponentsInChild(bool addThis)
139 {
140 std::vector<T*> result;
141 std::queue<CGameObject*> queueObjs;
142
143 if (addThis == true)
144 queueObjs.push(this);
145 else
146 {
147 for (CGameObject*& obj : m_childs)
148 queueObjs.push(obj);
149 }
150
151 while (queueObjs.size() != 0)
152 {
153 CGameObject* obj = queueObjs.front();
154 queueObjs.pop();
155
156 T* comp = obj->getComponent<T>();
157 if (comp != NULL)
158 result.push_back(comp);
159
160 CContainerObject* container = dynamic_cast<CContainerObject*>(obj);
161 if (container != NULL)
162 {
163 for (CGameObject*& child : container->m_childs)
164 queueObjs.push(child);
165 }
166 }
167
168 return result;
169 }
170}
It's an object class used to manage multiple objects.
Definition CContainerObject.h:39
This is the object class that describes an entity.
Definition CEntity.h:58
This object class stores information for a GameObject.
Definition CGameObject.h:52
Definition CObjectSerializable.h:36
It's the primary container object for the CScene; all CGameObject have a CZone as their root parent.
Definition CZone.h:37
Self reallocating template array (like stl vector) with additional features.
Definition irrArray.h:23
map template for associative arrays using a red-black tree
Definition irrMap.h:19
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58