Exemplo n.º 1
0
        private unsafe void ComputeNormals(float *pHeightmap)
        {
            int      size      = this._meshProvider.Size;
            int      divisions = this._meshProvider.Divisions;
            Point3D *pVertices = stackalloc Point3D[size];

            this.ComputeVerticesCore(pHeightmap, pVertices, divisions);
            fixed(Point3D *pNormals = this.AllocateNormals(size))
            {
                int indexCount;

                fixed(int *pIndices = this.GetIndices(out indexCount))
                MapLighting.AccumulateNormals(pIndices, pVertices, pNormals, indexCount, size);
            }
        }
Exemplo n.º 2
0
        public void Load()
        {
            MapLighting.CheckStretchTable();
            if (!MapLighting.m_AlwaysStretch[this.m_LandID & 16383])
            {
                Hues.Default.GetTerrainIsometric(this.m_LandID);
            }
            int textureId = (int)Map.GetTexture(this.m_LandID);

            if (textureId <= 0 || textureId >= 16384)
            {
                return;
            }
            Hues.Default.GetTerrainTexture(textureId);
        }
Exemplo n.º 3
0
        protected override unsafe void UpdateMesh(LandTile tile, int baseColor)
        {
            int shadow1 = MapLighting.GetShadow(tile.facet, tile.ax, tile.ay);
            int shadow2 = MapLighting.GetShadow(tile.facet, tile.ax + 1, tile.ay);
            int shadow3 = MapLighting.GetShadow(tile.facet, tile.ax + 1, tile.ay + 1);
            int shadow4 = MapLighting.GetShadow(tile.facet, tile.ax, tile.ay + 1);

            fixed(TransformedColoredTextured *pMesh = this._mesh)
            {
                TransformedColoredTextured[] transformedColoredTexturedArray = this._mesh;
                int divisions = this._meshProvider.Divisions;
                int stride    = this._meshProvider.Stride;

                if (divisions == 1)
                {
                    TerrainMesh3D.UpdateSimpleMesh(pMesh, shadow1, shadow2, shadow3, shadow4);
                }
                else
                {
                    this.UpdateMeshComplex(shadow1, shadow2, shadow3, shadow4);
                }
            }
        }
Exemplo n.º 4
0
        private unsafe void UpdateMeshComplex(int s00, int s10, int s11, int s01)
        {
            int stride    = this._meshProvider.Stride;
            int divisions = this._meshProvider.Divisions;

            int[] indices;
            if ((indices = this._meshProvider.GetIndices(this._foldLeftRight)) != null && indices.Length != 0)
            {
                fixed(int *numPtr = &indices[0])
                ;
            }

            fixed(TransformedColoredTextured *transformedColoredTexturedPtr1 = this._mesh)
            {
                TransformedColoredTextured *transformedColoredTexturedPtr2 = transformedColoredTexturedPtr1;
                int num1 = 0;
                int num2 = divisions;

                while (num1 <= divisions)
                {
                    int num3 = (s00 * num2 + s01 * num1) / divisions;
                    int num4 = (s10 * num2 + s11 * num1) / divisions;
                    int num5 = 0;
                    int num6 = divisions;
                    while (num5 <= divisions)
                    {
                        int     num7  = (num3 * num6 + num4 * num5) / divisions;
                        Point3D a     = this._normals[num1 * stride + num5];
                        int     num8  = num5 == 0 ? -1 : (num5 == divisions ? 1 : 0);
                        int     num9  = num1 == 0 ? -1 : (num1 == divisions ? 1 : 0);
                        int     num10 = 65793;
                        if (num8 != 0)
                        {
                            LandTile landTile = World.Viewport.GetLandTile(this.tile.ax + num8, this.tile.ay, Engine.m_World);
                            if ((!this.tile.m_Guarded ? 0 : (!this.tile.Impassable ? 1 : 0)) != (!landTile.m_Guarded ? 0 : (!landTile.Impassable ? 1 : 0)))
                            {
                                num10 = !this.tile.m_Guarded || this.tile.Impassable ? 65536 : 256;
                            }
                            landTile.EnsureMesh(landTile._lastMeshHue ?? this.tile._lastMeshHue ?? Hues.Default, this._meshProvider);
                            TerrainMesh3D terrainMesh3D = landTile._mesh as TerrainMesh3D;
                            if (terrainMesh3D != null)
                            {
                                terrainMesh3D.Update(terrainMesh3D.tile, terrainMesh3D._color);
                                a += terrainMesh3D._normals[num1 * stride + num6];
                            }
                        }
                        if (num9 != 0)
                        {
                            LandTile landTile = World.Viewport.GetLandTile(this.tile.ax, this.tile.ay + num9, Engine.m_World);
                            if ((!this.tile.m_Guarded ? 0 : (!this.tile.Impassable ? 1 : 0)) != (!landTile.m_Guarded ? 0 : (!landTile.Impassable ? 1 : 0)))
                            {
                                num10 = !this.tile.m_Guarded || this.tile.Impassable ? 65536 : 256;
                            }
                            landTile.EnsureMesh(landTile._lastMeshHue ?? this.tile._lastMeshHue ?? Hues.Default, this._meshProvider);
                            TerrainMesh3D terrainMesh3D = landTile._mesh as TerrainMesh3D;
                            if (terrainMesh3D != null)
                            {
                                terrainMesh3D.Update(terrainMesh3D.tile, terrainMesh3D._color);
                                a += terrainMesh3D._normals[num2 * stride + num5];
                            }
                        }
                        if (num8 != 0 && num9 != 0)
                        {
                            LandTile landTile = World.Viewport.GetLandTile(this.tile.ax + num8, this.tile.ay + num9, Engine.m_World);
                            if ((!this.tile.m_Guarded ? 0 : (!this.tile.Impassable ? 1 : 0)) != (!landTile.m_Guarded ? 0 : (!landTile.Impassable ? 1 : 0)))
                            {
                                num10 = !this.tile.m_Guarded || this.tile.Impassable ? 65536 : 256;
                            }
                            landTile.EnsureMesh(landTile._lastMeshHue ?? this.tile._lastMeshHue ?? Hues.Default, this._meshProvider);
                            TerrainMesh3D terrainMesh3D = landTile._mesh as TerrainMesh3D;
                            if (terrainMesh3D != null)
                            {
                                terrainMesh3D.Update(terrainMesh3D.tile, terrainMesh3D._color);
                                a += terrainMesh3D._normals[num2 * stride + num6];
                            }
                        }
                        Point3D normal = Point3D.Normalize256(a);
                        int     num11  = (num7 * 2 + MapLighting.GetShadow(normal) + 2) / 3;
                        transformedColoredTexturedPtr2++->Color = Renderer.GetQuadColor(num10 * num11);
                        ++num5;
                        --num6;
                    }
                    ++num1;
                    --num2;
                }
                // ISSUE: fixed variable is out of scope
                // ISSUE: __unpin statement
            }
        }