Skip to content

Commit

Permalink
Async ability loading fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iniside committed Jul 27, 2017
1 parent a194087 commit 9cf8aac
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 27 deletions.
19 changes: 18 additions & 1 deletion ActionRPGGame.uproject
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"Engine",
"AIModule",
"UMG",
"CoreUObject"
"CoreUObject",
"WorldArchitectEditor"
]
}
],
Expand All @@ -25,6 +26,22 @@
{
"Name": "ActorSequenceEditor",
"Enabled": true
},
{
"Name": "OculusVR",
"Enabled": false
},
{
"Name": "SteamVR",
"Enabled": false
},
{
"Name": "ImagePlate",
"Enabled": true
},
{
"Name": "PerformanceMonitor",
"Enabled": true
}
]
}
5 changes: 3 additions & 2 deletions Config/DefaultEngine.ini
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ s.AsyncLoadingThreadEnabled=True
+CollisionChannelRedirects=(OldName="VehicleMovement",NewName="Vehicle")
+CollisionChannelRedirects=(OldName="PawnMovement",NewName="Pawn")

[/Script/Engine.Engine]
AssetManagerClassName=/Script/AbilityFramework.AFAssetManager

[/Script/Engine.PhysicsSettings]
DefaultGravityZ=-980.000000
DefaultTerminalVelocity=4000.000000
Expand Down Expand Up @@ -124,6 +127,4 @@ AsyncSceneSmoothingFactor=0.990000
InitialAverageFrameRate=0.016667
PhysXTreeRebuildRate=10

[/Script/Engine.Engine]
AssetManagerClassName=/Script/AbilityFramework.AFAssetManager

23 changes: 13 additions & 10 deletions Source/ActionRPGGame/UI/ARAbilityWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void UARAbilityWidget::Setbility(const FGameplayTag& InAbility)
{
cls = Manager->GetPrimaryAssetObjectClass<UARAbilityBase>(PrimaryAssetId);
FStreamableDelegate del = FStreamableDelegate::CreateUObject(this, &UARAbilityWidget::OnFinishedLoad, PrimaryAssetId);
AbilityLoadedHandle = Manager->LoadPrimaryAsset(PrimaryAssetId,
Manager->LoadPrimaryAsset(PrimaryAssetId,
TArray<FName>(),
del);
}
Expand All @@ -119,16 +119,19 @@ void UARAbilityWidget::Setbility(const FGameplayTag& InAbility)
}
void UARAbilityWidget::OnFinishedLoad(FPrimaryAssetId PrimaryAssetId)
{
UObject* loaded = AbilityLoadedHandle->GetLoadedAsset();
TSubclassOf<UARAbilityBase> cls = Cast<UClass>(loaded);
if (cls)
{
UARAbilityBase* CDO = cls.GetDefaultObject();
Icon = CDO->UIData->Icon;
}
if (UAssetManager* Manager = UAssetManager::GetIfValid())
{
Manager->UnloadPrimaryAsset(PrimaryAssetId);
UObject* loaded = Manager->GetPrimaryAssetObject(PrimaryAssetId);
TSubclassOf<UARAbilityBase> cls = Cast<UClass>(loaded);
if (cls)
{
UARAbilityBase* CDO = cls.GetDefaultObject();
Icon = CDO->UIData->Icon;
}

{
Manager->UnloadPrimaryAsset(PrimaryAssetId);
}
}
}
FReply UARAbilityWidget::NativeOnMouseButtonDown(const FGeometry& InGeometry
Expand Down Expand Up @@ -162,6 +165,6 @@ bool UARAbilityWidget::NativeOnDrop(const FGeometry& InGeometry
UARAbilityWidget* Payload = Cast<UARAbilityWidget>(InOperation->Payload);
Setbility(Payload->AbilityTag);

OwningComponent->NativeEquipAbility(AbilityTagDebug, AbilitySetIndex, AbilityIndex, InputBinding);
OwningComponent->NativeEquipAbility(Payload->AbilityTag, AbilitySetIndex, AbilityIndex);
return false;
}
2 changes: 0 additions & 2 deletions Source/ActionRPGGame/UI/ARAbilityWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ class ACTIONRPGGAME_API UARAbilityWidget : public UARAbilityInfoWidget
UFUNCTION(BlueprintCallable, Category = "ActionRPGGame|UI|Abilities")
void Setbility(const FGameplayTag& InAbility);

TSharedPtr<FStreamableHandle> AbilityLoadedHandle;

UFUNCTION()
void OnFinishedLoad(FPrimaryAssetId PrimaryAssetId);
virtual FReply NativeOnMouseButtonDown(const FGeometry& InGeometry
Expand Down
24 changes: 14 additions & 10 deletions Source/ActionRPGGame/UI/Abilities/ARUIAbilityManagerComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ void UARUIAbilityManagerComponent::BeginPlay()
AbilityTagsSet[0].SetNum(6);
AbilityTagsSet[1].SetNum(6);

InputBindingsSet.SetNum(2);
InputBindingsSet[0].SetNum(6);
InputBindingsSet[1].SetNum(6);
//InputBindingsSet.SetNum(2);
//InputBindingsSet[0].SetNum(6);
//InputBindingsSet[1].SetNum(6);

ActiveSet = 0;

Expand Down Expand Up @@ -117,7 +117,7 @@ void UARUIAbilityManagerComponent::SetInputTag(int32 SetIndex, int32 AbilityInde
}

void UARUIAbilityManagerComponent::NativeEquipAbility(const FGameplayTag& InAbilityTag, int32 AbilitySet
, int32 AbilityIndex, const FGameplayTag& InputBinding)
, int32 AbilityIndex)
{
//fake implementation untill I add AssetManager support.
APlayerController* MyPC = Cast<APlayerController>(GetOwner());
Expand All @@ -131,14 +131,16 @@ void UARUIAbilityManagerComponent::NativeEquipAbility(const FGameplayTag& InAbil
UAFAbilityComponent* AbilityComp = ABInt->GetAbilityComp();
if (!AbilityComp)
return;

if (!AbilityComp->OnAbilityAdded.IsAlreadyBound(this, &UARUIAbilityManagerComponent::OnAbilityReady))
{
FGameplayTag d = GetInputTag(AbilitySet, AbilityIndex);
AbilityComp->OnAbilityAdded.AddDynamic(this, &UARUIAbilityManagerComponent::OnAbilityReady);
}
TSubclassOf<UGAAbilityBase> AbilityClass = AbilityData->Items.FindRef(InAbilityTag).AbilityClass;
FARAbilityEquipInfo ABInfo(AbilitySet, AbilityIndex, InputBinding);
FARAbilityEquipInfo ABInfo(AbilitySet, AbilityIndex, GetInputTag(AbilitySet, AbilityIndex));
AwatingAbilityConfimation.Add(InAbilityTag, ABInfo);
AbilityComp->NativeAddAbility(AbilityClass, nullptr, InputBinding, false);
AbilityComp->NativeAddAbilityFromTag(InAbilityTag, nullptr, GetInputTag(AbilitySet, AbilityIndex));

}
void UARUIAbilityManagerComponent::OnAbilityReady(const FGameplayTag& InAbilityTag)
Expand Down Expand Up @@ -176,6 +178,8 @@ void UARUIAbilityManagerComponent::NativeOnAbilityReady(const FGameplayTag& InAb

void UARUIAbilityManagerComponent::SwitchSet()
{
//in reality it should be vlidated on server as well
//although this system is independent from ability component.
APlayerController* MyPC = Cast<APlayerController>(GetOwner());
if (!MyPC)
return;
Expand All @@ -191,8 +195,8 @@ void UARUIAbilityManagerComponent::SwitchSet()
if (ActiveSet == 0)
{
const TArray<FGameplayTag>& AbilityTags = AbilityTagsSet[0];
const TArray<FGameplayTag>& InputTags = InputBindingsSet[0];
const TArray<FGameplayTag>& InputTags2 = InputBindingsSet[1];
const FARAbilityInputBinding& InputTags = InputBindingsSet[0];
const FARAbilityInputBinding InputTags2 = InputBindingsSet[1];
for (int32 Idx = 0; Idx < 6; Idx++)
{
AbilityComp->SetBlockedInput(InputTags[Idx], true);
Expand All @@ -205,8 +209,8 @@ void UARUIAbilityManagerComponent::SwitchSet()
else if (ActiveSet == 1)
{
const TArray<FGameplayTag>& AbilityTags = AbilityTagsSet[1];
const TArray<FGameplayTag>& InputTags = InputBindingsSet[1];
const TArray<FGameplayTag>& InputTags2 = InputBindingsSet[0];
const FARAbilityInputBinding& InputTags = InputBindingsSet[1];
const FARAbilityInputBinding& InputTags2 = InputBindingsSet[0];
for (int32 Idx = 0; Idx < 6; Idx++)
{
AbilityComp->SetBlockedInput(InputTags[Idx], true);
Expand Down
24 changes: 22 additions & 2 deletions Source/ActionRPGGame/UI/Abilities/ARUIAbilityManagerComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ struct FARAbilityEquipInfo
InputBinding(InInputBinding)
{};
};
USTRUCT(BlueprintType)
struct FARAbilityInputBinding
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere)
TArray<FGameplayTag> InputBinding;

inline FGameplayTag& operator[](int32 InIndex)
{
return InputBinding[InIndex];
}

inline const FGameplayTag& operator[](int32 InIndex) const
{
return InputBinding[InIndex];
}
};
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FAROnAbilitySetChanged, int32, AbilitySet);
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class ACTIONRPGGAME_API UARUIAbilityManagerComponent : public UActorComponent
Expand Down Expand Up @@ -64,7 +82,9 @@ class ACTIONRPGGAME_API UARUIAbilityManagerComponent : public UActorComponent
TWeakObjectPtr<class UGAAbilityBase> WeaponFour;

int32 ActiveSet;
TArray<TArray<FGameplayTag>> InputBindingsSet;
UPROPERTY(EditAnywhere, Category = "Input Config")
TArray<FARAbilityInputBinding> InputBindingsSet;

TArray<TArray<FGameplayTag>> AbilityTagsSet;
TArray<TArray<TWeakObjectPtr<class UARAbilityBase>>> AbilitySet;
TMap<FGameplayTag, FARAbilityEquipInfo> AwatingAbilityConfimation;
Expand Down Expand Up @@ -98,7 +118,7 @@ class ACTIONRPGGAME_API UARUIAbilityManagerComponent : public UActorComponent
void SetInputTag(int32 SetIndex, int32 AbilityIndex, FGameplayTag InAbilityTag);

void NativeEquipAbility(const FGameplayTag& InAbilityTag, int32 AbilitySet
, int32 AbilityIndex, const FGameplayTag& InputBinding);
, int32 AbilityIndex);
UFUNCTION()
void OnAbilityReady(const FGameplayTag& InAbilityTag);

Expand Down

0 comments on commit 9cf8aac

Please sign in to comment.