UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ModuleFactoryRegister.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
7#include "Hash/CityHash.h"
8
9#define UE_API CHAOSVEHICLESCORE_API
10
11namespace Chaos
12{
13
14 struct FModuleNetData;
15 class IFactoryModule;
16
18 {
19 public:
21
25 UE_API void Reset();
26 UE_API bool ContainsFactory(const FName TypeName) const;
27 UE_API bool ContainsFactory(const uint32 TypeNameHash) const;
28 UE_API TSharedPtr<Chaos::FModuleNetData> GenerateNetData(const uint32 TypeNameHash, const int32 SimArrayIndex);
29
30 static uint32 GetModuleHash(const FName TypeName)
31 {
32 uint32 Hash = CityHash32((const char*)TypeName.ToString().GetCharArray().GetData(), sizeof(FString::ElementType) * TypeName.GetStringLength());
33 return Hash;
34 }
35 protected:
36
39 };
40
41 template<typename _To, typename ..._Rest>
43 //Static helper function to create and register a factory of the correct type. The returned Factory MUST be stored somewhere by the caller.
44 template<typename T, typename... Args>
45 static bool RegisterFactoryHelper(Args... args)
46 {
47 FName SimTypeName = T::StaticSimType();
48 if(SimTypeName.IsValid() == false)
49 {
50 return false;
51 }
53 if(FModuleFactoryRegister::Get().ContainsFactory(SimTypeNameHash))
54 {
55 return true;
56 }
58 if (SharedFactory.IsValid())
59 {
61 return true;
62 }
63 return false;
64 }
65} // namespace Chaos
66
67#undef UE_API
uint32 CityHash32(const char *s, uint32 len)
Definition CityHash.cpp:203
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UE_API
Definition SColorGradingComponentViewer.h:12
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition ModuleFactoryRegister.h:18
static UE_API FModuleFactoryRegister & Get()
Definition ModuleFactoryRegister.cpp:9
TMap< int32, TWeakPtr< IFactoryModule > > RegisteredFactoriesByName
Definition ModuleFactoryRegister.h:38
UE_API void Reset()
Definition ModuleFactoryRegister.cpp:41
UE_API TSharedPtr< Chaos::FModuleNetData > GenerateNetData(const uint32 TypeNameHash, const int32 SimArrayIndex)
Definition ModuleFactoryRegister.cpp:56
UE_API void RemoveFactory(TWeakPtr< IFactoryModule > InFactory)
Definition ModuleFactoryRegister.cpp:28
UE_API void RegisterFactory(const FName TypeName, TWeakPtr< IFactoryModule > InFactory)
Definition ModuleFactoryRegister.cpp:15
UE_API bool ContainsFactory(const FName TypeName) const
Definition ModuleFactoryRegister.cpp:46
static uint32 GetModuleHash(const FName TypeName)
Definition ModuleFactoryRegister.h:30
Definition ModuleFactoryRegister.h:42
Definition NameTypes.h:617
CORE_API uint32 GetStringLength() const
Definition UnrealNames.cpp:3666
CORE_API FString ToString() const
Definition UnrealNames.cpp:3537
Definition UnrealString.h.inl:34
Definition SharedPointer.h:692
Definition SharedPointer.h:1295
Definition SkeletalMeshComponent.h:307