vault backup: 2024-10-12 17:19:45

This commit is contained in:
2024-10-12 17:19:46 +08:00
parent ff94ddca61
commit 244c0c52f6
960 changed files with 31348 additions and 10 deletions

View File

@@ -0,0 +1,158 @@
# NoExport
- **功能描述:** 指定UHT不要用来自动生成注册的代码而只是进行词法分析提取元数据。
- **元数据类型:** bool
- **引擎模块:** UHT
- **常用程度:★**
指定UHT不要用来自动生成注册的代码而只是进行词法分析提取元数据。
NoExportTypes.h里使用了很多该例子。定义的结构常常用!CPP宏包起来以不在C++中参与编译。因此一般是只给引擎内部使用的。
实际上我们想使用也可以只要保持C++中内存布局一样就可以自己多定义。使用场景想自己定义一个UHT头喂给UHT分析然后自己在别处定义实际的C++。一种典型用途是C++里的实际多个类继承于一个模板基类如FVector2MaterialInput这样可以每个特化子类定一个UHT类型别名。另一种目的是把UHT要分析的头文件都放在一个文件里加速UHT分析生成不用分析多个文件反正只要UHT信息和内存布局对就行。
```cpp
#if !CPP // begin noexport class
USTRUCT(noexport, BlueprintType) //如果不写noexport会报错Expected a GENERATED_BODY() at the start of the struct、
struct FFloatRK4SpringInterpolator
{
UPROPERTY(EditAnywhere, Category = "FloatRK4SpringInterpolator")
float StiffnessConstant;
/** 0 = Undamped, <1 = Underdamped, 1 = Critically damped, >1 = Over damped */
UPROPERTY(EditAnywhere, Category = "FloatRK4SpringInterpolator")
float DampeningRatio;
bool bIsInitialized;
bool bIsInMotion;
float TimeRemaining;
FRK4SpringConstants SpringConstants;
float LastPosition;
RK4Integrator::FRK4State<float> State;
};
#endif // end noexport class
//实际应用:
template <typename T>
struct FRK4SpringInterpolator
{
protected:
float StiffnessConstant;
float DampeningRatio;
bool bIsInitialized;
bool bIsInMotion;
float TimeRemaining;
FRK4SpringConstants SpringConstants;
T LastPosition;
RK4Integrator::FRK4State<T> State;
}
struct FFloatRK4SpringInterpolator : FRK4SpringInterpolator<float>
struct FVectorRK4SpringInterpolator : FRK4SpringInterpolator<FVector>
```
不生成的代码包括:
```cpp
USTRUCT(BlueprintType,noexport)
struct INSIDER_API FMyStruct_NoExport
{
//抑制GENERATED_BODY()解释生成的:
//static class UScriptStruct* StaticStruct();
UPROPERTY(BlueprintReadWrite, EditAnywhere)
float Score;
};
//抑制:
//template<> INSIDER_API UScriptStruct* StaticStruct<struct FMyStruct_NoExport>();
```
 .h里不会生成因此不会在别的模块里使用
```cpp
template<> INSIDER_API UScriptStruct* StaticStruct<struct FMyStruct_NoExport>();
```
但是依然会在Module.init.gen.cpp里生成Z_Construct_UScriptStruct_FMyStruct_NoExport的调用因此还是会在蓝图里暴露出来。
```cpp
#include "UObject/GeneratedCppIncludes.h"
PRAGMA_DISABLE_DEPRECATION_WARNINGS
void EmptyLinkFunctionForGeneratedCodeInsider_init() {}
INSIDER_API UScriptStruct* Z_Construct_UScriptStruct_FMyStruct_NoExport();
static FPackageRegistrationInfo Z_Registration_Info_UPackage__Script_Insider;
FORCENOINLINE UPackage* Z_Construct_UPackage__Script_Insider()
{
if (!Z_Registration_Info_UPackage__Script_Insider.OuterSingleton)
{
static UObject* (*const SingletonFuncArray[])() = {
(UObject* (*)())Z_Construct_UScriptStruct_FMyStruct_NoExport,//这里注入调用
};
static const UECodeGen_Private::FPackageParams PackageParams = {
"/Script/Insider",
SingletonFuncArray,
UE_ARRAY_COUNT(SingletonFuncArray),
PKG_CompiledIn | 0x00000000,
0x02A7B98C,
0xFA17C3C4,
METADATA_PARAMS(0, nullptr)
};
UECodeGen_Private::ConstructUPackage(Z_Registration_Info_UPackage__Script_Insider.OuterSingleton, PackageParams);
}
return Z_Registration_Info_UPackage__Script_Insider.OuterSingleton;
}
static FRegisterCompiledInInfo Z_CompiledInDeferPackage_UPackage__Script_Insider(Z_Construct_UPackage__Script_Insider, TEXT("/Script/Insider"), Z_Registration_Info_UPackage__Script_Insider, CONSTRUCT_RELOAD_VERSION_INFO(FPackageReloadVersionInfo, 0x02A7B98C, 0xFA17C3C4));
PRAGMA_ENABLE_DEPRECATION_WARNINGS
```
蓝图里的效果:依然可以当作变量。
![Untitled](Untitled.png)
![Untitled](Untitled%201.png)
加上noexport的区别是不能用StaticStruct和没了TCppStructOps不能做一些优化。其他还是可以正常使用就像FVector一样。
缺失的代码,也可以通过手动添加代码来获得。
```cpp
USTRUCT(BlueprintType,noexport)
struct INSIDER_API FMyStruct_NoExport
{
//GENERATED_BODY() //missing type specifier - int assumed..generated.h里只是定一个StaticStruct()函数
static class UScriptStruct* StaticStruct(); //可以自己定义
UPROPERTY(BlueprintReadWrite, EditAnywhere)
float Score;
};
template<> INSIDER_API UScriptStruct* StaticStruct<struct FMyStruct_NoExport>();//可以自己定义
//.cpp
//链入函数声明在其他的cpp里已经有实现所以可以正常调用到
INSIDER_API UScriptStruct* Z_Construct_UScriptStruct_FMyStruct_NoExport();
UPackage* Z_Construct_UPackage__Script_Insider();
static FStructRegistrationInfo Z_Registration_Info_UScriptStruct_MyStruct_NoExport;
class UScriptStruct* FMyStruct_NoExport::StaticStruct()
{
if (!Z_Registration_Info_UScriptStruct_MyStruct_NoExport.OuterSingleton)
{
Z_Registration_Info_UScriptStruct_MyStruct_NoExport.OuterSingleton = GetStaticStruct(Z_Construct_UScriptStruct_FMyStruct_NoExport, Z_Construct_UPackage__Script_Insider(), TEXT("MyStruct_NoExport"));
}
return Z_Registration_Info_UScriptStruct_MyStruct_NoExport.OuterSingleton;
}
template<> INSIDER_API UScriptStruct* StaticStruct<FMyStruct_NoExport>()
{
return FMyStruct_NoExport::StaticStruct();
}
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB