Exemple #1
0
        public Cluster(ClusterData data)
        {
            Type = data.Type;
              tiles = data.Tiles;
              Coordinates = data.Coordinates;

              SetHashCode();
              Active = false;
        }
        //public void InsertCluster(Cluster cluster)
        //{
        //  InsertCluster(cluster);
        //}
        private void GetClusterDataFromRow(DataRow row, out ClusterData data)
        {
            byte[] bytes = (byte[])row["data"];
              //using (MemoryStream memStream = new MemoryStream(bytes))
              //{
              //  memStream.Seek(0, SeekOrigin.Begin);
              //  data = (ClusterData)serializer.Deserialize(memStream);
              //  memStream.Close();
              //}

              const int clusterLength = Constants.ClusterWidth * Constants.ClusterHeight;

              data = new ClusterData();
              data.Tiles = new Tile[clusterLength];

              // Get huffman encoded tile data.
              using (MemoryStream stream = new MemoryStream(bytes))
              {
            data.Type = (ClusterType)stream.ReadByte();
            int tileIndex = 0;
            while (tileIndex < clusterLength)
            {
              //stream.Seek(streamIndex, SeekOrigin.End);
              TileType type = (TileType)stream.ReadByte();

              byte[] intCounter = new byte[4];

              for (int i = 0; i < 4; ++i)
            intCounter[i] = (byte)stream.ReadByte();

              int tileCount = BitConverter.ToInt32(intCounter, 0);

              for (int i = 0; i < tileCount; ++i)
              {
            data.Tiles[tileIndex++] = new Tile(type);
              }
            }
              }

              //for (int i = 1; i < clusterLength + 1; ++i)
              //{
              //  data.Tiles[i - 1] = new Tile((TileType)bytes[i]);
              //}

              Coordinates coords = new Coordinates();
              coords.X = BitConverter.ToInt32(bytes, bytes.Length - 8);
              coords.Y = BitConverter.ToInt32(bytes, bytes.Length - 4);
              data.Coordinates = coords;
        }
Exemple #3
0
        public void Load(ClusterData data)
        {
            if (HashCode != GetHashFromXY(data.Coordinates.X, data.Coordinates.Y))
              {
            throw new Exception("Data does not match the cluster");
              }
              squareRes = ResourceManager.TileTextureBank.Query("Grass");
              tiles = data.Tiles;

              SetHashCode();
        }
Exemple #4
0
 public ClusterData GetData()
 {
     ClusterData data = new ClusterData();
       data.Coordinates = Coordinates;
       data.Tiles = tiles;
       data.Type = Type;
       return data;
 }