static void OnPositionBatchUpdate(ref PositionUpdateBatchMsg msg, MyNetworkClient sender) { for (int i = 0; i < msg.Positions.Count; i++) { var m = msg.Positions[i]; MyEntity e; if (MyEntities.TryGetEntityById <MyEntity>(m.EntityId, out e)) { (e.SyncObject as MySyncEntity).OnPositionUpdate(ref m, sender); } } }
public static void SendPositionUpdates(List <MyEntity> entities) { PositionUpdateBatchMsg msg = new PositionUpdateBatchMsg(); msg.Positions = new List <PositionUpdateMsg>(entities.Count); foreach (var entity in entities) { msg.Positions.Add(CreatePositionMsg(entity)); ((MySyncEntity)entity.SyncObject).ResetUpdateTimer(); ((MySyncEntity)entity.SyncObject).m_positionDirty = false; } MySession.Static.SyncLayer.SendMessageToAll(ref msg); }
private void SendPositionUpdate() { float epsilonSq = 0.05f * 0.05f; if (m_updateFrameCount == ConstantMovementUpdateCount && (Entity.Physics == null || Entity.Physics.LinearAcceleration.LengthSquared() > epsilonSq || Entity.Physics.AngularAcceleration.LengthSquared() > epsilonSq)) { m_updateFrameCount = DefaultUpdateCount; } if (MyMultiplayer.Static != null && MyMultiplayer.Static.FrameCounter - m_lastUpdateFrame >= m_updateFrameCount) { m_updateFrameCount = ConstantMovementUpdateCount; // TODO: abstraction would be nice var syncGrid = this as MySyncGrid; if (syncGrid != null) { var g = MyCubeGridGroups.Static.Physical.GetGroup(syncGrid.Entity); PositionUpdateBatchMsg msg = new PositionUpdateBatchMsg(); msg.Positions = new List <PositionUpdateMsg>(g.Nodes.Count); foreach (var node in g.Nodes) { msg.Positions.Add(CreatePositionMsg(node.NodeData)); node.NodeData.SyncObject.ResetUpdateTimer(); node.NodeData.SyncObject.m_positionDirty = false; } MySession.Static.SyncLayer.SendMessageToAll(ref msg); } else { ResetUpdateTimer(); PositionUpdateMsg msg = CreatePositionMsg(Entity); MySession.Static.SyncLayer.SendMessageToAll(ref msg); } m_positionDirty = false; } else if (MyMultiplayer.Static != null) { MyMultiplayer.Static.RegisterForTick(this); m_positionDirty = true; } }
private void SendPositionUpdate() { if (MyMultiplayer.Static == null) { return; } Debug.Assert(MySandboxGame.Static != null); float epsilonSq = 0.05f * 0.05f; if (m_updateFrameCount == ConstantMovementUpdateCount && (Entity.Physics == null || Entity.Physics.LinearAcceleration.LengthSquared() > epsilonSq || Entity.Physics.AngularAcceleration.LengthSquared() > epsilonSq)) { m_updateFrameCount = DefaultUpdateCount; } bool timeForUpdate; if (MyFakes.NEW_POS_UPDATE_TIMING) { timeForUpdate = (MySandboxGame.Static.UpdateTime - m_lastUpdateTime).Seconds > (m_updateFrameCount / MyEngineConstants.UPDATE_STEPS_PER_SECOND); } else { timeForUpdate = MyMultiplayer.Static.FrameCounter - m_lastUpdateFrame >= m_updateFrameCount; } if (timeForUpdate) { m_updateFrameCount = ConstantMovementUpdateCount; // TODO: abstraction would be nice var syncGrid = this as MySyncGrid; if (syncGrid != null) { var g = MyCubeGridGroups.Static.Physical.GetGroup(syncGrid.Entity); PositionUpdateBatchMsg msg = new PositionUpdateBatchMsg(); msg.Positions = new List <PositionUpdateMsg>(g.Nodes.Count); foreach (var node in g.Nodes) { msg.Positions.Add(CreatePositionMsg(node.NodeData)); node.NodeData.SyncObject.ResetUpdateTimer(); node.NodeData.SyncObject.m_positionDirty = false; } MySession.Static.SyncLayer.SendMessageToAll(ref msg); } else { ResetUpdateTimer(); PositionUpdateMsg msg = CreatePositionMsg(Entity); MySession.Static.SyncLayer.SendMessageToAll(ref msg); } m_positionDirty = false; } else if (MyMultiplayer.Static != null) { MyMultiplayer.Static.RegisterForTick(this); m_positionDirty = true; } }