Inheritance: IScheduledTask
Exemplo n.º 1
0
 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.");
         }
     }
 }
Exemplo n.º 2
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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 4
0
 public void SetPageMode(AbstractPage page, CachingMode mode)
 {
     if (page.cacheMode == mode)
     {
         return;
     }
     SetPageMode(page.address, mode);
 }
Exemplo n.º 5
0
        public void SwapEntityCallbackOwner(AbstractEntity ent, AbstractPage oldpage, AbstractPage newpage)
        {
            List <PageCallbackInfo> pci = oldpage.RemoveAllAIDelegates(ent);

            foreach (PageCallbackInfo callback in pci)
            {
                newpage.RegisterAIDelegate(callback);
            }
        }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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);
            }
        }
Exemplo n.º 12
0
        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);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 15
0
        /// <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();
        }
Exemplo n.º 16
0
 public void SetPageMode(AbstractPage page, CachingMode mode)
 {
     if (page.cacheMode == mode) return;
     SetPageMode(page.address, mode);
 }