Skip to content

Commit

Permalink
[C] Use double precision floats
Browse files Browse the repository at this point in the history
  • Loading branch information
mcsab committed Apr 22, 2024
1 parent 42c8360 commit 6ae9b61
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 28 deletions.
12 changes: 6 additions & 6 deletions Source/DlgSystem/DlgCondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool FDlgCondition::IsConditionMet(const UDlgContext& Context, const UObject* Pa
return CheckBool(Context, IDlgDialogueParticipant::Execute_GetBoolValue(Participant, CallbackName));

case EDlgConditionType::FloatCall:
return CheckFloat(Context, IDlgDialogueParticipant::Execute_GetFloatValue(Participant, CallbackName));
return CheckFloat(Context, static_cast<double>(IDlgDialogueParticipant::Execute_GetFloatValue(Participant, CallbackName)));

case EDlgConditionType::IntCall:
return CheckInt(Context, IDlgDialogueParticipant::Execute_GetIntValue(Participant, CallbackName));
Expand All @@ -85,7 +85,7 @@ bool FDlgCondition::IsConditionMet(const UDlgContext& Context, const UObject* Pa
return CheckBool(Context, FNYReflectionHelper::GetVariable<FBoolProperty, bool>(Participant, CallbackName));

case EDlgConditionType::ClassFloatVariable:
return CheckFloat(Context, FNYReflectionHelper::GetVariable<FFloatProperty, float>(Participant, CallbackName));
return CheckFloat(Context, FNYReflectionHelper::GetVariable<FDoubleProperty, double>(Participant, CallbackName));

case EDlgConditionType::ClassIntVariable:
return CheckInt(Context, FNYReflectionHelper::GetVariable<FIntProperty, int32>(Participant, CallbackName));
Expand All @@ -110,9 +110,9 @@ bool FDlgCondition::IsConditionMet(const UDlgContext& Context, const UObject* Pa
}
}

bool FDlgCondition::CheckFloat(const UDlgContext& Context, float Value) const
bool FDlgCondition::CheckFloat(const UDlgContext& Context, double Value) const
{
float ValueToCheckAgainst = FloatValue;
double ValueToCheckAgainst = FloatValue;
if (CompareType == EDlgCompare::ToVariable || CompareType == EDlgCompare::ToClassVariable)
{
const UObject* OtherParticipant = Context.GetParticipant(OtherParticipantName);
Expand All @@ -123,11 +123,11 @@ bool FDlgCondition::CheckFloat(const UDlgContext& Context, float Value) const

if (CompareType == EDlgCompare::ToVariable)
{
ValueToCheckAgainst = IDlgDialogueParticipant::Execute_GetFloatValue(OtherParticipant, OtherVariableName);
ValueToCheckAgainst = static_cast<double>(IDlgDialogueParticipant::Execute_GetFloatValue(OtherParticipant, OtherVariableName));
}
else
{
ValueToCheckAgainst = FNYReflectionHelper::GetVariable<FFloatProperty, float>(OtherParticipant, OtherVariableName);
ValueToCheckAgainst = FNYReflectionHelper::GetVariable<FDoubleProperty, double>(OtherParticipant, OtherVariableName);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Source/DlgSystem/DlgCondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ struct DLGSYSTEM_API FDlgCondition
// Helper functions doing the check on the primary value based on EDlgCompare
//

bool CheckFloat(const UDlgContext& Context, float Value) const;
bool CheckFloat(const UDlgContext& Context, double Value) const;
bool CheckInt(const UDlgContext& Context, int32 Value) const;
bool CheckBool(const UDlgContext& Context, bool bValue) const;
bool CheckName(const UDlgContext& Context, FName Value) const;
Expand Down Expand Up @@ -256,7 +256,7 @@ struct DLGSYSTEM_API FDlgCondition

// Float the participants float is checked against
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Condition")
float FloatValue = 0.f;
double FloatValue = 0.f;

// FName the participants name is checked against
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Condition")
Expand Down
2 changes: 1 addition & 1 deletion Source/DlgSystem/DlgEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void FDlgEvent::Call(UDlgContext& Context, const FString& ContextString, UObject
FNYReflectionHelper::ModifyVariable<FIntProperty>(Participant, EventName, IntValue, bDelta);
break;
case EDlgEventType::ModifyClassFloatVariable:
FNYReflectionHelper::ModifyVariable<FFloatProperty>(Participant, EventName, FloatValue, bDelta);
FNYReflectionHelper::ModifyVariable<FDoubleProperty>(Participant, EventName, FloatValue, bDelta);
break;
case EDlgEventType::ModifyClassBoolVariable:
FNYReflectionHelper::SetVariable<FBoolProperty>(Participant, EventName, bValue);
Expand Down
6 changes: 3 additions & 3 deletions Source/DlgSystem/DlgEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ enum class EDlgEventType : uint8
// Modifies the value from the Participant Int Variable
ModifyClassIntVariable UMETA(DisplayName = "Modify Class Int Variable"),

// Modifies the value from the Participant Float Variable
ModifyClassFloatVariable UMETA(DisplayName = "Modify Class Float Variable"),
// Modifies the value from the Participant Float Variable (Double Precision, double for c++)
ModifyClassFloatVariable UMETA(DisplayName = "Modify Class Float (Double Precision) Variable"),

// Modifies the value from the Participant Bool Variable
ModifyClassBoolVariable UMETA(DisplayName = "Modify Class Bool Variable"),
Expand Down Expand Up @@ -143,7 +143,7 @@ struct DLGSYSTEM_API FDlgEvent

// The value the participant gets
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Event")
float FloatValue = 0.f;
double FloatValue = 0.f;

// The value the participant gets
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dialogue|Event")
Expand Down
2 changes: 1 addition & 1 deletion Source/DlgSystem/DlgTextArgument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ FFormatArgumentValue FDlgTextArgument::ConstructFormatArgumentValue(const UDlgCo
return FFormatArgumentValue(IDlgDialogueParticipant::Execute_GetFloatValue(Participant, VariableName));

case EDlgTextArgumentType::ClassFloat:
return FFormatArgumentValue(FNYReflectionHelper::GetVariable<FFloatProperty, float>(Participant, VariableName));
return FFormatArgumentValue(FNYReflectionHelper::GetVariable<FDoubleProperty, double>(Participant, VariableName));

case EDlgTextArgumentType::ClassText:
return FFormatArgumentValue(FNYReflectionHelper::GetVariable<FTextProperty, FText>(Participant, VariableName));
Expand Down
6 changes: 3 additions & 3 deletions Source/DlgSystem/GameplayDebugger/SDlgDataPropertyValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void SDlgDataPropertyValue::UpdateVariableNodeFromActor()
}
case EDlgDataDisplayVariableTreeNodeType::ClassFloat:
{
const float Value = FNYReflectionHelper::GetVariable<FFloatProperty, float>(Actor.Get(), VariableName);
const double Value = FNYReflectionHelper::GetVariable<FDoubleProperty, double>(Actor.Get(), VariableName);
VariableNode->SetVariableValue(FString::SanitizeFloat(Value));
break;
}
Expand Down Expand Up @@ -246,8 +246,8 @@ void SDlgDataTextPropertyValue::HandleTextCommitted(const FText& NewText, ETextC
}
case EDlgDataDisplayVariableTreeNodeType::ClassFloat:
{
const float Value = NewString.IsNumeric() ? FCString::Atof(*NewString) : 0.f;
FNYReflectionHelper::SetVariable<FFloatProperty>(Actor.Get(), VariableName, Value);
const double Value = NewString.IsNumeric() ? FCString::Atod(*NewString) : 0.f;
FNYReflectionHelper::SetVariable<FDoubleProperty>(Actor.Get(), VariableName, Value);
break;
}
case EDlgDataDisplayVariableTreeNodeType::ClassBool:
Expand Down
48 changes: 40 additions & 8 deletions Source/DlgSystem/IO/DlgConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,24 @@ bool FDlgConfigParser::GetActiveWordAsFloat(float& FloatValue) const
return true;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool FDlgConfigParser::GetActiveWordAsDouble(double& DoubleValue) const
{
if (!HasValidWord())
{
return false;
}

const FString DoubleString = String.Mid(From, Len);
if (DoubleString.Len() == 0 || !DoubleString.IsNumeric())
{
return false;
}

DoubleValue = FCString::Atod(*DoubleString);
return true;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FString FDlgConfigParser::ConstructConfigFile(const UStruct* ReferenceType, void* SourceObject)
{
Expand Down Expand Up @@ -470,6 +488,10 @@ bool FDlgConfigParser::TryToReadPrimitiveProperty(void* TargetObject, FProperty*
{
return true;
}
if (ReadPrimitiveProperty<double, FDoubleProperty>(TargetObject, PropertyBase, std::bind(&FDlgConfigParser::GetAsDouble, this), "double", false))
{
return true;
}
if (ReadPrimitiveProperty<int32, FIntProperty>(TargetObject, PropertyBase, std::bind(&FDlgConfigParser::GetAsInt32, this), "int32", false))
{
return true;
Expand Down Expand Up @@ -558,8 +580,9 @@ bool FDlgConfigParser::ReadSet(void* TargetObject, FSetProperty& Property, UObje
const int32 Index = Helper.AddDefaultValue_Invalid_NeedsRehash();
bool bDone = false;
uint8* ElementPtr = Helper.GetElementPtr(Index);
if (FNYReflectionHelper::CastProperty<FBoolProperty>(Helper.ElementProp)) { *(bool*)ElementPtr = GetAsBool(); bDone = true; }
if (FNYReflectionHelper::CastProperty<FBoolProperty>(Helper.ElementProp)) { *(bool*)ElementPtr = GetAsBool(); bDone = true; }
else if (FNYReflectionHelper::CastProperty<FFloatProperty>(Helper.ElementProp)) { *(float*)ElementPtr = GetAsFloat(); bDone = true; }
else if (FNYReflectionHelper::CastProperty<FDoubleProperty>(Helper.ElementProp)) { *(double*)ElementPtr = GetAsDouble(); bDone = true; }
else if (FNYReflectionHelper::CastProperty<FIntProperty>(Helper.ElementProp)) { *(int32*)ElementPtr = GetAsInt32(); bDone = true; }
else if (FNYReflectionHelper::CastProperty<FInt64Property>(Helper.ElementProp)) { *(int64*)ElementPtr = GetAsInt64(); bDone = true; }
else if (FNYReflectionHelper::CastProperty<FNameProperty>(Helper.ElementProp)) { *(FName*)ElementPtr = GetAsName(); bDone = true; }
Expand Down Expand Up @@ -599,13 +622,14 @@ bool FDlgConfigParser::ReadMap(void* TargetObject, FMapProperty& Property, UObje

for (int32 i = 0; i < 2; ++i)
{
if (FNYReflectionHelper::CastProperty<FBoolProperty>(Props[i])) { *(bool*)Ptrs[i] = GetAsBool(); bDone = true; }
else if (FNYReflectionHelper::CastProperty<FFloatProperty>(Props[i])) { *(float*)Ptrs[i] = GetAsFloat(); bDone = true; }
else if (FNYReflectionHelper::CastProperty<FIntProperty>(Props[i])) { *(int32*)Ptrs[i] = GetAsInt32(); bDone = true; }
else if (FNYReflectionHelper::CastProperty<FInt64Property>(Props[i])) { *(int64*)Ptrs[i] = GetAsInt64(); bDone = true; }
else if (FNYReflectionHelper::CastProperty<FNameProperty>(Props[i])) { *(FName*)Ptrs[i] = GetAsName(); bDone = true; }
else if (FNYReflectionHelper::CastProperty<FStrProperty>(Props[i])) { *(FString*)Ptrs[i] = GetAsString(); bDone = true; }
else if (FNYReflectionHelper::CastProperty<FTextProperty>(Props[i])) { *(FText*)Ptrs[i] = GetAsText(); bDone = true; }
if (FNYReflectionHelper::CastProperty<FBoolProperty>(Props[i])) { *(bool*)Ptrs[i] = GetAsBool(); bDone = true; }
else if (FNYReflectionHelper::CastProperty<FFloatProperty>(Props[i])) { *(float*)Ptrs[i] = GetAsFloat(); bDone = true; }
else if (FNYReflectionHelper::CastProperty<FDoubleProperty>(Props[i])) { *(double*)Ptrs[i] = GetAsDouble();bDone = true; }
else if (FNYReflectionHelper::CastProperty<FIntProperty>(Props[i])) { *(int32*)Ptrs[i] = GetAsInt32(); bDone = true; }
else if (FNYReflectionHelper::CastProperty<FInt64Property>(Props[i])) { *(int64*)Ptrs[i] = GetAsInt64(); bDone = true; }
else if (FNYReflectionHelper::CastProperty<FNameProperty>(Props[i])) { *(FName*)Ptrs[i] = GetAsName(); bDone = true; }
else if (FNYReflectionHelper::CastProperty<FStrProperty>(Props[i])) { *(FString*)Ptrs[i] = GetAsString();bDone = true; }
else if (FNYReflectionHelper::CastProperty<FTextProperty>(Props[i])) { *(FText*)Ptrs[i] = GetAsText(); bDone = true; }
else if (i == 1 && bHasNullptr) { bDone = true; } // Value is nullptr, ignore
// else if (FNYReflectionHelper::CastProperty<FByteProperty>(Props[i])) { *(uint8*)Ptrs[i] = OnGetAsEnum(); bDone = true; } // would not work, check enum above

Expand Down Expand Up @@ -715,6 +739,14 @@ float FDlgConfigParser::GetAsFloat() const
return Value;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double FDlgConfigParser::GetAsDouble() const
{
double Value = 0.0f;
if (!GetActiveWordAsDouble(Value))
OnInvalidValue("Double");
return Value;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int32 FDlgConfigParser::GetAsInt32() const
{
int32 Value = 0;
Expand Down
7 changes: 7 additions & 0 deletions Source/DlgSystem/IO/DlgConfigParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ class DLGSYSTEM_API FDlgConfigParser : public IDlgParser
*/
bool GetActiveWordAsFloat(float& FloatValue) const;

/**
* @param DoubleValue: out double value if the call succeeds
* @return the active word converted, or an empty string if there isn't any
*/
bool GetActiveWordAsDouble(double& DoubleValue) const;

/**
*
* @param TabCount: amount of tabs at the begining of each new line
Expand Down Expand Up @@ -231,6 +237,7 @@ class DLGSYSTEM_API FDlgConfigParser : public IDlgParser

bool GetAsBool() const;
float GetAsFloat() const;
double GetAsDouble() const;
int32 GetAsInt32() const;
int64 GetAsInt64() const;
FName GetAsName() const;
Expand Down
9 changes: 9 additions & 0 deletions Source/DlgSystem/IO/DlgConfigWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ bool FDlgConfigWriter::WritePrimitiveElementToString(const FProperty* Property,
{
return true;
}
if (WritePrimitiveElementToStringTemplated<FDoubleProperty, double>(Property, Object, bInContainer, DoubleToString, PreS, PostS, Target))
{
return true;
}
if (WritePrimitiveElementToStringTemplated<FStrProperty, FString>(Property, Object, bInContainer, StringToString, PreS, PostS, Target))
{
return true;
Expand Down Expand Up @@ -241,6 +245,10 @@ bool FDlgConfigWriter::WritePrimitiveArrayToString(const FProperty* Property,
{
return true;
}
if (WritePrimitiveArrayToStringTemplated<FDoubleProperty, double>(ArrayProp, Object, DoubleToString, PreString, PostString, Target))
{
return true;
}
if (WritePrimitiveArrayToStringTemplated<FStrProperty, FString>(ArrayProp, Object, StringToString, PreString, PostString, Target))
{
return true;
Expand Down Expand Up @@ -591,6 +599,7 @@ bool FDlgConfigWriter::IsPrimitive(const FProperty* Property)
FNYReflectionHelper::CastProperty<FIntProperty>(Property) != nullptr ||
FNYReflectionHelper::CastProperty<FInt64Property>(Property) != nullptr ||
FNYReflectionHelper::CastProperty<FFloatProperty>(Property) != nullptr ||
FNYReflectionHelper::CastProperty<FDoubleProperty>(Property) != nullptr ||
FNYReflectionHelper::CastProperty<FStrProperty>(Property) != nullptr ||
FNYReflectionHelper::CastProperty<FNameProperty>(Property) != nullptr ||
FNYReflectionHelper::CastProperty<FTextProperty>(Property) != nullptr ||
Expand Down
5 changes: 5 additions & 0 deletions Source/DlgSystem/IO/DlgConfigWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ class DLGSYSTEM_API FDlgConfigWriter : public IDlgWriter
return FString::SanitizeFloat(FloatVal);
};

const std::function<FString(const double&)> DoubleToString = [](const double& DoubleVal) -> FString
{
return FString::SanitizeFloat(DoubleVal);
};

const std::function<FString(const FString&)> StringToString = [](const FString& String) -> FString
{
return FString("\"") + NormalizeEndlines(String) + "\"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ TArray<FName> FDlgCondition_Details::GetCallbackNamesForParticipant(bool bCurren
{
FNYReflectionHelper::GetVariableNames(
Dialogue->GetParticipantClass(ParticipantName),
FFloatProperty::StaticClass(),
FDoubleProperty::StaticClass(),
Suggestions,
GetDefault<UDlgSystemSettings>()->BlacklistedReflectionClasses
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ TArray<FName> FDlgEvent_Details::GetDialoguesParticipantEventNames() const
{
FNYReflectionHelper::GetVariableNames(
Dialogue->GetParticipantClass(ParticipantName),
FFloatProperty::StaticClass(),
FDoubleProperty::StaticClass(),
Suggestions,
GetDefault<UDlgSystemSettings>()->BlacklistedReflectionClasses
);
Expand Down Expand Up @@ -325,7 +325,7 @@ TArray<FName> FDlgEvent_Details::GetCurrentDialogueEventNames() const
case EDlgEventType::ModifyClassFloatVariable:
FNYReflectionHelper::GetVariableNames(
Dialogue->GetParticipantClass(ParticipantName),
FFloatProperty::StaticClass(),
FDoubleProperty::StaticClass(),
Suggestions,
GetDefault<UDlgSystemSettings>()->BlacklistedReflectionClasses
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ TArray<FName> FDlgTextArgument_Details::GetDialogueVariableNames(bool bCurrentOn
{
FNYReflectionHelper::GetVariableNames(
Dialogue->GetParticipantClass(ParticipantName),
FFloatProperty::StaticClass(),
FDoubleProperty::StaticClass(),
Suggestions,
GetDefault<UDlgSystemSettings>()->BlacklistedReflectionClasses
);
Expand Down

0 comments on commit 6ae9b61

Please sign in to comment.