Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SystemState.BeforeOnUpdate.Complete() removed
SystemState.BeforeOnUpdate.Complete() was removed to stop sync points in fixed updated. This has been replaced with CompleteWorldDependencySystem.
  • Loading branch information
tertle committed Sep 29, 2023
1 parent bd11c03 commit 3c81cc6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -2,6 +2,7 @@
This fork provides performance optimizations, quick fixes, and improvements to the entities package. It will never add new features. Therefore, as long as you don't depend on some obscure behavior, you should always be able to switch between the official package and this fork without any issues.

## Changes
- SystemState.BeforeOnUpdate.Complete() removed to stop sync points in fixed updated. Replaced with CompleteWorldDependencySystem.

# About Entities
The Entities package provides a modern Entity Component System (ECS) implementation with a basic set of systems and components made for Unity.
Expand Down
45 changes: 45 additions & 0 deletions Unity.Entities/CompleteWorldDependencySystem.cs
@@ -0,0 +1,45 @@
namespace Unity.Entities
{
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using UnityEngine.Scripting;

[Preserve]
[UpdateInGroup(typeof(InitializationSystemGroup))]
[WorldSystemFilter(WorldSystemFilterFlags.Default | WorldSystemFilterFlags.ThinClientSimulation | WorldSystemFilterFlags.Editor)]
public unsafe partial struct CompleteWorldDependencySystem : ISystem
{
private NativeList<JobHandle> m_dependencies;
private JobHandle m_dependency;

[BurstCompile]
public void OnCreate(ref SystemState state)
{
m_dependencies = new NativeList<JobHandle>(128, Allocator.Persistent);
}

[BurstCompile]
public void OnDestroy(ref SystemState state)
{
m_dependencies.Dispose();
}

[BurstCompile]
public void OnUpdate(ref SystemState state)
{
m_dependency.Complete();

using var e = state.WorldUnmanaged.GetImpl().m_SystemStatePtrMap.GetEnumerator();
while (e.MoveNext())
{
var systemState = (SystemState*)e.Current.Value;
this.m_dependencies.Add(systemState->m_JobHandle);
}

// This seems slightly faster than doing JobHandle.CompleteAll()
m_dependency = JobHandle.CombineDependencies(m_dependencies.AsArray());
m_dependencies.Clear();
}
}
}
3 changes: 3 additions & 0 deletions Unity.Entities/CompleteWorldDependencySystem.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Unity.Entities/SystemState.cs
Expand Up @@ -412,9 +412,9 @@ public JobHandle Dependency
{
var depMgr = m_DependencyManager;
NeedToGetDependencyFromSafetyManager = false;
m_JobHandle = depMgr->GetDependency(m_JobDependencyForReadingSystems.Ptr,
m_JobHandle = JobHandle.CombineDependencies(m_JobHandle, depMgr->GetDependency(m_JobDependencyForReadingSystems.Ptr,
m_JobDependencyForReadingSystems.Length, m_JobDependencyForWritingSystems.Ptr,
m_JobDependencyForWritingSystems.Length);
m_JobDependencyForWritingSystems.Length));
}

return m_JobHandle;
Expand Down Expand Up @@ -585,7 +585,7 @@ internal void BeforeOnUpdate()

// We need to wait on all previous frame dependencies, otherwise it is possible that we create infinitely long dependency chains
// without anyone ever waiting on it
m_JobHandle.Complete();
// m_JobHandle.Complete();
NeedToGetDependencyFromSafetyManager = true;
}

Expand Down

0 comments on commit 3c81cc6

Please sign in to comment.