protected override void OnEventFired(object source, EntityCreationStartingEventArgs args) { IMovementData movementData = MovementDataMappable.RetrieveEntity(args.EntityGuid); //We just need to make the world transform match //the initial movement data TransformMap.AddObject(args.EntityGuid, new WorldTransform(movementData.InitialPosition.x, movementData.InitialPosition.y, movementData.InitialPosition.z, movementData.Rotation)); }
/// <summary> /// Remove o mapeamento existente entre origem e destino /// </summary> /// <param name="sourceField"></param> /// <returns></returns> public Transform Unmap(string sourceField) { if (TransformMap.ContainsKey(sourceField)) { TransformMap.Remove(sourceField); } if (TransformFuncs.ContainsKey(sourceField)) { TransformFuncs.Remove(sourceField); } return(this); }
/// <inheritdoc /> public void Tick() { //Don't pass in different remote time, large amounts of objects may get a millisecond or two more time drift from the start. long currentRemoteTime = TimeService.CurrentRemoteTime; foreach (var entry in MovementGenerators.EnumerateWithGuid(KnonwnEntities)) { entry.ComponentValue.Update(WorldObjectMap.RetrieveEntity(entry.EntityGuid), currentRemoteTime); Vector3 currentPosition = entry.ComponentValue.CurrentPosition; TransformMap.ReplaceObject(entry.EntityGuid, new WorldTransform(currentPosition.x, currentPosition.y, currentPosition.z, TransformMap.RetrieveEntity(entry.EntityGuid).YAxisRotation)); } }
protected override void OnEventFired(object source, MovementInputChangedEventArgs args) { //We send remote time instead of remoteTime + latency because //our client is going to move right away and we want EVERYONE //to view us as if we had started moving at the same time as the //local client percieves it. long timeStamp = TimeService.CurrentRemoteTime; //We also are going to send a position hint to the server. //Server has authority in rejecting this hint, and it should if it finds its //WAY off. However this is how we deal with the issue of desyncronization //by having the client be semi-authorative about where it is. WorldTransform entity = TransformMap.RetrieveEntity(PlayerDetails.LocalPlayerGuid); SendService.SendMessage(new ClientMovementDataUpdateRequest(new Vector2(args.NewHorizontalInput, args.NewVerticalInput), timeStamp, new Vector3(entity.PositionX, entity.PositionY, entity.PositionZ))); }
protected override void OnEventFired(object source, MovementInputChangedEventArgs args) { //Don't predict on heartbeat if (args.isHeartBeat) { return; } Vector2 direction = new Vector2(args.NewHorizontalInput, args.NewVerticalInput); WorldTransform worldTransform = TransformMap.RetrieveEntity(PlayerDetails.LocalPlayerGuid); long predictedTime = TimeService.CurrentRemoteTime; IMovementData data = new PositionChangeMovementData(predictedTime, new Vector3(worldTransform.PositionX, worldTransform.PositionY, worldTransform.PositionZ), direction, worldTransform.YAxisRotation); MovementDataMappable.ReplaceObject(PlayerDetails.LocalPlayerGuid, data); MovementUpdateHandler.HandleMovementUpdate(new EntityAssociatedData <IMovementData>(PlayerDetails.LocalPlayerGuid, data), true); }