From 5852f67c1361001ba89bf0d1673b7ac6060da74f Mon Sep 17 00:00:00 2001 From: victor Date: Sun, 26 Jul 2020 15:36:13 +0200 Subject: [PATCH] Dead code removed --- .../ECSTesting/ECS_Base/ECS_BaseSystems.cpp | 282 +----------------- Source/ECSTesting/ECS_Base/ECS_BaseSystems.h | 2 + .../ECS_SpaceBattle/ECS_BattleSystems.cpp | 35 +-- 3 files changed, 15 insertions(+), 304 deletions(-) diff --git a/Source/ECSTesting/ECS_Base/ECS_BaseSystems.cpp b/Source/ECSTesting/ECS_Base/ECS_BaseSystems.cpp index 72f484a..4925c67 100644 --- a/Source/ECSTesting/ECS_Base/ECS_BaseSystems.cpp +++ b/Source/ECSTesting/ECS_Base/ECS_BaseSystems.cpp @@ -41,86 +41,6 @@ StaticMeshDrawSystem::ISMData* StaticMeshDrawSystem::GetInstancedMeshForMesh(USt void StaticMeshDrawSystem::update(ECS_Registry ®istry, float dt) { - //reset instances once per second - Elapsed -= dt; - if (Elapsed < 0) - { - Elapsed = 1; - for (auto i : MeshMap) - { - i.Value.ISM->ClearInstances(); - i.Value.rendered = 0; - } - } - - { - SCOPE_CYCLE_COUNTER(STAT_InstancedMeshPrepare); - //copy transforms into the ISM RenderTransform - registry.view().each([&, dt](auto entity, FInstancedStaticMesh & ism, FPosition & pos) { - ism.RenderTransform.SetLocation(pos.pos); - }); - registry.view().each([&, dt](auto entity, FInstancedStaticMesh & ism, FRotationComponent & rot) { - ism.RenderTransform.SetRotation(rot.rot); - }); - registry.view().each([&, dt](auto entity, FInstancedStaticMesh & ism, FScale & sc) { - ism.RenderTransform.SetScale3D(sc.scale); - }); - - } - - - { - SCOPE_CYCLE_COUNTER(STAT_InstancedMeshDraw); - - auto view = registry.view(); - - for (auto entity : view) { - - FInstancedStaticMesh &mesh = view.get(entity); - - auto MeshData = GetInstancedMeshForMesh(mesh.mesh); - auto RenderMesh = MeshData->ISM; - - const FTransform &RenderTransform = mesh.RenderTransform;// mesh.RelativeTransform.GetRelativeTransform(mesh.RenderTransform); - - if (RenderMesh->GetInstanceCount() < MeshData->rendered) - { - RenderMesh->AddInstanceWorldSpace(RenderTransform); - } - else - { - RenderMesh->UpdateInstanceTransform(MeshData->rendered, RenderTransform, true, false); - } - MeshData->rendered++; - } - - - } - { - SCOPE_CYCLE_COUNTER(STAT_InstancedMeshClean) - for (auto& i : MeshMap) - { - - - FTransform nulltransform; - nulltransform.SetScale3D(FVector(0.0, 0.0, 0.0)); - - //if we have more instances than renderables, set the instances to null transform so they dont draw. - //they will get cleanup once a second. - if (IsValid(i.Value.ISM)) - { - while (i.Value.rendered < i.Value.ISM->GetInstanceCount()) - { - - i.Value.rendered++; - i.Value.ISM->UpdateInstanceTransform(i.Value.rendered, nulltransform, true, false); - - } - i.Value.ISM->MarkRenderStateDirty(); - } - } - } - } void StaticMeshDrawSystem::schedule(ECSSystemScheduler* sysScheduler) @@ -269,84 +189,7 @@ EntityHandle ArchetypeSpawnerSystem::SpawnFromArchetype(ECS_Registry& registry, void ArchetypeSpawnerSystem::update(ECS_Registry ®istry, float dt) { - assert(OwnerActor); - - SCOPE_CYCLE_COUNTER(STAT_ECSSpawn); - - //exclusively update timing - auto SpawnerView = registry.view(); - for (auto e : SpawnerView) - { - SpawnerView.get(e).TimeUntilSpawn -= dt; - } - - //spawn from arc and actortransform - auto SpawnerArcView = registry.view(); - for (auto e : SpawnerArcView) - { - const FTransform &ActorTransform = SpawnerArcView.get(e).transform; - FArchetypeSpawner& spawner = SpawnerArcView.get(e); - const FRandomArcSpawn& arc = SpawnerArcView.get(e); - - if (spawner.TimeUntilSpawn < 0) - { - if (spawner.ArchetypeClass) - { - EntityHandle h = SpawnFromArchetype(registry, spawner.ArchetypeClass); - registry.accommodate(h.handle, ActorTransform.GetLocation()); - - if (registry.has(e)) - { - registry.accommodate(h.handle, registry.get(e)); - } - - FVelocity vel; - const float VelMagnitude = World->rng.FRandRange(arc.MinVelocity, arc.MaxVelocity); - const float Arc = FMath::DegreesToRadians(World->rng.FRandRange(arc.MinAngle, arc.MaxAngle)); - - - FVector ArcVel = World->rng.VRandCone(FVector(1.0, 0.0, 0.0), Arc) *VelMagnitude; - - FVector BulletVelocity = ActorTransform.GetRotation().RotateVector(ArcVel); - registry.accommodate(h.handle, BulletVelocity); - } - - if (spawner.bLoopSpawn) - { - spawner.TimeUntilSpawn = spawner.SpawnRate; - } - else - { - registry.remove(e); - } - } - } - - //Spawn with basic position - auto SpawnerPositionView = registry.view(); - for (auto e : SpawnerPositionView) - { - const FVector &SpawnPosition = SpawnerPositionView.get(e).pos; - FArchetypeSpawner& spawner = SpawnerPositionView.get(e); - - if (spawner.TimeUntilSpawn < 0) - { - if (spawner.ArchetypeClass) - { - EntityHandle h = SpawnFromArchetype(registry, spawner.ArchetypeClass); - registry.accommodate(h.handle, SpawnPosition); - } - - if (spawner.bLoopSpawn) - { - spawner.TimeUntilSpawn = spawner.SpawnRate; - } - else - { - registry.remove(e); - } - } - } + } PRAGMA_DISABLE_OPTIMIZATION void ArchetypeSpawnerSystem::schedule(ECSSystemScheduler* sysScheduler) @@ -501,34 +344,6 @@ void RaycastSystem::CheckRaycasts(ECS_Registry& registry, float dt, UWorld* Game } } }); - - // if (GameWorld->IsTraceHandleValid(ray.handle, false)) - // { - // FTraceDatum tdata; - // GameWorld->QueryTraceData(ray.handle, tdata); - // if (tdata.OutHits.IsValidIndex(0)) - // { - // //it actually hit - // if (tdata.OutHits[0].bBlockingHit) - // { - // ////if its an actor, try to damage it. - // AActor* act = tdata.OutHits[0].GetActor(); - // if (act) - // { - // actorCalls.enqueue({act}); - // } - // - // //if the entity was a projectile, create explosion and destroy it - // if (registry.has(entity)) - // { - // FVector ExplosionPoint = tdata.OutHits[0].ImpactPoint; - // - // explosions.enqueue({entity,ExplosionPoint}); - // } - // } - // } - // } - //}); } void RaycastSystem::CreateExplosion(ECS_Registry& registry, EntityID entity, FVector ExplosionPoint) @@ -656,33 +471,7 @@ void RaycastSystem::schedule(ECSSystemScheduler* sysScheduler) void LifetimeSystem::update(ECS_Registry& registry, float dt) { - assert(OwnerActor); - - SCOPE_CYCLE_COUNTER(STAT_Lifetime); - - ////tick the lifetime timers - //auto LifetimeView = registry.view(); - //for (auto e : LifetimeView) - //{ - // auto& Deleter = LifetimeView.get(e); - // - // Deleter.LifeLeft -= dt; - // if (Deleter.LifeLeft < 0) - // { - // //add a Destroy component so it gets deleted - // registry.accommodate(e); - // } - //} - // - ////logic can be done here for custom deleters, nothing right now - // - // - ////delete everything with a FDestroy component - //auto DeleteView = registry.view(); - //for (auto e : DeleteView) - //{ - // registry.destroy(e); - //} + } @@ -758,24 +547,26 @@ void LifetimeSystem::schedule(ECSSystemScheduler* sysScheduler) void CopyTransformToActorSystem::update(ECS_Registry& registry, float dt) { +} - assert(OwnerActor); +void CopyTransformToActorSystem::PackTransforms(ECS_Registry& registry) +{ SCOPE_CYCLE_COUNTER(STAT_PackActorTransform); { - + //fill ActorTransform from separate components - registry.view().each([&, dt](auto entity, FActorTransform& transform, FPosition& pos) { + registry.view().each([&](auto entity, FActorTransform& transform, FPosition& pos) { transform.transform.SetLocation(pos.pos); }); - registry.view().each([&, dt](auto entity, FActorTransform& transform, FRotationComponent& rot) { + registry.view().each([&](auto entity, FActorTransform& transform, FRotationComponent& rot) { transform.transform.SetRotation(rot.rot); }); - registry.view().each([&, dt](auto entity, FActorTransform& transform, FScale& sc) { + registry.view().each([&](auto entity, FActorTransform& transform, FScale& sc) { transform.transform.SetScale3D(sc.scale); }); } - + //copy transforms from actor into FActorTransform auto TransformView = registry.view(); for (auto e : TransformView) @@ -805,7 +596,7 @@ void CopyTransformToActorSystem::schedule(ECSSystemScheduler* sysScheduler) builder.AddTask(deps1, //builder.AddSyncTask( [=](ECS_Registry& reg) { - this->update(reg, 1.0 / 60.0); + PackTransforms(reg); } ); @@ -834,39 +625,6 @@ void CopyTransformToActorSystem::schedule(ECSSystemScheduler* sysScheduler) void CopyTransformToECSSystem::update(ECS_Registry& registry, float dt) { -#if 0 - assert(OwnerActor); - - //copy transforms from actor into FActorTransform - auto ActorTransformView = registry.view(); - for (auto e : ActorTransformView) - { - SCOPE_CYCLE_COUNTER(STAT_CopyTransformECS); - FActorReference& actor = ActorTransformView.get(e); - if (actor.ptr.IsValid()) - { - const FTransform& ActorTransform = actor.ptr->GetActorTransform(); - registry.accommodate(e, ActorTransform); - } - } - { - - SCOPE_CYCLE_COUNTER(STAT_UnpackActorTransform); - //unpack from ActorTransform into the separate transform components, only if the entity does have that component - registry.view().each([&, dt](auto entity, FActorTransform& transform, FPosition& pos) { - - pos.pos = transform.transform.GetLocation(); - }); - registry.view().each([&, dt](auto entity, FActorTransform& transform, FRotationComponent& rot) { - - rot.rot = transform.transform.GetRotation(); - }); - registry.view().each([&, dt](auto entity, FActorTransform& transform, FScale& sc) { - - sc.scale = transform.transform.GetScale3D(); - }); - } -#endif } void CopyTransformToECSSystem::schedule(ECSSystemScheduler* sysScheduler) @@ -933,24 +691,6 @@ void CopyTransformToECSSystem::schedule(ECSSystemScheduler* sysScheduler) void MovementSystem::update(ECS_Registry& registry, float dt) { -#if 0 - SCOPE_CYCLE_COUNTER(STAT_Movement); - - //movement raycast gets a "last position" component - registry.view().each([&, dt](auto entity, FMovementRaycast& ray, FPosition& pos) { - registry.accommodate(entity, pos.pos); - }); - - //add gravity and basic movement from velocity - registry.view().each([&, dt](auto entity, FMovement& m, FPosition& pos, FVelocity& vel) { - - //gravity - const FVector gravity = FVector(0.f, 0.f, -980) * m.GravityStrenght; - vel.Add(gravity * dt); - - pos.Add(vel.vel * dt); - }); -#endif } void MovementSystem::schedule(ECSSystemScheduler* sysScheduler) diff --git a/Source/ECSTesting/ECS_Base/ECS_BaseSystems.h b/Source/ECSTesting/ECS_Base/ECS_BaseSystems.h index 06a7acf..5706a3a 100644 --- a/Source/ECSTesting/ECS_Base/ECS_BaseSystems.h +++ b/Source/ECSTesting/ECS_Base/ECS_BaseSystems.h @@ -50,6 +50,8 @@ struct CopyTransformToActorSystem :public System { void update(ECS_Registry ®istry, float dt) override; + void PackTransforms(ECS_Registry& registry); + void schedule(ECSSystemScheduler* sysScheduler) override; diff --git a/Source/ECSTesting/ECS_SpaceBattle/ECS_BattleSystems.cpp b/Source/ECSTesting/ECS_SpaceBattle/ECS_BattleSystems.cpp index 72bffcf..8d46cff 100644 --- a/Source/ECSTesting/ECS_SpaceBattle/ECS_BattleSystems.cpp +++ b/Source/ECSTesting/ECS_SpaceBattle/ECS_BattleSystems.cpp @@ -11,9 +11,7 @@ void SpaceshipSystem::update(ECS_Registry& registry, float dt) registry.view().each([&, dt](auto entity, FSpaceship& ship, FRotationComponent& rotation, FVelocity& vel) { rotation.rot = vel.vel.Rotation().Quaternion(); - //scale.scale = FVector((ex.LiveTime / ex.Duration)*ex.MaxScale); - - }); + }); } void SpaceshipSystem::schedule(ECSSystemScheduler* sysScheduler) @@ -37,9 +35,7 @@ void SpaceshipSystem::schedule(ECSSystemScheduler* sysScheduler) } void BoidSystem::update(ECS_Registry& registry, float dt) -{ - - +{ UpdateGridmap(registry); UpdateAllBoids(registry, dt); @@ -231,37 +227,12 @@ void BoidSystem::schedule(ECSSystemScheduler* sysScheduler) ); builder.AddDependency("CopyTransform"); - ////block everything past boids for good logic - //builder.AddSyncTask([](ECS_Registry& reg) { - // - //}); sysScheduler->AddTaskgraph(builder.FinishGraph()); } void ExplosionSystem::update(ECS_Registry& registry, float dt) { - assert(OwnerActor); - SCOPE_CYCLE_COUNTER(STAT_Explosion); - - auto AllExplosionsView = registry.view(); - for (auto e : AllExplosionsView) { - FExplosion& ex = AllExplosionsView.get(e); - - ex.LiveTime += dt; - if (ex.LiveTime > ex.Duration) - { - //registry.assign(e); - } - } - - - registry.view().each([&, dt](auto entity, FExplosion& ex, FScale& scale) { - - - scale.scale = FVector((ex.LiveTime / ex.Duration) * ex.MaxScale); - - }); } void ExplosionSystem::schedule(ECSSystemScheduler* sysScheduler) @@ -279,10 +250,8 @@ void ExplosionSystem::schedule(ECSSystemScheduler* sysScheduler) [=](ECS_Registry& reg) { SCOPE_CYCLE_COUNTER(STAT_Explosion); - DeletionContext* del = DeletionContext::GetFromRegistry(reg); - auto AllExplosionsView = reg.view(); for (auto e : AllExplosionsView) { FExplosion& ex = AllExplosionsView.get(e);