Beispiel #1
0
        public void Index3LengthTest()
        {
            int    length = 2;
            Index3 i1     = new Index3(length, 0, 0);
            Index3 i2     = new Index3(0, length, 0);
            Index3 i3     = new Index3(0, 0, length);

            Assert.Equals(i1.LengthSquared(), 4.0);
            Assert.Equals(i2.LengthSquared(), 4.0);
            Assert.Equals(i3.LengthSquared(), 4.0);

            Assert.Equals(i1.Length(), 2.0);
            Assert.Equals(i2.Length(), 2.0);
            Assert.Equals(i3.Length(), 2.0);

            Index3 i4 = new Index3(3, 2, 4);
            Index3 i5 = new Index3(3, 4, 2);
            Index3 i6 = new Index3(4, 2, 3);

            Assert.Equals(i4.LengthSquared(), 29.0);
            Assert.Equals(i5.LengthSquared(), 29.0);
            Assert.Equals(i6.LengthSquared(), 29.0);
        }
Beispiel #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);
        }
Beispiel #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);
        }