public int AddChunk()
        {
            var info = _containerInfo[0];

            if (_containerInfo[0].ChunkCapacity <= _containerInfo[0].ChunkCount)
            {
                var newChunkCapacity = _containerInfo[0].ChunkCapacity * 2;
                var newNodes         = new NativeArray <ActionStateNode>(newChunkCapacity * _containerInfo[0].NodeCount, Allocator.Persistent);
                NativeArray <ActionStateNode> .Copy(_nodes, 0, newNodes, 0, info.ChunkCapacity *info.NodeCount);

                _nodes.Dispose();
                _nodes = newNodes;


                var newStates = UnsafeUtility.Malloc(newChunkCapacity * info.StatesSize, 4, Allocator.Persistent);
                UnsafeUtility.MemCpy(newStates, _states, info.ChunkCapacity * info.StatesSize);
                UnsafeUtility.Free(_states, Allocator.Persistent);
                _states = (byte *)newStates;

                info.ChunkCapacity = newChunkCapacity;
            }

            _chunks.Add(new ActionStateChunk()
            {
                Position = info.ChunkCount
            });
            //var v = Nodes[chunkCount * nodeCount];
            //v.Cycle = NodeCycle.Active;
            //Nodes[chunkCount * nodeCount] = v;
            info.ChunkCount++;
            //BlackboardArray.Add();
            _blackboard.NewItem();
            _containerInfo[0] = info;
            return(info.ChunkCount - 1);
        }
Esempio n. 2
0
        public int AddChunk()
        {
            var _info = ContainerInfo[0];

            if (ContainerInfo[0].chunkCapacity <= ContainerInfo[0].chunkCount)
            {
                var newChunkCapacity = ContainerInfo[0].chunkCapacity * 2;
                var newNodes         = new NativeArray <ActionStateNode>(newChunkCapacity * ContainerInfo[0].nodeCount, Allocator.Persistent);
                NativeArray <ActionStateNode> .Copy(Nodes, 0, newNodes, 0, _info.chunkCapacity *_info.nodeCount);

                Nodes.Dispose();
                Nodes = newNodes;


                var newStates = UnsafeUtility.Malloc(newChunkCapacity * _info.statesSize, 4, Allocator.Persistent);
                UnsafeUtility.MemCpy(newStates, States, _info.chunkCapacity * _info.statesSize);
                UnsafeUtility.Free(States, Allocator.Persistent);
                States = (byte *)newStates;

                _info.chunkCapacity = newChunkCapacity;
            }

            Chunks.Add(new ActionStateChunk()
            {
                Position = _info.chunkCount
            });
            //var v = Nodes[chunkCount * nodeCount];
            //v.Cycle = NodeCycle.Active;
            //Nodes[chunkCount * nodeCount] = v;
            _info.chunkCount++;
            //BlackboardArray.Add();
            Blackboard.NewItem();
            ContainerInfo[0] = _info;
            return(_info.chunkCount - 1);
        }