예제 #1
0
    public void ConvertAllToBlockVectors()
    {
        List <BlockVectorNode> chunksToConvert = new List <BlockVectorNode>();

        foreach (KeyValuePair <IntVector4, B45ChunkData> kvp in _chunks)
        {
            BlockVectorNode bvNode = kvp.Value._bvNode;
            if (bvNode == null)
            {
                Debug.LogError("node null!");
            }
            chunksToConvert.Add(bvNode);
        }
        for (int i = 0; i < chunksToConvert.Count; i++)
        {
            BlockVectorNode bvNode = chunksToConvert[i];
            B45ChunkData    cd     = bvNode.chunk;
            // convert the chunk data from byte array mode to block vector mode
            //if((cd.d_state & B45ChunkData.DS_BEING_DESTROYED) > 0)
            if (cd != null)
            {
                cd.bp();
                bvNode.blockVectors = BlockVectorNode.ChunkData2BlockVectors(cd.DataVT);
            }
        }
    }
예제 #2
0
    void deferredRemoval()
    {
        for (int i = deferredRemoveList.Count - 1; i >= 0; i--)
        {
            B45ChunkData cd = deferredRemoveList[i];
            cd.bp();
//			if(colliderMan.isColliderBeingRebuilt(cd.ChunkPos.XYZ)){
//				Debug.LogError("the replacement collider is not done rebuilding.");
//			}
            if (cd != null && cd.isInQueue == false && colliderMan.isColliderBeingRebuilt(cd.ChunkPos.XYZ) == false)
            {
                cd.bp();
                if (_chunks.Remove(new IntVector4(cd.ChunkPos.XYZ, 0)) == false)
                {
                    Debug.LogError("a chunk can not be removed from the dictionary");
                }
                cd.ClearMem();
                cd.DestroyChunkGO();
                deferredRemoveList.RemoveAt(i);
            }
        }
    }
예제 #3
0
    B45ChunkData CreateChunk(IntVector4 index)
    {
        B45ChunkData chunk = new B45ChunkData(colliderMan);

        chunk.BuildList = _chunkRebuildList;
        writeChunk(index.x, index.y, index.z, chunk);

        chunk.ChunkPosLod_w = new IntVector4(
            (index.x),
            (index.y),
            (index.z), 0);
        chunk.bp();
        chunk.AddToBuildList();

        // make the bv node.
        if (true)
        {
            IntVector3 shiftVec = IntVector3.Zero;
            shiftVec.x = index.x << Block45Constants._shift;
            shiftVec.y = index.y << Block45Constants._shift;
            shiftVec.z = index.z << Block45Constants._shift;

            try{                // Add try for StackOverflowException
                BlockVectorNode newRootNode = bvtRoot.reroot(shiftVec);
                bvtRoot = newRootNode;
            }
            catch (Exception e)
            {
                Debug.LogWarning("Unexpected exception while creating chunk to" + index + e);
                return(chunk);
            }

            BlockVectorNode bvNode = BlockVectorNode.readNode(shiftVec, bvtRoot);
            if (bvNode.chunk != null)
            {
                // already a chunk has been assigned to this node. something is wrong here.
                return(chunk);
            }
            bvNode.chunk           = chunk;
            chunk._bvNode          = bvNode;
            bvNode.isByteArrayMode = true;
        }


        return(chunk);
    }
예제 #4
0
    public void OctreeUpdate(IntVector3 cursorPos)
    {
        List <BlockVectorNode> blkNodeToConv = new List <BlockVectorNode>();

        // check if there are block vector nodes that should be converted into lod chunks.
//		BlockVectorNode.rec_findLod(cursorPos, bvtRoot, blkNodeToConv);
//		for(int i = 0; i < blkNodeToConv.Count; i++){
//			BlockVectorNode bvNode = blkNodeToConv[i];
//
//			// shift xyz
//			IntVector4 shiftXYZ = IntVector4.Zero;
//			shiftXYZ.x = bvNode.Pos.x >> Block45Constants._shift;
//			shiftXYZ.y = bvNode.Pos.y >> Block45Constants._shift;
//			shiftXYZ.z = bvNode.Pos.z >> Block45Constants._shift;
//			shiftXYZ.w = bvNode.Pos.w;
//
//
//			if(!_chunks.ContainsKey(shiftXYZ) )
//			{
//
//				B45ChunkData newChunk = CreateChunk(shiftXYZ);
//
//				bvNode.chunk = newChunk;
//				newChunk._bvNode = bvNode;
//
//				_chunks[shiftXYZ] = newChunk;
//				newChunk.bp();
//			}
//			if(bvNode.blockVectors != null && bvNode.chunk != null){
//				bvNode.chunk.bp();
//				try
//				{
//				BlockVectorNode.BlockVectors2ChunkData(bvNode.blockVectors, bvNode.chunk.DataVT);
//				}
//				catch(Exception ex){
//					int sdkf = 0;
//				}
//				bvNode.blockVectors.Clear();
//				bvNode.blockVectors = null;
//			}
//		}

        // check if there are block vector nodes that should be converted into real chunks(byte array mode).
        BlockVectorNode.rec_find(cursorPos, bvtRoot, blkNodeToConv);

//		for(int i = 0; i < blkNodeToConv.Count; i++){
////			blkNodeToConv[i].makeCube();
//		}
////		B45LODNode.makeCubeRec(bvtRoot as B45LODNode);

        int elementCount1   = 0;
        int fills1          = 0;
        int fillsIn_Chunks1 = 0;

        if (b45Building.DebugMode)
        {
            elementCount1   = BlockVectorNode.rec_count(bvtRoot);
            fills1          = BlockVectorNode.rec_count_dbg(bvtRoot);
            fillsIn_Chunks1 = countpoints();
        }
        for (int i = 0; i < blkNodeToConv.Count; i++)
        {
            BlockVectorNode bvNode = blkNodeToConv[i];

            // shift xyz
            IntVector4 shiftXYZ = IntVector4.Zero;
            shiftXYZ.x = bvNode.Pos.x >> Block45Constants._shift;
            shiftXYZ.y = bvNode.Pos.y >> Block45Constants._shift;
            shiftXYZ.z = bvNode.Pos.z >> Block45Constants._shift;


            if (!_chunks.ContainsKey(shiftXYZ))
            {
                B45ChunkData newChunk = CreateChunk(shiftXYZ);

                bvNode.chunk     = newChunk;
                newChunk._bvNode = bvNode;

                _chunks[shiftXYZ] = newChunk;
                newChunk.bp();
            }
            if (bvNode.blockVectors != null && bvNode.chunk != null)
            {
                bvNode.chunk.bp();
                try
                {
                    BlockVectorNode.BlockVectors2ChunkData(bvNode.blockVectors, bvNode.chunk.DataVT);
                }
                catch {
                    //int sdkf = 0;
                }
                bvNode.blockVectors.Clear();
                bvNode.blockVectors = null;
            }
        }

        if (b45Building.DebugMode)
        {
            int elementCount2 = BlockVectorNode.rec_count(bvtRoot);

            int fills2          = BlockVectorNode.rec_count_dbg(bvtRoot);
            int fillsIn_Chunks2 = countpoints();
            Debug.LogError("B45 Octree State: " + elementCount1 + " / " + fills1 + " / " + fillsIn_Chunks1 + " ------------- " + elementCount2 + " / " + fills2 + " / " + fillsIn_Chunks2);                     // check for chunks that are out of view
        }
        //List<BlockVectorNode> bvToDispose = new List<BlockVectorNode>();
        List <B45ChunkData> cdToDispose = new List <B45ChunkData>();

        foreach (KeyValuePair <IntVector4, B45ChunkData> kvp in _chunks)
        {
            BlockVectorNode bvNode = kvp.Value._bvNode;
            B45ChunkData    cd     = kvp.Value;
            if (bvNode == null)
            {
                Debug.LogError("node null!");
            }
            if (!bvNode.isCloseTo(cursorPos)
                &&
                cd != null
                )
            {
                // this node is too far from the camera, put it in the dispose list
                cd.bp();
                cdToDispose.Add(cd);
//				_chunks.Remove(kvp.Key);
            }
        }
        for (int i = 0; i < cdToDispose.Count; i++)
        {
            B45ChunkData cd = cdToDispose[i];
            // convert the chunk data from byte array mode to block vector mode

            if (cd != null && cd.isBeingDestroyed == false)
            {
                cd.setBeingDestroyed();
                cd.bp();

                cd._bvNode.blockVectors    = BlockVectorNode.ChunkData2BlockVectors(cd.DataVT);
                cd._bvNode.isByteArrayMode = false;
                cd._bvNode.removeCube();
                // remove this chunk from memory
                cd._bvNode.chunk = null;
                deferredRemoveList.Add(cd);
            }
            else
            {
                //int sdgf = 0;
            }
        }
        deferredRemoval();
    }