private List <ChunkFeature> GetUnfittedChunkIndices(ChunkRequest chunkRequest, List <ChunkFeature> chunkFeatures)
        {
            List <ChunkFeature> unfittedChunkIndices = new List <ChunkFeature>();

            for (int index = 0; index < chunkFeatures.Count; ++index)
            {
                ChunkFeature chunkFeature        = chunkFeatures[index];
                ChunkFeature chunkChainedFeature = chunkFeature;

                int  chunkNumOffset = 0;
                bool chained        = false;
                while (chunkChainedFeature != null)
                {
                    ChunkRequest nextChunkRequest = new ChunkRequest()
                    {
                        chunkNum = chunkRequest.chunkNum - chunkNumOffset,
                    };


                    if (chained && nextChunkRequest.chunkNum != 0 && nextChunkRequest.chunkNum == chunkRequest.sprintEndChunkNum)
                    {
                        unfittedChunkIndices.Add(chunkFeature);
                        break;
                    }

                    int nextDepth = ChunkMath.Depth(nextChunkRequest);
                    int nextDepthStartChunkNum = ChunkMath.DepthStartChunkNum(nextChunkRequest);
                    int nextDepthEndChunkNum   = ChunkMath.DepthEndChunkNum(nextChunkRequest);
                    int nextSideChunkNum       = ChunkMath.SideChunkNum(nextChunkRequest);

                    // Mark chunk feature to be removed if it hits a corner and it is supposed to skip corners
                    if (chunkChainedFeature.SkipCorners && (chained || nextChunkRequest.chunkNum != nextDepthEndChunkNum) &&
                        (nextSideChunkNum == nextDepth - 1 ||
                         nextChunkRequest.chunkNum == nextDepthStartChunkNum))
                    {
                        unfittedChunkIndices.Add(chunkFeature);
                        break;
                    }

                    chunkChainedFeature = chunkChainedFeature.ChunkChainNext;
                    chunkNumOffset++;
                    chained = true;
                }
            }

            return(unfittedChunkIndices);
        }
Example #2
0
        public void Place(ChunkView chunkView, ChunkRequest chunkRequest, ChunkFeature chunkFeature, ChunkFeatureView chunkFeatureView)
        {
            if (chunkRequest.chunkNum == 0)
            {
                chunkView.Rotation *= Quaternion.AngleAxis(
                    120,
                    chunkView.Up
                    );
                chunkView.Position = Vector3.zero + Altitude(chunkRequest, chunkFeature, chunkFeatureView);
                return;
            }

            chunkView.Rotation *= BirdseyeRotation(chunkView, chunkRequest);
            chunkView.Position  = BirdseyePosition(chunkView, chunkRequest, chunkFeature, chunkFeatureView);

            previousChunkView = chunkView;
        }
Example #3
0
 public Chunk(
     DiContainer container,
     Settings settings,
     ChunkRequest chunkRequest,
     ChunkView chunkView,
     ChunkFeature chunkFeature,
     ChunkFeatureView chunkFeatureView,
     IChunkPlacingStrategy chunkPlacingStrategy)
 {
     this.container            = container;
     this.settings             = settings;
     this.chunkRequest         = chunkRequest;
     this.chunkView            = chunkView;
     this.chunkFeature         = chunkFeature;
     this.chunkFeatureView     = chunkFeatureView;
     this.chunkPlacingStrategy = chunkPlacingStrategy;
 }
Example #4
0
        private Vector3 Altitude(ChunkRequest chunkRequest, ChunkFeature chunkFeature, ChunkFeatureView chunkFeatureView)
        {
            if (previousChunkView == null)
            {
                return(settings.mountainOffset * Vector3.up);
            }

            float previousAltitude = previousChunkView.Position.y + previousChunkView.ChunkFeatureView.ExitAltitude;

            if (chunkFeature.MatchChainHeight)
            {
                return((previousAltitude - chunkFeatureView.EntryAltitude) * Vector3.up);
            }

            float variability = UnityEngine.Random.value * settings.altitudeRange;

            return((variability + previousAltitude - chunkFeatureView.EntryAltitude) * Vector3.up);
        }
        public override ChunkFacade Create(ChunkRequest chunkRequest)
        {
            DiContainer subContainer = CreateSubContainer(chunkRequest);

            ChunkFeature chunkFeature = chunkFeaturePickingStrategy.Pick(chunkRequest);

            subContainer.Bind <ChunkFeature>().ToSingleInstance(chunkFeature);

            GameObject prefab = chunkFeature.ChunkFeatureView.gameObject;

            subContainer.Bind <ChunkFeatureView>().ToSinglePrefab(prefab);

            ChunkFacade chunkFacade = subContainer.Resolve <ChunkFacade>();

            chunkFacade.Initialize();

            return(chunkFacade);
        }
        public ChunkFeature Pick(ChunkRequest chunkRequest)
        {
            if (chunkChain != null)
            {
                ChunkFeature chunkChainedFeature = chunkChain;
                chunkChain = chunkChain.ChunkChainNext;

                return(chunkChainedFeature);
            }

            IBiome biome = chunkRequest.biome;
            List <ChunkFeature> chunkFeatures = biome.ChunkFeatures();

            chunkFeatures = chunkFeatures
                            .Where(chunkFeature => !chunkFeature.IsUnique || (chunkFeature.IsUnique && !pickedUniqueChunkFeatures.Contains(chunkFeature)))
                            .ToList();

            List <ChunkFeature> unfittedChunkIndices = GetUnfittedChunkIndices(chunkRequest, chunkFeatures);

            foreach (ChunkFeature chunkFeature in unfittedChunkIndices)
            {
                chunkFeatures.Remove(chunkFeature);
            }

            List <int>   cdf                = CreateCDF(chunkFeatures);
            int          randomIndex        = GetRandomIndex(cdf, chunkFeatures);
            ChunkFeature pickedChunkFeature = chunkFeatures[randomIndex];

            if (pickedChunkFeature.IsUnique)
            {
                pickedUniqueChunkFeatures.Add(pickedChunkFeature);
            }

            chunkChain = pickedChunkFeature.ChunkChainNext;

            return(pickedChunkFeature);
        }
Example #7
0
 private Vector3 Position(ChunkRequest chunkRequest, Vector3 sideDirection, Vector3 depthDirection, int sideChunkNum, int depth, ChunkFeature chunkFeature, ChunkFeatureView chunkFeatureView)
 {
     return(((sideChunkNum + 1) * sideDirection) + ((depth - sideChunkNum - 1) * depthDirection) + Altitude(chunkRequest, chunkFeature, chunkFeatureView));
 }
Example #8
0
        private Vector3 BirdseyePosition(ChunkView chunkView, ChunkRequest chunkRequest, ChunkFeature chunkFeature, ChunkFeatureView chunkFeatureView)
        {
            int depth = ChunkMath.Depth(chunkRequest);
            int side  = ChunkMath.Side(chunkRequest);
            int depthStartChunkNum = ChunkMath.DepthStartChunkNum(chunkRequest);
            int sideStartChunkNum  = ChunkMath.SideStartChunkNum(chunkRequest);
            int sideChunkNum       = ChunkMath.SideChunkNum(chunkRequest);

            switch (side)
            {
            case 0:
                return(Position(chunkRequest, chunkReference.Northeast, chunkReference.Northwest, sideChunkNum, depth, chunkFeature, chunkFeatureView));

            case 1:
                return(Position(chunkRequest, chunkReference.East, chunkReference.Northeast, sideChunkNum, depth, chunkFeature, chunkFeatureView));

            case 2:
                return(Position(chunkRequest, chunkReference.Southeast, chunkReference.East, sideChunkNum, depth, chunkFeature, chunkFeatureView));

            case 3:
                return(Position(chunkRequest, chunkReference.Southwest, chunkReference.Southeast, sideChunkNum, depth, chunkFeature, chunkFeatureView));

            case 4:
                return(Position(chunkRequest, chunkReference.West, chunkReference.Southwest, sideChunkNum, depth, chunkFeature, chunkFeatureView));

            case 5:
                return(Position(chunkRequest, chunkReference.Northwest, chunkReference.West, sideChunkNum, depth, chunkFeature, chunkFeatureView));
            }

            Debug.LogError("Failed to compute spiral chunk position");
            return(Vector3.zero);
        }
 public void Initialize()
 {
     pickedUniqueChunkFeatures = new HashSet <ChunkFeature>();
     chunkChain = null;
 }