private void OnPlayerUpdate(PlayerUpdate playerUpdate) { // Update the values of the player objects in the packet if (playerUpdate.UpdateTypes.Contains(PlayerUpdateType.Position)) { _playerManager.UpdatePosition(playerUpdate.Id, playerUpdate.Position); } if (playerUpdate.UpdateTypes.Contains(PlayerUpdateType.Scale)) { _playerManager.UpdateScale(playerUpdate.Id, playerUpdate.Scale); } if (playerUpdate.UpdateTypes.Contains(PlayerUpdateType.MapPosition)) { _mapManager.OnPlayerMapUpdate(playerUpdate.Id, playerUpdate.MapPosition); } if (playerUpdate.UpdateTypes.Contains(PlayerUpdateType.Animation)) { foreach (var animationInfo in playerUpdate.AnimationInfos) { _animationManager.OnPlayerAnimationUpdate( playerUpdate.Id, animationInfo.ClipId, animationInfo.Frame, animationInfo.EffectInfo ); } } }
private void OnUpdatePacket(ClientUpdatePacket packet) { // We received an update from the server, so we can reset the heart beat stopwatch _heartBeatReceiveStopwatch.Reset(); // Only start the stopwatch again if we are actually connected if (_netClient.IsConnected) { _heartBeatReceiveStopwatch.Start(); } if (packet.UpdateTypes.Contains(UpdateType.PlayerUpdate)) { // Update the values of the player objects in the packet foreach (var playerUpdate in packet.PlayerUpdates) { if (playerUpdate.UpdateTypes.Contains(PlayerUpdateType.Position)) { _playerManager.UpdatePosition(playerUpdate.Id, playerUpdate.Position); } if (playerUpdate.UpdateTypes.Contains(PlayerUpdateType.Scale)) { _playerManager.UpdateScale(playerUpdate.Id, playerUpdate.Scale); } if (playerUpdate.UpdateTypes.Contains(PlayerUpdateType.MapPosition)) { _mapManager.OnPlayerMapUpdate(playerUpdate.Id, playerUpdate.MapPosition); } if (playerUpdate.UpdateTypes.Contains(PlayerUpdateType.Animation)) { foreach (var animationInfo in playerUpdate.AnimationInfos) { _animationManager.OnPlayerAnimationUpdate( playerUpdate.Id, animationInfo.ClipId, animationInfo.Frame, animationInfo.EffectInfo ); } } } } // We only propagate entity updates to the entity manager if we have determined the scene host if (_sceneHostDetermined && packet.UpdateTypes.Contains(UpdateType.EntityUpdate)) { foreach (var entityUpdate in packet.EntityUpdates) { if (entityUpdate.UpdateTypes.Contains(EntityUpdateType.Position)) { _entityManager.UpdateEntityPosition(entityUpdate.EntityType, entityUpdate.Id, entityUpdate.Position); } // First update the variables, afterwards the state if (entityUpdate.UpdateTypes.Contains(EntityUpdateType.Variables)) { _entityManager.UpdateEntityVariables(entityUpdate.EntityType, entityUpdate.Id, entityUpdate.FsmVariables); } if (entityUpdate.UpdateTypes.Contains(EntityUpdateType.State)) { _entityManager.UpdateEntityState(entityUpdate.EntityType, entityUpdate.Id, entityUpdate.StateIndex); } } } }