diff --git a/Assets/Scripts/Server/ServerGameLogicJobs.cs b/Assets/Scripts/Server/ServerGameLogicJobs.cs index c2dcbb6..0e7e03d 100644 --- a/Assets/Scripts/Server/ServerGameLogicJobs.cs +++ b/Assets/Scripts/Server/ServerGameLogicJobs.cs @@ -22,6 +22,20 @@ namespace ECSTest.Server // Debug.LogError($"xxxx2222 CannonData id: {componentId2}"); } } + + [BurstCompile] + public struct GetDeferred : IJob + { + public World world; + + public void Execute() + { + // var componentId = ComponentId.Get(); + // Debug.LogError($"XXXX bulletData id: {componentId}"); + // var componentId2 = ComponentId.Get(); + // Debug.LogError($"xxxx2222 CannonData id: {componentId2}"); + } + } [BurstCompile] public struct SpawnCannonJob : IJob @@ -33,6 +47,7 @@ namespace ECSTest.Server public int maxCount; public int spawnCountPerFrame; public Rect rect; + public int initHealth; public void Execute() { @@ -49,7 +64,11 @@ namespace ECSTest.Server var velocity = new float2(c, s); var entity = database.AddEntity(); - //TODO + ref var cannonData = ref database.GetDataRef(entity); + cannonData.position = pos; + cannonData.velocity = velocity; + cannonData.direction = dir; + cannonData.health = initHealth; } } } diff --git a/Assets/Scripts/Server/ServerMain.cs b/Assets/Scripts/Server/ServerMain.cs index 65d9d37..8124c35 100644 --- a/Assets/Scripts/Server/ServerMain.cs +++ b/Assets/Scripts/Server/ServerMain.cs @@ -58,11 +58,6 @@ namespace ECSTest.Server void Update() { - var componentId = ComponentId.Get(); - Debug.LogError($"AAAA bulletData id: {componentId}"); - var componentId2 = ComponentId.Get(); - Debug.LogError($"AAAA2222 CannonData id: {componentId2}"); - networkJobHandle.Complete(); var concurrentDriver = driver.ToConcurrent(); diff --git a/Assets/Scripts/TestIJobParallelForDefer.cs b/Assets/Scripts/TestIJobParallelForDefer.cs new file mode 100644 index 0000000..c6b0175 --- /dev/null +++ b/Assets/Scripts/TestIJobParallelForDefer.cs @@ -0,0 +1,57 @@ +using Unity.Burst; +using Unity.Collections; +using Unity.Jobs; +using UnityEngine; + +namespace ECSTest +{ + public class TestIJobParallelForDefer + { + [BurstCompile] + public struct PopulateJob : IJob + { + public NativeList input; + + public void Execute() + { + Debug.Log($"000===== length: {input.Length}"); + for (int i = 0; i < 100; ++i) + input.Add(i); + } + } + + [BurstCompile] + public struct StatJob : IJob + { + public NativeList input; + + public void Execute() + { + Debug.Log($"111===== length: {input.Length}"); + } + } + + + [BurstCompile] + public struct ParallelJob : IJobParallelForDefer + { + [ReadOnly] public NativeList input; + + public void Execute(int index) + { + Debug.Log($"index: {index}, length: {input.Length}"); + } + } + + public static void Test() + { + var list = new NativeList(100, Allocator.TempJob); + var handle = new PopulateJob() {input = list}.Schedule(); + handle = new ParallelJob() { input = list }.Schedule(list, 16, handle); + handle = new PopulateJob() {input = list}.Schedule(handle); + handle = new ParallelJob() { input = list }.Schedule(list, 16, handle); + handle.Complete(); + list.Dispose(); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/TestIJobParallelForDefer.cs.meta b/Assets/Scripts/TestIJobParallelForDefer.cs.meta new file mode 100644 index 0000000..fc96495 --- /dev/null +++ b/Assets/Scripts/TestIJobParallelForDefer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c02a6e16e5b349d3b07d50471da304c9 +timeCreated: 1766089200 \ No newline at end of file