예제 #1
0
 public void ChunkPositionTest()
 {
     WorldPosition target = new WorldPosition(); // TODO: Passenden Wert initialisieren
     WorldPosition actual;
     actual = target.ChunkPosition;
     Assert.Inconclusive("Überprüfen Sie die Richtigkeit dieser Testmethode.");
 }
예제 #2
0
 public override void UnregisterChunk(WorldPosition pos)
 {
     nc.Send(new PChunkUnregister
     {
         Position = pos
     });
 }
예제 #3
0
 public static bool Same(WorldPosition wp1, WorldPosition wp2)
 {
     if (wp1 == null || wp2 == null)
         return false;
     if (wp1.X != wp2.X)
         return false;
     if (wp1.Y != wp2.Y)
         return false;
     if (wp1.Z != wp2.Z)
         return false;
     return true;
 }
예제 #4
0
 public void ServerSetCell(WorldPosition position, uint value)
 {
     physics.Update(position);
     var ids = OctTree.GetTree(position.ChunkPosition).Set(position.X, position.Y, position.Z, value).ToList();
     foreach (var node in clientList.AsEnumerable)
         if (ids.Contains(node.Value.ID))
             node.Key.Send(new PChunkUpdate
             {
                 NewId = value,
                 Position = position
             });
 }
예제 #5
0
        public static int[,] GenerateHeightmap(WorldPosition position, int realExp, int bufferExp)
        {
            var gebirge = VolumeGenerator.getData2D(0xFF, position.X, position.Y, realExp, bufferExp, 0x10000000, 0x100, 0x200);
            var height2 = VolumeGenerator.getData2D(1, position.X, position.Y, realExp, bufferExp, 0x10000000, -0x100, 0x180);
            int bufferSize = 1 << bufferExp;
            var height = new int[bufferSize, bufferSize];
            for (int y = 0; y < bufferSize; y++)
                for (int x = 0; x < bufferSize; x++)
                    height[x, y] = /*(int)(*/height2[x, y]/* / Math.Pow(2, gebirge[x, y] / 42.5 / 0x8)) - 0x50*/;

            return height;
        }
예제 #6
0
 static void fillBuffer3D(WorldPosition chunkPosition, int[, ,] buffer, int x, int y, int z, int exp, int seed, int tolerance)
 {
     int d = 1 << exp;
     var seeds = getFrame3D(buffer, x, y, z, d, seed, tolerance);
     tolerance = toleranceStep(tolerance);
     for (int xx = 0; xx < 2; xx++)
         for (int yy = 0; yy < 2; yy++)
             for (int zz = 0; zz < 2; zz++)
             {
                 seed = seeds[xx, yy, zz] + toSeedComponent(chunkPosition.X + (uint)(x + xx * d), chunkPosition.Y + (uint)(y + yy * d), chunkPosition.Z + (uint)(z + zz * d));
                 if(d != 1)
                     fillBuffer3D(chunkPosition, buffer, x + xx * d, y + yy * d, z + zz * d, exp - 1, seed, tolerance);
             }
 }
예제 #7
0
        public static int[,] GenerateHeightmap(WorldPosition position, int realExp, int bufferExp)
        {
            var gebirge = VolumeGenerator.getData2D(0xFF, position.X, position.Y, realExp, bufferExp, 0x10000000, 0x100, 0x200);
            //var height2 = VolumeGenerator.getData2D(1, position.X, position.Y, realExp, bufferExp, 0x10000000, -0x100, 0x180);
            //var gebirge = VolumeGenerator.getData2D(42, position.X, position.Y, realExp, bufferExp, 0x30000000, -0x20, 0x10);
            var height2 = VolumeGenerator.getData2D(42, position.X, position.Y, realExp, bufferExp, 0x70000000, -0x10, 0x10);
            int bufferSize = 1 << bufferExp;
            var height = new int[bufferSize, bufferSize];
            for (int y = 0; y < bufferSize; y++)
                for (int x = 0; x < bufferSize; x++)
                    height[x, y] = gebirge[x,y] > 0 ?
                        (height2[x, y] + 0x10) :
                        height2[x, y];
                        //4;

            return height;
        }
예제 #8
0
파일: Octree.cs 프로젝트: olydis/FineCraft
 public static OctTree GetTree(WorldPosition position, uint userid)
 {
     var ot = GetObject<OctTree>(position.ToString(), userid);
     if (ot == null)
     {
         ot = new OctTree(new Chunk
         {
             Data = Generator.GenerateChunk(position).Cast<uint>().Select(x => (byte)x).ToArray(),
             Position = position,
             isUntouched = true
         });
         ot.chunk.Value = ot.chunk.Data[4095];
         ot.Optimize();
         RegisterNewObject(ot, false);
         return GetObject<OctTree>(ot.Key, userid);
     }
     return ot;
 }
예제 #9
0
        public static WorldPosition FirstHitWithSide(GameManager gm, int maxDist, WorldPosition absoluteOffset, Vector3 offset, Vector3 delta, out Vector3 side)
        {
            Vector3 current = offset;

            WorldPosition pos = new WorldPosition();
            while (true)
            {
                current = NextNewBlock(current, delta, out side);
                if ((current - offset).Length() > maxDist)
                    return null;
                pos.X = (uint)(absoluteOffset.X + (int)Math.Round(current.X));
                pos.Y = (uint)(absoluteOffset.Y + (int)Math.Round(current.Y));
                pos.Z = (uint)(absoluteOffset.Z + (int)Math.Round(current.Z));
                uint value = gm.GetValue(
                                pos.X,
                                pos.Y,
                                pos.Z);
                if (!BlockTypes.FromID(value).IsEmpty)
                    return pos;
            }
        }
예제 #10
0
        public static int[, ,] getData3D(WorldPosition chunkPosition, int seed, int tolerance)
        {
            int[, ,] buffer = new int[3,3,3];
            for (int i = 31; i > 3; i--)
            {
                var seeds = getFrame3D(buffer, 0, 0, 0, 1, seed, tolerance);
                tolerance = toleranceStep(tolerance);
                uint x = (chunkPosition.X >> i) & 1;
                uint y = (chunkPosition.Y >> i) & 1;
                uint z = (chunkPosition.Z >> i) & 1;
                seed = seeds[x, y, z];
                seed += toSeedComponent(chunkPosition.X & (0xFFFFFFFF << i), chunkPosition.Y & (0xFFFFFFFF << i), chunkPosition.Z & (0xFFFFFFFF << i));
                buffer[2 - 2 * x, 2 - 2 * y, 2 - 2 * z] = buffer[1, 1, 1];
                buffer[2 * x, 2 - 2 * y, 2 - 2 * z] = buffer[2 * x, 1, 1];
                buffer[2 - 2 * x, 2 * y, 2 - 2 * z] = buffer[1, 2 * y, 1];
                buffer[2 * x, 2 * y, 2 - 2 * z] = buffer[2 * y, 2 * y, 1];
                buffer[2 - 2 * x, 2 - 2 * y, 2 * z] = buffer[1, 1, 2 * z];
                buffer[2 * x, 2 - 2 * y, 2 * z] = buffer[2 * x, 1, 2 * z];
                buffer[2 - 2 * x, 2 * y, 2 * z] = buffer[1, 2 * y, 2 * z];
            }
            int[, ,] chunk = new int[17, 17, 17];
            chunk[0, 0, 0] = buffer[0, 0, 0];
            chunk[16, 0, 0] = buffer[2, 0, 0];
            chunk[0, 16, 0] = buffer[0, 2, 0];
            chunk[16, 16, 0] = buffer[2, 2, 0];
            chunk[0, 0, 16] = buffer[0, 0, 2];
            chunk[16, 0, 16] = buffer[2, 0, 2];
            chunk[0, 16, 16] = buffer[0, 2, 2];
            chunk[16, 16, 16] = buffer[2, 2, 2];
            fillBuffer3D(chunkPosition, chunk, 0, 0, 0, 3, seed, tolerance);

            interpolate(chunk);
            interpolate(chunk);
            interpolate(chunk);
            interpolate(chunk);

            return chunk;
        }
예제 #11
0
 public static WorldPosition FirstHitWithSide(GameManager gm, int maxDist, WorldPosition absoluteOffset, Matrix view, out Vector3 side)
 {
     view = Matrix.Invert(view);
     return FirstHitWithSide(gm, maxDist, absoluteOffset, view.Translation, view.Forward, out side);
 }
예제 #12
0
 public static WorldPosition FirstHit(GameManager gm, int maxDist, WorldPosition absoluteOffset, Vector3 offset, Vector3 delta)
 {
     Vector3 dummy;
     return FirstHitWithSide(gm, maxDist, absoluteOffset, offset, delta, out dummy);
 }
예제 #13
0
 public static WorldPosition FirstHit(GameManager gm, int maxDist, WorldPosition absoluteOffset, Matrix view)
 {
     Vector3 dummy;
     return FirstHitWithSide(gm, maxDist, absoluteOffset, view, out dummy);
 }
예제 #14
0
 public void ToStringTest()
 {
     WorldPosition target = new WorldPosition(); // TODO: Passenden Wert initialisieren
     string expected = string.Empty; // TODO: Passenden Wert initialisieren
     string actual;
     actual = target.ToString();
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Überprüfen Sie die Richtigkeit dieser Testmethode.");
 }
예제 #15
0
 public uint GetValue(WorldPosition pos)
 {
     return Static.Volume.ReadValue(pos.X, pos.Y, pos.Z);
 }
예제 #16
0
 public void SetValue(WorldPosition pos, uint value)
 {
     Static.Volume.UpdateChunk(pos.X, pos.Y, pos.Z, value);
     Static.DataProvider.UpdateChunk(new PChunkUpdate
     {
         Position = pos,
         NewId = value
     });
 }
예제 #17
0
        public void UpdatePosition()
        {
            chunkX = coordToChunkCoord(x);
            chunkY = coordToChunkCoord(y);
            chunkZ = coordToChunkCoord(z);

            UpdateMinimap();

            Chunk old;
            for (uint zz = unchecked((uint)-3); zz != 4; zz++)
                for (uint xx = unchecked((uint)-3); xx != 4; xx++)
                    for (uint yy = unchecked((uint)-3); yy != 4; yy++)
                    {
                        old = volume[coordToIndex(chunkX + 16 * xx), coordToIndex(chunkY + 16 * yy), coordToIndex(chunkZ + 16 * zz)];
                        if (old == null || old.X != chunkX + 16 * xx || old.Y != chunkY + 16 * yy || old.Z != chunkZ + 16 * zz)
                        {
                            if (old != null)
                            {
                                lock (vertexBuffers)
                                {
                                    FreeVertexBuffers(old);
                                    vertexBuffers.Remove(old);
                                }
                                provider.UnregisterChunk(old.Position);
                            }
                            var wp =
                                new WorldPosition
                                {
                                    X = chunkX + 16 * xx,
                                    Y = chunkY + 16 * yy,
                                    Z = chunkZ + 16 * zz
                                };
                            volume[coordToIndex(chunkX + 16 * xx), coordToIndex(chunkY + 16 * yy), coordToIndex(chunkZ + 16 * zz)] = new Chunk
                            {
                                Value = 0,
                                Data = null,
                                Position = wp
                            };
                            //int dist = Math.Abs((int)zz) + Math.Abs((int)yy) + Math.Abs((int)xx);
                            lock (chunkWishList)
                                chunkWishList.Add(wp);
                        }
                    }
        }
예제 #18
0
 Chunk regChunk(uint userid, WorldPosition position)
 {
     return OctTree.GetTree(position, userid).GetChunk();
 }
예제 #19
0
 public void Update(WorldPosition wp)
 {
     lock (toUpdate)
         toUpdate.Enqueue(wp);
 }
예제 #20
0
 public static int GenerateHeight(WorldPosition position)
 {
     return GenerateHeightmap(position, 1, 1)[0,0];
 }
예제 #21
0
 public abstract void UnregisterChunk(WorldPosition pos);
예제 #22
0
 void ValidatePhysics(WorldPosition wp)
 {
 }
예제 #23
0
 public void Goto(WorldPosition pos)
 {
     center = Vector3.Zero;
     Position = pos;
 }
예제 #24
0
        public static uint[, ,] GenerateChunk(WorldPosition position)
        {
            Func<string, uint> nameToId = id => BlockTypes.FromID(id).ID;

            var buffer = new uint[16, 16, 16];

            var height = GenerateHeightmap(position, 4, 4);
            
            int caveLayers = 20;
            //cave
            var caveData = Enumerable
                .Range(0x100, caveLayers)
                .Select(seed => VolumeGenerator.getData2D(seed, position.X, position.Y, 4, 4, 0x30000000, -0x30000000, 0x30000000))
                .ToArray();
            var caveDepth = Enumerable
                .Range(0x200, caveLayers)
                .Select(seed => VolumeGenerator.getData2D(seed, position.X, position.Y, 4, 4, 0x10000000, -0x400, 0x400))
                .ToArray();

            for (uint xx = 0; xx < 16; xx++)
                for (uint yy = 0; yy < 16; yy++)
                {
                    for (uint zz = 0; zz < 16; zz++)
                    {
                        int absoluteCurrentHeight = (int)(position.Z + zz - 0x80000000);
                        int absoluteGroundHeight = height[xx, yy];

                        if (-0x1100 < absoluteCurrentHeight && absoluteCurrentHeight < 0x1100)
                        {
                            int tiefe = absoluteGroundHeight - absoluteCurrentHeight;
                            if (tiefe >= 0)
                            {
                                uint radius = (uint)tiefe / 5 + 2;
                                if (radius > 10) radius = 10;

                                uint data;
                                bool cave;
                                bool noGround = false;
                                for (int i = 0; i < caveLayers; i++)
                                {
                                    data = (uint)caveData[i][xx, yy];
                                    data %= 0x40;
                                    data = HelpfulStuff.abs(data - 0x20);
                                    cave = data < radius;
                                    if (cave)
                                    {
                                        data = radius - data;
                                        cave = HelpfulStuff.abs((uint)absoluteCurrentHeight - (uint)caveDepth[i][xx, yy]) < data;
                                        if (!cave)
                                            cave = HelpfulStuff.abs((uint)absoluteCurrentHeight - (uint)caveDepth[(i + caveLayers / 8) % caveLayers][xx, yy] / 2) < data;
                                        if (!cave)
                                            cave = HelpfulStuff.abs((uint)absoluteCurrentHeight - (uint)caveDepth[(i + caveLayers * 2 / 8) % caveLayers][xx, yy] + 0x20) < data;
                                        if (!cave)
                                            cave = HelpfulStuff.abs((uint)absoluteCurrentHeight - (uint)caveDepth[(i + caveLayers * 3 / 8) % caveLayers][xx, yy] * 2) < data;
                                        //if (!cave)
                                        //    cave = HelpfulStuff.abs((uint)absoluteCurrentHeight - (uint)caveDepth[(i + caveLayers * 4 / 8) % caveLayers][xx, yy]) < data;
                                        //if (!cave)
                                        //    cave = HelpfulStuff.abs((uint)absoluteCurrentHeight - (uint)caveDepth[(i + caveLayers * 5 / 8) % caveLayers][xx, yy] / 2) < data;
                                        //if (!cave)
                                        //    cave = HelpfulStuff.abs((uint)absoluteCurrentHeight - (uint)caveDepth[(i + caveLayers * 6 / 8) % caveLayers][xx, yy] - 0x20) < data;
                                        //if (!cave)
                                        //    cave = HelpfulStuff.abs((uint)absoluteCurrentHeight - (uint)caveDepth[(i + caveLayers * 7 / 8) % caveLayers][xx, yy] * 2) < data;
                                    }
                                    if (cave)
                                    {
                                        buffer[xx, yy, zz] = nameToId("Air");
                                        goto done;
                                    }
                                }

                                if (tiefe == 0)
                                    buffer[xx, yy, zz] = /*noGround ? nameToId("Marble") :*/ nameToId("Grass");
                                else if (tiefe < 0x80)
                                    buffer[xx, yy, zz] = nameToId("Dirt");
                                else
                                    buffer[xx, yy, zz] = nameToId("Stone");

                            done: ;
                            }
                            else
                            {
                                if (tiefe == -1)
                                {
                                    if (absoluteGroundHeight > 0 && absoluteGroundHeight < 0x400)
                                        if (caveData[0][xx, yy] % 10 == 0 && caveData[1][xx, yy] % 13 == 0)
                                        {
                                            buffer[xx, yy, zz] = nameToId("Flower");
                                            goto noair;
                                        }
                                    if (absoluteGroundHeight > 0 && absoluteGroundHeight < 0x400)
                                        if (caveData[0][xx, yy] % 8 == 0 && caveData[1][xx, yy] % 13 == 0)
                                        {
                                            buffer[xx, yy, zz] = nameToId("Bush");
                                            goto noair;
                                        }
                                }
                                buffer[xx, yy, zz] = nameToId(absoluteCurrentHeight >= 0 ? "Air" : "Water");
                            noair: ;
                            }
                        }
                    }
                }
            return buffer;
        }
예제 #25
0
 void unregChunk(uint userid, WorldPosition position)
 {
     OctTree.GetTree(position).Useless(userid);
 }
예제 #26
0
 public void FastDistanceTest()
 {
     WorldPosition target = new WorldPosition(); // TODO: Passenden Wert initialisieren
     uint x = 0; // TODO: Passenden Wert initialisieren
     uint y = 0; // TODO: Passenden Wert initialisieren
     uint z = 0; // TODO: Passenden Wert initialisieren
     uint expected = 0; // TODO: Passenden Wert initialisieren
     uint actual;
     actual = target.FastDistance(x, y, z);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Überprüfen Sie die Richtigkeit dieser Testmethode.");
 }
예제 #27
0
        public void Render(BoundingFrustum frustum, WorldPosition hoverBox)
        {
            int vertices = 0;
            uint cx = x;
            uint cy = y; //cache = anti-earthquake
            uint cz = z;
            Matrix world = Matrix.Identity;
            Vector3 middle = new Vector3(8, 8, 8);
            foreach (var node in vertexBuffers.AsEnumerable)
            {
                if (node.Value == null)
                    continue;
                world.Translation = new Vector3((int)(node.Key.X - cx), (int)(node.Key.Y - cy), (int)(node.Key.Z - cz));
                bs.Center = middle + world.Translation;

                if (ContainmentType.Disjoint == frustum.Contains(bs))
                    continue;
                effect.WMatrix = world;

                effect.BeginPass3D();
                device.Indices = Static.Indices;
                VBuffer7 vbuffer = node.Value;
                device.Vertices[0].SetSource(vbuffer.VertexBuffer, 0, VertexAwesome.SizeInBytes);
                Action<int> draw =
                    i =>
                    {
                        if (vbuffer.Count[i] != 0)
                        {
                            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, vbuffer.Offset[i], 0, vbuffer.Count[i], 0, vbuffer.Count[i] / 2);
                            vertices += vbuffer.Count[i];
                        }
                    };
                if (node.Key.Z - cz - 1 > 0x80000000) draw(0);
                if (node.Key.Z - cz + 16 < 0x80000000) draw(1);
                if (node.Key.X - cx - 1 > 0x80000000) draw(2);
                if (node.Key.X - cx + 16 < 0x80000000) draw(3);
                if (node.Key.Y - cy - 1 > 0x80000000) draw(4);
                if (node.Key.Y - cy + 16 < 0x80000000) draw(5);
                draw(6);
                effect.EndPass3D();
            }
            this.Vertices = vertices;

            //hovered box:
            if (hoverBox != null)
            {
                Static.Effect.LightDirection = Vector3.Backward;
                Static.Effect.AmbientLightColor = Color.LightGreen.ToVector4();
                hoverBoxMesh.Draw(Matrix.CreateTranslation((int)(hoverBox.X - cx), (int)(hoverBox.Y - cy), (int)(hoverBox.Z - cz)));
            }
        }
예제 #28
0
 public void DeserializeTest()
 {
     WorldPosition target = new WorldPosition(); // TODO: Passenden Wert initialisieren
     BinaryReader reader = null; // TODO: Passenden Wert initialisieren
     target.Deserialize(reader);
     Assert.Inconclusive("Eine Methode, die keinen Wert zurückgibt, kann nicht überprüft werden.");
 }
예제 #29
0
 public void UpdatePositionFast(WorldPosition pos)
 {
     x = pos.X;
     y = pos.Y;
     z = pos.Z;
 }
예제 #30
0
 public void WorldPositionConstructorTest()
 {
     WorldPosition target = new WorldPosition();
     Assert.Inconclusive("TODO: Code zum Überprüfen des Ziels implementieren");
 }