Skip to content

Commit

Permalink
【ECSLearn】 使用IJobEntityBatch 代替IJobchunk
Browse files Browse the repository at this point in the history
  • Loading branch information
hexinping committed Aug 12, 2021
1 parent eb37e82 commit acc4d08
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ protected override void OnCreate()
_query = GetEntityQuery(typeof(Rotation), ComponentType.ReadOnly<RotationSpeed_IJobChunk>());
}
[BurstCompile]
struct RotationSpeedJob : IJobChunk
struct RotationSpeedJob : IJobEntityBatch
{
public ComponentTypeHandle<Rotation> RotationTypeHandle;
[ReadOnly] public ComponentTypeHandle<RotationSpeed_IJobChunk> RotationSpeedTypeHandle;
public float DeltaTime;
// public uint LastSystemVersion;
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
public void Execute(ArchetypeChunk chunk, int batchIndex)
{
// var RotationTypeHandleChanged = chunk.DidChange(RotationTypeHandle, LastSystemVersion);
// var RotationSpeedTypeChanged = chunk.DidChange(RotationSpeedTypeHandle, LastSystemVersion);
Expand Down Expand Up @@ -57,6 +57,6 @@ protected override void OnUpdate()
job.DeltaTime = Time.DeltaTime;
// job.LastSystemVersion = this.LastSystemVersion;

this.Dependency = job.ScheduleParallel(_query,this.Dependency);
Dependency = job.ScheduleParallel(_query, 1, Dependency);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protected override void OnCreate()
m_Query = GetEntityQuery(typeof(Rotation), ComponentType.ReadOnly<RotationSpeed_IJobEntityBatch>());
}

//IJobEntityBatch 效率特别高效
// Use the [BurstCompile] attribute to compile a job with Burst. You may see significant speed ups, so try it!
[BurstCompile]
struct RotationSpeedJob : IJobEntityBatch
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit acc4d08

Please sign in to comment.