protected override void OnUpdate() { transformGroup.SetFilter(TransformInternal.ComponentAuthority.NotAuthoritative); var transformToSetArray = transformGroup.GetComponentDataArray <TransformToSet>(); var spatialEntityIdArray = transformGroup.GetComponentDataArray <SpatialEntityId>(); var transformComponentArray = transformGroup.GetComponentDataArray <TransformInternal.Component>(); for (int i = 0; i < transformToSetArray.Length; ++i) { var entityId = spatialEntityIdArray[i]; var updates = updateSystem.GetEntityComponentUpdatesReceived <TransformInternal.Update>(entityId.EntityId); if (updates.Count == 0) { continue; } var t = transformComponentArray[i]; transformToSetArray[i] = new TransformToSet { Position = t.Location.ToUnityVector3() + worker.Origin, Velocity = t.Velocity.ToUnityVector3(), Orientation = t.Rotation.ToUnityQuaternion() }; } }
protected override void OnUpdate() { transformGroup.SetFilter(TransformInternal.ComponentAuthority.NotAuthoritative); var transformToSetArray = transformGroup.GetComponentDataArray <TransformToSet>(); var transformBufferArray = transformGroup.GetBufferArray <BufferedTransform>(); for (int i = 0; i < transformToSetArray.Length; ++i) { var buffer = transformBufferArray[i]; if (buffer.Length == 0) { continue; } var bufferHead = buffer[0]; var currentTransform = new TransformToSet { Position = bufferHead.Position + worker.Origin, Orientation = bufferHead.Orientation, Velocity = bufferHead.Velocity, ApproximateRemoteTick = bufferHead.PhysicsTick }; transformToSetArray[i] = currentTransform; buffer.RemoveAt(0); } }
protected override void OnUpdate() { for (int i = 0; i < data.Length; ++i) { var buffer = data.TransformBuffer[i]; if (buffer.Length == 0) { continue; } var bufferHead = buffer[0]; var currentTransform = new TransformToSet { Position = bufferHead.Position + worker.Origin, Orientation = bufferHead.Orientation, Velocity = bufferHead.Velocity, ApproximateRemoteTick = bufferHead.PhysicsTick }; data.CurrentTransform[i] = currentTransform; buffer.RemoveAt(0); } }
protected override void OnUpdate() { for (int i = 0; i < data.Length; ++i) { // Need to split this out into server / client / whatever var transform = data.Transform[i]; var defaultToSet = new TransformToSet { Position = transform.Location.ToUnityVector3() + worker.Origin, Velocity = transform.Velocity.ToUnityVector3(), Orientation = transform.Rotation.ToUnityQuaternion() }; var defaultToSend = new TransformToSend { Position = transform.Location.ToUnityVector3() - worker.Origin, Velocity = transform.Velocity.ToUnityVector3(), Orientation = transform.Rotation.ToUnityQuaternion() }; var previousTransform = new DefferedUpdateTransform { Transform = transform }; var ticksSinceLastUpdate = new TicksSinceLastTransformUpdate { NumberOfTicks = 0 }; var lastTransform = new LastTransformSentData { // could set this to the max time if we want to immediately send something TimeSinceLastUpdate = 0.0f, Transform = transform }; var lastPosition = new LastPositionSentData { // could set this to the max time if we want to immediately send something TimeSinceLastUpdate = 0.0f, Position = data.Position[i] }; PostUpdateCommands.AddComponent(data.Entity[i], defaultToSet); PostUpdateCommands.AddComponent(data.Entity[i], defaultToSend); PostUpdateCommands.AddComponent(data.Entity[i], previousTransform); PostUpdateCommands.AddComponent(data.Entity[i], ticksSinceLastUpdate); PostUpdateCommands.AddComponent(data.Entity[i], lastPosition); PostUpdateCommands.AddComponent(data.Entity[i], lastTransform); PostUpdateCommands.AddBuffer <BufferedTransform>(data.Entity[i]); } }
protected override void OnUpdate() { for (int i = 0; i < data.Length; ++i) { var buffer = data.TransformBuffer[i]; if (buffer.Length == 0) { continue; } var currentTransform = new TransformToSet { Position = buffer[0].Position + worker.Origin, Orientation = buffer[0].Orientation }; data.CurrentTransform[i] = currentTransform; buffer.RemoveAt(0); } }
protected override void OnUpdate() { Entities.With(transformGroup).ForEach( (ref TransformToSet transformToSet, ref SpatialEntityId spatialEntityId, ref TransformInternal.Component transformInternal) => { var updates = updateSystem.GetEntityComponentUpdatesReceived <TransformInternal.Update>(spatialEntityId.EntityId); if (updates.Count == 0) { return; } transformToSet = new TransformToSet { Position = transformInternal.Location.ToUnityVector() + worker.Origin, Velocity = transformInternal.Velocity.ToUnityVector(), Orientation = transformInternal.Rotation.ToUnityQuaternion() }; }); }
private void AddCommonReceiveComponents(EntityCommandBuffer commandBuffer) { commandBuffer.AddComponent(entity, new SetTransformToGameObjectTag()); var transformComponent = transformReader.Data; var defaultToSet = new TransformToSet { Position = transformComponent.Location.ToUnityVector() + world.GetExistingSystem <WorkerSystem>().Origin, Velocity = transformComponent.Velocity.ToUnityVector(), Orientation = transformComponent.Rotation.ToUnityQuaternion(), ApproximateRemoteTick = 0 }; var previousTransform = new DeferredUpdateTransform { Transform = transformComponent }; commandBuffer.AddComponent(entity, defaultToSet); commandBuffer.AddComponent(entity, previousTransform); commandBuffer.AddBuffer <BufferedTransform>(entity); }
protected override void OnUpdate() { Entities.With(transformGroup).ForEach( (DynamicBuffer <BufferedTransform> buffer, ref TransformToSet transformToSet) => { if (buffer.Length == 0) { return; } var bufferHead = buffer[0]; transformToSet = new TransformToSet { Position = bufferHead.Position + worker.Origin, Orientation = bufferHead.Orientation, Velocity = bufferHead.Velocity, ApproximateRemoteTick = bufferHead.PhysicsTick }; buffer.RemoveAt(0); }); }
public void ApplyLatestTransform(ref TransformToSet transformToSet, Rigidbody rigidbody) { rigidbody.MovePosition(transformToSet.Position); rigidbody.MoveRotation(transformToSet.Orientation); rigidbody.AddForce(transformToSet.Velocity - rigidbody.velocity, ForceMode.VelocityChange); }
public void ApplyLatestTransform(ref TransformToSet transformToSet, Rigidbody2D rigidbody) { rigidbody.MovePosition(transformToSet.Position); rigidbody.MoveRotation(transformToSet.Orientation); rigidbody.AddForce((Vector2)transformToSet.Velocity - rigidbody.velocity, ForceMode2D.Impulse); }