// Writes Chunk c's state metadata into given buffer // and returns the amount of bytes written public static int CompressMetadataState(Chunk c, byte[] buffer, int targetPos = 0) { List <ushort> palleteList = Compression.GetPallete(Pallete.METADATA); int bytes; NativeArray <int> writtenBytes = new NativeArray <int>(new int[1] { 0 }, Allocator.TempJob); NativeArray <ushort> chunkData = NativeTools.CopyToNative(c.metadata.GetStateData()); NativeArray <byte> buff = NativeTools.CopyToNative(buffer); NativeArray <ushort> palleteArray = NativeTools.CopyToNative(palleteList.ToArray()); CompressionJob cmdJob = new CompressionJob { chunkData = chunkData, buffer = buff, palleteArray = palleteArray, writtenBytes = writtenBytes }; JobHandle handle = cmdJob.Schedule(); handle.Complete(); NativeArray <byte> .Copy(buff, 0, buffer, targetPos, writtenBytes[0]); bytes = writtenBytes[0]; chunkData.Dispose(); palleteArray.Dispose(); buff.Dispose(); writtenBytes.Dispose(); return(bytes); }
public static void Copy(NativeArray <T> input, NativeArray <T> output, Int2 inputSize, Int2 outputSize, IntRect inputBounds, IntRect outputBounds) { Assert(input.Length == inputSize.x * inputSize.y); Assert(output.Length == outputSize.x * outputSize.y); Assert(inputBounds.xmin >= 0 && inputBounds.ymin >= 0 && inputBounds.xmax < inputSize.x && inputBounds.ymax < inputSize.y); Assert(outputBounds.xmin >= 0 && outputBounds.ymin >= 0 && outputBounds.xmax < outputSize.x && outputBounds.ymax < outputSize.y); Assert(inputBounds.Width == outputBounds.Width && inputBounds.Height == outputBounds.Height); if (inputSize == outputSize && inputBounds.Width == inputSize.x && inputBounds.Height == inputSize.y) { // One contiguous chunk input.CopyTo(output); } else { // Copy row-by-row for (int z = 0; z < outputBounds.Height; z++) { var rowOffsetInput = (z + inputBounds.ymin) * inputSize.x + inputBounds.xmin; var rowOffsetOutput = (z + outputBounds.ymin) * outputSize.x + outputBounds.xmin; // Using a raw MemCpy call is a bit faster, but that requires unsafe code // Using a for loop is *a lot* slower (except for very small arrays, in which case it is about the same or very slightly faster). NativeArray <T> .Copy(input, rowOffsetInput, output, rowOffsetOutput, outputBounds.Width); } } }
public void RemoveChunkAt(int index) { #if ENABLE_UNITY_COLLECTIONS_CHECKS if (index < 0 || index >= Chunks.Length) { throw new ArgumentOutOfRangeException(nameof(index), "index 溢出"); } #endif var _info = ContainerInfo[0]; var remove_chunk = Chunks[index]; var last_chunk = Chunks[_info.chunkCount - 1]; NativeArray <ActionStateNode> .Copy( Nodes, last_chunk.Position *_info.nodeCount, Nodes, remove_chunk.Position *_info.nodeCount, _info.nodeCount); UnsafeUtility.MemCpy( States + last_chunk.Position * _info.statesSize, States + remove_chunk.Position * _info.statesSize, _info.statesSize); Chunks[index] = last_chunk; _info.chunkCount--; ContainerInfo[0] = _info; }
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); }
public void CopyToCache(UncompressedImageData target) { target.Name = Name; target.Frame = Frame; target.Time = Time; target.Sequence = Sequence; target.Width = Width; target.Height = Height; target.Length = Length; target.Encoding = Encoding; target.IsBigEndian = IsBigEndian; if (target.Bytes == null || target.Bytes.Length != Length) { target.Bytes = new byte[Length]; } if (NativeArray != default) { NativeArray <byte> .Copy(NativeArray, 0, target.Bytes, 0, Length); } else { Array.Copy(Bytes, target.Bytes, Length); } }
public void ToData(Data data) { if (distances != null && distances.Length == data.RawData.Length) { NativeArray <float> .Copy(distances, data.RawData); } }
public void FromData(Data data) { colNum = data.ColNum; rowNum = data.RowNum; distances = new float[colNum * rowNum]; NativeArray <float> .Copy(data.RawData, distances); }
public static void Copy(NativeArray <T> input, NativeArray <T> output, int3 inputSize, int3 outputSize, IntBounds inputBounds, IntBounds outputBounds) { Assert(input.Length == inputSize.x * inputSize.y * inputSize.z); Assert(output.Length == outputSize.x * outputSize.y * outputSize.z); Assert(math.all(inputBounds.min >= 0 & inputBounds.max <= inputSize)); Assert(math.all(outputBounds.min >= 0 & outputBounds.max <= outputSize)); Assert(math.all(inputBounds.size == outputBounds.size)); if (math.all(inputSize == outputSize & inputBounds.size == inputSize)) { // One contiguous chunk input.CopyTo(output); } else { // Copy row-by-row var inputStrides = new int3(1, inputSize.x * inputSize.z, inputSize.x); var outputStrides = new int3(1, outputSize.x * outputSize.z, outputSize.x); for (int y = 0; y < outputBounds.size.y; y++) { for (int z = 0; z < outputBounds.size.z; z++) { var rowOffsetInput = math.csum((new int3(0, y, z) + inputBounds.min) * inputStrides); var rowOffsetOutput = math.csum((new int3(0, y, z) + outputBounds.min) * outputStrides); // Using a raw MemCpy call is a bit faster, but that requires unsafe code // Using a for loop is *a lot* slower (except for very small arrays, in which case it is about the same or very slightly faster). NativeArray <T> .Copy(input, rowOffsetInput, output, rowOffsetOutput, outputBounds.size.x); } } } }
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); }
public void Execute() { if (numAgents == 0) { outBoundingBox[0] = float3.zero; outBoundingBox[1] = float3.zero; return; } float3 mn = agentPositions[0]; float3 mx = agentPositions[0]; for (int i = 0; i < numAgents; i++) { agents[i] = i; mn = math.min(mn, agentPositions[i]); mx = math.max(mx, agentPositions[i]); } outBoundingBox[0] = mn; outBoundingBox[1] = mx; int firstFreeChild = 1; BuildNode(mn, mx, 0, 0, numAgents, 0, ref firstFreeChild); CalculateSpeeds(firstFreeChild); NativeArray <float3> .Copy(agentPositions, outAgentPositions, numAgents); NativeArray <float> .Copy(agentRadii, outAgentRadii, numAgents); }
private void CopyState <T>(ref NativeEntityArray <T> ary, ref NativeArray <T> entityAry) where T : unmanaged, IEntity { if (ary.Length != 0) { if (entityAry.Length == ary._EntityAry.Length) { NativeArray <T> .Copy(ary._EntityAry, entityAry); } else { if (entityAry.Length != 0) { entityAry.Dispose(); } entityAry = new NativeArray <T>(ary._EntityAry, Allocator.Persistent); } } else { if (entityAry.Length != 0) { entityAry.Dispose(); } } }
private void CopyState <T>(ref NativeEntityArray <T> ary, ref NativeArray <T> _allBoids) where T : unmanaged, IEntity { if (ary.Length != 0) { if (_allBoids.Length == ary._EntityAry.Length) { NativeArray <T> .Copy(ary._EntityAry, _allBoids); } else { if (_allBoids.Length != 0) { _allBoids.Dispose(); } _allBoids = new NativeArray <T>(ary._EntityAry, Allocator.Persistent); } } else { if (_allBoids.Length != 0) { _allBoids.Dispose(); } } }
public void RenderPheromones(GameOptions options) { Blocked = false; currentSettings.particleSize = options.blurryPheromones ? 0.25f : 0.05f; if (CurrentState == RenderState.RENDERING && jobHandle.IsCompleted) { renderer.material = options.blurryPheromones ? blurryMaterial : solidMaterial; if (options.blurryPheromones) { var am = pheroParticleSystem.textureSheetAnimation; am.enabled = false; } else { var am = pheroParticleSystem.textureSheetAnimation; am.enabled = true; } jobHandle.Complete(); NativeArray <ParticleSystem.Particle> .Copy(jobResult, 0, jobResultOutput, 0, pheroCount); pheroParticleSystem.SetParticles(jobResultOutput, pheroCount); CurrentState = RenderState.IDLE; //startingIndex += PARTICLES_PER_FRAME; } else { if (!jobHandle.IsCompleted) { Blocked = true; } } }
public void RemoveChunkAt(int index) { #if ENABLE_UNITY_COLLECTIONS_CHECKS if (index < 0 || index >= _chunks.Length) { throw new ArgumentOutOfRangeException(nameof(index), "index 溢出"); } #endif var info = _containerInfo[0]; var removeChunk = _chunks[index]; var lastChunk = _chunks[info.ChunkCount - 1]; NativeArray <ActionStateNode> .Copy( _nodes, lastChunk.Position *info.NodeCount, _nodes, removeChunk.Position *info.NodeCount, info.NodeCount); UnsafeUtility.MemCpy( _states + lastChunk.Position * info.StatesSize, _states + removeChunk.Position * info.StatesSize, info.StatesSize); _chunks[index] = lastChunk; info.ChunkCount--; _containerInfo[0] = info; }
public DecodeContext(PhotoshopFile.Layer layer, Rectangle bounds) { Layer = layer; ByteDepth = Util.BytesFromBitDepth(layer.PsdFile.BitDepth); HasAlphaChannel = 0; Channels = layer.Channels.ToIdArray(); var alphaSize = 4; if (layer.AlphaChannel != null && layer.AlphaChannel.ImageData.Length > 0) { HasAlphaChannel = 1; alphaSize = layer.AlphaChannel.ImageData.Length; alphaSize = (alphaSize / 4) + (alphaSize % 4 > 0 ? 1 : 0); alphaSize = alphaSize * 4; } AlphaChannel = new NativeArray <byte>(alphaSize, Allocator.TempJob); if (HasAlphaChannel > 0) { NativeArray <byte> .Copy(layer.AlphaChannel.ImageData, AlphaChannel, layer.AlphaChannel.ImageData.Length); } ColorMode = layer.PsdFile.ColorMode; ColorModeData = new NativeArray <byte>(layer.PsdFile.ColorModeData, Allocator.TempJob); // Clip the layer to the specified bounds Rectangle = Layer.Rect.IntersectWith(bounds); if (layer.Masks != null) { LayerMaskContext = GetMaskContext(layer.Masks.LayerMask); UserMaskContext = GetMaskContext(layer.Masks.UserMask); } }
public void EnsureCapacity(int value) { if (value <= Capacity) { return; } int newCapacity = Math.Max(Capacity, 16); while (newCapacity < value) { newCapacity *= 2; } var newArray = new NativeArray <T>(newCapacity, Allocator.Persistent); if (array.Length != 0) { NativeArray <T> .Copy(array, newArray, length); array.Dispose(); } array = newArray; }
protected override void OnUpdate() { UnityEngine.Profiling.Profiler.BeginSample("BeamSync"); Sync(); UnityEngine.Profiling.Profiler.EndSample(); // BeamSync var batchMatrices = _beamSystem.BatchMatrices; int num = batchMatrices.Length; var matrices = batchMatrices.AsArray(); int idx = 0; UnityEngine.Profiling.Profiler.BeginSample("BeamDrawMeshInstanced"); while (num > 0) { int cnum = num >= Cv.InstanceLimit ? Cv.InstanceLimit : num; NativeArray <Matrix4x4> .Copy(matrices, idx *Cv.InstanceLimit, _matricesInRenderer[idx], 0 /* dstIndex */, cnum); Graphics.DrawMeshInstanced(_mesh, 0, _material, _matricesInRenderer[idx], cnum, null, ShadowCastingMode.Off, false /* receive shadows */, 0 /* layer */, null /* camera */, LightProbeUsage.BlendProbes, null /* lightProbeProxyVolume */); num -= cnum; ++idx; } UnityEngine.Profiling.Profiler.EndSample(); // BeamDrawMeshInstanced }
NativeArray <XRRaycastHit> RaycastFallback( Ray ray, TrackableType trackableTypeMask, Allocator allocator) { s_NativeRaycastHits.Clear(); int count = 0; foreach (var raycaster in m_Raycasters) { var hits = raycaster.Raycast(ray, trackableTypeMask, Allocator.Temp); if (hits.IsCreated) { s_NativeRaycastHits.Add(hits); count += hits.Length; } } var allHits = new NativeArray <XRRaycastHit>(count, allocator); int dstIndex = 0; foreach (var hitArray in s_NativeRaycastHits) { NativeArray <XRRaycastHit> .Copy(hitArray, 0, allHits, dstIndex, hitArray.Length); hitArray.Dispose(); dstIndex += hitArray.Length; } return(allHits); }
private void Update() { if (isConnected) { if (positionTex.width != Record3DDeviceStream.frameWidth || positionTex.height != Record3DDeviceStream.frameHeight) { Debug.Log(String.Format("REINITIALIZING TEXTURES {0}x{1}", Record3DDeviceStream.frameWidth, Record3DDeviceStream.frameHeight)); ReinitializeTextures(Record3DDeviceStream.frameWidth, Record3DDeviceStream.frameHeight); } var positionTexBufferSize = positionTex.width * positionTex.height * sizeof(float); if (Record3DDeviceStream.positionsBuffer != null) { NativeArray <float> .Copy(Record3DDeviceStream.positionsBuffer, positionTex.GetRawTextureData <float>(), positionTexBufferSize); positionTex.Apply(false, false); } const int numRGBChannels = 3; var colorTexBufferSize = colorTex.width * colorTex.height * numRGBChannels * sizeof(byte); if (Record3DDeviceStream.rgbBuffer != null) { NativeArray <byte> .Copy(Record3DDeviceStream.rgbBuffer, colorTex.GetRawTextureData <byte>(), colorTexBufferSize); colorTex.Apply(false, false); } } }
public void CopyPixelDataToLayer <T>(NativeArray <T> colorData, int layerIdx, GraphicsFormat format) where T : struct { var layer = GetLayer(layerIdx); NativeArray <T> dstDataAsColor; AtomicSafetyHandle safety = AtomicSafetyHandle.Create(); unsafe { dstDataAsColor = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <T>(layer.data, layer.dataSize, Allocator.None); NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref dstDataAsColor, safety); } var dstWidth = layer.scanlineSize / UnsafeUtility.SizeOf <T>(); int scanLines = height / (int)GraphicsFormatUtility.GetBlockHeight(format); int pitch = (width * (int)GraphicsFormatUtility.GetBlockSize(format)) / ((int)GraphicsFormatUtility.GetBlockWidth(format) * UnsafeUtility.SizeOf <T>()); if (scanLines * pitch > colorData.Length) { throw new ArgumentException($"Could not copy from ColorData in layer {layer}, {format}. The Provided source array is smaller than the tile content."); } if ((scanLines - 1) * dstWidth + pitch > dstDataAsColor.Length) { throw new ArgumentException($"Trying to write outside of the layer {layer} data buffer bounds. Is the provided format {format} correct?"); } for (int i = 0; i < scanLines; ++i) { NativeArray <T> .Copy(colorData, i *pitch, dstDataAsColor, i *dstWidth, pitch); } dstDataAsColor.Dispose(); AtomicSafetyHandle.Release(safety); }
// Update is called once per frame void Update() { if (isConnected) { //Record3DDeviceStream.positionsBuffer (4 floats per pixel) inputPositionBuffer.SetData(Record3DDeviceStream.positionsBuffer); ////Record3DDeviceStream.rgbBuffer (3 bytes per pixel) //inputColorBuffer.SetData(Record3DDeviceStream.rgbBuffer); TextureGenerator.Dispatch(vertexTextureGeneratorKernelId, Record3DDeviceStream.frameMetadata.width, Record3DDeviceStream.frameMetadata.height, 1); //TextureGenerator.Dispatch(colorTextureGeneratorKernelId, Record3DDeviceStream.frameMetadata.width, Record3DDeviceStream.frameMetadata.height, 1); //var positionTexBufferSize = vertexTexture.width * vertexTexture.height * sizeof(float); //NativeArray<float>.Copy(Record3DDeviceStream.positionsBuffer, ((Texture2D)vertexTexture).GetRawTextureData<float>(), positionTexBufferSize); //((Texture2D)vertexTexture).Apply(false, false); const int numRGBChannels = 3; var colorTexBufferSize = colorTexture.width * colorTexture.height * numRGBChannels * sizeof(byte); NativeArray <byte> .Copy(Record3DDeviceStream.rgbBuffer, ((Texture2D)colorTexture).GetRawTextureData <byte>(), colorTexBufferSize); ((Texture2D)colorTexture).Apply(false, false); } }
protected override void EndGeneration(Mesh mesh) { uint flags = MeshDataBufferFlags; if (HasUVs) { flags |= (uint)MeshBuffer.UV; } using (MeshData data = new MeshData(vertices.Length, triangles.Length, Allocator.Temp, flags)) { NativeArray <float3> .Copy(vertices, data.Vertices); NativeArray <int> .Copy(triangles, data.Triangles); if (HasNormals) { NativeArray <float3> .Copy(normals, data.Normals); } if (HasUVs) { NativeArray <float2> .Copy(uvs, data.UVs); } data.UpdateMesh(mesh, MeshData.UpdateMode.Clear); } Dispose(); }
internal void AddMobsToSystem(int mobCnt) { movementJH.Complete(); if (!taa_mobs.isCreated) { taa_mobs = new TransformAccessArray(0); } if (na_mobStates == null || !na_mobStates.IsCreated) { na_mobStates = new NativeArray <MobState>(0, Allocator.Persistent); } if (!nl_startPos.IsCreated) { nl_startPos = new NativeList <Vector3>(Allocator.Persistent); } if (!nl_targetPos.IsCreated) { nl_targetPos = new NativeList <Vector3>(Allocator.Persistent); } int oldMobCnt = PoolManager.instance.MobPool.m_cnt - mobCnt; for (int i = 0; i < mobCnt; ++i) { var startPos = GameManager.instance.GetSpawnPosFromStart(GameManager.instance.m_defaultSpawnPos, oldMobCnt + i, 2.0f); var SpawnedMob = PoolManager.instance.MobPool.SpawnObject(startPos, Quaternion.identity) as MobFightComponent; taa_mobs.Add(SpawnedMob.transform); nl_startPos.Add(startPos); nl_targetPos.Add(new Vector3(startPos.x, startPos.y, GameManager.instance.Target.transform.position.z)); } if (na_mobStates.Length > 0) { var tempMobState = new NativeArray <MobState>(na_mobStates, Allocator.Temp); na_mobStates.Dispose(); na_mobStates = new NativeArray <MobState>(tempMobState.Length + mobCnt, Allocator.Persistent); NativeArray <MobState> .Copy(tempMobState, 0, na_mobStates, 0, tempMobState.Length); } else { na_mobStates.Dispose(); na_mobStates = new NativeArray <MobState>(mobCnt, Allocator.Persistent); } for (int i = oldMobCnt; i < na_mobStates.Length; ++i) { na_mobStates[i] = MobState.ToTarget; } if (PoolManager.instance.SpearPool.m_cnt < PoolManager.instance.MobPool.m_cnt) { int diff = PoolManager.instance.MobPool.m_cnt - PoolManager.instance.SpearPool.m_cnt; AddSpearsToSystem(diff); } }
protected override void OnUpdate() { var currentTime = UTJ.Time.GetCurrent(); _material.SetFloat(MaterialCurrentTime, currentTime); Sync(); var batchMatrices = _distortionSystem.BatchMatrices; int num = batchMatrices.Length; var matrices = batchMatrices.AsArray(); int idx = 0; while (num > 0) { int cnum = num >= Cv.InstanceLimit ? Cv.InstanceLimit : num; NativeArray <Matrix4x4> .Copy(matrices, idx *Cv.InstanceLimit, _matricesInRenderer[idx], 0 /* dstIndex */, cnum); Graphics.DrawMeshInstanced(_mesh, 0, _material, _matricesInRenderer[idx], cnum, null, ShadowCastingMode.Off, false /* receive shadows */, 0 /* layer */, null /* camera */, LightProbeUsage.BlendProbes, null /* lightProbeProxyVolume */); num -= cnum; ++idx; } }
public virtual void Upload(float[] data, TensorShape shape, int managedBufferStartIndex = 0) { var numItemToCopy = shape.length; var numItemAvailableInData = data.Length - managedBufferStartIndex; Assert.IsTrue(managedBufferStartIndex >= 0); Assert.IsTrue(numItemToCopy <= numItemAvailableInData); int w = Mathf.Min(shape.length, MaxTextureSize); int h = Mathf.Max(1, ComputeHelper.IDivC(shape.length, w)); Texture2D texture = new Texture2D(w, h, TextureFormat.RFloat, false); var textureData = texture.GetRawTextureData <float>(); unsafe { UnsafeUtility.MemSet(textureData.GetUnsafePtr(), 0, sizeof(float) * (textureData.Length)); } NativeArray <float> .Copy(data, managedBufferStartIndex, textureData, 0, shape.length); texture.Apply(); Material material = new Material(PixelShaderSingleton.Instance.FindShader("Barracuda/BufferToTensor")); material.SetTexture("Xtex2D", texture); material.SetInt("_InputWidth", w); material.SetInt("_InputHeight", h); material.SetVector("OdeclShape", new Vector4(shape.batch, shape.height, shape.width, shape.channels)); Graphics.Blit(null, m_BufferAsTexture, material); m_AsyncDownloadSchedulingFrame = -1; }
internal void AddSpearsToSystem(int spearCnt) { spearMovementJH.Complete(); if (!taa_spears.isCreated) { taa_spears = new TransformAccessArray(0); } if (!na_spearVelocities.IsCreated) { na_spearVelocities = new NativeArray <Vector3>(0, Allocator.Persistent); } if (!na_spearState.IsCreated) { na_spearState = new NativeArray <SpearState>(0, Allocator.Persistent); } PoolManager.instance.SpearPool.Expand(spearCnt); int oldMobCnt = PoolManager.instance.SpearPool.m_cnt - spearCnt; for (int i = 0; i < spearCnt; ++i) { taa_spears.Add(PoolManager.instance.SpearPool.GetAt(oldMobCnt + i).transform); } if (na_spearVelocities.Length > 0) { var tempSpearVelocities = new NativeArray <Vector3>(na_spearVelocities, Allocator.Temp); na_spearVelocities.Dispose(); na_spearVelocities = new NativeArray <Vector3>(tempSpearVelocities.Length + spearCnt, Allocator.Persistent); NativeArray <Vector3> .Copy(tempSpearVelocities, 0, na_spearVelocities, 0, tempSpearVelocities.Length); } else { na_spearVelocities.Dispose(); na_spearVelocities = new NativeArray <Vector3>(spearCnt, Allocator.Persistent); } if (na_spearState.Length > 0) { var tempSpearActive = new NativeArray <SpearState>(na_spearState, Allocator.Temp); na_spearState.Dispose(); na_spearState = new NativeArray <SpearState>(tempSpearActive.Length + spearCnt, Allocator.Persistent); NativeArray <SpearState> .Copy(tempSpearActive, 0, na_spearState, 0, tempSpearActive.Length); } else { na_spearState.Dispose(); na_spearState = new NativeArray <SpearState>(spearCnt, Allocator.Persistent); } for (int i = oldMobCnt; i < na_spearState.Length; ++i) { na_spearState[i] = SpearState.Inactive; } }
public NativeArray <Tile> ReadAllTiles(Allocator allocator) { NativeArray <Tile> output = new NativeArray <Tile>(_tiles.Length, allocator); NativeArray <Tile> .Copy(_tiles, output); return(output); }
public static T[] ToArray <T>(this NativeArray <T> arr, int length) where T : unmanaged { var dst = new T[length]; NativeArray <T> .Copy(arr, dst, length); return(dst); }
public static T[] ToArray <T>(NativeArray <T> src, int length) where T : struct { var dst = new T[length]; NativeArray <T> .Copy(src, dst, length); return(dst); }
void ProcessReadbackRequests() { foreach (var capture in CaptureList) { if (capture.Request.hasError) { AvailableGpuDataArrays.Add(capture.GpuData); Debug.Log("Failed to read GPU texture"); } else if (capture.Request.done) { if (Bridge != null && Bridge.Status == Status.Connected) { // TODO: Remove the following two lines of extra memory copy, when we can use // AsyncGPUReadback.RequestIntoNativeArray. var data = capture.Request.GetData <byte>(); NativeArray <byte> .Copy(data, capture.GpuData, data.Length); var imageData = new ImageData() { Name = Name, Frame = Frame, Width = Width, Height = Height, Sequence = Sequence, }; if (!JpegOutput.TryTake(out imageData.Bytes)) { imageData.Bytes = new byte[MaxJpegSize]; } Tasks.Enqueue(Task.Run(() => { imageData.Length = JpegEncoder.Encode(capture.GpuData, Width, Height, 4, JpegQuality, imageData.Bytes); if (imageData.Length > 0) { imageData.Time = capture.CaptureTime; ImageWriter.Write(imageData); } else { Debug.Log("Compressed image is empty, length = 0"); } JpegOutput.Add(imageData.Bytes); AvailableGpuDataArrays.Add(capture.GpuData); })); Sequence++; } else { AvailableGpuDataArrays.Add(capture.GpuData); } } } CaptureList.RemoveAll(capture => capture.Request.done == true); }