1.ComponentData/Component/ComponentManager增加各种StaticHashCode/GetHashCode.
2.Component增加ChangeData函数
This commit is contained in:
parent
19aee81063
commit
3bcaf0e012
@ -50,8 +50,19 @@ public:
|
|||||||
|
|
||||||
ComponentData()=default;
|
ComponentData()=default;
|
||||||
virtual ~ComponentData()=default;
|
virtual ~ComponentData()=default;
|
||||||
|
|
||||||
|
virtual const size_t GetHashCode()const=0; ///<取得ComponentData的类型哈希值
|
||||||
|
virtual const size_t GetComponentHashCode()const=0; ///<取得Component的类型哈希值
|
||||||
|
virtual const size_t GetManagerHashCode()const=0; ///<取得ComponentManager的类型哈希值
|
||||||
};//struct ComponentData
|
};//struct ComponentData
|
||||||
|
|
||||||
|
#define COMPONENT_DATA_CLASS_BODY(name) static constexpr const size_t StaticHashCode (){return hgl::GetTypeHash<name##ComponentData>();} \
|
||||||
|
static constexpr const size_t StaticComponentHashCode(){return hgl::GetTypeHash<name##Component>();} \
|
||||||
|
static constexpr const size_t StaticManagerHashCode (){return hgl::GetTypeHash<name##ComponentManager>();} \
|
||||||
|
const size_t GetHashCode ()const override{return name##ComponentData::StaticHashCode();} \
|
||||||
|
const size_t GetComponentHashCode ()const override{return name##ComponentData::StaticComponentHashCode();} \
|
||||||
|
const size_t GetManagerHashCode ()const override{return name##ComponentData::StaticManagerHashCode();}
|
||||||
|
|
||||||
using ComponentDataPtr=SharedPtr<ComponentData>;
|
using ComponentDataPtr=SharedPtr<ComponentData>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,7 +95,9 @@ public:
|
|||||||
Component(ComponentDataPtr,ComponentManager *);
|
Component(ComponentDataPtr,ComponentManager *);
|
||||||
virtual ~Component();
|
virtual ~Component();
|
||||||
|
|
||||||
virtual const size_t GetHashCode()const=0;
|
virtual const size_t GetHashCode()const=0; ///<取得Component的类型哈希值
|
||||||
|
virtual const size_t GetDataHashCode()const=0; ///<取得ComponentData的类型哈希值
|
||||||
|
virtual const size_t GetManagerHashCode()const=0; ///<取得ComponentManager的类型哈希值
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -94,6 +107,10 @@ public:
|
|||||||
ComponentManager * GetManager ()const{return Manager;}
|
ComponentManager * GetManager ()const{return Manager;}
|
||||||
ComponentDataPtr GetData ()const{return Data;}
|
ComponentDataPtr GetData ()const{return Data;}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual bool ChangeData(ComponentDataPtr cdp);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual Component *Duplication();
|
virtual Component *Duplication();
|
||||||
@ -112,7 +129,9 @@ public: //事件
|
|||||||
#define COMPONENT_CLASS_BODY(name) static name##ComponentManager *GetDefaultManager () {return name##ComponentManager::GetDefaultManager();} \
|
#define COMPONENT_CLASS_BODY(name) static name##ComponentManager *GetDefaultManager () {return name##ComponentManager::GetDefaultManager();} \
|
||||||
name##ComponentManager *GetManager ()const {return (name##ComponentManager *)Component::GetManager();} \
|
name##ComponentManager *GetManager ()const {return (name##ComponentManager *)Component::GetManager();} \
|
||||||
static constexpr const size_t StaticHashCode () {return hgl::GetTypeHash<name##Component>();} \
|
static constexpr const size_t StaticHashCode () {return hgl::GetTypeHash<name##Component>();} \
|
||||||
const size_t GetHashCode ()const override{return name##Component::StaticHashCode();}
|
const size_t GetHashCode ()const override{return name##Component::StaticHashCode();} \
|
||||||
|
const size_t GetDataHashCode ()const override{return name::ComponentData::StaticHashCode();} \
|
||||||
|
const size_t GetManagerHashCode ()const override{return name##ComponentManager::StaticHashCode();}
|
||||||
|
|
||||||
using ComponentSet=SortedSet<Component *>;
|
using ComponentSet=SortedSet<Component *>;
|
||||||
using ComponentList=ArrayList<Component *>;
|
using ComponentList=ArrayList<Component *>;
|
||||||
@ -130,8 +149,9 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual const size_t GetComponentHashCode()const=0;
|
virtual const size_t GetComponentHashCode()const=0; ///<取得Component的类型哈希值
|
||||||
virtual const size_t GetHashCode()const=0;
|
virtual const size_t GetDataHashCode()const=0; ///<取得ComponentData的类型哈希值
|
||||||
|
virtual const size_t GetHashCode()const=0; ///<取得ComponentManager的类型哈希值
|
||||||
|
|
||||||
virtual ~ComponentManager();
|
virtual ~ComponentManager();
|
||||||
|
|
||||||
@ -155,9 +175,11 @@ public: //事件
|
|||||||
|
|
||||||
#define COMPONENT_MANAGER_CLASS_BODY(name) static name##ComponentManager * GetDefaultManager () {return GetComponentManager<name##ComponentManager>(true);} \
|
#define COMPONENT_MANAGER_CLASS_BODY(name) static name##ComponentManager * GetDefaultManager () {return GetComponentManager<name##ComponentManager>(true);} \
|
||||||
static constexpr const size_t StaticHashCode () {return hgl::GetTypeHash<name##ComponentManager>();} \
|
static constexpr const size_t StaticHashCode () {return hgl::GetTypeHash<name##ComponentManager>();} \
|
||||||
|
static constexpr const size_t StaticDataHashCode () {return hgl::GetTypeHash<name##ComponentData>();} \
|
||||||
static constexpr const size_t StaticComponentHashCode () {return hgl::GetTypeHash<name##Component>();} \
|
static constexpr const size_t StaticComponentHashCode () {return hgl::GetTypeHash<name##Component>();} \
|
||||||
const size_t GetComponentHashCode ()const override{return name##ComponentManager::StaticComponentHashCode();} \
|
const size_t GetComponentHashCode ()const override{return name##ComponentManager::StaticComponentHashCode();} \
|
||||||
const size_t GetHashCode ()const override{return name##ComponentManager::StaticHashCode();} \
|
const size_t GetDataHashCode ()const override{return name##ComponentManager::StaticDataHashCode();} \
|
||||||
|
const size_t GetHashCode ()const override{return name##ComponentManager::StaticHashCode();}
|
||||||
|
|
||||||
bool RegistryComponentManager(ComponentManager *);
|
bool RegistryComponentManager(ComponentManager *);
|
||||||
ComponentManager *GetComponentManager(const size_t hash_code);
|
ComponentManager *GetComponentManager(const size_t hash_code);
|
||||||
|
@ -34,6 +34,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual ~MeshComponentData();
|
virtual ~MeshComponentData();
|
||||||
|
|
||||||
|
COMPONENT_DATA_CLASS_BODY(Mesh)
|
||||||
};//struct MeshComponentData
|
};//struct MeshComponentData
|
||||||
|
|
||||||
class MeshComponent;
|
class MeshComponent;
|
||||||
|
@ -33,6 +33,29 @@ namespace hgl::graph
|
|||||||
Manager->DetachComponent(this);
|
Manager->DetachComponent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Component::ChangeData(ComponentDataPtr cdp)
|
||||||
|
{
|
||||||
|
if(!cdp)
|
||||||
|
{
|
||||||
|
LOG_ERROR(OS_TEXT("Component::ChangeData: invalid component data pointer."));
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Data==cdp)
|
||||||
|
return(true); //数据没有变化
|
||||||
|
|
||||||
|
ComponentData *cd=cdp.get();
|
||||||
|
|
||||||
|
if(cd->GetHashCode()!=GetHashCode()) //类型不对
|
||||||
|
{
|
||||||
|
LOG_ERROR(OS_TEXT("Component::ChangeData: component data type mismatch."));
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Data=cdp;
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
Component *Component::Duplication()
|
Component *Component::Duplication()
|
||||||
{
|
{
|
||||||
return GetManager()->CreateComponent(Data);
|
return GetManager()->CreateComponent(Data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user