Example #1
0
        public void Enqueue(T value)
        {
            if (!isCreated)
            {
                return;
            }
            if (nodes.Length <= 0)
            {
                for (int i = 0; i < capacity; ++i)
                {
                    void *ptr = MUnsafeUtility.Malloc(sizeof(T) + sizeof(ulong), queueData->alloc);
                    UnsafeUtility.MemClear(ptr, sizeof(T) + sizeof(ulong));
                    nodes.Add((ulong)ptr);
                }
            }

            void *nodePtr = (void *)nodes[nodes.Length - 1];

            *(T *)nodePtr = value;
            nodes.RemoveLast();
            if (queueData->length <= 0)
            {
                queueData->startNode = nodePtr;
                queueData->endNode   = nodePtr;
            }
            else
            {
                ref void *lastNodeNextPos = ref Node.GetNext(queueData->endNode);
                lastNodeNextPos    = nodePtr;
                queueData->endNode = nodePtr;
            }
        public int GetTex(int4x4 guidValue, bool isNormal = false)
        {
            AssetReference guid = clusterRes.GetReference(ref guidValue);
            int            index;

            if (guidToIndex.TryGetValue(guid, out index))
            {
                usageCount[index]++;
            }
            else
            {
                if (indexPool.Length <= 0)
                {
                    Debug.Log("Texture Pool out of Range!!");
                    return(0);
                }
                index = indexPool[indexPool.Length - 1];
                indexPool.RemoveLast();
                usageCount[index] = 1;
                guidToIndex.Add(guid, index);
                clusterRes.AddLoadCommand(guid, rt, index, isNormal);
                //TODO
                //Streaming Load Texture
            }

            return(index);
        }
Example #3
0
            public int GetLightmapIndex(string guid, out bool alreadyContained)
            {
                if (lightmapDict.ContainsKey(guid) && lightmapDict[guid].usedCount > 0)
                {
                    TextureIdentifier ident = lightmapDict[guid];
                    ident.usedCount++;
                    lightmapDict[guid] = ident;
                    alreadyContained   = true;
                    return(ident.belonged);
                }
                else
                {
                    TextureIdentifier ident;
                    ident.usedCount = 1;
                    if (avaiableLightmap.Length <= 0)
                    {
                        throw new Exception("No available lightmap lefted!");
                    }
                    ident.belonged = avaiableLightmap[avaiableLightmap.Length - 1];

                    avaiableLightmap.RemoveLast();
                    lightmapDict[guid] = ident;
                    alreadyContained   = false;
                    return(ident.belonged);
                }
            }
Example #4
0
            public int GetIndex(string guid, out bool alreadyContained)
            {
                if (string.IsNullOrEmpty(guid))
                {
                    alreadyContained = false;
                    return(-1);
                }

                if (texDict.ContainsKey(guid) && texDict[guid].usedCount > 0)
                {
                    TextureIdentifier ident = texDict[guid];
                    ident.usedCount++;
                    texDict[guid]    = ident;
                    alreadyContained = true;
                    return(ident.belonged);
                }
                else
                {
                    TextureIdentifier ident;
                    ident.usedCount = 1;
                    if (avaiableTexs.Length <= 0)
                    {
                        throw new Exception("No available texture lefted!");
                    }
                    ident.belonged = avaiableTexs[avaiableTexs.Length - 1];

                    avaiableTexs.RemoveLast();
                    texDict[guid]    = ident;
                    alreadyContained = false;
                    return(ident.belonged);
                }
            }
        public int GetTex(AssetReference guid)
        {
            int index;

            if (guidToIndex.TryGetValue(guid, out index))
            {
                usageCount[index]++;
            }
            else
            {
                if (indexPool.Length <= 0)
                {
                    throw new Exception("Texture Pool out of Range!!");
                }
                index = indexPool[indexPool.Length - 1];
                indexPool.RemoveLast();
                usageCount[index] = 1;
                guidToIndex.Add(guid, index);
                clusterRes.AddLoadCommand(guid, rt, index, isNormal);
                //TODO
                //Streaming Load Texture
            }

            return(index);
        }
        public int GetTex(string guid)
        {
            int index;

            if (guidToIndex.TryGetValue(guid, out index))
            {
                usageCount[index]++;
            }
            else
            {
                if (indexPool.Length <= 0)
                {
                    throw new Exception("Texture Pool out of Range!!");
                }
                index = indexPool[indexPool.Length - 1];
                indexPool.RemoveLast();
                usageCount[index] = 1;
                guidToIndex.Add(guid, index);
                msb.Clear();
                msb.Add(ClusterMatResources.texturePath);
                msb.Add(guid);
                msb.Add(".mtex");
                streamer.AddStreamingCommand(msb.str, rt, index, streamingIndex);
                //TODO
                //Streaming Load Texture
            }

            return(index);
        }
Example #7
0
        private void OnDestroy()
        {
            Decal lastDec = MUnsafeUtility.GetObject <Decal>(decalDatas[decalDatas.Length - 1].comp);

            lastDec.index     = index;
            decalDatas[index] = decalDatas[decalDatas.Length - 1];
            decalDatas.RemoveLast();
        }
Example #8
0
        private void OnDisable()
        {
            *container = allVolumes[allVolumes.Length - 1];
            FogVolumeComponent lastComp = MUnsafeUtility.GetObject <FogVolumeComponent>(container->light);

            lastComp.container = container;
            allVolumes.RemoveLast();
        }
        private void OnDisable()
        {
            allVolumes[index] = allVolumes[allVolumes.Length - 1];
            FogVolumeComponent lastComp = MUnsafeUtility.GetObject <FogVolumeComponent>(allVolumes[index].light);

            lastComp.index = index;
            allVolumes.RemoveLast();
        }
Example #10
0
        public NativeArray <int> SetMaterials(int count)
        {
            NativeArray <int> indexArray = new NativeArray <int>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

            for (int i = 0; i < indexArray.Length; ++i)
            {
                indexArray[i] = indexPool[indexPool.Length - i - 1];
            }
            indexPool.RemoveLast(indexArray.Length);
            return(indexArray);
        }
Example #11
0
        void Remove(NativeList <int> removeCommands)
        {
            int removeCount = removeCommands.Length;
            int newCount    = loadedBufferList.Length - removeCount;

            for (int i = 0; i < removeCommands.Length; ++i)
            {
                ref int index = ref removeCommands[i];
                if (index >= loadedBufferList.Length || index < 0)
                {
                    index = removeCommands[removeCommands.Length - 1];
                    removeCommands.RemoveLast();
                    --i;
                }
                else if (index >= newCount)
                {
                    loadedBufferList[index].scale = 0;
                    index = removeCommands[removeCommands.Length - 1];
                    removeCommands.RemoveLast();
                    --i;
                }
            }
 public NativeArray<uint> GetPropertyIndex(int count)
 {
     if (count > avaiableProperties.Length) throw new Exception("Property pool is gone!");
     NativeArray<uint> properties = new NativeArray<uint>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
     uint* ptr = properties.Ptr();
     int last = avaiableProperties.Length - 1;
     for (int i = 0; i < count; ++i)
     {
         ptr[i] = (uint)avaiableProperties[last - i];
     }
     avaiableProperties.RemoveLast(count);
     return properties;
 }
Example #13
0
 public bool Get(out int t)
 {
     do
     {
         if (arrayPool.Length <= 0)
         {
             t = -1;
             return(false);
         }
         t = arrayPool[arrayPool.Length - 1];
         arrayPool.RemoveLast();
     } while (marks[t]);
     marks[t] = true;
     return(true);
 }
            public int Get()
            {
                int t;

                do
                {
                    if (arrayPool.Length <= 0)
                    {
                        return(-1);
                    }
                    t = arrayPool[arrayPool.Length - 1];
                    arrayPool.RemoveLast();
                } while (marks[t]);
                marks[t] = true;
                return(t);
            }
        private void DeleteAsync()
        {
            int  targetListLength = pointerContainer.Length - indicesBuffer.Length;
            int *indicesPtr       = indicesBuffer.Ptr();
            int  currentIndex     = pointerContainer.Length - 1;

            for (int i = 0; i < indicesBuffer.Length; ++i)
            {
                if (indicesPtr[i] >= targetListLength)
                {
                    indicesPtr[i] = -1;
                    pointerContainer[indicesPtr[i]] = 0;
                }
            }

            for (int i = 0; i < indicesBuffer.Length; ++i)
            {
                int index = indicesPtr[i];
                if (index >= 0)
                {
                    while (currentIndex >= 0 && pointerContainer[currentIndex] == 0)
                    {
                        currentIndex--;
                    }
                    if (currentIndex < 0)
                    {
                        goto FINALIZE;
                    }
                    Vector2Int value = new Vector2Int(index, currentIndex);
                    currentIndex--;
                    results[resultLength]             = value;
                    pointerContainer[value.x]         = pointerContainer[value.y];
                    *(int *)pointerContainer[value.x] = value.x;
                    resultLength += 1;
                }
            }
FINALIZE:
            pointerContainer.RemoveLast(indicesBuffer.Length);
            lock (commandQueue)
            {
                commandQueue.Queue(deleteCommand);
            }
        }
Example #16
0
        private void ReadBack(AsyncGPUReadbackRequest request)
        {
            NativeArray <float3x3> values = request.GetData <float3x3>();

            finalData.AddRange(values.Ptr(), values.Length);
            int start = finalData.Length - values.Length;

            finalData[start] /= values.Length;
            for (int i = start; i < finalData.Length; ++i)
            {
                finalData[start] += finalData[i] / values.Length;
            }
            finalData.RemoveLast(values.Length - 1);
            count++;
            if (count >= resolution.x * resolution.y * resolution.z)
            {
                DisposeBake();
            }
        }
Example #17
0
        public void AddQuadTrees(NativeList <ulong> addList, NativeArray <float> heightMap)
        {
            TerrainQuadTree.QuadTreeNode **tree = (TerrainQuadTree.QuadTreeNode * *)addList.unsafePtr;
            int length = addList.Length;
            NativeArray <TerrainPanel> panel = new NativeArray <TerrainPanel>(length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
            TerrainPanel *panelPtr           = panel.Ptr();

            for (int i = 0; i < length; ++i)
            {
                tree[i]->listPosition = referenceBuffer.Length + i;
                int heightIndex = notUsedHeightmapIndices[notUsedHeightmapIndices.Length - 1];
                tree[i]->panel.heightMapIndex = heightIndex;
                notUsedHeightmapIndices.RemoveLast();
                heightMapBuffer.SetData(heightMap, 0, heightIndex * (meshSize + 1) * (meshSize + 1), heightMap.Length);
                panelPtr[i] = tree[i]->panel;
            }
            clusterBuffer.SetData(panel, 0, referenceBuffer.Length, length);
            panel.Dispose();
            referenceBuffer.AddRange(addList);
        }
Example #18
0
        public void RemoveQuadTrees(NativeList <ulong> removeList)
        {
            void ErasePoint(TerrainQuadTree.QuadTreeNode *node)
            {
                node->listPosition = -1;
                notUsedHeightmapIndices.Add(node->panel.heightMapIndex);
            }

            int length = removeList.Length;

            TerrainQuadTree.QuadTreeNode **tree = (TerrainQuadTree.QuadTreeNode * *)removeList.unsafePtr;
            int targetLength = referenceBuffer.Length - length;
            int len          = 0;

            if (targetLength <= 0)
            {
                for (int i = 0; i < length; ++i)
                {
                    ErasePoint(tree[i]);
                }
                referenceBuffer.Clear();
                return;
            }
            for (int i = 0; i < length; ++i)
            {
                TerrainQuadTree.QuadTreeNode *currentNode = tree[i];
                if (currentNode->listPosition >= targetLength)
                {
                    referenceBuffer[currentNode->listPosition] = 0;
                    ErasePoint(currentNode);
                }
            }
            NativeArray <int2> transformList = new NativeArray <int2>(length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
            int2 *transformPtr = transformList.Ptr();

            len = 0;
            int currentIndex = referenceBuffer.Length - 1;

            for (int i = 0; i < length; ++i)
            {
                TerrainQuadTree.QuadTreeNode *treeNode = tree[i];
                if (treeNode->listPosition < 0)
                {
                    continue;
                }
                while (referenceBuffer[currentIndex] == 0)
                {
                    currentIndex--;
                    if (currentIndex < 0)
                    {
                        goto FINALIZE;
                    }
                }
                TerrainQuadTree.QuadTreeNode *lastNode = (TerrainQuadTree.QuadTreeNode *)referenceBuffer[currentIndex];
                currentIndex--;
                transformPtr[len] = new int2(treeNode->listPosition, lastNode->listPosition);
                len++;
                lastNode->listPosition = treeNode->listPosition;
                referenceBuffer[lastNode->listPosition] = (ulong)lastNode;
                ErasePoint(treeNode);
            }
FINALIZE:
            referenceBuffer.RemoveLast(length);
            if (len <= 0)
            {
                return;
            }
            if (len > removebuffer.count)
            {
                removebuffer.Dispose();
                removebuffer = new ComputeBuffer(len, sizeof(int2));
            }
            removebuffer.SetData(transformList, 0, 0, len);
            transformShader.SetBuffer(0, ShaderIDs._IndexBuffer, removebuffer);
            transformShader.SetBuffer(0, ShaderIDs.clusterBuffer, clusterBuffer);
            ComputeShaderUtility.Dispatch(transformShader, 0, len, 64);
            transformList.Dispose();
        }