Skip to content

Commit

Permalink
5.1 Port mostly done! Phew
Browse files Browse the repository at this point in the history
  • Loading branch information
Megafunk committed Oct 15, 2022
1 parent 4b2086d commit 435181d
Show file tree
Hide file tree
Showing 27 changed files with 69 additions and 114 deletions.
3 changes: 3 additions & 0 deletions Config/DefaultEditor.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ bBlueprintIsNotBlueprintType= true
RealtimeScreenPercentageMode=Manual
NonRealtimeScreenPercentageMode=Manual

[/Script/AdvancedPreviewScene.SharedProfiles]


5 changes: 4 additions & 1 deletion Config/DefaultEngine.ini
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,11 @@ bUseManualIPAddress=False
ManualIPAddress=

[ConsoleVariables]
; This enables fully parallel mass processing
mass.FullyParallel=1

mass.FullyParallel=False
; This is to avoid a bug in 5.1's cmc
p.CVarGeometryCollectionImpulseWorkAround=0

[CoreRedirects]
+ClassRedirects=(OldName="/Script/MassSample.MSBPFunctionLibarary",NewName="/Script/MassSample.MSBPFunctionLibrary")
Expand Down
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
#include "CoreMinimal.h"
#include "MassEntityTypes.h"
#include "MassNavigationSubsystem.h"
#include "Chaos/SpatialHash.h"
#include "Spatial/PointHashGrid3.h"
#include "MSHashGridFragments.generated.h"

// FIXMEFUNK: Less weird place to stuff this? some types thing? oh well...
typedef UE::Geometry::TPointHashGrid3<FMassEntityHandle,Chaos::FReal> FMSHashGrid3D;

//
//typedef Chaos::TSpatialHash<Chaos::FReal> FMSSpatialHash;

// This entity's start location on our 2D hashgrid this frame
USTRUCT()
struct MASSCOMMUNITYSAMPLE_API FMSGridCellStartingLocationFragment : public FMassFragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,66 +54,6 @@ FEntityHandleWrapper UMSBPFunctionLibrary::SpawnEntityFromEntityConfig(UMassEnti
FEntityHandleWrapper UMSBPFunctionLibrary::SpawnEntityFromEntityConfigDeferred(
AActor* Owner, UMassEntityConfigAsset* MassEntityConfig,
const UObject* WorldContextObject)
{
// FMassExecutionContext ExecutionContext(WorldContextObject->GetWorld()->DeltaTimeSeconds);
FMassExecutionContext ExecutionContext;

ExecutionContext.SetDeferredCommandBuffer(MakeShareable(new FMassCommandBuffer()));


if (!Owner || !MassEntityConfig) return FEntityHandleWrapper();

const FMassEntityTemplate& EntityTemplate = MassEntityConfig->GetConfig().GetOrCreateEntityTemplate(
*WorldContextObject->GetWorld(), *MassEntityConfig);

FMassEntityManager& EntitySubSystem = WorldContextObject->GetWorld()->GetSubsystem<UMassEntitySubsystem>()->
GetMutableEntityManager();

//const FMassEntityHandle ReservedEntity = EntitySubSystem.ReserveEntity();


//todo: this is very slow! I am just doing this to be able to stuff configs in here for now
TArray<const UScriptStruct*> FragmentTypesList;
EntityTemplate.GetCompositionDescriptor().Fragments.ExportTypes(FragmentTypesList);
TArray<const UScriptStruct*> TagsTypeList;

EntityTemplate.GetCompositionDescriptor().Tags.ExportTypes(TagsTypeList);

TArray<FInstancedStruct> InstanceStructs = TArray<FInstancedStruct>(FragmentTypesList);

TConstArrayView<FInstancedStruct> InitialFragmentInstances = EntityTemplate.GetInitialFragmentValues();

// InstanceStructs need to have the InitialFragmentInstances data-filled instanced structs, all of which already exist inside of InstanceStructs

for (auto InitialFragmentInstance : InitialFragmentInstances)
{
int32 index = InstanceStructs.IndexOfByPredicate([&](const FInstancedStruct InstancedStructValue)
{
return InstancedStructValue.GetScriptStruct() == InitialFragmentInstance.GetScriptStruct();
});
if (index != INDEX_NONE)
InstanceStructs[index] = InitialFragmentInstance;
}

// ExecutionContext.Defer().PushCommand<FMassCommandAddFragments<>(
// FBuildEntityFromFragmentInstancesAndTags(ReservedEntity,
// InstanceStructs,
// TagsTypeList,
// EntityTemplate.GetSharedFragmentValues()));


ExecutionContext.FlushDeferred();
//EntitySubSystem->FlushCommands(MakeShareable(new FMassCommandBuffer()));
//return FEntityHandleWrapper{ReservedEntity};


return FEntityHandleWrapper();
}


FEntityHandleWrapper UMSBPFunctionLibrary::SpawnEntityFromEntityConfigDeferredBugRepro(
AActor* Owner, UMassEntityConfigAsset* MassEntityConfig,
const UObject* WorldContextObject)
{
if (!Owner || !MassEntityConfig) return FEntityHandleWrapper();

Expand All @@ -123,7 +63,6 @@ FEntityHandleWrapper UMSBPFunctionLibrary::SpawnEntityFromEntityConfigDeferredBu
FMassEntityManager& EntityManager = WorldContextObject->GetWorld()->GetSubsystem<UMassEntitySubsystem>()->
GetMutableEntityManager();

const FMassEntityHandle ReservedEntity = EntityManager.ReserveEntity();


//todo: this is very slow! I am just doing this to be able to stuff configs in here for now
Expand Down Expand Up @@ -153,16 +92,30 @@ FEntityHandleWrapper UMSBPFunctionLibrary::SpawnEntityFromEntityConfigDeferredBu
// Copy a new composition descriptor because it gets changed in the addcomposition call
FMassArchetypeCompositionDescriptor CompositionDescriptor = EntityTemplate.GetCompositionDescriptor();

// Reserve an entity
const FMassEntityHandle ReservedEntity = EntityManager.ReserveEntity();

// We are using a lambda here because we don't have a deferred command that can do
EntityManager.Defer().PushCommand<FMassDeferredCreateCommand>([&](FMassEntityManager& System)
{
System.BuildEntity(ReservedEntity,InstanceStructs,EntityTemplate.GetSharedFragmentValues());
System.AddCompositionToEntity_GetDelta(ReservedEntity,CompositionDescriptor);
EntityManager.BuildEntity(ReservedEntity,InstanceStructs,EntityTemplate.GetSharedFragmentValues());
EntityManager.AddCompositionToEntity_GetDelta(ReservedEntity,CompositionDescriptor);
});

// Immediately flush? Doesn't seem too bad here but I imagine we could do this in a nicer way?s
// Immediately flush? Doesn't seem too bad here but I imagine we could do this in a nicer way?
EntityManager.FlushCommands();

// trigger observers manually for now as I'm too lazy to use the batch add for now
if (EntityManager.GetObserverManager().HasObserversForBitSet(EntityTemplate.GetCompositionDescriptor().Fragments, EMassObservedOperation::Add))
{

EntityManager.GetObserverManager().OnCompositionChanged(
FMassArchetypeEntityCollection(EntityTemplate.GetArchetype(), {ReservedEntity},FMassArchetypeEntityCollection::NoDuplicates)
, EntityTemplate.GetCompositionDescriptor()
, EMassObservedOperation::Add);
}


return FEntityHandleWrapper{ReservedEntity};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,10 @@ class MASSCOMMUNITYSAMPLE_API UMSBPFunctionLibrary : public UBlueprintFunctionLi
static FEntityHandleWrapper SpawnEntityFromEntityConfig(UMassEntityConfigAsset* MassEntityConfig, const UObject* WorldContextObject, const bool bDebug = false);


// todo: broken and hardcoded for testing, Don't use this yet!
UFUNCTION(BlueprintCallable, Category = "Mass", meta = (WorldContext = "WorldContextObject"))
static FEntityHandleWrapper SpawnEntityFromEntityConfigDeferred(AActor* Owner, UMassEntityConfigAsset* MassEntityConfig,
const UObject* WorldContextObject);
// todo: also broken and hardcoded for testing, Don't use this yet!
UFUNCTION(BlueprintCallable, Category = "Mass", meta = (WorldContext = "WorldContextObject"))
static FEntityHandleWrapper SpawnEntityFromEntityConfigDeferredBugRepro(AActor* Owner,
UMassEntityConfigAsset* MassEntityConfig,
const UObject* WorldContextObject);

//todo: Lazy fragment-specific versions until we can think of something nicer
UFUNCTION(BlueprintCallable, Category = "Mass", meta = (WorldContext = "WorldContextObject"))
static void SetEntityTransform(const FEntityHandleWrapper EntityHandle,const FTransform Transform, const UObject* WorldContextObject);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
UMSHashGridProcessor::UMSHashGridProcessor()
{
ExecutionOrder.ExecuteAfter.Add(UE::Mass::ProcessorGroupNames::Movement);
// In theory it should be thread save but I'm seeing wackiness so I'm slapping on singlethreaded for now
bRequiresGameThreadExecution = true;
ExecutionFlags = (int32)EProcessorExecutionFlags::All;
}

Expand Down Expand Up @@ -49,6 +51,7 @@ void UMSHashGridProcessor::Execute(FMassEntityManager& EntitySubsystem, FMassExe
UMSHashGridMemberInitializationProcessor::UMSHashGridMemberInitializationProcessor()
{
ObservedType = FMSGridCellStartingLocationFragment::StaticStruct();
bRequiresGameThreadExecution = true;
Operation = EMassObservedOperation::Add;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class MASSCOMMUNITYSAMPLE_API UMSHashGridProcessor : public UMassProcessor
FMassEntityQuery AddToHashGridQuery;
FMassEntityQuery UpdateHashGridQuery;
FMassEntityQuery RemoveFromGridEntityQuery;

UPROPERTY()
UMSSubsystem* MassSampleSystem;

virtual void Initialize(UObject& Owner) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
void UMSMoverMassTrait::BuildTemplate(FMassEntityTemplateBuildContext& BuildContext, const UWorld& World) const
{
BuildContext.AddTag<FSampleMoverTag>();
BuildContext.AddFragment<FTransformFragment>();
BuildContext.RequireFragment<FTransformFragment>();
BuildContext.AddFragment_GetRef<FMassForceFragment>().Value = Force;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ EStateTreeRunStatus FMassNavMeshPathFollowTask::Tick(FStateTreeExecutionContext&
{
FMassStateTreeExecutionContext& MassContext = static_cast<FMassStateTreeExecutionContext&>(Context);

const UMSSubsystem& MSSubsystem = Context.GetExternalData(MSSubsystemHandle);
const FAgentRadiusFragment& AgentRadius = Context.GetExternalData(AgentRadiusHandle);
FMassMoveTargetFragment& MoveTarget = Context.GetExternalData(MoveTargetHandle);
FMassNavMeshPathFollowTaskInstanceData& InstanceData = Context.GetInstanceData<
Expand All @@ -34,13 +33,7 @@ EStateTreeRunStatus FMassNavMeshPathFollowTask::Tick(FStateTreeExecutionContext&
const FMassMovementParameters& MovementParams = Context.GetExternalData(MovementParamsHandle);

const FVector AgentNavLocation = Context.GetExternalData(TransformHandle).GetTransform().GetLocation();

// const FMassMovementStyleRef MovementStyle = Context.GetInstanceData(MovementStyleHandle);
//
// const FVector TargetLocation = Context.GetInstanceData(TargetLocationHandle);
// const float SpeedScale = Context.GetInstanceData(SpeedScaleHandle);



auto NavMeshSubsystem = Cast<UNavigationSystemV1>(Context.GetWorld()->GetNavigationSystem());


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class MASSCOMMUNITYSAMPLE_API UMSSubsystem : public UWorldSubsystem

FMassArchetypeHandle MoverArchetype;

//FMSSpatialHash SpatialHashGrid;
FMSHashGrid3D HashGrid = FMSHashGrid3D(100.0f,FMassEntityHandle());

UPROPERTY()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
void UMSProjectileSimTrait::BuildTemplate(FMassEntityTemplateBuildContext& BuildContext, const UWorld& World) const
{
BuildContext.AddFragment<FLineTraceFragment>();
BuildContext.AddFragment<FTransformFragment>();
BuildContext.AddFragment<FMassVelocityFragment>();
BuildContext.RequireFragment<FTransformFragment>();
BuildContext.RequireFragment<FMassVelocityFragment>();
BuildContext.AddTag<FProjectileTag>();

if (bFiresHitEventToActors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void UMSNiagaraRepresentationTrait::BuildTemplate(FMassEntityTemplateBuildContex
{
UMSNiagaraSubsystem* ProjectileSubsystem = UWorld::GetSubsystem<UMSNiagaraSubsystem>(&World);

BuildContext.AddFragment<FTransformFragment>();
BuildContext.RequireFragment<FTransformFragment>();

FSharedStruct SharedFragment = ProjectileSubsystem->GetOrCreateSharedNiagaraFragmentForSystemType(
SharedNiagaraSystem);
Expand Down

0 comments on commit 435181d

Please sign in to comment.