GetChunk() public abstract méthode

public abstract GetChunk ( Vector3i ChunkPos ) : Chunk
ChunkPos Vector3i
Résultat Chunk
Exemple #1
0
        public override void DoSkyLighting(IMapHandler _mh, long X, long Y)
        {
            Chunk c = _mh.GetChunk(X, Y);

            if (c == null)
            {
                return;
            }
            this.DoSkylighting(c);
        }
Exemple #2
0
 /// <summary>
 /// Initialize and set up events for this MapChunk.
 /// </summary>
 /// <param name="mc">Parent mapcontrol</param>
 /// <param name="pos">Position of chunk</param>
 /// <param name="sz">Chunk size</param>
 public MapChunkControl(MapControl mc,Vector3i pos,Vector3i sz)
 {
     parent=mc;
     Map = parent.Map;
     AssignedChunk = pos;
     ChunkSize = sz;
     MyChunk = Map.GetChunk(AssignedChunk);
     //Console.WriteLine("{0}: Chunk ({1},{2}), origin ({3},{4}), size {5}", this, pos.X, pos.Y, pos.X * sz.X, pos.Y * sz.Y, sz);
     InitializeComponent();
     Paint += new PaintEventHandler(MapChunkControl_Paint);
 }
Exemple #3
0
 public override void DoSkyLighting(IMapHandler _mh, long X, long Y)
 {
     Chunk c = _mh.GetChunk(X, Y);
     if (c == null) return;
     this.DoSkylighting(c);
 }
Exemple #4
0
        public void UpdateCache()
        {
            TileEntities.Clear();
            Entities.Clear();
            SQLiteTransaction trans = database.BeginTransaction();
            int numChunksChanged    = 0;
            int numNewChunks        = 0;
            int numChunksTotal      = 0;

            //mThread = new Thread(delegate()
            //{
            map.SetBusy("Updating cache...");
            map.SetBusy(string.Format("Please wait, {0}...\r\n{1} new, {2} changed", (FirstCache) ? "creating cache (may take a while)" : "updating cache", numNewChunks, numChunksChanged));
            Dimension[] dims = (Dimension[])map.GetDimensions();
            Dimension   dim  = dims[map.Dimension];

            map.ForEachChunkFile(dim.ID, delegate(IMapHandler _map, string file)
            {
                bool NeedsUpdate = false;
                bool NewChunk    = false;
                using (SQLiteCommand cmd = database.CreateCommand())
                {
                    Vector2i pos;
                    cmd.CommandText      = "SELECT cnkMD5,cnkX,cnkZ,dimID FROM Chunks WHERE cnkFile='" + file + "';";
                    SQLiteDataReader rdr = cmd.ExecuteReader();
                    if (!rdr.HasRows)
                    {
                        NewChunk    = true;
                        NeedsUpdate = true;
                        pos         = map.GetChunkCoordsFromFile(file, true);
                    }
                    else
                    {
                        pos = new Vector2i(
                            (int)((long)rdr["cnkX"]),
                            (int)((long)rdr["cnkZ"])
                            );
                        if (!mFileCoords.ContainsKey(file))
                        {
                            mFileCoords.Add(file, new Vector3i(pos.X, pos.Y,
                                                               (int)((long)rdr["dimID"])));
                        }
                    }

                    if (dim.MinimumChunk.X > pos.X)
                    {
                        dim.MinimumChunk.X = pos.X;
                    }
                    if (dim.MaximumChunk.X < pos.X)
                    {
                        dim.MaximumChunk.X = pos.X;
                    }
                    if (dim.MinimumChunk.Y > pos.Y)
                    {
                        dim.MinimumChunk.Y = pos.Y;
                    }
                    if (dim.MaximumChunk.Y < pos.Y)
                    {
                        dim.MaximumChunk.Y = pos.Y;
                    }

                    if (!NeedsUpdate)
                    {
                        if (rdr["cnkMD5"].ToString() != GetMD5HashFromFile(file))
                        {
                            NeedsUpdate = true;
                        }
                    }
                    if (NeedsUpdate)
                    {
                        if (NewChunk)
                        {
                            numNewChunks++;
                        }
                        else
                        {
                            numChunksChanged++;
                        }
                        if (pos == null)
                        {
                            return;
                        }
                        //Console.WriteLine(string.Format("Updating chunk {0} in {1} ({2})...", pos, dim.Name, file));
                        map.SetBusy(string.Format("Please wait, {0}...\r\n{1} new, {2} changed", (FirstCache) ? "creating cache (may take a while)" : "updating cache", numNewChunks, numChunksChanged));
                        Chunk c = map.GetChunk(pos.X, pos.Y);
                        map.UnloadChunks();
                    }
                    System.Windows.Forms.Application.DoEvents();
                }

                // Dump it from RAM onto disk to prevent bloat.
                if (numChunksChanged + numNewChunks % 500 == 499)
                {
                    Console.WriteLine("Saving cache...");
                    map.SetBusy(string.Format("Please wait, {0}...\r\n[Saving]", (FirstCache) ? "creating cache (may take a while)" : "updating cache"));
                    trans.Commit();
                    trans = database.BeginTransaction();
                    map.UnloadChunks();
                }
            });
            UpdateDimension(dim);
            map.SetIdle();
            trans.Commit();     // NOW save to disk.
            //});
            //mThread.Start();
        }