diff --git a/Content/Maps/warmup.umap b/Content/Maps/warmup.umap index 8a1cd6534..7fe9e0ebf 100644 Binary files a/Content/Maps/warmup.umap and b/Content/Maps/warmup.umap differ diff --git a/Content/Modes/BP_Cloud9Default.uasset b/Content/Modes/BP_Cloud9Default.uasset index 9229f69f9..4991004cb 100644 Binary files a/Content/Modes/BP_Cloud9Default.uasset and b/Content/Modes/BP_Cloud9Default.uasset differ diff --git a/Source/Cloud9/Character/Components/Cloud9SpringArmComponent.cpp b/Source/Cloud9/Character/Components/Cloud9SpringArmComponent.cpp index 6d73cad5a..3bd37c466 100644 --- a/Source/Cloud9/Character/Components/Cloud9SpringArmComponent.cpp +++ b/Source/Cloud9/Character/Components/Cloud9SpringArmComponent.cpp @@ -24,7 +24,7 @@ #include "Cloud9SpringArmComponent.h" #include "Cloud9/Tools/Macro/Common.h" #include "Cloud9/Game/Cloud9DeveloperSettings.h" -#include "Cloud9/Tools/Cloud9ToolsLibrary.h" +#include "Cloud9/Tools/Extensions/FVector.h" UCloud9SpringArmComponent::UCloud9SpringArmComponent() { @@ -112,13 +112,13 @@ void UCloud9SpringArmComponent::UpdateDesiredArmLocation( LerpTarget += ArmMovementStep * LerpAmount; RemainingTime -= LerpAmount; - DesiredLoc = UCloud9ToolsLibrary::VInterpTo(PreviousDesiredLoc, LerpTarget, LerpAmount, LocationLag); + DesiredLoc = EFVector::VInterpTo(PreviousDesiredLoc, LerpTarget, LerpAmount, LocationLag); PreviousDesiredLoc = DesiredLoc; } } else { - DesiredLoc = UCloud9ToolsLibrary::VInterpTo(PreviousDesiredLoc, DesiredLoc, DeltaTime, LocationLag); + DesiredLoc = EFVector::VInterpTo(PreviousDesiredLoc, DesiredLoc, DeltaTime, LocationLag); } if (let FromOrigin = DesiredLoc - ArmOrigin; diff --git a/Source/Cloud9/Contollers/Cloud9MouseController.cpp b/Source/Cloud9/Contollers/Cloud9MouseController.cpp index c05cde42c..94fd387a7 100644 --- a/Source/Cloud9/Contollers/Cloud9MouseController.cpp +++ b/Source/Cloud9/Contollers/Cloud9MouseController.cpp @@ -25,6 +25,7 @@ #include "Cloud9/Tools/Cloud9ToolsLibrary.h" #include "Cloud9/Tools/Extensions/APlayerController.h" +#include "Cloud9/Tools/Math.h" #include "Cloud9/Contollers/Cloud9PlayerController.h" #include "Cloud9/Game/Cloud9DeveloperSettings.h" @@ -74,11 +75,11 @@ float UCloud9MouseController::GetCameraZoomHeightLevel() const { if (let Pawn = GetCloud9Pawn(); IsValid(Pawn)) { - let ZoomHeightLevel = UCloud9ToolsLibrary::InverseLerp( + let ZoomHeightLevel = Math::InverseLerp( MinCameraZoomHeight, MaxCameraZoomHeight, Pawn->GetCameraZoomHeight()); - let ZoomAngleLevel = UCloud9ToolsLibrary::InverseLerp( + let ZoomAngleLevel = Math::InverseLerp( MinCameraZoomAngle, MaxCameraZoomAngle, Pawn->GetCameraRotationRoll()); diff --git a/Source/Cloud9/Tools/Cloud9ToolsLibrary.cpp b/Source/Cloud9/Tools/Cloud9ToolsLibrary.cpp index 99af6787b..4ef55a469 100644 --- a/Source/Cloud9/Tools/Cloud9ToolsLibrary.cpp +++ b/Source/Cloud9/Tools/Cloud9ToolsLibrary.cpp @@ -104,44 +104,6 @@ void UCloud9ToolsLibrary::GetWidthHeightDepth(const FBox& Box, float& Width, flo Depth = Size.Z; } -FRotator UCloud9ToolsLibrary::RadiansToDegrees(const FRotator Rotator) -{ - return { - FMath::RadiansToDegrees(Rotator.Pitch), - FMath::RadiansToDegrees(Rotator.Yaw), - FMath::RadiansToDegrees(Rotator.Roll) - }; -} - -FVector UCloud9ToolsLibrary::VInterpTo( - const FVector Current, - const FVector Target, - float DeltaTime, - const FVector InterpSpeed) -{ - let ClampLerp = [](auto Current, auto Dist, auto Alpha, auto Target) - { - return Alpha <= 0.0f ? Target : Current + Dist * FMath::Clamp(Alpha, 0.0f, 1.0f); - }; - - // Distance to reach - let Dist = Target - Current; - - // If distance is too small, just set the desired location - if (Dist.SizeSquared() < KINDA_SMALL_NUMBER) - { - return Target; - } - - let Alpha = DeltaTime * InterpSpeed; - - return { - ClampLerp(Current.X, Dist.X, Alpha.X, Target.X), - ClampLerp(Current.Y, Dist.Y, Alpha.Y, Target.Y), - ClampLerp(Current.Z, Dist.Z, Alpha.Z, Target.Z), - }; -} - TArray UCloud9ToolsLibrary::GetObjectEditorProperties(UClass* Class) { if (IsValid(Class)) diff --git a/Source/Cloud9/Tools/Cloud9ToolsLibrary.h b/Source/Cloud9/Tools/Cloud9ToolsLibrary.h index 4fc0d8ea7..eeb314635 100644 --- a/Source/Cloud9/Tools/Cloud9ToolsLibrary.h +++ b/Source/Cloud9/Tools/Cloud9ToolsLibrary.h @@ -94,67 +94,11 @@ class CLOUD9_API UCloud9ToolsLibrary : public UBlueprintFunctionLibrary return reinterpret_cast&>(Actors); } - template - static T InverseLerp(const T& A, const T& B, const U& X) { return static_cast((X - A) / (B - A)); } - static FBox GetAccurateReferencePoseBounds(const USkeletalMesh* Mesh); UFUNCTION(BlueprintCallable) static void GetWidthHeightDepth(const FBox& Box, float& Width, float& Height, float& Depth); - static FRotator RadiansToDegrees(const FRotator Rotator); - - static FVector VInterpTo( - const FVector Current, - const FVector Target, - float DeltaTime, - const FVector InterpSpeed); - UFUNCTION(BlueprintCallable) static TArray GetObjectEditorProperties(UClass* Class); - - // see mathlib.h from cstrike15_src - - template - static constexpr InputType Select(InputType Value, OutputType A, OutputType B) - { - return Value < 0 ? A : B; - } - - template - static constexpr OutRangeType RemapValue( - ValueType Value, - InRangeType InRangeMin, - InRangeType InRangeMax, - OutRangeType OutRangeMin, - OutRangeType OutRangeMax) - { - if (InRangeMin == InRangeMax) - { - return Select(Value - InRangeMax, OutRangeMax, OutRangeMin); - } - - let InRange = static_cast(InRangeMax - InRangeMin); - let OutRange = OutRangeMax - OutRangeMin; - return OutRangeMin + OutRange * static_cast(Value - InRangeMin) / InRange; - } - - template - static constexpr OutRangeType RemapValueClamped( - ValueType Value, - InRangeType InRangeMin, - InRangeType InRangeMax, - OutRangeType OutRangeMin, - OutRangeType OutRangeMax) - { - if (InRangeMin == InRangeMax) - { - return Select(Value - InRangeMax, OutRangeMax, OutRangeMin); - } - - let InRange = static_cast(InRangeMax - InRangeMin); - let Temp = FMath::Clamp(static_cast(Value - InRangeMin) / InRange, 0.0f, 1.0f); - let OutRange = OutRangeMax - OutRangeMin; - return OutRangeMin + OutRange * Temp; - } }; diff --git a/Source/Cloud9/Tools/Extensions/FRotator.h b/Source/Cloud9/Tools/Extensions/FRotator.h index 30ee9118d..4f5f3ac63 100644 --- a/Source/Cloud9/Tools/Extensions/FRotator.h +++ b/Source/Cloud9/Tools/Extensions/FRotator.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 @@ -27,34 +27,20 @@ #include "Cloud9/Tools/Macro/Common.h" #include "Cloud9/Tools/Concepts.h" -namespace EFVector +namespace EFRotator { - struct Normalize + struct ToDegrees { - template requires Concepts::convertiable - FORCEINLINE FVector operator()(SelfType&& Self) const + template requires Concepts::convertiable + FORCEINLINE FRotator operator()(SelfType&& Self) const { - FVector Normalized = Self; - Normalized.Normalize(); - return Normalized; + return { + FMath::RadiansToDegrees(Self.Pitch), + FMath::RadiansToDegrees(Self.Yaw), + FMath::RadiansToDegrees(Self.Roll) + }; } - OPERATOR_BODY(Normalize) + OPERATOR_BODY(ToDegrees) }; - - FVector VInterpTo( - const FVector Current, - const FVector Target, - float DeltaTime, - const FVector InterpSpeed); - - inline FVector Random(FVector Min, FVector Max, FVector Grid) - { - let Vector = FMath::RandPointInBox({Min, Max}); - return { - FMath::GridSnap(Vector.X, Grid.X), - FMath::GridSnap(Vector.Y, Grid.Y), - FMath::GridSnap(Vector.Z, Grid.Z), - }; - } } diff --git a/Source/Cloud9/Tools/Extensions/FVector.cpp b/Source/Cloud9/Tools/Extensions/FVector.cpp index 9d95d6bbe..996bce29a 100644 --- a/Source/Cloud9/Tools/Extensions/FVector.cpp +++ b/Source/Cloud9/Tools/Extensions/FVector.cpp @@ -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 @@ -23,25 +23,10 @@ #pragma once -#include "Cloud9/Tools/Macro/Operator.h" -#include "Cloud9/Tools/Macro/Common.h" -#include "Cloud9/Tools/Concepts.h" +#include "FVector.h" namespace EFVector { - struct Normalize - { - template requires Concepts::convertiable - FORCEINLINE FVector operator()(SelfType&& Self) const - { - FVector Normalized = Self; - Normalized.Normalize(); - return Normalized; - } - - OPERATOR_BODY(Normalize) - }; - FVector VInterpTo( const FVector Current, const FVector Target, @@ -70,14 +55,4 @@ namespace EFVector ClampLerp(Current.Z, Dist.Z, Alpha.Z, Target.Z), }; } - - inline FVector Random(FVector Min, FVector Max, FVector Grid) - { - let Vector = FMath::RandPointInBox({Min, Max}); - return { - FMath::GridSnap(Vector.X, Grid.X), - FMath::GridSnap(Vector.Y, Grid.Y), - FMath::GridSnap(Vector.Z, Grid.Z), - }; - } } diff --git a/Source/Cloud9/Tools/Extensions/FVector.h b/Source/Cloud9/Tools/Extensions/FVector.h index 375d7c58e..30ee9118d 100644 --- a/Source/Cloud9/Tools/Extensions/FVector.h +++ b/Source/Cloud9/Tools/Extensions/FVector.h @@ -42,18 +42,15 @@ namespace EFVector OPERATOR_BODY(Normalize) }; - inline FVector Random(FVector Min, FVector Max) - { - return { - FMath::RandRange(Min.X, Max.X), - FMath::RandRange(Min.Y, Max.Y), - FMath::RandRange(Min.Z, Max.Z), - }; - } + FVector VInterpTo( + const FVector Current, + const FVector Target, + float DeltaTime, + const FVector InterpSpeed); inline FVector Random(FVector Min, FVector Max, FVector Grid) { - let Vector = Random(Min, Max); + let Vector = FMath::RandPointInBox({Min, Max}); return { FMath::GridSnap(Vector.X, Grid.X), FMath::GridSnap(Vector.Y, Grid.Y), diff --git a/Source/Cloud9/Tools/Math.h b/Source/Cloud9/Tools/Math.h index 1b02fe9d9..95c4c522a 100644 --- a/Source/Cloud9/Tools/Math.h +++ b/Source/Cloud9/Tools/Math.h @@ -1,56 +1,54 @@ -// Copyright (c) 2023 Alexei Gladkikh -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) 2024 Alexei Gladkikh #pragma once -/** - * std abstraction because UE4 has self APIs to avoid mixin std and UE4 APIs - */ -namespace Concepts +namespace Math { - template - concept incrementable = requires(SelfType Self) + template + T InverseLerp(const T& A, const T& B, const U& X) { return static_cast((X - A) / (B - A)); } + + // see mathlib.h from cstrike15_src + + template + constexpr InputType Select(InputType Value, OutputType A, OutputType B) { - ++Self; - }; + return Value < 0 ? A : B; + } - template - concept plusassingable = - incrementable - && requires(SelfType Self, OtherType Other) + template + constexpr OutRangeType RemapValue( + ValueType Value, + InRangeType InRangeMin, + InRangeType InRangeMax, + OutRangeType OutRangeMin, + OutRangeType OutRangeMax) + { + if (InRangeMin == InRangeMax) { - Self += Other; - }; + return Select(Value - InRangeMax, OutRangeMax, OutRangeMin); + } - template - concept dereferencable = requires(SelfType Self) - { - { *Self } -> std::convertible_to; - }; + let InRange = static_cast(InRangeMax - InRangeMin); + let OutRange = OutRangeMax - OutRangeMin; + return OutRangeMin + OutRange * static_cast(Value - InRangeMin) / InRange; + } - template - concept convertiable = requires(SelfType Self) + template + constexpr OutRangeType RemapValueClamped( + ValueType Value, + InRangeType InRangeMin, + InRangeType InRangeMax, + OutRangeType OutRangeMin, + OutRangeType OutRangeMax) { - { Self } -> std::convertible_to; - }; + if (InRangeMin == InRangeMax) + { + return Select(Value - InRangeMax, OutRangeMax, OutRangeMin); + } + + let InRange = static_cast(InRangeMax - InRangeMin); + let Temp = FMath::Clamp(static_cast(Value - InRangeMin) / InRange, 0.0f, 1.0f); + let OutRange = OutRangeMax - OutRangeMin; + return OutRangeMin + OutRange * Temp; + } } diff --git a/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp b/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp index ccaea367f..fcab94176 100644 --- a/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp +++ b/Source/Cloud9/Weapon/Classes/Cloud9WeaponFirearm.cpp @@ -43,6 +43,7 @@ #include "Cloud9/Character/Damages/FirearmDamageType.h" #include "Cloud9/Game/Cloud9DeveloperSettings.h" #include "Cloud9/Physicals/Cloud9PhysicalMaterial.h" +#include "Cloud9/Tools/Math.h" #include "Cloud9/Tools/Structures.h" #include "Cloud9/Tools/Extensions/TArray.h" #include "Cloud9/Tools/Extensions/USoundBase.h" @@ -669,7 +670,7 @@ float ACloud9WeaponFirearm::GetInaccuracy() const let MaxSpeed = WeaponInfo->GetMaxSpeed(); - var MovementInaccuracyScale = UCloud9ToolsLibrary::RemapValueClamped( + var MovementInaccuracyScale = Math::RemapValueClamped( Velocity.Size2D(), MaxSpeed * Cloud9Player::SpeedDuckModifier, MaxSpeed * 0.95f, // max out at 95% of run speed to avoid jitter near max speed @@ -701,7 +702,7 @@ float ACloud9WeaponFirearm::GetInaccuracy() const let SqrtMaxJumpSpeed = FMath::Sqrt(Settings->JumpImpulse); let SqrtVerticalSpeed = FMath::Sqrt(VerticalSpeed); - var AirSpeedInaccuracy = UCloud9ToolsLibrary::RemapValue( + var AirSpeedInaccuracy = Math::RemapValue( SqrtVerticalSpeed, SqrtMaxJumpSpeed * 0.25f, @@ -970,7 +971,7 @@ float ACloud9WeaponFirearm::GetRecoveryTime() const { const int RecoilIndex = RecoilPattern; - RecoveryTime = UCloud9ToolsLibrary::RemapValueClamped( + RecoveryTime = Math::RemapValueClamped( RecoilIndex, WeaponInfo->GetRecoveryTransitionStartBullet(), WeaponInfo->GetRecoveryTransitionEndBullet(), @@ -989,7 +990,7 @@ float ACloud9WeaponFirearm::GetRecoveryTime() const { const int RecoilIndex = RecoilPattern; - RecoveryTime = UCloud9ToolsLibrary::RemapValueClamped( + RecoveryTime = Math::RemapValueClamped( RecoilIndex, WeaponInfo->GetRecoveryTransitionStartBullet(), WeaponInfo->GetRecoveryTransitionEndBullet(),