Esempio n. 1
0
        public void SetTarget(Vector3Int chunkId, int targetStage, TargetUpdateMode mode = TargetUpdateMode.any)
        {
            CheckLockBeforeExternalOperation();

            //TODO remove DEBUG
            if (targetStage != FullyGeneratedStage &&
                targetStage != RenderedStage &&
                targetStage != CompleteStage &&
                targetStage != OwnStructuresStage &&
                targetStage != TerrainDataStage)
            {
                throw new ArgumentOutOfRangeException("Target stage was not one of the valid target stages");
            }

            var stageData = GetStageData(chunkId);

            var prevTarget = stageData.targetStage;

            //Clamp the target stage
            clampTarget(ref targetStage, stageData.maxStage, chunkId);

            if (prevTarget == targetStage)
            {
                //If targets equal, no work to be done
                return;
            }

            //Upgrade
            if (targetStage > prevTarget)
            {
                if (!mode.allowsUpgrade())
                {
                    return;//Nothing to be done if the mode does not allow upgrading
                }

                if (stageData.WorkInProgress)//Have to check work in progress against the old target
                {
                    //The existing work will reach the new target
                    //Set new target stage
                    stageData.targetStage = targetStage;
                }
                else
                {
                    //Set new target stage
                    stageData.targetStage = targetStage;
                    //Must restart work from previous max
                    ReenterAtStage(chunkId, stageData.maxStage, stageData);
                }
            }
            else//Downgrade
            {
                if (!mode.allowsDowngrade())
                {
                    return;//Nothing to be done if the mode does not allow downgrading
                }

                var prevMax = stageData.maxStage;

                //Set new target stage
                stageData.targetStage = targetStage;

                var newMax = Math.Min(targetStage, stageData.maxStage);
                stageData.maxStage = newMax;

                if (stageData.maxStage < prevMax)
                {
                    //Downgrading the maximum state of the chunk

                    var chunkComponent = getChunkComponent(chunkId);
                    if (stageData.maxStage < CompleteStage)
                    {
                        chunkComponent.RemoveCollisionMesh();
                    }
                    if (stageData.maxStage < RenderedStage)
                    {
                        chunkComponent.RemoveRenderMesh();
                    }
                    if (stageData.maxStage < FullyGeneratedStage)
                    {
                        chunkComponent.Data.FullyGenerated = false;
                    }

                    //Ensure min stage isn't greater than max
                    SetNewMinimumIfSmallerThanCurrent(chunkId, stageData, stageData.maxStage);
                }
                else
                {
                    /* target has decreased, but the chunk never reached a higher stage than that,
                     * so nothing extra has to be done. Work in progress will stop at the new target
                     */
                }

                Profiler.BeginSample("ChunkTargetDecreasedEvent");
                OnChunkTargetStageDecreased(chunkId, stageData.targetStage);
                Profiler.EndSample();
            }
        }
Esempio n. 2
0
 public static bool allowsDowngrade(this TargetUpdateMode mode)
 {
     return(mode == TargetUpdateMode.any || mode == TargetUpdateMode.downgradeOnly);
 }