/// <inheritdoc /> public void Tick() { //Don't need to do this if we aren't moving if (isMoving) { using (SyncObj.Lock()) { //Double check locking if (!isMoving) { return; } GameObject worldObject = WorldObjectMap[EntityGuid.ComputeEntityGuid(EntityType.Player, SlotModel.SlotSelected)]; //From old movement //Vector3.Magnitude(lastPosition - transform.position) > Vector3.kEpsilon if (Vector3.Magnitude(LastPosition - worldObject.transform.position) > Vector3.kEpsilon) { LocalPlayerNetworkController.UpdatedMovementLocation(worldObject.transform.position, worldObject.transform.rotation); //TODO: This design is such that the above statement will be true the first time around. This could be bad for the first time the player moves LastPosition = worldObject.transform.position; } } } }
/// <inheritdoc /> public void Tick() { if (currentTimeSince < timeSendInterval) { currentTimeSince += Time.deltaTime; return; } //Don't need to do this if we aren't moving if (isMoving) { using (SyncObj.Lock()) { //Only reset if we're actually moving. Want to broadcast right away. currentTimeSince = 0.0f; //Double check locking if (!isMoving) { return; } GameObject worldObject = WorldObjectMap[EntityGuid.ComputeEntityGuid(EntityType.Player, SlotModel.SlotSelected)]; //From old movement //Vector3.Magnitude(lastPosition - transform.position) > Vector3.kEpsilon if (Vector3.Magnitude(LastPosition - worldObject.transform.position) > Vector3.kEpsilon) { LocalPlayerNetworkController.UpdatedMovementLocation(worldObject.transform.position, worldObject.transform.rotation); //TODO: This design is such that the above statement will be true the first time around. This could be bad for the first time the player moves LastPosition = worldObject.transform.position; } } } }
/// <inheritdoc /> protected override async void OnEventFired(object source, MovementInputChangedEventArgs args) { //State doesn't need to change if this is true //but it SHOULDN'T be true, as the event should not be //broadcasted if (CurrentMovementArgs == args) { return; } //It's ok to capture the sync context here, we'll need it to touch the GameObject //and the Transform. using (var l = await SyncObj.LockAsync()) { //If the input says NOT MOVING but we are MOVING //then we need to end the movement and then send a movement finished command if (!args.isMoving && isMoving) { GameObject worldObject = WorldObjectMap[EntityGuid.ComputeEntityGuid(EntityType.Player, SlotModel.SlotSelected)]; //It's important that this doesn't capture the sync context otheriwse it could block Update from finishing (causing deadlock) //since it needs to wait on SyncContext to be serviced by Unity3D in fixed update. It's CRITICAL that we do NOT block on the main thread //or such a deadlock will occur. await LocalPlayerNetworkController.StopMovementAsync(worldObject.transform.position, worldObject.transform.rotation) .ConfigureAwait(false); //We tell the controller to stop moving and we set our movement here to false. isMoving = false; } else { isMoving = true; //it probably already is true but it doesn't hurt to set it again. } CurrentMovementArgs = args; } }