From e5fbeec365ca4f4095ef3dff8f9b38db7d6badea Mon Sep 17 00:00:00 2001 From: Alexei Gladkikh Date: Fri, 10 May 2024 15:10:31 +0300 Subject: [PATCH 1/2] #288 Refactored object checking --- .../Cloud9/Character/Cloud9AIController.cpp | 2 +- .../Components/Cloud9AnimationComponent.cpp | 47 +--- .../Components/Cloud9EffectsComponent.cpp | 14 +- .../Components/Cloud9HealthComponent.cpp | 60 +---- .../Components/Cloud9InventoryComponent.cpp | 194 ++++---------- .../Effects/Cloud9CharacterEffectTrait.cpp | 10 +- .../Effects/Cloud9CharacterShieldEffect.cpp | 4 +- .../Contollers/Cloud9KeyboardController.cpp | 23 +- .../Contollers/Cloud9MouseController.cpp | 47 ++-- .../Cloud9/Environment/Cloud9LinearDoor.cpp | 2 +- .../Environment/Cloud9PracticeSpawner.cpp | 22 +- Source/Cloud9/Game/Cloud9AssetManager.cpp | 21 +- Source/Cloud9/Game/Cloud9GameState.cpp | 21 +- Source/Cloud9/Modes/Cloud9DefaultGameMode.cpp | 7 +- Source/Cloud9/Modes/Cloud9GameMode.cpp | 8 +- .../Physicals/Cloud9PhysicalMaterial.cpp | 6 +- Source/Cloud9/Tools/Cloud9ToolsLibrary.cpp | 17 +- .../Components/CooldownActionComponent.h | 11 +- Source/Cloud9/Tools/Extensions/AActor.h | 8 +- Source/Cloud9/Tools/Extensions/ACharacter.h | 2 +- .../Tools/Extensions/APlayerController.h | 2 +- Source/Cloud9/Tools/Extensions/FVector.cpp | 2 +- Source/Cloud9/Tools/Extensions/UObject.h | 20 +- Source/Cloud9/Tools/Extensions/UWorld.h | 17 +- Source/Cloud9/Tools/Macro/Common.h | 41 ++- Source/Cloud9/Tools/Macro/Logging.h | 24 +- .../Weapon/Assets/WeaponDefinitionsAsset.cpp | 53 ++-- .../Weapon/Classes/Cloud9WeaponBase.cpp | 239 ++++++------------ .../Cloud9/Weapon/Classes/Cloud9WeaponBase.h | 6 +- .../Weapon/Classes/Cloud9WeaponFirearm.cpp | 24 +- .../Weapon/Classes/Cloud9WeaponGrenade.cpp | 55 +--- .../Weapon/Classes/Cloud9WeaponMelee.cpp | 7 +- .../Notifiers/Cloud9AnimNotifyPlaySound.cpp | 45 ++-- .../Weapon/Sounds/Cloud9SoundPlayer.cpp | 2 +- .../Cloud9/Weapon/Structures/WeaponConfig.cpp | 4 +- .../Weapon/Structures/WeaponDefinition.h | 2 +- 36 files changed, 334 insertions(+), 735 deletions(-) diff --git a/Source/Cloud9/Character/Cloud9AIController.cpp b/Source/Cloud9/Character/Cloud9AIController.cpp index 0d1633bfc..fa89a3b03 100644 --- a/Source/Cloud9/Character/Cloud9AIController.cpp +++ b/Source/Cloud9/Character/Cloud9AIController.cpp @@ -46,7 +46,7 @@ void ACloud9AIController::OnMoveCompleted(FAIRequestID RequestID, const FPathFol void ACloud9AIController::OnPossess(APawn* InPawn) { Super::OnPossess(InPawn); - CheckIsValid(InPawn, Error, "Pawn is invalid") + AssertOrVoid(InPawn, Error, "Pawn is invalid"); BaseLocation = InPawn->GetActorLocation(); } diff --git a/Source/Cloud9/Character/Components/Cloud9AnimationComponent.cpp b/Source/Cloud9/Character/Components/Cloud9AnimationComponent.cpp index 99142a9a3..cdc0d9b89 100644 --- a/Source/Cloud9/Character/Components/Cloud9AnimationComponent.cpp +++ b/Source/Cloud9/Character/Components/Cloud9AnimationComponent.cpp @@ -12,45 +12,28 @@ UCloud9AnimationComponent::UCloud9AnimationComponent() {} UAnimInstance* UCloud9AnimationComponent::GetAnimInstance() const { let Character = GetOwner(); - - if (not IsValid(Character)) - { - log(Error, "[Component='%s'] Character is invalid", *GetName()); - return nullptr; - } + AssertOrReturn(IsValid(Character), nullptr, Error, "Character is invalid"); let Mesh = Character->GetMesh(); - - if (not IsValid(Mesh)) - { - log(Error, "[Component='%s'] Mesh is invalid", *GetName()); - return nullptr; - } + AssertOrReturn(IsValid(Mesh), nullptr, Error, "Mesh is invalid"); return Mesh->GetAnimInstance(); } bool UCloud9AnimationComponent::PlayMontage(UAnimMontage* Montage, float StartTime, float Rate) const { - if (not IsValid(Montage)) - { - log(Error, "[Component='%s'] Montage is invalid", *GetName()); - return false; - } + AssertOrReturn(IsValid(Montage), false, Error, "Montage is invalid"); let AnimInstance = GetAnimInstance(); + AssertOrReturn( + IsValid(AnimInstance), false, + Error, "AnimInstance is invalid for montage '%s'", + *Montage->GetName()); - if (not IsValid(AnimInstance)) - { - log(Error, "[Component='%s'] AnimInstance is invalid for montage '%s'", *GetName(), *Montage->GetName()); - return false; - } - - if (not AnimInstance->Montage_Play(Montage, Rate, EMontagePlayReturnType::MontageLength, StartTime)) - { - log(Error, "[Component='%s'] Can't play montage '%s'", *GetName(), *Montage->GetName()); - return false; - } + AssertOrReturn( + AnimInstance->Montage_Play(Montage, Rate, EMontagePlayReturnType::MontageLength, StartTime), false, + Error, "Can't play montage '%s'", *Montage->GetName() + ); return true; } @@ -58,12 +41,6 @@ bool UCloud9AnimationComponent::PlayMontage(UAnimMontage* Montage, float StartTi bool UCloud9AnimationComponent::IsAnyMontagePlaying() const { let AnimInstance = GetAnimInstance(); - - if (not IsValid(AnimInstance)) - { - log(Error, "[Component='%s'] AnimInstance is invalid", *GetName()); - return false; - } - + AssertOrReturn(IsValid(AnimInstance), false, Error, "AnimInstance is invalid"); return AnimInstance->IsAnyMontagePlaying(); } diff --git a/Source/Cloud9/Character/Components/Cloud9EffectsComponent.cpp b/Source/Cloud9/Character/Components/Cloud9EffectsComponent.cpp index 050be0c23..afaf12527 100644 --- a/Source/Cloud9/Character/Components/Cloud9EffectsComponent.cpp +++ b/Source/Cloud9/Character/Components/Cloud9EffectsComponent.cpp @@ -42,7 +42,7 @@ UCloud9CharacterEffectTrait* UCloud9EffectsComponent::AddEffect( AppliedCanDamagedEffects.Add(Effect); } - log(Verbose, "[Component='%s'] Apply effect class='%s' effect='%s' (%p) on owner='%s'", + log(Verbose, "[%s] Apply effect class='%s' effect='%s' (%p) on owner='%s'", *GetName(), *EffectClass->GetName(), *Effect->GetName(), Effect, *GetOwnerName()); return Effect; @@ -54,11 +54,7 @@ UCloud9CharacterEffectTrait* UCloud9EffectsComponent::AddEffect( bool UCloud9EffectsComponent::RemoveEffect(UCloud9CharacterEffectTrait* Effect) { - if (AppliedEffects.Remove(Effect) == 0) - { - log(Warning, "[Component='%s'] Effect '%s' not found", *GetName(), *Effect->GetName()); - return false; - } + AssertOrReturn(AppliedEffects.Remove(Effect) != 0, false, Warning, "Effect '%s' not found", *Effect->GetName()); AppliedCanDamagedEffects.Remove(Effect); AppliedCanTickEffects.Remove(Effect); @@ -67,7 +63,7 @@ bool UCloud9EffectsComponent::RemoveEffect(UCloud9CharacterEffectTrait* Effect) Effect->OnRemove(); - log(Verbose, "[Component='%s'] Remove effect='%s' (%p) on owner='%s'", + log(Verbose, "[%s] Remove effect='%s' (%p) on owner='%s'", *GetName(), *Effect->GetName(), Effect, *GetOwnerName()); return true; } @@ -82,10 +78,10 @@ void UCloud9EffectsComponent::RemoveAllEffects() UCloud9HealthComponent* UCloud9EffectsComponent::GetHealthComponent() const { let Character = GetOwner(); - CheckIsValid(Character, Error, "Owner is invalid", nullptr); + AssertOrReturn(IsValid(Character), nullptr, Error, "Owner is invalid"); let HealthComponent = Character->GetHealthComponent(); - CheckIsValid(HealthComponent, Error, "Owner HealthComponent is invalid", nullptr); + AssertOrReturn(HealthComponent, nullptr, Error, "Owner HealthComponent is invalid"); return HealthComponent; } diff --git a/Source/Cloud9/Character/Components/Cloud9HealthComponent.cpp b/Source/Cloud9/Character/Components/Cloud9HealthComponent.cpp index 9e2208525..90ad6b3aa 100644 --- a/Source/Cloud9/Character/Components/Cloud9HealthComponent.cpp +++ b/Source/Cloud9/Character/Components/Cloud9HealthComponent.cpp @@ -24,46 +24,26 @@ void UCloud9HealthComponent::Initialize(FHealthConfig Config) bool UCloud9HealthComponent::TakeHealthDamage(float Change) { - if (Change >= 0.0f) - { - return ChangeHealth(Health - Change); - } - - log(Warning, "Can't increase health using this method Change=%f", Change); - return false; + AssertOrReturn(Change >= 0.0f, false, Warning, "Can't increase health using this method Change=%f", Change); + return ChangeHealth(Health - Change); } bool UCloud9HealthComponent::TakeArmorDamage(float Change) { - if (Change >= 0.0f) - { - return ChangeArmor(Armor - Change); - } - - log(Warning, "Can't increase armor using this method Change=%f", Change); - return false; + AssertOrReturn(Change >= 0.0f, false, Warning, "Can't increase armor using this method Change=%f", Change); + return ChangeArmor(Armor - Change); } bool UCloud9HealthComponent::IncreaseHealth(float Change) { - if (Change >= 0.0f) - { - return ChangeHealth(Health + Change); - } - - log(Warning, "Can't decimante health using this method Change=%f", Change); - return false; + AssertOrReturn(Change >= 0.0f, false, Warning, "Can't decimante health using this method Change=%f", Change); + return ChangeHealth(Health + Change); } bool UCloud9HealthComponent::IncreaseArmor(float Change) { - if (Change >= 0.0f) - { - return ChangeArmor(Health + Change); - } - - log(Warning, "Can't decimante armor using this method Change=%f", Change); - return false; + AssertOrReturn(Change >= 0.0f, false, Warning, "Can't decimante armor using this method Change=%f", Change); + return ChangeArmor(Health + Change); } bool UCloud9HealthComponent::IsInvulnerable() const { return bIsInvulnerable; } @@ -79,16 +59,11 @@ bool UCloud9HealthComponent::ChangeHealth(float NewHealth) if (Health == 0.0f) { - let Owner = GetOwner(); - - if (not IsValid(Owner)) - { - log(Fatal, "[Component=%s] Owner isn't valid", *GetName()); - return false; - } + let MyOwner = GetOwner(); + AssertOrReturn(IsValid(MyOwner), false, Fatal, "Owner isn't valid"); bIsAlive = false; - OnCharacterDie.Broadcast(Owner); + OnCharacterDie.Broadcast(MyOwner); } return true; @@ -118,12 +93,7 @@ void UCloud9HealthComponent::OnRegister() Super::OnRegister(); let MyOwner = GetOwner(); - - if (not IsValid(MyOwner)) - { - log(Error, "HealthComponent isn't valid"); - return; - } + AssertOrVoid(IsValid(MyOwner), Error, "HealthComponent isn't valid"); // Register twice or delegate add twice (?) MyOwner->OnTakePointDamage.AddUniqueDynamic(this, &UCloud9HealthComponent::OnTakePointDamage); @@ -134,11 +104,7 @@ void UCloud9HealthComponent::AddAttackerScore(const AController* InstigatedBy) c { if (not bIsAlive) { - if (not IsValid(InstigatedBy)) - { - log(Error, "[Component = %s] InstigatedBy is invalid", *GetName()); - return; - } + AssertOrVoid(IsValid(InstigatedBy), Error, "InstigatedBy is invalid"); // TODO: Make score component if (let Character = Cast(InstigatedBy->GetCharacter()); IsValid(Character)) diff --git a/Source/Cloud9/Character/Components/Cloud9InventoryComponent.cpp b/Source/Cloud9/Character/Components/Cloud9InventoryComponent.cpp index 28c8d026d..caed8d128 100644 --- a/Source/Cloud9/Character/Components/Cloud9InventoryComponent.cpp +++ b/Source/Cloud9/Character/Components/Cloud9InventoryComponent.cpp @@ -54,82 +54,52 @@ bool UCloud9InventoryComponent::Initialize(const TArray& WeaponCo | ETContainer::Filter{[](let& Config) { return IsValid(Config); }} | ETContainer::ForEach{[this](let& Config) { AddWeapon(Config); }}; - if (not SelectWeapon(WeaponSlot)) - { - log(Error, - "[Actor='%s'] Can't select default weapon slot='%s'", - *GetName(), WeaponSlot | EUEnum::GetValueName() | EFName::ToCStr()); - return false; - } + AssertOrReturn( + SelectWeapon(WeaponSlot), false, + Error, "Can't select default weapon slot='%s'", WeaponSlot | EUEnum::GetValueName() | EFName::ToCStr()); return true; } bool UCloud9InventoryComponent::SelectWeaponImpl(EWeaponSlot Slot, bool Instant, bool Force) { - if (Slot == EWeaponSlot::NotSelected) - { - log(Warning, "[Inventory='%s'] Should not be called with EWeaponSlot::NotSelected", *GetName()); - return false; - } - - if (IsWeaponChanging()) - { - log(Warning, "[Inventory='%s'] Weapon deploying in progress", *GetName()); - return false; - } + AssertOrReturn( + Slot != EWeaponSlot::NotSelected, false, + Warning, "Should not be called with EWeaponSlot::NotSelected"); - if (not Force and Slot == SelectedWeaponSlot) - { - log(Warning, "[Inventory='%s'] No switching will be performed", *GetName()); - return false; - } + AssertOrReturn(not IsWeaponChanging(), false, Warning, "Weapon deploying in progress"); + AssertOrReturn(Force or Slot != SelectedWeaponSlot, false, Warning, "No switching will be performed"); let PendingWeapon = GetWeaponAt(Slot); - - if (not IsValid(PendingWeapon)) - { - log(Warning, "[Inventory='%s'] Weapon at requested slot='%d' not set or invalid", *GetName(), Slot); - return false; - } + AssertOrReturn(IsValid(PendingWeapon), false, Warning, "Weapon at requested slot='%d' not set or invalid", Slot); if (SelectedWeaponSlot == EWeaponSlot::NotSelected) { let SelectedWeapon = GetWeaponAt(SelectedWeaponSlot); - assertf( + AssertOrCrash( not IsValid(SelectedWeapon), - "[Inventory='%s'] SelectedWeapon should not be valid if slot == EWeaponSlot::NotSelected", + "[%s] SelectedWeapon should not be valid if slot == EWeaponSlot::NotSelected", *GetName()); - if (PendingWeapon->ChangeState(EWeaponBond::Armed, Instant, Force)) - { - SelectedWeaponSlot = Slot; - return true; - } + AssertOrReturn( + PendingWeapon->ChangeState(EWeaponBond::Armed, Instant, Force), false, + Error, "Can't select starting weapon"); - log(Error, "[Inventory='%s'] Can't select starting weapon", *GetName()); - return false; + SelectedWeaponSlot = Slot; + return true; } if (let SelectedWeapon = GetSelectedWeapon(); IsValid(SelectedWeapon)) { - if (not SelectedWeapon->ChangeState(EWeaponBond::Holstered, true, Force)) - { - log(Verbose, - "[Inventory='%s'] Can't change state of selected weapon from slot='%d'", - *GetName(), SelectedWeaponSlot); - return false; - } + AssertOrReturn( + SelectedWeapon->ChangeState(EWeaponBond::Holstered, true, Force), false, + Verbose, "Can't change state of selected weapon from slot='%d'", SelectedWeaponSlot); } - if (not PendingWeapon->ChangeState(EWeaponBond::Armed, Instant, Force)) - { - log(Verbose, - "[Inventory='%s'] Can't change state of pending weapon to slot='%d'", - *GetName(), Slot); - return false; - } + AssertOrReturn( + PendingWeapon->ChangeState(EWeaponBond::Armed, Instant, Force), false, + Verbose, "Can't change state of pending weapon to slot='%d'", SelectedWeaponSlot); SelectedWeaponSlot = Slot; @@ -153,25 +123,14 @@ ACloud9WeaponBase* UCloud9InventoryComponent::GetWeaponAt(EWeaponSlot Slot) cons bool UCloud9InventoryComponent::ShoveWeapon(EWeaponSlot Slot, ACloud9WeaponBase* Weapon) { - if (not IsValid(Weapon)) - { - log(Error, "Weapon is invalid to shove into inventory"); - return false; - } + AssertOrReturn(IsValid(Weapon), false, Error, "Weapon is invalid to shove into inventory"); let Character = GetOwner(); + AssertOrReturn(IsValid(Character), false, Error, "Inventory owner wasn't set"); - if (not IsValid(Character)) - { - log(Error, "Inventory owner wasn't set"); - return false; - } - - if (not Weapon->AddToInventory(Character, Slot)) - { - log(Error, "Failed add to inventory weapon '%s'", *Weapon->GetName()); - return false; - } + AssertOrReturn( + Weapon->AddToInventory(Character, Slot), false, + Error, "Failed add to inventory weapon '%s'", *Weapon->GetName()); WeaponAt(Slot) = Weapon; return true; @@ -180,20 +139,10 @@ bool UCloud9InventoryComponent::ShoveWeapon(EWeaponSlot Slot, ACloud9WeaponBase* bool UCloud9InventoryComponent::DropWeapon(EWeaponSlot Slot, FVector ViewLocation, float Angle, float Impulse) { let Character = GetOwner(); - - if (not IsValid(Character)) - { - log(Error, "Inventory owner wasn't set"); - return false; - } + AssertOrReturn(IsValid(Character), false, Error, "Inventory owner wasn't set"); let Weapon = WeaponAt(Slot); - - if (not Weapon) - { - log(Error, "Inventory cell for slot '%d' is empty", Slot); - return false; - } + AssertOrReturn(Weapon, false, Error, "Inventory cell for slot '%d' is empty", Slot); let StartLocation = Weapon->GetActorLocation(); let ViewDirection = ViewLocation - StartLocation | EFVector::Normalize{}; @@ -201,11 +150,9 @@ bool UCloud9InventoryComponent::DropWeapon(EWeaponSlot Slot, FVector ViewLocatio let Direction = ViewDirection.RotateAngleAxis(-Angle, RotationAxis); - if (not Weapon->RemoveFromInventory()) - { - log(Error, "Failed to remove from inventory weapon '%s'", *Weapon->GetName()); - return false; - } + AssertOrReturn( + Weapon->RemoveFromInventory(), false, + Error, "Failed to remove from inventory weapon '%s'", *Weapon->GetName()); Weapon->SetActorLocation(StartLocation); @@ -218,61 +165,31 @@ bool UCloud9InventoryComponent::DropWeapon(EWeaponSlot Slot, FVector ViewLocatio bool UCloud9InventoryComponent::AddWeapon(const FWeaponConfig& Config, bool Select, bool Force) { - if (let Character = GetOwner(); not IsValid(Character)) - { - log(Error, "[Inventory='%s'] Owner wasn't set", *GetName()); - return false; - } - - if (IsWeaponChanging()) - { - log(Verbose, - "[Inventory='%s'] Weapon deploying in progress when added by config='%s'", - *GetName(), *Config.ToString()); - return false; - } + let Character = GetOwner(); + AssertOrReturn(IsValid(Character), false, Error, "Inventory owner wasn't set"); + AssertOrReturn( + not IsWeaponChanging(), false, + Verbose, "Weapon deploying in progress when added by config='%s'", *Config.ToString()); let Slot = Config.GetWeaponSlot(); if (WeaponAt(Slot)) { - if (not Force) - { - log(Error, "[Inventory='%s'] Weapon slot already occupied", *GetName()); - return false; - } - - if (not RemoveWeapon(Slot)) - { - log(Error, "[Inventory='%s'] Can't remove weapon", *GetName()); - return false; - } + AssertOrReturn(Force, false, Error, "Weapon slot already occupied"); + AssertOrReturn(RemoveWeapon(Slot), false, Error, "Can't remove weapon"); } let Weapon = Config.SpawnWeapon(GetWorld()); - if (not IsValid(Weapon)) - { - log(Error, "[Inventory='%s'] Can't spawn weapon by config: %s", *GetName(), *Config.ToString()); - return false; - } - - if (not ShoveWeapon(Slot, Weapon)) - { - log(Error, "[Inventory='%s'] Can't shove weapon by config: %s", *GetName(), *Config.ToString()); - return false; - } + AssertOrReturn(IsValid(Weapon), false, Error, "Can't spawn weapon by config: %s", *Config.ToString()); + AssertOrReturn(ShoveWeapon(Slot, Weapon), false, Error, "Can't shove weapon by config: %s", *Config.ToString()); if (Select) { - if (not SelectWeapon(Slot)) - { - log(Error, "[Inventory='%s'] New weapon selection failure: %s", *GetName(), *Config.ToString()); - return false; - } + AssertOrReturn(SelectWeapon(Slot), false, Error, "New weapon selection failure: %s", *Config.ToString()); } - log(Verbose, "[Inventory='%s'] Added configured weapon = '%s'", *GetName(), *Config.ToString()); + log(Verbose, "[%s] Added configured weapon = '%s'", *GetName(), *Config.ToString()); WeaponsCount++; OnWeaponAddDelegate.Broadcast(Weapon); @@ -281,23 +198,12 @@ bool UCloud9InventoryComponent::AddWeapon(const FWeaponConfig& Config, bool Sele bool UCloud9InventoryComponent::RemoveWeapon(EWeaponSlot Slot) { - if (let Character = GetOwner(); not IsValid(Character)) - { - log(Error, "[Inventory='%s'] Owner is invalid", *GetName()); - return false; - } - - if (not WeaponAt(Slot)) - { - log(Error, "[Inventory='%s'] Cell for slot '%d' is empty", *GetName(), Slot); - return false; - } - - if (IsWeaponChanging()) - { - log(Error, "[Inventory='%s'] Weapon deploying in progress when remove weapon from slot='%d'", *GetName(), Slot); - return false; - } + let Character = GetOwner(); + AssertOrReturn(IsValid(Character), false, Error, "Inventory owner wasn't set"); + AssertOrReturn(WeaponAt(Slot), false, Error, "Cell for slot '%d' is empty", Slot); + AssertOrReturn( + not IsWeaponChanging(), false, + Error, "Weapon deploying in progress when remove weapon from slot='%d'", Slot); if (Slot == SelectedWeaponSlot and not SelectOtherAvailableWeapon(true)) { @@ -322,7 +228,7 @@ bool UCloud9InventoryComponent::SelectOtherAvailableWeapon(bool Instant, bool Fo | ETContainer::Find{[&](let It) { return It->GetWeaponSlot() != SelectedWeaponSlot; }} | ETOptional::OnSet{[&](let It) { NewSlot = It->GetWeaponSlot(); }}; - log(Verbose, "[Inventory='%s'] Change selected slot to '%d'", *GetName(), NewSlot); + log(Verbose, "[%s] Change selected slot to '%d'", *GetName(), NewSlot); return SelectWeapon(NewSlot, Instant, Force); } diff --git a/Source/Cloud9/Character/Effects/Cloud9CharacterEffectTrait.cpp b/Source/Cloud9/Character/Effects/Cloud9CharacterEffectTrait.cpp index 5b926235b..fa4dc875a 100644 --- a/Source/Cloud9/Character/Effects/Cloud9CharacterEffectTrait.cpp +++ b/Source/Cloud9/Character/Effects/Cloud9CharacterEffectTrait.cpp @@ -15,7 +15,7 @@ void UCloud9CharacterEffectTrait::OnApply_Implementation() { let Character = GetCharacter(); let MeshComponent = Cast(Character->GetMesh()); - CheckIsValid(MeshComponent, Error, "SkeletalMeshComponent is invalid"); + AssertOrVoid(MeshComponent, Error, "SkeletalMeshComponent is invalid"); MeshComponent->OnSkeletalMeshChanged.AddDynamic(this, &UCloud9CharacterEffectTrait::OnSkeletalMeshChanged); } @@ -23,7 +23,7 @@ void UCloud9CharacterEffectTrait::OnRemove_Implementation() { let Character = GetCharacter(); let MeshComponent = Cast(Character->GetMesh()); - CheckIsValid(MeshComponent, Error, "SkeletalMeshComponent is invalid"); + AssertOrVoid(MeshComponent, Error, "SkeletalMeshComponent is invalid"); MeshComponent->OnSkeletalMeshChanged.RemoveDynamic(this, &UCloud9CharacterEffectTrait::OnSkeletalMeshChanged); } @@ -42,13 +42,13 @@ void UCloud9CharacterEffectTrait::OnSkeletalMeshChanged_Implementation(bool bRei ACloud9Character* UCloud9CharacterEffectTrait::GetCharacter() const { let MyOuter = GetOuter(); - CheckIsValid(MyOuter, Fatal, "Effect outer parent object wasn't specified", nullptr); + AssertOrReturn(MyOuter, nullptr, Fatal, "Effect outer parent object wasn't specified"); let Container = Cast(MyOuter); - CheckIsValid(Container, Fatal, "Outer parent object is invalid", nullptr); + AssertOrReturn(Container, nullptr, Fatal, "Outer parent object is invalid"); let Character = Container->GetOwner(); - CheckIsValid(Character, Fatal, "Owner is invalid", nullptr); + AssertOrReturn(Character, nullptr, Fatal, "Owner is invalid"); return Character; } diff --git a/Source/Cloud9/Character/Effects/Cloud9CharacterShieldEffect.cpp b/Source/Cloud9/Character/Effects/Cloud9CharacterShieldEffect.cpp index 31c6d36e3..d57234353 100644 --- a/Source/Cloud9/Character/Effects/Cloud9CharacterShieldEffect.cpp +++ b/Source/Cloud9/Character/Effects/Cloud9CharacterShieldEffect.cpp @@ -17,7 +17,7 @@ void UCloud9CharacterShieldEffect::ToggleEffect(bool NewState) IsEnabled = NewState; let Character = GetCharacter(); let HealthComponent = Character->GetHealthComponent(); - CheckIsValid(HealthComponent, Error, "HealthComponent is invalid"); + AssertOrVoid(HealthComponent, Error, "HealthComponent is invalid"); HealthComponent->IsInvulnerable(NewState); ToggleVisual(NewState); } @@ -26,7 +26,7 @@ void UCloud9CharacterShieldEffect::ToggleVisual(bool NewState) { let Character = GetCharacter(); let MeshComponent = Character->GetMesh(); - CheckIsValid(MeshComponent, Error, "MeshComponent is invalid"); + AssertOrVoid(MeshComponent, Error, "MeshComponent is invalid"); MeshComponent->GetMaterials() | ETContainer::Transform{[](let It) { return Cast(It); }} | ETContainer::Filter{[](let It) { return IsValid(It); }} diff --git a/Source/Cloud9/Contollers/Cloud9KeyboardController.cpp b/Source/Cloud9/Contollers/Cloud9KeyboardController.cpp index 301d790a4..3dc7c3758 100644 --- a/Source/Cloud9/Contollers/Cloud9KeyboardController.cpp +++ b/Source/Cloud9/Contollers/Cloud9KeyboardController.cpp @@ -66,32 +66,17 @@ template void UCloud9KeyboardController::WeaponAction(FunctionType Function) { let Pawn = GetCloud9Pawn(); - - if (not IsValid(Pawn)) - { - log(Error, "Pawn is invalid") - return; - } + AssertOrVoid(IsValid(Pawn), Error, "Pawn is invalid"); let Inventory = Pawn->GetInventoryComponent(); - - if (not IsValid(Inventory)) - { - log(Error, "Pawn inventory is invalid") - return; - } + AssertOrVoid(IsValid(Inventory), Error, "Pawn inventory is invalid"); if (not Inventory->IsWeaponChanging()) { let SelectedWeapon = Inventory->GetSelectedWeapon(); + AssertOrVoid(IsValid(SelectedWeapon), Error, "Selected weapon is invalid"); - if (not IsValid(SelectedWeapon)) - { - log(Error, "Selected weapon is invalid"); - return; - } - - // Checking of other actions in progress should be done inside weapon + // Checking of other actions in progress should be done inside a weapon // because this can depend on implementation of weapon work logic Function(SelectedWeapon); } diff --git a/Source/Cloud9/Contollers/Cloud9MouseController.cpp b/Source/Cloud9/Contollers/Cloud9MouseController.cpp index 94fd387a7..26628ff04 100644 --- a/Source/Cloud9/Contollers/Cloud9MouseController.cpp +++ b/Source/Cloud9/Contollers/Cloud9MouseController.cpp @@ -60,40 +60,33 @@ UCloud9MouseController::UCloud9MouseController() FVector2D UCloud9MouseController::GetMousePosition() const { - if (let Owner = GetOwner(); IsValid(Owner)) - { - FVector2D MousePosition = FVector2D::ZeroVector; - GetOwner()->GetMousePosition(MousePosition.X, MousePosition.Y); - return MousePosition; - } - - log(Fatal, "Can't get Cloud9PlayerController"); - return FVector2D::ZeroVector; + let Owner = GetOwner(); + AssertOrReturn(IsValid(Owner), {}, Fatal, "Can't get Cloud9PlayerController"); + FVector2D MousePosition = FVector2D::ZeroVector; + GetOwner()->GetMousePosition(MousePosition.X, MousePosition.Y); + return MousePosition; } float UCloud9MouseController::GetCameraZoomHeightLevel() const { - if (let Pawn = GetCloud9Pawn(); IsValid(Pawn)) + let Pawn = GetCloud9Pawn(); + AssertOrReturn(IsValid(Pawn), InvalidCameraZoomLevel, Fatal, "Can't get Cloud9Pawn"); + + let ZoomHeightLevel = Math::InverseLerp( + MinCameraZoomHeight, + MaxCameraZoomHeight, + Pawn->GetCameraZoomHeight()); + let ZoomAngleLevel = Math::InverseLerp( + MinCameraZoomAngle, + MaxCameraZoomAngle, + Pawn->GetCameraRotationRoll()); + + if (not FMath::IsNearlyEqual(ZoomHeightLevel, ZoomAngleLevel, 0.001f)) { - let ZoomHeightLevel = Math::InverseLerp( - MinCameraZoomHeight, - MaxCameraZoomHeight, - Pawn->GetCameraZoomHeight()); - let ZoomAngleLevel = Math::InverseLerp( - MinCameraZoomAngle, - MaxCameraZoomAngle, - Pawn->GetCameraRotationRoll()); - - if (not FMath::IsNearlyEqual(ZoomHeightLevel, ZoomAngleLevel, 0.001f)) - { - log(Error, "ZoomHeightLevel = %f != ZoomAngleLevel != %f", ZoomHeightLevel, ZoomAngleLevel); - } - - return ZoomHeightLevel; + log(Error, "ZoomHeightLevel = %f != ZoomAngleLevel != %f", ZoomHeightLevel, ZoomAngleLevel); } - log(Fatal, "Can't get Cloud9Pawn"); - return InvalidCameraZoomLevel; + return ZoomHeightLevel; } void UCloud9MouseController::SetCameraZoomLevel(float Value) const diff --git a/Source/Cloud9/Environment/Cloud9LinearDoor.cpp b/Source/Cloud9/Environment/Cloud9LinearDoor.cpp index 4bd7f4915..93c4a6b82 100644 --- a/Source/Cloud9/Environment/Cloud9LinearDoor.cpp +++ b/Source/Cloud9/Environment/Cloud9LinearDoor.cpp @@ -97,7 +97,7 @@ void ACloud9LinearDoor::BeginPlay() let ActualDistance = Distance - Extent; - log(Display, "Door '%s' distance = '%f'", *GetName(), ActualDistance); + log(Verbose, "Door '%s' distance = '%f'", *GetName(), ActualDistance); let Sign = bIsOpen ? -1 : 1; OriginPosition = Transform.GetLocation(); diff --git a/Source/Cloud9/Environment/Cloud9PracticeSpawner.cpp b/Source/Cloud9/Environment/Cloud9PracticeSpawner.cpp index fb2b35dc1..7f23ec362 100644 --- a/Source/Cloud9/Environment/Cloud9PracticeSpawner.cpp +++ b/Source/Cloud9/Environment/Cloud9PracticeSpawner.cpp @@ -103,7 +103,7 @@ AActor* ACloud9PracticeSpawner::SpawnTarget_Implementation(FVector Location) { if (not IsValid(Template)) { - log(Error, "Actor class not specified!"); + log(Error, "[%s]: Actor class not specified", *GetName()); bIsEnabled = false; SetActorTickEnabled(false); return nullptr; @@ -128,26 +128,16 @@ bool ACloud9PracticeSpawner::AddPracticeTargets() let Location = EFVector::Random(Origin - BoxExtent, Origin + BoxExtent, GridSize); let Actor = SpawnTarget(Location); - - if (not IsValid(Actor)) - { - log(Error, "Can't spawn actor at location = %s", *Location.ToString()); - return false; - } + AssertOrReturn(IsValid(Actor), false, Error, "Can't spawn actor at location = %s", *Location.ToString()); if (Actors | ETContainer::AnyByPredicate{[Actor](let It) { return It->IsOverlappingActor(Actor); }}) { Actor->Destroy(); - if (constexpr int MaxRetries = 10; Retries++ == MaxRetries) - { - log( - Error, - "[Range=%s] parameters seems to be invalid can't spawn specified count of Actors = %d", - *GetName(), MaxTargetsCount - ); - return false; - } + constexpr int MaxRetries = 10; + AssertOrReturn( + Retries++ != MaxRetries, false, + Error, "Parameters seems to be invalid can't spawn specified count of Actors = %d", MaxRetries); continue; } diff --git a/Source/Cloud9/Game/Cloud9AssetManager.cpp b/Source/Cloud9/Game/Cloud9AssetManager.cpp index 4f903890c..07c0ad900 100644 --- a/Source/Cloud9/Game/Cloud9AssetManager.cpp +++ b/Source/Cloud9/Game/Cloud9AssetManager.cpp @@ -52,20 +52,13 @@ UObject* UCloud9AssetManager::GetOrLoadScannedAssetSync(FPrimaryAssetId PrimaryA static var& Manager = Get(); let Future = Manager.LoadPrimaryAsset(PrimaryAssetId); + StaticAssertOrReturn(Future, nullptr, Error, "Can't find asset: '%s'", *PrimaryAssetId.ToString()); - if (not Future) - { - log(Error, "Can't find asset: '%s'", *PrimaryAssetId.ToString()) - return nullptr; - } + StaticAssertOrReturn( + Future->WaitUntilComplete() == EAsyncPackageState::Complete, nullptr, Error, + "Failed to loading asset: '%s'", *PrimaryAssetId.ToString()); - if (Future->WaitUntilComplete() == EAsyncPackageState::Complete) - { - let Asset = Future->GetLoadedAsset(); - Asset->AddToRoot(); // Prevent GC destroy asset - return Asset; - } - - log(Error, "Failed to loading asset: '%s'", *PrimaryAssetId.ToString()) - return nullptr; + let Asset = Future->GetLoadedAsset(); + Asset->AddToRoot(); // Prevent GC destroy asset + return Asset; } diff --git a/Source/Cloud9/Game/Cloud9GameState.cpp b/Source/Cloud9/Game/Cloud9GameState.cpp index f4ab714b6..391af6e9b 100644 --- a/Source/Cloud9/Game/Cloud9GameState.cpp +++ b/Source/Cloud9/Game/Cloud9GameState.cpp @@ -22,29 +22,14 @@ void ACloud9GameState::Tick(float DeltaSeconds) if (Settings->NetGraph > 0) { let MyWorld = GetWorld(); - - if (not IsValid(MyWorld)) - { - log(Error, "World isn't exist") - return; - } + AssertOrVoid(IsValid(MyWorld), Error, "World isn't exist"); // TODO: Make valid for any player let FirstPlayerController = MyWorld->GetFirstPlayerController(); - - if (not IsValid(FirstPlayerController)) - { - log(Error, "FirstPlayerController isn't exist") - return; - } + AssertOrVoid(IsValid(FirstPlayerController), Error, "World isn't exist"); let Character = Cast(FirstPlayerController->GetCharacter()); - - if (not IsValid(FirstPlayerController)) - { - log(Error, "Character isn't exist") - return; - } + AssertOrVoid(IsValid(Character), Error, "Character isn't exist"); let Fps = 1.0f / DeltaSeconds; let Location = Character->GetActorLocation(); diff --git a/Source/Cloud9/Modes/Cloud9DefaultGameMode.cpp b/Source/Cloud9/Modes/Cloud9DefaultGameMode.cpp index a47a9e2bc..33c613861 100644 --- a/Source/Cloud9/Modes/Cloud9DefaultGameMode.cpp +++ b/Source/Cloud9/Modes/Cloud9DefaultGameMode.cpp @@ -46,12 +46,7 @@ void ACloud9DefaultGameMode::InitializeCharacter(ACloud9Character* Character) let BotConfig = InitialPlayerConfig.Find(BotConfigName); let Config = Character->IsPlayerControlled() ? PlayerConfig : BotConfig; - - if (Config == nullptr) - { - log(Warning, "[Character='%s'] Initialization skipped cus config wasn't specified", *Character->GetName()); - return; - } + AssertOrVoid(Config, Warning, "Initialization skipped cus config wasn't specified for '%s'", *Character->GetName()); let Inventory = Character->GetInventoryComponent(); let Health = Character->GetHealthComponent(); diff --git a/Source/Cloud9/Modes/Cloud9GameMode.cpp b/Source/Cloud9/Modes/Cloud9GameMode.cpp index 1f01296bb..2febf2d87 100644 --- a/Source/Cloud9/Modes/Cloud9GameMode.cpp +++ b/Source/Cloud9/Modes/Cloud9GameMode.cpp @@ -66,12 +66,6 @@ void ACloud9GameMode::StartToLeaveMap() UCloud9GameInstance* ACloud9GameMode::GetCloud9GameInstance() const { let GameInstance = GetGameInstance(); - - if (not IsValid(GameInstance)) - { - log(Fatal, "GameInstance isn't valid"); - return nullptr; - } - + AssertOrReturn(IsValid(GameInstance), nullptr, Fatal, "GameInstance is invalid (required Cloud9 class)"); return GameInstance; } diff --git a/Source/Cloud9/Physicals/Cloud9PhysicalMaterial.cpp b/Source/Cloud9/Physicals/Cloud9PhysicalMaterial.cpp index cd286dbde..419c0f9f9 100644 --- a/Source/Cloud9/Physicals/Cloud9PhysicalMaterial.cpp +++ b/Source/Cloud9/Physicals/Cloud9PhysicalMaterial.cpp @@ -47,11 +47,7 @@ USoundBase* UCloud9PhysicalMaterial::GetRandomFirearmHitSound() const { return G USoundBase* UCloud9PhysicalMaterial::GetFirearmAltHitSound(const TSet Sounds) const { let Sound = GetRandomItem(Sounds); - if (not IsValid(Sound)) - { - log(Warning, "[Phys. Material='%s'] Can't get alternative sound, fallback to base sound", *GetName()); - return GetRandomFirearmHitSound(); - } + AssertOrReturn(IsValid(Sound), nullptr, Warning, "Can't get alternative sound, fallback to base sound"); return Sound; } diff --git a/Source/Cloud9/Tools/Cloud9ToolsLibrary.cpp b/Source/Cloud9/Tools/Cloud9ToolsLibrary.cpp index b27a44cb9..7c2da0fb2 100644 --- a/Source/Cloud9/Tools/Cloud9ToolsLibrary.cpp +++ b/Source/Cloud9/Tools/Cloud9ToolsLibrary.cpp @@ -94,15 +94,10 @@ void UCloud9ToolsLibrary::GetWidthHeightDepth(const FBox& Box, float& Width, flo TArray UCloud9ToolsLibrary::GetObjectEditorProperties(UClass* Class) { - if (IsValid(Class)) - { - return TFieldIterator(Class) - | ETContainer::FromIterator{} - | ETContainer::Filter{[](let& It) { return It.HasAnyPropertyFlags(CPF_Edit); }} - | ETContainer::Transform{[](let& It) { return It.GetName(); }} - | ETContainer::ToArray{}; - } - - log(Error, "Input class is invalid"); - return {}; + StaticAssertOrReturn(IsValid(Class), {}, Error, "Input class is invalid"); + return TFieldIterator(Class) + | ETContainer::FromIterator{} + | ETContainer::Filter{[](let& It) { return It.HasAnyPropertyFlags(CPF_Edit); }} + | ETContainer::Transform{[](let& It) { return It.GetName(); }} + | ETContainer::ToArray{}; } diff --git a/Source/Cloud9/Tools/Components/CooldownActionComponent.h b/Source/Cloud9/Tools/Components/CooldownActionComponent.h index dfb7a6b9d..20e3b3871 100644 --- a/Source/Cloud9/Tools/Components/CooldownActionComponent.h +++ b/Source/Cloud9/Tools/Components/CooldownActionComponent.h @@ -46,7 +46,6 @@ class CLOUD9_API UCooldownActionComponent : public UActorComponent bIsExecuting = false; } -public: /** * Function executes new action with specified function if cooldown * finished; also setups timer to wait new cooldown and returns true. @@ -62,7 +61,7 @@ class CLOUD9_API UCooldownActionComponent : public UActorComponent { if (not OnExecute()) { - log(Error, "[Action='%s'] Failed to execute function", *GetName()); + log(Error, "[%s] Failed to execute function", *GetName()); OnComplete(); return false; } @@ -87,11 +86,7 @@ class CLOUD9_API UCooldownActionComponent : public UActorComponent { if (not bIsExecuting) { - if (not OnExecute()) - { - log(Error, "[Action='%s'] Failed to execute function", *GetName()); - return false; - } + AssertOrReturn(OnExecute(), false, Error, "Failed to execute action function"); bIsExecuting = true; TimerHandle = GetWorld() | EUWorld::AsyncAfter{[this] { bIsExecuting = false; }, CooldownTime}; } @@ -103,7 +98,7 @@ class CLOUD9_API UCooldownActionComponent : public UActorComponent protected: /** - * Whether or not action currently in process + * Whether action currently in process */ UPROPERTY(Category=Implementation, BlueprintReadOnly) bool bIsExecuting; diff --git a/Source/Cloud9/Tools/Extensions/AActor.h b/Source/Cloud9/Tools/Extensions/AActor.h index 9a48fe282..e0918413d 100644 --- a/Source/Cloud9/Tools/Extensions/AActor.h +++ b/Source/Cloud9/Tools/Extensions/AActor.h @@ -36,7 +36,7 @@ namespace EAActor FVector operator()(const AActor* Self) const { - assertf(Self != nullptr, "Actor should not be nullptr"); + AssertOrCrash(Self != nullptr, "Actor should not be nullptr"); if (Direction == EDirection::Right) { @@ -81,12 +81,12 @@ namespace EAActor FTimerHandle operator()(AActor* Self) const { - assertf(Self != nullptr, "Actor should not be nullptr"); + AssertOrCrash(Self != nullptr, "Actor should not be nullptr"); // May be not needed? if (Self->IsPendingKill()) { - log(Warning, "[Actor='%s'] Already waiting it's death", *Self->GetName()) + log(Warning, "[%s] Already waiting it's death", *Self->GetName()); return {}; } @@ -103,7 +103,7 @@ namespace EAActor log( Verbose, - "[Actor='%s'] Set to be destroyed with delay but won't be because Delay<0.0f", + "[%s] Set to be destroyed with delay but won't be because Delay<0.0f", *Self->GetName()); return {}; } diff --git a/Source/Cloud9/Tools/Extensions/ACharacter.h b/Source/Cloud9/Tools/Extensions/ACharacter.h index fa3149a1a..ff8bba6c7 100644 --- a/Source/Cloud9/Tools/Extensions/ACharacter.h +++ b/Source/Cloud9/Tools/Extensions/ACharacter.h @@ -17,7 +17,7 @@ namespace EACharacter { int operator()(const ACharacter* Self) const { - assertf(Self != nullptr, "ACharacter should not be nullptr"); + AssertOrCrash(Self != nullptr, "ACharacter should not be nullptr"); if (let PlayerState = Self->GetPlayerState()) { diff --git a/Source/Cloud9/Tools/Extensions/APlayerController.h b/Source/Cloud9/Tools/Extensions/APlayerController.h index 58c2119d8..109733d0f 100644 --- a/Source/Cloud9/Tools/Extensions/APlayerController.h +++ b/Source/Cloud9/Tools/Extensions/APlayerController.h @@ -16,7 +16,7 @@ namespace EAPlayerController TOptional operator()(const APlayerController* Self) const { - assertf(Self != nullptr, "APlayerController should not be nullptr"); + AssertOrCrash(Self != nullptr, "APlayerController should not be nullptr"); let LocalPlayer = Cast(Self->Player); if (IsValid(LocalPlayer) and LocalPlayer->ViewportClient) diff --git a/Source/Cloud9/Tools/Extensions/FVector.cpp b/Source/Cloud9/Tools/Extensions/FVector.cpp index 996bce29a..59865edbd 100644 --- a/Source/Cloud9/Tools/Extensions/FVector.cpp +++ b/Source/Cloud9/Tools/Extensions/FVector.cpp @@ -41,7 +41,7 @@ namespace EFVector // Distance to reach let Dist = Target - Current; - // If distance is too small, just set the desired location + // If the distance is too small, just set the desired location if (Dist.SizeSquared() < KINDA_SMALL_NUMBER) { return Target; diff --git a/Source/Cloud9/Tools/Extensions/UObject.h b/Source/Cloud9/Tools/Extensions/UObject.h index c28a42b04..005c50506 100644 --- a/Source/Cloud9/Tools/Extensions/UObject.h +++ b/Source/Cloud9/Tools/Extensions/UObject.h @@ -57,14 +57,8 @@ namespace EUObject FORCEINLINE FTimerHandle operator()(const UObject* Self) const { var MyWorld = Self->GetWorld(); - - if (not IsValid(MyWorld)) - { - // Should we crash or not crash in this case? - log(Fatal, "Timer not set due to game World not exists") - return {}; - } - + // Should we crash or not crash in this case? + StaticAssertOrReturn(IsValid(MyWorld), {}, Fatal, "Timer not set due to game World not exists"); return MyWorld | EUWorld::AsyncAfter{Block, InRate, bInLoop}; } @@ -78,14 +72,8 @@ namespace EUObject FORCEINLINE bool operator()(const UObject* Self) const { let MyWorld = Self->GetWorld(); - - if (not IsValid(MyWorld)) - { - // Should we crash or not crash in this case? - log(Fatal, "Timer not set due to game World not exists") - return false; - } - + // Should we crash or not crash in this case? + StaticAssertOrReturn(IsValid(MyWorld), {}, Fatal, "Timer not set due to game World not exists"); return MyWorld | EUWorld::IsTimerActive{TimerHandle}; } diff --git a/Source/Cloud9/Tools/Extensions/UWorld.h b/Source/Cloud9/Tools/Extensions/UWorld.h index 2a9a44b32..7e1ce387b 100644 --- a/Source/Cloud9/Tools/Extensions/UWorld.h +++ b/Source/Cloud9/Tools/Extensions/UWorld.h @@ -76,7 +76,7 @@ namespace EUWorld return {}; } - assertf(Self != nullptr, "World should not be nullptr to start timer"); + AssertOrCrash(Self != nullptr, "World should not be nullptr to start timer"); FTimerHandle Handle; let Delegate = FTimerDelegate::CreateStatic(&AsyncAfter::Execute, Block, Handle); @@ -144,20 +144,9 @@ namespace EUWorld { FORCEINLINE GameModeType* operator()(const UWorld* Self) const { - if (not IsValid(Self)) - { - log(Error, "World isn't valid to get GameMode") - return nullptr; - } - + StaticAssertOrReturn(IsValid(Self), nullptr, Error, "World isn't valid to get GameMode"); let GameMode = UGameplayStatics::GetGameMode(Self); - - if (not IsValid(GameMode)) - { - log(Error, "Current GameMode isn't valid") - return nullptr; - } - + StaticAssertOrReturn(IsValid(GameMode), nullptr, Error, "Current GameMode isn't valid"); return Cast(GameMode); } diff --git a/Source/Cloud9/Tools/Macro/Common.h b/Source/Cloud9/Tools/Macro/Common.h index 4c4aadece..af5af111c 100644 --- a/Source/Cloud9/Tools/Macro/Common.h +++ b/Source/Cloud9/Tools/Macro/Common.h @@ -23,15 +23,46 @@ #pragma once +#include "Cloud9/Tools/Macro/Logging.h" + // Simplification of const auto/auto #define let const auto #define var auto -#define CheckIsValid(What, Severity, Message, ...) \ +#define AssertOrReturn(What, Value, Severity, Message, ...) \ + do { \ + if (not (What)) \ + { \ + log(Severity, "[%s]: %s", *GetName(), *FString::Printf(TEXT(Message), ##__VA_ARGS__)); \ + return Value; \ + } \ + } while(false) + +#define AssertOrVoid(What, Severity, Message, ...) \ + do { \ + if (not (What)) \ + { \ + log(Severity, "[%s]: %s", *GetName(), *FString::Printf(TEXT(Message), ##__VA_ARGS__)); \ + return; \ + } \ + } while(false) + +#define StaticAssertOrReturn(What, Value, Severity, Message, ...) \ do { \ - if (not IsValid(What)) \ + if (not (What)) \ { \ - log(Severity, Message); \ - return __VA_ARGS__; \ + log(Severity, Message, __VA_ARGS__); \ + return Value; \ } \ - } while(false); + } while(false) + +#define StaticAssertOrVoid(What, Severity, Message, ...) \ + do { \ + if (not (What)) \ + { \ + log(Severity, Message, ##__VA_ARGS__); \ + return; \ + } \ + } while(false) + +#define AssertOrCrash(Condition, FormatString, ...) checkf(Condition, TEXT(FormatString), ##__VA_ARGS__) diff --git a/Source/Cloud9/Tools/Macro/Logging.h b/Source/Cloud9/Tools/Macro/Logging.h index a5be16a49..cb05faac9 100644 --- a/Source/Cloud9/Tools/Macro/Logging.h +++ b/Source/Cloud9/Tools/Macro/Logging.h @@ -33,18 +33,14 @@ ) \ ) -// UE LOG - #define log(Severity, FormatString, ...) \ - UE_LOG(\ - LogCloud9, \ - Severity, \ - TEXT("%s: %s"), \ - *TRACE_STR_CUR_CLASS_FUNC_LINE, \ - *FString::Printf(TEXT(FormatString), ##__VA_ARGS__ ) \ - ) - -#define assert(Condition) check(Condition) - -#define assertf(Condition, FormatString, ...) \ - checkf(Condition, TEXT(FormatString), ##__VA_ARGS__) + do { \ + UE_LOG(\ + LogCloud9, \ + Severity, \ + TEXT("%s: %s"), \ + *TRACE_STR_CUR_CLASS_FUNC_LINE, \ + *FString::Printf(TEXT(FormatString), ##__VA_ARGS__) \ + ) \ + } \ + while (false) diff --git a/Source/Cloud9/Weapon/Assets/WeaponDefinitionsAsset.cpp b/Source/Cloud9/Weapon/Assets/WeaponDefinitionsAsset.cpp index bcaabc783..95fd37d75 100644 --- a/Source/Cloud9/Weapon/Assets/WeaponDefinitionsAsset.cpp +++ b/Source/Cloud9/Weapon/Assets/WeaponDefinitionsAsset.cpp @@ -23,6 +23,7 @@ #include "WeaponDefinitionsAsset.h" +#include "Cloud9/Tools/Extensions/FString.h" #include "Cloud9/Tools/Macro/Common.h" #include "Cloud9/Tools/Macro/Logging.h" @@ -40,42 +41,21 @@ FWeaponDefinition UWeaponDefinitionsAsset::GetWeaponDefinition( using WeaponInfoType = typename EFWeaponId::WeaponInfo::Type; let WeaponName = WeaponId | EUEnum::GetValueName{}; - - if (WeaponName.IsNone()) - { - log(Error, "WeaponName/WeaponId is invalid"); - return {}; - } - - if (WeaponsInfoTable == nullptr) - { - log(Error, "WeaponsInfoTable isn't set"); - return {}; - } + AssertOrReturn(not WeaponName.IsNone(), {}, Error, "WeaponName/WeaponId is invalid"); + AssertOrReturn(WeaponsInfoTable, {}, Error, "WeaponsInfoTable isn't set"); let WeaponInfo = WeaponsInfoTable->FindRow(WeaponName, "", false); - - if (WeaponInfo == nullptr) - { - log(Error, "Can't get weapon info for '%s'", *WeaponName.ToString()); - return {}; - } - - if (not Validator(WeaponInfo->Type)) - { - let TypeName = WeaponInfo->Type | EUEnum::GetEnumFullValueName{}; - log(Error, "Specified weapon type '%s' is invalid", *TypeName.ToString()); - return {}; - } + AssertOrReturn(WeaponInfo, {}, Error, "Can't get weapon info for '%s'", *WeaponName.ToString()); + AssertOrReturn( + Validator(WeaponInfo->Type), {}, + Error, "Specified weapon type '%s' is invalid", + WeaponInfo->Type | EUEnum::GetEnumFullValueName{} | EFName::ToCStr{}); let Montages = WeaponActionMontages.Find(WeaponInfo->Type); - - if (Montages == nullptr) - { - let TypeName = WeaponInfo->Type | EUEnum::GetValueName{}; - log(Error, "Animation montages not defined for weapon type '%s'", *TypeName.ToString()); - return {}; - } + AssertOrReturn( + Montages, {}, + Error, "Animation montages not defined for weapon type '%s'", + WeaponInfo->Type | EUEnum::GetValueName{} | EFName::ToCStr{}); return FWeaponDefinition(*WeaponInfo, *Montages, WeaponCommonData); } @@ -91,11 +71,10 @@ bool UWeaponDefinitionsAsset::GetWeaponDefinition(const FWeaponId& WeaponId, FWe }, WeaponId ); - if (not IsValid(WeaponDefinition)) - { - log(Error, "Can't get weapon definition for WeaponId='%s'", WeaponId | EFWeaponId::ToName() | EFName::ToCStr()); - return false; - } + AssertOrReturn( + IsValid(WeaponDefinition), false, + Error, "Can't get weapon definition for WeaponId='%s'", + WeaponId | EFWeaponId::ToName() | EFName::ToCStr()); return true; } diff --git a/Source/Cloud9/Weapon/Classes/Cloud9WeaponBase.cpp b/Source/Cloud9/Weapon/Classes/Cloud9WeaponBase.cpp index faf4f93b8..ba9640260 100644 --- a/Source/Cloud9/Weapon/Classes/Cloud9WeaponBase.cpp +++ b/Source/Cloud9/Weapon/Classes/Cloud9WeaponBase.cpp @@ -54,34 +54,22 @@ const FName ACloud9WeaponBase::CaseEjectSocketName = TEXT("CaseEjectSocket"); ACloud9WeaponBase::ACloud9WeaponBase() { - // Required for weapon with automatic fire + // Required for a weapon with automatic fire PrimaryActorTick.bCanEverTick = true; WeaponSkin = NAME_None; - if (WeaponMesh = CreateMeshComponent(WeaponMeshComponentName); not IsValid(WeaponMesh)) - { - log(Error, "Failed to create WeaponMeshComponent"); - return; - } + WeaponMesh = CreateMeshComponent(WeaponMeshComponentName); + AssertOrVoid(IsValid(WeaponMesh), Error, "Failed to create WeaponMeshComponent"); - if (MagazineMesh = CreateMeshComponent(MagazineMeshComponentName, MagazineSocketName); not IsValid(MagazineMesh)) - { - log(Error, "Failed to create MagazineMeshComponent"); - return; - } + MagazineMesh = CreateMeshComponent(MagazineMeshComponentName, MagazineSocketName); + AssertOrVoid(IsValid(WeaponMesh), Error, "Failed to create MagazineMeshComponent"); - if (MuzzleFlash = CreateEffectComponent(MuzzleFlashComponentName, MuzzleFlashSocketName); not IsValid(MuzzleFlash)) - { - log(Error, "Failed to create MuzzleFlashComponent"); - return; - } + MuzzleFlash = CreateEffectComponent(MuzzleFlashComponentName, MuzzleFlashSocketName); + AssertOrVoid(IsValid(WeaponMesh), Error, "Failed to create MuzzleFlashComponent"); - if (SilencerMesh = CreateMeshComponent(SilencerMeshComponentName, SilencerSocketName); not IsValid(SilencerMesh)) - { - log(Error, "Failed to create SilencerMeshComponent"); - return; - } + SilencerMesh = CreateMeshComponent(SilencerMeshComponentName, SilencerSocketName); + AssertOrVoid(IsValid(WeaponMesh), Error, "Failed to create SilencerMeshComponent"); let Actions = StaticEnum(); @@ -109,13 +97,9 @@ UWeaponDefinitionsAsset* ACloud9WeaponBase::GetWeaponDefinitionsAsset() let Asset = UCloud9AssetManager::GetOrLoadAssetSync(); - if (not IsValid(Asset)) - { - // Try reload later then ... this will haven in PIE - // if some object required this asset placed on level - log(Error, "WeaponDefinitionsAsset loading failure"); - return nullptr; - } + // Try reload later then ... this will haven in PIE + // if some object required this asset placed on level + StaticAssertOrReturn(IsValid(Asset), nullptr, Error, "WeaponDefinitionsAsset loading failure"); WeaponDefinitionsAsset = Asset; @@ -125,67 +109,49 @@ UWeaponDefinitionsAsset* ACloud9WeaponBase::GetWeaponDefinitionsAsset() UCooldownActionComponent* ACloud9WeaponBase::CreateCooldownAction(FName ComponentName) { let Component = CreateDefaultSubobject(ComponentName); - - if (not IsValid(Component)) - { - log(Error, "Can't cooldown action '%s' for actor '%s'", *ComponentName.ToString(), *GetName()); - return nullptr; - } - + AssertOrReturn(IsValid(Component), nullptr, Error, "Can't create cooldown action '%s'", *ComponentName.ToString()); return Component; } UStaticMeshComponent* ACloud9WeaponBase::CreateMeshComponent(FName ComponentName, FName SocketName) { - if (let Component = CreateDefaultSubobject(ComponentName); IsValid(Component)) + let Component = CreateDefaultSubobject(ComponentName); + AssertOrReturn(IsValid(Component), nullptr, Error, "Can't create mesh '%s'", *ComponentName.ToString()); + + Component->bOwnerNoSee = false; + Component->AlwaysLoadOnClient = true; + Component->AlwaysLoadOnServer = true; + Component->bCastDynamicShadow = true; + Component->bAffectDynamicIndirectLighting = true; + Component->PrimaryComponentTick.TickGroup = TG_PrePhysics; + Component->SetCollisionProfileName(WeaponMeshCollisionProfile); + + if (not SocketName.IsNone()) { - Component->bOwnerNoSee = false; - Component->AlwaysLoadOnClient = true; - Component->AlwaysLoadOnServer = true; - Component->bCastDynamicShadow = true; - Component->bAffectDynamicIndirectLighting = true; - Component->PrimaryComponentTick.TickGroup = TG_PrePhysics; - Component->SetCollisionProfileName(WeaponMeshCollisionProfile); - - if (not SocketName.IsNone()) - { - Component->SetupAttachment(RootComponent, SocketName); - } - else - { - RootComponent = Component; - } - - return Component; + Component->SetupAttachment(RootComponent, SocketName); + } + else + { + RootComponent = Component; } - log(Error, "Can't create mesh '%s' for actor '%s'", *ComponentName.ToString(), *GetName()); - return nullptr; + return Component; } URadialForceComponent* ACloud9WeaponBase::CreateDetonateComponent(FName ComponentName) { - if (let Component = CreateDefaultSubobject(ComponentName); IsValid(Component)) - { - Component->SetupAttachment(RootComponent); - return Component; - } - - log(Error, "Can't create VFX '%s' for actor '%s'", *ComponentName.ToString(), *GetName()); - return nullptr; + let Component = CreateDefaultSubobject(ComponentName); + AssertOrReturn(IsValid(Component), nullptr, Error, "Can't create VFX '%s'", *ComponentName.ToString()); + Component->SetupAttachment(RootComponent); + return Component; } - UNiagaraComponent* ACloud9WeaponBase::CreateEffectComponent(FName ComponentName, FName SocketName) { - if (let Component = CreateDefaultSubobject(ComponentName); IsValid(Component)) - { - Component->SetupAttachment(RootComponent, SocketName); - return Component; - } - - log(Error, "Can't create VFX '%s' for actor '%s'", *ComponentName.ToString(), *GetName()); - return nullptr; + let Component = CreateDefaultSubobject(ComponentName); + AssertOrReturn(IsValid(Component), nullptr, Error, "Can't create VFX '%s'", *ComponentName.ToString()); + Component->SetupAttachment(RootComponent, SocketName); + return Component; } void ACloud9WeaponBase::InitializeName(const FWeaponId& NewWeaponId) @@ -209,11 +175,7 @@ bool ACloud9WeaponBase::InitializeMeshComponent( UStaticMesh* Mesh, UMaterialInstance* Material) const { - if (Mesh == nullptr) - { - log(Error, "[Weapon='%s'] Mesh is invalid", *GetName()); - return false; - } + AssertOrReturn(Mesh, false, Error, "Mesh is invalid"); Component->SetStaticMesh(Mesh); @@ -230,11 +192,7 @@ bool ACloud9WeaponBase::InitializeEffectComponent( UNiagaraSystem* Effect, float Scale) const { - if (Effect == nullptr) - { - log(Error, "[Weapon='%s'] Effect is invalid", *GetName()); - return false; - } + AssertOrReturn(Effect, false, Error, "Effect is invalid"); Component->SetAsset(Effect); Component->SetFloatParameter(ExplosionEffectScaleName, Scale); @@ -249,36 +207,19 @@ bool ACloud9WeaponBase::InitializeEffectComponent( bool ACloud9WeaponBase::UpdateWeaponAttachment(EWeaponSlot NewSlot, EWeaponBond NewBond, bool Instant) { let Character = GetOwner(); - - if (not IsValid(Character)) - { - log(Error, "[Weapon='%s' Slot='%s'] Weapon owner is invalid", *GetName(), SLOT_NAME); - return false; - } + AssertOrReturn(IsValid(Character), false, Error, "Weapon owner is invalid for slot '%s'", SLOT_NAME); let CharacterMesh = Character->GetMesh(); - - if (not IsValid(CharacterMesh)) - { - log(Error, "[Weapon='%s' Slot='%s'] Character mesh is invalid", *GetName(), SLOT_NAME); - return false; - } + AssertOrReturn(IsValid(CharacterMesh), false, Error, "Character mesh is invalid for slot '%s'", SLOT_NAME); let SocketName = NewBond == EWeaponBond::Armed ? UWeaponSlot::EquippedSocket() : UWeaponSlot::HolsteredSocket(NewSlot); - if (SocketName.IsNone()) - { - log(Error, "[Weapon='%s' Slot='%s'] Can't get socket name", *GetName(), SLOT_NAME); - return false; - } - - if (not CharacterMesh->GetSocketByName(SocketName)) - { - log(Error, "[Weapon='%s' Slot='%s'] Socket not found in character mesh", *GetName(), SLOT_NAME); - return false; - } + AssertOrReturn(not SocketName.IsNone(), false, Error, "Can't get socket name for slot '%s'", SLOT_NAME); + AssertOrReturn( + CharacterMesh->GetSocketByName(SocketName), false, + Error, "Socket not found in character mesh for '%s'", SLOT_NAME); log(Verbose, "[Weapon='%s' Slot='%s'] Update attachment to character '%s' into socket '%s'", @@ -306,45 +247,21 @@ USceneComponent* ACloud9WeaponBase::GetShootLocationActor() const bool ACloud9WeaponBase::AddToInventory(ACloud9Character* Character, EWeaponSlot NewSlot) { - if (let MyOwner = GetOwner()) - { - log( - Warning, - "[Weapon='%s' Slot='%s'] Weapon already in inventory of '%s'", - *GetName(), SLOT_NAME, *MyOwner->GetName()); - return false; - } - - if (not IsValid(Character)) - { - log(Error, "[Weapon='%s' Slot='%s'] Invalid character", *GetName(), SLOT_NAME); - return false; - } - - if (NewSlot == EWeaponSlot::NotSelected) - { - log(Error, "[Weapon='%s' Slot='%s'] Invalid slot", *GetName(), SLOT_NAME); - return false; - } + AssertOrReturn( + not GetOwner(), false, + Error, "Weapon already in inventory of '%s'", *GetOwner()->GetName()); + AssertOrReturn(IsValid(Character), false, Error, "Invalid character for slot '%s'", SLOT_NAME); + AssertOrReturn(NewSlot != EWeaponSlot::NotSelected, false, Error, "Invalid slot"); let Inventory = Character->GetInventoryComponent(); - if (not IsValid(Inventory)) - { - log(Error, "[Weapon='%s' Slot='%s'] Character inventory is invalid", *GetName(), SLOT_NAME); - return false; - } - - if (Inventory->GetWeaponAt(NewSlot) != nullptr) - { - log(Error, "[Weapon='%s' Slot='%s'] Weapon slot already occupied", *GetName(), SLOT_NAME); - return false; - } + AssertOrReturn(IsValid(Inventory), false, Error, "Character inventory is invalid for slot '%s'", SLOT_NAME); + AssertOrReturn(not Inventory->GetWeaponAt(NewSlot), false, Error, "Weapon slot '%s' already occupied", SLOT_NAME); SetOwner(Character); - // Set new instigator for this weapon so When weapon thrown owner will be changed - // to nothing but we need to know who do it (throw a weapon) + // Set new instigator for this weapon, so When a weapon thrown an owner will be changed + // to nothing, but we need to know who do it (throw a weapon). // This is important for nades to get handle number of kills for player SetInstigator(Character); @@ -383,25 +300,18 @@ bool ACloud9WeaponBase::RemoveFromInventory() bool ACloud9WeaponBase::ChangeState(EWeaponBond NewBond, bool Instant, bool Force) { let Character = GetOwner(); + AssertOrReturn(IsValid(Character), false, Error, "Weapon owner is invalid for bond '%s'", BOND_NAME); - if (not IsValid(Character)) - { - log(Error, "[Weapon='%s' Bond='%s'] Weapon not in any inventory", *GetName(), BOND_NAME); - return false; - } + let AnimComponent = Character->GetAnimationComponent(); + AssertOrReturn(IsValid(AnimComponent), false, Error, "Weapon owner animation component is invalid '%s'", BOND_NAME); - if (let AnimComponent = Character->GetAnimationComponent(); - not Force and IsValid(AnimComponent) and AnimComponent->IsAnyMontagePlaying()) - { - log(Verbose, "[Weapon='%s' Bond='%s'] Montage is playing now", *GetName(), BOND_NAME); - return false; - } + AssertOrReturn( + Force or not AnimComponent->IsAnyMontagePlaying(), false, + Verbose, "Montage is playing now"); - if (not Force and IsActionInProgress()) - { - log(Verbose, "[Weapon='%s' Bond='%s'] Some action is in progress", *GetName(), BOND_NAME); - return false; - } + AssertOrReturn( + Force or not IsActionInProgress(), false, + Verbose, "Some action is in progress for bond '%s'", BOND_NAME); return UpdateWeaponAttachment(WeaponState.GetWeaponSlot(), NewBond, Instant); } @@ -456,17 +366,10 @@ bool ACloud9WeaponBase::OnInitialize(const FWeaponConfig& WeaponConfig) { let Asset = GetWeaponDefinitionsAsset(); - if (not IsValid(Asset)) - { - log(Error, "[Weapon='%s'] Can't get weapon definitions asset", *GetName()); - return false; - } - - if (not Asset->GetWeaponDefinition(WeaponConfig.GetWeaponId(), WeaponDefinition)) - { - log(Error, "[Weapon='%s'] Not initialized and Tick() will be disabled", *GetName()); - return false; - } + AssertOrReturn(IsValid(Asset), false, Error, "Can't get weapon definitions asset"); + AssertOrReturn( + Asset->GetWeaponDefinition(WeaponConfig.GetWeaponId(), WeaponDefinition), false, + Error, "Not initialized and Tick() will be disabled"); return true; } @@ -505,7 +408,7 @@ FName ACloud9WeaponBase::GetWeaponName() const { return GetWeaponId() | EFWeapon FWeaponId ACloud9WeaponBase::GetWeaponId() const { static let UnknownWeaponId = ETVariant::Convert(EBadWeapon::NoClass); - log(Fatal, "[Weapon='%s'] Not implmemented", *GetName()) + log(Fatal, "[Weapon='%s'] Not implmemented", *GetName()); return UnknownWeaponId; } @@ -513,7 +416,7 @@ FName ACloud9WeaponBase::GetWeaponSkin() const { return WeaponSkin; } EWeaponType ACloud9WeaponBase::GetWeaponType() const { - assertf(IsValid(WeaponDefinition), "[Weapon='%ls'] Not initialized", *GetName()); + AssertOrCrash(IsValid(WeaponDefinition), "[Weapon='%ls'] Not initialized", *GetName()); return WeaponDefinition.GetWeaponInfo()->Type; } diff --git a/Source/Cloud9/Weapon/Classes/Cloud9WeaponBase.h b/Source/Cloud9/Weapon/Classes/Cloud9WeaponBase.h index 01ca58cff..1bf679a6d 100644 --- a/Source/Cloud9/Weapon/Classes/Cloud9WeaponBase.h +++ b/Source/Cloud9/Weapon/Classes/Cloud9WeaponBase.h @@ -237,21 +237,21 @@ class CLOUD9_API ACloud9WeaponBase : public AActor #define WEAPON_IS_DEFINED_GUARD() \ if (not IsWeaponDefined()) \ { \ - log(Error, "[Weapon='%s'] Not defined", *GetName()); \ + log(Error, "[%s] Not defined", *GetName()); \ return; \ } #define WEAPON_ANIM_COMPONENT_GUARD() \ if (not IsValid(AnimComponent)) \ { \ - log(Warning, "[Weapon='%s'] AnimComponent isn't valid", *GetName()); \ + log(Warning, "[%s] AnimComponent isn't valid", *GetName()); \ return; \ } #define WEAPON_IS_ACTION_IN_PROGRESS_GUARD() \ if (IsActionInProgress()) \ { \ - log(Verbose, "[Weapon='%s'] Action already in progress during Tick", *GetName()); \ + log(Verbose, "[%s] Action already in progress during Tick", *GetName()); \ return; \ } diff --git a/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp b/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp index 6c4343d4b..5674f53bf 100644 --- a/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp +++ b/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp @@ -66,7 +66,7 @@ TErrorValue FCursorHitScanInfo::Create( if (not IsValid(Character)) { - log(Error, "Character is invalid") + log(Error, "Character is invalid"); return EFirearmFireStatus::Error; } @@ -74,7 +74,7 @@ TErrorValue FCursorHitScanInfo::Create( if (not IsValid(Controller)) { - log(Error, "Can't hit object because player controller isn't valid") + log(Error, "Can't hit object because player controller isn't valid"); return EFirearmFireStatus::Error; } @@ -94,7 +94,7 @@ TErrorValue FCursorHitScanInfo::Create( if (not CursorHit) { - log(Error, "Cursor wasn't hit anything") + log(Error, "Cursor wasn't hit anything"); return EFirearmFireStatus::NoCursorHit; } @@ -110,7 +110,7 @@ TErrorValue FCursorHitScanInfo::Create( if (not CursorHit) { - log(Error, "Cursor wasn't anything") + log(Error, "Cursor wasn't anything"); return EFirearmFireStatus::NoCursorHit; } @@ -440,7 +440,7 @@ EFirearmFireStatus ACloud9WeaponFirearm::GunFire( if (not IsValid(Character)) { - log(Error, "Character is invalid") + log(Error, "Character is invalid"); return EFirearmFireStatus::Error; } @@ -517,10 +517,9 @@ EFirearmFireStatus ACloud9WeaponFirearm::GunFire( } let DamagedActor = Cast(LineHit.Actor); - CheckIsValid( - DamagedActor, - Warning, "Line trace got hit but target actor is invalid", - EFirearmFireStatus::Success); + AssertOrReturn( + DamagedActor, EFirearmFireStatus::Success, + Warning, "Line trace got hit but target actor is invalid"); let Damage = UGameplayStatics::ApplyPointDamage( DamagedActor, @@ -546,7 +545,7 @@ EFirearmFireStatus ACloud9WeaponFirearm::GunFire( Damage * FirearmCommonData.ImpulseMultiplier, FirearmCommonData.MinAppliedImpulse, FirearmCommonData.MaxAppliedImpulse); - log(Verbose, "[Weapon='%s'] Damage=%f Impulse=%f", *GetName(), Damage, Impulse); + log(Verbose, "[%s] Damage=%f Impulse=%f", *GetName(), Damage, Impulse); Target->AddImpulseAtLocation(Direction * Impulse, LineHit.Location, LineHit.BoneName); } @@ -847,9 +846,10 @@ TArray ACloud9WeaponFirearm::RecalculateByShotInaccuracy( let OffsetX0 = Radius0 * FMath::Cos(Theta0); let OffsetY0 = Radius0 * FMath::Sin(Theta0); - assert( + AssertOrCrash( WeaponInfo->BulletsPerShot >= 1 and - WeaponInfo->BulletsPerShot <= MaxBullets + WeaponInfo->BulletsPerShot <= MaxBullets, + "Invalid bullets per shot" ); FVector Forward, Right, Up; diff --git a/Source/Cloud9/Weapon/Classes/Cloud9WeaponGrenade.cpp b/Source/Cloud9/Weapon/Classes/Cloud9WeaponGrenade.cpp index 9949a46be..2b3be906a 100644 --- a/Source/Cloud9/Weapon/Classes/Cloud9WeaponGrenade.cpp +++ b/Source/Cloud9/Weapon/Classes/Cloud9WeaponGrenade.cpp @@ -45,23 +45,14 @@ const FName ACloud9WeaponGrenade::ActiveEffectComponentName = TEXT("ActiveEffect ACloud9WeaponGrenade::ACloud9WeaponGrenade() { - if (Explosion = CreateDetonateComponent(ExplosionComponentName); not IsValid(Explosion)) - { - log(Error, "Failed to create URadialForceComponent"); - return; - } + Explosion = CreateDetonateComponent(ExplosionComponentName); + AssertOrVoid(IsValid(Explosion), Error, "Failed to create URadialForceComponent"); - if (DetonationEffect = CreateEffectComponent(DetonationEffectComponentName); not IsValid(DetonationEffect)) - { - log(Error, "Failed to create DetonationEffect"); - return; - } + DetonationEffect = CreateEffectComponent(DetonationEffectComponentName); + AssertOrVoid(IsValid(Explosion), Error, "Failed to create DetonationEffect"); - if (ActiveEffect = CreateEffectComponent(ActiveEffectComponentName); not IsValid(ActiveEffect)) - { - log(Error, "Failed to create ActiveEffect"); - return; - } + ActiveEffect = CreateEffectComponent(ActiveEffectComponentName); + AssertOrVoid(IsValid(Explosion), Error, "Failed to create ActiveEffect"); } FWeaponId ACloud9WeaponGrenade::GetWeaponId() const { return ETVariant::Convert(WeaponId); } @@ -77,12 +68,7 @@ bool ACloud9WeaponGrenade::OnInitialize(const FWeaponConfig& WeaponConfig) { let MyWeaponInfo = GetWeaponInfo(); let MySkinInfo = MyWeaponInfo | EFWeaponInfo::GetSkinByNameOrThrow(WeaponConfig.GetSkinName()); - - if (MySkinInfo.Material == nullptr) - { - log(Error, "[Weapon='%s'] Skin material is invalid", *GetName()); - return false; - } + AssertOrReturn(MySkinInfo.Material, false, Error, "Skin material is invalid"); let& [OnDetonationEffect, OnDetonationScale, OnActiveEffect, OnActiveScale] = MyWeaponInfo->Effects; @@ -367,28 +353,13 @@ bool ACloud9WeaponGrenade::OnGrenadeThrown() bool ACloud9WeaponGrenade::Throw() const { let Character = GetOwner(); - - if (not IsValid(Character)) - { - log(Error, "[Weapon='%s'] Character is invalid", *GetName()); - return false; - } + AssertOrReturn(IsValid(Character), false, Error, "Character is invalid"); let Controller = Character->GetCloud9Controller(); - - if (not IsValid(Controller)) - { - log(Error, "[Weapon='%s'] Controller is invalid", *GetName()); - return false; - } + AssertOrReturn(IsValid(Controller), false, Error, "Controller is invalid"); let Inventory = Character->GetInventoryComponent(); - - if (not IsValid(Inventory)) - { - log(Error, "[Weapon='%s'] Inventory is invalid", *GetName()); - return false; - } + AssertOrReturn(IsValid(Inventory), false, Error, "Inventory is invalid"); let ActorsToIgnore = TArray{Character}; let CursorHit = Controller | EAPlayerController::GetHitUnderCursor{ @@ -397,11 +368,7 @@ bool ACloud9WeaponGrenade::Throw() const ActorsToIgnore }; - if (not CursorHit) - { - log(Error, "[Weapon='%s'] Cursor not hit anything", *GetName()); - return false; - } + AssertOrReturn(CursorHit, false, Error, "Cursor not hit anything"); static let Settings = UCloud9DeveloperSettings::Get(); FWeaponConfig GrenadeConfig; diff --git a/Source/Cloud9/Weapon/Classes/Cloud9WeaponMelee.cpp b/Source/Cloud9/Weapon/Classes/Cloud9WeaponMelee.cpp index 1d5f7f0e2..bb4236111 100644 --- a/Source/Cloud9/Weapon/Classes/Cloud9WeaponMelee.cpp +++ b/Source/Cloud9/Weapon/Classes/Cloud9WeaponMelee.cpp @@ -45,12 +45,7 @@ bool ACloud9WeaponMelee::OnInitialize(const FWeaponConfig& WeaponConfig) { let MyWeaponInfo = WeaponDefinition.GetWeaponInfo(); let MySkinInfo = MyWeaponInfo | EFWeaponInfo::GetSkinByNameOrThrow(WeaponConfig.GetSkinName()); - - if (MySkinInfo.Material == nullptr) - { - log(Error, "[Weapon='%s'] Skin material is invalid", *GetName()); - return false; - } + AssertOrReturn(MySkinInfo.Material, false, Error, "Skin material is invalid"); return InitializeMeshComponent(WeaponMesh, MyWeaponInfo->WeaponModel, MySkinInfo.Material); } diff --git a/Source/Cloud9/Weapon/Notifiers/Cloud9AnimNotifyPlaySound.cpp b/Source/Cloud9/Weapon/Notifiers/Cloud9AnimNotifyPlaySound.cpp index e70a46f0a..89413c8e1 100644 --- a/Source/Cloud9/Weapon/Notifiers/Cloud9AnimNotifyPlaySound.cpp +++ b/Source/Cloud9/Weapon/Notifiers/Cloud9AnimNotifyPlaySound.cpp @@ -38,11 +38,9 @@ FString UCloud9AnimNotifyPlaySound::GetNotifyName_Implementation() const bool UCloud9AnimNotifyPlaySound::PlayMeleeSound(USkeletalMeshComponent* MeshComp, float Volume) const { let SelectedWeapon = GetSelectedWeapon(MeshComp); - if (not IsValid(SelectedWeapon) or not SelectedWeapon->IsWeaponDefined()) - { - log(Error, "[Notify='%s'] Invalid or undefined weapon for play sound", *GetName()); - return false; - } + AssertOrReturn( + IsValid(SelectedWeapon) and SelectedWeapon->IsWeaponDefined(), false, + Error, "Invalid or undefined weapon for play sound"); let WeaponInfo = SelectedWeapon->GetWeaponInfo(); let Location = SelectedWeapon->GetActorLocation(); @@ -56,7 +54,7 @@ bool UCloud9AnimNotifyPlaySound::PlayMeleeSound(USkeletalMeshComponent* MeshComp case EWeaponSoundType::Secondary: return UCloud9SoundPlayer::PlayRandomSound(WeaponInfo->Sounds.StabSounds, Location, Volume); default: - log(Error, "[Notify='%s'] Invalid sound type for melee sound", *GetName()); + log(Error, "[%s] Invalid sound type for melee sound", *GetName()); return false; } } @@ -64,11 +62,9 @@ bool UCloud9AnimNotifyPlaySound::PlayMeleeSound(USkeletalMeshComponent* MeshComp bool UCloud9AnimNotifyPlaySound::PlayFirearmSound(USkeletalMeshComponent* MeshComp, float Volume) const { let SelectedWeapon = GetSelectedWeapon(MeshComp); - if (not IsValid(SelectedWeapon) or not SelectedWeapon->IsWeaponDefined()) - { - log(Error, "[Notify='%s'] Invalid or undefined weapon for play sound", *GetName()); - return false; - } + AssertOrReturn( + IsValid(SelectedWeapon) and SelectedWeapon->IsWeaponDefined(), false, + Error, "Invalid or undefined weapon for play sound"); let WeaponInfo = SelectedWeapon->GetWeaponInfo(); let CommonData = SelectedWeapon->GetWeaponCommonData(); @@ -92,7 +88,7 @@ bool UCloud9AnimNotifyPlaySound::PlayFirearmSound(USkeletalMeshComponent* MeshCo } return false; default: - log(Error, "[Notify='%s'] Invalid sound type for firearm sound SoundType=%d", *GetName(), SoundType); + log(Error, "[%s] Invalid sound type for firearm sound SoundType=%d", *GetName(), SoundType); return false; } } @@ -100,11 +96,9 @@ bool UCloud9AnimNotifyPlaySound::PlayFirearmSound(USkeletalMeshComponent* MeshCo bool UCloud9AnimNotifyPlaySound::PlayGrenadeSound(USkeletalMeshComponent* MeshComp, float Volume) const { let SelectedWeapon = GetSelectedWeapon(MeshComp); - if (not IsValid(SelectedWeapon) or not SelectedWeapon->IsWeaponDefined()) - { - log(Error, "[Notify='%s'] Invalid or undefined weapon for play sound", *GetName()); - return false; - } + AssertOrReturn( + IsValid(SelectedWeapon) and SelectedWeapon->IsWeaponDefined(), false, + Error, "Invalid or undefined weapon for play sound"); let WeaponInfo = SelectedWeapon->GetWeaponInfo(); let Location = SelectedWeapon->GetActorLocation(); @@ -118,28 +112,19 @@ bool UCloud9AnimNotifyPlaySound::PlayGrenadeSound(USkeletalMeshComponent* MeshCo case EWeaponSoundType::Primary: return UCloud9SoundPlayer::PlaySingleSound(WeaponInfo->Sounds.ThrowSound, Location, Volume); default: - log(Error, "[Notify='%s'] Invalid sound type for firearm sound SoundType=%d", *GetName(), SoundType); + log(Error, "[%s] Invalid sound type for firearm sound SoundType=%d", *GetName(), SoundType); return false; } } void UCloud9AnimNotifyPlaySound::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) { - if (not bIsEnabled) - { - log(Verbose, "[Notify='%s'] Is disabled", *GetName()); - return; - } + AssertOrVoid(bIsEnabled, Verbose, "Notify is disabled"); #if WITH_EDITORONLY_DATA // See AnimNotify_PlaySound (only variant that's work) let World = MeshComp->GetWorld(); - - if (not IsValid(World)) - { - log(Error, "Game world is invalid") - return; - } + AssertOrVoid(IsValid(World), Error, "Game world is invalid"); if (World->WorldType == EWorldType::EditorPreview) { @@ -164,7 +149,7 @@ void UCloud9AnimNotifyPlaySound::Notify(USkeletalMeshComponent* MeshComp, UAnimS PlayGrenadeSound(MeshComp, Volume); break; default: - log(Error, "[Notify='%s'] Invalid class name", *GetName()); + log(Error, "[%s] Invalid class name", *GetName()); } } } diff --git a/Source/Cloud9/Weapon/Sounds/Cloud9SoundPlayer.cpp b/Source/Cloud9/Weapon/Sounds/Cloud9SoundPlayer.cpp index 7701d7d3b..249c2ebfc 100644 --- a/Source/Cloud9/Weapon/Sounds/Cloud9SoundPlayer.cpp +++ b/Source/Cloud9/Weapon/Sounds/Cloud9SoundPlayer.cpp @@ -9,7 +9,7 @@ bool UCloud9SoundPlayer::PlaySingleSound(USoundBase* Sound, FVector Location, float Volume) { - CheckIsValid(Sound, Error, "Invalid Sound", false); + StaticAssertOrReturn(Sound, false, Error, "Invalid Sound"); USoundAttenuation* AttenuationSettings = nullptr; diff --git a/Source/Cloud9/Weapon/Structures/WeaponConfig.cpp b/Source/Cloud9/Weapon/Structures/WeaponConfig.cpp index 9da0436b9..c942324a3 100644 --- a/Source/Cloud9/Weapon/Structures/WeaponConfig.cpp +++ b/Source/Cloud9/Weapon/Structures/WeaponConfig.cpp @@ -78,7 +78,7 @@ bool FWeaponConfig::Initialize(AActor* Actor) const { if (not IsValid(Actor)) { - log(Error, "Actor is invalid") + log(Error, "Actor is invalid"); return false; } @@ -148,7 +148,7 @@ FWeaponConfig FWeaponConfig::FromWeapon(const ACloud9WeaponBase* Weapon) if (not Config.IsSet()) { - log(Fatal, "Weapon class is undefined") + log(Fatal, "Weapon class is undefined"); return {}; } diff --git a/Source/Cloud9/Weapon/Structures/WeaponDefinition.h b/Source/Cloud9/Weapon/Structures/WeaponDefinition.h index 8f9ff3cb0..1f62731c1 100644 --- a/Source/Cloud9/Weapon/Structures/WeaponDefinition.h +++ b/Source/Cloud9/Weapon/Structures/WeaponDefinition.h @@ -109,7 +109,7 @@ struct FWeaponDefinition } } - log(Error, "WeaponInfo class wasn't set") + log(Error, "WeaponInfo class wasn't set"); return nullptr; } From 4cb6bdffd8803a0b84c4e5698254d62ab6d68b04 Mon Sep 17 00:00:00 2001 From: Alexei Gladkikh Date: Sat, 11 May 2024 16:30:26 +0300 Subject: [PATCH 2/2] #288 Refactored object checking --- Source/Cloud9/Character/Cloud9Character.cpp | 21 +- .../Components/Cloud9EffectsComponent.cpp | 9 +- .../Components/Cloud9InventoryComponent.cpp | 4 +- .../Contollers/Cloud9MouseController.cpp | 2 +- .../Cloud9/Environment/Cloud9LinearDoor.cpp | 6 +- .../Environment/Cloud9PracticeSpawner.cpp | 2 +- Source/Cloud9/Game/Cloud9AssetManager.cpp | 4 +- .../Cloud9/Game/Cloud9DeveloperSettings.cpp | 4 +- Source/Cloud9/Modes/Cloud9GameMode.cpp | 2 +- Source/Cloud9/Tools/Cloud9ToolsLibrary.cpp | 2 +- .../Components/CooldownActionComponent.h | 2 +- Source/Cloud9/Tools/Extensions/AActor.h | 9 +- Source/Cloud9/Tools/Extensions/TOptional.h | 7 +- Source/Cloud9/Tools/Extensions/UEnum.h | 17 +- Source/Cloud9/Tools/Extensions/UObject.h | 4 +- Source/Cloud9/Tools/Extensions/UWorld.h | 4 +- Source/Cloud9/Tools/Macro/Common.h | 60 ++--- Source/Cloud9/Tools/Macro/Logging.h | 60 ++++- .../Weapon/Classes/Cloud9WeaponBase.cpp | 23 +- .../Cloud9/Weapon/Classes/Cloud9WeaponBase.h | 27 -- .../Weapon/Classes/Cloud9WeaponFirearm.cpp | 241 ++++++------------ .../Weapon/Classes/Cloud9WeaponGrenade.cpp | 9 +- .../Weapon/Classes/Cloud9WeaponMelee.cpp | 9 +- Source/Cloud9/Weapon/Enums/WeaponSlot.h | 5 +- .../Notifiers/Cloud9AnimNotifyPlaySound.cpp | 8 +- .../Weapon/Notifiers/Cloud9AnimNotifyWeapon.h | 28 +- .../Weapon/Sounds/Cloud9SoundPlayer.cpp | 19 +- .../Cloud9/Weapon/Structures/WeaponConfig.cpp | 21 +- .../Cloud9/Weapon/Structures/WeaponConfig.h | 25 +- .../Weapon/Structures/WeaponDefinition.h | 2 +- Source/Cloud9/Weapon/Tables/WeaponTableBase.h | 6 +- .../Cloud9/Weapon/Utils/EquipmentSpawner.cpp | 2 +- Source/Cloud9/Weapon/Utils/ItemSpawner.cpp | 14 +- 33 files changed, 246 insertions(+), 412 deletions(-) diff --git a/Source/Cloud9/Character/Cloud9Character.cpp b/Source/Cloud9/Character/Cloud9Character.cpp index 2dc108d78..714c27eff 100644 --- a/Source/Cloud9/Character/Cloud9Character.cpp +++ b/Source/Cloud9/Character/Cloud9Character.cpp @@ -437,15 +437,14 @@ float ACloud9Character::InternalTakePointDamage( if (Settings->WeaponDebugDamageInfo) { - log(Display, - "[Actor='%s'] Distance=%f RangeCoefficient=%f BoneName=%s Armored=%d DamageToHealth=%f DamageToArmor=%f", - *GetName(), - FMath::Sqrt(Distance), - RangeCoefficient, - *BoneName.ToString(), - HitInArmor, - DamageToHealth, - DamageToArmor); + ObjectDisplay( + "Distance=%f RangeCoefficient=%f BoneName=%s Armored=%d DamageToHealth=%f DamageToArmor=%f", + FMath::Sqrt(Distance), + RangeCoefficient, + *BoneName.ToString(), + HitInArmor, + DamageToHealth, + DamageToArmor); } FlinchModLarge = WeaponInfo->GetFlinchVelocityModifierLarge(); @@ -492,7 +491,7 @@ void ACloud9Character::OnConstruction(const FTransform& Transform) if (not CameraTargetBoneName.IsNone()) { let HeadBoneLocation = MyMesh->GetBoneLocation(CameraTargetBoneName, EBoneSpaces::WorldSpace); - log(Verbose, "Setup CameraBoom = %s", *HeadBoneLocation.ToString()); + ObjectVerbose("Setup CameraBoom = %s", *HeadBoneLocation.ToString()); CameraBoom->SetWorldLocation(HeadBoneLocation); } @@ -523,7 +522,7 @@ void ACloud9Character::OnConstruction(const FTransform& Transform) HitBox->SetCollisionProfileName(TRACE_HITBOX); HitBox->CreationMethod = EComponentCreationMethod::UserConstructionScript; - log(Error, "Hitbox registered = %s [%f]", *HitBox->GetName(), HitBox->GetUnscaledCapsuleRadius()); + ObjectVerbose("Hitbox registered = %s [%f]", *HitBox->GetName(), HitBox->GetUnscaledCapsuleRadius()); } } #endif diff --git a/Source/Cloud9/Character/Components/Cloud9EffectsComponent.cpp b/Source/Cloud9/Character/Components/Cloud9EffectsComponent.cpp index afaf12527..60ff01b87 100644 --- a/Source/Cloud9/Character/Components/Cloud9EffectsComponent.cpp +++ b/Source/Cloud9/Character/Components/Cloud9EffectsComponent.cpp @@ -42,8 +42,9 @@ UCloud9CharacterEffectTrait* UCloud9EffectsComponent::AddEffect( AppliedCanDamagedEffects.Add(Effect); } - log(Verbose, "[%s] Apply effect class='%s' effect='%s' (%p) on owner='%s'", - *GetName(), *EffectClass->GetName(), *Effect->GetName(), Effect, *GetOwnerName()); + ObjectVerbose( + "Apply effect class='%s' effect='%s' (%p) on owner='%s'", + *EffectClass->GetName(), *Effect->GetName(), Effect, *GetOwnerName()); return Effect; } @@ -63,8 +64,8 @@ bool UCloud9EffectsComponent::RemoveEffect(UCloud9CharacterEffectTrait* Effect) Effect->OnRemove(); - log(Verbose, "[%s] Remove effect='%s' (%p) on owner='%s'", - *GetName(), *Effect->GetName(), Effect, *GetOwnerName()); + ObjectVerbose("Remove effect='%s' (%p) on owner='%s'", *Effect->GetName(), Effect, *GetOwnerName()); + return true; } diff --git a/Source/Cloud9/Character/Components/Cloud9InventoryComponent.cpp b/Source/Cloud9/Character/Components/Cloud9InventoryComponent.cpp index caed8d128..40c065841 100644 --- a/Source/Cloud9/Character/Components/Cloud9InventoryComponent.cpp +++ b/Source/Cloud9/Character/Components/Cloud9InventoryComponent.cpp @@ -189,7 +189,7 @@ bool UCloud9InventoryComponent::AddWeapon(const FWeaponConfig& Config, bool Sele AssertOrReturn(SelectWeapon(Slot), false, Error, "New weapon selection failure: %s", *Config.ToString()); } - log(Verbose, "[%s] Added configured weapon = '%s'", *GetName(), *Config.ToString()); + ObjectVerbose("Added configured weapon='%s'", *Config.ToString()); WeaponsCount++; OnWeaponAddDelegate.Broadcast(Weapon); @@ -228,7 +228,7 @@ bool UCloud9InventoryComponent::SelectOtherAvailableWeapon(bool Instant, bool Fo | ETContainer::Find{[&](let It) { return It->GetWeaponSlot() != SelectedWeaponSlot; }} | ETOptional::OnSet{[&](let It) { NewSlot = It->GetWeaponSlot(); }}; - log(Verbose, "[%s] Change selected slot to '%d'", *GetName(), NewSlot); + ObjectVerbose("Change selected slot='%d'", NewSlot); return SelectWeapon(NewSlot, Instant, Force); } diff --git a/Source/Cloud9/Contollers/Cloud9MouseController.cpp b/Source/Cloud9/Contollers/Cloud9MouseController.cpp index 26628ff04..da0f13678 100644 --- a/Source/Cloud9/Contollers/Cloud9MouseController.cpp +++ b/Source/Cloud9/Contollers/Cloud9MouseController.cpp @@ -83,7 +83,7 @@ float UCloud9MouseController::GetCameraZoomHeightLevel() const if (not FMath::IsNearlyEqual(ZoomHeightLevel, ZoomAngleLevel, 0.001f)) { - log(Error, "ZoomHeightLevel = %f != ZoomAngleLevel != %f", ZoomHeightLevel, ZoomAngleLevel); + ObjectError("ZoomHeightLevel = %f != ZoomAngleLevel != %f", ZoomHeightLevel, ZoomAngleLevel); } return ZoomHeightLevel; diff --git a/Source/Cloud9/Environment/Cloud9LinearDoor.cpp b/Source/Cloud9/Environment/Cloud9LinearDoor.cpp index 93c4a6b82..a27805c93 100644 --- a/Source/Cloud9/Environment/Cloud9LinearDoor.cpp +++ b/Source/Cloud9/Environment/Cloud9LinearDoor.cpp @@ -78,13 +78,13 @@ void ACloud9LinearDoor::BeginPlay() if (DirectionVector.IsZero()) { SetActorTickEnabled(false); - log(Error, "Door '%s' can't moved due to incorrect direction vector", *GetName()); + ObjectError("Can't moved due to incorrect direction vector"); } if (Speed <= 0.0f) { SetActorTickEnabled(false); - log(Warning, "Door '%s' can't moved due to speed <= 0.0f", *GetName()); + ObjectWarn("Can't moved due to speed <= 0.0f"); } if (Distance <= 0.0f) @@ -97,7 +97,7 @@ void ACloud9LinearDoor::BeginPlay() let ActualDistance = Distance - Extent; - log(Verbose, "Door '%s' distance = '%f'", *GetName(), ActualDistance); + ObjectVerbose("Distance = '%f'", ActualDistance); let Sign = bIsOpen ? -1 : 1; OriginPosition = Transform.GetLocation(); diff --git a/Source/Cloud9/Environment/Cloud9PracticeSpawner.cpp b/Source/Cloud9/Environment/Cloud9PracticeSpawner.cpp index 7f23ec362..8cb5fe5ac 100644 --- a/Source/Cloud9/Environment/Cloud9PracticeSpawner.cpp +++ b/Source/Cloud9/Environment/Cloud9PracticeSpawner.cpp @@ -103,7 +103,7 @@ AActor* ACloud9PracticeSpawner::SpawnTarget_Implementation(FVector Location) { if (not IsValid(Template)) { - log(Error, "[%s]: Actor class not specified", *GetName()); + ObjectError("Actor class not specified"); bIsEnabled = false; SetActorTickEnabled(false); return nullptr; diff --git a/Source/Cloud9/Game/Cloud9AssetManager.cpp b/Source/Cloud9/Game/Cloud9AssetManager.cpp index 07c0ad900..aeffdb055 100644 --- a/Source/Cloud9/Game/Cloud9AssetManager.cpp +++ b/Source/Cloud9/Game/Cloud9AssetManager.cpp @@ -52,9 +52,9 @@ UObject* UCloud9AssetManager::GetOrLoadScannedAssetSync(FPrimaryAssetId PrimaryA static var& Manager = Get(); let Future = Manager.LoadPrimaryAsset(PrimaryAssetId); - StaticAssertOrReturn(Future, nullptr, Error, "Can't find asset: '%s'", *PrimaryAssetId.ToString()); + FunctionAssertOrReturn(Future, nullptr, Error, "Can't find asset: '%s'", *PrimaryAssetId.ToString()); - StaticAssertOrReturn( + FunctionAssertOrReturn( Future->WaitUntilComplete() == EAsyncPackageState::Complete, nullptr, Error, "Failed to loading asset: '%s'", *PrimaryAssetId.ToString()); diff --git a/Source/Cloud9/Game/Cloud9DeveloperSettings.cpp b/Source/Cloud9/Game/Cloud9DeveloperSettings.cpp index a614cf05d..79c41586d 100644 --- a/Source/Cloud9/Game/Cloud9DeveloperSettings.cpp +++ b/Source/Cloud9/Game/Cloud9DeveloperSettings.cpp @@ -91,7 +91,7 @@ UCloud9DeveloperSettings* UCloud9DeveloperSettings::Get() void UCloud9DeveloperSettings::Save() { UpdateDefaultConfigFile(); - log(Display, "%s", this | EUObject::Stringify{} | EFString::ToCStr{}); + ObjectDisplay("%s", this | EUObject::Stringify{} | EFString::ToCStr{}); } template @@ -268,7 +268,7 @@ void UCloud9DeveloperSettings::InitializeCVars() TEXT("Decal size to fade off screen") ); - log(Display, "%s", this | EUObject::Stringify{} | EFString::ToCStr{}); + ObjectDisplay("%s", this | EUObject::Stringify{} | EFString::ToCStr{}); } } diff --git a/Source/Cloud9/Modes/Cloud9GameMode.cpp b/Source/Cloud9/Modes/Cloud9GameMode.cpp index 2febf2d87..e230692d5 100644 --- a/Source/Cloud9/Modes/Cloud9GameMode.cpp +++ b/Source/Cloud9/Modes/Cloud9GameMode.cpp @@ -56,7 +56,7 @@ void ACloud9GameMode::StartToLeaveMap() if (let MyWorld = GetWorld(); MyWorld != nullptr) { - log(Verbose, "Cleanup world timers = %p", this); + ObjectVerbose("Cleanup world timers = %p", this); MyWorld | EUWorld::ClearAllTimers{}; } diff --git a/Source/Cloud9/Tools/Cloud9ToolsLibrary.cpp b/Source/Cloud9/Tools/Cloud9ToolsLibrary.cpp index 7c2da0fb2..1c5d8ec7c 100644 --- a/Source/Cloud9/Tools/Cloud9ToolsLibrary.cpp +++ b/Source/Cloud9/Tools/Cloud9ToolsLibrary.cpp @@ -94,7 +94,7 @@ void UCloud9ToolsLibrary::GetWidthHeightDepth(const FBox& Box, float& Width, flo TArray UCloud9ToolsLibrary::GetObjectEditorProperties(UClass* Class) { - StaticAssertOrReturn(IsValid(Class), {}, Error, "Input class is invalid"); + FunctionAssertOrReturn(IsValid(Class), {}, Error, "Input class is invalid"); return TFieldIterator(Class) | ETContainer::FromIterator{} | ETContainer::Filter{[](let& It) { return It.HasAnyPropertyFlags(CPF_Edit); }} diff --git a/Source/Cloud9/Tools/Components/CooldownActionComponent.h b/Source/Cloud9/Tools/Components/CooldownActionComponent.h index 20e3b3871..a0a566df2 100644 --- a/Source/Cloud9/Tools/Components/CooldownActionComponent.h +++ b/Source/Cloud9/Tools/Components/CooldownActionComponent.h @@ -61,7 +61,7 @@ class CLOUD9_API UCooldownActionComponent : public UActorComponent { if (not OnExecute()) { - log(Error, "[%s] Failed to execute function", *GetName()); + ObjectError("Failed to execute action function"); OnComplete(); return false; } diff --git a/Source/Cloud9/Tools/Extensions/AActor.h b/Source/Cloud9/Tools/Extensions/AActor.h index e0918413d..784470102 100644 --- a/Source/Cloud9/Tools/Extensions/AActor.h +++ b/Source/Cloud9/Tools/Extensions/AActor.h @@ -68,7 +68,7 @@ namespace EAActor return -Self->GetActorForwardVector(); } - log(Fatal, "Invalid value Actor = '%s' Direction = '%d'", *Self->GetName(), Direction); + FunctionFatal("Invalid value Actor = '%s' Direction = '%d'", *Self->GetName(), Direction); return {}; } @@ -86,7 +86,7 @@ namespace EAActor // May be not needed? if (Self->IsPendingKill()) { - log(Warning, "[%s] Already waiting it's death", *Self->GetName()); + FunctionWarning("Object '%s' already waiting it's death", *Self->GetName()); return {}; } @@ -101,10 +101,7 @@ namespace EAActor return {}; } - log( - Verbose, - "[%s] Set to be destroyed with delay but won't be because Delay<0.0f", - *Self->GetName()); + FunctionVerbose("[%s] Set to be destroyed with delay but won't be because Delay<0.0f", *Self->GetName()); return {}; } diff --git a/Source/Cloud9/Tools/Extensions/TOptional.h b/Source/Cloud9/Tools/Extensions/TOptional.h index 868540410..e163d7a74 100644 --- a/Source/Cloud9/Tools/Extensions/TOptional.h +++ b/Source/Cloud9/Tools/Extensions/TOptional.h @@ -31,7 +31,6 @@ namespace ETOptional template struct Get : TOperator> { - public: constexpr explicit Get() : DefaultValueGetter(NullOptionalDereference) {} template requires std::invocable @@ -44,7 +43,7 @@ namespace ETOptional constexpr const ValueType& operator()(const TOptional& Self) { // nullptr_t is acceptable because we case crash on dereference - // using log(Fatal) if not default argument was set + // using Fatal if not default argument was set static_assert( TIsSame::Value or TIsSame::Value, "Default value type and value type should be the same or default value type should be nullptr_t" @@ -66,7 +65,7 @@ namespace ETOptional constexpr static DefaultValueType NullOptionalDereference() { - log(Fatal, "nullopt dereference"); + FunctionFatal("nullopt dereference"); return {}; } }; @@ -82,7 +81,6 @@ namespace ETOptional template struct OnNull { - public: const BlockType& Block; template @@ -120,7 +118,6 @@ namespace ETOptional struct IsSet { - public: template constexpr bool operator()(const TOptional& Self) { return Self.IsSet(); } diff --git a/Source/Cloud9/Tools/Extensions/UEnum.h b/Source/Cloud9/Tools/Extensions/UEnum.h index 697fdc4f6..7fa1a3f1e 100644 --- a/Source/Cloud9/Tools/Extensions/UEnum.h +++ b/Source/Cloud9/Tools/Extensions/UEnum.h @@ -60,7 +60,7 @@ namespace EUEnum return Block(EnumClass, EnumValue); } - log(Error, "Can't get static enum class for value '%d'", Self); + FunctionError("Can't get static enum class for value '%d'", Self); return Default; } @@ -111,12 +111,8 @@ namespace EUEnum FORCEINLINE FName operator()(const UEnum* Self) const { - if (ValueId < 0) - { - log(Error, "GetValueName should not be called with ValueId < 0"); - return {NAME_None}; - } - + FunctionAssertOrReturn(ValueId >= 0, NAME_None, Error, + "GetValueName should not be called with ValueId < 0"); return GetOnlyValueName(Self, ValueId); } @@ -135,12 +131,7 @@ namespace EUEnum static FName GetOnlyValueName(const UEnum* Enum, const int Value) { let Name = Enum->GetNameByIndex(Value); - - if (Name.IsNone()) - { - log(Error, "Invalid value name"); - return {NAME_None}; - } + FunctionAssertOrReturn(not Name.IsNone(), NAME_None, Error, "Invalid value name"); let String = Name.ToString(); diff --git a/Source/Cloud9/Tools/Extensions/UObject.h b/Source/Cloud9/Tools/Extensions/UObject.h index 005c50506..32874071b 100644 --- a/Source/Cloud9/Tools/Extensions/UObject.h +++ b/Source/Cloud9/Tools/Extensions/UObject.h @@ -58,7 +58,7 @@ namespace EUObject { var MyWorld = Self->GetWorld(); // Should we crash or not crash in this case? - StaticAssertOrReturn(IsValid(MyWorld), {}, Fatal, "Timer not set due to game World not exists"); + FunctionAssertOrReturn(IsValid(MyWorld), {}, Fatal, "Timer not set due to game World not exists"); return MyWorld | EUWorld::AsyncAfter{Block, InRate, bInLoop}; } @@ -73,7 +73,7 @@ namespace EUObject { let MyWorld = Self->GetWorld(); // Should we crash or not crash in this case? - StaticAssertOrReturn(IsValid(MyWorld), {}, Fatal, "Timer not set due to game World not exists"); + FunctionAssertOrReturn(IsValid(MyWorld), {}, Fatal, "Timer not set due to game World not exists"); return MyWorld | EUWorld::IsTimerActive{TimerHandle}; } diff --git a/Source/Cloud9/Tools/Extensions/UWorld.h b/Source/Cloud9/Tools/Extensions/UWorld.h index 7e1ce387b..3eb1d1506 100644 --- a/Source/Cloud9/Tools/Extensions/UWorld.h +++ b/Source/Cloud9/Tools/Extensions/UWorld.h @@ -144,9 +144,9 @@ namespace EUWorld { FORCEINLINE GameModeType* operator()(const UWorld* Self) const { - StaticAssertOrReturn(IsValid(Self), nullptr, Error, "World isn't valid to get GameMode"); + FunctionAssertOrReturn(IsValid(Self), nullptr, Error, "World isn't valid to get GameMode"); let GameMode = UGameplayStatics::GetGameMode(Self); - StaticAssertOrReturn(IsValid(GameMode), nullptr, Error, "Current GameMode isn't valid"); + FunctionAssertOrReturn(IsValid(GameMode), nullptr, Error, "Current GameMode isn't valid"); return Cast(GameMode); } diff --git a/Source/Cloud9/Tools/Macro/Common.h b/Source/Cloud9/Tools/Macro/Common.h index af5af111c..8776cfa6d 100644 --- a/Source/Cloud9/Tools/Macro/Common.h +++ b/Source/Cloud9/Tools/Macro/Common.h @@ -29,40 +29,36 @@ #define let const auto #define var auto -#define AssertOrReturn(What, Value, Severity, Message, ...) \ - do { \ - if (not (What)) \ - { \ - log(Severity, "[%s]: %s", *GetName(), *FString::Printf(TEXT(Message), ##__VA_ARGS__)); \ - return Value; \ - } \ - } while(false) +#define AssertOrReturn(What, Value, Severity, Message, ...) do { \ + if (not (What)) \ + { \ + log(Severity, "[%s]: %s", *GetName(), *FString::Printf(TEXT(Message), ##__VA_ARGS__)); \ + return Value; \ + } \ +} while (false) -#define AssertOrVoid(What, Severity, Message, ...) \ - do { \ - if (not (What)) \ - { \ - log(Severity, "[%s]: %s", *GetName(), *FString::Printf(TEXT(Message), ##__VA_ARGS__)); \ - return; \ - } \ - } while(false) +#define AssertOrVoid(What, Severity, Message, ...) do { \ + if (not (What)) \ + { \ + log(Severity, "[%s]: %s", *GetName(), *FString::Printf(TEXT(Message), ##__VA_ARGS__)); \ + return; \ + } \ +} while (false) -#define StaticAssertOrReturn(What, Value, Severity, Message, ...) \ - do { \ - if (not (What)) \ - { \ - log(Severity, Message, __VA_ARGS__); \ - return Value; \ - } \ - } while(false) +#define FunctionAssertOrReturn(What, Value, Severity, Message, ...) do { \ + if (not (What)) \ + { \ + log(Severity, Message, __VA_ARGS__); \ + return Value; \ + } \ +} while (false) -#define StaticAssertOrVoid(What, Severity, Message, ...) \ - do { \ - if (not (What)) \ - { \ - log(Severity, Message, ##__VA_ARGS__); \ - return; \ - } \ - } while(false) +#define FunctionAssertOrVoid(What, Severity, Message, ...) do { \ + if (not (What)) \ + { \ + log(Severity, Message, ##__VA_ARGS__); \ + return; \ + } \ +} while (false) #define AssertOrCrash(Condition, FormatString, ...) checkf(Condition, TEXT(FormatString), ##__VA_ARGS__) diff --git a/Source/Cloud9/Tools/Macro/Logging.h b/Source/Cloud9/Tools/Macro/Logging.h index cb05faac9..09b1c5fd6 100644 --- a/Source/Cloud9/Tools/Macro/Logging.h +++ b/Source/Cloud9/Tools/Macro/Logging.h @@ -33,14 +33,52 @@ ) \ ) -#define log(Severity, FormatString, ...) \ - do { \ - UE_LOG(\ - LogCloud9, \ - Severity, \ - TEXT("%s: %s"), \ - *TRACE_STR_CUR_CLASS_FUNC_LINE, \ - *FString::Printf(TEXT(FormatString), ##__VA_ARGS__) \ - ) \ - } \ - while (false) +#define log(Severity, FormatString, ...) do { \ + UE_LOG(\ + LogCloud9, \ + Severity, \ + TEXT("%s: %s"), \ + *TRACE_STR_CUR_CLASS_FUNC_LINE, \ + *FString::Printf(TEXT(FormatString), ##__VA_ARGS__) \ + ) \ +} while (false) + +#define FunctionFatal(Message, ...) do { \ + log(Fatal, Message, ##__VA_ARGS__); \ +} while (false) + +#define FunctionError(Message, ...) do { \ + log(Error, Message, ##__VA_ARGS__); \ +} while (false) + +#define FunctionWarning(Message, ...) do { \ + log(Warning, Message, ##__VA_ARGS__); \ +} while (false) + +#define FunctionDisplay(Message, ...) do { \ + log(Display, Message, ##__VA_ARGS__); \ +} while (false) + +#define FunctionVerbose(Message, ...) do { \ + log(Verbose, Message, ##__VA_ARGS__); \ +} while (false) + +#define ObjectFatal(Message, ...) do { \ + log(Fatal, "[%s]: %s", *GetName(), *FString::Printf(TEXT(Message), ##__VA_ARGS__)); \ +} while (false) + +#define ObjectError(Message, ...) do { \ + log(Error, "[%s]: %s", *GetName(), *FString::Printf(TEXT(Message), ##__VA_ARGS__)); \ +} while (false) + +#define ObjectWarn(Message, ...) do { \ + log(Warning, "[%s]: %s", *GetName(), *FString::Printf(TEXT(Message), ##__VA_ARGS__)); \ +} while (false) + +#define ObjectDisplay(Message, ...) do { \ + log(Display, "[%s]: %s", *GetName(), *FString::Printf(TEXT(Message), ##__VA_ARGS__)); \ +} while (false) + +#define ObjectVerbose(Message, ...) do { \ + log(Verbose, "[%s]: %s", *GetName(), *FString::Printf(TEXT(Message), ##__VA_ARGS__)); \ +} while (false) diff --git a/Source/Cloud9/Weapon/Classes/Cloud9WeaponBase.cpp b/Source/Cloud9/Weapon/Classes/Cloud9WeaponBase.cpp index ba9640260..f89df7f24 100644 --- a/Source/Cloud9/Weapon/Classes/Cloud9WeaponBase.cpp +++ b/Source/Cloud9/Weapon/Classes/Cloud9WeaponBase.cpp @@ -99,7 +99,7 @@ UWeaponDefinitionsAsset* ACloud9WeaponBase::GetWeaponDefinitionsAsset() // Try reload later then ... this will haven in PIE // if some object required this asset placed on level - StaticAssertOrReturn(IsValid(Asset), nullptr, Error, "WeaponDefinitionsAsset loading failure"); + FunctionAssertOrReturn(IsValid(Asset), nullptr, Error, "WeaponDefinitionsAsset loading failure"); WeaponDefinitionsAsset = Asset; @@ -221,9 +221,9 @@ bool ACloud9WeaponBase::UpdateWeaponAttachment(EWeaponSlot NewSlot, EWeaponBond CharacterMesh->GetSocketByName(SocketName), false, Error, "Socket not found in character mesh for '%s'", SLOT_NAME); - log(Verbose, - "[Weapon='%s' Slot='%s'] Update attachment to character '%s' into socket '%s'", - *GetName(), SLOT_NAME, *Character->GetName(), *SocketName.ToString()); + ObjectDisplay( + "Update attachment to character '%s' into socket '%s'", + *Character->GetName(), *SocketName.ToString()); AttachToComponent(CharacterMesh, FAttachmentTransformRules::SnapToTargetIncludingScale, SocketName); @@ -267,7 +267,7 @@ bool ACloud9WeaponBase::AddToInventory(ACloud9Character* Character, EWeaponSlot if (not UpdateWeaponAttachment(NewSlot, EWeaponBond::Holstered)) { - log(Error, "Failed to update attachment for weapon '%s' slot '%s'", *GetName(), SLOT_NAME); + ObjectError("Failed to update attachment for slot '%s'", SLOT_NAME); SetOwner(nullptr); return false; } @@ -279,11 +279,8 @@ bool ACloud9WeaponBase::AddToInventory(ACloud9Character* Character, EWeaponSlot bool ACloud9WeaponBase::RemoveFromInventory() { - if (let Character = GetOwner(); not Character) - { - log(Error, "[Weapon='%s'] Weapon not in any inventory", *GetName()); - return false; - } + let Character = GetOwner(); + AssertOrReturn(IsValid(Character), false, Error, "Weapon not in any inventory"); // TODO: Add velocity impulse when weapon dropped @@ -351,7 +348,7 @@ bool ACloud9WeaponBase::Initialize(const FWeaponConfig& WeaponConfig) if (not OnInitialize(WeaponConfig)) { - log(Error, "[Weapon='%s'] Weapon initialization failure", *GetName()); + ObjectError("Weapon initialization failure"); Deinitialize(); return false; } @@ -376,7 +373,7 @@ bool ACloud9WeaponBase::OnInitialize(const FWeaponConfig& WeaponConfig) void ACloud9WeaponBase::Deinitialize() { - log(Warning, "[Weapon='%s'] Deinitialize weapon to initial state", *GetName()); + ObjectWarn("Deinitialize weapon to initial state"); WeaponSkin = FWeaponSkin::Default; @@ -408,7 +405,7 @@ FName ACloud9WeaponBase::GetWeaponName() const { return GetWeaponId() | EFWeapon FWeaponId ACloud9WeaponBase::GetWeaponId() const { static let UnknownWeaponId = ETVariant::Convert(EBadWeapon::NoClass); - log(Fatal, "[Weapon='%s'] Not implmemented", *GetName()); + ObjectFatal("Not implmemented"); return UnknownWeaponId; } diff --git a/Source/Cloud9/Weapon/Classes/Cloud9WeaponBase.h b/Source/Cloud9/Weapon/Classes/Cloud9WeaponBase.h index 1bf679a6d..73cb1f542 100644 --- a/Source/Cloud9/Weapon/Classes/Cloud9WeaponBase.h +++ b/Source/Cloud9/Weapon/Classes/Cloud9WeaponBase.h @@ -234,33 +234,6 @@ class CLOUD9_API ACloud9WeaponBase : public AActor const FWeaponCommonData* GetWeaponCommonData() const; -#define WEAPON_IS_DEFINED_GUARD() \ - if (not IsWeaponDefined()) \ - { \ - log(Error, "[%s] Not defined", *GetName()); \ - return; \ - } - -#define WEAPON_ANIM_COMPONENT_GUARD() \ - if (not IsValid(AnimComponent)) \ - { \ - log(Warning, "[%s] AnimComponent isn't valid", *GetName()); \ - return; \ - } - -#define WEAPON_IS_ACTION_IN_PROGRESS_GUARD() \ - if (IsActionInProgress()) \ - { \ - log(Verbose, "[%s] Action already in progress during Tick", *GetName()); \ - return; \ - } - -#define WEAPON_IS_DISARMED_GUARD() \ - if (IsWeaponDisarmed()) \ - { \ - return; \ - } - // properties /** * Current weapon skin name diff --git a/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp b/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp index 5674f53bf..2c1984ba2 100644 --- a/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp +++ b/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp @@ -63,20 +63,12 @@ TErrorValue FCursorHitScanInfo::Create( static let Settings = UCloud9DeveloperSettings::Get(); let Character = Firearm->GetOwner(); - - if (not IsValid(Character)) - { - log(Error, "Character is invalid"); - return EFirearmFireStatus::Error; - } + FunctionAssertOrReturn(IsValid(Character), EFirearmFireStatus::Error, Error, "Character is invalid"); let Controller = Character->GetCloud9Controller(); - - if (not IsValid(Controller)) - { - log(Error, "Can't hit object because player controller isn't valid"); - return EFirearmFireStatus::Error; - } + FunctionAssertOrReturn( + IsValid(Controller), EFirearmFireStatus::Error, + Error, "Can't hit object because player controller isn't valid"); var Result = FCursorHitScanInfo(); @@ -92,11 +84,9 @@ TErrorValue FCursorHitScanInfo::Create( Result.ActorsToIgnore }; - if (not CursorHit) - { - log(Error, "Cursor wasn't hit anything"); - return EFirearmFireStatus::NoCursorHit; - } + FunctionAssertOrReturn( + CursorHit, EFirearmFireStatus::NoCursorHit, + Error, "Cursor wasn't hit anything"); Result.EndLocation = CursorHit->Location; Result.Alpha = FirearmCommonData.LineTraceAlpha; @@ -108,13 +98,11 @@ TErrorValue FCursorHitScanInfo::Create( true }; - if (not CursorHit) - { - log(Error, "Cursor wasn't anything"); - return EFirearmFireStatus::NoCursorHit; - } + FunctionAssertOrReturn( + CursorHit, EFirearmFireStatus::NoCursorHit, + Error, "Cursor wasn't hit anything"); - // Check if use Somali shooting (when cursor on Character) + // Check if character use Somali shooting (when cursor on Character) if (CursorHit->Actor == Character) { Result.EndLocation = Result.StartLocation + Firearm->GetShootLocationActor()->GetForwardVector(); @@ -138,41 +126,31 @@ bool ACloud9WeaponFirearm::OnInitialize(const FWeaponConfig& WeaponConfig) { let MyWeaponInfo = WeaponDefinition.GetWeaponInfo(); let MySkinInfo = MyWeaponInfo | EFWeaponInfo::GetSkinByNameOrThrow(WeaponConfig.GetSkinName()); + AssertOrReturn(MySkinInfo.Material, false, Error, "Skin material is invalid"); - if (MySkinInfo.Material == nullptr) - { - log(Error, "[Weapon='%s'] Skin material is invalid", *GetName()); - return false; - } - - if (not InitializeMeshComponent(WeaponMesh, MyWeaponInfo->WeaponModel, MySkinInfo.Material)) - { - log(Error, "[Weapon='%s'] Can't initilaize WeaponMesh", *GetName()); - return false; - } + AssertOrReturn( + InitializeMeshComponent(WeaponMesh, MyWeaponInfo->WeaponModel, MySkinInfo.Material), false, + Error, "Can't initilaize WeaponMesh" + ); - if (not InitializeMeshComponent( - MagazineMesh, - MyWeaponInfo->MagazineModel, - MyWeaponInfo->bIsMagazinePainted ? MySkinInfo.Material : nullptr)) - { - log(Error, "[Weapon='%s'] Can't initilaize MagazineMesh", *GetName()); - return false; - } + AssertOrReturn( + InitializeMeshComponent( + MagazineMesh, MyWeaponInfo->MagazineModel, + MyWeaponInfo->bIsMagazinePainted ? MySkinInfo.Material : nullptr), false, + Error, "Can't initilaize MagazineMesh" + ); - if (not InitializeEffectComponent(MuzzleFlash, MyWeaponInfo->Effects.MuzzleFlash)) - { - log(Error, "[Weapon='%s'] Can't initilaize MuzzleFlash", *GetName()); - return false; - } + AssertOrReturn( + InitializeEffectComponent(MuzzleFlash, MyWeaponInfo->Effects.MuzzleFlash), false, + Error, "Can't initilaize MuzzleFlash" + ); if (MyWeaponInfo->SilencerModel) { - if (not InitializeMeshComponent(SilencerMesh, MyWeaponInfo->SilencerModel, MySkinInfo.Material)) - { - log(Error, "[Weapon='%s'] Can't initilaize SilencerMesh", *GetName()); - return false; - } + AssertOrReturn( + InitializeMeshComponent(SilencerMesh, MyWeaponInfo->SilencerModel, MySkinInfo.Material), false, + Error, "Can't initilaize SilencerMesh" + ); } MaxMagazineSize = MyWeaponInfo->MagazineSize; @@ -188,8 +166,9 @@ bool ACloud9WeaponFirearm::OnInitialize(const FWeaponConfig& WeaponConfig) OnAmmoInMagazineChanged.Broadcast(CurrentAmmo); OnAmmoInReserveChanged.Broadcast(AmmoInReserve); - log(Verbose, "[Weapon='%s'] CurrentAmmo=%d MaxMagazineSize=%d AmmoInReserve=%d MaxAmmoInReserve=%d", - *GetName(), CurrentAmmo, MaxMagazineSize, AmmoInReserve, MaxAmmoInReserve); + ObjectVerbose( + "CurrentAmmo=%d MaxMagazineSize=%d AmmoInReserve=%d MaxAmmoInReserve=%d", + CurrentAmmo, MaxMagazineSize, AmmoInReserve, MaxAmmoInReserve); return true; } @@ -217,17 +196,16 @@ void ACloud9WeaponFirearm::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); - WEAPON_IS_DEFINED_GUARD(); - WEAPON_IS_DISARMED_GUARD(); + AssertOrVoid(IsWeaponDefined(), Error, "Weapon not defined"); + AssertOrVoid(not IsWeaponDisarmed(), Verbose, "AnimComponent isn't valid"); UpdateAccuracyPenalty(DeltaSeconds); - WEAPON_IS_ACTION_IN_PROGRESS_GUARD(); + AssertOrVoid(not IsActionInProgress(), Verbose, "Action already in progress during Tick"); let Character = GetOwner(); // suppose a weapon has owner cus we pass bond guard let AnimComponent = Character->GetAnimationComponent(); - - WEAPON_ANIM_COMPONENT_GUARD(); + AssertOrVoid(IsValid(AnimComponent), Error, "AnimComponent isn't valid"); let WeaponInfo = WeaponDefinition.GetWeaponInfo(); let PoseMontages = WeaponDefinition.GetPoseMontages(Character->bIsCrouched); @@ -318,17 +296,14 @@ void ACloud9WeaponFirearm::Tick(float DeltaSeconds) return true; } - if (Status == EFirearmFireStatus::Error) - { - log(Error, "[Weapon='%s'] Weapon fire failure status = %d", *GetName(), Status); - return false; - } + AssertOrReturn( + Status != EFirearmFireStatus::Error, false, + Error, "Weapon fire failure status=%d", Status); - if (not AnimComponent->PlayMontage(PoseMontages->PrimaryActionMontage)) - { - log(Error, "[Weapon='%s'] No montage for primary action specified", *GetName()); - return false; - } + AssertOrReturn( + AnimComponent->PlayMontage(PoseMontages->PrimaryActionMontage), false, + Error, "No montage for primary action specified" + ); // TODO: May be move to notifier? MuzzleFlash->Activate(true); @@ -408,11 +383,7 @@ EFirearmFireStatus ACloud9WeaponFirearm::PrimaryAttack( } }; - if (not IsOk) - { - log(Error, "[Weapon='%s'] Gun fire error...", *GetName()); - return EFirearmFireStatus::Error; - } + AssertOrReturn(IsOk, EFirearmFireStatus::Error, Error, "Gun fire error..."); } AccuracyPenalty += WeaponInfo->GetInaccuracyFire(); @@ -437,12 +408,7 @@ EFirearmFireStatus ACloud9WeaponFirearm::GunFire( static let Settings = UCloud9DeveloperSettings::Get(); let Character = GetOwner(); - - if (not IsValid(Character)) - { - log(Error, "Character is invalid"); - return EFirearmFireStatus::Error; - } + AssertOrReturn(IsValid(Character), EFirearmFireStatus::Error, Error, "Character is invalid"); // GetHitResultUnderCursor can return coordinates slightly upper then surface // Prolong line in shoot direction @@ -479,16 +445,16 @@ EFirearmFireStatus ACloud9WeaponFirearm::GunFire( : TEXT("???"); FString PhysicalMaterial = LineHit.PhysMaterial.IsValid() ? *LineHit.PhysMaterial->GetName() : TEXT("???"); - log(Display, - "Target='%s' Owner='%s' Material='%s' Start={%s} End={%s} TraceEnd={%s} Hit={%s} Normal={%s}", - *TargetName, - *OwnerName, - *PhysicalMaterial, - *HitScanInfo.StartLocation.ToString(), - *EndLocation.ToString(), - *LineHit.TraceEnd.ToString(), - *LineHit.Location.ToString(), - *LineHit.Normal.ToString() + ObjectDisplay( + "Target='%s' Owner='%s' Material='%s' Start={%s} End={%s} TraceEnd={%s} Hit={%s} Normal={%s}", + *TargetName, + *OwnerName, + *PhysicalMaterial, + *HitScanInfo.StartLocation.ToString(), + *EndLocation.ToString(), + *LineHit.TraceEnd.ToString(), + *LineHit.Location.ToString(), + *LineHit.Normal.ToString() ); } @@ -545,7 +511,7 @@ EFirearmFireStatus ACloud9WeaponFirearm::GunFire( Damage * FirearmCommonData.ImpulseMultiplier, FirearmCommonData.MinAppliedImpulse, FirearmCommonData.MaxAppliedImpulse); - log(Verbose, "[%s] Damage=%f Impulse=%f", *GetName(), Damage, Impulse); + ObjectVerbose("[%s] Damage=%f Impulse=%f", *GetName(), Damage, Impulse); Target->AddImpulseAtLocation(Direction * Impulse, LineHit.Location, LineHit.BoneName); } @@ -777,7 +743,7 @@ float ACloud9WeaponFirearm::GetInaccuracy() const 0.0f, // No movement-related penalty when close to stopped InaccuracyJumpInitial - ); // Movement-penalty at start of jump + ); // Movement-penalty at the start of jump // Clamp to min/max values. (Don't use RemapValClamped because it makes clamping to > kJumpMovePenalty hard) if (AirSpeedInaccuracy < 0.0f) @@ -818,7 +784,7 @@ TArray ACloud9WeaponFirearm::RecalculateByShotInaccuracy( RadiusCurveDensity = 1.0f - RadiusCurveDensity * RadiusCurveDensity; } - // Negev currently not implemented but left this check if will be added + // Negev currently isn't implemented but left this check if will be added if (GetWeaponId() == EFirearm::Negev and RecoilPattern < 3) /* NEGEV WILD BEAST */ { for (int j = 3; j > RecoilPattern; --j) @@ -941,12 +907,7 @@ void ACloud9WeaponFirearm::UpdateAccuracyPenalty(float DeltaSeconds) static let Settings = UCloud9DeveloperSettings::Get(); let Character = GetOwner(); - - if (not IsValid(Character)) - { - log(Error, "[Weapon='%s'] Weapon owner is invalid", *GetName()); - return; - } + AssertOrVoid(IsValid(Character), Error, "Weapon owner is invalid"); let WeaponInfo = GetWeaponInfo(); @@ -1006,12 +967,7 @@ void ACloud9WeaponFirearm::UpdateAccuracyPenalty(float DeltaSeconds) float ACloud9WeaponFirearm::GetRecoveryTime() const { let Character = GetOwner(); - - if (not IsValid(Character)) - { - log(Error, "[Weapon='%s'] Weapon owner is invalid", *GetName()); - return -1.0f; - } + AssertOrReturn(IsValid(Character), -1.0f, Error, "Weapon owner is invalid"); let WeaponInfo = GetWeaponInfo(); @@ -1074,12 +1030,7 @@ float ACloud9WeaponFirearm::GetRecoveryTime() const bool ACloud9WeaponFirearm::UpdateMagazineAttachment(bool IsReload) { let Character = GetOwner(); - - if (not IsValid(Character)) - { - log(Error, "[Weapon='%s'] Weapon owner is invalid", *GetName()); - return false; - } + AssertOrReturn(IsValid(Character), false, Error, "Weapon owner is invalid"); UMeshComponent* Mesh; FName SocketName; @@ -1088,26 +1039,11 @@ bool ACloud9WeaponFirearm::UpdateMagazineAttachment(bool IsReload) if (IsReload) { let CharacterMesh = Character->GetMesh(); - - if (not IsValid(CharacterMesh)) - { - log(Error, "[Weapon='%s'] Character mesh is invalid", *GetName()); - return false; - } + AssertOrReturn(IsValid(CharacterMesh), false, Error, "Character mesh is invalid"); SocketName = UWeaponSlot::ReloadWeaponSocket(GetWeaponType()); - - if (SocketName.IsNone()) - { - log(Error, "[Weapon='%s'] Can't get socket name='%s'", *GetName(), *SocketName.ToString()); - return false; - } - - if (not CharacterMesh->GetSocketByName(SocketName)) - { - log(Error, "[Weapon='%s'] Socket not found in character mesh", *GetName()); - return false; - } + AssertOrReturn(not SocketName.IsNone(), false, Error, "Can't get socket name='%s'", *SocketName.ToString()); + AssertOrReturn(CharacterMesh->GetSocketByName(SocketName), false, Error, "Socket not found in character mesh"); Mesh = CharacterMesh; IsDetached = true; @@ -1115,20 +1051,10 @@ bool ACloud9WeaponFirearm::UpdateMagazineAttachment(bool IsReload) else { let Inventory = Character->GetInventoryComponent(); - - if (not IsValid(Inventory)) - { - log(Error, "[Weapon='%s'] Inventory is invalid", *GetName()); - return false; - } + AssertOrReturn(IsValid(Inventory), false, Error, "Inventory is invalid"); let SelectedWeapon = Inventory->GetSelectedWeapon(); - - if (not IsValid(SelectedWeapon)) - { - log(Error, "[Weapon='%s'] Selected weapon is invalid", *GetName()); - return false; - } + AssertOrReturn(IsValid(SelectedWeapon), false, Error, "Selected weapon is invalid"); Mesh = SelectedWeapon->GetWeaponMesh(); @@ -1136,19 +1062,16 @@ bool ACloud9WeaponFirearm::UpdateMagazineAttachment(bool IsReload) IsDetached = false; } - if (MagazineMesh->AttachToComponent(Mesh, FAttachmentTransformRules::KeepRelativeTransform, SocketName)) - { - log(Verbose, - "[Weapon='%s'] Update magazine attachment to Mesh='%s' socket='%s'", - *GetName(), *Mesh->GetName(), *SocketName.ToString()); + // Attach in any case either to character (if reloading in progress) or to weapon (if reloading finished) + // WARN: Also need to correct socket (size and rotation) in skeletal mesh if added other weapons + AssertOrReturn( + MagazineMesh->AttachToComponent(Mesh, FAttachmentTransformRules::KeepRelativeTransform, SocketName), false, + Error, "Can't change magazine attachement"); - WeaponState.DetachMagazine(IsDetached); - return true; - } - - log(Error, "[Weapon='%s'] Can't change magazine attachement", *GetName()); + ObjectVerbose("Update magazine attachment to Mesh='%s' Socket='%s'", *Mesh->GetName(), *SocketName.ToString()); - return false; + WeaponState.DetachMagazine(IsDetached); + return true; } void ACloud9WeaponFirearm::DropMagazine() const @@ -1172,22 +1095,12 @@ void ACloud9WeaponFirearm::DropMagazine() const void ACloud9WeaponFirearm::EjectCase() const { let World = GetWorld(); - - if (not GetWeaponMesh()->GetSocketByName(CaseEjectSocketName)) - { - log(Error, "[Weapon='%s'] Socket case ejector not found", *GetName()); - return; - } + AssertOrVoid(GetWeaponMesh()->GetSocketByName(CaseEjectSocketName), Error, "Socket case ejector not found"); let Transform = GetWeaponMesh()->GetSocketTransform(CaseEjectSocketName); let CaseModel = GetWeaponInfo()->CaseModel; - - if (not IsValid(CaseModel)) - { - log(Error, "[Weapon='%s'] Case model is invalid", *GetName()); - return; - } + AssertOrVoid(IsValid(CaseModel), Error, "Case model is invalid"); let Case = World->SpawnActor(AStaticMeshActor::StaticClass(), Transform); diff --git a/Source/Cloud9/Weapon/Classes/Cloud9WeaponGrenade.cpp b/Source/Cloud9/Weapon/Classes/Cloud9WeaponGrenade.cpp index 2b3be906a..bfcde502b 100644 --- a/Source/Cloud9/Weapon/Classes/Cloud9WeaponGrenade.cpp +++ b/Source/Cloud9/Weapon/Classes/Cloud9WeaponGrenade.cpp @@ -118,7 +118,7 @@ void ACloud9WeaponGrenade::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); - WEAPON_IS_DEFINED_GUARD(); + AssertOrVoid(IsWeaponDefined(), Error, "Weapon not defined"); if (WeaponState.IsGrenadeActionFinished()) { @@ -138,13 +138,12 @@ void ACloud9WeaponGrenade::Tick(float DeltaSeconds) return; } - WEAPON_IS_DISARMED_GUARD(); - WEAPON_IS_ACTION_IN_PROGRESS_GUARD(); + AssertOrVoid(not IsWeaponDisarmed(), Verbose, "AnimComponent isn't valid"); + AssertOrVoid(not IsActionInProgress(), Verbose, "Action already in progress during Tick"); let Character = GetOwner(); let AnimComponent = Character->GetAnimationComponent(); - - WEAPON_ANIM_COMPONENT_GUARD(); + AssertOrVoid(IsValid(AnimComponent), Error, "AnimComponent isn't valid"); let PoseMontages = WeaponDefinition.GetPoseMontages(Character->bIsCrouched); diff --git a/Source/Cloud9/Weapon/Classes/Cloud9WeaponMelee.cpp b/Source/Cloud9/Weapon/Classes/Cloud9WeaponMelee.cpp index bb4236111..c4ebf7a3a 100644 --- a/Source/Cloud9/Weapon/Classes/Cloud9WeaponMelee.cpp +++ b/Source/Cloud9/Weapon/Classes/Cloud9WeaponMelee.cpp @@ -69,14 +69,13 @@ void ACloud9WeaponMelee::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); - WEAPON_IS_DEFINED_GUARD(); - WEAPON_IS_DISARMED_GUARD(); - WEAPON_IS_ACTION_IN_PROGRESS_GUARD(); + AssertOrVoid(IsWeaponDefined(), Error, "Weapon not defined"); + AssertOrVoid(not IsWeaponDisarmed(), Verbose, "AnimComponent isn't valid"); + AssertOrVoid(not IsActionInProgress(), Verbose, "Action already in progress during Tick"); let Character = GetOwner(); let AnimComponent = Character->GetAnimationComponent(); - - WEAPON_ANIM_COMPONENT_GUARD(); + AssertOrVoid(IsValid(AnimComponent), Error, "AnimComponent isn't valid"); let WeaponInfo = WeaponDefinition.GetWeaponInfo(); let PoseMontages = WeaponDefinition.GetPoseMontages(Character->bIsCrouched); diff --git a/Source/Cloud9/Weapon/Enums/WeaponSlot.h b/Source/Cloud9/Weapon/Enums/WeaponSlot.h index 14abdd519..04ab890e7 100644 --- a/Source/Cloud9/Weapon/Enums/WeaponSlot.h +++ b/Source/Cloud9/Weapon/Enums/WeaponSlot.h @@ -1,4 +1,4 @@ -// Copyright (c) 2023 Alexei Gladkikh +// Copyright (c) 2023 Alexei Gladkikh // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -81,8 +81,7 @@ class CLOUD9_API UWeaponSlot : public UBlueprintFunctionLibrary case EWeaponType::Sniper: return TEXT("ReloadSniperSocket"); default: - log( - Error, + FunctionError( "Can't get reload weapon socket for weapon type '%s'", WeaponType | EUEnum::GetValueName() | EFName::ToCStr()); return NAME_None; diff --git a/Source/Cloud9/Weapon/Notifiers/Cloud9AnimNotifyPlaySound.cpp b/Source/Cloud9/Weapon/Notifiers/Cloud9AnimNotifyPlaySound.cpp index 89413c8e1..18e3298a0 100644 --- a/Source/Cloud9/Weapon/Notifiers/Cloud9AnimNotifyPlaySound.cpp +++ b/Source/Cloud9/Weapon/Notifiers/Cloud9AnimNotifyPlaySound.cpp @@ -54,7 +54,7 @@ bool UCloud9AnimNotifyPlaySound::PlayMeleeSound(USkeletalMeshComponent* MeshComp case EWeaponSoundType::Secondary: return UCloud9SoundPlayer::PlayRandomSound(WeaponInfo->Sounds.StabSounds, Location, Volume); default: - log(Error, "[%s] Invalid sound type for melee sound", *GetName()); + ObjectError("Invalid sound type for melee sound"); return false; } } @@ -88,7 +88,7 @@ bool UCloud9AnimNotifyPlaySound::PlayFirearmSound(USkeletalMeshComponent* MeshCo } return false; default: - log(Error, "[%s] Invalid sound type for firearm sound SoundType=%d", *GetName(), SoundType); + ObjectError("Invalid sound type for firearm sound SoundType=%d", SoundType); return false; } } @@ -112,7 +112,7 @@ bool UCloud9AnimNotifyPlaySound::PlayGrenadeSound(USkeletalMeshComponent* MeshCo case EWeaponSoundType::Primary: return UCloud9SoundPlayer::PlaySingleSound(WeaponInfo->Sounds.ThrowSound, Location, Volume); default: - log(Error, "[%s] Invalid sound type for firearm sound SoundType=%d", *GetName(), SoundType); + ObjectError("Invalid sound type for firearm sound SoundType=%d", SoundType); return false; } } @@ -149,7 +149,7 @@ void UCloud9AnimNotifyPlaySound::Notify(USkeletalMeshComponent* MeshComp, UAnimS PlayGrenadeSound(MeshComp, Volume); break; default: - log(Error, "[%s] Invalid class name", *GetName()); + ObjectError("Invalid class name"); } } } diff --git a/Source/Cloud9/Weapon/Notifiers/Cloud9AnimNotifyWeapon.h b/Source/Cloud9/Weapon/Notifiers/Cloud9AnimNotifyWeapon.h index 50db5bd7f..02e7803d7 100644 --- a/Source/Cloud9/Weapon/Notifiers/Cloud9AnimNotifyWeapon.h +++ b/Source/Cloud9/Weapon/Notifiers/Cloud9AnimNotifyWeapon.h @@ -24,34 +24,14 @@ class CLOUD9_API UCloud9AnimNotifyWeapon : public UAnimNotify static WeaponClassType* GetSelectedWeapon(USkeletalMeshComponent* MeshComp) { let Character = MeshComp->GetOwner(); - - if (not IsValid(Character)) - { - log(Error, "Character is invalid"); - return nullptr; - } + FunctionAssertOrReturn(IsValid(Character), nullptr, Error, "Character is invalid"); let Inventory = Character->GetInventoryComponent(); - - if (not IsValid(Inventory)) - { - log(Error, "Inventory is invalid"); - return nullptr; - } + FunctionAssertOrReturn(IsValid(Inventory), nullptr, Error, "Inventory is invalid"); let SelectedWeapon = Inventory->GetSelectedWeapon(); - - if (not IsValid(SelectedWeapon)) - { - log(Error, "Selected weapon is invalid"); - return nullptr; - } - - if (not SelectedWeapon->IsWeaponDefined()) - { - log(Error, "Selected weapon is not defined"); - return nullptr; - } + FunctionAssertOrReturn(IsValid(SelectedWeapon), nullptr, Error, "Selected weapon is invalid"); + FunctionAssertOrReturn(SelectedWeapon->IsWeaponDefined(), nullptr, Error, "Selected weapon is not defined"); return Cast(SelectedWeapon); } diff --git a/Source/Cloud9/Weapon/Sounds/Cloud9SoundPlayer.cpp b/Source/Cloud9/Weapon/Sounds/Cloud9SoundPlayer.cpp index 249c2ebfc..a287d480c 100644 --- a/Source/Cloud9/Weapon/Sounds/Cloud9SoundPlayer.cpp +++ b/Source/Cloud9/Weapon/Sounds/Cloud9SoundPlayer.cpp @@ -9,7 +9,7 @@ bool UCloud9SoundPlayer::PlaySingleSound(USoundBase* Sound, FVector Location, float Volume) { - StaticAssertOrReturn(Sound, false, Error, "Invalid Sound"); + FunctionAssertOrReturn(Sound, false, Error, "Invalid Sound"); USoundAttenuation* AttenuationSettings = nullptr; @@ -36,20 +36,9 @@ bool UCloud9SoundPlayer::PlaySoundByName( FVector Location, float Volume) { - if (Name.IsNone()) - { - log(Error, "Name not specified"); - return false; - } - + FunctionAssertOrReturn(not Name.IsNone(), false, Error, "Name not specified"); let Sound = Sounds.Find(Name); - - if (not Sound or not*Sound) - { - log(Error, "No sound specified"); - return false; - } - + FunctionAssertOrReturn(Sound and *Sound, false, Error, "No sound specified"); return PlaySingleSound(*Sound, Location, Volume); } @@ -63,7 +52,7 @@ bool UCloud9SoundPlayer::PlayRandomSound( return Sounds | Random() - | OnNull{[] { log(Error, "No sound specified"); }} + | OnNull{[] { FunctionError("No sound specified"); }} | OnSet{[Location, Volume](var It) { PlaySingleSound(It, Location, Volume); }} | IsSet{}; } diff --git a/Source/Cloud9/Weapon/Structures/WeaponConfig.cpp b/Source/Cloud9/Weapon/Structures/WeaponConfig.cpp index c942324a3..a83327764 100644 --- a/Source/Cloud9/Weapon/Structures/WeaponConfig.cpp +++ b/Source/Cloud9/Weapon/Structures/WeaponConfig.cpp @@ -76,11 +76,7 @@ TSubclassOf FWeaponConfig::GetWeaponStaticClass() const bool FWeaponConfig::Initialize(AActor* Actor) const { - if (not IsValid(Actor)) - { - log(Error, "Actor is invalid"); - return false; - } + FunctionAssertOrReturn(IsValid(Actor), false, Error, "Actor is invalid"); let IsInitialized = Actor | WhenOrNone{ [this](ACloud9WeaponMelee* It) { return Initialize(It); }, @@ -88,11 +84,9 @@ bool FWeaponConfig::Initialize(AActor* Actor) const [this](ACloud9WeaponGrenade* It) { return Initialize(It); } }; - if (not IsInitialized.Get(false)) - { - log(Error, "[Actor='%s' Config='%s'] Weapon initialization failure", *Actor->GetName(), *ToString()); - return false; - } + FunctionAssertOrReturn( + IsInitialized.Get(false), false, + Error, "Weapon '%s' initialization failure with config '%s'", *Actor->GetName(), *ToString()); return true; } @@ -146,11 +140,6 @@ FWeaponConfig FWeaponConfig::FromWeapon(const ACloud9WeaponBase* Weapon) } }; - if (not Config.IsSet()) - { - log(Fatal, "Weapon class is undefined"); - return {}; - } - + AssertOrCrash(Config.IsSet(), "Weapon class is undefined"); return *Config; } diff --git a/Source/Cloud9/Weapon/Structures/WeaponConfig.h b/Source/Cloud9/Weapon/Structures/WeaponConfig.h index 2856cf890..7c059d629 100644 --- a/Source/Cloud9/Weapon/Structures/WeaponConfig.h +++ b/Source/Cloud9/Weapon/Structures/WeaponConfig.h @@ -118,13 +118,8 @@ struct FWeaponConfig template bool Initialize(WeaponClassType* Weapon) const { - if (not IsValid(Weapon)) - { - log(Error, "[Config='%s'] Weapon to initialize is invalid", *ToString()); - return false; - } - - log(Verbose, "[Config='%s'] Initializing weapon...", *ToString()); + FunctionAssertOrReturn(IsValid(Weapon), false, Error, "Weapon to initialize is invalid"); + FunctionVerbose("[%s] Initializing weapon...", *ToString()); return Weapon->Initialize(*this); } @@ -157,22 +152,14 @@ struct FWeaponConfig void PostEditChangeProperty() { let Asset = ACloud9WeaponBase::GetWeaponDefinitionsAsset(); - - if (not IsValid(Asset)) - { - log(Error, "Can't get WeaponDefinitionsAsset"); - return; - } + FunctionAssertOrVoid(IsValid(Asset), Error, "WCan't get WeaponDefinitionsAsset"); if (WeaponClass == EWeaponClass::Firearm) { FWeaponDefinition WeaponDefinition; - - if (not Asset->GetWeaponDefinition(GetWeaponId(), WeaponDefinition)) - { - log(Error, "Can't get WeaponDefinition for firearm = %d", FirearmWeaponId); - return; - } + FunctionAssertOrVoid( + Asset->GetWeaponDefinition(GetWeaponId(), WeaponDefinition), + Error, "Can't get WeaponDefinition for firearm = %d", FirearmWeaponId); let FirearmWeaponInfo = WeaponDefinition.GetWeaponInfo(); diff --git a/Source/Cloud9/Weapon/Structures/WeaponDefinition.h b/Source/Cloud9/Weapon/Structures/WeaponDefinition.h index 1f62731c1..2f6cfabf6 100644 --- a/Source/Cloud9/Weapon/Structures/WeaponDefinition.h +++ b/Source/Cloud9/Weapon/Structures/WeaponDefinition.h @@ -109,7 +109,7 @@ struct FWeaponDefinition } } - log(Error, "WeaponInfo class wasn't set"); + FunctionError("WeaponInfo class wasn't set"); return nullptr; } diff --git a/Source/Cloud9/Weapon/Tables/WeaponTableBase.h b/Source/Cloud9/Weapon/Tables/WeaponTableBase.h index e68f5fb1a..cbed8fe7e 100644 --- a/Source/Cloud9/Weapon/Tables/WeaponTableBase.h +++ b/Source/Cloud9/Weapon/Tables/WeaponTableBase.h @@ -121,8 +121,8 @@ namespace EFWeaponInfo { if (SkinName == FWeaponSkin::Default) { - // Crash if have no even default skin - log(Fatal, "Can't get default skin"); + // Crash if we have no even default skin + FunctionFatal("Can't get default skin"); } return {}; @@ -147,7 +147,7 @@ namespace EFWeaponInfo | GetSkinByNameOrNull(SkinName) | Get([&] { - log(Error, "Weapon skin '%s' not found -> try to get default skin", *SkinName.ToString()); + FunctionError("Weapon skin '%s' not found -> try to get default skin", *SkinName.ToString()); return Self | GetSkinByNameOrNull() | Get(); diff --git a/Source/Cloud9/Weapon/Utils/EquipmentSpawner.cpp b/Source/Cloud9/Weapon/Utils/EquipmentSpawner.cpp index 00ac77b5e..ce069c752 100644 --- a/Source/Cloud9/Weapon/Utils/EquipmentSpawner.cpp +++ b/Source/Cloud9/Weapon/Utils/EquipmentSpawner.cpp @@ -71,7 +71,7 @@ void AEquipmentSpawner::PostEditChangeProperty(FPropertyChangedEvent& PropertyCh if (not bChangeArmor) { - log(Warning, "Can't add helmet without kevlar vest"); + ObjectWarn("Can't add helmet without kevlar vest"); bHelmet = false; } } diff --git a/Source/Cloud9/Weapon/Utils/ItemSpawner.cpp b/Source/Cloud9/Weapon/Utils/ItemSpawner.cpp index c3b92272b..016d98c41 100644 --- a/Source/Cloud9/Weapon/Utils/ItemSpawner.cpp +++ b/Source/Cloud9/Weapon/Utils/ItemSpawner.cpp @@ -78,12 +78,7 @@ void AItemSpawner::OnConstruction(const FTransform& Transform) Super::OnConstruction(Transform); let ItemSample = CreateChildActor(); - - if (not IsValid(ItemSample)) - { - log(Error, "[ItemSpawner=%s] Can't create spawner sample", *GetName()); - return; - } + AssertOrVoid(IsValid(ItemSample), Error, "Can't create spawner sample"); ItemSample->SetActorTickEnabled(false); ItemSample->UpdateComponentTransforms(); @@ -108,12 +103,7 @@ void AItemSpawner::BeginPlay() Super::BeginPlay(); let ItemSample = ItemSampleComponent->GetChildActor(); - - if (not IsValid(ItemSample)) - { - log(Error, "[AItemSpawnerBase=%s] Invalid spawner", *GetName()); - return; - } + AssertOrVoid(IsValid(ItemSample), Error, "Invalid spawner"); if (bIsRandomInitialRotation) {