Beispiel #1
0
        private _2DSprite GetAirSprite(WorldState world)
        {
            var       _Sprite  = world._2D.NewSprite(_2DBatchRenderMode.Z_BUFFER);
            var       airTiles = TextureGenerator.GetAirTiles(world.Device);
            Texture2D sprite   = null;

            switch (world.Zoom)
            {
            case WorldZoom.Far:
                sprite           = airTiles[2];
                _Sprite.DestRect = FLOORDEST_FAR;
                _Sprite.Depth    = ArchZBuffers[14];
                break;

            case WorldZoom.Medium:
                sprite           = airTiles[1];
                _Sprite.DestRect = FLOORDEST_MED;
                _Sprite.Depth    = ArchZBuffers[13];
                break;

            case WorldZoom.Near:
                sprite           = airTiles[0];
                _Sprite.DestRect = FLOORDEST_NEAR;
                _Sprite.Depth    = ArchZBuffers[12];
                break;
            }

            _Sprite.Pixel   = sprite;
            _Sprite.SrcRect = new Microsoft.Xna.Framework.Rectangle(0, 0, _Sprite.Pixel.Width, _Sprite.Pixel.Height);

            return(_Sprite);
        }
Beispiel #2
0
        public void DrawFloor(GraphicsDevice gd, Effect e, WorldZoom zoom, WorldRotation rot, List <Texture2D> roommaps, HashSet <sbyte> floors, EffectPass pass,
                              Matrix?lightWorld = null, WorldState state = null, int minFloor = 0)
        {
            var parallax = WorldConfig.Current.Complex;
            //assumes the effect and all its parameters have been set up already
            //we just need to get the right texture and offset
            var flrContent = Content.Content.Get().WorldFloors;

            e.Parameters["TexOffset"].SetValue(new Vector2());// TexOffset[zoom]*-1f);
            var tmat = TexMat[rot];

            e.Parameters["TexMatrix"].SetValue(tmat);

            var f = 0;

            foreach (var floor in Floors)
            {
                if (!floors.Contains((sbyte)(f++)))
                {
                    continue;
                }

                Matrix worldmat;
                if (lightWorld == null)
                {
                    worldmat = Matrix.CreateTranslation(0, 2.95f * (f - 1) * 3 - Bp.BaseAlt * Bp.TerrainFactor * 3, 0);
                }
                else
                {
                    worldmat = Matrix.CreateScale(1, 0, 1) * Matrix.CreateTranslation(0, 1f * (f - (1 + minFloor)), 0) * lightWorld.Value;
                    e.Parameters["DiffuseColor"].SetValue(new Vector4(1, 1, 1, 1) * (float)(6 - (f - (minFloor))) / 5f);
                }

                e.Parameters["World"].SetValue(worldmat);
                e.Parameters["Level"].SetValue((float)(f - ((lightWorld == null)?0.999f:1f)));
                if (roommaps != null)
                {
                    e.Parameters["RoomMap"].SetValue(roommaps[f - 1]);
                }
                foreach (var type in floor.GroupForTileType)
                {
                    bool water = false;
                    var  dat   = type.Value.GPUData;
                    if (dat == null)
                    {
                        continue;
                    }
                    gd.Indices = dat;

                    var       id         = type.Key;
                    var       doubleDraw = false;
                    Texture2D SPR        = null;
                    Texture2D pSPR       = null;

                    if (id == 0)
                    {
                        e.Parameters["UseTexture"].SetValue(false);
                        e.Parameters["IgnoreColor"].SetValue(false);
                        e.Parameters["GrassShininess"].SetValue(0.02f);// (float)0.25);
                    }
                    else
                    {
                        e.Parameters["GrassShininess"].SetValue((id >= 65503)?0.02f:0f);
                        if (id >= 65503)
                        {
                            if (id == 65503)
                            {
                                water = true;
                                var airTiles = TextureGenerator.GetAirTiles(gd);
                                switch (zoom)
                                {
                                case WorldZoom.Far:
                                    SPR = airTiles[2];
                                    break;

                                case WorldZoom.Medium:
                                    SPR = airTiles[1];
                                    break;

                                case WorldZoom.Near:
                                    SPR = airTiles[0];
                                    break;
                                }
                            }
                            else
                            {
                                e.Parameters["Water"].SetValue(true);
                                var pool = id >= 65520;
                                water = true;
                                if (!pool)
                                {
                                    e.Parameters["UseTexture"].SetValue(false);
                                    e.Parameters["IgnoreColor"].SetValue(false);

                                    //quickly draw under the water
                                    pass.Apply();
                                    gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, type.Value.GeomForOffset.Count * 2);

                                    e.Parameters["UseTexture"].SetValue(true);
                                    e.Parameters["IgnoreColor"].SetValue(true);
                                    if (lightWorld == null)
                                    {
                                        e.Parameters["World"].SetValue(worldmat * Matrix.CreateTranslation(0, 0.05f, 0));
                                    }
                                    id -= 65504;
                                }
                                else
                                {
                                    id -= 65520;
                                }

                                e.Parameters["TexMatrix"].SetValue(CounterTexMat[rot]);

                                var roti = (int)rot;
                                roti = (4 - roti) % 4;
                                id   = (ushort)(((id << roti) & 15) | (id >> (4 - roti)));
                                //pools & water are drawn with special logic, and may also be drawn slightly above the ground.

                                int baseSPR;
                                int frameNum = 0;
                                if (state != null)
                                {
                                    if (PoolReplace != null && pool)
                                    {
                                        SPR = PoolReplace[id];
                                        if (parallax)
                                        {
                                            pSPR = PoolReplaceParallax[id];
                                        }
                                    }
                                    else
                                    {
                                        switch (zoom)
                                        {
                                        case WorldZoom.Far:
                                            baseSPR  = (pool) ? 0x400 : 0x800;
                                            frameNum = (pool) ? 0 : 2;
                                            SPR      = state._2D.GetTexture(flrContent.GetGlobalSPR((ushort)(baseSPR + id)).Frames[frameNum]);
                                            break;

                                        case WorldZoom.Medium:
                                            baseSPR  = (pool) ? 0x410 : 0x800;
                                            frameNum = (pool) ? 0 : 1;
                                            SPR      = state._2D.GetTexture(flrContent.GetGlobalSPR((ushort)(baseSPR + id)).Frames[frameNum]);
                                            break;

                                        default:
                                            baseSPR = (pool) ? 0x420 : 0x800;
                                            SPR     = state._2D.GetTexture(flrContent.GetGlobalSPR((ushort)(baseSPR + id)).Frames[frameNum]);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            var flr = flrContent.Get(id);

                            if (flr == null)
                            {
                                continue;
                            }

                            if (state != null)
                            {
                                switch (zoom)
                                {
                                case WorldZoom.Far:
                                    SPR = state._2D.GetTexture(flr.Far.Frames[0]);
                                    break;

                                case WorldZoom.Medium:
                                    SPR = state._2D.GetTexture(flr.Medium.Frames[0]);
                                    break;

                                default:
                                    SPR = state._2D.GetTexture(flr.Near.Frames[0]);
                                    break;
                                }
                            }
                        }

                        //e.Parameters["UseTexture"].SetValue(SPR != null);
                    }

                    e.Parameters["BaseTex"].SetValue(SPR);
                    if (SPR != null && SPR.Name == null)
                    {
                        doubleDraw = true;
                        SPR.Name   = Alt.ToString();
                    }
                    if (pSPR != null)
                    {
                        var parallaxPass = e.CurrentTechnique.Passes[4];
                        e.Parameters["ParallaxTex"].SetValue(pSPR);
                        e.Parameters["ParallaxUVTexMat"].SetValue(new Vector4(0.7071f, -0.7071f, 0.7071f, 0.7071f));
                        e.Parameters["ParallaxHeight"].SetValue(0.1f);
                        parallaxPass.Apply();
                    }
                    else
                    {
                        pass.Apply();
                    }
                    if (Alt && !FSOEnvironment.DirectX)
                    {
                        //opengl bug workaround. For some reason, the texture is set to clamp mode by some outside force on first draw.
                        //Monogame then thinks the texture is wrapping.
                        gd.SamplerStates[1] = CustomWrap;
                    }
                    gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, type.Value.GeomForOffset.Count * 2);
                    //gd.SamplerStates[1] = SamplerState.LinearWrap;

                    if (id == 0)
                    {
                        e.Parameters["UseTexture"].SetValue(true);
                        e.Parameters["IgnoreColor"].SetValue(true);
                    }
                    if (water)
                    {
                        e.Parameters["World"].SetValue(worldmat);
                        e.Parameters["TexMatrix"].SetValue(tmat);
                        e.Parameters["Water"].SetValue(false);
                    }
                }
            }
            e.Parameters["Water"].SetValue(false);
            Alt = !Alt;
        }
Beispiel #3
0
        public void DrawFloor(GraphicsDevice gd, Effect e, WorldZoom zoom, WorldRotation rot, List <Texture2D> roommaps, HashSet <sbyte> floors, EffectPass pass,
                              Matrix?lightWorld = null, WorldState state = null, int minFloor = 0)
        {
            //assumes the effect and all its parameters have been set up already
            //we just need to get the right texture and offset
            var flrContent = Content.Content.Get().WorldFloors;

            e.Parameters["TexOffset"].SetValue(new Vector2());// TexOffset[zoom]*-1f);
            var tmat = TexMat[rot];

            e.Parameters["TexMatrix"].SetValue(tmat);

            var f = 0;

            foreach (var floor in Floors)
            {
                if (!floors.Contains((sbyte)(f++)))
                {
                    continue;
                }

                Matrix worldmat;
                if (lightWorld == null)
                {
                    worldmat = Matrix.CreateTranslation(0, 2.95f * (f - 1) * 3 - Bp.BaseAlt * Bp.TerrainFactor * 3, 0);
                }
                else
                {
                    worldmat = Matrix.CreateScale(1, 0, 1) * Matrix.CreateTranslation(0, 1f * (f - (1 + minFloor)), 0) * lightWorld.Value;
                    e.Parameters["DiffuseColor"].SetValue(new Vector4(1, 1, 1, 1) * (float)(6 - (f - (minFloor))) / 5f);
                }

                e.Parameters["World"].SetValue(worldmat);
                e.Parameters["Level"].SetValue((float)(f - ((lightWorld == null)?0.999f:1f)));
                if (roommaps != null)
                {
                    e.Parameters["RoomMap"].SetValue(roommaps[f - 1]);
                }
                foreach (var type in floor.GroupForTileType)
                {
                    bool water = false;
                    var  dat   = type.Value.GPUData;
                    if (dat == null)
                    {
                        continue;
                    }
                    gd.Indices = dat;

                    var id = type.Key;

                    if (id == 0)
                    {
                        e.Parameters["UseTexture"].SetValue(false);
                        e.Parameters["IgnoreColor"].SetValue(false);
                    }
                    else
                    {
                        Texture2D SPR = null;
                        if (id >= 65503)
                        {
                            if (id == 65503)
                            {
                                water = true;
                                var airTiles = TextureGenerator.GetAirTiles(gd);
                                switch (zoom)
                                {
                                case WorldZoom.Far:
                                    SPR = airTiles[2];
                                    break;

                                case WorldZoom.Medium:
                                    SPR = airTiles[1];
                                    break;

                                case WorldZoom.Near:
                                    SPR = airTiles[0];
                                    break;
                                }
                            }
                            else
                            {
                                e.Parameters["Water"].SetValue(true);
                                var pool = id >= 65520;
                                water = true;
                                if (!pool)
                                {
                                    e.Parameters["UseTexture"].SetValue(false);
                                    e.Parameters["IgnoreColor"].SetValue(false);

                                    //quickly draw under the water
                                    pass.Apply();
                                    gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, type.Value.GeomForOffset.Count * 2);

                                    e.Parameters["UseTexture"].SetValue(true);
                                    e.Parameters["IgnoreColor"].SetValue(true);
                                    if (lightWorld == null)
                                    {
                                        e.Parameters["World"].SetValue(worldmat * Matrix.CreateTranslation(0, 0.05f, 0));
                                    }
                                    id -= 65504;
                                }
                                else
                                {
                                    id -= 65520;
                                }

                                e.Parameters["TexMatrix"].SetValue(CounterTexMat[rot]);

                                var roti = (int)rot;
                                roti = (4 - roti) % 4;
                                id   = (ushort)(((id << roti) & 15) | (id >> (4 - roti)));
                                //pools & water are drawn with special logic, and may also be drawn slightly above the ground.

                                int baseSPR;
                                int frameNum = 0;
                                if (state != null)
                                {
                                    switch (zoom)
                                    {
                                    case WorldZoom.Far:
                                        baseSPR  = (pool) ? 0x400 : 0x800;
                                        frameNum = (pool) ? 0 : 2;
                                        SPR      = state._2D.GetTexture(flrContent.GetGlobalSPR((ushort)(baseSPR + id)).Frames[frameNum]);
                                        break;

                                    case WorldZoom.Medium:
                                        baseSPR  = (pool) ? 0x410 : 0x800;
                                        frameNum = (pool) ? 0 : 1;
                                        SPR      = state._2D.GetTexture(flrContent.GetGlobalSPR((ushort)(baseSPR + id)).Frames[frameNum]);
                                        break;

                                    default:
                                        baseSPR = (pool) ? 0x420 : 0x800;
                                        SPR     = state._2D.GetTexture(flrContent.GetGlobalSPR((ushort)(baseSPR + id)).Frames[frameNum]);
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            var flr = flrContent.Get(id);

                            if (flr == null)
                            {
                                continue;
                            }

                            if (state != null)
                            {
                                switch (zoom)
                                {
                                case WorldZoom.Far:
                                    SPR = state._2D.GetTexture(flr.Far.Frames[0]);
                                    break;

                                case WorldZoom.Medium:
                                    SPR = state._2D.GetTexture(flr.Medium.Frames[0]);
                                    break;

                                default:
                                    SPR = state._2D.GetTexture(flr.Near.Frames[0]);
                                    break;
                                }
                            }
                        }

                        //e.Parameters["UseTexture"].SetValue(SPR != null);
                        e.Parameters["BaseTex"].SetValue(SPR);
                    }

                    pass.Apply();
                    gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, type.Value.GeomForOffset.Count * 2);

                    if (id == 0)
                    {
                        e.Parameters["UseTexture"].SetValue(true);
                        e.Parameters["IgnoreColor"].SetValue(true);
                    }
                    if (water)
                    {
                        e.Parameters["World"].SetValue(worldmat);
                        e.Parameters["TexMatrix"].SetValue(tmat);
                        e.Parameters["Water"].SetValue(false);
                    }
                }
            }
            e.Parameters["Water"].SetValue(false);
        }