Exemple #1
0
        protected override void Update(GameTime gameTime)
        {
            GameTime = gameTime;

            Action action;
            if (PendingMainThreadActions.TryTake(out action))
                action();

            IChunk chunk;
            var adjusted = Client.World.World.FindBlockPosition(
                new Coordinates3D((int)Client.Position.X, 0, (int)Client.Position.Z), out 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 detecing 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);
            }

            foreach (var module in InputModules)
                module.Update(gameTime);
            foreach (var module in GraphicalModules)
                module.Update(gameTime);

            UpdateCamera();

            base.Update(gameTime);
        }
Exemple #2
0
        public void FlushMainThreadActions()
        {
            Action action;

            while (PendingMainThreadActions.TryTake(out action))
            {
                action();
            }
        }
Exemple #3
0
        protected override void Update(GameTime gameTime)
        {
            GameTime = gameTime;

            foreach (var i in Interfaces)
            {
                i.Update(gameTime);
            }

            Mesh mesh;

            while (IncomingChunks.TryTake(out mesh))
            {
                ChunkMeshes.Add(mesh);
            }
            Action action;

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

            if (NextPhysicsUpdate < DateTime.UtcNow && Client.LoggedIn)
            {
                IChunk chunk;
                var    adjusted = Client.World.World.FindBlockPosition(new Coordinates3D((int)Client.Position.X, 0, (int)Client.Position.Z), out chunk);
                if (chunk != null)
                {
                    if (chunk.GetHeight((byte)adjusted.X, (byte)adjusted.Z) != 0)
                    {
                        Client.Physics.Update();
                    }
                }
                // NOTE: This is to make the vanilla server send us chunk packets
                // We should eventually make some means of detecing 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
                });
                Client.QueuePacket(new PlayerPositionAndLookPacket(Client.Position.X, Client.Position.Y,
                                                                   Client.Position.Y + MultiplayerClient.Height, Client.Position.Z, Client.Yaw, Client.Pitch, false));
                NextPhysicsUpdate = DateTime.UtcNow.AddMilliseconds(1000 / 20);
            }

            if (Delta != Microsoft.Xna.Framework.Vector3.Zero)
            {
                var lookAt = Microsoft.Xna.Framework.Vector3.Transform(
                    Delta, Matrix.CreateRotationY(Microsoft.Xna.Framework.MathHelper.ToRadians(Client.Yaw)));

                Client.Position += new TrueCraft.API.Vector3(lookAt.X, lookAt.Y, lookAt.Z)
                                   * (gameTime.ElapsedGameTime.TotalSeconds * 4.3717);
            }

            base.Update(gameTime);
        }