增加ComponentManager::GetComponents(..SceneNode)
This commit is contained in:
parent
6d211b3840
commit
ee5d633596
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include<hgl/type/DataType.h>
|
#include<hgl/type/DataType.h>
|
||||||
#include<hgl/type/SortedSet.h>
|
#include<hgl/type/SortedSet.h>
|
||||||
|
#include<hgl/type/List.h>
|
||||||
|
|
||||||
namespace hgl::graph
|
namespace hgl::graph
|
||||||
{
|
{
|
||||||
@ -32,6 +33,12 @@ namespace hgl::graph
|
|||||||
|
|
||||||
virtual ~Component()=default;
|
virtual ~Component()=default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
SceneNode * GetOwnerNode()const{return OwnerNode;}
|
||||||
|
ComponentManager * GetManager ()const{return Manager;}
|
||||||
|
ComponentData * GetData ()const{return Data;}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual void Update(const double delta_time)=0;
|
virtual void Update(const double delta_time)=0;
|
||||||
@ -42,9 +49,11 @@ namespace hgl::graph
|
|||||||
virtual void OnFocusGained(){} ///<焦点获得事件
|
virtual void OnFocusGained(){} ///<焦点获得事件
|
||||||
};//class Component
|
};//class Component
|
||||||
|
|
||||||
|
using ComponentSet=SortedSet<Component *>;
|
||||||
|
|
||||||
class ComponentManager
|
class ComponentManager
|
||||||
{
|
{
|
||||||
SortedSet<Component *> ComponentSet;
|
ComponentSet component_set;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -52,26 +61,24 @@ namespace hgl::graph
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual size_t ComponentHashCode()const=0;
|
virtual size_t ComponentHashCode()const=0;
|
||||||
|
|
||||||
virtual Component * CreateComponent(SceneNode *,ComponentData *)=0;
|
virtual Component * CreateComponent(SceneNode *,ComponentData *)=0;
|
||||||
|
|
||||||
int GetComponentCount()const{return ComponentSet.GetCount();}
|
int GetComponentCount()const{return component_set.GetCount();}
|
||||||
|
|
||||||
virtual void UpdateComponents(const double delta_time)
|
ComponentSet & GetComponents(){return component_set;}
|
||||||
{
|
|
||||||
Component **cc=ComponentSet.GetData();
|
|
||||||
|
|
||||||
for(int i=0;i<ComponentSet.GetCount();i++)
|
int GetComponents(List<Component *> &comp_list,SceneNode *);
|
||||||
cc[i]->Update(delta_time);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void JoinComponent(Component *c){if(!c)return;ComponentSet.Add(c);}
|
virtual void UpdateComponents(const double delta_time);
|
||||||
virtual void UnjonComponent(Component *c){if(!c)return;ComponentSet.Delete(c);}
|
|
||||||
|
virtual void JoinComponent(Component *c){if(!c)return;component_set.Add(c);}
|
||||||
|
virtual void UnjonComponent(Component *c){if(!c)return;component_set.Delete(c);}
|
||||||
|
|
||||||
public: //事件
|
public: //事件
|
||||||
|
|
||||||
virtual void OnFocusLost(){} ///<焦点丢失事件
|
virtual void OnFocusLost(){} ///<焦点丢失事件
|
||||||
virtual void OnFocusGained(){} ///<焦点获得事件
|
virtual void OnFocusGained(){} ///<焦点获得事件
|
||||||
};//class ComponentManager
|
};//class ComponentManager
|
||||||
}//namespace hgl::graph
|
}//namespace hgl::graph
|
||||||
|
@ -300,7 +300,9 @@ set(COMPONENT_INCLUDE_PATH ${ROOT_INCLUDE_PATH}/hgl/component)
|
|||||||
|
|
||||||
SET(COMPONENT_FILES ${COMPONENT_INCLUDE_PATH}/Component.h
|
SET(COMPONENT_FILES ${COMPONENT_INCLUDE_PATH}/Component.h
|
||||||
${COMPONENT_INCLUDE_PATH}/RenderComponent.h
|
${COMPONENT_INCLUDE_PATH}/RenderComponent.h
|
||||||
${COMPONENT_INCLUDE_PATH}/PrimitiveComponent.h)
|
${COMPONENT_INCLUDE_PATH}/PrimitiveComponent.h
|
||||||
|
component/ComponentManager.cpp
|
||||||
|
)
|
||||||
|
|
||||||
SOURCE_GROUP("Component" FILES ${COMPONENT_FILES})
|
SOURCE_GROUP("Component" FILES ${COMPONENT_FILES})
|
||||||
|
|
||||||
|
30
src/SceneGraph/component/ComponentManager.cpp
Normal file
30
src/SceneGraph/component/ComponentManager.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include<hgl/component/Component.h>
|
||||||
|
|
||||||
|
namespace hgl::graph
|
||||||
|
{
|
||||||
|
int ComponentManager::GetComponents(List<Component *> &comp_list,SceneNode *node)
|
||||||
|
{
|
||||||
|
if(!node)return(-1);
|
||||||
|
|
||||||
|
Component **cc=component_set.GetData();
|
||||||
|
|
||||||
|
int result=0;
|
||||||
|
|
||||||
|
for(int i=0;i<component_set.GetCount();i++)
|
||||||
|
if(cc[i]->GetOwnerNode()==node)
|
||||||
|
{
|
||||||
|
comp_list.Add(cc[i]);
|
||||||
|
++result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComponentManager::UpdateComponents(const double delta_time)
|
||||||
|
{
|
||||||
|
Component **cc=component_set.GetData();
|
||||||
|
|
||||||
|
for(int i=0;i<component_set.GetCount();i++)
|
||||||
|
cc[i]->Update(delta_time);
|
||||||
|
}
|
||||||
|
}//namespace hgl::graph
|
Loading…
x
Reference in New Issue
Block a user