コード例 #1
0
ファイル: TrueCraftGame.cs プロジェクト: jdc20181/OpenCraft
        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);
        }
コード例 #2
0
ファイル: TrueCraftGame.cs プロジェクト: jdc20181/OpenCraft
 public void Invoke(Action action)
 {
     if (ThreadID == Thread.CurrentThread.ManagedThreadId)
         action();
     else
         PendingMainThreadActions.Add(action);
 }
コード例 #3
0
ファイル: TrueCraftGame.cs プロジェクト: simisu/TrueCraft
        public void FlushMainThreadActions()
        {
            Action action;

            while (PendingMainThreadActions.TryTake(out action))
            {
                action();
            }
        }
コード例 #4
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);
        }
コード例 #5
0
 void HandleClientPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     switch (e.PropertyName)
     {
     case "Position":
         UpdateCamera();
         var sorter = new ChunkRenderer.ChunkSorter(new Coordinates3D(
                                                        (int)Client.Position.X, 0, (int)Client.Position.Z));
         PendingMainThreadActions.Add(() => ChunkMeshes.Sort(sorter));
         break;
     }
 }