Skip to content

Commit

Permalink
4.25 update
Browse files Browse the repository at this point in the history
- FProperty change was quite substantial for the plugin
- not fully thoroughly tested, CopyPropertyToPinnedBuffer and cleanup may not function as expected if assumptions on e.g. add to root are not held
  • Loading branch information
getnamo committed May 20, 2020
1 parent ae9af04 commit ce64020
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 81 deletions.
2 changes: 1 addition & 1 deletion GlobalEventSystem.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "0.4.0",
"VersionName": "0.5.0",
"FriendlyName": "GlobalEventSystem",
"Description": "Loosely coupled internal event system plugin for the unreal engine.",
"Category": "Other",
Expand Down
6 changes: 1 addition & 5 deletions Source/GlobalEventSystem/Private/GESDataTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
void FGESPinnedData::CopyPropertyToPinnedBuffer()
{
//Copy this property data to temp
Property->AddToRoot();
//Property->AddToRoot();
int32 Num = Property->GetSize();
PropertyData.SetNumUninitialized(Num);
FMemory::Memcpy(PropertyData.GetData(), PropertyPtr, Num);
Expand All @@ -14,10 +14,6 @@ void FGESPinnedData::CopyPropertyToPinnedBuffer()

void FGESPinnedData::CleanupPinnedData()
{
if (Property && Property->IsValidLowLevelFast())
{
Property->RemoveFromRoot();
}
PropertyData.Empty();
Property = nullptr;
PropertyPtr = nullptr;
Expand Down
66 changes: 33 additions & 33 deletions Source/GlobalEventSystem/Private/GESHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ TSharedPtr<FGESHandler> FGESHandler::PrivateDefaultHandler = MakeShareable(new F

bool FGESHandler::FirstParamIsCppType(UFunction* Function, const FString& TypeString)
{
TArray<UProperty*> Properties;
TArray<FProperty*> Properties;
FunctionParameters(Function, Properties);
if (Properties.Num() == 0)
{
Expand All @@ -16,9 +16,9 @@ bool FGESHandler::FirstParamIsCppType(UFunction* Function, const FString& TypeSt
return (FirstParam == TypeString);
}

bool FGESHandler::FirstParamIsSubclassOf(UFunction* Function, UClass* ClassType)
bool FGESHandler::FirstParamIsSubclassOf(UFunction* Function, FFieldClass* ClassType)
{
TArray<UProperty*> Properties;
TArray<FProperty*> Properties;
FunctionParameters(Function, Properties);
if (Properties.Num() == 0)
{
Expand All @@ -42,19 +42,19 @@ FString FGESHandler::EmitEventLogString(const FGESEmitData& EmitData)
return EmitData.Domain + TEXT(".") + EmitData.Event;
}

void FGESHandler::FunctionParameters(UFunction* Function, TArray<UProperty*>& OutParamProperties)
void FGESHandler::FunctionParameters(UFunction* Function, TArray<FProperty*>& OutParamProperties)
{
TFieldIterator<UProperty> Iterator(Function);
TFieldIterator<FProperty> Iterator(Function);

while (Iterator && (Iterator->PropertyFlags & CPF_Parm))
{
UProperty* Prop = *Iterator;
FProperty* Prop = *Iterator;
OutParamProperties.Add(Prop);
++Iterator;
}
}

bool FGESHandler::FunctionHasValidParams(UFunction* Function, UClass* ClassType, const FGESEmitData& EmitData, const FGESEventListener& Listener)
bool FGESHandler::FunctionHasValidParams(UFunction* Function, FFieldClass* ClassType, const FGESEmitData& EmitData, const FGESEventListener& Listener)
{
if (FirstParamIsSubclassOf(Function, ClassType))
{
Expand Down Expand Up @@ -110,7 +110,7 @@ void FGESHandler::UnpinEvent(const FString& Domain, const FString& EventName)
{
FGESEvent& Event = EventMap[KeyString];
Event.bPinned = false;
Event.PinnedData.Property->RemoveFromRoot();
//Event.PinnedData.Property->RemoveFromRoot();
//Event.PinnedData.PropertyData.Empty(); not sure if safe to delete instead of rebuilding on next pin
}
}
Expand Down Expand Up @@ -325,15 +325,15 @@ void FGESHandler::EmitEvent(const FGESEmitData& EmitData, UStruct* Struct, void*
bool bValidateStructs = Options.bValidateStructTypes;
EmitToListenersWithData(EmitData, [&EmitData, Struct, StructPtr, bValidateStructs](const FGESEventListener& Listener)
{
if (FunctionHasValidParams(Listener.Function, UStructProperty::StaticClass(), EmitData, Listener))
if (FunctionHasValidParams(Listener.Function, FStructProperty::StaticClass(), EmitData, Listener))
{
if (bValidateStructs)
{
//For structs we can have different mismatching structs at this point check class types
//optimization note: unroll the above function for structs to avoid double param lookup
TArray<UProperty*> Properties;
TArray<FProperty*> Properties;
FunctionParameters(Listener.Function, Properties);
UStructProperty* StructProperty = Cast<UStructProperty>(Properties[0]);
FStructProperty* StructProperty = CastField<FStructProperty>(Properties[0]);
if (StructProperty->Struct == Struct)
{
Listener.Receiver->ProcessEvent(Listener.Function, StructPtr);
Expand All @@ -360,7 +360,7 @@ void FGESHandler::EmitEvent(const FGESEmitData& EmitData, const FString& ParamDa
FString MutableParamString = ParamData;
EmitToListenersWithData(EmitData, [&EmitData, &MutableParamString](const FGESEventListener& Listener)
{
if (FunctionHasValidParams(Listener.Function, UStrProperty::StaticClass(), EmitData, Listener))
if (FunctionHasValidParams(Listener.Function, FStrProperty::StaticClass(), EmitData, Listener))
{
Listener.Receiver->ProcessEvent(Listener.Function, &MutableParamString);
}
Expand All @@ -371,7 +371,7 @@ void FGESHandler::EmitEvent(const FGESEmitData& EmitData, UObject* ParamData)
{
EmitToListenersWithData(EmitData, [&EmitData, ParamData](const FGESEventListener& Listener)
{
if (FunctionHasValidParams(Listener.Function, UObjectProperty::StaticClass(), EmitData, Listener))
if (FunctionHasValidParams(Listener.Function, FObjectProperty::StaticClass(), EmitData, Listener))
{
FGESDynamicArg ParamWrapper;
ParamWrapper.Arg01 = ParamData;
Expand All @@ -384,7 +384,7 @@ void FGESHandler::EmitEvent(const FGESEmitData& EmitData, float ParamData)
{
EmitToListenersWithData(EmitData, [&EmitData, &ParamData](const FGESEventListener& Listener)
{
if (FunctionHasValidParams(Listener.Function, UNumericProperty::StaticClass(), EmitData, Listener))
if (FunctionHasValidParams(Listener.Function, FNumericProperty::StaticClass(), EmitData, Listener))
{
Listener.Receiver->ProcessEvent(Listener.Function, &ParamData);
}
Expand All @@ -395,7 +395,7 @@ void FGESHandler::EmitEvent(const FGESEmitData& EmitData, int32 ParamData)
{
EmitToListenersWithData(EmitData, [&EmitData, &ParamData](const FGESEventListener& Listener)
{
if (FunctionHasValidParams(Listener.Function, UNumericProperty::StaticClass(), EmitData, Listener))
if (FunctionHasValidParams(Listener.Function, FNumericProperty::StaticClass(), EmitData, Listener))
{
Listener.Receiver->ProcessEvent(Listener.Function, &ParamData);
}
Expand All @@ -406,7 +406,7 @@ void FGESHandler::EmitEvent(const FGESEmitData& EmitData, bool ParamData)
{
EmitToListenersWithData(EmitData, [&EmitData, &ParamData](const FGESEventListener& Listener)
{
if (FunctionHasValidParams(Listener.Function, UBoolProperty::StaticClass(), EmitData, Listener))
if (FunctionHasValidParams(Listener.Function, FBoolProperty::StaticClass(), EmitData, Listener))
{
Listener.Receiver->ProcessEvent(Listener.Function, &ParamData);
}
Expand All @@ -418,7 +418,7 @@ void FGESHandler::EmitEvent(const FGESEmitData& EmitData, const FName& ParamData
FName MutableName = ParamData;
EmitToListenersWithData(EmitData, [&EmitData, &ParamData, &MutableName](const FGESEventListener& Listener)
{
if (FunctionHasValidParams(Listener.Function, UNameProperty::StaticClass(), EmitData, Listener))
if (FunctionHasValidParams(Listener.Function, FNameProperty::StaticClass(), EmitData, Listener))
{
Listener.Receiver->ProcessEvent(Listener.Function, &MutableName);
}
Expand All @@ -437,7 +437,7 @@ bool FGESHandler::EmitEvent(const FGESEmitData& EmitData)
}
return false;
}
UProperty* ParameterProp = EmitData.Property;
FProperty* ParameterProp = EmitData.Property;
void* PropPtr = EmitData.PropertyPtr;

//no params specified
Expand All @@ -454,12 +454,12 @@ bool FGESHandler::EmitEvent(const FGESEmitData& EmitData)
Listener.OnePropertyFunctionDelegate.ExecuteIfBound(Wrapper);
return;
}
TFieldIterator<UProperty> Iterator(Listener.Function);
TFieldIterator<FProperty> Iterator(Listener.Function);

TArray<UProperty*> Properties;
TArray<FProperty*> Properties;
while (Iterator && (Iterator->PropertyFlags & CPF_Parm))
{
UProperty* Prop = *Iterator;
FProperty* Prop = *Iterator;
Properties.Add(Prop);
++Iterator;
}
Expand All @@ -475,29 +475,29 @@ bool FGESHandler::EmitEvent(const FGESEmitData& EmitData)
}
});
}
else if (ParameterProp->IsA<UStructProperty>())
else if (ParameterProp->IsA<FStructProperty>())
{
UStructProperty* StructProperty = ExactCast<UStructProperty>(ParameterProp);
FStructProperty* StructProperty = CastField<FStructProperty>(ParameterProp);
EmitEvent(EmitData, StructProperty->Struct, PropPtr);
return true;
}
else if (ParameterProp->IsA<UStrProperty>())
else if (ParameterProp->IsA<FStrProperty>())
{
UStrProperty* StrProperty = Cast<UStrProperty>(ParameterProp);
FStrProperty* StrProperty = CastField<FStrProperty>(ParameterProp);
FString Data = StrProperty->GetPropertyValue(PropPtr);
EmitEvent(EmitData, Data);
return true;
}
else if (ParameterProp->IsA<UObjectProperty>())
else if (ParameterProp->IsA<FObjectProperty>())
{
UObjectProperty* ObjectProperty = Cast<UObjectProperty>(ParameterProp);
FObjectProperty* ObjectProperty = CastField<FObjectProperty>(ParameterProp);
UObject* Data = ObjectProperty->GetPropertyValue(PropPtr);
EmitEvent(EmitData, Data);
return true;
}
else if (ParameterProp->IsA<UNumericProperty>())
else if (ParameterProp->IsA<FNumericProperty>())
{
UNumericProperty* NumericProperty = Cast<UNumericProperty>(ParameterProp);
FNumericProperty* NumericProperty = CastField<FNumericProperty>(ParameterProp);
if (NumericProperty->IsFloatingPoint())
{
double Data = NumericProperty->GetFloatingPointPropertyValue(PropPtr);
Expand All @@ -511,16 +511,16 @@ bool FGESHandler::EmitEvent(const FGESEmitData& EmitData)
return true;
}
}
else if (ParameterProp->IsA<UBoolProperty>())
else if (ParameterProp->IsA<FBoolProperty>())
{
UBoolProperty* BoolProperty = Cast<UBoolProperty>(ParameterProp);
FBoolProperty* BoolProperty = CastField<FBoolProperty>(ParameterProp);
bool Data = BoolProperty->GetPropertyValue(PropPtr);
EmitEvent(EmitData, Data);
return true;
}
else if (ParameterProp->IsA<UNameProperty>())
else if (ParameterProp->IsA<FNameProperty>())
{
UNameProperty* NameProperty = Cast<UNameProperty>(ParameterProp);
FNameProperty* NameProperty = CastField<FNameProperty>(ParameterProp);
FName Data = NameProperty->GetPropertyValue(PropPtr);
EmitEvent(EmitData, Data);
return true;
Expand Down
6 changes: 3 additions & 3 deletions Source/GlobalEventSystem/Private/GESHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ class FGESHandler

//can check function signature vs e.g. FString
static bool FirstParamIsCppType(UFunction* Function, const FString& TypeString);
static bool FirstParamIsSubclassOf(UFunction* Function, UClass* ClassType);
static bool FirstParamIsSubclassOf(UFunction* Function, FFieldClass* ClassType);
static FString ListenerLogString(const FGESEventListener& Listener);
static FString EventLogString(const FGESEvent& Event);
static FString EmitEventLogString(const FGESEmitData& EmitData);
static void FunctionParameters(UFunction* Function, TArray<UProperty*>& OutParamProperties);
static void FunctionParameters(UFunction* Function, TArray<FProperty*>& OutParamProperties);

//this function logs warnings otherwise
static bool FunctionHasValidParams(UFunction* Function, UClass* ClassType, const FGESEmitData& EmitData, const FGESEventListener& Listener);
static bool FunctionHasValidParams(UFunction* Function, FFieldClass* ClassType, const FGESEmitData& EmitData, const FGESEventListener& Listener);

//Key == TargetDomain.TargetFunction
TMap<FString, FGESEvent> EventMap;
Expand Down
Loading

0 comments on commit ce64020

Please sign in to comment.