Exemplo n.º 1
0
        public void Index2NormaizeMethodenTest()
        {
            Index2 i1  = new Index2(20, 20);     // Startwert
            Index2 i2  = new Index2(12, 13);     // 2D-Size
            Index3 i2b = new Index3(12, 13, 14); // 3D-Size
            Index2 i3  = new Index2(8, 20);      // Ergebnis bei NormX
            Index2 i4  = new Index2(20, 7);      // Ergebnis bei NormY
            Index2 i5  = new Index2(8, 7);       // Ergebnis bei NormXY

            // Norm X (int)
            Index2 t = i1;

            t.NormalizeX(i2.X);
            Assert.Equals(i3, t);

            // Norm X (index2)
            t = i1;
            t.NormalizeX(i2);
            Assert.Equals(i3, t);

            // Norm X (index3)
            t = i1;
            t.NormalizeX(i2b);
            Assert.Equals(i3, t);

            // Norm Y (int)
            t = i1;
            t.NormalizeY(i2.Y);
            Assert.Equals(i4, t);

            // Norm Y (index2)
            t = i1;
            t.NormalizeY(i2);
            Assert.Equals(i4, t);

            // Norm Y (index3)
            t = i1;
            t.NormalizeY(i2b);
            Assert.Equals(i4, t);

            // Norm XY (int)
            t = i1;
            t.NormalizeXY(i2.X, i2.Y);
            Assert.Equals(i5, t);

            // Norm XY (index2)
            t = i1;
            t.NormalizeXY(i2);
            Assert.Equals(i5, t);

            // Norm XY (index3)
            t = i1;
            t.NormalizeXY(i2b);
            Assert.Equals(i5, t);
        }
Exemplo n.º 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;
        }
Exemplo n.º 3
0
        private IChunkColumn loadChunkColumn(int planetId, Index2 index)
        {
            IPlanet planet = GetPlanet(planetId);

            // Load from disk
            IChunkColumn column11 = persistenceManager.LoadColumn(universe.Id, planet, index);

            if (column11 == null)
            {
                IChunkColumn column = planet.Generator.GenerateColumn(DefinitionManager.Instance.GetBlockDefinitions(), planet, new Index2(index.X, index.Y));
                column11 = column;
            }

            IChunkColumn column00 = GlobalChunkCache.Peek(planet.Id, Index2.NormalizeXY(index + new Index2(-1, -1), planet.Size));
            IChunkColumn column10 = GlobalChunkCache.Peek(planet.Id, Index2.NormalizeXY(index + new Index2(0, -1), planet.Size));
            IChunkColumn column20 = GlobalChunkCache.Peek(planet.Id, Index2.NormalizeXY(index + new Index2(1, -1), planet.Size));

            IChunkColumn column01 = GlobalChunkCache.Peek(planet.Id, Index2.NormalizeXY(index + new Index2(-1, 0), planet.Size));
            IChunkColumn column21 = GlobalChunkCache.Peek(planet.Id, Index2.NormalizeXY(index + new Index2(1, 0), planet.Size));

            IChunkColumn column02 = GlobalChunkCache.Peek(planet.Id, Index2.NormalizeXY(index + new Index2(-1, 1), planet.Size));
            IChunkColumn column12 = GlobalChunkCache.Peek(planet.Id, Index2.NormalizeXY(index + new Index2(0, 1), planet.Size));
            IChunkColumn column22 = GlobalChunkCache.Peek(planet.Id, Index2.NormalizeXY(index + new Index2(1, 1), planet.Size));

            // Populatoren erzeugen
            if (populators == null)
            {
                populators = ExtensionManager.GetInstances <IMapPopulator>().OrderBy(p => p.Order).ToList();
            }

            // Zentrum
            if (!column11.Populated && column21 != null && column12 != null && column22 != null)
            {
                foreach (var populator in populators)
                {
                    populator.Populate(DefinitionManager.Instance, planet, column11, column21, column12, column22);
                }

                column11.Populated = true;
            }

            // Links oben
            if (column00 != null && !column00.Populated && column10 != null && column01 != null)
            {
                foreach (var populator in populators)
                {
                    populator.Populate(DefinitionManager.Instance, planet, column00, column10, column01, column11);
                }

                column00.Populated = true;
            }

            // Oben
            if (column10 != null && !column10.Populated && column20 != null && column21 != null)
            {
                foreach (var populator in populators)
                {
                    populator.Populate(DefinitionManager.Instance, planet, column10, column20, column11, column21);
                }
                column10.Populated = true;
            }

            // Links
            if (column01 != null && !column01.Populated && column02 != null && column12 != null)
            {
                foreach (var populator in populators)
                {
                    populator.Populate(DefinitionManager.Instance, planet, column01, column11, column02, column12);
                }
                column01.Populated = true;
            }

            return(column11);
        }
Exemplo n.º 4
0
        private bool FillChunkRenderer()
        {
            Index2 destinationChunk = new Index2(player.ActorHost.Position.ChunkIndex);

            // Nur ausführen wenn der Spieler den Chunk gewechselt hat
            if (destinationChunk != currentChunk)
            {
                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(_manager, local.X, local.Y, z);
                        }
                    }
                }

                currentChunk = destinationChunk;
            }

            #region Chunkrenderer updaten

            //            int shortestDistance = int.MaxValue;
            //            ChunkRenderer updatableRenderer = null;
            foreach (var renderer in chunkRenderer)
            {
                if (!renderer.NeedUpdate())
                    continue;

                renderer.RegenerateVertexBuffer();

                //                Index2 absoluteIndex = new Index2(renderer.ChunkPosition.Value);
                //                Index2 relativeIndex = destinationChunk.ShortestDistanceXY(
                //                                   absoluteIndex, new Index2(
                //                                       planet.Size.X,
                //                                       planet.Size.Y));
                //
                //                int distance = relativeIndex.LengthSquared();
                //                if (distance < shortestDistance)
                //                {
                //                    updatableRenderer = renderer;
                //                    shortestDistance = distance;
                //                }
            }

            //            if (updatableRenderer != null)
            //                updatableRenderer.RegenerateVertexBuffer();

            #endregion

            return true;
            //            return updatableRenderer != null;
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        private bool FillChunkRenderer()
        {
            Index2 destinationChunk = new Index2(player.ActorHost.Position.ChunkIndex);

            // Nur ausführen wenn der Spieler den Chunk gewechselt hat
            if (destinationChunk != currentChunk)
            {
                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(_manager, local.X, local.Y, z);
                        }
                    }
                }

                currentChunk = destinationChunk;
            }

            #region Chunkrenderer updaten

            //            int shortestDistance = int.MaxValue;
            //            ChunkRenderer updatableRenderer = null;
            foreach (var renderer in chunkRenderer)
            {
                if (!renderer.NeedUpdate())
                {
                    continue;
                }

                renderer.RegenerateVertexBuffer();

                //                Index2 absoluteIndex = new Index2(renderer.ChunkPosition.Value);
                //                Index2 relativeIndex = destinationChunk.ShortestDistanceXY(
                //                                   absoluteIndex, new Index2(
                //                                       planet.Size.X,
                //                                       planet.Size.Y));
                //
                //                int distance = relativeIndex.LengthSquared();
                //                if (distance < shortestDistance)
                //                {
                //                    updatableRenderer = renderer;
                //                    shortestDistance = distance;
                //                }
            }

            //            if (updatableRenderer != null)
            //                updatableRenderer.RegenerateVertexBuffer();

            #endregion

            return(true);
            //            return updatableRenderer != null;
        }