8#include "ModuleInput.generated.h"
12#define UE_API CHAOSVEHICLESCORE_API
25 MAxis1D
UMETA(DisplayName =
"Axis1D (float)"),
26 MAxis2D
UMETA(DisplayName =
"Axis2D (Vector2D)"),
27 MAxis3D
UMETA(DisplayName =
"Axis3D (Vector)"),
28 MInteger
UMETA(DisplayName =
"Digital (int32)"),
55 template<
int32 MaxValue, u
int32 NumBits>
65 template<
int32 MaxValue, u
int32 NumBits,
typename T UE_REQUIRES(std::is_
floating_po
int_v<T>&& NumBits < 32)>
66 bool ToCompressedFloat(const T InValue, u
int32& OutCompressedFloat)
68 using Details = ModularQuantize::TCompressedFloatDetails<MaxValue, NumBits>;
72 if (MaxValue > Details::MaxBitValue)
75 const T
Scale = T(Details::MaxBitValue) / MaxValue;
81 constexpr int32 Scale = Details::MaxBitValue / MaxValue;
87 if (
Delta > Details::MaxDelta)
98 template<
int32 MaxValue, u
int32 NumBits,
typename T UE_REQUIRES(std::is_
floating_po
int_v<T>&& NumBits < 32)>
99 bool FromCompressedFloat(const u
int32 InCompressed, T& OutValue )
101 using Details = ModularQuantize::TCompressedFloatDetails<MaxValue, NumBits>;
103 u
int32 Delta = InCompressed;
104 T UnscaledValue = static_cast<T>(static_cast<
int32>(Delta) - Details::Bias);
106 if constexpr (MaxValue > Details::MaxBitValue)
109 constexpr T InvScale = MaxValue / (T)Details::MaxBitValue;
114 constexpr int32 Scale = Details::MaxBitValue / MaxValue;
115 constexpr T InvScale = T(1) / (T)
Scale;
123 template<
int32 MaxValue, u
int32 NumBits,
typename T UE_REQUIRES(std::is_
floating_po
int_v<T>&& NumBits < 32)>
124 bool WriteCompressedFloat(const T Value, FArchive& Ar)
126 using Details = ModularQuantize::TCompressedFloatDetails<MaxValue, NumBits>;
128 u
int32 CompressedValue;
129 bool clamp = ModularQuantize::ToCompressedFloat<MaxValue, NumBits>(Value, CompressedValue);
131 Ar.SerializeInt(CompressedValue, Details::SerIntMax);
136 template<
int32 MaxValue, u
int32 NumBits,
typename T UE_REQUIRES(std::is_
floating_po
int_v<T>&& NumBits < 32)>
137 bool ReadCompressedFloat(T& Value, FArchive& Ar)
139 using Details = ModularQuantize::TCompressedFloatDetails<MaxValue, NumBits>;
141 u
int32 CompressedValue;
142 Ar.SerializeInt(CompressedValue, Details::SerIntMax);
144 ModularQuantize::FromCompressedFloat<MaxValue, NumBits>(CompressedValue, Value);
150 template<
int32 MaxValue, u
int32 NumBits>
156 success &= ModularQuantize::WriteCompressedFloat<MaxValue, NumBits>(
InOutValue, Ar);
160 ModularQuantize::ReadCompressedFloat<MaxValue, NumBits>(
InOutValue, Ar);
164 template<
int32 MaxValue, u
int32 NumBits,
typename T UE_REQUIRES(std::is_
floating_po
int_v<T>&& NumBits < 32)>
165 void QuantizeValue(T& Value)
167 u
int32 CompressedValue = 0;
168 ModularQuantize::ToCompressedFloat<MaxValue, NumBits>(Value, CompressedValue);
169 ModularQuantize::FromCompressedFloat<MaxValue, NumBits>(CompressedValue, Value);
172 template<
int32 MaxValue, u
int32 NumBits,
typename T UE_REQUIRES(std::is_
floating_po
int_v<T>&& NumBits < 32)>
173 bool QuantizedIsNearlyEqual(const T& Left,const T& Right)
175 u
int32 CompressedValue = 0;
176 T QuantLeft, QuantRight;
177 ModularQuantize::ToCompressedFloat<MaxValue, NumBits>(Left, CompressedValue);
178 ModularQuantize::FromCompressedFloat<MaxValue, NumBits>(CompressedValue, QuantLeft);
179 ModularQuantize::ToCompressedFloat<MaxValue, NumBits>(Right, CompressedValue);
180 ModularQuantize::FromCompressedFloat<MaxValue, NumBits>(CompressedValue, QuantRight);
181 return FMath::IsNearlyEqual(QuantLeft, QuantRight);
185USTRUCT(Bluepr
intType)
186struct FModuleInputValue
191 using MAxis1D =
double;
192 using MAxis2D = FVector2D;
193 using MAxis3D = FVector;
194 using MInteger =
int32;
197 FModuleInputValue() = default;
198 FModuleInputValue(const FModuleInputValue&) = default;
199 FModuleInputValue& operator= (const FModuleInputValue&) = default;
203 FModuleInputValue(
bool bInValue) : Value(FVector::ZeroVector), ValueInt(bInValue), ValueType(EModuleInputValueType::MBoolean) {}
204 FModuleInputValue(MInteger InValue) : Value(FVector::ZeroVector), ValueInt(InValue), ValueType(EModuleInputValueType::MInteger) {}
205 FModuleInputValue(MAxis1D InValue) : Value(InValue, 0.f, 0.f), ValueInt(0), ValueType(EModuleInputValueType::MAxis1D) {}
206 FModuleInputValue(MAxis2D InValue) : Value(InValue.X, InValue.Y, 0.f), ValueInt(0), ValueType(EModuleInputValueType::MAxis2D) {}
207 FModuleInputValue(MAxis3D InValue) : Value(InValue), ValueInt(0), ValueType(EModuleInputValueType::MAxis3D) {}
209 FModuleInputValue ReturnQuantized(EModuleInputQuantizationType InInputQuantizationType) const;
211 static
void Quantize(
double& InOutValue, EModuleInputQuantizationType InInputQuantizationType);
213 static
bool SerializeQuantized(
double& InOutValue, FArchive& Ar, EModuleInputQuantizationType InInputQuantizationType);
216 FModuleInputValue(EModuleInputValueType InValueType, MAxis3D InValue) : Value(InValue), ValueType(InValueType)
223 case EModuleInputValueType::MBoolean:
224 case EModuleInputValueType::MAxis1D:
227 case EModuleInputValueType::MAxis2D:
230 case EModuleInputValueType::MAxis3D:
237 FModuleInputValue(EModuleInputValueType InValueType, MInteger InValue) : ValueInt(InValue), ValueType(InValueType)
248 Value = FVector::ZeroVector;
252 FModuleInputValue& operator+=(const FModuleInputValue& Rhs)
254 ensure(ValueType == Rhs.ValueType);
258 ValueType = FMath::Max(ValueType, Rhs.ValueType);
262 friend FModuleInputValue operator+(const FModuleInputValue& Lhs, const FModuleInputValue& Rhs)
264 ensure(Lhs.ValueType == Rhs.ValueType);
266 FModuleInputValue Result(Lhs);
271 FModuleInputValue& operator-=(const FModuleInputValue& Rhs)
273 ensure(ValueType == Rhs.ValueType);
277 ValueType = FMath::Max(ValueType, Rhs.ValueType);
281 friend FModuleInputValue operator-(const FModuleInputValue& Lhs, const FModuleInputValue& Rhs)
283 ensure(Lhs.ValueType == Rhs.ValueType);
285 FModuleInputValue Result(Lhs);
291 FModuleInputValue& operator*=(
float Scalar)
293 ensure(ValueType != EModuleInputValueType::MBoolean);
294 ensure(ValueType != EModuleInputValueType::MInteger);
300 friend FModuleInputValue operator*(const FModuleInputValue& Lhs, const
float Rhs)
302 ensure(Lhs.GetValueType() != EModuleInputValueType::MBoolean);
303 ensure(Lhs.GetValueType() != EModuleInputValueType::MInteger);
305 FModuleInputValue Result(Lhs);
310 static FModuleInputValue Clamp(const FModuleInputValue& InValue, const
float InMin, const
float InMax)
312 FModuleInputValue OutValue = InValue;
313 float Mag = InValue.GetMagnitude();
317 OutValue.SetMagnitude(InMin);
319 else if (Mag > InMax)
321 OutValue.SetMagnitude(InMax);
329 inline T
Get()
const {
static_assert(
sizeof(T) == 0,
"Unsupported conversion for type"); }
340 if (ValueType != Type)
350 UE_API float GetMagnitudeSq()
const;
351 UE_API float GetMagnitude()
const;
370 UE_API FString ToString()
const;
381 void SetMagnitude(
float NewSize);
439 ensure(
InValue.GetValueType() == EModuleInputValueType::MBoolean);
445 ensure(
InValue.GetValueType() == EModuleInputValueType::MAxis1D);
451 ensure(
InValue.GetValueType() == EModuleInputValueType::MAxis2D);
457 ensure(
InValue.GetValueType() == EModuleInputValueType::MAxis3D);
463 ensure(
InValue.GetValueType() == EModuleInputValueType::MInteger);
474UCLASS(BlueprintType, Blueprintable, MinimalAPI)
525 Type = EModuleInputValueType::MBoolean;
526 bApplyInputDecay =
false;
527 bClearAfterConsumed =
false;
533 , bApplyInputDecay(
false)
534 , bClearAfterConsumed(
false)
540 return (
Name == Rhs.Name);
551 bool bApplyInputDecay;
555 bool bClearAfterConsumed;
568 InitSetupData =
nullptr;
571 static bool HasSetup() {
return InitSetupData !=
nullptr; }
630 if (
Other.InputValues.Num())
632 InputValues =
Other.InputValues;
646 UE_API void RemoveAllInputs();
658 UE_API void ClearConsumedInputs();
687 UE_API float GetMagnitude(
const FName& InName)
const;
689 UE_API bool InputsNonZero()
const;
720 ensure(GetValueType(InName) == EModuleInputValueType::MBoolean);
722 SetValue(InName,
Value);
726 ensure(GetValueType(InName) == EModuleInputValueType::MInteger);
728 SetValue(InName,
Value);
732 ensure(GetValueType(InName) == EModuleInputValueType::MAxis1D);
734 SetValue(InName,
Value, Quantize);
738 ensure(GetValueType(InName) == EModuleInputValueType::MAxis2D);
743 ensure(GetValueType(InName) == EModuleInputValueType::MAxis3D);
#define ensure( InExpression)
Definition AssertionMacros.h:464
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity)
Definition LogMacros.h:361
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UCLASS(...)
Definition ObjectMacros.h:776
#define UENUM(...)
Definition ObjectMacros.h:749
#define USTRUCT(...)
Definition ObjectMacros.h:746
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
#define KINDA_SMALL_NUMBER
Definition UnrealMathUtility.h:67
Definition Archive.h:1208
UE_FORCEINLINE_HINT bool IsSaving() const
Definition Archive.h:248
Definition NameTypes.h:617
Definition UObjectGlobals.h:1292
Definition UnrealString.h.inl:34
Definition ModuleInput.h:54
bool SerializeFixedFloat(double &InOutValue, FArchive &Ar)
Definition ModuleInput.h:151
@ false
Definition radaudio_common.h:23
U16 Index
Definition radfft.cpp:71
Definition ModuleInput.h:57
static constexpr int32 Bias
Definition ModuleInput.h:60
static constexpr int32 MaxBitValue
Definition ModuleInput.h:59
static constexpr int32 MaxDelta
Definition ModuleInput.h:62
static constexpr int32 SerIntMax
Definition ModuleInput.h:61
T Y
Definition Vector.h:65
T X
Definition Vector.h:62