private void Start() { var N = 10000; Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.None); var def = new TreeDef { Nodes = new INode[] { new FooNode(), new FooNode(), new FooNode(), new FooNode(), new FooNode(), new BarNode(), } }; _runtime = TreeRuntime.Create(def, N); var man = World.Active.GetOrCreateManager <EntityManager>(); for (int i = 0; i < N; ++i) { var e = man.CreateEntity(); _runtime.Register(man, e); //man.AddSharedComponentData(e, _runtime); } }
public static TreeRuntime Create(TreeDef tree, int capacity = 10) { var rt = new TreeRuntime { Def = tree, Capacity = capacity, }; rt.Data = new NativeArray <byte>(tree.Nodes.Sum(n => UnsafeUtility.SizeOf(n.DataType)) * capacity, Allocator.Persistent, NativeArrayOptions.ClearMemory); rt.State = new NativeArray <NodeState>(tree.Nodes.Length * capacity, Allocator.Persistent, NativeArrayOptions.ClearMemory); rt.NodeDataOffset = new NativeArray <int>(tree.Nodes.Length, Allocator.Persistent); rt._allocHandle = GCHandle.Alloc(new AllocState()); int off = 0; for (int i = 0; i < tree.Nodes.Length; ++i) { rt.NodeDataOffset[i] = off; off += UnsafeUtility.SizeOf(tree.Nodes[i].DataType) * capacity; } return(rt); }