Ejemplo n.º 1
0
        private static void UpdateLastTransform(ref TransformInternal.Component lastTransform, TransformInternal.Update update)
        {
            if (update.Location.HasValue)
            {
                lastTransform.Location = update.Location.Value;
            }

            if (update.Rotation.HasValue)
            {
                lastTransform.Rotation = update.Rotation.Value;
            }

            if (update.Velocity.HasValue)
            {
                lastTransform.Velocity = update.Velocity.Value;
            }

            if (update.TicksPerSecond.HasValue)
            {
                lastTransform.TicksPerSecond = update.TicksPerSecond.Value;
            }

            if (update.PhysicsTick.HasValue)
            {
                lastTransform.PhysicsTick = update.PhysicsTick.Value;
            }
        }
 public void OnResetAuth(WorkerSystem worker, Entity entity, ref TransformInternal.Component transformComponent, Rigidbody rigidbody)
 {
     rigidbody.MovePosition(transformComponent.Location.ToUnityVector() + worker.Origin);
     rigidbody.MoveRotation(transformComponent.Rotation.ToUnityQuaternion());
     rigidbody.AddForce(transformComponent.Velocity.ToUnityVector() - rigidbody.velocity,
                        ForceMode.VelocityChange);
 }
Ejemplo n.º 3
0
 private static BufferedTransform ToBufferedTransformAtTick(TransformInternal.Component component, uint tick)
 {
     return(new BufferedTransform
     {
         Position = component.Location.ToUnityVector3(),
         Velocity = component.Velocity.ToUnityVector3(),
         Orientation = component.Rotation.ToUnityQuaternion(),
         PhysicsTick = tick
     });
 }
Ejemplo n.º 4
0
 private static BufferedTransform ToBufferedTransform(TransformInternal.Component transform)
 {
     return(new BufferedTransform
     {
         Position = transform.Location.ToUnityVector3(),
         Velocity = transform.Velocity.ToUnityVector3(),
         Orientation = transform.Rotation.ToUnityQuaternion(),
         PhysicsTick = transform.PhysicsTick
     });
 }
Ejemplo n.º 5
0
        protected override void OnUpdate()
        {
            transformGroup.SetFilter(TransformInternal.ComponentAuthority.Authoritative);

            var rateLimitedConfigArray    = transformGroup.GetSharedComponentDataArray <RateLimitedSendConfig>();
            var transformArray            = transformGroup.GetComponentDataArray <TransformInternal.Component>();
            var transformToSendArray      = transformGroup.GetComponentDataArray <TransformToSend>();
            var lastTransformSentArray    = transformGroup.GetComponentDataArray <LastTransformSentData>();
            var ticksSinceLastUpdateArray = transformGroup.GetComponentDataArray <TicksSinceLastTransformUpdate>();

            for (int i = 0; i < transformArray.Length; ++i)
            {
                var lastTransformSent = lastTransformSentArray[i];
                lastTransformSent.TimeSinceLastUpdate += Time.deltaTime;
                lastTransformSentArray[i]              = lastTransformSent;

                if (lastTransformSent.TimeSinceLastUpdate <
                    1.0f / rateLimitedConfigArray[i].MaxTransformUpdateRateHz)
                {
                    continue;
                }

                var transform = transformArray[i];

                var transformToSend = transformToSendArray[i];

                var currentTransform = new TransformInternal.Component
                {
                    Location       = (transformToSend.Position - worker.Origin).ToImprobableLocation(),
                    Rotation       = transformToSend.Orientation.ToImprobableQuaternion(),
                    Velocity       = transformToSend.Velocity.ToImprobableVelocity(),
                    PhysicsTick    = transform.PhysicsTick + ticksSinceLastUpdateArray[i].NumberOfTicks,
                    TicksPerSecond = tickRate.PhysicsTicksPerRealSecond
                };

                if (!(TransformUtils.HasChanged(currentTransform.Location, transform.Location) ||
                      TransformUtils.HasChanged(currentTransform.Rotation, transform.Rotation)))
                {
                    continue;
                }

                lastTransformSent.TimeSinceLastUpdate = 0.0f;
                lastTransformSent.Transform           = transform;
                lastTransformSentArray[i]             = lastTransformSent;

                transformArray[i] = currentTransform;

                ticksSinceLastUpdateArray[i] = new TicksSinceLastTransformUpdate
                {
                    NumberOfTicks = 0
                };
            }
        }
        protected override void OnUpdate()
        {
            for (int i = 0; i < data.Length; ++i)
            {
                var lastTransformSent = data.LastTransformSent[i];
                lastTransformSent.TimeSinceLastUpdate += Time.deltaTime;
                data.LastTransformSent[i]              = lastTransformSent;

                if (lastTransformSent.TimeSinceLastUpdate <
                    1.0f / data.RateLimitedConfig[i].MaxTransformUpdateRateHz)
                {
                    continue;
                }

                var transform = data.TransformComponent[i];

                var transformToSend = data.TransformToSend[i];

                var currentTransform = new TransformInternal.Component
                {
                    Location       = (transformToSend.Position - worker.Origin).ToImprobableLocation(),
                    Rotation       = transformToSend.Orientation.ToImprobableQuaternion(),
                    Velocity       = transformToSend.Velocity.ToImprobableVelocity(),
                    PhysicsTick    = transform.PhysicsTick + data.TicksSinceLastUpdate[i].NumberOfTicks,
                    TicksPerSecond = tickRate.PhysicsTicksPerRealSecond,
                    DirtyBit       = true
                };

                if (!(TransformUtils.HasChanged(currentTransform.Location, transform.Location) ||
                      TransformUtils.HasChanged(currentTransform.Rotation, transform.Rotation)))
                {
                    continue;
                }

                lastTransformSent.TimeSinceLastUpdate = 0.0f;
                lastTransformSent.Transform           = transform;
                data.LastTransformSent[i]             = lastTransformSent;

                data.TransformComponent[i] = currentTransform;

                data.TicksSinceLastUpdate[i] = new TicksSinceLastTransformUpdate
                {
                    NumberOfTicks = 0
                };
            }
        }
        protected override void OnUpdate()
        {
            for (int i = 0; i < data.Length; ++i)
            {
                var t         = data.CurrentTransform[i];
                var transform = new TransformInternal.Component
                {
                    Location       = (t.Position - worker.Origin).ToImprobableLocation(),
                    Rotation       = t.Orientation.ToImprobableQuaternion(),
                    Velocity       = t.Velocity.ToImprobableVelocity(),
                    PhysicsTick    = data.Transform[i].PhysicsTick + data.TicksSinceLastUpdate[i].NumberOfTicks,
                    TicksPerSecond = tickRate.PhysicsTicksPerRealSecond
                };

                data.Transform[i] = transform;

                data.TicksSinceLastUpdate[i] = new TicksSinceLastTransformUpdate
                {
                    NumberOfTicks = 0
                };
            }
        }