Exemple #1
0
        public void Index3ShortestDistanceMethodenTest()
        {
            Index3 size = new Index3(20, 20, 20);
            Index3 i1   = new Index3(5, 7, 6);   // Startwert
            Index3 i2   = new Index3(12, 13, 8); // Destinations
            Index3 i3   = new Index3(7, 6, 2);   // Results

            Assert.AreEqual(i3.X, i1.ShortestDistanceX(i2.X, size.X));
            Assert.AreEqual(i3.Y, i1.ShortestDistanceY(i2.Y, size.Y));
            Assert.AreEqual(i3.Z, i1.ShortestDistanceZ(i2.Z, size.Z));

            Assert.AreEqual(new Index2(i3.X, i3.Y), i1.ShortestDistanceXY(new Index2(i2.X, i2.Y), new Index2(size.X, size.Y)));
            Assert.AreEqual(new Index3(i3.X, i3.Y, i2.Z - i1.Z), i1.ShortestDistanceXY(i2, new Index2(size.X, size.Y)));

            Assert.AreEqual(i3, i1.ShortestDistanceXYZ(i2, size));
        }
        public void Index3ShortestDistanceMethodenTest()
        {
            Index3 size = new Index3(20, 20, 20);
            Index3 i1 = new Index3(5, 7, 6); // Startwert
            Index3 i2 = new Index3(12, 13, 8); // Destinations
            Index3 i3 = new Index3(7, 6, 2); // Results

            Assert.AreEqual(i3.X, i1.ShortestDistanceX(i2.X, size.X));
            Assert.AreEqual(i3.Y, i1.ShortestDistanceY(i2.Y, size.Y));
            Assert.AreEqual(i3.Z, i1.ShortestDistanceZ(i2.Z, size.Z));

            Assert.AreEqual(new Index2(i3.X, i3.Y), i1.ShortestDistanceXY(new Index2(i2.X, i2.Y), new Index2(size.X, size.Y)));
            Assert.AreEqual(new Index3(i3.X, i3.Y, i2.Z - i1.Z), i1.ShortestDistanceXY(i2, new Index2(size.X, size.Y)));

            Assert.AreEqual(i3, i1.ShortestDistanceXYZ(i2, size));
        }
Exemple #3
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);
        }
Exemple #4
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);
        }