HashCode统一改名为TypeHash

This commit is contained in:
hyzboy 2025-06-24 00:49:18 +08:00
parent 3bcaf0e012
commit fa7a0fca62
5 changed files with 36 additions and 35 deletions

View File

@ -51,17 +51,17 @@ public:
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的类型哈希值
virtual const size_t GetTypeHash()const=0; ///<取得ComponentData的类型哈希值
virtual const size_t GetComponentTypeHash()const=0; ///<取得Component的类型哈希值
virtual const size_t GetManagerTypeHash()const=0; ///<取得ComponentManager的类型哈希值
};//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();}
#define COMPONENT_DATA_CLASS_BODY(name) static constexpr const size_t StaticTypeHash (){return hgl::GetTypeHash<name##ComponentData>();} \
static constexpr const size_t StaticComponentTypeHash(){return hgl::GetTypeHash<name##Component>();} \
static constexpr const size_t StaticManagerTypeHash (){return hgl::GetTypeHash<name##ComponentManager>();} \
const size_t GetTypeHash ()const override{return StaticTypeHash();} \
const size_t GetComponentTypeHash ()const override{return StaticComponentTypeHash();} \
const size_t GetManagerTypeHash ()const override{return StaticManagerTypeHash();}
using ComponentDataPtr=SharedPtr<ComponentData>;
@ -95,9 +95,9 @@ public:
Component(ComponentDataPtr,ComponentManager *);
virtual ~Component();
virtual const size_t GetHashCode()const=0; ///<取得Component的类型哈希值
virtual const size_t GetDataHashCode()const=0; ///<取得ComponentData的类型哈希值
virtual const size_t GetManagerHashCode()const=0; ///<取得ComponentManager的类型哈希值
virtual const size_t GetTypeHash()const=0; ///<取得Component的类型哈希值
virtual const size_t GetDataTypeHash()const=0; ///<取得ComponentData的类型哈希值
virtual const size_t GetManagerTypeHash()const=0; ///<取得ComponentManager的类型哈希值
public:
@ -128,10 +128,12 @@ public: //事件
#define COMPONENT_CLASS_BODY(name) static name##ComponentManager *GetDefaultManager () {return name##ComponentManager::GetDefaultManager();} \
name##ComponentManager *GetManager ()const {return (name##ComponentManager *)Component::GetManager();} \
static constexpr const size_t StaticHashCode () {return hgl::GetTypeHash<name##Component>();} \
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();}
static constexpr const size_t StaticTypeHash () {return hgl::GetTypeHash<name##Component>();} \
static constexpr const size_t StaticDataTypeHash () {return hgl::GetTypeHash<name##ComponentData>();} \
static constexpr const size_t StaticManagerTypeHash () {return hgl::GetTypeHash<name##ComponentManager>();} \
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 ComponentList=ArrayList<Component *>;
@ -149,9 +151,9 @@ protected:
public:
virtual const size_t GetComponentHashCode()const=0; ///<取得Component的类型哈希值
virtual const size_t GetDataHashCode()const=0; ///<取得ComponentData的类型哈希值
virtual const size_t GetHashCode()const=0; ///<取得ComponentManager的类型哈希值
virtual const size_t GetComponentTypeHash()const=0; ///<取得Component的类型哈希值
virtual const size_t GetDataTypeHash()const=0; ///<取得ComponentData的类型哈希值
virtual const size_t GetTypeHash()const=0; ///<取得ComponentManager的类型哈希值
virtual ~ComponentManager();
@ -174,19 +176,19 @@ public: //事件
};//class ComponentManager
#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 StaticDataHashCode () {return hgl::GetTypeHash<name##ComponentData>();} \
static constexpr const size_t StaticComponentHashCode () {return hgl::GetTypeHash<name##Component>();} \
const size_t GetComponentHashCode ()const override{return name##ComponentManager::StaticComponentHashCode();} \
const size_t GetDataHashCode ()const override{return name##ComponentManager::StaticDataHashCode();} \
const size_t GetHashCode ()const override{return name##ComponentManager::StaticHashCode();}
static constexpr const size_t StaticTypeHash () {return hgl::GetTypeHash<name##ComponentManager>();} \
static constexpr const size_t StaticDataTypeHash () {return hgl::GetTypeHash<name##ComponentData>();} \
static constexpr const size_t StaticComponentTypeHash () {return hgl::GetTypeHash<name##Component>();} \
const size_t GetComponentTypeHash ()const override{return StaticComponentTypeHash();} \
const size_t GetDataTypeHash ()const override{return StaticDataTypeHash();} \
const size_t GetTypeHash ()const override{return StaticTypeHash();}
bool RegistryComponentManager(ComponentManager *);
ComponentManager *GetComponentManager(const size_t hash_code);
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)
{

View File

@ -7,6 +7,9 @@
COMPONENT_NAMESPACE_BEGIN
class MeshComponent;
class MeshComponentManager;
struct MeshComponentData:public ComponentData
{
//static uint unique_id_count;
@ -38,8 +41,6 @@ public:
COMPONENT_DATA_CLASS_BODY(Mesh)
};//struct MeshComponentData
class MeshComponent;
class MeshComponentManager:public ComponentManager
{
public:

View File

@ -44,9 +44,7 @@ namespace hgl::graph
if(Data==cdp)
return(true); //数据没有变化
ComponentData *cd=cdp.get();
if(cd->GetHashCode()!=GetHashCode()) //类型不对
if(cdp->GetTypeHash()!=GetTypeHash()) //类型不对
{
LOG_ERROR(OS_TEXT("Component::ChangeData: component data type mismatch."));
return(false);

View File

@ -39,7 +39,7 @@ namespace hgl::graph
if(!component_manager_map)
return(false);
const size_t hash_code=cm->GetHashCode();
const size_t hash_code=cm->GetTypeHash();
if(component_manager_map->contains(hash_code))
return(false);

View File

@ -25,7 +25,7 @@ namespace hgl
for(auto component:sn->GetComponents())
{
if(component->GetHashCode()!=MeshComponent::StaticHashCode()) //暂时只支持MeshComponent
if(component->GetTypeHash()!=MeshComponent::StaticTypeHash()) //暂时只支持MeshComponent
continue;
MeshComponent *smc=dynamic_cast<MeshComponent *>(component);