Example #1
0
        public void Update(GameTime timeSpend)
        {
            var playerChunk     = _worldChunks.GetChunkFromChunkCoord(_playerEntityManager.ChunkPosition);
            var inChunkPosition = BlockHelper.GlobalToInternalChunkPosition(_playerEntityManager.Player.Position);

            var chunkColumnMeta = playerChunk.BlockData.GetColumnInfo(inChunkPosition.X, inChunkPosition.Z);
            //var c = GetChunk((int)PlayerManager.CameraWorldPosition.X, (int)PlayerManager.CameraWorldPosition.Z);
            ////From World Coord to Cube Array Coord
            //int arrayX = MathHelper.Mod((int)PlayerManager.CameraWorldPosition.X, AbstractChunk.ChunkSize.X);
            //int arrayZ = MathHelper.Mod((int)PlayerManager.CameraWorldPosition.Z, AbstractChunk.ChunkSize.Z);
            //var columnInfo = c.BlockData.GetColumnInfo(new Vector2I(arrayX, arrayZ));
            //var line2 = string.Format("Biomes MetaData : Temperature {0:0.00}, Moisture {1:0.00}, ColumnMaxHeight : {2}, ChunkID : {3}", columnInfo.Temperature / 255.0f, columnInfo.Moisture / 255.0f, columnInfo.MaxHeight, c.Position);

            float temperature = chunkColumnMeta.Temperature / 256.0f;

            temperature  = (temperature * 0.6f) + 0.2f;
            temperature += _weather.TemperatureOffset;
            temperature  = Math.Max(Math.Min(temperature, 1.0f), 0.0f);

            float moisture = chunkColumnMeta.Moisture / 256.0f;

            moisture  = (temperature * 0.6f) + 0.2f;
            moisture += _weather.MoistureOffset;
            moisture  = Math.Max(Math.Min(moisture, 1.0f), 0.0f);

            _tempCursor.Bounds.Location.Y     = _weatherFrame.GetAbsoluteBounds().Height - (temperature * _weatherFrame.GetAbsoluteBounds().Height);
            _moistureCursor.Bounds.Location.Y = _weatherFrame.GetAbsoluteBounds().Height - (moisture * _weatherFrame.GetAbsoluteBounds().Height);
        }
        /// <summary>
        /// Check the impact of the block/Item replacement.
        /// Mostly will check wish of the surrounding visualchunks must be refresh (lighting or cube masked face reason).
        /// This is only for drawing purpose, not landscape modification here.
        /// </summary>
        /// <param name="cubeCoordinates">The cube where the modification has been realized</param>
        /// <param name="replacementCubeId">The type of the modified cube</param>
        public void CheckImpact(VisualChunkBase cubeChunk, Range3I cubeRange)
        {
            Vector3I mainChunkId;

#if PERFTEST
            Utopia.Worlds.Chunks.WorldChunks.perf.AddData("CheckImpact BEGIN");
#endif
            //Add lighting step to the range
            cubeRange.Position = new Vector3I(cubeRange.Position.X - _lightManager.LightPropagateSteps, 0, cubeRange.Position.Z - _lightManager.LightPropagateSteps);
            cubeRange.Size     = new Vector3I(cubeRange.Size.X + (2 * _lightManager.LightPropagateSteps), _worldChunks.VisualWorldParameters.WorldVisibleSize.Y, cubeRange.Size.Z + (2 * _lightManager.LightPropagateSteps));

            //Get the chunk collections
            var minChunkPosition = BlockHelper.BlockToChunkPosition(cubeRange.Position);
            var maxChunkPosition = BlockHelper.BlockToChunkPosition(cubeRange.Max);
            maxChunkPosition.Y = 0;
            Range3I chunkRange = new Range3I()
            {
                Position = minChunkPosition,
                Size     = (maxChunkPosition - minChunkPosition) + Vector3I.One
            };

            //recompute the light sources without the range
            _lightManager.CreateLightSources(ref cubeRange);
            cubeRange.Position.X--;
            cubeRange.Position.Z--;
            cubeRange.Size.X += 2;
            cubeRange.Size.Z += 2;

            //Propagate the light, we add one cube around the previous Range !! <= !!
            _lightManager.PropagateLightSources(ref cubeRange, true, true);

            //Find the chunks that have been impacted around the 8 surrounding chunks
            cubeChunk.State = ChunkState.OuterLightSourcesProcessed;
            mainChunkId     = cubeChunk.Position;
            //Console.WriteLine(cubeChunk.ChunkID + " => " + cubeChunk.UpdateOrder);

#if PERFTEST
            Utopia.Worlds.Chunks.WorldChunks.perf.cubeChunkID = mainChunkId;
            Utopia.Worlds.Chunks.WorldChunks.perf.AddData("Modified chunk is : " + mainChunkId);
#endif
            VisualChunk NeightBorChunk;
            foreach (var chunklocation in chunkRange)
            {
                NeightBorChunk = _worldChunks.GetChunkFromChunkCoord(chunklocation);
                if (NeightBorChunk.Position != mainChunkId && NeightBorChunk.State > ChunkState.OuterLightSourcesProcessed)
                {
                    NeightBorChunk.State       = ChunkState.OuterLightSourcesProcessed;
                    NeightBorChunk.UpdateOrder = cubeChunk.UpdateOrder == 1 ? 2 : 1;
                }
            }

#if PERFTEST
            Utopia.Worlds.Chunks.WorldChunks.perf.AddData("CheckImpact END");
#endif
        }