コード例 #1
0
ファイル: WorldMap.cs プロジェクト: ALenfant/WorldEngine
        //Load a tile's heightmap (here uses the sin function)
        private void LoadTileHeightmap2(MapTile TileToLoad)
        {
            //return;
            //We don't use the debug sinus code
            if (TileToLoad != null)
            {
                //TimeSpan Start1 = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime;
                MTV3D65.CONST_TV_LANDSCAPE_PRECISION precision = TileToLoad.Landscape.GetPrecision();
                int Vertices = (256 / GlobalVars.getTVPrecisionDivider(precision)) * TileToLoad.Landscape.GetLandWidth();
                float[] Height_Array = new float[(Vertices + 1) * (Vertices + 1)];
                for (int j = 0; j <= Vertices; j++)
                {
                    for (int i = 0; i <= Vertices; i++)
                    {
                        if ((TileToLoad.TilePosition.TileX == -1) && (TileToLoad.TilePosition.TileZ == 0) && (j == Vertices - 1) && (i == Vertices - 1))
                        {
                            Debug.WriteLine("debug");
                        }

                        int realx = i + TileToLoad.TilePosition.TileX * Vertices;
                        int realz = j + TileToLoad.TilePosition.TileZ * Vertices;

                        //Sinus-like thing... Yeah, it's useless but it looks good (well, for a demo... okay, I'm not that inspired I think !)
                        Height_Array[j * (Vertices + 1) + i] = (float)(Math.Sin(Math.Sqrt(Math.Pow(realx, 2) + Math.Pow(realz, 2)) / 25) * 100);
                    }
                }
                TileToLoad.Landscape.SetHeightArray(0, 0, Vertices + 1, Vertices + 1, Height_Array); //This is 100 TIMES FASTER than setting every point one by one! (which is not that surprising)

                //double Total1 = (System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime - Start1).TotalMilliseconds;

                //TimeSpan Start2 = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime;
                /*for (int i = TileToLoad.TilePosition.TileX * 256 * MapTile.TileSize; i <= TileToLoad.TilePosition.TileX * 256 * MapTile.TileSize + 256 * MapTile.TileSize; i += 2)
                {
                    for (int j = TileToLoad.TilePosition.TileZ * 256 * MapTile.TileSize; j <= TileToLoad.TilePosition.TileZ * 256 * MapTile.TileSize + 256 * MapTile.TileSize; j = j + 1)
                    {
                        TileToLoad.Landscape.SetHeight(i, j, (float)Math.Sin(Math.Sqrt(i * i + j * j) / 25) * 10);
                    }
                }*/
                //double Total2 = (System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime - Start2).TotalMilliseconds;

                //Debug.WriteLine("Method 1 : " + Total1 + "ms; Method 2 : " + Total2 + "ms");
                //Method 1 : 31,2002ms; Method 2 : 3120,02ms

                //TileToLoad.Landscape.FlushHeightChanges();
            }
        }
コード例 #2
0
        //Check if there are tiles to load and load them
        public bool CheckLoadTiles(bool force = false) //Force : force the reload of all the tiles
        {
            System.Diagnostics.Debug.WriteLine("Start loadtiles (" + WorldPos.TileX + "," + WorldPos.TileZ + ")");
            if (force || ((PlayerPos.TileX != WorldPos.TileX) || (PlayerPos.TileZ != WorldPos.TileZ)))
            {
                //The player moved too much
                LoadingMapTiles = true;
                System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Highest;

                int TilesMoveX = PlayerPos.TileX - WorldPos.TileX;
                int TilesMoveZ = PlayerPos.TileZ - WorldPos.TileZ;

                TimeSpan CheckLandscapeBegin = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime;

                //We create the new MapTile which will contain the new terrains
                MapTile[][]          MapTiles_New  = new MapTile[2 * RenderedTilesDistance + 1][];// = MapTiles = new MapTile[2 * RenderedTilesDistance + 1, 2 * RenderedTilesDistance + 1];
                LinkedList <MapTile> TilesList_New = new LinkedList <MapTile>();

                //We check all the new tiles to see if we have to create a new one or copy an old one
                for (short i = 0; i < (2 * RenderedTilesDistance + 1); i++)
                {
                    MapTiles_New[i] = new MapTile[2 * RenderedTilesDistance + 1];
                    for (short j = 0; j < (2 * RenderedTilesDistance + 1); j++)
                    {
                        int oldIndexX = i + TilesMoveX; //Correspondance to the old MapTiles
                        int oldIndexZ = j + TilesMoveZ; //Correspondance to the old MapTiles
                        if (!force && (((oldIndexX >= 0) && (oldIndexX <= 2 * RenderedTilesDistance)) && ((oldIndexZ >= 0) && (oldIndexZ <= 2 * RenderedTilesDistance))))
                        {
                            //The old index is valid, we just move the tile
                            MapTiles_New[i][j] = MapTiles[oldIndexX][oldIndexZ];
                        }
                        else
                        {
                            //New landscape, we create it
                            TimeSpan NewLandscapeBegin = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime;
                            MapTiles_New[i][j] = new MapTile(new TilePosition(PlayerPos.TileX + i - RenderedTilesDistance, PlayerPos.TileZ + j - RenderedTilesDistance));
                            TimeSpan NewLandscapeEnd = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime;
                            System.Diagnostics.Debug.WriteLine("New tile i:" + i + "(" + (PlayerPos.TileX + i - RenderedTilesDistance) + ");j:" + j + "(" + (PlayerPos.TileZ + j - RenderedTilesDistance) + ") - " + (NewLandscapeEnd - NewLandscapeBegin).TotalMilliseconds + " ms.");
                        }

                        if ((i - RenderedTilesDistance == 0) && (j - RenderedTilesDistance == 0))
                        {
                            //Player's tile
                            MapTiles_New[i][j].Landscape.SetTexture(GlobalVars.GameEngine.Globals.GetTex("LandTexture"), -1);
                            MapTiles_New[i][j].Landscape.SetTextureScale(3, 3, -1);
                        }
                        else
                        {
                            //Another tile
                            MapTiles_New[i][j].Landscape.SetTexture(GlobalVars.GameEngine.Globals.GetTex("LandTexture2"), -1);
                            MapTiles_New[i][j].Landscape.SetTextureScale(3, 3, -1);
                        }

                        TilePosition Position = new TilePosition(i - RenderedTilesDistance + PlayerPos.TileX, j - RenderedTilesDistance + PlayerPos.TileZ);

                        TilesHeightmapToLoad.Enqueue(Position, Position.TileDistanceTo(PlayerPos));

                        //LoadTileHeightmap(new TilePosition(i - RenderedTilesDistance, j - RenderedTilesDistance));
                        //LoadTileHeightmap2(MapTiles_New[i][j]);

                        WorldPosition SplatPosition = new WorldPosition(Position);

                        /*MapTiles_New[i][j].Landscape.AddSplattingTexture(GlobalVars.GameEngine.Globals.GetTex("SplattingTexture"), 1, 1, 1, 0, 0);
                         * MapTiles_New[i][j].Landscape.ExpandSplattingTexture(GlobalVars.GameEngine.Globals.GetTex("SplattingAlphaTexture"), GlobalVars.GameEngine.Globals.GetTex("SplattingTexture"), 0, 0, 4, 4);
                         * MapTiles_New[i][j].Landscape.SetSplattingEnable(true);*/
                        //AddSplattingToTile(SplatPosition, GlobalVars.GameEngine.Globals.GetTex("SplattingTexture"));

                        TilesList_New.AddLast(MapTiles_New[i][j]);
                    }
                }
                TimeSpan CheckLandscapeEnd = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime;

                //We replace the old tiles with the new ones
                MapTiles  = MapTiles_New;
                TilesList = TilesList_New;
                TimeSpan CopyMapTilesEnd = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime;

                WorldPos.TileX = PlayerPos.TileX;
                WorldPos.TileZ = PlayerPos.TileZ;

                //DEBUG : add a mesh to each tile

                /*for (short i = 0; i < (2 * RenderedTilesDistance + 1); i++)
                 * {
                 *  for (short j = 0; j < (2 * RenderedTilesDistance + 1); j++)
                 *  {
                 *      if (!MapTiles[i][j].MeshesLoaded) //DEBUG
                 *      {
                 *          MapTiles[i][j].MeshesLoaded = true; //DEBUG
                 *
                 *          //Debug : we add a mesh
                 *          TVMesh newmesh = new TVMesh();
                 *          newmesh = GlobalVars.GameEngine.Scene.CreateMeshBuilder();
                 *          newmesh.CreateTeapot();
                 *          newmesh.SetScale(50, 50, 50);
                 *          newmesh.SetCullMode(CONST_TV_CULLING.TV_BACK_CULL);
                 *          AddMeshToTile(new WorldPosition(i - RenderedTilesDistance + PlayerPos.TileX, i - RenderedTilesDistance + PlayerPos.TileZ, 0, 0, 0), newmesh);
                 *      }
                 *  }
                 * }*/

                LoadingMapTiles = false;
                Thread.CurrentThread.Priority = ThreadPriority.Normal;
                System.Diagnostics.Debug.WriteLine("Finished load new MapTiles (" + WorldPos.TileX + "," + WorldPos.TileZ + ") - " + (CheckLandscapeEnd - CheckLandscapeBegin).TotalMilliseconds + " ms|" + (CopyMapTilesEnd - CheckLandscapeEnd).TotalMilliseconds + " ms");
                return(true);
            }
            System.Diagnostics.Debug.WriteLine("Nothing loaded");
            return(false);
        }
コード例 #3
0
ファイル: WorldMap.cs プロジェクト: ALenfant/WorldEngine
        //Force : force the reload of all the tiles
        //Check if there are tiles to load and load them
        public bool CheckLoadTiles(bool force = false)
        {
            System.Diagnostics.Debug.WriteLine("Start loadtiles (" + WorldPos.TileX + "," + WorldPos.TileZ + ")");
            if (force || ((PlayerPos.TileX != WorldPos.TileX) || (PlayerPos.TileZ != WorldPos.TileZ)))
            {
                //The player moved too much
                LoadingMapTiles = true;
                System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Highest;

                int TilesMoveX = PlayerPos.TileX - WorldPos.TileX;
                int TilesMoveZ = PlayerPos.TileZ - WorldPos.TileZ;

                TimeSpan CheckLandscapeBegin = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime;

                //We create the new MapTile which will contain the new terrains
                MapTile[][] MapTiles_New = new MapTile[2 * RenderedTilesDistance + 1][];// = MapTiles = new MapTile[2 * RenderedTilesDistance + 1, 2 * RenderedTilesDistance + 1];
                LinkedList<MapTile> TilesList_New = new LinkedList<MapTile>();

                //We check all the new tiles to see if we have to create a new one or copy an old one
                for (short i = 0; i < (2 * RenderedTilesDistance + 1); i++)
                {
                    MapTiles_New[i] = new MapTile[2 * RenderedTilesDistance + 1];
                    for (short j = 0; j < (2 * RenderedTilesDistance + 1); j++)
                    {
                        int oldIndexX = i + TilesMoveX; //Correspondance to the old MapTiles
                        int oldIndexZ = j + TilesMoveZ; //Correspondance to the old MapTiles
                        if (!force && (((oldIndexX >= 0) && (oldIndexX <= 2 * RenderedTilesDistance)) && ((oldIndexZ >= 0) && (oldIndexZ <= 2 * RenderedTilesDistance))))
                        {
                            //The old index is valid, we just move the tile
                            MapTiles_New[i][j] = MapTiles[oldIndexX][oldIndexZ];
                        }
                        else
                        {
                            //New landscape, we create it
                            TimeSpan NewLandscapeBegin = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime;
                            MapTiles_New[i][j] = new MapTile(new TilePosition(PlayerPos.TileX + i - RenderedTilesDistance, PlayerPos.TileZ + j - RenderedTilesDistance));
                            TimeSpan NewLandscapeEnd = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime;
                            System.Diagnostics.Debug.WriteLine("New tile i:" + i + "(" + (PlayerPos.TileX + i - RenderedTilesDistance) + ");j:" + j + "(" + (PlayerPos.TileZ + j - RenderedTilesDistance) + ") - " + (NewLandscapeEnd - NewLandscapeBegin).TotalMilliseconds + " ms.");
                        }

                        if ((i - RenderedTilesDistance == 0) && (j - RenderedTilesDistance == 0))
                        {
                            //Player's tile
                            MapTiles_New[i][j].Landscape.SetTexture(GlobalVars.GameEngine.Globals.GetTex("LandTexture"), -1);
                            MapTiles_New[i][j].Landscape.SetTextureScale(3, 3, -1);
                        }
                        else
                        {
                            //Another tile
                            MapTiles_New[i][j].Landscape.SetTexture(GlobalVars.GameEngine.Globals.GetTex("LandTexture2"), -1);
                            MapTiles_New[i][j].Landscape.SetTextureScale(3, 3, -1);
                        }

                        TilePosition Position = new TilePosition(i - RenderedTilesDistance + PlayerPos.TileX, j - RenderedTilesDistance + PlayerPos.TileZ);

                        TilesHeightmapToLoad.Enqueue(Position, Position.TileDistanceTo(PlayerPos));

                        //LoadTileHeightmap(new TilePosition(i - RenderedTilesDistance, j - RenderedTilesDistance));
                        //LoadTileHeightmap2(MapTiles_New[i][j]);

                        WorldPosition SplatPosition = new WorldPosition(Position);
                        /*
                        MapTiles_New[i][j].Landscape.AddSplattingTexture(GlobalVars.GameEngine.Globals.GetTex("SplattingTexture"), 1, 1, 1, 0, 0);
                        MapTiles_New[i][j].Landscape.ExpandSplattingTexture(GlobalVars.GameEngine.Globals.GetTex("SplattingAlphaTexture"), GlobalVars.GameEngine.Globals.GetTex("SplattingTexture"), 0, 0, 4, 4);
                        MapTiles_New[i][j].Landscape.SetSplattingEnable(true);*/
                        //AddSplattingToTile(SplatPosition, GlobalVars.GameEngine.Globals.GetTex("SplattingTexture"));

                        TilesList_New.AddLast(MapTiles_New[i][j]);
                    }
                }
                TimeSpan CheckLandscapeEnd = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime;

                //We replace the old tiles with the new ones
                MapTiles = MapTiles_New;
                TilesList = TilesList_New;
                TimeSpan CopyMapTilesEnd = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime;

                WorldPos.TileX = PlayerPos.TileX;
                WorldPos.TileZ = PlayerPos.TileZ;

                //DEBUG : add a mesh to each tile
                /*for (short i = 0; i < (2 * RenderedTilesDistance + 1); i++)
                {
                    for (short j = 0; j < (2 * RenderedTilesDistance + 1); j++)
                    {
                        if (!MapTiles[i][j].MeshesLoaded) //DEBUG
                        {
                            MapTiles[i][j].MeshesLoaded = true; //DEBUG

                            //Debug : we add a mesh
                            TVMesh newmesh = new TVMesh();
                            newmesh = GlobalVars.GameEngine.Scene.CreateMeshBuilder();
                            newmesh.CreateTeapot();
                            newmesh.SetScale(50, 50, 50);
                            newmesh.SetCullMode(CONST_TV_CULLING.TV_BACK_CULL);
                            AddMeshToTile(new WorldPosition(i - RenderedTilesDistance + PlayerPos.TileX, i - RenderedTilesDistance + PlayerPos.TileZ, 0, 0, 0), newmesh);
                        }
                    }
                }*/

                LoadingMapTiles = false;
                Thread.CurrentThread.Priority = ThreadPriority.Normal;
                System.Diagnostics.Debug.WriteLine("Finished load new MapTiles (" + WorldPos.TileX + "," + WorldPos.TileZ + ") - " + (CheckLandscapeEnd - CheckLandscapeBegin).TotalMilliseconds + " ms|" + (CopyMapTilesEnd - CheckLandscapeEnd).TotalMilliseconds + " ms");
                return true;
            }
            System.Diagnostics.Debug.WriteLine("Nothing loaded");
            return false;
        }
コード例 #4
0
ファイル: WorldMap.cs プロジェクト: satlanski2/WorldEngine
        //Load a tile's heightmap (here uses the sin function)
        private void LoadTileHeightmap2(MapTile TileToLoad)
        {
            //return;
            //We don't use the debug sinus code
            if (TileToLoad != null)
            {
                //TimeSpan Start1 = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime;
                MTV3D65.CONST_TV_LANDSCAPE_PRECISION precision = TileToLoad.Landscape.GetPrecision();
                int Vertices = (256 / GlobalVars.getTVPrecisionDivider(precision)) * TileToLoad.Landscape.GetLandWidth();
                float[] Height_Array = new float[Vertices * Vertices];
                for (int i = 0; i < Vertices; i++)
                {
                    for (int j = 0; j < Vertices; j++)
                    {
                        Height_Array[i * Vertices + j] = (float)Math.Sin(Math.Sqrt(Math.Pow(i * 2, 2) + Math.Pow(j * 2, 2)) / 25) * 10;
                    }
                }
                TileToLoad.Landscape.SetHeightArray(0, 0, Vertices, Vertices, Height_Array);
                //double Total1 = (System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime - Start1).TotalMilliseconds;

                //TimeSpan Start2 = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime;
                /*for (int i = TileToLoad.TilePosition.TileX * 256 * MapTile.TileSize; i <= TileToLoad.TilePosition.TileX * 256 * MapTile.TileSize + 256 * MapTile.TileSize; i += 2)
                {
                    for (int j = TileToLoad.TilePosition.TileZ * 256 * MapTile.TileSize; j <= TileToLoad.TilePosition.TileZ * 256 * MapTile.TileSize + 256 * MapTile.TileSize; j = j + 1)
                    {
                        TileToLoad.Landscape.SetHeight(i, j, (float)Math.Sin(Math.Sqrt(i * i + j * j) / 25) * 10);
                    }
                }*/
                //double Total2 = (System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime - Start2).TotalMilliseconds;

                //Debug.WriteLine("Method 1 " + Total1 + "ms; Method 2 " + Total2 + "ms");
                //Method 1 31,2002ms; Method 2 3120,02ms

                TileToLoad.Landscape.FlushHeightChanges();
            }
        }