示例#1
0
 /// <summary>
 /// Initialisiert den ActorHost und lädtc die Chunks rund um den Spieler.
 /// </summary>
 public void Initialize()
 {
     localChunkCache.SetCenter(planet, new Index2(Player.Position.ChunkIndex), (success) =>
     {
         ReadyState = success;
     });
 }
示例#2
0
        private bool FillChunkRenderer()
        {
            if (player.ActorHost == null)
            {
                return(false);
            }

            Index2 destinationChunk = new Index2(player.ActorHost.Position.ChunkIndex);

            // Nur ausführen wenn der Spieler den Chunk gewechselt hat
            if (destinationChunk != currentChunk)
            {
                localChunkCache.SetCenter(planet, new Index2(player.ActorHost.Position.ChunkIndex));

                int mask      = (int)Math.Pow(2, VIEWRANGE) - 1;
                int span      = (int)Math.Pow(2, VIEWRANGE);
                int spanOver2 = span >> 1;

                for (int x = 0; x < span; x++)
                {
                    for (int y = 0; y < span; y++)
                    {
                        Index2 local = new Index2(x - spanOver2, y - spanOver2) + destinationChunk;
                        local.NormalizeXY(planet.Size);

                        int virtualX = local.X & mask;
                        int virtualY = local.Y & mask;

                        int rendererIndex = virtualX +
                                            (virtualY << VIEWRANGE);

                        for (int z = 0; z < planet.Size.Z; z++)
                        {
                            chunkRenderer[rendererIndex, z].SetChunk(localChunkCache, local.X, local.Y, z);
                        }
                    }
                }

                Index3 comparationIndex = player.ActorHost.Position.ChunkIndex;
                orderedChunkRenderer.Sort((x, y) =>
                {
                    if (!x.ChunkPosition.HasValue)
                    {
                        return(1);
                    }
                    if (!y.ChunkPosition.HasValue)
                    {
                        return(-1);
                    }

                    Index3 distX = comparationIndex.ShortestDistanceXYZ(x.ChunkPosition.Value, planet.Size);
                    Index3 distY = comparationIndex.ShortestDistanceXYZ(y.ChunkPosition.Value, planet.Size);
                    return(distX.LengthSquared().CompareTo(distY.LengthSquared()));
                });

                currentChunk = destinationChunk;
            }

            foreach (var renderer in orderedChunkRenderer)
            {
                if (!renderer.NeedUpdate())
                {
                    continue;
                }

                renderer.RegenerateVertexBuffer();
                return(true);
            }

            return(false);
        }
示例#3
0
        private void FillChunkRenderer()
        {
            if (player?.CurrentEntity == null)
            {
                return;
            }

            Index2 destinationChunk = new Index2(player.Position.Position.ChunkIndex);

            // Nur ausführen wenn der Spieler den Chunk gewechselt hat
            if (destinationChunk != currentChunk)
            {
                localChunkCache.SetCenter(
                    new Index2(player.Position.Position.ChunkIndex),
                    b =>
                {
                    if (b)
                    {
                        fillResetEvent.Set();
                        OnCenterChanged?.Invoke(this, System.EventArgs.Empty);
                    }
                });

                for (int x = 0; x < Span; x++)
                {
                    for (int y = 0; y < Span; y++)
                    {
                        Index2 local = new Index2(x - SpanOver2, y - SpanOver2) + destinationChunk;
                        local.NormalizeXY(planet.Size);

                        int virtualX = local.X & Mask;
                        int virtualY = local.Y & Mask;

                        int rendererIndex = virtualX +
                                            (virtualY << VIEWRANGE);

                        for (int z = 0; z < planet.Size.Z; z++)
                        {
                            chunkRenderer[rendererIndex, z].SetChunk(localChunkCache, local.X, local.Y, z);
                        }
                    }
                }

                Index3 comparationIndex = player.Position.Position.ChunkIndex;
                orderedChunkRenderer.Sort((x, y) =>
                {
                    if (!x.ChunkPosition.HasValue)
                    {
                        return(1);
                    }
                    if (!y.ChunkPosition.HasValue)
                    {
                        return(-1);
                    }

                    Index3 distX = comparationIndex.ShortestDistanceXYZ(x.ChunkPosition.Value, planet.Size);
                    Index3 distY = comparationIndex.ShortestDistanceXYZ(y.ChunkPosition.Value, planet.Size);
                    return(distX.LengthSquared().CompareTo(distY.LengthSquared()));
                });

                currentChunk = destinationChunk;
            }

            foreach (var e in additionalFillResetEvents)
            {
                e.Set();
            }

            RegenerateAll(0);
        }