コード例 #1
0
            internal unsafe void Initialize()
            {
                brushIDValues            = new NativeList <CompactNodeID>(1000, Allocator.Persistent);
                allKnownBrushMeshIndices = new NativeHashSet <int>(1000, Allocator.Persistent);

                // TODO: not used??
                brushTreeSpaceBoundLookup = new NativeHashMap <CompactNodeID, ChiselAABB>(1000, Allocator.Persistent);
                brushRenderBufferLookup   = new NativeHashMap <CompactNodeID, ChiselBlobAssetReference <ChiselBrushRenderBuffer> >(1000, Allocator.Persistent);

                // brushIndex
                basePolygonCache           = new NativeList <ChiselBlobAssetReference <BasePolygonsBlob> >(1000, Allocator.Persistent);
                brushTreeSpaceBoundCache   = new NativeList <ChiselAABB>(1000, Allocator.Persistent);
                treeSpaceVerticesCache     = new NativeList <ChiselBlobAssetReference <BrushTreeSpaceVerticesBlob> >(1000, Allocator.Persistent);
                routingTableCache          = new NativeList <ChiselBlobAssetReference <RoutingTable> >(1000, Allocator.Persistent);
                brushTreeSpacePlaneCache   = new NativeList <ChiselBlobAssetReference <BrushTreeSpacePlanes> >(1000, Allocator.Persistent);
                brushesTouchedByBrushCache = new NativeList <ChiselBlobAssetReference <BrushesTouchedByBrush> >(1000, Allocator.Persistent);
                transformationCache        = new NativeList <NodeTransformations>(1000, Allocator.Persistent);
                brushRenderBufferCache     = new NativeList <ChiselBlobAssetReference <ChiselBrushRenderBuffer> >(1000, Allocator.Persistent);

                parameters = new NativeArray <ChiselLayerParameters>(SurfaceLayers.ParameterCount, Allocator.Persistent);
                // Regular index operator will return a copy instead of a reference *sigh*
                var parameterPtr = parameters.GetUnsafePtr();

                for (int i = 0; i < parameters.Length; i++)
                {
                    ref var parameter = ref UnsafeUtility.ArrayElementAsRef <ChiselLayerParameters>(parameterPtr, i);
                    parameter.Initialize();
                    Debug.Assert(parameter.IsCreated);
                }
コード例 #2
0
            public static unsafe void Execute(ref JobNativeMultiHashMapVisitKeyMutableValueProducer <TJob, TKey, TValue> producer, IntPtr additionalPtr, IntPtr bufferRangePatchData, ref JobRanges ranges, int jobIndex)
            {
                while (true)
                {
                    int begin;
                    int end;

                    if (!JobsUtility.GetWorkStealingRange(ref ranges, jobIndex, out begin, out end))
                    {
                        return;
                    }

                    var bucketData = producer.HashMap.GetUnsafeBucketData();
                    var buckets    = (int *)bucketData.buckets;
                    var nextPtrs   = (int *)bucketData.next;
                    var keys       = bucketData.keys;
                    var values     = bucketData.values;

                    for (int i = begin; i < end; i++)
                    {
                        int entryIndex = buckets[i];

                        while (entryIndex != -1)
                        {
                            var key = UnsafeUtility.ReadArrayElement <TKey>(keys, entryIndex);

                            producer.JobData.ExecuteNext(key, ref UnsafeUtility.ArrayElementAsRef <TValue>(values, entryIndex));

                            entryIndex = nextPtrs[entryIndex];
                        }
                    }
                }
            }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public ref T ElementAt(int index)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.CheckWriteAndThrow(m_Safety);
#endif
            CheckIndexInRange(index, m_ListData->Length);
            return ref UnsafeUtility.ArrayElementAsRef<T>(m_ListData->Ptr, index);
        }
コード例 #4
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            var random          = new Unity.Mathematics.Random(RandomSeed);
            var index           = chunk.GetSharedComponentIndex(SpriteAnimationChunkType);
            var spriteAnimation = UniqueSpriteAnimations[index];
            var entities        = chunk.GetNativeArray(EntityChunkType);
            var states          = chunk.GetNativeArray(SpriteAnimationStateChunkType).GetUnsafePtr();
            var randomizers     = chunk.GetNativeArray(SpriteAnimationRandomizerChunkType);

            for (var i = 0; i < chunk.Count; ++i)
            {
                spriteAnimation.ClipIndex = random.NextInt(0, spriteAnimation.ClipCount);
                SpriteAnimationMap.TryAdd(entities[i], spriteAnimation);
                UnsafeUtility.ArrayElementAsRef <SpriteAnimationTimeSpeedState>(states, i).Speed =
                    random.NextFloat(randomizers[i].RandomSpeedStart, randomizers[i].RandomSpeedEnd);
            }
        }
コード例 #5
0
ファイル: Curves.cs プロジェクト: Simoyd/com.unity.kinematica
 public ref       Keyframe this[int index] => ref UnsafeUtility.ArrayElementAsRef <Keyframe>(array, index);
コード例 #6
0
ファイル: CullingSystem.cs プロジェクト: theor/Automation
        protected override unsafe void OnUpdate()
        {
            _renderedItemPositionComputationSystem.SetupDependency.Complete();
            if (!RenderedItemCount.IsCreated)
            {
                RenderedItemCount = new NativeArray <int>(ItemTypes, Allocator.Persistent);
            }
            else
            {
                for (var index = 0; index < RenderedItemCount.Length; index++)
                {
                    RenderedItemCount[index] = 0;
                }
            }

            var countPtr = (int *)RenderedItemCount.GetUnsafePtr();
            var camera   = Camera.main;
            var camPos   = camera.transform.position;

            camera.CalculateFrustumCorners(new Rect(0, 0, 1, 1), camera.farClipPlane, Camera.MonoOrStereoscopicEye.Mono, _corners);
            for (int i = 0; i < 4; i++)
            {
                var worldSpaceCorner = camera.transform.TransformVector(_corners[i]);
                Debug.DrawRay(camPos, worldSpaceCorner, Color.blue);
            }

            var cullingPlanes = _cameraPlanes;

            FrustumPlanes.FromCamera(camera, cullingPlanes);
            Dependency = Entities.ForEach((DynamicBuffer <BeltItem> items, ref BeltSegment s) =>
            {
                var sAABB  = s.AABB;
                s.Rendered = FrustumPlanes.Intersect(cullingPlanes, sAABB) != FrustumPlanes.IntersectResult.Out;
                if (s.Rendered)
                {
                    int *counts = stackalloc int[2];
                    UnsafeUtility.MemClear(counts, UnsafeUtility.SizeOf <int>() * ItemTypes);

                    for (int i = 0; i < items.Length; i++)
                    {
                        counts[items[i].Type - ItemType.PaintBucket]++;
                    }

                    for (int i = 0; i < ItemTypes; i++)
                    {
                        Interlocked.Add(ref UnsafeUtility.ArrayElementAsRef <int>(countPtr, i), counts[i]);
                    }
                }
            })
                         .WithNativeDisableUnsafePtrRestriction(countPtr)
                         .WithNativeDisableParallelForRestriction(cullingPlanes)
                         .ScheduleParallel(Dependency);
            var countPtr2 = (int *)RenderedItemCount.GetUnsafePtr();

            CountDependency = Dependency = Entities.ForEach((ref BeltSplitter s) =>
            {
                var sAABB  = s.AABB;
                s.Rendered = FrustumPlanes.Intersect(cullingPlanes, sAABB) != FrustumPlanes.IntersectResult.Out;
                if (s.Rendered)
                {
                    int *counts = stackalloc int[2];
                    UnsafeUtility.MemClear(counts, UnsafeUtility.SizeOf <int>() * 2);

                    if (s.Input.Type != ItemType.None)
                    {
                        counts[s.Input.Type - ItemType.PaintBucket]++;
                    }
                    if (s.Output1.Type != ItemType.None)
                    {
                        counts[s.Output1.Type - ItemType.PaintBucket]++;
                    }
                    if (s.Output2.Type != ItemType.None)
                    {
                        counts[s.Output2.Type - ItemType.PaintBucket]++;
                    }
                    for (int i = 0; i < 2; i++)
                    {
                        Interlocked.Add(ref UnsafeUtility.ArrayElementAsRef <int>(countPtr2, i), counts[i]);
                    }
                }
            })
                                           .WithNativeDisableUnsafePtrRestriction(countPtr2)
                                           .WithNativeDisableParallelForRestriction(cullingPlanes)
                                           .ScheduleParallel(Dependency);
        }
コード例 #7
0
 public ref            T this[int index] => ref UnsafeUtility.ArrayElementAsRef <T>((byte *)m_OffsetPtr + *m_OffsetPtr, index);