Trim() public method

public Trim ( ) : void
return void
Exemplo n.º 1
0
        public override RenderOperation[] GetRenderOperation()
        {
            if (ResVisible != null)
            {
                ResVisible(this);
            }

            opBuffer.FastClear();

            TreeBatchModel mdl = model;

            RenderOperation[] ops = mdl.GetRenderOperation();
            if (ops != null)
            {
                opBuffer.Add(ops);
            }

            if (Visiblity > 0)
            {
                ops = board.GetRenderOperation();
                if (ops != null)
                {
                    for (int i = 0; i < ops.Length; i++)
                    {
                        ops[i].Sender          = this;
                        ops[i].Transformation *= stdTransform;
                    }
                    opBuffer.Add(ops);
                }
            }


            opBuffer.Trim();
            return(opBuffer.Elements);
        }
Exemplo n.º 2
0
        public RenderOperation[] GetRenderOperation()
        {
            bool passed = false;

            opBuffer.FastClear();
            foreach (Smoke s in emitSmokes)
            {
                if (s.ReleaseTime <= 0 && s.Life > 0)
                {
                    RenderOperation[] ops = smokeModel.GetRenderOperation();
                    if (ops != null)
                    {
                        for (int i = 0; i < ops.Length; i++)
                        {
                            ops[i].Transformation = Matrix.RotationZ(s.Rotation) * Matrix.Scaling(s.Scale * 2, s.Scale * 2, s.Scale * 2);
                            ops[i].Transformation.TranslationValue = s.Position;
                        }

                        opBuffer.Add(ops);

                        passed = true;
                    }
                }
            }

            if (passed)
            {
                opBuffer.Trim();
                return(opBuffer.Elements);
            }
            return(null);
        }
Exemplo n.º 3
0
        private void CheckInitMethods()
        {
            if (isMethodsInit)
            {
                return;
            }
            lock (Environment)
            {
                if (isMethodsInit)
                {
                    return;
                }

                methods      = new Dictionary <string, FastList <CLRGeneralMethod> >();
                idToMethhods = new Dictionary <int, CLRGeneralMethod>();

                var clrMethods = typeForCLR.GetMethods();
                foreach (var clrMethod in clrMethods)
                {
                    FastList <CLRGeneralMethod> list;
                    if (!methods.TryGetValue(clrMethod.Name, out list))
                    {
                        list = new FastList <CLRGeneralMethod>();
                        methods.Add(clrMethod.Name, list);
                    }

                    var method = new CLRMethod(clrMethod, this);
                    list.Add(method);
                    idToMethhods.Add(method.GetHashCode(), method);
                }

                {
                    var list = new FastList <CLRGeneralMethod>();
                    methods.Add(ILMethod.ConstructorName, list);
                    foreach (var constructor in typeForCLR.GetConstructors())
                    {
                        var method = new CLRConstructor(constructor, this);
                        list.Add(method);
                        idToMethhods.Add(method.GetHashCode(), method);
                    }
                }

                foreach (var list in methods.Values)
                {
                    list.Trim();
                }

                isMethodsInit = true;
            }
        }
Exemplo n.º 4
0
        public RenderOperation[] GetRenderOperation()
        {
            opBuffer.FastClear();
            foreach (Smoke s in emitSmokes)
            {
                if (s.Life > 0)
                {
                    RenderOperation[] ops = smokeModel.GetRenderOperation();
                    if (ops != null)
                    {
                        for (int i = 0; i < ops.Length; i++)
                        {
                            ops[i].Transformation = Matrix.RotationZ(s.Rotation) * Matrix.Scaling(new Vector3(s.Scale));
                            ops[i].Transformation.TranslationValue = s.Position;
                        }

                        opBuffer.Add(ops);
                    }
                }
            }
            opBuffer.Trim();
            return(opBuffer.Elements);
        }
Exemplo n.º 5
0
        public override RenderOperation[] GetRenderOperation()
        {
            if (ResVisible != null)
            {
                ResVisible(this);
            }

            opBuffer.FastClear();

            if (Visiblity > 0)
            {
                RenderOperation[] ops = board.GetRenderOperation();
                if (ops != null)
                {
                    for (int i = 0; i < ops.Length; i++)
                    {
                        ops[i].Sender = this;
                    }
                    opBuffer.Add(ops);
                }
            }

            if (ModelL0 != null)
            {
                RenderOperation[] ops = ModelL0.GetRenderOperation();
                if (ops != null)
                {
                    for (int i = 0; i < ops.Length; i++)
                    {
                        ops[i].Sender = this;
                    }
                    opBuffer.Add(ops);
                }
            }
            opBuffer.Trim();
            return(opBuffer.Elements);
        }
Exemplo n.º 6
0
        protected unsafe override void load()
        {
            resourceSize = 0;

            float radlng = MathEx.Degree2Radian(info.Longitude);
            float radlat = MathEx.Degree2Radian(info.Latitude);
            float radr   = MathEx.Degree2Radian(info.Radius) * 2;

            TreeOrientation = PlanetEarth.GetOrientation(radlng, radlat);
            TreeOrientation.TranslationValue = PlanetEarth.GetPosition(radlng, radlat, PlanetEarth.PlanetRadius);


            int vtxCount   = 0;
            int vtxOffset  = 0;
            int vtxCount2  = 0;
            int vtxOffset2 = 0;

            int plantCount = (int)(info.Amount * 0.05f);



            FastList <byte> vertices2     = new FastList <byte>(plantCount * 2500);
            FastList <int>  indices2      = new FastList <int>();
            int             partVtxCount2 = 0;


            FastList <byte> vertices = new FastList <byte>(plantCount * 2500);
            Dictionary <Material, FastList <int> > indices      = new Dictionary <Material, FastList <int> >();
            Dictionary <Material, int>             partVtxCount = new Dictionary <Material, int>();

            plantCount = 0;

            byte[] vtxBldBuffer = new byte[TreeVertex.Size];

            const float AreaWidth = 0.036f;

            for (float blkLng = radlng - radr; blkLng < radlng + radr; blkLng += AreaWidth)
            {
                for (float blkLat = radlat - radr; blkLat < radlat + radr; blkLat += AreaWidth)
                {
                    float altblk = TerrainData.Instance.QueryHeight(blkLng, blkLat) - 100;

                    if (altblk < 0)
                    {
                        continue;
                    }

                    float density = PlantDensity.Instance.GetPlantDensity(blkLng, blkLat);

                    int count = (int)(density * 2.25f);

                    for (int i = 0; i < count; i++)
                    {
                        float treeLng = blkLng + AreaWidth * Randomizer.GetRandomSingle();
                        float treeLat = blkLat + AreaWidth * Randomizer.GetRandomSingle();

                        float alt = TerrainData.Instance.QueryHeight(treeLng, treeLat);

                        PlantDensityData d = PlantDensity.Instance.GetDensity(treeLng, treeLat);
                        int idx            = Randomizer.Random(d.Density, PlantDensity.TypeCount);

                        TreeModelData[] mdls     = TreeModelLibrary.Instance.Get(idx);
                        TreeModelData   meshData = mdls[Randomizer.GetRandomInt(mdls.Length)];


                        Matrix treeOrientation = PlanetEarth.GetOrientation(treeLng, treeLat);
                        treeOrientation.TranslationValue = PlanetEarth.GetPosition(treeLng, treeLat,
                                                                                   PlanetEarth.PlanetRadius + alt * TerrainMeshManager.PostHeightScale);

                        float instanceData = Randomizer.GetRandomSingle();

                        float theta  = instanceData * MathEx.PIf * 2;
                        float rotCos = (float)Math.Cos(theta);
                        float rotSin = (float)Math.Sin(theta);

                        #region 数据
                        resourceSize += meshData.VertexCount * TreeVertex.Size;
                        vtxCount     += meshData.VertexCount;

                        fixed(byte *src = &meshData.VertexData[0])
                        {
                            VertexPNT1 *ptr = (VertexPNT1 *)src;

                            for (int j = 0; j < meshData.VertexCount; j++)
                            {
                                TreeVertex p;
                                p.pos.X = rotCos * ptr[j].pos.X - rotSin * ptr[j].pos.Z;
                                p.pos.Z = rotSin * ptr[j].pos.X + rotCos * ptr[j].pos.Z;
                                p.pos.Y = ptr[j].pos.Y;

                                p.pos = p.pos * (Game.TreeScale * (instanceData * 0.4f + 0.8f));

                                Vector3 pp;
                                Vector3.TransformSimple(ref p.pos, ref treeOrientation, out pp);
                                p.pos = pp;

                                p.n.X = rotCos * ptr[j].n.X - rotSin * ptr[j].n.Z;
                                p.n.Z = rotSin * ptr[j].n.Z + rotCos * ptr[j].n.Z;
                                p.n.Y = ptr[j].n.Y;

                                p.tex1 = new Vector3(ptr[j].u, ptr[j].v, instanceData);

                                fixed(byte *dst = &vtxBldBuffer[0])
                                {
                                    Memory.Copy(&p, dst, TreeVertex.Size);
                                }

                                p.tc    = new Vector2(treeLng, treeLat);
                                p.tc.X += MathEx.PIf;
                                //p.tc.Y -= MathEx.Degree2Radian(10);

                                p.tc.X = 0.5f * p.tc.X / MathEx.PIf;
                                p.tc.Y = (-p.tc.Y + MathEx.PiOver2) / MathEx.PIf;

                                vertices.Add(vtxBldBuffer);
                            }
                        }

                        Material[] mtrls = meshData.Materials;
                        for (int k = 0; k < mtrls.Length; k++)
                        {
                            Material mtrl = mtrls[k];

                            FastList <int> idxData;
                            if (!indices.TryGetValue(mtrl, out idxData))
                            {
                                idxData = new FastList <int>(plantCount * 120);
                                indices.Add(mtrl, idxData);

                                partVtxCount.Add(mtrl, 0);
                            }

                            partVtxCount[mtrl] += meshData.PartVtxCount[k];

                            int[] meshIdx = meshData.Indices[k];

                            for (int j = 0; j < meshIdx.Length; j++)
                            {
                                idxData.Add(meshIdx[j] + vtxOffset);
                            }
                        }
                        vtxOffset += meshData.VertexCount;
                        #endregion

                        TreeModelData meshData2 = TreeModelLibrary.Instance.GetTrunk();
                        #region 树桩
                        resourceSize += meshData2.VertexCount * TreeVertex.Size;
                        vtxCount2    += meshData2.VertexCount;

                        fixed(byte *src = &meshData2.VertexData[0])
                        {
                            VertexPNT1 *ptr = (VertexPNT1 *)src;

                            for (int j = 0; j < meshData2.VertexCount; j++)
                            {
                                TreeVertex p;
                                p.pos.X = rotCos * ptr[j].pos.X - rotSin * ptr[j].pos.Z;
                                p.pos.Z = rotSin * ptr[j].pos.X + rotCos * ptr[j].pos.Z;
                                p.pos.Y = ptr[j].pos.Y;

                                p.pos = p.pos * (Game.TreeScale * (instanceData * 0.4f + 0.8f));

                                Vector3 pp;
                                Vector3.TransformSimple(ref p.pos, ref treeOrientation, out pp);
                                p.pos = pp;

                                p.n.X = rotCos * ptr[j].n.X - rotSin * ptr[j].n.Z;
                                p.n.Z = rotSin * ptr[j].n.Z + rotCos * ptr[j].n.Z;
                                p.n.Y = ptr[j].n.Y;

                                p.tex1 = new Vector3(ptr[j].u, ptr[j].v, instanceData);

                                fixed(byte *dst = &vtxBldBuffer[0])
                                {
                                    Memory.Copy(&p, dst, TreeVertex.Size);
                                }

                                vertices2.Add(vtxBldBuffer);
                            }
                        }

                        material2      = meshData2.Materials[0];
                        partVtxCount2 += meshData2.PartVtxCount[0];

                        int[] meshIdx2 = meshData2.Indices[0];

                        for (int j = 0; j < meshIdx2.Length; j++)
                        {
                            indices2.Add(meshIdx2[j] + vtxOffset2);
                        }
                        vtxOffset2 += meshData2.VertexCount;
                        #endregion
                        plantCount++;
                    }
                }
            }



            // ============================================================================

            ObjectFactory fac = renderSys.ObjectFactory;
            vtxDecl = fac.CreateVertexDeclaration(TreeVertex.Elements);
            int vtxSize = vtxDecl.GetVertexSize();

            vtxBuffer = fac.CreateVertexBuffer(vtxCount, vtxDecl, BufferUsage.Static);

            vertices.Trim();
            vtxBuffer.SetData <byte>(vertices.Elements);

            vtxBuffer2 = fac.CreateVertexBuffer(vtxCount2, vtxDecl, BufferUsage.Static);
            vertices2.Trim();
            vtxBuffer2.SetData <byte>(vertices2.Elements);

            int partCount = indices.Count;

            idxBuffer = new IndexBuffer[partCount];
            materials = new Material[partCount];
            opBuf     = new RenderOperation[partCount];

            int index = 0;

            foreach (KeyValuePair <Material, FastList <int> > e in indices)
            {
                FastList <int> list = e.Value;
                list.Trim();

                materials[index] = e.Key;
                idxBuffer[index] = fac.CreateIndexBuffer(IndexBufferType.Bit32, list.Count, BufferUsage.Static);

                idxBuffer[index].SetData <int>(list.Elements);

                resourceSize += sizeof(int) * list.Count;

                // ==============================================================================================

                opBuf[index].Material  = e.Key;
                opBuf[index].Geomentry = new GeomentryData();
                opBuf[index].Geomentry.BaseIndexStart    = 0;
                opBuf[index].Geomentry.BaseVertex        = 0;
                opBuf[index].Geomentry.IndexBuffer       = idxBuffer[index];
                opBuf[index].Geomentry.PrimCount         = idxBuffer[index].IndexCount / 3;
                opBuf[index].Geomentry.PrimitiveType     = RenderPrimitiveType.TriangleList;
                opBuf[index].Geomentry.VertexBuffer      = vtxBuffer;
                opBuf[index].Geomentry.VertexCount       = partVtxCount[e.Key];
                opBuf[index].Geomentry.VertexDeclaration = vtxDecl;
                opBuf[index].Geomentry.VertexSize        = vtxSize;
                opBuf[index].Sender = this;
                index++;
            }

            indices2.Trim();

            idxBuffer2 = fac.CreateIndexBuffer(IndexBufferType.Bit32, indices2.Count, BufferUsage.Static);
            idxBuffer2.SetData <int>(indices2.Elements);
            opbuf2              = new RenderOperation[1];
            opbuf2[0].Material  = material2;
            opbuf2[0].Geomentry = new GeomentryData();
            opbuf2[0].Geomentry.BaseIndexStart    = 0;
            opbuf2[0].Geomentry.BaseVertex        = 0;
            opbuf2[0].Geomentry.IndexBuffer       = idxBuffer2;
            opbuf2[0].Geomentry.PrimCount         = idxBuffer2.IndexCount / 3;
            opbuf2[0].Geomentry.PrimitiveType     = RenderPrimitiveType.TriangleList;
            opbuf2[0].Geomentry.VertexBuffer      = vtxBuffer2;
            opbuf2[0].Geomentry.VertexCount       = partVtxCount2;
            opbuf2[0].Geomentry.VertexDeclaration = vtxDecl;
            opbuf2[0].Geomentry.VertexSize        = vtxSize;
            opbuf2[0].Sender = this;
        }
Exemplo n.º 7
0
        public override RenderOperation[] GetRenderOperation()
        {
            // not drawing anything when in fog
            if (dockCity != null)
            {
                if (!dockCity.IsInVisibleRange)
                {
                    return(null);
                }
            }

            // normal drawing
            if (state != RBallState.AttackCity || (state == RBallState.AttackCity && speedModifier < AttackCitySpeedMod - 0.1f))
            {
                RenderOperation[] ops = base.GetRenderOperation();
                if (ops != null)
                {
                    for (int i = 0; i < ops.Length; i++)
                    {
                        //ops[i].Sender = this;
                        ops[i].Transformation = displayScale * ops[i].Transformation;
                    }
                }

                return(ops);
            }

            // add the tails to the render operation when needed, beside the normal model
            {
                opBuffer.FastClear();
                RenderOperation[] ops = base.GetRenderOperation();
                if (ops != null)
                {
                    for (int i = 0; i < ops.Length; i++)
                    {
                        //ops[i].Sender = this;
                        ops[i].Transformation = displayScale * ops[i].Transformation;
                    }
                    opBuffer.Add(ops);
                }


                Matrix trans = Transformation;
                trans.TranslationValue = dockCity.Position + Transformation.Up * currentHeight;


                Matrix invTrans = Transformation;
                invTrans.Invert();

                Matrix.Multiply(ref trans, ref invTrans, out trans);

                if (dockCity.Owner == null)
                {
                    ops = green_tail.GetRenderOperation();
                    for (int i = 0; i < ops.Length; i++)
                    {
                        ops[i].Transformation = trans * ops[i].Transformation;
                    }
                    if (ops != null)
                    {
                        opBuffer.Add(ops);
                    }
                }
                else
                {
                    ops = red_tail.GetRenderOperation();
                    if (ops != null)
                    {
                        for (int i = 0; i < ops.Length; i++)
                        {
                            ops[i].Transformation = trans * ops[i].Transformation;
                        }
                        opBuffer.Add(ops);
                    }
                }


                opBuffer.Trim();
                return(opBuffer.Elements);
            }
        }
Exemplo n.º 8
0
        public override RenderOperation[] GetRenderOperation()
        {
            opBuffer.FastClear();

            if (selectedCity != null)
            {
                if (nodes == null)
                {
                    if (selectedCity.IsCaptured && selectedCity.Owner == player)
                    {
                        for (int i = 0; i < targets.Length; i++)
                        {
                            RenderOperation[] ops = linkArrow[i].GetRenderOperation();
                            if (ops != null)
                            {
                                opBuffer.Add(ops);
                            }
                        }
                    }
                }
                else if (nodes != null)
                {
                    if (selectedCity.IsCaptured && selectedCity.Owner == player)
                    {
                        for (int i = 0; i < nodes.Length - 1; i++)
                        {
                            RenderOperation[] ops = nodeLinks[i].GetRenderOperation();
                            if (ops != null)
                            {
                                opBuffer.Add(ops);
                            }
                        }
                    }
                }
            }
            if (selectedCity != null || selectedResource != null || selectedHarv != null)
            {
                RenderOperation[] ops = inner_marker.GetRenderOperation();

                if (selectedCity != null)
                {
                    for (int i = 0; i < ops.Length; i++)
                    {
                        ops[i].Sender = selectedCity.Owner;
                    }
                }
                else if (selectedHarv != null)
                {
                    for (int i = 0; i < ops.Length; i++)
                    {
                        ops[i].Sender = selectedHarv.Parent.Owner;
                    }
                }
                else
                {
                    for (int i = 0; i < ops.Length; i++)
                    {
                        ops[i].Sender = null;
                    }
                }
                if (ops != null)
                {
                    opBuffer.Add(ops);
                }
            }
            if (mouseHoverCity != null || mouseHoverHarv != null || mouseHoverResource != null)
            {
                RenderOperation[] ops = outter_marker.GetRenderOperation();
                if (mouseHoverCity != null)
                {
                    for (int i = 0; i < ops.Length; i++)
                    {
                        ops[i].Sender = mouseHoverCity.Owner;
                    }
                }
                else if (mouseHoverHarv != null)
                {
                    for (int i = 0; i < ops.Length; i++)
                    {
                        ops[i].Sender = mouseHoverHarv.Parent.Owner;
                    }
                }
                else
                {
                    for (int i = 0; i < ops.Length; i++)
                    {
                        ops[i].Sender = null;
                    }
                }
                if (ops != null)
                {
                    opBuffer.Add(ops);
                }
            }
            opBuffer.Trim();
            return(opBuffer.Elements);
        }
Exemplo n.º 9
0
        protected unsafe override void load()
        {
            resourceSize = 0;

            float radlng = MathEx.Degree2Radian(info.Longitude);
            float radlat = MathEx.Degree2Radian(info.Latitude);
            float radr = MathEx.Degree2Radian(info.Radius) * 2;

            TreeOrientation = PlanetEarth.GetOrientation(radlng, radlat);
            TreeOrientation.TranslationValue = PlanetEarth.GetPosition(radlng, radlat, PlanetEarth.PlanetRadius);


            int vtxCount = 0;
            int vtxOffset = 0;
            int vtxCount2 = 0;
            int vtxOffset2 = 0;

            int plantCount = (int)(info.Amount * 0.05f);



            FastList<byte> vertices2 = new FastList<byte>(plantCount * 2500);
            FastList<int> indices2 = new FastList<int>();
            int partVtxCount2 = 0;


            FastList<byte> vertices = new FastList<byte>(plantCount * 2500);
            Dictionary<Material, FastList<int>> indices = new Dictionary<Material, FastList<int>>();
            Dictionary<Material, int> partVtxCount = new Dictionary<Material, int>();

            plantCount = 0;

            byte[] vtxBldBuffer = new byte[TreeVertex.Size];

            const float AreaWidth = 0.036f;
            for (float blkLng = radlng - radr; blkLng < radlng + radr; blkLng += AreaWidth)
            {
                for (float blkLat = radlat - radr; blkLat < radlat + radr; blkLat += AreaWidth)
                {
                    float altblk = TerrainData.Instance.QueryHeight(blkLng, blkLat) - 100;

                    if (altblk < 0)
                        continue;

                    float density = PlantDensity.Instance.GetPlantDensity(blkLng, blkLat);

                    int count = (int)(density * 2.25f);

                    for (int i = 0; i < count; i++)
                    {
                        float treeLng = blkLng + AreaWidth * Randomizer.GetRandomSingle();
                        float treeLat = blkLat + AreaWidth * Randomizer.GetRandomSingle();

                        float alt = TerrainData.Instance.QueryHeight(treeLng, treeLat);

                        PlantDensityData d = PlantDensity.Instance.GetDensity(treeLng, treeLat);
                        int idx = Randomizer.Random(d.Density, PlantDensity.TypeCount);
                       
                        TreeModelData[] mdls = TreeModelLibrary.Instance.Get(idx);
                        TreeModelData meshData = mdls[Randomizer.GetRandomInt(mdls.Length)];


                        Matrix treeOrientation = PlanetEarth.GetOrientation(treeLng, treeLat);
                        treeOrientation.TranslationValue = PlanetEarth.GetPosition(treeLng, treeLat,
                            PlanetEarth.PlanetRadius + alt * TerrainMeshManager.PostHeightScale);

                        float instanceData = Randomizer.GetRandomSingle();

                        float theta = instanceData * MathEx.PIf * 2;
                        float rotCos = (float)Math.Cos(theta);
                        float rotSin = (float)Math.Sin(theta);

                        #region 数据
                        resourceSize += meshData.VertexCount * TreeVertex.Size;
                        vtxCount += meshData.VertexCount;

                        fixed (byte* src = &meshData.VertexData[0])
                        {
                            VertexPNT1* ptr = (VertexPNT1*)src;

                            for (int j = 0; j < meshData.VertexCount; j++)
                            {
                                TreeVertex p;
                                p.pos.X = rotCos * ptr[j].pos.X - rotSin * ptr[j].pos.Z;
                                p.pos.Z = rotSin * ptr[j].pos.X + rotCos * ptr[j].pos.Z;
                                p.pos.Y = ptr[j].pos.Y;

                                p.pos = p.pos * (Game.TreeScale * (instanceData * 0.4f + 0.8f));

                                Vector3 pp;
                                Vector3.TransformSimple(ref p.pos, ref treeOrientation, out pp);
                                p.pos = pp;

                                p.n.X = rotCos * ptr[j].n.X - rotSin * ptr[j].n.Z;
                                p.n.Z = rotSin * ptr[j].n.Z + rotCos * ptr[j].n.Z;
                                p.n.Y = ptr[j].n.Y;

                                p.tex1 = new Vector3(ptr[j].u, ptr[j].v, instanceData);

                                fixed (byte* dst = &vtxBldBuffer[0])
                                {
                                    Memory.Copy(&p, dst, TreeVertex.Size);
                                }

                                p.tc = new Vector2(treeLng, treeLat);
                                p.tc.X += MathEx.PIf;
                                //p.tc.Y -= MathEx.Degree2Radian(10);

                                p.tc.X = 0.5f * p.tc.X / MathEx.PIf;
                                p.tc.Y = (-p.tc.Y + MathEx.PiOver2) / MathEx.PIf;

                                vertices.Add(vtxBldBuffer);
                            }
                        }

                        Material[] mtrls = meshData.Materials;
                        for (int k = 0; k < mtrls.Length; k++)
                        {
                            Material mtrl = mtrls[k];

                            FastList<int> idxData;
                            if (!indices.TryGetValue(mtrl, out idxData))
                            {
                                idxData = new FastList<int>(plantCount * 120);
                                indices.Add(mtrl, idxData);

                                partVtxCount.Add(mtrl, 0);
                            }

                            partVtxCount[mtrl] += meshData.PartVtxCount[k];

                            int[] meshIdx = meshData.Indices[k];

                            for (int j = 0; j < meshIdx.Length; j++)
                            {
                                idxData.Add(meshIdx[j] + vtxOffset);
                            }


                        }
                        vtxOffset += meshData.VertexCount;
                        #endregion

                        TreeModelData meshData2 = TreeModelLibrary.Instance.GetTrunk();
                        #region 树桩
                        resourceSize += meshData2.VertexCount * TreeVertex.Size;
                        vtxCount2 += meshData2.VertexCount;

                        fixed (byte* src = &meshData2.VertexData[0])
                        {
                            VertexPNT1* ptr = (VertexPNT1*)src;

                            for (int j = 0; j < meshData2.VertexCount; j++)
                            {
                                TreeVertex p;
                                p.pos.X = rotCos * ptr[j].pos.X - rotSin * ptr[j].pos.Z;
                                p.pos.Z = rotSin * ptr[j].pos.X + rotCos * ptr[j].pos.Z;
                                p.pos.Y = ptr[j].pos.Y;

                                p.pos = p.pos * (Game.TreeScale * (instanceData * 0.4f + 0.8f));

                                Vector3 pp;
                                Vector3.TransformSimple(ref p.pos, ref treeOrientation, out pp);
                                p.pos = pp;

                                p.n.X = rotCos * ptr[j].n.X - rotSin * ptr[j].n.Z;
                                p.n.Z = rotSin * ptr[j].n.Z + rotCos * ptr[j].n.Z;
                                p.n.Y = ptr[j].n.Y;

                                p.tex1 = new Vector3(ptr[j].u, ptr[j].v, instanceData);

                                fixed (byte* dst = &vtxBldBuffer[0])
                                {
                                    Memory.Copy(&p, dst, TreeVertex.Size);
                                }
                                vertices2.Add(vtxBldBuffer);
                            }
                        }

                        material2 = meshData2.Materials[0];
                        partVtxCount2 += meshData2.PartVtxCount[0];

                        int[] meshIdx2 = meshData2.Indices[0];

                        for (int j = 0; j < meshIdx2.Length; j++)
                        {
                            indices2.Add(meshIdx2[j] + vtxOffset2);
                        }
                        vtxOffset2 += meshData2.VertexCount;
                        #endregion
                        plantCount++;
                    }
                }
            }



            // ============================================================================

            ObjectFactory fac = renderSys.ObjectFactory;
            vtxDecl = fac.CreateVertexDeclaration(TreeVertex.Elements);
            int vtxSize = vtxDecl.GetVertexSize();

            vtxBuffer = fac.CreateVertexBuffer(vtxCount, vtxDecl, BufferUsage.Static);

            vertices.Trim();
            vtxBuffer.SetData<byte>(vertices.Elements);

            vtxBuffer2 = fac.CreateVertexBuffer(vtxCount2, vtxDecl, BufferUsage.Static);
            vertices2.Trim();
            vtxBuffer2.SetData<byte>(vertices2.Elements);

            int partCount = indices.Count;

            idxBuffer = new IndexBuffer[partCount];
            materials = new Material[partCount];
            opBuf = new RenderOperation[partCount];

            int index = 0;

            foreach (KeyValuePair<Material, FastList<int>> e in indices)
            {
                FastList<int> list = e.Value;
                list.Trim();

                materials[index] = e.Key;
                idxBuffer[index] = fac.CreateIndexBuffer(IndexBufferType.Bit32, list.Count, BufferUsage.Static);

                idxBuffer[index].SetData<int>(list.Elements);

                resourceSize += sizeof(int) * list.Count;

                // ==============================================================================================

                opBuf[index].Material = e.Key;
                opBuf[index].Geomentry = new GeomentryData();
                opBuf[index].Geomentry.BaseIndexStart = 0;
                opBuf[index].Geomentry.BaseVertex = 0;
                opBuf[index].Geomentry.IndexBuffer = idxBuffer[index];
                opBuf[index].Geomentry.PrimCount = idxBuffer[index].IndexCount / 3;
                opBuf[index].Geomentry.PrimitiveType = RenderPrimitiveType.TriangleList;
                opBuf[index].Geomentry.VertexBuffer = vtxBuffer;
                opBuf[index].Geomentry.VertexCount = partVtxCount[e.Key];
                opBuf[index].Geomentry.VertexDeclaration = vtxDecl;
                opBuf[index].Geomentry.VertexSize = vtxSize;
                opBuf[index].Sender = this;
                index++;
            }

            indices2.Trim();

            idxBuffer2 = fac.CreateIndexBuffer(IndexBufferType.Bit32, indices2.Count, BufferUsage.Static);
            idxBuffer2.SetData<int>(indices2.Elements);
            opbuf2 = new RenderOperation[1];
            opbuf2[0].Material = material2;
            opbuf2[0].Geomentry = new GeomentryData();
            opbuf2[0].Geomentry.BaseIndexStart = 0;
            opbuf2[0].Geomentry.BaseVertex = 0;
            opbuf2[0].Geomentry.IndexBuffer = idxBuffer2;
            opbuf2[0].Geomentry.PrimCount = idxBuffer2.IndexCount / 3;
            opbuf2[0].Geomentry.PrimitiveType = RenderPrimitiveType.TriangleList;
            opbuf2[0].Geomentry.VertexBuffer = vtxBuffer2;
            opbuf2[0].Geomentry.VertexCount = partVtxCount2;
            opbuf2[0].Geomentry.VertexDeclaration = vtxDecl;
            opbuf2[0].Geomentry.VertexSize = vtxSize;
            opbuf2[0].Sender = this;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Copies from original list to a new list based on treeindex values, based upon the flag sent.
        /// ie copies entries with 0 to 262144 only or that have 262144 to 'limit', or just all.
        /// </summary>
        /// <param name="orgBurningList">The orginal source list</param>
        /// <param name="bCopyFlag">0= CopyAllEntries; 1= 0 to 262144; 2= 262144 to 'limit'</param>
        /// <returns>a new FastList of treemanager.burningtrees, returns an empty list on none or error.</returns>
        public static FastList <TreeManager.BurningTree> CopyBurningTreesList(ref FastList <TreeManager.BurningTree> orgBurningList, byte bCopyFlag)
        {
            FastList <TreeManager.BurningTree> newlist = new FastList <TreeManager.BurningTree>();

            newlist.Clear();
            try
            {
                if (orgBurningList != null)
                {
                    int orgcount = orgBurningList.m_size;
                    newlist.EnsureCapacity(orgcount);
                    TreeManager.BurningTree tmpTree = new TreeManager.BurningTree();

                    int tmpcounter = 0;
                    int MinValue   = 0;
                    int MaxValue   = 0;
                    if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                    {
                        Logger.dbgLog("CopyFlag = " + bCopyFlag.ToString());
                    }
                    switch (bCopyFlag)
                    {
                    //0-262144 mainserialze()
                    case 1:
                        MinValue = 0;
                        MaxValue = Mod.DEFAULT_TREE_COUNT;
                        break;

                    //262144 to activelimit  customserialze( not packed)
                    case 2:
                        MinValue = Mod.DEFAULT_TREE_COUNT;
                        MaxValue = LimitTreeManager.Helper.TreeLimit;
                        break;

                    //262144 to lastsavecount.count customseralize(packed)???
                    case 3:
                        MinValue = Mod.DEFAULT_TREE_COUNT;
                        MaxValue = LoadingExtension.LastSaveList.Count;
                        break;

                    //just copy all of them.
                    default:
                        MinValue = 0;
                        MaxValue = LimitTreeManager.Helper.TreeLimit;
                        break;
                    }
                    if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                    {
                        Logger.dbgLog(string.Concat("copying from: ", MinValue.ToString(), " to ", MaxValue.ToString()));
                    }

                    if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                    {
                        m_PerfMonitor.Reset(); m_PerfMonitor.Start();
                    }

                    foreach (TreeManager.BurningTree orgTree in orgBurningList)
                    {
                        if (orgTree.m_treeIndex > 0 && (orgTree.m_treeIndex >= MinValue & orgTree.m_treeIndex < MaxValue))
                        {
                            //copy tree
                            tmpTree.m_treeIndex     = orgTree.m_treeIndex;
                            tmpTree.m_fireDamage    = orgTree.m_fireDamage;
                            tmpTree.m_fireIntensity = orgTree.m_fireIntensity;
                            newlist.Add(tmpTree);
                            tmpcounter++;
                        }
                    }
                    newlist.Trim();
                    if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                    {
                        m_PerfMonitor.Stop(); Logger.dbgLog(string.Concat("Copy time took (ticks):", m_PerfMonitor.ElapsedTicks.ToString()));
                    }
                    if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                    {
                        Logger.dbgLog(string.Concat("orgCount(m_size):", orgcount.ToString(), " copycount:", tmpcounter.ToString()) + " new_msize:" + newlist.m_size.ToString());
                    }
                }
                else
                {
                    Logger.dbgLog("orgBurningList is Null!");
                    return(newlist);
                }
            }
            catch (Exception ex)
            { Logger.dbgLog(ex.ToString()); }

            return(newlist);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Trims the neighbors list
 /// </summary>
 internal void TrimNeighbors()
 {
     m_jumps.Trim();
 }