Exemple #1
0
        //*
        public override void Render(FrameEventArgs e)
        {
            base.Render(e);
            if (_mapDataChanged)
            {
                return;
            }
            if (_mapInstance != null)
            {
                Renderer.PushWorldMatrix();
                Renderer.TranslateWorld((int)Transform.Position.X, (int)Transform.Position.Y, 0);

                for (int i = 0; i < _MapTileMeshes.Count; i++)
                {
                    Shape shape = _MapTileMeshes[i].GetShape();
                    if (shape != null)
                    {
                        Vector3 pos         = Vector3.Zero;
                        Vector3 scale       = new Vector3(32, 32, 1);
                        Color4  colour      = Color4.White;
                        Texture texture     = _MapTileMeshes[i].GetTexture();
                        bool    reflections = _MapTileMeshes[i].IsReflections();
                        bool    autoTiles   = _MapTileMeshes[i].IsAutoTiles();

                        if (reflections)
                        {
                            Renderer.PushStencilDepth(OpenTK.Graphics.OpenGL.StencilOp.Incr, OpenTK.Graphics.OpenGL.StencilFunction.Equal);
                        }

                        if (autoTiles)
                        {
                            int numFrames = _MapTileMeshes[i].NumFrames;
                            TilesetData.Tileset tileset = _MapTileMeshes[i].GetTileset();
                            int tileID = _MapTileMeshes[i].AutoTileID;

                            int   frame   = (int)(_autoTileAnimationTimer * tileset.GetAutoTileTimer(tileID - 1)) % numFrames;
                            float offsetX = (frame * 96f) / texture.GetWidth();
                            Renderer.SetTextureOffset(offsetX, 0);
                        }

                        Renderer.FillTexture(texture, shape, ref pos, ref scale, ref colour);

                        if (reflections)
                        {
                            Renderer.PopStencilDepth();
                        }

                        if (autoTiles)
                        {
                            Renderer.SetTextureOffset(0, 0);
                        }
                    }
                }

                Renderer.PopWorldMatrix();
            }
        }
Exemple #2
0
            public MapTileMeshData(bool isReflections, bool isAutoTiles, TilesetData.Tileset tileset, Texture texture)
            {
                _isReflections = isReflections;
                _isAutoTiles   = isAutoTiles;
                _tileset       = tileset;
                _texture       = texture;

                _vertices      = new List <float>();
                _textureCoords = new List <float>();
                _indices       = new List <int>();
                _shape         = null;

                Ready      = false;
                NumFrames  = 1;
                AutoTileID = -1;
            }
Exemple #3
0
        public override bool BushFlag()
        {
            MapData data = MapComponent.Instance.GetMapInstance().GetMapData();

            if (data == null)
            {
                return(false);
            }
            for (int i = 0; i < 3; i++)
            {
                float x = _mapPlayer.GetPlayerPacket().RealX;
                float y = _mapPlayer.GetPlayerPacket().RealY;
                if ((x % 32) / 32f < 0.5)
                {
                    x = (int)Math.Floor(x / 32);
                }
                else
                {
                    x = (int)Math.Ceiling(x / 32);
                }

                if ((y % 32) / 32f < 0.3)
                {
                    y = (int)Math.Floor(y / 32);
                }
                else
                {
                    y = (int)Math.Ceiling(y / 32);
                }

                Tuple <int, int> tileInfo = data.GetTile(i, (int)x, (int)y);
                if (tileInfo == null)
                {
                    continue;
                }
                TilesetData.Tileset tileset = TilesetData.GetTileset(tileInfo.Item2);
                if (tileset != null)
                {
                    if (tileset.GetBushFlag(tileInfo.Item1))
                    {
                        return(true);
                    }
                }
            }

            return(base.BushFlag());
        }
Exemple #4
0
        public override bool BushFlag()
        {
            if (_mapEvent.Priority == RenderPriority.OnTop)
            {
                return(false);
            }
            MapData data = MapComponent.Instance.GetMapInstance().GetMapData();

            for (int i = 0; i < 3; i++)
            {
                float x = _mapEvent.RealX;
                float y = _mapEvent.RealY;
                if ((x % 32) / 32f < 0.5)
                {
                    x = (int)Math.Floor(x / 32);
                }
                else
                {
                    x = (int)Math.Ceiling(x / 32);
                }

                if ((y % 32) / 32f < 0.3)
                {
                    y = (int)Math.Floor(y / 32);
                }
                else
                {
                    y = (int)Math.Ceiling(y / 32);
                }

                Tuple <int, int> tileInfo = data.GetTile(i, (int)x, (int)y);
                if (tileInfo != null)
                {
                    TilesetData.Tileset tileset = TilesetData.GetTileset(tileInfo.Item2);
                    if (tileset != null)
                    {
                        if (tileset.GetBushFlag(tileInfo.Item1))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(base.BushFlag());
        }
Exemple #5
0
        private void GenerateMapMeshes()
        {
            _MapTileMeshes.Clear();
            Dictionary <string, List <TileInfo> > tiles = new Dictionary <string, List <TileInfo> >();

            for (int layer = 0; layer < MapData.NUM_LAYERS; layer++)
            {
                for (int x = 0; x < _mapInstance.GetMapData().GetWidth(); x++)
                {
                    for (int y = 0; y < _mapInstance.GetMapData().GetHeight(); y++)
                    {
                        Tuple <int, int> tileInfo = _mapInstance.GetMapData().GetTile(layer, x, y);
                        if (tileInfo == null)
                        {
                            continue;
                        }
                        int tileID = tileInfo.Item1;
                        if (tileID == 0)
                        {
                            continue;
                        }
                        int tilesetID = tileInfo.Item2;
                        if (tilesetID == -1)
                        {
                            continue;
                        }

                        TilesetData.Tileset tileset = TilesetData.GetTileset(tilesetID);

                        TileInfo tileInfo2;
                        tileInfo2.Layer     = layer;
                        tileInfo2.X         = x;
                        tileInfo2.Y         = y;
                        tileInfo2.TileID    = tileID;
                        tileInfo2.TilesetID = tilesetID;

                        string key;

                        if (tileID < 8)
                        {
                            key = "AutoTiles/" + tileset.GetAutoTile(tileID - 1) + "," + tilesetID + "," + tileID;
                        }
                        else
                        {
                            key = "Tilesets/" + tileset.ImagePath + "," + tilesetID;
                        }

                        if (!tiles.ContainsKey(key))
                        {
                            tiles.Add(key, new List <TileInfo>());
                        }

                        tiles[key].Add(tileInfo2);
                    }
                }
            }

            int[] hashValues = new int[] { 1, 2, 4, 8, 16, 32, 64, 128 };
            int[,] offsets = new int[, ] {
                { 0, -1 }, { 1, -1 }, { 1, 0 }, { 1, 1 }, { 0, 1 }, { -1, 1 }, { -1, 0 }, { -1, -1 }
            };
            Tuple <int, int> targetInfo;

            for (int i = 0; i < tiles.Count; i++)
            {
                string key                  = tiles.ElementAt(i).Key;
                string textureName          = key.Split(',')[0];
                int    tilesetID            = tiles.ElementAt(i).Value[0].TilesetID;
                TilesetData.Tileset tileset = TilesetData.GetTileset(tilesetID);
                Texture             texture = Assets.GetTexture(textureName);
                bool isAutoTiles            = textureName.StartsWith("AutoTiles/");

                MapTileMeshData regularMeshData    = new MapTileMeshData(false, isAutoTiles, tileset, texture);
                MapTileMeshData reflectionMeshData = new MapTileMeshData(true, isAutoTiles, tileset, texture);

                for (int j = 0; j < tiles[key].Count; j++)
                {
                    int layer    = tiles[key][j].Layer;
                    int x        = tiles[key][j].X;
                    int y        = tiles[key][j].Y;
                    int tileID   = tiles[key][j].TileID;
                    int hashCode = -1;

                    if (isAutoTiles)
                    {
                        hashCode = 0;
                        for (int k = 0; k < 8; k++)
                        {
                            targetInfo = _mapInstance.GetMapData().GetTile(layer, x + offsets[k, 0], y + offsets[k, 1]);
                            if (targetInfo == null)
                            {
                                hashCode += hashValues[k];
                            }
                            else if (targetInfo.Item1 == tileID && targetInfo.Item2 == tilesetID)
                            {
                                hashCode += hashValues[k];
                            }
                        }
                    }

                    bool isReflection = tileset.GetReflectionFlag(tileID);
                    if (isReflection)
                    {
                        if (isAutoTiles)
                        {
                            reflectionMeshData.AddAutoMapTile(tileID, x, y, layer, hashCode);
                            reflectionMeshData.NumFrames  = texture.GetWidth() / 96;
                            reflectionMeshData.AutoTileID = tileID;
                        }
                        else
                        {
                            reflectionMeshData.AddRegularMapTile(tileID, x, y, layer);
                        }
                    }
                    else
                    {
                        if (isAutoTiles)
                        {
                            regularMeshData.AddAutoMapTile(tileID, x, y, layer, hashCode);
                            regularMeshData.NumFrames  = texture.GetWidth() / 96;
                            regularMeshData.AutoTileID = tileID;
                        }
                        else
                        {
                            regularMeshData.AddRegularMapTile(tileID, x, y, layer);
                        }
                    }
                }

                regularMeshData.Ready    = true;
                reflectionMeshData.Ready = true;

                if (regularMeshData.Valid())
                {
                    _MapTileMeshes.Add(regularMeshData);
                }
                if (reflectionMeshData.Valid())
                {
                    _MapTileMeshes.Add(reflectionMeshData);
                }
            }
        }