HashCode统一改名为TypeHash
This commit is contained in:
parent
3bcaf0e012
commit
fa7a0fca62
@ -51,17 +51,17 @@ public:
|
|||||||
ComponentData()=default;
|
ComponentData()=default;
|
||||||
virtual ~ComponentData()=default;
|
virtual ~ComponentData()=default;
|
||||||
|
|
||||||
virtual const size_t GetHashCode()const=0; ///<取得ComponentData的类型哈希值
|
virtual const size_t GetTypeHash()const=0; ///<取得ComponentData的类型哈希值
|
||||||
virtual const size_t GetComponentHashCode()const=0; ///<取得Component的类型哈希值
|
virtual const size_t GetComponentTypeHash()const=0; ///<取得Component的类型哈希值
|
||||||
virtual const size_t GetManagerHashCode()const=0; ///<取得ComponentManager的类型哈希值
|
virtual const size_t GetManagerTypeHash()const=0; ///<取得ComponentManager的类型哈希值
|
||||||
};//struct ComponentData
|
};//struct ComponentData
|
||||||
|
|
||||||
#define COMPONENT_DATA_CLASS_BODY(name) static constexpr const size_t StaticHashCode (){return hgl::GetTypeHash<name##ComponentData>();} \
|
#define COMPONENT_DATA_CLASS_BODY(name) static constexpr const size_t StaticTypeHash (){return hgl::GetTypeHash<name##ComponentData>();} \
|
||||||
static constexpr const size_t StaticComponentHashCode(){return hgl::GetTypeHash<name##Component>();} \
|
static constexpr const size_t StaticComponentTypeHash(){return hgl::GetTypeHash<name##Component>();} \
|
||||||
static constexpr const size_t StaticManagerHashCode (){return hgl::GetTypeHash<name##ComponentManager>();} \
|
static constexpr const size_t StaticManagerTypeHash (){return hgl::GetTypeHash<name##ComponentManager>();} \
|
||||||
const size_t GetHashCode ()const override{return name##ComponentData::StaticHashCode();} \
|
const size_t GetTypeHash ()const override{return StaticTypeHash();} \
|
||||||
const size_t GetComponentHashCode ()const override{return name##ComponentData::StaticComponentHashCode();} \
|
const size_t GetComponentTypeHash ()const override{return StaticComponentTypeHash();} \
|
||||||
const size_t GetManagerHashCode ()const override{return name##ComponentData::StaticManagerHashCode();}
|
const size_t GetManagerTypeHash ()const override{return StaticManagerTypeHash();}
|
||||||
|
|
||||||
using ComponentDataPtr=SharedPtr<ComponentData>;
|
using ComponentDataPtr=SharedPtr<ComponentData>;
|
||||||
|
|
||||||
@ -95,9 +95,9 @@ public:
|
|||||||
Component(ComponentDataPtr,ComponentManager *);
|
Component(ComponentDataPtr,ComponentManager *);
|
||||||
virtual ~Component();
|
virtual ~Component();
|
||||||
|
|
||||||
virtual const size_t GetHashCode()const=0; ///<取得Component的类型哈希值
|
virtual const size_t GetTypeHash()const=0; ///<取得Component的类型哈希值
|
||||||
virtual const size_t GetDataHashCode()const=0; ///<取得ComponentData的类型哈希值
|
virtual const size_t GetDataTypeHash()const=0; ///<取得ComponentData的类型哈希值
|
||||||
virtual const size_t GetManagerHashCode()const=0; ///<取得ComponentManager的类型哈希值
|
virtual const size_t GetManagerTypeHash()const=0; ///<取得ComponentManager的类型哈希值
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -126,12 +126,14 @@ public: //事件
|
|||||||
virtual void OnFocusGained(){} ///<焦点获得事件
|
virtual void OnFocusGained(){} ///<焦点获得事件
|
||||||
};//class Component
|
};//class Component
|
||||||
|
|
||||||
#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 StaticTypeHash () {return hgl::GetTypeHash<name##Component>();} \
|
||||||
const size_t GetHashCode ()const override{return name##Component::StaticHashCode();} \
|
static constexpr const size_t StaticDataTypeHash () {return hgl::GetTypeHash<name##ComponentData>();} \
|
||||||
const size_t GetDataHashCode ()const override{return name::ComponentData::StaticHashCode();} \
|
static constexpr const size_t StaticManagerTypeHash () {return hgl::GetTypeHash<name##ComponentManager>();} \
|
||||||
const size_t GetManagerHashCode ()const override{return name##ComponentManager::StaticHashCode();}
|
const size_t GetTypeHash ()const override{return StaticTypeHash();} \
|
||||||
|
const size_t GetDataTypeHash ()const override{return StaticDataTypeHash();} \
|
||||||
|
const size_t GetManagerTypeHash ()const override{return StaticManagerTypeHash();}
|
||||||
|
|
||||||
using ComponentSet=SortedSet<Component *>;
|
using ComponentSet=SortedSet<Component *>;
|
||||||
using ComponentList=ArrayList<Component *>;
|
using ComponentList=ArrayList<Component *>;
|
||||||
@ -149,9 +151,9 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual const size_t GetComponentHashCode()const=0; ///<取得Component的类型哈希值
|
virtual const size_t GetComponentTypeHash()const=0; ///<取得Component的类型哈希值
|
||||||
virtual const size_t GetDataHashCode()const=0; ///<取得ComponentData的类型哈希值
|
virtual const size_t GetDataTypeHash()const=0; ///<取得ComponentData的类型哈希值
|
||||||
virtual const size_t GetHashCode()const=0; ///<取得ComponentManager的类型哈希值
|
virtual const size_t GetTypeHash()const=0; ///<取得ComponentManager的类型哈希值
|
||||||
|
|
||||||
virtual ~ComponentManager();
|
virtual ~ComponentManager();
|
||||||
|
|
||||||
@ -174,19 +176,19 @@ public: //事件
|
|||||||
};//class ComponentManager
|
};//class ComponentManager
|
||||||
|
|
||||||
#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 StaticTypeHash () {return hgl::GetTypeHash<name##ComponentManager>();} \
|
||||||
static constexpr const size_t StaticDataHashCode () {return hgl::GetTypeHash<name##ComponentData>();} \
|
static constexpr const size_t StaticDataTypeHash () {return hgl::GetTypeHash<name##ComponentData>();} \
|
||||||
static constexpr const size_t StaticComponentHashCode () {return hgl::GetTypeHash<name##Component>();} \
|
static constexpr const size_t StaticComponentTypeHash () {return hgl::GetTypeHash<name##Component>();} \
|
||||||
const size_t GetComponentHashCode ()const override{return name##ComponentManager::StaticComponentHashCode();} \
|
const size_t GetComponentTypeHash ()const override{return StaticComponentTypeHash();} \
|
||||||
const size_t GetDataHashCode ()const override{return name##ComponentManager::StaticDataHashCode();} \
|
const size_t GetDataTypeHash ()const override{return StaticDataTypeHash();} \
|
||||||
const size_t GetHashCode ()const override{return name##ComponentManager::StaticHashCode();}
|
const size_t GetTypeHash ()const override{return StaticTypeHash();}
|
||||||
|
|
||||||
bool RegistryComponentManager(ComponentManager *);
|
bool RegistryComponentManager(ComponentManager *);
|
||||||
ComponentManager *GetComponentManager(const size_t hash_code);
|
ComponentManager *GetComponentManager(const size_t hash_code);
|
||||||
|
|
||||||
template<typename T> inline T *GetComponentManager(bool create_default=true)
|
template<typename T> inline T *GetComponentManager(bool create_default=true)
|
||||||
{
|
{
|
||||||
T *cm=(T *)GetComponentManager(T::StaticHashCode());
|
T *cm=(T *)GetComponentManager(T::StaticTypeHash());
|
||||||
|
|
||||||
if(!cm&&create_default)
|
if(!cm&&create_default)
|
||||||
{
|
{
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
COMPONENT_NAMESPACE_BEGIN
|
COMPONENT_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
class MeshComponent;
|
||||||
|
class MeshComponentManager;
|
||||||
|
|
||||||
struct MeshComponentData:public ComponentData
|
struct MeshComponentData:public ComponentData
|
||||||
{
|
{
|
||||||
//static uint unique_id_count;
|
//static uint unique_id_count;
|
||||||
@ -38,8 +41,6 @@ public:
|
|||||||
COMPONENT_DATA_CLASS_BODY(Mesh)
|
COMPONENT_DATA_CLASS_BODY(Mesh)
|
||||||
};//struct MeshComponentData
|
};//struct MeshComponentData
|
||||||
|
|
||||||
class MeshComponent;
|
|
||||||
|
|
||||||
class MeshComponentManager:public ComponentManager
|
class MeshComponentManager:public ComponentManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -44,9 +44,7 @@ namespace hgl::graph
|
|||||||
if(Data==cdp)
|
if(Data==cdp)
|
||||||
return(true); //数据没有变化
|
return(true); //数据没有变化
|
||||||
|
|
||||||
ComponentData *cd=cdp.get();
|
if(cdp->GetTypeHash()!=GetTypeHash()) //类型不对
|
||||||
|
|
||||||
if(cd->GetHashCode()!=GetHashCode()) //类型不对
|
|
||||||
{
|
{
|
||||||
LOG_ERROR(OS_TEXT("Component::ChangeData: component data type mismatch."));
|
LOG_ERROR(OS_TEXT("Component::ChangeData: component data type mismatch."));
|
||||||
return(false);
|
return(false);
|
||||||
|
@ -39,7 +39,7 @@ namespace hgl::graph
|
|||||||
if(!component_manager_map)
|
if(!component_manager_map)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
const size_t hash_code=cm->GetHashCode();
|
const size_t hash_code=cm->GetTypeHash();
|
||||||
|
|
||||||
if(component_manager_map->contains(hash_code))
|
if(component_manager_map->contains(hash_code))
|
||||||
return(false);
|
return(false);
|
||||||
|
@ -25,7 +25,7 @@ namespace hgl
|
|||||||
|
|
||||||
for(auto component:sn->GetComponents())
|
for(auto component:sn->GetComponents())
|
||||||
{
|
{
|
||||||
if(component->GetHashCode()!=MeshComponent::StaticHashCode()) //暂时只支持MeshComponent
|
if(component->GetTypeHash()!=MeshComponent::StaticTypeHash()) //暂时只支持MeshComponent
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
MeshComponent *smc=dynamic_cast<MeshComponent *>(component);
|
MeshComponent *smc=dynamic_cast<MeshComponent *>(component);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user