void OnUpdatePosition(ref MyEventUpdatePosition msg)
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("Update position");
            MyEntityIdentifier entityId = new MyEntityIdentifier(msg.EntityId);

            if (!CheckSenderId(msg, msg.EntityId))
            {
                Alert("Player is updating entity which is not his", msg.SenderEndpoint, MyEventEnum.UPDATE_POSITION);
                return;
            }

            MyEntity entity;
            if (MyEntities.TryGetEntityById(entityId, out entity))
            {
                entity.WorldMatrix = msg.Position.GetMatrix();
                if (entity.Physics != null)
                {
                    entity.Physics.LinearVelocity = msg.Velocity;
                    entity.Physics.LinearAcceleration = msg.Acceleration;
                }
                entity.Physics.AngularVelocity = Vector3.Zero;
                //FixPlayerPosition(entity);
            }
            else
            {
                Alert("Entity to update not found", msg.SenderEndpoint, MyEventEnum.UPDATE_POSITION);
            }

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
        }
        public void UpdatePosition(MyEntity entity, Matrix worldMatrix, Vector3 velocity, Vector3 acceleration)
        {
            Debug.Assert(entity != null);
            Debug.Assert(!entity.Closed);

            var posMsg = new MyEventUpdatePosition();
            posMsg.EntityId = entity.EntityId.Value.NumericValue;
            posMsg.Position = new MyMwcPositionAndOrientation(worldMatrix);
            posMsg.Velocity = velocity;
            posMsg.Acceleration = acceleration;
            Peers.SendToAll(ref posMsg, entity.EntityId.Value, m_multiplayerConfig.PositionTickRateMax, NetDeliveryMethod.UnreliableSequenced, 1);
        }
        public void UpdatePosition(MyEntity entity)
        {
            Debug.Assert(entity != null);
            Debug.Assert(!entity.Closed);

            var posMsg = new MyEventUpdatePosition();
            MyEntity.FillMessage(entity, ref posMsg);
            Peers.SendToAll(ref posMsg, entity.EntityId.Value, m_multiplayerConfig.PositionTickRateMax, NetDeliveryMethod.UnreliableSequenced, 1);
        }
Esempio n. 4
0
 /// <summary>
 /// Optimized version for setting up message data
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="msg"></param>
 public static void FillMessage(MyEntity entity, ref MyEventUpdatePosition msg)
 {
     msg.EntityId = entity.EntityId.Value.NumericValue;
     msg.Position = new MyMwcPositionAndOrientation(ref entity.m_worldMatrix);
     msg.Velocity = entity.Physics.LinearVelocity;
     msg.Acceleration = entity.Physics.LinearAcceleration;
 }