Exemple #1
0
 void Update()
 {
     playerSectorCoord       = GetSectorCoordFromVector3(player.transform.position);
     playerSectorCoordVector = GetSectorVectorFromSectorCoord(playerSectorCoord);
     if (!playerSectorCoord.Equals(playerLastSectorCoord))
     {
         CheckViewDistance();
     }
     if (sectorsToDraw.Count > 0)
     {
         if (sectorsToDraw.Peek().IsEditable)
         {
             //Debug.Log("I am creating");
             sectorsToDraw.Dequeue().Init();
         }
     }
     if (sectorsToCreate.Count > 0)
     {
         CreateSector();
         //Debug.Log("CreatingSectors");
     }
     if (!enableThreading)
     {
         if (sectorsToUpdate.Count > 0)
         {
             ThreadCreateSectors();
         }
     }
 }
Exemple #2
0
 public Sector(SectorCoord SectorCoord, SectorCoord TrueSectorCoord, Mesh sectorSphereMesh, Galaxy Galaxy)
 {
     galaxy          = Galaxy;
     sectorCoord     = SectorCoord;
     trueSectorCoord = TrueSectorCoord;
     sphereMesh      = sectorSphereMesh;
 }
Exemple #3
0
        void CreateSector()
        {
            SectorCoord s = sectorsToCreate[0];

            GenerateSectorAt(s.x, s.y, s.z);
            sectorsToCreate.RemoveAt(0);
            //Debug.Log("" + s.x + "" + s.y + "" + s.z);
        }
Exemple #4
0
        public Vector3 GetSectorVectorFromSectorCoord(SectorCoord sectorCoord)
        {
            Vector3 sectorCoordVector3convert;

            sectorCoordVector3convert.x = sectorCoord.x;
            sectorCoordVector3convert.y = sectorCoord.y;
            sectorCoordVector3convert.z = sectorCoord.z;
            return(sectorCoordVector3convert);
        }
Exemple #5
0
 // Start is called before the first frame update
 void Start()
 {
     if (enableThreading)
     {
         if (UpdateThreadNumber == 1)
         {
             sectorUpdateThread1 = new Thread(new ThreadStart(ThreadedUpdate));
             sectorUpdateThread1.Start();
         }
         if (UpdateThreadNumber == 2)
         {
             sectorUpdateThread1 = new Thread(new ThreadStart(ThreadedUpdate));
             sectorUpdateThread1.Start();
             sectorUpdateThread2 = new Thread(new ThreadStart(ThreadedUpdate));
             sectorUpdateThread2.Start();
         }
         if (UpdateThreadNumber == 3)
         {
             sectorUpdateThread1 = new Thread(new ThreadStart(ThreadedUpdate));
             sectorUpdateThread1.Start();
             sectorUpdateThread2 = new Thread(new ThreadStart(ThreadedUpdate));
             sectorUpdateThread2.Start();
             sectorUpdateThread3 = new Thread(new ThreadStart(ThreadedUpdate));
             sectorUpdateThread3.Start();
         }
         if (UpdateThreadNumber == 4)
         {
             sectorUpdateThread1 = new Thread(new ThreadStart(ThreadedUpdate));
             sectorUpdateThread1.Start();
             sectorUpdateThread2 = new Thread(new ThreadStart(ThreadedUpdate));
             sectorUpdateThread2.Start();
             sectorUpdateThread3 = new Thread(new ThreadStart(ThreadedUpdate));
             sectorUpdateThread3.Start();
             sectorUpdateThread4 = new Thread(new ThreadStart(ThreadedUpdate));
             sectorUpdateThread4.Start();
         }
         if (UpdateThreadNumber == 5)
         {
             sectorUpdateThread1 = new Thread(new ThreadStart(ThreadedUpdate));
             sectorUpdateThread1.Start();
             sectorUpdateThread2 = new Thread(new ThreadStart(ThreadedUpdate));
             sectorUpdateThread2.Start();
             sectorUpdateThread3 = new Thread(new ThreadStart(ThreadedUpdate));
             sectorUpdateThread3.Start();
             sectorUpdateThread4 = new Thread(new ThreadStart(ThreadedUpdate));
             sectorUpdateThread4.Start();
             sectorUpdateThread5 = new Thread(new ThreadStart(ThreadedUpdate));
             sectorUpdateThread5.Start();
         }
         //Debug.Log("Yub");
     }
     GenerateGalaxy((int)(player.transform.position.x / SectorSize), (int)(player.transform.position.y / SectorSize), (int)(player.transform.position.z / SectorSize), ViewDistanceInSectors);
     player.transform.position = new Vector3(500, 500, 500);
     playerLastSectorCoord     = GetSectorCoordFromVector3(player.transform.position);
 }
Exemple #6
0
 bool IsSectorCreatedBefore(SectorCoord coord, List <Sector> previouslyActiveSectors)
 {
     for (int i = 0; i < createdSectors.Count; i++)
     {
         if (createdSectors[i].sectorCoord == coord && previouslyActiveSectors[i].sectorCoord == coord)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #7
0
 Sector ReturnSector(SectorCoord coord, List <Sector> previouslyActiveSectors)
 {
     for (int i = 0; i < createdSectors.Count; i++)
     {
         if (createdSectors[i].sectorCoord == coord && previouslyActiveSectors[i].sectorCoord == coord)
         {
             return(createdSectors[i]);
         }
     }
     return(null);
 }
Exemple #8
0
        void CheckViewDistance()
        {
            SectorCoord sectorCoord = GetSectorCoordFromVector3(player.transform.position);

            playerLastSectorCoord = playerSectorCoord;
            List <SectorCoord> previouslyActiveSectors = new List <SectorCoord>(activeSectors);

            activeSectors.Clear();
            for (int x = sectorCoord.x - ViewDistanceInSectors; x <= sectorCoord.x + ViewDistanceInSectors; x++)
            {
                for (int y = sectorCoord.y - ViewDistanceInSectors; y <= sectorCoord.y + ViewDistanceInSectors; y++)
                {
                    for (int z = sectorCoord.z - ViewDistanceInSectors; z <= sectorCoord.z + ViewDistanceInSectors; z++)
                    {
                        SectorCoord NewSectorCoord = new SectorCoord(x, y, z);
                        if (IsSectorInGalaxy(NewSectorCoord))
                        {
                            //bool IsCreatedBefore = IsSectorCreatedBefore(NewSectorCoord, previouslyActiveSectors);
                            //if ( IsCreatedBefore == true)
                            //{
                            //    ReturnSector(NewSectorCoord, previouslyActiveSectors);
                            //    sectorsToCreate.Add(NewSectorCoord);
                            //}
                            //Debug.Log("CheckViewDistance" + " " + x + " " + y + " " + z);
                            sectorsToCreate.Add(NewSectorCoord);
                            activeSectors.Add(NewSectorCoord);
                        }
                        for (int i = 0; i < previouslyActiveSectors.Count; i++)
                        {
                            if (previouslyActiveSectors[i].Equals(NewSectorCoord))
                            {
                                previouslyActiveSectors.RemoveAt(i);
                            }
                        }
                    }
                }
            }
            foreach (SectorCoord c in previouslyActiveSectors)
            {
                for (int i = 0; i < activeSectors.Count; i++)
                {
                    if (activeSectors[i] == c)
                    {
                        activeSectors.Remove(c);
                    }
                }

                for (int i = 0; i < createdSectors.Count; i++)
                {
                    createdSectors[i].IsActive = false;
                }
            }
            //Debug.Log("CheckViewDistance");
        }
Exemple #9
0
 bool IsSectorInGalaxy(SectorCoord coord)
 {
     if (coord.x >= -galaxyLength && coord.x <= galaxyLength &&
         coord.y >= -galaxyHeight && coord.y <= galaxyHeight &&
         coord.z >= -galaxyWidth && coord.z <= galaxyWidth)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #10
0
 void GenerateSectorAt(int x, int y, int z)// builds Sectors
 {
     Vector3     SectorPosition = new Vector3(x * SectorSize, y * SectorSize, z * SectorSize);
     SectorCoord rawSectorCoord = GetRawSectorCoordFromVector3(SectorPosition);
     SectorCoord sectorCoord    = GetSectorCoordFromVector3(SectorPosition);
     Sector      i = new Sector(sectorCoord, rawSectorCoord, sphereMesh, this);
     {
         i.IsActive = true;
         sectorsToUpdate.Add(i);
         createdSectors.Add(i);
     }
     //Debug.Log(" " + SectorPosition.x + " " + SectorPosition.y + " " + SectorPosition.z + " " + i.IsActive);
     //Debug.Log(" " + sectorCoord.x + " " + sectorCoord.y + " " + sectorCoord.z + " " + i.IsActive);
 }
Exemple #11
0
 public bool Equals(SectorCoord other)
 {
     if (other == null)
     {
         return(false);
     }
     else if (other.x == x && other.y == y && other.z == z)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #12
0
 void GenerateGalaxy(int x, int y, int z, int startradius)// builds Sectors around the player
 {
     for (int startx = x - startradius; startx <= x + startradius; startx++)
     {
         for (int starty = y - startradius; starty <= y + startradius; starty++)
         {
             for (int startz = z - startradius; startz <= z + startradius; startz++)
             {
                 SectorCoord NewSectorCoord = new SectorCoord(startx, starty, startz);
                 sectorsToCreate.Add(NewSectorCoord);
                 activeSectors.Add(NewSectorCoord);
                 //Debug.Log("Generated Sector on Start" + " " + startx + " " + starty + " " + startz);
             }
         }
     }
     CheckViewDistance();
 }
Exemple #13
0
        public SectorType SectorTypeGeneration(SectorCoord sectorCoord)
        {
            SectorType sectorType;

            if (sectorCoord.x >= galaxy.SectorTypeTable[0].xpositiveBoundsMin && sectorCoord.x <= galaxy.SectorTypeTable[0].xpositiveBoundsMax || sectorCoord.x >= galaxy.SectorTypeTable[0].xnegativeBoundsMin && sectorCoord.x <= galaxy.SectorTypeTable[0].xnegativeBoundsMax ||
                sectorCoord.y >= galaxy.SectorTypeTable[0].ypositiveBoundsMin && sectorCoord.y <= galaxy.SectorTypeTable[0].ypositiveBoundsMax || sectorCoord.y >= galaxy.SectorTypeTable[0].ynegativeBoundsMin && sectorCoord.y <= galaxy.SectorTypeTable[0].ynegativeBoundsMax ||
                sectorCoord.z >= galaxy.SectorTypeTable[0].zpositiveBoundsMin && sectorCoord.z <= galaxy.SectorTypeTable[0].zpositiveBoundsMax || sectorCoord.z >= galaxy.SectorTypeTable[0].znegativeBoundsMin && sectorCoord.z <= galaxy.SectorTypeTable[0].znegativeBoundsMax)
            {
                sectorType = SectorType.Core;
                return(sectorType);
            }
            if (sectorCoord.x > galaxy.SectorTypeTable[1].xpositiveBoundsMin && sectorCoord.x <= galaxy.SectorTypeTable[1].xpositiveBoundsMax || sectorCoord.x > galaxy.SectorTypeTable[1].xnegativeBoundsMin && sectorCoord.x <= galaxy.SectorTypeTable[1].xnegativeBoundsMax ||
                sectorCoord.y > galaxy.SectorTypeTable[1].ypositiveBoundsMin && sectorCoord.y <= galaxy.SectorTypeTable[1].ypositiveBoundsMax || sectorCoord.y > galaxy.SectorTypeTable[1].ynegativeBoundsMin && sectorCoord.y <= galaxy.SectorTypeTable[1].ynegativeBoundsMax ||
                sectorCoord.z > galaxy.SectorTypeTable[1].zpositiveBoundsMin && sectorCoord.z <= galaxy.SectorTypeTable[1].zpositiveBoundsMax || sectorCoord.z > galaxy.SectorTypeTable[1].znegativeBoundsMin && sectorCoord.z <= galaxy.SectorTypeTable[1].znegativeBoundsMax)
            {
                sectorType = SectorType.Middle;
                return(sectorType);
            }
            if (sectorCoord.x > galaxy.SectorTypeTable[2].xpositiveBoundsMin && sectorCoord.x <= galaxy.SectorTypeTable[2].xpositiveBoundsMax || sectorCoord.x > galaxy.SectorTypeTable[2].xnegativeBoundsMin && sectorCoord.x <= galaxy.SectorTypeTable[2].xnegativeBoundsMax ||
                sectorCoord.y > galaxy.SectorTypeTable[2].ypositiveBoundsMin && sectorCoord.y <= galaxy.SectorTypeTable[2].ypositiveBoundsMax || sectorCoord.y > galaxy.SectorTypeTable[2].ynegativeBoundsMin && sectorCoord.y <= galaxy.SectorTypeTable[2].ynegativeBoundsMax ||
                sectorCoord.z > galaxy.SectorTypeTable[2].zpositiveBoundsMin && sectorCoord.z <= galaxy.SectorTypeTable[2].zpositiveBoundsMax || sectorCoord.z > galaxy.SectorTypeTable[2].znegativeBoundsMin && sectorCoord.z <= galaxy.SectorTypeTable[2].znegativeBoundsMax)
            {
                sectorType = SectorType.Edge;
                return(sectorType);
            }
            if (sectorCoord.x > galaxy.SectorTypeTable[3].xpositiveBoundsMin && sectorCoord.x <= galaxy.SectorTypeTable[3].xpositiveBoundsMax || sectorCoord.x > galaxy.SectorTypeTable[3].xnegativeBoundsMin && sectorCoord.x <= galaxy.SectorTypeTable[3].xnegativeBoundsMax ||
                sectorCoord.y > galaxy.SectorTypeTable[3].ypositiveBoundsMin && sectorCoord.y <= galaxy.SectorTypeTable[3].ypositiveBoundsMax || sectorCoord.y > galaxy.SectorTypeTable[3].ynegativeBoundsMin && sectorCoord.y <= galaxy.SectorTypeTable[3].ynegativeBoundsMax ||
                sectorCoord.z > galaxy.SectorTypeTable[3].zpositiveBoundsMin && sectorCoord.z <= galaxy.SectorTypeTable[3].zpositiveBoundsMax || sectorCoord.z > galaxy.SectorTypeTable[3].znegativeBoundsMin && sectorCoord.z <= galaxy.SectorTypeTable[3].znegativeBoundsMax)
            {
                sectorType = SectorType.Far;
                return(sectorType);
            }
            else
            {
                sectorType = SectorType.Core;
                return(sectorType);
            }
        }
Exemple #14
0
 public static string BuildSectorName(SectorCoord v) // assigning a name to a Sector
 {
     return("Sector : " + (int)v.x + "_" + (int)v.y + "_" + (int)v.z);
 }