Ejemplo n.º 1
0
    // Enqueue a block for meshing; inclde
    public bool Enqueue(DFCoord targetLocation, bool tiles, bool liquids)
    {
        if (!GameMap.IsBlockCorner(targetLocation))
        {
            throw new UnityException("Can't enqueue non-block-corners");
        }
        if (!tiles && !liquids)
        {
            throw new UnityException("Why mesh something without tiles or liquids?");
        }
        UnityEngine.Profiling.Profiler.BeginSample("BlockMesher.Enqueue");
        // Using our object pool
        MapDataStore targetDataStore = AllocateBlockStore();

        // Copy data
        if (!MapDataStore.Main.CopySliceTo(targetLocation, MapDataStore.BLOCK_SIZE, targetDataStore))
        {
            UnityEngine.Profiling.Profiler.EndSample();
            return(true); //it's empty, but it isn't a failure condition.
        }

        // In case we displace another block update
        Request redundant;

        lock (requestQueue)
        {
            // Will be { tiles: false, liquids: false, data: null } if we don't have anything queued
            redundant = requestQueue[targetLocation];

            //if there's no existing queue member, don't add more than needed.
            if (redundant.data == null)
            {
                if (requestQueue.Count >= 16)
                {
                    UnityEngine.Profiling.Profiler.EndSample();
                    return(false);
                }
            }

            Request meshRequest = new Request();
            // If either request wanted liquids, do liquids;
            // If either request wanted tiles, do tiles.
            meshRequest.liquids = liquids || redundant.liquids;
            meshRequest.tiles   = tiles || redundant.tiles;
            meshRequest.data    = targetDataStore;
            requestQueue.EnqueueAndDisplace(targetLocation, meshRequest);
        }
        if (redundant.data != null)
        {
            lock (recycledBlocks) {
                // Object pooling!
                recycledBlocks.Push(redundant.data);
            }
        }
        UnityEngine.Profiling.Profiler.EndSample();
        return(true);
    }
Ejemplo n.º 2
0
    // Enqueue a block for meshing; inclde
    public void Enqueue(DFCoord targetLocation, bool tiles, bool liquids)
    {
        if (!GameMap.IsBlockCorner(targetLocation))
        {
            throw new UnityException("Can't enqueue non-block-corners");
        }
        if (!tiles && !liquids)
        {
            throw new UnityException("Why mesh something without tiles or liquids?");
        }

        // Using our object pool
        MapDataStore targetDataStore = AllocateBlockStore();

        // Copy data
        MapDataStore.Main.CopySliceTo(targetLocation, MapDataStore.BLOCK_SIZE, targetDataStore);

        // In case we displace another block update
        Request redundant;

        lock (requestQueue) {
            // Will be { tiles: false, liquids: false, data: null } if we don't have anything queued
            redundant = requestQueue[targetLocation];

            Request meshRequest = new Request();
            // If either request wanted liquids, do liquids;
            // If either request wanted tiles, do tiles.
            meshRequest.liquids = liquids || redundant.liquids;
            meshRequest.tiles   = tiles || redundant.tiles;
            meshRequest.data    = targetDataStore;
            requestQueue.EnqueueAndDisplace(targetLocation, meshRequest);
        }
        if (redundant.data != null)
        {
            lock (recycledBlocks) {
                // Object pooling!
                recycledBlocks.Push(redundant.data);
            }
        }
    }