Skip to content

Commit

Permalink
added simple way to graph 3dhashgrid entities and show their debug in…
Browse files Browse the repository at this point in the history
…fo to BP_FirstPersonCharacter

removed volumetric clouds
spelling errors in bpf library
  • Loading branch information
Megafunk committed Apr 27, 2022
1 parent 7e2e4ab commit 2f58041
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 23 deletions.
4 changes: 3 additions & 1 deletion Config/DefaultEngine.ini
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,6 @@ ManualIPAddress=

[ConsoleVariables]

mass.FullyParallel=False
mass.FullyParallel=False
[CoreRedirects]
+ClassRedirects=(OldName="/Script/MassSample.MSBPFunctionLibarary",NewName="/Script/MassSample.MSBPFunctionLibrary")
1 change: 1 addition & 0 deletions Config/DefaultInput.ini
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ DoubleClickTime=0.200000
+ActionMappings=(ActionName="Jump",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=SpaceBar)
+ActionMappings=(ActionName="Jump",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_FaceButton_Bottom)
+ActionMappings=(ActionName="PrimaryAction",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=LeftMouseButton)
+ActionMappings=(ActionName="SecondaryAction",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=RightMouseButton)
+AxisMappings=(AxisName="Move Forward / Backward",Scale=1.000000,Key=W)
+AxisMappings=(AxisName="Move Forward / Backward",Scale=-1.000000,Key=S)
+AxisMappings=(AxisName="Move Forward / Backward",Scale=1.000000,Key=Gamepad_LeftY)
Expand Down
4 changes: 2 additions & 2 deletions Content/MassSample/Blueprints/BP_FirstPersonCharacter.uasset
Git LFS file not shown
4 changes: 2 additions & 2 deletions Content/MassSample/Maps/CrowdGym.umap
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
1 change: 0 additions & 1 deletion Source/MassSample/Common/Fragments/MSHashGridFragments.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//todo: less weird place to stuff this? some types thing? oh well...
typedef UE::Geometry::TPointHashGrid3<FMassEntityHandle,Chaos::FReal> FMSHashGrid3D;


//This entity's startomg location on our 2D hashgrid this frame
USTRUCT()
struct MASSSAMPLE_API FMSGridCellStartingLocationFragment : public FMassFragment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// Fill out your copyright notice in the Description page of Project Settings.


#include "MSBPFunctionLibarary.h"
#include "MSBPFunctionLibrary.h"

#include "MassCommonFragments.h"
#include "MassEntityConfigAsset.h"
#include "MassEntityTemplateRegistry.h"
#include "MassExecutor.h"
#include "MassMovementFragments.h"
#include "MassProcessingPhase.h"
#include "MSSubsystem.h"
#include "AI/NavigationSystemBase.h"
#include "ProjectileSim/Fragments/MSProjectileFragments.h"

FEntityHandleWrapper UMSBPFunctionLibarary::SpawnEntityFromEntityConfig(AActor* Owner, UMassEntityConfigAsset* MassEntityConfig,
FEntityHandleWrapper UMSBPFunctionLibrary::SpawnEntityFromEntityConfig(AActor* Owner, UMassEntityConfigAsset* MassEntityConfig,
const UObject* WorldContextObject)
{

Expand All @@ -39,7 +40,7 @@ FEntityHandleWrapper UMSBPFunctionLibarary::SpawnEntityFromEntityConfig(AActor*
return FEntityHandleWrapper();
}

void UMSBPFunctionLibarary::SetEntityTransform(const FEntityHandleWrapper EntityHandle,const FTransform Transform,const UObject* WorldContextObject)
void UMSBPFunctionLibrary::SetEntityTransform(const FEntityHandleWrapper EntityHandle,const FTransform Transform,const UObject* WorldContextObject)
{
const UMassEntitySubsystem* EntitySubSystem = WorldContextObject->GetWorld()->GetSubsystem<UMassEntitySubsystem>();

Expand All @@ -53,7 +54,7 @@ void UMSBPFunctionLibarary::SetEntityTransform(const FEntityHandleWrapper Entity

}

void UMSBPFunctionLibarary::SetEntityCollisionQueryIgnoredActors(const FEntityHandleWrapper EntityHandle,const TArray<AActor*> IgnoredActors,const UObject* WorldContextObject)
void UMSBPFunctionLibrary::SetEntityCollisionQueryIgnoredActors(const FEntityHandleWrapper EntityHandle,const TArray<AActor*> IgnoredActors,const UObject* WorldContextObject)
{
const UMassEntitySubsystem* EntitySubSystem = WorldContextObject->GetWorld()->GetSubsystem<UMassEntitySubsystem>();

Expand All @@ -66,11 +67,13 @@ void UMSBPFunctionLibarary::SetEntityCollisionQueryIgnoredActors(const FEntityHa
}

}
FTransform UMSBPFunctionLibarary::GetEntityTransform(const FEntityHandleWrapper EntityHandle,const UObject* WorldContextObject)
FTransform UMSBPFunctionLibrary::GetEntityTransform(const FEntityHandleWrapper EntityHandle,const UObject* WorldContextObject)
{
const UMassEntitySubsystem* EntitySubSystem = WorldContextObject->GetWorld()->GetSubsystem<UMassEntitySubsystem>();

check(EntitySubSystem)

if(!EntitySubSystem->IsEntityValid(EntityHandle.Entity)) return FTransform::Identity;

if(const auto TransformFragmentPtr = EntitySubSystem->GetFragmentDataPtr<FTransformFragment>(EntityHandle.Entity))
{
Expand All @@ -81,7 +84,7 @@ FTransform UMSBPFunctionLibarary::GetEntityTransform(const FEntityHandleWrapper

}

void UMSBPFunctionLibarary::SetEntityForce(const FEntityHandleWrapper EntityHandle,const FVector Force,const UObject* WorldContextObject)
void UMSBPFunctionLibrary::SetEntityForce(const FEntityHandleWrapper EntityHandle,const FVector Force,const UObject* WorldContextObject)
{
const UMassEntitySubsystem* EntitySubSystem = WorldContextObject->GetWorld()->GetSubsystem<UMassEntitySubsystem>();

Expand All @@ -96,7 +99,7 @@ void UMSBPFunctionLibarary::SetEntityForce(const FEntityHandleWrapper EntityHand



void UMSBPFunctionLibarary::FindHashGridEntitiesInSphere(const FVector Location, double Radius, TArray<FEntityHandleWrapper>& Entities ,const UObject* WorldContextObject)
void UMSBPFunctionLibrary::FindHashGridEntitiesInSphere(const FVector Location,const double Radius, TArray<FEntityHandleWrapper>& Entities ,const UObject* WorldContextObject)
{

QUICK_SCOPE_CYCLE_COUNTER(FindHashGridEntitiesInSphere);
Expand All @@ -123,7 +126,37 @@ void UMSBPFunctionLibarary::FindHashGridEntitiesInSphere(const FVector Location,
}
}

void UMSBPFunctionLibarary::AddFragmentToEntity(FFragmentWrapper Fragment, FEntityHandleWrapper Entity,
void UMSBPFunctionLibrary::FindClosestHashGridEntityInSphere(const FVector Location,const double Radius, FEntityHandleWrapper& Entity ,const UObject* WorldContextObject,TEnumAsByte<EReturnSuccess>& ReturnBranch)
{

QUICK_SCOPE_CYCLE_COUNTER(FindCloestHashGridEntityInSphere);

if(auto MassSampleSystem = WorldContextObject->GetWorld()->GetSubsystem<UMSSubsystem>())
{
auto EntitySystem = WorldContextObject->GetWorld()->GetSubsystem<UMassEntitySubsystem>();

const auto FoundEntityHashMember = MassSampleSystem->HashGrid.FindNearestInRadius(Location, Radius,
//todo-performance it feels bad to get random entities to query...
[&,Location](const FMassEntityHandle Entity)
{
const FVector EntityLocation = EntitySystem->GetFragmentDataPtr<FTransformFragment>(Entity)->
GetTransform().GetLocation();
return UE::Geometry::DistanceSquared(Location, EntityLocation);
});

if(FoundEntityHashMember.Key.IsValid())
{
Entity.Entity = FoundEntityHashMember.Key;
ReturnBranch = EReturnSuccess::Success;
}
else
{
ReturnBranch = EReturnSuccess::Failure;
}
}
}

void UMSBPFunctionLibrary::AddFragmentToEntity(FFragmentWrapper Fragment, FEntityHandleWrapper Entity,
const UObject* WorldContextObject)
{

Expand All @@ -132,4 +165,22 @@ void UMSBPFunctionLibarary::AddFragmentToEntity(FFragmentWrapper Fragment, FEnti

}

FString UMSBPFunctionLibrary::GetEntityDebugString(FEntityHandleWrapper Entity, const UObject* WorldContextObject)
{
auto EntitySystem = WorldContextObject->GetWorld()->GetSubsystem<UMassEntitySubsystem>();
check(EntitySystem)

if (!Entity.Entity.IsValid())
return FString();


FStringOutputDevice OutPut;
OutPut.SetAutoEmitLineTerminator(true);
EntitySystem->DebugPrintEntity(Entity.Entity,OutPut);


return FString{OutPut};

}


Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@

#include "MassEntityTypes.h"

#include "MSBPFunctionLibarary.generated.h"
#include "MSBPFunctionLibrary.generated.h"



USTRUCT(BlueprintType)
struct FEntityHandleWrapper
{
GENERATED_BODY()
FMassEntityHandle Entity;

};



USTRUCT(BlueprintType)
struct FFragmentWrapper
{
Expand All @@ -29,8 +31,15 @@ struct FFragmentWrapper

};

UENUM(BlueprintType)
enum EReturnSuccess
{
Success,
Failure
};

UCLASS()
class MASSSAMPLE_API UMSBPFunctionLibarary : public UBlueprintFunctionLibrary
class MASSSAMPLE_API UMSBPFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()

Expand All @@ -53,13 +62,18 @@ class MASSSAMPLE_API UMSBPFunctionLibarary : public UBlueprintFunctionLibrary


UFUNCTION(BlueprintCallable, Category = "Mass", meta = (WorldContext = "WorldContextObject"))
static void FindHashGridEntitiesInSphere(const FVector Location, double Radius, TArray<FEntityHandleWrapper>& Entities ,const UObject* WorldContextObject);
static void FindHashGridEntitiesInSphere(const FVector Location,const double Radius, TArray<FEntityHandleWrapper>& Entities ,const UObject* WorldContextObject);

UFUNCTION(BlueprintCallable, Category = "Mass", meta = (WorldContext = "WorldContextObject",ExpandEnumAsExecs = "ReturnBranch"))
static void FindClosestHashGridEntityInSphere(const FVector Location,const double Radius, FEntityHandleWrapper& Entity, const UObject* WorldContextObject,TEnumAsByte<EReturnSuccess>& ReturnBranch);


UFUNCTION(BlueprintCallable, Category = "Mass", meta = (WorldContext = "WorldContextObject"))
static void AddFragmentToEntity(FFragmentWrapper Fragment , FEntityHandleWrapper Entity ,const UObject* WorldContextObject);


UFUNCTION(BlueprintCallable, Category = "Mass", meta = (WorldContext = "WorldContextObject"))
static FString GetEntityDebugString(FEntityHandleWrapper Entity, const UObject* WorldContextObject);



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#pragma once

#include "CoreMinimal.h"
#include "Common/Misc/MSBPFunctionLibarary.h"
#include "Common/Misc/MSBPFunctionLibrary.h"
#include "UObject/Interface.h"
#include "MassProjectileHitInterface.generated.h"

Expand Down

0 comments on commit 2f58041

Please sign in to comment.