Ejemplo n.º 1
0
        public ChunkModule(TrueCraftGame game)
        {
            Game = game;

            ChunkRenderer = new ChunkRenderer(Game.Client.World, Game, Game.BlockRepository);
            Game.Client.ChunkLoaded += (sender, e) => ChunkRenderer.Enqueue(e.Chunk);
            Game.Client.ChunkUnloaded += (sender, e) => UnloadChunk(e.Chunk);
            Game.Client.ChunkModified += (sender, e) => ChunkRenderer.Enqueue(e.Chunk, true);
            ChunkRenderer.MeshCompleted += MeshCompleted;
            ChunkRenderer.Start();

            OpaqueEffect = new BasicEffect(Game.GraphicsDevice);
            OpaqueEffect.TextureEnabled = true;
            OpaqueEffect.Texture = Game.TextureMapper.GetTexture("terrain.png");
            OpaqueEffect.FogEnabled = true;
            OpaqueEffect.FogStart = 512f;
            OpaqueEffect.FogEnd = 1000f;
            OpaqueEffect.FogColor = Color.CornflowerBlue.ToVector3();
            OpaqueEffect.VertexColorEnabled = true;

            TransparentEffect = new AlphaTestEffect(Game.GraphicsDevice);
            TransparentEffect.AlphaFunction = CompareFunction.Greater;
            TransparentEffect.ReferenceAlpha = 127;
            TransparentEffect.Texture = Game.TextureMapper.GetTexture("terrain.png");
            TransparentEffect.VertexColorEnabled = true;

            ChunkMeshes = new List<ChunkMesh>();
            IncomingChunks = new ConcurrentBag<Mesh>();
            ActiveMeshes = new HashSet<Coordinates2D>();
        }
Ejemplo n.º 2
0
        public ChunkModule(TrueCraftGame game)
        {
            Game = game;

            ChunkRenderer                = new ChunkRenderer(Game.Client.World, Game, Game.BlockRepository);
            Game.Client.ChunkLoaded     += (sender, e) => ChunkRenderer.Enqueue(e.Chunk);
            Game.Client.ChunkUnloaded   += (sender, e) => UnloadChunk(e.Chunk);
            Game.Client.ChunkModified   += (sender, e) => ChunkRenderer.Enqueue(e.Chunk, true);
            ChunkRenderer.MeshCompleted += MeshCompleted;
            ChunkRenderer.Start();

            OpaqueEffect = new BasicEffect(Game.GraphicsDevice);
            OpaqueEffect.TextureEnabled     = true;
            OpaqueEffect.Texture            = Game.TextureMapper.GetTexture("terrain.png");
            OpaqueEffect.FogEnabled         = true;
            OpaqueEffect.FogStart           = 512f;
            OpaqueEffect.FogEnd             = 1000f;
            OpaqueEffect.FogColor           = Color.CornflowerBlue.ToVector3();
            OpaqueEffect.VertexColorEnabled = true;

            TransparentEffect = new AlphaTestEffect(Game.GraphicsDevice);
            TransparentEffect.AlphaFunction      = CompareFunction.Greater;
            TransparentEffect.ReferenceAlpha     = 127;
            TransparentEffect.Texture            = Game.TextureMapper.GetTexture("terrain.png");
            TransparentEffect.VertexColorEnabled = true;

            ChunkMeshes    = new List <ChunkMesh>();
            IncomingChunks = new ConcurrentBag <Mesh>();
            ActiveMeshes   = new HashSet <Coordinates2D>();
        }
Ejemplo n.º 3
0
 private void Game_Client_ChunkLoaded(object sender, ChunkEventArgs e)
 {
     ChunkRenderer.Enqueue(e.Chunk);
     for (int i = 0; i < AdjacentCoordinates.Length; i++)
     {
         ReadOnlyChunk adjacent = Game.Client.World.GetChunk(
             AdjacentCoordinates[i] + e.Chunk.Coordinates);
         if (adjacent != null)
         {
             ChunkRenderer.Enqueue(adjacent);
         }
     }
 }
Ejemplo n.º 4
0
        protected override void Initialize()
        {
            Interfaces  = new List <IGameInterface>();
            SpriteBatch = new SpriteBatch(GraphicsDevice);
            base.Initialize(); // (calls LoadContent)
            ChunkConverter      = new ChunkRenderer(this, Client.World.World.BlockRepository);
            Client.ChunkLoaded += (sender, e) => ChunkConverter.Enqueue(e.Chunk);
            //Client.ChunkModified += (sender, e) => ChunkConverter.Enqueue(e.Chunk, true);
            ChunkConverter.MeshCompleted += ChunkConverter_MeshGenerated;
            ChunkConverter.Start();
            Client.PropertyChanged += HandleClientPropertyChanged;
            Client.Connect(EndPoint);
            var centerX = GraphicsDevice.Viewport.Width / 2;
            var centerY = GraphicsDevice.Viewport.Height / 2;

            Mouse.SetPosition(centerX, centerY);
            Camera = new Camera(GraphicsDevice.Viewport.AspectRatio, 70.0f, 0.25f, 1000.0f);
            UpdateCamera();
            Window.ClientSizeChanged  += (sender, e) => CreateRenderTarget();
            MouseComponent.Move       += OnMouseComponentMove;
            KeyboardComponent.KeyDown += OnKeyboardKeyDown;
            KeyboardComponent.KeyUp   += OnKeyboardKeyUp;
            CreateRenderTarget();
        }
Ejemplo n.º 5
0
 protected override void Initialize()
 {
     Interfaces = new List<IGameInterface>();
     SpriteBatch = new SpriteBatch(GraphicsDevice);
     base.Initialize(); // (calls LoadContent)
     ChunkConverter = new ChunkRenderer(this, Client.World.World.BlockRepository);
     Client.ChunkLoaded += (sender, e) => ChunkConverter.Enqueue(e.Chunk);
     //Client.ChunkModified += (sender, e) => ChunkConverter.Enqueue(e.Chunk, true);
     ChunkConverter.MeshCompleted += ChunkConverter_MeshGenerated;
     ChunkConverter.Start();
     Client.PropertyChanged += HandleClientPropertyChanged;
     Client.Connect(EndPoint);
     var centerX = GraphicsDevice.Viewport.Width / 2;
     var centerY = GraphicsDevice.Viewport.Height / 2;
     Mouse.SetPosition(centerX, centerY);
     Camera = new Camera(GraphicsDevice.Viewport.AspectRatio, 70.0f, 0.25f, 1000.0f);
     UpdateCamera();
     Window.ClientSizeChanged += (sender, e) => CreateRenderTarget();
     MouseComponent.Move += OnMouseComponentMove;
     KeyboardComponent.KeyDown += OnKeyboardKeyDown;
     KeyboardComponent.KeyUp += OnKeyboardKeyUp;
     CreateRenderTarget();
 }
Ejemplo n.º 6
0
 private void Game_Client_ChunkModified(object sender, ChunkEventArgs e)
 {
     ChunkRenderer.Enqueue(e.Chunk, true);
 }