示例#1
0
 public override PhysicalProperties GetProperties(ILocalChunkCache manager, int x, int y, int z)
 {
     return new PhysicalProperties()
     {
         Density = 1.5f,
         FractureToughness = 0.2f,
         Granularity = 0.9f,
         Hardness = 0.05f
     };
 }
示例#2
0
        public ActorHost(Player player)
        {
            Player = player;
            planet = ResourceManager.Instance.GetPlanet(Player.Position.Planet);

            localChunkCache = new LocalChunkCache(ResourceManager.Instance.GlobalChunkCache, 2, 1, true);
            _oldIndex = Player.Position.ChunkIndex;

            ActiveTool = null;
            ReadyState = false;
        }
示例#3
0
        public void SetChunk(ILocalChunkCache manager, int x, int y, int z)
        {
            var newPosition = new Index3(x, y, z);

            if (_manager == manager && newPosition == ChunkPosition)
                return;

            _manager = manager;
            ChunkPosition = newPosition;

            chunk = null;
            loaded = false;
        }
        public override int GetBottomTextureRotation(ILocalChunkCache manager, int x, int y, int z)
        {
            OrientationFlags orientation = (OrientationFlags)manager.GetBlockMeta(x, y, z);

            switch (orientation)
            {
                case OrientationFlags.SideWest:
                case OrientationFlags.SideEast:
                    return 1;
                case OrientationFlags.SideSouth:
                case OrientationFlags.SideNorth:
                case OrientationFlags.SideBottom:
                case OrientationFlags.SideTop:
                default:
                    return 0;
            }
        }
        public override int GetBottomTextureRotation(ILocalChunkCache manager, int x, int y, int z)
        {
            OrientationFlags orientation = (OrientationFlags)manager.GetBlockMeta(x, y, z);

            switch (orientation)
            {
            case OrientationFlags.SideWest:
            case OrientationFlags.SideEast:
                return(1);

            case OrientationFlags.SideSouth:
            case OrientationFlags.SideNorth:
            case OrientationFlags.SideBottom:
            case OrientationFlags.SideTop:
            default:
                return(0);
            }
        }
示例#6
0
        public override int GetTextureRotation(Wall wall, ILocalChunkCache manager, int x, int y, int z)
        {
            OrientationFlags orientation = (OrientationFlags)manager.GetBlockMeta(x, y, z);

            switch (wall)
            {
            case Wall.Top:
            case Wall.Bottom:
            case Wall.Back:
            case Wall.Front:
                switch (orientation)
                {
                case OrientationFlags.SideWest:
                case OrientationFlags.SideEast:
                    return(1);

                case OrientationFlags.SideSouth:
                case OrientationFlags.SideNorth:
                case OrientationFlags.SideBottom:
                case OrientationFlags.SideTop:
                default:
                    return(0);
                }

            case Wall.Left:
            case Wall.Right:
                switch (orientation)
                {
                case OrientationFlags.SideSouth:
                case OrientationFlags.SideNorth:
                    return(1);

                case OrientationFlags.SideWest:
                case OrientationFlags.SideEast:
                case OrientationFlags.SideBottom:
                case OrientationFlags.SideTop:
                default:
                    return(0);
                }

            default:
                return(base.GetTextureRotation(wall, manager, x, y, z));    //should never ever happen
            }
        }
        public override int GetEastTextureIndex(ILocalChunkCache manager, int x, int y, int z)
        {
            OrientationFlags orientation = (OrientationFlags)manager.GetBlockMeta(x, y, z);
            ushort topblock = manager.GetBlock(x, y, z + 1);

            switch (orientation)
            {
                case OrientationFlags.SideWest:
                case OrientationFlags.SideEast:
                    if (topblock != 0)
                        return 0;
                    else
                        return 2;
                case OrientationFlags.SideSouth:
                case OrientationFlags.SideNorth:
                case OrientationFlags.SideBottom:
                case OrientationFlags.SideTop:
                default:
                    return 1;
            }
        }
示例#8
0
        public void SetChunk(ILocalChunkCache manager, int x, int y, int z)
        {
            var newPosition = new Index3(x, y, z);

            if (_manager == manager && newPosition == ChunkPosition)
            {
                NeedsUpdate = !loaded;
                return;
            }

            _manager      = manager;
            ChunkPosition = newPosition;

            if (chunk != null)
            {
                chunk.Changed -= OnChunkChanged;
                chunk          = null;
            }

            loaded      = false;
            NeedsUpdate = true;
        }
示例#9
0
 /// <summary>
 /// Texturindex für das Array <see cref="Textures"/> für die Westseite (Negativ X) des Blocks
 /// </summary>
 /// <param name="manager">[Bitte ergänzen]</param>
 /// <param name="x">X-Anteil der Koordinate des Blocks</param>
 /// <param name="y">Y-Anteil der Koordinate des Blocks</param>
 /// <param name="z">Z-Anteil der Koordinate des Blocks</param>
 /// <returns>Index für das Array <see cref="Textures"/></returns>
 public virtual int GetWestTextureIndex(ILocalChunkCache manager, int x, int y, int z)
 {
     return 0;
 }
示例#10
0
 /// <summary>
 /// Liefert die Physikalischen Paramerter, wie härte, dichte und bruchzähigkeit
 /// </summary>
 /// <param name="manager"></param>
 /// <param name="x">X-Anteil der Koordinate des Blocks</param>
 /// <param name="y">Y-Anteil der Koordinate des Blocks</param>
 /// <param name="z">Z-Anteil der Koordinate des Blocks</param>
 /// <returns>Die physikalischen Parameter</returns>
 public abstract PhysicalProperties GetProperties(ILocalChunkCache manager, int x, int y, int z);
示例#11
0
 public override int GetEastTextureIndex(ILocalChunkCache manager, int x, int y, int z)
 {
     return(2);
 }
示例#12
0
 /// <summary>
 /// Gibt an, ob die Ostseite (Negativ X) undurchsichtig ist, also Blöcke dahinter nicht gesehen werden können
 /// </summary>
 /// <param name="manager">[Bitte ergänzen]</param>
 /// <param name="x">X-Anteil der Koordinate des Blocks</param>
 /// <param name="y">Y-Anteil der Koordinate des Blocks</param>
 /// <param name="z">Z-Anteil der Koordinate des Blocks</param>
 /// <returns>True, wenn die Wand undurchsichtig ist</returns>
 public virtual bool IsEastSolidWall(ILocalChunkCache manager, int x, int y, int z)
 {
     return(true);
 }
示例#13
0
        public SceneControl(ScreenComponent manager, string style = "")
            : base(manager, style)
        {
            player = manager.Player;
            camera = manager.Camera;

            Manager = manager;

            simpleShader = manager.Game.Content.Load<Effect>("simple");
            sunTexture = manager.Game.Content.LoadTexture2DFromFile("./Assets/OctoAwesome.Client/sun.png", manager.GraphicsDevice);

            List<Bitmap> bitmaps = new List<Bitmap>();
            var definitions = DefinitionManager.Instance.GetBlockDefinitions();
            foreach (var definition in definitions)
                bitmaps.AddRange(definition.Textures);

            int size = (int)Math.Ceiling(Math.Sqrt(bitmaps.Count));
            Bitmap blocks = new Bitmap(size * TEXTURESIZE, size * TEXTURESIZE);
            using (Graphics g = Graphics.FromImage(blocks))
            {
                int counter = 0;
                foreach (var bitmap in bitmaps)
                {
                    int x = counter % size;
                    int y = (int)(counter / size);
                    g.DrawImage(bitmap, new System.Drawing.Rectangle(TEXTURESIZE * x, TEXTURESIZE * y, TEXTURESIZE, TEXTURESIZE));
                    counter++;
                }
            }

            using (MemoryStream stream = new MemoryStream())
            {
                blocks.Save(stream, ImageFormat.Png);
                stream.Seek(0, SeekOrigin.Begin);
                blockTextures = Texture2D.FromStream(manager.GraphicsDevice, stream);
            }

            planet = ResourceManager.Instance.GetPlanet(0);

            // TODO: evtl. Cache-Size (Dimensions) VIEWRANGE + 1

            int range = ((int)Math.Pow(2, VIEWRANGE) - 2) / 2;
            localChunkCache = new LocalChunkCache(ResourceManager.Instance.GlobalChunkCache, VIEWRANGE, range);

            chunkRenderer = new ChunkRenderer[
                (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE),
                planet.Size.Z];
            orderedChunkRenderer = new List<ChunkRenderer>(
                (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE) * planet.Size.Z);

            for (int i = 0; i < chunkRenderer.GetLength(0); i++)
            {
                for (int j = 0; j < chunkRenderer.GetLength(1); j++)
                {
                    ChunkRenderer renderer = new ChunkRenderer(simpleShader, manager.GraphicsDevice, camera.Projection, blockTextures);
                    chunkRenderer[i, j] = renderer;
                    orderedChunkRenderer.Add(renderer);
                }
            }

            backgroundThread = new Thread(BackgroundLoop);
            backgroundThread.Priority = ThreadPriority.Lowest;
            backgroundThread.IsBackground = true;
            backgroundThread.Start();

            selectionLines = new[]
            {
                new VertexPositionColor(new Vector3(-0.001f, +1.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, +1.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(-0.001f, -0.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, -0.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(-0.001f, +1.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, +1.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(-0.001f, -0.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, -0.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f),
            };

            billboardVertices = new[]
            {
                new VertexPositionTexture(new Vector3(-0.5f, 0.5f, 0), new Vector2(0, 0)),
                new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)),
                new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)),
                new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)),
                new VertexPositionTexture(new Vector3(0.5f, -0.5f, 0), new Vector2(1, 1)),
                new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)),
            };

            selectionIndeces = new short[]
            {
                0, 1, 0, 2, 1, 3, 2, 3,
                4, 5, 4, 6, 5, 7, 6, 7,
                0, 4, 1, 5, 2, 6, 3, 7
            };

            sunEffect = new BasicEffect(manager.GraphicsDevice);
            sunEffect.TextureEnabled = true;

            selectionEffect = new BasicEffect(manager.GraphicsDevice);
            selectionEffect.VertexColorEnabled = true;

            MiniMapTexture = new RenderTarget2D(manager.GraphicsDevice, 128, 128, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8); // , false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents);
            miniMapProjectionMatrix = Matrix.CreateOrthographic(128, 128, 1, 10000);
        }
 public override bool IsEastSolidWall(ILocalChunkCache manager, int x, int y, int z)
 {
     return(false);
 }
示例#15
0
 /// <summary>
 /// Liefert die Kollisionsbox für den Block. Da ein Array zurück gegeben wird, lässt sich die 
 /// </summary>
 /// <param name="manager">[Bitte ergänzen]</param>
 /// <param name="x">X-Anteil der Koordinate des Blocks</param>
 /// <param name="y">Y-Anteil der Koordinate des Blocks</param>
 /// <param name="z">Z-Anteil der Koordinate des Blocks</param>
 /// <returns>Ein Array von Kollisionsboxen</returns>
 public virtual BoundingBox[] GetCollisionBoxes(ILocalChunkCache manager, int x, int y, int z)
 {
     return new[] { new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)) };
 }
示例#16
0
        public override int GetTextureIndex(Wall wall, ILocalChunkCache manager, int x, int y, int z)
        {
            OrientationFlags orientation = (OrientationFlags)manager.GetBlockMeta(x, y, z);

            switch (wall)
            {
            case Wall.Top:
            case Wall.Bottom:
            {
                switch (orientation)
                {
                case OrientationFlags.SideWest:
                case OrientationFlags.SideEast:
                case OrientationFlags.SideSouth:
                case OrientationFlags.SideNorth:
                    return(1);

                case OrientationFlags.SideBottom:
                case OrientationFlags.SideTop:
                default:
                    return(0);
                }
            }

            case Wall.Back:     // North
            case Wall.Front:    // South
            {
                switch (orientation)
                {
                case OrientationFlags.SideSouth:
                case OrientationFlags.SideNorth:
                    return(0);

                case OrientationFlags.SideWest:
                case OrientationFlags.SideEast:
                case OrientationFlags.SideBottom:
                case OrientationFlags.SideTop:
                default:
                    return(1);
                }
            }

            case Wall.Left:
            case Wall.Right:
            {
                switch (orientation)
                {
                case OrientationFlags.SideWest:
                case OrientationFlags.SideEast:
                    return(0);

                case OrientationFlags.SideSouth:
                case OrientationFlags.SideNorth:
                case OrientationFlags.SideBottom:
                case OrientationFlags.SideTop:
                default:
                    return(1);
                }
            }
            }

            // Assert this
            return(-1);
        }
 public override PhysicalProperties GetProperties(ILocalChunkCache manager, int x, int y, int z)
 {
     throw new NotImplementedException();
 }
 public override PhysicalProperties GetProperties(ILocalChunkCache manager, int x, int y, int z)
 {
     throw new NotImplementedException();
 }
示例#19
0
 public LocalChunkCacheComponent(IGlobalChunkCache globalChunkCache, int dimensions, int range)
 {
     LocalChunkCache = new LocalChunkCache(globalChunkCache, dimensions, range);
 }
示例#20
0
        public SceneControl(ScreenComponent manager, string style = "") :
            base(manager, style)
        {
            Mask      = (int)Math.Pow(2, VIEWRANGE) - 1;
            Span      = (int)Math.Pow(2, VIEWRANGE);
            SpanOver2 = Span >> 1;

            player   = manager.Player;
            camera   = manager.Camera;
            assets   = manager.Game.Assets;
            entities = manager.Game.Entity;
            Manager  = manager;

            simpleShader = manager.Game.Content.Load <Effect>("simple");
            sunTexture   = assets.LoadTexture(typeof(ScreenComponent), "sun");

            //List<Bitmap> bitmaps = new List<Bitmap>();
            var definitions  = Manager.Game.DefinitionManager.GetBlockDefinitions();
            int textureCount = 0;

            foreach (var definition in definitions)
            {
                textureCount += definition.Textures.Length;
            }
            int bitmapSize = 128;

            blockTextures = new Texture2DArray(manager.GraphicsDevice, 1, bitmapSize, bitmapSize, textureCount);
            int layer = 0;

            foreach (var definition in definitions)
            {
                foreach (var bitmap in definition.Textures)
                {
                    System.Drawing.Bitmap texture = manager.Game.Assets.LoadBitmap(definition.GetType(), bitmap);

                    var   scaled     = texture;//new Bitmap(bitmap, new System.Drawing.Size(bitmapSize, bitmapSize));
                    int[] data       = new int[scaled.Width * scaled.Height];
                    var   bitmapData = scaled.LockBits(new System.Drawing.Rectangle(0, 0, scaled.Width, scaled.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, data, 0, data.Length);
                    blockTextures.SetData(data, layer);
                    scaled.UnlockBits(bitmapData);
                    layer++;
                }
            }

            planet = Manager.Game.ResourceManager.GetPlanet(player.Position.Position.Planet);

            // TODO: evtl. Cache-Size (Dimensions) VIEWRANGE + 1

            int range = ((int)Math.Pow(2, VIEWRANGE) - 2) / 2;

            localChunkCache = new LocalChunkCache(planet.GlobalChunkCache, VIEWRANGE, range);

            chunkRenderer = new ChunkRenderer[
                (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE),
                planet.Size.Z];
            orderedChunkRenderer = new List <ChunkRenderer>(
                (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE) * planet.Size.Z);

            for (int i = 0; i < chunkRenderer.GetLength(0); i++)
            {
                for (int j = 0; j < chunkRenderer.GetLength(1); j++)
                {
                    ChunkRenderer renderer = new ChunkRenderer(this, Manager.Game.DefinitionManager, simpleShader, manager.GraphicsDevice, camera.Projection, blockTextures);
                    chunkRenderer[i, j] = renderer;
                    orderedChunkRenderer.Add(renderer);
                }
            }

            backgroundThread = new Thread(BackgroundLoop)
            {
                Priority     = ThreadPriority.Lowest,
                IsBackground = true
            };
            backgroundThread.Start();

            backgroundThread2 = new Thread(ForceUpdateBackgroundLoop)
            {
                Priority     = ThreadPriority.Lowest,
                IsBackground = true
            };
            backgroundThread2.Start();

            var additional = Environment.ProcessorCount / 3;

            additional                     = additional == 0 ? 1 : additional;
            _fillIncrement                 = additional + 1;
            additionalFillResetEvents      = new AutoResetEvent[additional];
            _additionalRegenerationThreads = new Thread[additional];
            for (int i = 0; i < additional; i++)
            {
                var t = new Thread(AdditionalFillerBackgroundLoop)
                {
                    Priority     = ThreadPriority.Lowest,
                    IsBackground = true
                };
                var are = new AutoResetEvent(false);
                t.Start(new object[] { are, i });
                additionalFillResetEvents[i]      = are;
                _additionalRegenerationThreads[i] = t;
            }



            var selectionVertices = new[]
            {
                new VertexPositionColor(new Vector3(-0.001f, +1.001f, +1.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, +1.001f, +1.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(-0.001f, -0.001f, +1.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, -0.001f, +1.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(-0.001f, +1.001f, -0.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, +1.001f, -0.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(-0.001f, -0.001f, -0.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, -0.001f, -0.001f), Color.Black * 0.5f),
            };

            var billboardVertices = new[]
            {
                new VertexPositionTexture(new Vector3(-0.5f, 0.5f, 0), new Vector2(0, 0)),
                new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)),
                new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)),
                new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)),
                new VertexPositionTexture(new Vector3(0.5f, -0.5f, 0), new Vector2(1, 1)),
                new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)),
            };

            var selectionIndices = new short[]
            {
                0, 1, 0, 2, 1, 3, 2, 3,
                4, 5, 4, 6, 5, 7, 6, 7,
                0, 4, 1, 5, 2, 6, 3, 7
            };

            selectionLines = new VertexBuffer(manager.GraphicsDevice, VertexPositionColor.VertexDeclaration, selectionVertices.Length);
            selectionLines.SetData(selectionVertices);

            selectionIndexBuffer = new IndexBuffer(manager.GraphicsDevice, DrawElementsType.UnsignedShort, selectionIndices.Length);
            selectionIndexBuffer.SetData(selectionIndices);

            billboardVertexbuffer = new VertexBuffer(manager.GraphicsDevice, VertexPositionTexture.VertexDeclaration, billboardVertices.Length);
            billboardVertexbuffer.SetData(billboardVertices);


            sunEffect = new BasicEffect(manager.GraphicsDevice)
            {
                TextureEnabled = true
            };

            selectionEffect = new BasicEffect(manager.GraphicsDevice)
            {
                VertexColorEnabled = true
            };

            MiniMapTexture          = new RenderTarget2D(manager.GraphicsDevice, 128, 128, PixelInternalFormat.Rgb8); // , false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents);
            miniMapProjectionMatrix = Matrix.CreateOrthographic(128, 128, 1, 10000);
        }
示例#21
0
        public SceneControl(ScreenComponent manager, string style = "") :
            base(manager, style)
        {
            player = manager.Player;
            camera = manager.Camera;

            Manager = manager;

            simpleShader = manager.Game.Content.Load <Effect>("simple");
            sunTexture   = manager.Game.Content.LoadTexture2DFromFile("./Assets/OctoAwesome.Client/sun.png", manager.GraphicsDevice);

            List <Bitmap> bitmaps     = new List <Bitmap>();
            var           definitions = DefinitionManager.Instance.GetBlockDefinitions();

            foreach (var definition in definitions)
            {
                bitmaps.AddRange(definition.Textures);
            }

            int    size   = (int)Math.Ceiling(Math.Sqrt(bitmaps.Count));
            Bitmap blocks = new Bitmap(size * TEXTURESIZE, size * TEXTURESIZE);

            using (Graphics g = Graphics.FromImage(blocks))
            {
                int counter = 0;
                foreach (var bitmap in bitmaps)
                {
                    int x = counter % size;
                    int y = (int)(counter / size);
                    g.DrawImage(bitmap, new System.Drawing.Rectangle(TEXTURESIZE * x, TEXTURESIZE * y, TEXTURESIZE, TEXTURESIZE));
                    counter++;
                }
            }

            using (MemoryStream stream = new MemoryStream())
            {
                blocks.Save(stream, ImageFormat.Png);
                stream.Seek(0, SeekOrigin.Begin);
                blockTextures = Texture2D.FromStream(manager.GraphicsDevice, stream);
            }

            planet = ResourceManager.Instance.GetPlanet(0);

            // TODO: evtl. Cache-Size (Dimensions) VIEWRANGE + 1

            int range = ((int)Math.Pow(2, VIEWRANGE) - 2) / 2;

            localChunkCache = new LocalChunkCache(ResourceManager.Instance.GlobalChunkCache, VIEWRANGE, range);

            chunkRenderer = new ChunkRenderer[
                (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE),
                planet.Size.Z];
            orderedChunkRenderer = new List <ChunkRenderer>(
                (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE) * planet.Size.Z);

            for (int i = 0; i < chunkRenderer.GetLength(0); i++)
            {
                for (int j = 0; j < chunkRenderer.GetLength(1); j++)
                {
                    ChunkRenderer renderer = new ChunkRenderer(simpleShader, manager.GraphicsDevice, camera.Projection, blockTextures);
                    chunkRenderer[i, j] = renderer;
                    orderedChunkRenderer.Add(renderer);
                }
            }

            backgroundThread              = new Thread(BackgroundLoop);
            backgroundThread.Priority     = ThreadPriority.Lowest;
            backgroundThread.IsBackground = true;
            backgroundThread.Start();

            selectionLines = new[]
            {
                new VertexPositionColor(new Vector3(-0.001f, +1.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, +1.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(-0.001f, -0.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, -0.001f, +1.001f), Microsoft.Xna.Framework.Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(-0.001f, +1.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, +1.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(-0.001f, -0.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, -0.001f, -0.001f), Microsoft.Xna.Framework.Color.Black * 0.5f),
            };

            billboardVertices = new[]
            {
                new VertexPositionTexture(new Vector3(-0.5f, 0.5f, 0), new Vector2(0, 0)),
                new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)),
                new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)),
                new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)),
                new VertexPositionTexture(new Vector3(0.5f, -0.5f, 0), new Vector2(1, 1)),
                new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)),
            };

            selectionIndeces = new short[]
            {
                0, 1, 0, 2, 1, 3, 2, 3,
                4, 5, 4, 6, 5, 7, 6, 7,
                0, 4, 1, 5, 2, 6, 3, 7
            };

            sunEffect = new BasicEffect(manager.GraphicsDevice);
            sunEffect.TextureEnabled = true;

            selectionEffect = new BasicEffect(manager.GraphicsDevice);
            selectionEffect.VertexColorEnabled = true;

            MiniMapTexture          = new RenderTarget2D(manager.GraphicsDevice, 128, 128, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8); // , false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents);
            miniMapProjectionMatrix = Matrix.CreateOrthographic(128, 128, 1, 10000);
        }
示例#22
0
 /// <summary>
 /// Gibt an, ob die Westseite (Positiv X) undurchsichtig ist, also Blöcke dahinter nicht gesehen werden können
 /// </summary>
 /// <param name="manager">[Bitte ergänzen]</param>
 /// <param name="x">X-Anteil der Koordinate des Blocks</param>
 /// <param name="y">Y-Anteil der Koordinate des Blocks</param>
 /// <param name="z">Z-Anteil der Koordinate des Blocks</param>
 /// <returns>True, wenn die Wand undurchsichtig ist</returns>
 public virtual bool IsWestSolidWall(ILocalChunkCache manager, int x, int y, int z)
 {
     return true;
 }
示例#23
0
 /// <summary>
 /// Rotation der Textur in 90° Schritten für die Unterseite (Negativ Z) des Blocks
 /// </summary>
 /// <param name="manager">[Bitte ergänzen]</param>
 /// <param name="x">X-Anteil der Koordinate des Blocks</param>
 /// <param name="y">Y-Anteil der Koordinate des Blocks</param>
 /// <param name="z">Z-Anteil der Koordinate des Blocks</param>
 /// <returns>Rotation der Textur in 90° Schritten</returns>
 public virtual int GetBottomTextureRotation(ILocalChunkCache manager, int x, int y, int z)
 {
     return 0;
 }
示例#24
0
        public override int GetTextureIndex(Wall wall, ILocalChunkCache manager,
                                            int x, int y, int z)
        {
            OrientationFlags orientation = (OrientationFlags)manager.GetBlockMeta(x, y, z);

            switch (wall)
            {
            case Wall.Top:
            {
                ushort topblock = manager.GetBlock(x, y, z + 1);

                switch (orientation)
                {
                case OrientationFlags.SideWest:
                case OrientationFlags.SideEast:
                case OrientationFlags.SideSouth:
                case OrientationFlags.SideNorth:
                    return(1);

                case OrientationFlags.SideBottom:
                case OrientationFlags.SideTop:
                default:
                    if (topblock != 0)
                    {
                        return(0);
                    }
                    else
                    {
                        return(2);
                    }
                }
            }

            case Wall.Bottom:
            {
                ushort topblock = manager.GetBlock(x, y, z + 1);

                switch (orientation)
                {
                case OrientationFlags.SideWest:
                case OrientationFlags.SideEast:
                case OrientationFlags.SideSouth:
                case OrientationFlags.SideNorth:
                    return(1);

                case OrientationFlags.SideBottom:
                case OrientationFlags.SideTop:
                default:
                    if (topblock != 0)
                    {
                        return(0);
                    }
                    else
                    {
                        return(2);
                    }
                }
            }

            case Wall.Front:
            {
                ushort topblock = manager.GetBlock(x, y, z + 1);

                switch (orientation)
                {
                case OrientationFlags.SideSouth:
                case OrientationFlags.SideNorth:
                    if (topblock != 0)
                    {
                        return(0);
                    }
                    else
                    {
                        return(2);
                    }

                case OrientationFlags.SideWest:
                case OrientationFlags.SideEast:
                case OrientationFlags.SideBottom:
                case OrientationFlags.SideTop:
                default:
                    return(1);
                }
            }

            case Wall.Back:
            {
                ushort topblock = manager.GetBlock(x, y, z + 1);

                switch (orientation)
                {
                case OrientationFlags.SideSouth:
                case OrientationFlags.SideNorth:
                    if (topblock != 0)
                    {
                        return(0);
                    }
                    else
                    {
                        return(2);
                    }

                case OrientationFlags.SideWest:
                case OrientationFlags.SideEast:
                case OrientationFlags.SideBottom:
                case OrientationFlags.SideTop:
                default:
                    return(1);
                }
            }

            case Wall.Left:
            {
                ushort topblock = manager.GetBlock(x, y, z + 1);

                switch (orientation)
                {
                case OrientationFlags.SideWest:
                case OrientationFlags.SideEast:
                    if (topblock != 0)
                    {
                        return(0);
                    }
                    else
                    {
                        return(2);
                    }

                case OrientationFlags.SideSouth:
                case OrientationFlags.SideNorth:
                case OrientationFlags.SideBottom:
                case OrientationFlags.SideTop:
                default:
                    return(1);
                }
            }

            case Wall.Right:
            {
                ushort topblock = manager.GetBlock(x, y, z + 1);

                switch (orientation)
                {
                case OrientationFlags.SideWest:
                case OrientationFlags.SideEast:
                    if (topblock != 0)
                    {
                        return(0);
                    }
                    else
                    {
                        return(2);
                    }

                case OrientationFlags.SideSouth:
                case OrientationFlags.SideNorth:
                case OrientationFlags.SideBottom:
                case OrientationFlags.SideTop:
                default:
                    return(1);
                }
            }
            }

            // Should never happen
            // Assert here
            return(-1);
        }
示例#25
0
 /// <summary>
 /// Texturindex für das Array <see cref="Textures"/> für die Unterseite (Negativ Z) des Blocks
 /// </summary>
 /// <param name="manager">[Bitte ergänzen]</param>
 /// <param name="x">X-Anteil der Koordinate des Blocks</param>
 /// <param name="y">Y-Anteil der Koordinate des Blocks</param>
 /// <param name="z">Z-Anteil der Koordinate des Blocks</param>
 /// <returns>Index für das Array <see cref="Textures"/></returns>
 public virtual int GetBottomTextureIndex(ILocalChunkCache manager, int x, int y, int z)
 {
     return(0);
 }
示例#26
0
 /// <summary>
 /// Liefert die Physikalischen Paramerter, wie härte, dichte und bruchzähigkeit
 /// </summary>
 /// <param name="manager"></param>
 /// <param name="x">X-Anteil der Koordinate des Blocks</param>
 /// <param name="y">Y-Anteil der Koordinate des Blocks</param>
 /// <param name="z">Z-Anteil der Koordinate des Blocks</param>
 /// <returns>Die physikalischen Parameter</returns>
 public abstract PhysicalProperties GetProperties(ILocalChunkCache manager, int x, int y, int z);
示例#27
0
 public virtual int GetTextureRotation(Wall wall, ILocalChunkCache manager, int x, int y, int z) => 0;
示例#28
0
 /// <summary>
 /// Rotation der Textur in 90° Schritten für die Südseite (Negativ Y) des Blocks
 /// </summary>
 /// <param name="manager">[Bitte ergänzen]</param>
 /// <param name="x">X-Anteil der Koordinate des Blocks</param>
 /// <param name="y">Y-Anteil der Koordinate des Blocks</param>
 /// <param name="z">Z-Anteil der Koordinate des Blocks</param>
 /// <returns>Rotation der Textur in 90° Schritten</returns>
 public virtual int GetSouthTextureRotation(ILocalChunkCache manager, int x, int y, int z)
 {
     return(0);
 }
示例#29
0
 public override int GetBottomTextureIndex(ILocalChunkCache manager, int x, int y, int z)
 {
     return 1;
 }
示例#30
0
        public SceneControl(ScreenComponent manager, string style = "")
            : base(manager, style)
        {
            player = manager.Player;
            camera = manager.Camera;
            assets = manager.Game.Assets;

            Manager = manager;

            simpleShader = manager.Game.Content.Load<Effect>("simple");
            sunTexture = assets.LoadTexture(typeof(ScreenComponent), "sun");

            //List<Bitmap> bitmaps = new List<Bitmap>();
            var definitions = DefinitionManager.Instance.GetBlockDefinitions();
            int textureCount = 0;
            foreach (var definition in definitions)
            {
                textureCount += definition.Textures.Length;
            }
            int bitmapSize = 128;
            blockTextures = new Texture2DArray(manager.GraphicsDevice, 1, bitmapSize, bitmapSize, textureCount);
            int layer = 0;
            foreach (var definition in definitions)
            {
                foreach (var bitmap in definition.Textures)
                {
                    System.Drawing.Bitmap texture = manager.Game.Assets.LoadBitmap(definition.GetType(), bitmap);

                    var scaled = texture;//new Bitmap(bitmap, new System.Drawing.Size(bitmapSize, bitmapSize));
                    int[] data = new int[scaled.Width * scaled.Height];
                    var bitmapData = scaled.LockBits(new System.Drawing.Rectangle(0, 0, scaled.Width, scaled.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, data, 0, data.Length);
                    blockTextures.SetData(data, layer);
                    scaled.UnlockBits(bitmapData);
                    layer++;
                }
            }

            /*int size = (int)Math.Ceiling(Math.Sqrt(bitmaps.Count));
            Bitmap blocks = new Bitmap(size * TEXTURESIZE, size * TEXTURESIZE);
            using (Graphics g = Graphics.FromImage(blocks))
            {
                int counter = 0;
                foreach (var bitmap in bitmaps)
                {
                    int x = counter % size;
                    int y = (int)(counter / size);
                    g.DrawImage(bitmap, new System.Drawing.Rectangle(TEXTURESIZE * x, TEXTURESIZE * y, TEXTURESIZE, TEXTURESIZE));
                    counter++;
                }
            }

            using (MemoryStream stream = new MemoryStream())
            {
                blocks.Save(stream, ImageFormat.Png);
                stream.Seek(0, SeekOrigin.Begin);
                blockTextures = Texture2D.FromStream(manager.GraphicsDevice, stream);
            }*/

            planet = ResourceManager.Instance.GetPlanet(0);

            // TODO: evtl. Cache-Size (Dimensions) VIEWRANGE + 1

            int range = ((int)Math.Pow(2, VIEWRANGE) - 2) / 2;
            localChunkCache = new LocalChunkCache(ResourceManager.Instance.GlobalChunkCache, VIEWRANGE, range);

            chunkRenderer = new ChunkRenderer[
                (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE),
                planet.Size.Z];
            orderedChunkRenderer = new List<ChunkRenderer>(
                (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE) * planet.Size.Z);

            for (int i = 0; i < chunkRenderer.GetLength(0); i++)
            {
                for (int j = 0; j < chunkRenderer.GetLength(1); j++)
                {
                    ChunkRenderer renderer = new ChunkRenderer(simpleShader, manager.GraphicsDevice, camera.Projection, blockTextures);
                    chunkRenderer[i, j] = renderer;
                    orderedChunkRenderer.Add(renderer);
                }
            }

            backgroundThread = new Thread(BackgroundLoop);
            backgroundThread.Priority = ThreadPriority.Lowest;
            backgroundThread.IsBackground = true;
            backgroundThread.Start();

            var selectionVertices = new[]
            {
                new VertexPositionColor(new Vector3(-0.001f, +1.001f, +1.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, +1.001f, +1.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(-0.001f, -0.001f, +1.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, -0.001f, +1.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(-0.001f, +1.001f, -0.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, +1.001f, -0.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(-0.001f, -0.001f, -0.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, -0.001f, -0.001f), Color.Black * 0.5f),
            };

            var billboardVertices = new[]
            {
                new VertexPositionTexture(new Vector3(-0.5f, 0.5f, 0), new Vector2(0, 0)),
                new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)),
                new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)),
                new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)),
                new VertexPositionTexture(new Vector3(0.5f, -0.5f, 0), new Vector2(1, 1)),
                new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)),
            };

            var selectionIndices = new short[]
            {
                0, 1, 0, 2, 1, 3, 2, 3,
                4, 5, 4, 6, 5, 7, 6, 7,
                0, 4, 1, 5, 2, 6, 3, 7
            };

            selectionLines = new VertexBuffer(manager.GraphicsDevice, VertexPositionColor.VertexDeclaration, selectionVertices.Length);
            selectionLines.SetData(selectionVertices);

            selectionIndexBuffer = new IndexBuffer(manager.GraphicsDevice, DrawElementsType.UnsignedShort, selectionIndices.Length);
            selectionIndexBuffer.SetData(selectionIndices);

            billboardVertexbuffer = new VertexBuffer(manager.GraphicsDevice, VertexPositionTexture.VertexDeclaration, billboardVertices.Length);
            billboardVertexbuffer.SetData(billboardVertices);

            sunEffect = new BasicEffect(manager.GraphicsDevice);
            sunEffect.TextureEnabled = true;

            selectionEffect = new BasicEffect(manager.GraphicsDevice);
            selectionEffect.VertexColorEnabled = true;

            MiniMapTexture = new RenderTarget2D(manager.GraphicsDevice, 128, 128, PixelInternalFormat.Rgb8); // , false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents);
            miniMapProjectionMatrix = Matrix.CreateOrthographic(128, 128, 1, 10000);
        }
示例#31
0
 public override int GetWestTextureIndex(ILocalChunkCache manager, int x, int y, int z)
 {
     return 2;
 }
示例#32
0
 public override int GetBottomTextureIndex(ILocalChunkCache manager, int x, int y, int z)
 {
     return(1);
 }
示例#33
0
 /// <summary>
 /// Liefert die Kollisionsbox für den Block. Da ein Array zurück gegeben wird, lässt sich die
 /// </summary>
 /// <param name="manager">[Bitte ergänzen]</param>
 /// <param name="x">X-Anteil der Koordinate des Blocks</param>
 /// <param name="y">Y-Anteil der Koordinate des Blocks</param>
 /// <param name="z">Z-Anteil der Koordinate des Blocks</param>
 /// <returns>Ein Array von Kollisionsboxen</returns>
 public virtual BoundingBox[] GetCollisionBoxes(ILocalChunkCache manager, int x, int y, int z)
 => new[] { new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)) };
 public override bool IsWestSolidWall(ILocalChunkCache manager, int x, int y, int z)
 {
     return false;
 }
示例#35
0
        /// <summary>
        /// Berechnet die Geschwindigkeit einer <see cref="Entity"/> nach der Kollision mit der Welt. (Original Lassi)
        /// </summary>
        /// <param name="gameTime">Simulation time</param>
        /// <param name="position">Position der <see cref="Entity"/></param>
        /// <param name="cache"><see cref="ILocalChunkCache"/> as workspace</param>
        /// <param name="radius">Radius der <see cref="Entity"/></param>
        /// <param name="height">Höhe der <see cref="Entity"/></param>
        /// <param name="deltaPosition">Positionsänderung zwischen zwei Simulationsdurchläufen</param>
        /// <param name="velocity">Berechnete Geschwindigkeit</param>
        /// <exception cref="ArgumentNullException">Cache</exception>
        /// <returns>Geschwindigkeit der <see cref="Entity"/> nach der Killisionsprüfung</returns>
        public Vector3 WorldCollision(GameTime gameTime, Coordinate position, ILocalChunkCache cache, float radius, float height,
                                      Vector3 deltaPosition, Vector3 velocity)
        {
            if (cache == null)
            {
                throw new ArgumentNullException(nameof(cache));
            }

            Vector3 move = deltaPosition;

            //Blocks finden die eine Kollision verursachen könnten
            int minx = (int)Math.Floor(Math.Min(
                                           position.BlockPosition.X - radius,
                                           position.BlockPosition.X - radius + deltaPosition.X));
            int maxx = (int)Math.Ceiling(Math.Max(
                                             position.BlockPosition.X + radius,
                                             position.BlockPosition.X + radius + deltaPosition.X));
            int miny = (int)Math.Floor(Math.Min(
                                           position.BlockPosition.Y - radius,
                                           position.BlockPosition.Y - radius + deltaPosition.Y));
            int maxy = (int)Math.Ceiling(Math.Max(
                                             position.BlockPosition.Y + radius,
                                             position.BlockPosition.Y + radius + deltaPosition.Y));
            int minz = (int)Math.Floor(Math.Min(
                                           position.BlockPosition.Z,
                                           position.BlockPosition.Z + deltaPosition.Z));
            int maxz = (int)Math.Ceiling(Math.Max(
                                             position.BlockPosition.Z + height,
                                             position.BlockPosition.Z + height + deltaPosition.Z));

            //Beteiligte Flächen des Spielers
            var playerplanes = CollisionPlane.GetEntityCollisionPlanes(radius, height, velocity, position);

            for (int z = minz; z <= maxz; z++)
            {
                for (int y = miny; y <= maxy; y++)
                {
                    for (int x = minx; x <= maxx; x++)
                    {
                        move = velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;

                        Index3 pos      = new Index3(x, y, z);
                        Index3 blockPos = pos + position.GlobalBlockIndex;
                        ushort block    = cache.GetBlock(blockPos);

                        if (block == 0)
                        {
                            continue;
                        }

                        var blockplanes = CollisionPlane.GetBlockCollisionPlanes(pos, velocity);

                        foreach (var playerPlane in playerplanes)
                        {
                            foreach (var blockPlane in blockplanes)
                            {
                                if (!CollisionPlane.Intersect(blockPlane, playerPlane))
                                {
                                    continue;
                                }

                                var distance = CollisionPlane.GetDistance(blockPlane, playerPlane);
                                if (!CollisionPlane.CheckDistance(distance, move))
                                {
                                    continue;
                                }

                                var subvelocity = (distance / (float)gameTime.ElapsedGameTime.TotalSeconds);
                                var diff        = velocity - subvelocity;

                                float vx;
                                float vy;
                                float vz;

                                if (blockPlane.normal.X != 0 && (velocity.X > 0 && diff.X >= 0 && subvelocity.X >= 0 ||
                                                                 velocity.X < 0 && diff.X <= 0 && subvelocity.X <= 0))
                                {
                                    vx = subvelocity.X;
                                }
                                else
                                {
                                    vx = velocity.X;
                                }

                                if (blockPlane.normal.Y != 0 && (velocity.Y > 0 && diff.Y >= 0 && subvelocity.Y >= 0 ||
                                                                 velocity.Y < 0 && diff.Y <= 0 && subvelocity.Y <= 0))
                                {
                                    vy = subvelocity.Y;
                                }
                                else
                                {
                                    vy = velocity.Y;
                                }

                                if (blockPlane.normal.Z != 0 && (velocity.Z > 0 && diff.Z >= 0 && subvelocity.Z >= 0 ||
                                                                 velocity.Z < 0 && diff.Z <= 0 && subvelocity.Z <= 0))
                                {
                                    vz = subvelocity.Z;
                                }
                                else
                                {
                                    vz = velocity.Z;
                                }

                                velocity = new Vector3(vx, vy, vz);
                                if (vx == 0 && vy == 0 && vz == 0)
                                {
                                    return(velocity);
                                }
                            }
                        }
                    }
                }
            }
            return(velocity);
        }
示例#36
0
        public SceneControl(ScreenComponent manager, string style = "") :
            base(manager, style)
        {
            player = manager.Player;
            camera = manager.Camera;
            assets = manager.Game.Assets;

            Manager = manager;

            simpleShader = manager.Game.Content.Load <Effect>("simple");
            sunTexture   = assets.LoadTexture(typeof(ScreenComponent), "sun");

            //List<Bitmap> bitmaps = new List<Bitmap>();
            var definitions  = DefinitionManager.Instance.GetBlockDefinitions();
            int textureCount = 0;

            foreach (var definition in definitions)
            {
                textureCount += definition.Textures.Length;
            }
            int bitmapSize = 128;

            blockTextures = new Texture2DArray(manager.GraphicsDevice, 1, bitmapSize, bitmapSize, textureCount);
            int layer = 0;

            foreach (var definition in definitions)
            {
                foreach (var bitmap in definition.Textures)
                {
                    System.Drawing.Bitmap texture = manager.Game.Assets.LoadBitmap(definition.GetType(), bitmap);

                    var   scaled     = texture;//new Bitmap(bitmap, new System.Drawing.Size(bitmapSize, bitmapSize));
                    int[] data       = new int[scaled.Width * scaled.Height];
                    var   bitmapData = scaled.LockBits(new System.Drawing.Rectangle(0, 0, scaled.Width, scaled.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, data, 0, data.Length);
                    blockTextures.SetData(data, layer);
                    scaled.UnlockBits(bitmapData);
                    layer++;
                }
            }

            /*int size = (int)Math.Ceiling(Math.Sqrt(bitmaps.Count));
             * Bitmap blocks = new Bitmap(size * TEXTURESIZE, size * TEXTURESIZE);
             * using (Graphics g = Graphics.FromImage(blocks))
             * {
             *  int counter = 0;
             *  foreach (var bitmap in bitmaps)
             *  {
             *      int x = counter % size;
             *      int y = (int)(counter / size);
             *      g.DrawImage(bitmap, new System.Drawing.Rectangle(TEXTURESIZE * x, TEXTURESIZE * y, TEXTURESIZE, TEXTURESIZE));
             *      counter++;
             *  }
             * }
             *
             * using (MemoryStream stream = new MemoryStream())
             * {
             *  blocks.Save(stream, ImageFormat.Png);
             *  stream.Seek(0, SeekOrigin.Begin);
             *  blockTextures = Texture2D.FromStream(manager.GraphicsDevice, stream);
             * }*/

            planet = ResourceManager.Instance.GetPlanet(0);

            // TODO: evtl. Cache-Size (Dimensions) VIEWRANGE + 1

            int range = ((int)Math.Pow(2, VIEWRANGE) - 2) / 2;

            localChunkCache = new LocalChunkCache(ResourceManager.Instance.GlobalChunkCache, VIEWRANGE, range);

            chunkRenderer = new ChunkRenderer[
                (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE),
                planet.Size.Z];
            orderedChunkRenderer = new List <ChunkRenderer>(
                (int)Math.Pow(2, VIEWRANGE) * (int)Math.Pow(2, VIEWRANGE) * planet.Size.Z);

            for (int i = 0; i < chunkRenderer.GetLength(0); i++)
            {
                for (int j = 0; j < chunkRenderer.GetLength(1); j++)
                {
                    ChunkRenderer renderer = new ChunkRenderer(simpleShader, manager.GraphicsDevice, camera.Projection, blockTextures);
                    chunkRenderer[i, j] = renderer;
                    orderedChunkRenderer.Add(renderer);
                }
            }

            backgroundThread              = new Thread(BackgroundLoop);
            backgroundThread.Priority     = ThreadPriority.Lowest;
            backgroundThread.IsBackground = true;
            backgroundThread.Start();

            var selectionVertices = new[]
            {
                new VertexPositionColor(new Vector3(-0.001f, +1.001f, +1.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, +1.001f, +1.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(-0.001f, -0.001f, +1.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, -0.001f, +1.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(-0.001f, +1.001f, -0.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, +1.001f, -0.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(-0.001f, -0.001f, -0.001f), Color.Black * 0.5f),
                new VertexPositionColor(new Vector3(+1.001f, -0.001f, -0.001f), Color.Black * 0.5f),
            };

            var billboardVertices = new[]
            {
                new VertexPositionTexture(new Vector3(-0.5f, 0.5f, 0), new Vector2(0, 0)),
                new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)),
                new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)),
                new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 0)),
                new VertexPositionTexture(new Vector3(0.5f, -0.5f, 0), new Vector2(1, 1)),
                new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 1)),
            };

            var selectionIndices = new short[]
            {
                0, 1, 0, 2, 1, 3, 2, 3,
                4, 5, 4, 6, 5, 7, 6, 7,
                0, 4, 1, 5, 2, 6, 3, 7
            };

            selectionLines = new VertexBuffer(manager.GraphicsDevice, VertexPositionColor.VertexDeclaration, selectionVertices.Length);
            selectionLines.SetData(selectionVertices);

            selectionIndexBuffer = new IndexBuffer(manager.GraphicsDevice, DrawElementsType.UnsignedShort, selectionIndices.Length);
            selectionIndexBuffer.SetData(selectionIndices);

            billboardVertexbuffer = new VertexBuffer(manager.GraphicsDevice, VertexPositionTexture.VertexDeclaration, billboardVertices.Length);
            billboardVertexbuffer.SetData(billboardVertices);


            sunEffect = new BasicEffect(manager.GraphicsDevice);
            sunEffect.TextureEnabled = true;

            selectionEffect = new BasicEffect(manager.GraphicsDevice);
            selectionEffect.VertexColorEnabled = true;

            MiniMapTexture          = new RenderTarget2D(manager.GraphicsDevice, 128, 128, PixelInternalFormat.Rgb8); // , false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents);
            miniMapProjectionMatrix = Matrix.CreateOrthographic(128, 128, 1, 10000);
        }