测试IJobParallelForDefer

master
孙钦者 1 month ago
parent d9b66edd89
commit 098cbfb696
  1. 21
      Assets/Scripts/Server/ServerGameLogicJobs.cs
  2. 5
      Assets/Scripts/Server/ServerMain.cs
  3. 57
      Assets/Scripts/TestIJobParallelForDefer.cs
  4. 3
      Assets/Scripts/TestIJobParallelForDefer.cs.meta

@ -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<BulletData>.Get();
// Debug.LogError($"XXXX bulletData id: {componentId}");
// var componentId2 = ComponentId<CannonData>.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<CannonData>(entity);
cannonData.position = pos;
cannonData.velocity = velocity;
cannonData.direction = dir;
cannonData.health = initHealth;
}
}
}

@ -58,11 +58,6 @@ namespace ECSTest.Server
void Update()
{
var componentId = ComponentId<BulletData>.Get();
Debug.LogError($"AAAA bulletData id: {componentId}");
var componentId2 = ComponentId<CannonData>.Get();
Debug.LogError($"AAAA2222 CannonData id: {componentId2}");
networkJobHandle.Complete();
var concurrentDriver = driver.ToConcurrent();

@ -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<int> 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<int> input;
public void Execute()
{
Debug.Log($"111===== length: {input.Length}");
}
}
[BurstCompile]
public struct ParallelJob : IJobParallelForDefer
{
[ReadOnly] public NativeList<int> input;
public void Execute(int index)
{
Debug.Log($"index: {index}, length: {input.Length}");
}
}
public static void Test()
{
var list = new NativeList<int>(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();
}
}
}

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c02a6e16e5b349d3b07d50471da304c9
timeCreated: 1766089200
Loading…
Cancel
Save