//single action of SectorsLoader or SectorsLoaderAtOnce, create, change or delete one sector
        private bool LoaderOneAction()
        {
            bool doneSth = false;

            //1. something was added?
            if (_biomsJustAdded.Count > 0)
            {
                InitBiom(_biomsJustAdded[0]);
                _biomsJustAdded.RemoveAt(0);
                doneSth = true;
            }
            //2. something changed LOD ?
            else if (_biomsJustChangedLOD.Count > 0)
            {
                Biom biomCh = _biomsJustChangedLOD[0];
                _biomsJustChangedLOD.RemoveAt(0);
                biomCh.SetLODLevel(GetBiomsCurrentLOD(biomCh));
            }
            //3. something was deleted?
            else if (_biomsForDelete.Count > 0)
            {
                while (_biomsForDelete.Count > 0)
                { //this should be fast, if this will become a bottleneck any in the future, process less objects
                    DestroySector(_biomsForDelete[0]);
                    _biomsForDelete.RemoveAt(0);
                    doneSth = true;
                }
            }

            return(doneSth);
        }
        //maintenance of one biom, it will be added to maintenance list if needed
        private void RefreshOneBiom(int currentBiomX, int currentBiomZ, int iX, int iZ)
        {
            Biom calcBiom = findBiom(iX, iZ);

            if (calcBiom == null)
            {
                calcBiom = new Biom(TheMapConfig, PrefabPool.Instance, iX, iZ);
                if (currentBiomX == iX && currentBiomZ == iZ)
                {
                    CurrentBiom = calcBiom;
                    InitBiom(calcBiom);
                }
                else
                {
                    _biomsJustAdded.Add(calcBiom);
                }
                _biomsHashed.Add(calcBiom.HashKey, calcBiom);
            }
            else
            {
                if (currentBiomX == iX && currentBiomZ == iZ)
                {
                    CurrentBiom = calcBiom;
                }
                if (calcBiom.CurrentLODLevel != GetBiomsCurrentLOD(calcBiom))
                {
                    _biomsJustChangedLOD.Add(calcBiom);
                }
            }
            //            calcBiom.SetLODLevel((currentBiomX - iX) * (currentBiomX - iX) + (currentBiomZ - iZ) * (currentBiomZ - iZ) < SettingsManager.LOD_DIST_BIOMS ? 0 : 1);
        }
예제 #3
0
        public void AddObjectsToVisibilityGroup(Biom forBiom)
        {
            List <MapObjectInfo> objs = EndlessWorldModuleManager.Instance.TheMapManager.GetBiomMapObjectsData(forBiom.BiomX, forBiom.BiomZ);

            forBiom.AddObjectsToTrack(objs);
            Vector3 biomPos = new Vector3(forBiom.BiomX * Biom.BIOM_SIZE, 0, forBiom.BiomZ * Biom.BIOM_SIZE);

            foreach (MapObjectInfo obj in objs)
            {
                obj.TheBiom = forBiom;
                if (obj.MaxLOD == 6)
                {
                    _visGroupsInfinite.ObjectList.Add(obj);
                    InstantiateMapObject(obj);
                }
                else
                {
                    int size_key = 256;
                    Dictionary <string, VisibilityGroupInfo> list = _visGroups256;
                    CalcKeySizeAndListForLOD(obj.MaxLOD, out size_key, out list);
                    string gkey = ((int)(obj.ObjectPosition.x + biomPos.x) / size_key).ToString() + "_" + ((int)(obj.ObjectPosition.z + biomPos.z) / size_key).ToString();
                    if (!list.ContainsKey(gkey))
                    {
                        list.Add(gkey, new VisibilityGroupInfo()
                        {
                            ObjectList = new List <MapObjectInfo>()
                        });
                    }
                    list[gkey].ObjectList.Add(obj);
                    obj.MyGroup = list[gkey];
                }
            }
        }
 private int GetBiomsCurrentLOD(Biom bm)
 {
     if (CurrentBiom == null)
     {
         return(1);
     }
     return((CurrentBiom.BiomX - bm.BiomX) * (CurrentBiom.BiomX - bm.BiomX) + (CurrentBiom.BiomZ - bm.BiomZ) * (CurrentBiom.BiomZ - bm.BiomZ) < SettingsManager.LOD_DIST_BIOMS ? 0 : 1);
 }
 //operations performed on sector that is recently added on lists
 private void InitBiom(Biom aNewBiom)
 {
     /*   int sectorSuperBiomX = (int)Math.Floor(aNewBiom.sectorX / (1.0f * SuperBiom.SUPERBIOM_SECTORS_LENGTH));   //coords of superbiom in superbioms area
      * int sectorSuperBiomZ = (int)Math.Floor(aNewSeaNewBiomctor.sectorZ / (1.0f * SuperBiom.SUPERBIOM_SECTORS_LENGTH));
      * SuperBiom theSuperBiom = GetOrCreateSuperBiom(sectorSuperBiomX, sectorSuperBiomZ);
      * aNewBiom.InitSector(theSuperBiom.GetSectorName(aNewSector.sectorX % SuperBiom.SUPERBIOM_SECTORS_LENGTH, aNewSector.sectorZ % SuperBiom.SUPERBIOM_SECTORS_LENGTH),   sceneGenerator);
      * aNewBiom.GenerateSceneObjects(_gameManager.TheSceneConfig, this, allRoot, worldGenerator, sceneGenerator);
      * aNewBiom.Owner = theSuperBiom;*/
     aNewBiom.InitBiom(BiomsRootObject, this, GetBiomsCurrentLOD(aNewBiom));
     MapObjectsManager.Instance.AddObjectsToVisibilityGroup(aNewBiom);
 }
 //find a biom at coords
 public Biom findBiom(int iX, int iZ)
 {
     if (_biomsHashed == null)
     {
         return(null);
     }
     if (_biomsHashed.ContainsKey(Biom.BiomHashKey(iX, iZ)))
     {
         return(_biomsHashed[Biom.BiomHashKey(iX, iZ)]);
     }
     return(null);
 }
 //operations performed on sector when its to be deleted
 private void DestroySector(Biom bm)
 {
     bm.ReleaseObjects();
 }
 public Vector3 GetBiomPosition(Biom bm)
 {
     return(new Vector3(bm.BiomX * Biom.BIOM_SIZE + rootPositionCorrection.x, 0, bm.BiomZ * Biom.BIOM_SIZE + rootPositionCorrection.z));
 }