Inheritance: IScheduledTask
 public void SetPageMode(Vector3 addr, CachingMode mode)
 {
     if (mode == CachingMode.Cold)
     {
         AbstractPage page = m_map.GetPage(addr);
         if (page == null)
         {
             throw new ArgumentException("No uncached page at this address.");
         }
         Cache(page);
     }
     else
     {
         try
         {
             AbstractPage coldpage = m_map.GetPage(addr);
             AbstractPage page     = Wake(addr);
             page.cacheMode = mode;
             if (coldpage != null)
             {
                 m_map.RemovePage(coldpage);
             }
             m_map.AddPage(page, addr);
         }
         catch (System.IO.FileNotFoundException)
         {
             throw new ArgumentException("No cached page at this address.");
         }
     }
 }
        public AbstractSquare GetSquare(AbstractPage p, Vector3 offset)
        {
            Vector3 npos = new Vector3(p.address.X * PageSize.X + offset.X,
                                       p.address.Y * PageSize.Y + offset.Y,
                                       p.address.Z * PageSize.Z + offset.Z);

            return(GetSquare(npos));
        }
Exemple #3
0
        public AbstractSquare GetSquare(AbstractPage p, Vector3 offset)
        {
            Vector3 npos = new Vector3(p.address.x * pageSize.x + offset.x,
                                       p.address.y * pageSize.y + offset.y,
                                       p.address.z * pageSize.z + offset.z);

            return(GetSquare(npos));
        }
 public void SetPageMode(AbstractPage page, CachingMode mode)
 {
     if (page.cacheMode == mode)
     {
         return;
     }
     SetPageMode(page.address, mode);
 }
        public void SwapEntityCallbackOwner(AbstractEntity ent, AbstractPage oldpage, AbstractPage newpage)
        {
            List <PageCallbackInfo> pci = oldpage.RemoveAllAIDelegates(ent);

            foreach (PageCallbackInfo callback in pci)
            {
                newpage.RegisterAIDelegate(callback);
            }
        }
 public void Cache(AbstractPage page)
 {
     Console.WriteLine("Caching " + page.address.ToString());
     FileStream file = new FileStream(Game.PathTo("cache/" + CacheName(page.address) + ".dat"), FileMode.Create);
     BinaryFormatter f = new BinaryFormatter();
     f.Serialize(file, page);
     file.Close();
     m_map.RemovePage(page);
     m_map.AddPage(new ColdPage(m_map.PageSize), page.address);
 }
        bool IsPageVisible(AbstractPage p)
        {
            Vector3 worldloc = new Vector3(
                p.address.X * PageSize.X,
                p.address.Y * PageSize.Y,
                p.address.Z * PageSize.Z);
            Rectangle pagerect = new Rectangle(new Point(worldloc.X, worldloc.Y), new Size(p.Size.X, p.Size.Y));

            return(pagerect.IntersectsWith(this.Viewport) && view.Z >= worldloc.Z && view.Z < worldloc.Z + PageSize.Z);
        }
Exemple #8
0
        bool IsPageVisible(AbstractPage p)
        {
            Vector3 worldloc = new Vector3(
                p.address.x * pageSize.x,
                p.address.y * pageSize.y,
                p.address.z * pageSize.z);
            Rectangle pagerect = new Rectangle(new Point(worldloc.x, worldloc.y), new Size(p.Size.x, p.Size.y));

            return(pagerect.IntersectsWith(this.Viewport) && view.z >= worldloc.z && view.z < worldloc.z + pageSize.z);
        }
        public void Cache(AbstractPage page)
        {
            Console.WriteLine("Caching " + page.address.ToString());
            FileStream      file = new FileStream(Game.PathTo("cache/" + CacheName(page.address) + ".dat"), FileMode.Create);
            BinaryFormatter f    = new BinaryFormatter();

            f.Serialize(file, page);
            file.Close();
            m_map.RemovePage(page);
            m_map.AddPage(new ColdPage(m_map.PageSize), page.address);
        }
        public AbstractPage Wake(Vector3 addr)
        {
            Console.WriteLine("Waking " + addr.ToString());
            string          path = Game.PathTo("cache/" + CacheName(addr) + ".dat");
            FileStream      file = new FileStream(path, FileMode.Open);
            BinaryFormatter f    = new BinaryFormatter();
            AbstractPage    page = (AbstractPage)f.Deserialize(file);

            file.Close();
            File.Delete(path);
            return(page);
        }
        public void RemovePage(AbstractPage page)
        {
            List <Vector3> keys = new List <Vector3>();

            foreach (KeyValuePair <Vector3, AbstractPage> pair in Pages)
            {
                if (pair.Value == page)
                {
                    keys.Add(pair.Key);
                }
            }
            foreach (Vector3 key in keys)
            {
                Pages.Remove(key);
            }
        }
        internal void RemoveEntity(AbstractEntity ent)
        {
            Vector3 addr;
            Vector3 newoff;

            Vector3.Divide(ent.Location, this.PageSize, out addr, out newoff);

            if (ent.Location.IntersectsWith(this.Viewport) && ent.Location.Z == view.Z)
            {
                this.RegionTiles[ent.Location.X - view.X, ent.Location.Y - view.Y].RemoveGlyphProvider(ent);
            }

            AbstractPage p = Pages[addr];

            if (p != null)
            {
                p.Entities.Remove(ent);
            }
        }
Exemple #13
0
        internal void AddEntity(AbstractEntity ent)
        {
            Vector3 addr;
            Vector3 newoff;

            Vector3.Divide(ent.Location, this.pageSize, out addr, out newoff);

            if (ent.Location.IntersectsWith(this.Viewport) && ent.Location.z == view.z)
            {
                this.RegionTiles[ent.Location.x - view.x, ent.Location.y - view.y].AddGlyphProvider(ent);
            }

            AbstractPage p = Pages[addr];

            if (p != null)
            {
                p.Entities.Add(ent);
            }
        }
Exemple #14
0
        public void AddPage(AbstractPage newPage, Vector3 pageLocation)
        {
            if (newPage.Size.Equals(this.pageSize) == false)
            {
                throw new ArgumentException("All pages must be the size specified to the Map object.");
            }

            if (Pages.ContainsKey(pageLocation))
            {
                throw new ArgumentException("Page already exists at " + pageLocation.ToString() + ".");
            }

            /*
             * Vector3 n = new Vector3(here.x, here.y - 1, here.z);
             * Vector3 s = new Vector3(here.x, here.y + 1, here.z);
             * Vector3 e = new Vector3(here.x + 1, here.y, here.z);
             * Vector3 w = new Vector3(here.x - 1, here.y, here.z);
             * Vector3 u = new Vector3(here.x, here.y, here.z - 1);
             * Vector3 d = new Vector3(here.x, here.y, here.z + 1);
             * bool valid = pages.Count == 0 ||
             *      (false &&
             *      (pages.ContainsKey(n) ||
             *       pages.ContainsKey(s) ||
             *       pages.ContainsKey(e) ||
             *       pages.ContainsKey(w) ||
             *       pages.ContainsKey(u) ||
             *       pages.ContainsKey(d)));
             * if (!valid)
             * {
             *      throw new ArgumentException("Provided coordinates for new page are not contiguous with existing pages.");
             * }
             */
            newPage.parentMap = this;
            newPage.address   = pageLocation;

            Game.Scheduler.AddTask(newPage);

            Pages.Add(pageLocation, newPage);
            newPage.Build();
        }
        /// <summary>
        /// Adds the passed in page to this map, at the specified map slot.
        /// </summary>
        /// <param name="newPage">The page to add to this map.</param>
        /// <param name="pageLocation">The map slot to place this page.</param>
        public void AddPage(AbstractPage newPage, Vector3 pageLocation)
        {
            if (newPage.Size.Equals(this.PageSize) == false)
            {
                throw new ArgumentException("All pages must be the size specified to the Map object.");
            }

            if (Pages.ContainsKey(pageLocation))
            {
                throw new ArgumentException("Page already exists at " + pageLocation.ToString() + ".");
            }

            // Let's allow them to make disjointed space -- maybe they have infinite terrain, as well as teleportation
            //bool Found = false;
            //for (int dx = -1; dx <= 1; dx++) {
            //    for (int dy = -1; dy <= 1; dy++) {
            //        for (int dz = -1; dz <= 1; dz++){
            //            if (Pages.ContainsKey(pageLocation + new Vector3(dx, dy, dz))) {
            //                Found = true;
            //                break;
            //            }
            //        }
            //        if (Found) break;
            //    }
            //    if (Found) break;
            //}
            //if (!Found)
            //{
            //    throw new ArgumentException("Provided coordinates for new page are not contiguous with existing pages.");
            //}

            newPage.ParentMap = this;
            newPage.address   = pageLocation;

            Game.Scheduler.AddTask(newPage);

            Pages.Add(pageLocation, newPage);
            newPage.Build();
        }
 public void SetPageMode(AbstractPage page, CachingMode mode)
 {
     if (page.cacheMode == mode) return;
     SetPageMode(page.address, mode);
 }