Exemplo n.º 1
0
 private void ChangeChunk(int x, int y, int z)
 {
     PositionChunk positionChunk = PositionChunk.CreateFrom(new PositionBlock(x,y,z));
     chunkCache = World.Instance.GetCachedChunks();
     chunk = chunkCache.GetChunk(positionChunk);
     chunk.Position.GetMinCornerBlock(out chunkCorner);
 }
Exemplo n.º 2
0
        private void RenderPass1AndBuildPass2List()
        {
            t.ResetTransformation();

            pass2ChunkRenderers.Clear();
            cachedChunks = World.Instance.GetCachedChunks();
            if (cachedChunks.Count != 0)
            {
                Counters.Instance.SetValue("c.all     ", cachedChunks.Count);
                Counters.Instance.SetValue("c.notgen  ", cachedChunks.OrderedChunks.Where(c => c.Stage == Chunk.ChunkStageEnum.NotGenerated).Count());
                Counters.Instance.SetValue("c.gen     ", cachedChunks.OrderedChunks.Where(c => c.Stage == Chunk.ChunkStageEnum.Generated).Count());
                Counters.Instance.SetValue("c.upd     ", cachedChunks.OrderedChunks.Where(c => c.Stage == Chunk.ChunkStageEnum.Update).Count());
                Counters.Instance.SetValue("col.all   ", cachedChunks.ChunkColumns.Values.Count());
                Counters.Instance.SetValue("col.notgen", cachedChunks.ChunkColumns.Values.Where(c => c.Stage == ChunkColumn.ColumnStageEnum.NotGenerated).Count());
                Counters.Instance.SetValue("col.gen   ", cachedChunks.ChunkColumns.Values.Where(c => c.Stage == ChunkColumn.ColumnStageEnum.Generated).Count());
                Counters.Instance.SetValue("col.rdygen", cachedChunks.ChunkColumns.Values.Where(c => c.Stage == ChunkColumn.ColumnStageEnum.AllNeighborsGenerated).Count());
                Counters.Instance.SetValue("col.deco  ", cachedChunks.ChunkColumns.Values.Where(c => c.Stage == ChunkColumn.ColumnStageEnum.Decorated).Count());
            }

            if (cachedChunks.Count == 0)
                return;

            float viewRadiusSquared = (int)((GameSettings.ViewRadius * GameSettings.ViewRadius) / 256f);
            forceCachedRendering = false;
            if (cachedChunks.IsDirty)
            {
                chunksToRender = cachedChunks.OrderedChunks.Where(c =>
                {
                    float dx = c.Position.X - cachedChunks.LastCenterChunk.X;
                    float dy = c.Position.Y - cachedChunks.LastCenterChunk.Y;
                    float dz = c.Position.Z - cachedChunks.LastCenterChunk.Z;
                    return dx * dx + dy * dy + dz * dz <= viewRadiusSquared;
                }).OrderBy(c =>
                {
                    float dx = c.Position.X - cachedChunks.LastCenterChunk.X;
                    float dy = c.Position.Y - cachedChunks.LastCenterChunk.Y;
                    float dz = c.Position.Z - cachedChunks.LastCenterChunk.Z;
                    return dx * dx + dy * dy + dz * dz;
                }).ToList();
                cachedChunks.IsDirty = false;
            }

            p.StartSection("renderchunks");
            foreach (Chunk chunk in chunksToRender)
            {
                RenderChunk(chunk);
            }
            p.EndStartSection("dispose");

            // dispose and remove expired chunks
            var expiredRenderer = chunkRenderers.Where(pair => pair.Value.Expired).ToList();
            expiredRenderer.ForEach(pair =>
            {
                pair.Value.Dispose();
                chunkRenderers.Remove(pair.Key);
            });
            Counters.Instance.SetValue("ChunkRenderer objects", chunkRenderers.Count);
            p.EndSection();
        }
Exemplo n.º 3
0
        internal void Decorate()
        {
            // Decorate here..
            ChunkCache cache = World.Instance.GetCachedChunks();
            Chunk      chunk = cache.GetChunk(new PositionChunk(Position.X, 0, Position.Z));

            World.Instance.Generator(chunk).Decorate(chunk);
            InvalidateMeAndNeighbors();

            // update chunks and column stages
            SetChunkStage(Chunk.ChunkStageEnum.Update);
            Stage = ColumnStageEnum.Decorated;
            NotifyNeighbors();
        }
Exemplo n.º 4
0
        private void NotifyNeighbors()
        {
            ChunkCache cache = World.Instance.GetCachedChunks();

            OnNeighborGenerated();
            foreach (var neighborColumn in cache.AllNeighborColumns(this))
            {
                if (neighborColumn == null)
                {
                    continue;
                }
                neighborColumn.OnNeighborGenerated();
            }
        }
Exemplo n.º 5
0
        private void OnNeighborGenerated()
        {
            if (Stage != ColumnStageEnum.Generated)
            {
                return;
            }
            ChunkCache cache = World.Instance.GetCachedChunks();
            var        allNeighborColumns = cache.AllNeighborColumns(this);

            foreach (var column in allNeighborColumns)
            {
                if (column == null || column.Stage == ColumnStageEnum.NotGenerated)
                {
                    return;
                }
            }
            Stage = ColumnStageEnum.AllNeighborsGenerated;
        }
Exemplo n.º 6
0
        internal void OnChunkGenerated()
        {
            ChunkCache cache = World.Instance.GetCachedChunks();

            if (Stage == ColumnStageEnum.NotGenerated)
            {
                // Check if we can progress to next stage
                for (int y = 0; y < Chunk.MaxSizeY / 16f; y++)
                {
                    Chunk chunk = cache.GetChunk(new PositionChunk(Position.X, y, Position.Z));
                    if (chunk.Stage == Chunk.ChunkStageEnum.NotGenerated)
                    {
                        return;
                    }
                }
                Stage = ColumnStageEnum.Generated;
                NotifyNeighbors();
            }
            else
            {
                throw new Exception("ERROR in chunkcolumn stage!!!");
            }
        }
Exemplo n.º 7
0
 internal void Initialize(WorldConfiguration config)
 {
     chunkCache = new ChunkCache();
     storage = new ChunkStorage();
     generator = config.Generator;
     Player = new Player();
     Player.PrevPosition = World.Instance.Player.Position = new Vector3(0, 100, -20);
     entityToControl = Player;
     globalEntities.Add(new Sun());
     globalEntities.Add(new Moon());
     globalEntities.Add(Player);
 }