Exemple #1
0
        public void Read(System.IO.BinaryReader r)
        {
            Width  = r.ReadInt32();
            Height = r.ReadInt32();
            Tiles  = new Tile.Tile[Width, Height];

            int tc = r.ReadInt32();

            List <Tile.Tile> UniqueTiles = new List <Tile.Tile>();

            for (int i = 0; i < tc; i++)
            {
                var lt = new Tile.Tile(r);
                UniqueTiles.Add(lt);
            }


            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    int tid = r.ReadInt32();
                    if (tid == -1)
                    {
                        continue;
                    }
                    Tiles[x, y] = UniqueTiles[tid];
                }
            }
            Owner.sceneChanged = true;
        }
        /** Load a set of renderables
         */
        public void ExecuteRenderableLoading()
        {
            long j = (long)renderablesLoadQueue.Size;

            if (j != 0)
            {
                if (j > Options.Instance.Num_Renderables_Loading)
                {
                    j = Options.Instance.Num_Renderables_Loading;
                }
                for (long i = 0; i < j; i++)
                {
                    Renderable rend = renderablesLoadQueue.Pop( );
                    if (rend != null)
                    {
                        rend.Load();
                        Tile.Tile tile = tilesLoadQueue.Pop( );
                        // make sure tile had not been unloaded til queue insertion
                        if (tile.IsLoaded)
                        {
//							Debug.Assert(tile != null &&  tile.getTileNode ());
                            // only attach if renderable loaded
                            tile.TileNode.AttachObject(rend);
                            tile.LinkRenderableNeighbor();
                        }
                    }
                }
            }
        }
        /** Get the real world height at a particular position
         *      @remarks
         *      Method is used to get the terrain height at a world position based on x and z.
         *      This method just figures out what page the position is on and then asks the page node
         *      to do the dirty work of getting the height.
         *
         *      @par
         *      the float returned is the real world height based on the scale of the world.  If the height could
         *      not be determined then -1 is returned and this would only occur if the page was not preloaded or loaded
         *
         *      @param x  x world position
         *      @param z  z world position
         */
        public float GetRealWorldHeight(float x, float z)
        {
            // figure out which page the point is on
            Vector3 pos = new Vector3(x, 0, z);
            long    dataX, dataZ;

            GetPageIndices(pos, out dataX, out dataZ);

            if (data2D[dataX][dataZ].Dynamic)

            {
                return(GetRealPageHeight(x, z, dataX, dataZ, 0));
            }

            else

            {
                if (!(data2D[dataX][dataZ].IsLoaded))
                {
                    return(0.0f);
                }

                // figure out which tile the point is on
                Tile.Tile t   = PageManager.Instance.GetTile(pos, dataX, dataZ);
                long      Lod = 0;
                if (t != null && t.IsLoaded)
                {
                    Lod = t.Renderable.RenderLevel;
                }

                return(GetRealPageHeight(x, z, dataX, dataZ, Lod));
            }
        }
Exemple #4
0
 public void Fill(Tile.Tile tile)
 {
     for (int y = 0; y < Height; y++)
     {
         for (int x = 0; x < Width; x++)
         {
             Tiles[x, y] = tile;
         }
     }
     Owner.sceneChanged = true;
 }
Exemple #5
0
        public void Load(string path)
        {
            FileStream   fs = new FileStream(path, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);

            int c = br.ReadInt32();

            for (int i = 0; i < c; i++)
            {
                var tile = new Tile.Tile(br);
                Tiles.Add(tile);
            }
        }
Exemple #6
0
 public MapLayer(int width, int height, Map owner)
 {
     Tiles  = new Tile.Tile[width, height];
     Width  = width;
     Height = height;
     for (int y = 0; y < height; y++)
     {
         for (int x = 0; x < width; x++)
         {
             Tiles[x, y] = null;
         }
     }
     this.Owner = owner;
 }
Exemple #7
0
 public virtual void Clear()
 {
     for (var i = 0; i < SizeGeneratior.WorldWidth; i++)
     {
         for (var j = 0; j < SizeGeneratior.WorldHeight; j++)
         {
             MapTile[i, j] = new Tile.Tile(this);
         }
     }
     Active = false;
     StructuresList.Clear();
     Zombies.Clear();
     IsPortal = false;
 }
Exemple #8
0
        /// <summary>
        /// Deletes this tree and all its subelements.
        /// Releases all the corresponding texture tiles.
        /// </summary>
        /// <param name="owner"></param>
        public void RecursiveDelete(TileSampler owner)
        {
            if (Tile != null && owner != null)
            {
                owner.Producer.PutTile(Tile);

                Tile = null;
            }

            if (!IsLeaf)
            {
                for (byte i = 0; i < 4; i++)
                {
                    Children[i].RecursiveDelete(owner);
                    Children[i] = null;
                }
            }
        }
        public float GetRealWorldHeight(float x, float z, TileInfo info)
        {
            // figure out which page the point is on
            long dataX = info.PageX;
            long dataZ = info.PageZ;

            if (!(data2D[dataX][dataZ].IsLoaded))
            {
                return(0.0f);
            }

            Tile.Tile t   = PageManager.Instance.GetPage(dataX, dataZ).GetTile(info.TileX, info.TileZ);
            long      Lod = 0;

            if (t != null && t.IsLoaded)
            {
                Lod = t.Renderable.RenderLevel;
            }

            return(GetRealPageHeight(x, z, dataX, dataZ, Lod));
        }
Exemple #10
0
        public Board(
            BoardData inData,
            Game.Game inGame,
            int seed)
        {
            // Set data
            boardSize = new Tuple <int, int>(inData.xSize, inData.ySize);
            _game     = inGame;

            // Create board tiles
            tiles = new ITileSimulation[inData.xSize, inData.ySize];
            int runningIndex = 0;

            for (int i = 0; i < inData.xSize; i++)
            {
                for (int e = 0; e < inData.ySize; e++)
                {
                    tiles[i, e] = new Tile.Tile(this)
                    {
                        boardPosition = new Tuple <int, int>(i, e),
                        boardIndex    = runningIndex
                    };
                    runningIndex++;
                }
            }

            // Distribute bombs amongst tiles
            totalBombs     = DistributeBombs(inData.bombProbability, tiles, seed);
            flagsRemaining = totalBombs;

            // Assign "neighbor numbers"
            SetNeighborNumbers(tiles, inData.xSize, inData.ySize);

            // Tiles are finished setting up
            OnBoardSetupComplete(tiles);
        }
Exemple #11
0
        /** Loads the landscape using parameters in the given in the constructor. */
        public void Load(ref SceneNode RootNode)
        {
            if (isPreLoaded == false)
            {
                return;
            }

            if (isLoaded == true)
            {
                return;
            }

            Texture.TextureManager.Instance.Load(tableX, tableZ);
            //create a root landscape node.
            pageNode = RootNode.CreateChildSceneNode("Page." + tableX.ToString() + "." + tableZ.ToString());
            // Set node position
            pageNode.Position = new Vector3((float)iniX, 0.0f, (float)iniZ);

            tiles = new Tiles();
            for (long i = 0; i < numTiles; i++)
            {
                tiles.Add(new TileRow());

                for (long j = 0; j < numTiles; j++)
                {
                    //Debug.WriteLine(String.Format("Page[{0},{1}][{2},{3}]",tableX,tableZ,i,j));

                    Tile.Tile tile = TileManager.Instance.GetTile();
                    if (tile != null)
                    {
                        tiles[i].Add(tile);
                        tile.Init(ref pageNode, (int)tableX, (int)tableZ, (int)i, (int)j);
                    }
                    else
                    {
                        string err = "Error: Invalid Tile: Make sure the default TileManager size is set to WorldWidth * WorldHeight * 4. Try increasing MaxNumTiles in the configuration file.";
                        throw new ApplicationException(err);
                    }
                }
            }

            for (long j = 0; j < numTiles; j++)
            {
                for (long i = 0; i < numTiles; i++)
                {
                    if (j != numTiles - 1)
                    {
                        tiles[i][j].SetNeighbor(Neighbor.South, tiles[i][j + 1]);
                        tiles[i][j + 1].SetNeighbor(Neighbor.North, tiles[i][j]);
                    }
                    if (i != numTiles - 1)
                    {
                        tiles[i][j].SetNeighbor(Neighbor.East, tiles[i + 1][j]);
                        tiles[i + 1][j].SetNeighbor(Neighbor.West, tiles[i][j]);
                    }
                }
            }

            LinkTileNeighbors();
            pageNode.NeedUpdate();
            isLoaded = true;
        }
Exemple #12
0
 public void SetTile(int x, int y, Tile.Tile tile)
 {
     Tiles[x, y]        = tile;
     Owner.sceneChanged = true;
 }
 internal override void CollidedWithTile(Tile.Tile tile)
 {
     Dispose();
     base.CollidedWithTile(tile);
 }
        public void Update(Camera cam)
        {
            // Here we have to look if we have to load, unload any of the LandScape Pages
            //Vector3 pos = cam.getPosition();
            // Fix from Praetor, so the camera used gives you "world-relative" coordinates
            Vector3 pos = cam.DerivedPosition;

            //updateStats( pos );

            // Update only if the camera was moved
            // make sure in the bounding box of landscape
            pos.y = 127.0f;
            if (Options.Instance.CameraThreshold <= (lastCameraPos - pos).LengthSquared)
            {
                // Check for the camera position in the LandScape Pages list, we check if we are in the inside the security zone
                //  if not, launch the change routine and update the camera position currentCameraX, currentCameraY.
                if (pages[currentCameraPageX][currentCameraPageZ] != null &&
                    (
                        pages[currentCameraPageX][currentCameraPageZ].IsLoaded == false ||
                        pages[currentCameraPageX][currentCameraPageZ].IsCameraIn(pos) != CameraPageState.Inside
                    )
                    )
                {
                    // JEFF
                    // convert camera pos to page index
                    long i, j;
                    Data2DManager.Instance.GetPageIndices(pos, out i, out j);
                    //if (((currentCameraPageX != i) || (currentCameraPageZ != j)) &&
                    Debug.Assert(i < width && j < heigth, "Page Indices out of bounds");
                    if ((pages[i] [j] == null) ||
                        (pages[i][j].IsCameraIn(pos) != CameraPageState.Outside)
                        )
                    {
                        long adjpages = Options.Instance.Max_Adjacent_Pages;
                        long prepages = Options.Instance.Max_Preload_Pages;
                        long w        = width;
                        long h        = heigth;

                        // We must load the next visible landscape pages,
                        // and unload the last visibles
                        // check the landscape boundaries

                        long iniX = ((int)(i - adjpages) > 0)? i - adjpages: 0;
                        long iniZ = ((int)(j - adjpages) > 0)? j - adjpages: 0;
                        long finX = (i + adjpages >= w)? w - 1: i + adjpages;
                        long finZ = (j + adjpages >= h)? h - 1: j + adjpages;

                        long preIniX = ((int)(i - prepages) > 0)? i - prepages: 0;
                        long preIniZ = ((int)(j - prepages) > 0)? j - prepages: 0;
                        long preFinX = (i + prepages >= w)?  w - 1: i + prepages;
                        long preFinZ = (j + prepages >= h)? h - 1: j + prepages;


                        // update the camera page position
                        currentCameraPageX = i;
                        currentCameraPageZ = j;


                        // Have the current page be loaded now
                        if (pages[currentCameraPageX][currentCameraPageZ].IsPreLoaded == false)
                        {
                            pages[currentCameraPageX][currentCameraPageZ].Preload();
                        }
                        if (pages[currentCameraPageX][currentCameraPageZ].IsLoaded == false)
                        {
                            pages[currentCameraPageX][currentCameraPageZ].Load(ref sceneRoot);
                        }
                        // Queue the rest

                        // Loading and unloading must be done one by one to avoid FPS drop, so they are queued.
                        // No need to queue for preload since _ProcessLoading will do it in Load if required.

                        // post unload as required
                        for (j = 0; j < preIniZ; j++)
                        {
                            for (i = 0; i < preIniX; i++)
                            {
                                pageUnloadQueue.Push(pages[i][j]);
                            }
                        }
                        for (j = preFinZ + 1; j < h; j++)
                        {
                            for (i = preFinX + 1; i < w; i++)
                            {
                                pageUnloadQueue.Push(pages[i][j]);
                            }
                        }

                        // Preload as required
                        for (j = preIniZ; j < iniZ; j++)
                        {
                            for (i = preIniX; i < iniX; i++)
                            {
                                pagePreloadQueue.Push(pages[i][j]);
                            }
                        }
                        for (j = finZ; j <= preFinZ; j++)
                        {
                            for (i = finX; i <= preFinX; i++)
                            {
                                pagePreloadQueue.Push(pages[i][j]);
                            }
                        }
                        // load as required
                        for (j = iniZ; j <= finZ; j++)
                        {
                            for (i = iniX; i <= finX; i++)
                            {
                                if (!pages[i][j].IsLoaded)
                                {
                                    pageLoadQueue.Push(pages[i][j]);
                                }
                            }
                        }
                    }
                }
                // Update the last camera position
                lastCameraPos = pos;
                Tile.Tile t = GetTile(pos, (long)currentCameraPageX, (long)currentCameraPageZ);
                if (t != null)
                {
                    Tile.TileInfo CurrentTileInfo = t.Info;
                    if (CurrentTileInfo != null)
                    {
                        currentCameraTileX = CurrentTileInfo.TileX;
                        currentCameraTileZ = CurrentTileInfo.TileZ;
                    }
                }
            }

            // Check for visibility
            Camera plsmCam = (cam);

            for (long j = 0; j < heigth; j++)
            {
                for (long i = 0; i < width; i++)
                {
                    pages[i][j].Notify(pos, plsmCam);
                }
            }

            // Preload, load, unload and post unload as required
            this.processLoading();
        }
Exemple #15
0
 void AddTile(Tile.Tile tile)
 {
     Tiles.Add(tile);
 }
Exemple #16
0
        public void LinkTileNeighbors()
        {
            if (neighbors[(int)Neighbor.East] != null)
            {
                if (neighbors[(int)Neighbor.East].IsLoaded)
                {
                    long i = numTiles - 1;
                    for (long j = 0; j < numTiles; j++)
                    {
                        Tile.Tile t_nextpage = neighbors[(int)Neighbor.East].GetTile(0, j);
                        Tile.Tile t_currpage = tiles[i][j];
                        //Debug.Assert(t_nextpage != null && t_currpage != null);
                        if (t_nextpage != null && t_currpage != null)
                        {
                            t_currpage.SetNeighbor(Neighbor.East, t_nextpage);
                            t_nextpage.SetNeighbor(Neighbor.West, t_currpage);
                        }
                    }
                }
            }
            if (neighbors[(int)Neighbor.West] != null)
            {
                if (neighbors[(int)Neighbor.West].IsLoaded)
                {
                    long i = numTiles - 1;
                    for (long j = 0; j < numTiles; j++)
                    {
                        Tile.Tile t_nextpage = neighbors[(int)Neighbor.West].GetTile(i, j);
                        Tile.Tile t_currpage = tiles[0][j];
                        //Debug.Assert(t_nextpage != null && t_currpage != null);
                        if (t_nextpage != null && t_currpage != null)
                        {
                            t_currpage.SetNeighbor(Neighbor.West, t_nextpage);
                            t_nextpage.SetNeighbor(Neighbor.East, t_currpage);
                        }
                    }
                }
            }

            if (neighbors[(int)Neighbor.South] != null)
            {
                if (neighbors[(int)Neighbor.South].IsLoaded)
                {
                    long j = numTiles - 1;
                    for (long i = 0; i < numTiles; i++)
                    {
                        Tile.Tile t_nextpage = neighbors[(int)Neighbor.South].GetTile(i, 0);
                        Tile.Tile t_currpage = tiles[i][j];
                        //Debug.Assert(t_nextpage != null  && t_currpage != null);
                        if (t_nextpage != null && t_currpage != null)
                        {
                            t_currpage.SetNeighbor(Neighbor.South, t_nextpage);
                            t_nextpage.SetNeighbor(Neighbor.North, t_currpage);
                        }
                    }
                }
            }
            if (neighbors[(int)Neighbor.North] != null)
            {
                if (neighbors[(int)Neighbor.North].IsLoaded)
                {
                    long j = numTiles - 1;
                    for (long i = 0; i < numTiles; i++)
                    {
                        Tile.Tile t_nextpage = neighbors[(int)Neighbor.North].GetTile(i, j);
                        Tile.Tile t_currpage = tiles[i][0];
                        //Debug.Assert(t_nextpage != null && t_currpage != null);
                        if (t_nextpage != null && t_currpage != null)
                        {
                            t_currpage.SetNeighbor(Neighbor.North, t_nextpage);
                            t_nextpage.SetNeighbor(Neighbor.South, t_currpage);
                        }
                    }
                }
            }
        }
 internal virtual void CollidedWithTile(Tile.Tile tile)
 {
 }
 /** Set this renderable to be loaded
  */
 public void QueueRenderableLoading(Renderable rend, Tile.Tile tile)
 {
     renderablesLoadQueue.Push(rend);
     tilesLoadQueue.Push(tile);
 }