Ejemplo n.º 1
0
        //set queary
        public static int newSet(string setFilename)
        {
            int setIndex = FoliageManager.giveIndexOfSet(setFilename);

            if (setIndex == -1)
            {
                FoliageSet fs = new FoliageSet();
                fs.loadSet(setFilename + ".xml");
                mFoliageSets.Add(fs);
                setIndex = mFoliageSets.Count - 1;
            }
            return(setIndex);
        }
Ejemplo n.º 2
0
        public static void eraseSetFromMap(int setIndex)
        {
            long            id;
            FoliageVertData maskValue;

            mVertData.ResetIterator();
            while (mVertData.MoveNext(out id, out maskValue))
            {
                if (maskValue.compare(cEmptyVertData))
                {
                    continue;
                }
                if (FoliageManager.giveIndexOfSet(maskValue.mFoliageSetName) == setIndex)
                {
                    mVertData.SetValue(id, cEmptyVertData);
                }
            }
            clearAllChunkVBs();
            mFoliageSets.RemoveAt(setIndex);
        }
Ejemplo n.º 3
0
        //-------------------------------------

        public void createRenderVBs()
        {
            destroyRenderVBs();
            int width = TerrainGlobals.getTerrain().getNumXVerts();

            for (int setI = 0; setI < mSetsUsed.Count; setI++)
            {
                List <int> validIndexes      = new List <int>();
                List <int> validBladeIndexes = new List <int>();
                for (int x = 0; x < BTerrainQuadNode.cMaxWidth; x++)
                {
                    for (int z = 0; z < BTerrainQuadNode.cMaxWidth; z++)
                    {
                        int             index = (x + mOwnerNodeDesc.mMinXVert) + width * (z + mOwnerNodeDesc.mMinZVert);
                        FoliageVertData fvd   = FoliageManager.mVertData.GetValue(index);
                        if (fvd.compare(FoliageManager.cEmptyVertData))
                        {
                            continue;
                        }

                        if (FoliageManager.giveIndexOfSet(fvd.mFoliageSetName) == FoliageManager.giveIndexOfSet(mSetsUsed[setI]))
                        {
                            int localIndex = x + FoliageManager.cNumXBladesPerChunk * z;
                            validIndexes.Add(localIndex);
                            validBladeIndexes.Add(fvd.mFoliageSetBladeIndex);
                        }
                    }
                }

                if (validIndexes.Count == 0)
                {
                    //remove this set from us
                    mSetsUsed.RemoveAt(setI);
                    setI--;
                    continue;
                }

                //now that we have our valid indexes
                int numVertsPerBlade = 10;
                int totalNumVerts    = (validIndexes.Count * numVertsPerBlade);

                //VERTEX BUFFERS
                mSetVBs.Add(new VertexBuffer(typeof(VertexTypes.Pos), totalNumVerts, BRenderDevice.getDevice(), Usage.WriteOnly, VertexTypes.Pos.FVF_Flags, Pool.Default));

                GraphicsStream gStream = mSetVBs[setI].Lock(0, 0, LockFlags.None);
                unsafe
                {
                    VertexTypes.Pos *verts = (VertexTypes.Pos *)gStream.InternalDataPointer;

                    mSetVertCount.Add(0);
                    //ADD OTHER STRIPS
                    for (int i = 0; i < validIndexes.Count; i++)
                    {
                        int vC = mSetVertCount[setI];

                        int startInd = validIndexes[i] * numVertsPerBlade;
                        //add 10 verts with:  index (x*width+z), bladeIndex, 0, 0
                        for (int k = 0; k < numVertsPerBlade; k++)
                        {
                            verts[vC].x = startInd + k;
                            verts[vC].y = validBladeIndexes[i];

                            vC++;
                        }

                        mSetVertCount[setI] += numVertsPerBlade;
                    }
                }

                gStream.Close();
                mSetVBs[setI].Unlock();


                //INDEX BUFFERS (UGG WE SHOULD BE USING TRI-STRIPS!!!)
                int numInds = (validIndexes.Count * ((numVertsPerBlade - 2) * 3));
                mSetIBs.Add(new IndexBuffer(typeof(short), numInds, BRenderDevice.getDevice(), Usage.WriteOnly, Pool.Default));

                gStream = mSetIBs[setI].Lock(0, 0, LockFlags.None);
                unsafe
                {
                    short *inds = (short *)gStream.InternalDataPointer;

                    mSetPolyCount.Add(0);

                    //add first strip
                    short startInd = (short)(0);
                    int   vC       = 0;

                    for (int i = 0; i < validIndexes.Count; i++)
                    {
                        startInd = (short)(i * (numVertsPerBlade));

                        short pC = (short)((numVertsPerBlade - 2) >> 1);
                        short sI = 0;
                        for (int k = 0; k < pC; k++)
                        {
                            inds[vC++] = (short)(startInd + sI + 0);
                            inds[vC++] = (short)(startInd + sI + 1);
                            inds[vC++] = (short)(startInd + sI + 2);

                            inds[vC++] = (short)(startInd + sI + 1);
                            inds[vC++] = (short)(startInd + sI + 2);
                            inds[vC++] = (short)(startInd + sI + 3);
                            sI        += 2;
                        }


                        mSetPolyCount[setI] += (numVertsPerBlade - 2);
                    }
                }
                gStream.Close();
                mSetIBs[setI].Unlock();
            }

            //COOL!
        }