Esempio n. 1
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.SetRenderTarget(RenderTarget);
            GraphicsDevice.RasterizerState  = RasterizerState.CullCounterClockwise;
            GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
            GraphicsDevice.SamplerStates[1] = SamplerState.PointClamp;

            Mesh.ResetStats();

            SkyModule.Draw(gameTime);
            ChunkModule.Draw(gameTime);
            HighlightModule.Draw(gameTime);
            HudModule.Draw(gameTime);
            ChatModule.Draw(gameTime);
            WindowModule.Draw(gameTime);
            DebugInfoModule.Draw(gameTime);

            _imgui.BeforeLayout(gameTime);
            ImGuiLayout();
            _imgui.AfterLayout();

            GraphicsDevice.SetRenderTarget(null);
            SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque);
            SpriteBatch.Draw(RenderTarget, Vector2.Zero, Color.White);
            SpriteBatch.End();

            base.Draw(gameTime);
        }
Esempio n. 2
0
        protected override void Update(GameTime gameTime)
        {
            GameTime = gameTime;

            if (PendingMainThreadActions.TryTake(out var action))
            {
                action();
            }

            var adjusted = Client.World.World.FindBlockPosition(
                new Coordinates3D((int)Client.Position.X, 0, (int)Client.Position.Z), out var chunk);

            if (chunk != null && Client.LoggedIn)
            {
                if (chunk.GetHeight((byte)adjusted.X, (byte)adjusted.Z) != 0)
                {
                    Client.Physics.Update(gameTime.ElapsedGameTime);
                }
            }

            if (NextPhysicsUpdate < DateTime.UtcNow && Client.LoggedIn)
            {
                // NOTE: This is to make the vanilla server send us chunk packets
                // We should eventually make some means of detecting that we're on a vanilla server to enable this
                // It's a waste of bandwidth to do it on a TrueCraft server
                Client.QueuePacket(new PlayerGroundedPacket {
                    OnGround = true
                });
                NextPhysicsUpdate = DateTime.UtcNow.AddMilliseconds(50);
            }

            if (IsActive)
            {
                foreach (var module in InputModules)
                {
                    module.Update(gameTime);
                }
            }

            SkyModule.Update(gameTime);
            ChunkModule.Update(gameTime);
            HighlightModule.Update(gameTime);
            HudModule.Update(gameTime);
            ChatModule.Update(gameTime);
            WindowModule.Update(gameTime);
            DebugInfoModule.Update(gameTime);

            UpdateCamera();

            base.Update(gameTime);
        }
Esempio n. 3
0
        protected override void Initialize()
        {
            InputModules = new List<IGameplayModule>();
            GraphicalModules = new List<IGameplayModule>();

            base.Initialize(); // (calls LoadContent)

            Camera = new Camera(GraphicsDevice.Viewport.AspectRatio, 70.0f, 0.1f, 1000.0f);
            UpdateCamera();

            White1x1 = new Texture2D(GraphicsDevice, 1, 1);
            White1x1.SetData<Color>(new[] { Color.White });

            Audio = new AudioManager();
            Audio.LoadDefaultPacks(Content);

            SkyModule = new SkyModule(this);
            ChunkModule = new ChunkModule(this);
            DebugInfoModule = new DebugInfoModule(this, Pixel);
            ChatModule = new ChatModule(this, Pixel);
            var hud = new HUDModule(this, Pixel);
            var windowModule = new WindowModule(this, Pixel);

            GraphicalModules.Add(SkyModule);
            GraphicalModules.Add(ChunkModule);
            GraphicalModules.Add(new HighlightModule(this));
            GraphicalModules.Add(hud);
            GraphicalModules.Add(ChatModule);
            GraphicalModules.Add(windowModule);
            GraphicalModules.Add(DebugInfoModule);

            InputModules.Add(windowModule);
            InputModules.Add(DebugInfoModule);
            InputModules.Add(ChatModule);
            InputModules.Add(new HUDModule(this, Pixel));
            InputModules.Add(ControlModule = new PlayerControlModule(this));

            Client.PropertyChanged += HandleClientPropertyChanged;
            Client.Connect(EndPoint);

            BlockProvider.BlockRepository = BlockRepository;
            var itemRepository = new ItemRepository();
            itemRepository.DiscoverItemProviders();
            ItemRepository = itemRepository;
            BlockProvider.ItemRepository = ItemRepository;

            IconRenderer.CreateBlocks(this, BlockRepository);

            var centerX = GraphicsDevice.Viewport.Width / 2;
            var centerY = GraphicsDevice.Viewport.Height / 2;
            Mouse.SetPosition(centerX, centerY);

            MouseComponent.Scroll += OnMouseComponentScroll;
            MouseComponent.Move += OnMouseComponentMove;
            MouseComponent.ButtonDown += OnMouseComponentButtonDown;
            MouseComponent.ButtonUp += OnMouseComponentButtonUp;
            KeyboardComponent.KeyDown += OnKeyboardKeyDown;
            KeyboardComponent.KeyUp += OnKeyboardKeyUp;
            GamePadComponent.ButtonDown += OnGamePadButtonDown;
            GamePadComponent.ButtonUp += OnGamePadButtonUp;

            CreateRenderTarget();
            SpriteBatch = new SpriteBatch(GraphicsDevice);
            ThreadID = Thread.CurrentThread.ManagedThreadId;
        }