Exemplo n.º 1
0
        protected override void OnUpdate()
        {
            var group     = World.GetExistingSystem <GhostPredictionSystemGroup>();
            var tick      = group.PredictingTick;
            var deltaTime = Time.DeltaTime;
            var isClient  = World.GetExistingSystem <ClientSimulationSystemGroup>() != null;

            Entities.ForEach((
                                 DynamicBuffer <PlayerInput> inputBuffer,
                                 ref PlayerView view,
                                 ref Rotation rot,
                                 in PlayerId playerId,
                                 in PredictedGhostComponent prediction) =>
            {
                if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction))
                {
                    return;
                }

                PlayerInput input;
                inputBuffer.GetDataAtTick(tick, out input);
                view.pitch      = input.targetPitch;
                view.yaw        = input.targetYaw;
                rot.Value.value = quaternion.Euler(new float3(0, math.radians(view.yaw), 0)).value;
            }).ScheduleParallel();
        protected override void OnUpdate()
        {
            var group     = World.GetExistingSystem <GhostPredictionSystemGroup>();
            var tick      = group.PredictingTick;
            var deltaTime = Time.DeltaTime;

            Entities.ForEach((
                                 DynamicBuffer <PlayerInput> inputBuffer,
                                 ref KCCVelocity velocity,
                                 ref KCCJumping jump,
                                 in PredictedGhostComponent prediction,
                                 in PlayerView view,
                                 in KCCMovementSettings settings) =>
            {
                if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction))
                {
                    return;
                }

                inputBuffer.GetDataAtTick(tick, out PlayerInput input);

                // Rotate movement vector around current attitude (only care about horizontal)
                float3 inputVector = new float3(input.horizMove, 0, input.vertMove);
                // Don't allow the total movement to be more than the 1x max move speed
                float3 direction = inputVector / math.max(math.length(inputVector), 1);

                float speedMultiplier = input.IsSprinting ? settings.SprintSpeed : settings.moveSpeed;

                quaternion horizPlaneView = quaternion.RotateY(math.radians(view.yaw));

                // Make movement vector based on player input
                velocity.playerVelocity = math.mul(horizPlaneView, direction) * speedMultiplier;
                // including jump action
                jump.attemptingJump = input.IsJumping;
            }).Schedule();
    protected override void OnCreate()
    {
        // m_BeginSimEcb = World.GetOrCreateSystem<BeginSimulationEntityCommandBufferSystem>();

        //We will grab this system so we can use its "prediction tick" and "DeltaTime"
        m_PredictionGroup = World.GetOrCreateSystem <GhostPredictionSystemGroup>();
    }
Exemplo n.º 4
0
        protected override void OnUpdate()
        {
            var group     = World.GetExistingSystem <GhostPredictionSystemGroup>();
            var tick      = group.PredictingTick;
            var deltaTime = group.Time.DeltaTime;

            Entities.ForEach((DynamicBuffer <CubeInput> inputBuffer, ref Translation trans, ref PredictedGhostComponent prediction) =>
            {
                if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction))
                {
                    return;
                }
                CubeInput input;
                inputBuffer.GetDataAtTick(tick, out input);
                if (input.Horizontal > 0)
                {
                    trans.Value.x += deltaTime;
                }
                if (input.Horizontal < 0)
                {
                    trans.Value.x -= deltaTime;
                }
                if (input.Vertical > 0)
                {
                    trans.Value.y += deltaTime;
                }
                if (input.Vertical < 0)
                {
                    trans.Value.y -= deltaTime;
                }
            });
        }
Exemplo n.º 5
0
 protected override void OnCreate()
 {
     m_GhostUpdateSystemGroup      = World.GetOrCreateSystem <GhostUpdateSystemGroup>();
     m_ClientSimulationSystemGroup = World.GetOrCreateSystem <ClientSimulationSystemGroup>();
     m_GhostPredictionSystemGroup  = World.GetOrCreateSystem <GhostPredictionSystemGroup>();
     m_interpolatedQuery           = GetEntityQuery(new EntityQueryDesc
     {
         All = new [] {
             ComponentType.ReadWrite <CharacterSnapshotData>(),
             ComponentType.ReadOnly <GhostComponent>(),
             ComponentType.ReadWrite <Attack>(),
             ComponentType.ReadWrite <Damage>(),
             ComponentType.ReadWrite <MovableCharacterComponent>(),
             ComponentType.ReadWrite <PlayerData>(),
             ComponentType.ReadWrite <PrefabCreator>(),
             ComponentType.ReadWrite <Translation>(),
         },
         None = new [] { ComponentType.ReadWrite <PredictedGhostComponent>() }
     });
     m_predictedQuery = GetEntityQuery(new EntityQueryDesc
     {
         All = new [] {
             ComponentType.ReadOnly <CharacterSnapshotData>(),
             ComponentType.ReadOnly <GhostComponent>(),
             ComponentType.ReadOnly <PredictedGhostComponent>(),
         }
     });
     RequireForUpdate(GetEntityQuery(ComponentType.ReadWrite <CharacterSnapshotData>(),
                                     ComponentType.ReadOnly <GhostComponent>()));
 }
Exemplo n.º 6
0
 protected override void OnCreate()
 {
     m_Barrier         = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>();
     m_PredictionGroup = World.GetOrCreateSystem <GhostPredictionSystemGroup>();
     RequireSingletonForUpdate <LevelComponent>();
     RequireSingletonForUpdate <GhostPrefabCollectionComponent>();
 }
Exemplo n.º 7
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            inputDeps.Complete();

            var healthStateFromEntity = GetComponentDataFromEntity <HealthStateData>(true);
            var time = GetEntityQuery(ComponentType.ReadOnly <GlobalGameTime>()).GetSingleton <GlobalGameTime>().gameTime;
            var predictedFromEntity = GetComponentDataFromEntity <PredictedGhostComponent>(false);
            var PredictingTick      = World.GetExistingSystem <GhostPredictionSystemGroup>().PredictingTick;

            Entities
            .ForEach((ref Ability.AbilityStateIdle stateIdle, ref Ability.EnabledAbility enabledAbility, ref PredictedState predictedState) =>
            {
                if (predictedFromEntity.Exists(enabledAbility.owner) && !GhostPredictionSystemGroup.ShouldPredict(PredictingTick, predictedFromEntity[enabledAbility.owner]))
                {
                    return;
                }

                var shouldDash = enabledAbility.activeButtonIndex == 0 && DashAllowed(healthStateFromEntity[enabledAbility.owner]);
                if (shouldDash)
                {
                    stateIdle.requestActive      = true;
                    predictedState.locoStartTick = time.tick;
                }
            }).Run();

            return(default);
Exemplo n.º 8
0
 protected override void OnCreate()
 {
     _storeSystem = World.GetOrCreateSystem <GameObjectManager>();
     RequireSingletonForUpdate <CommandTargetComponent>();
     RequireSingletonForUpdate <EnableNetFPS>();
     _clientSimulationSystemGroup = World.GetOrCreateSystem <GhostPredictionSystemGroup>();
 }
Exemplo n.º 9
0
    protected override void OnUpdate()
    {
        var group          = World.GetExistingSystem <GhostPredictionSystemGroup>();
        var predictingTick = group.PredictingTick;
        var deltaTime      = Time.DeltaTime;

        var speed = _appConfig.Characters[0].Speed;
        var time  = (int)(Time.ElapsedTime);

        var colliders = _colliders;
        var skillsMap = _skillsDurationMap;

        Entities.WithoutBurst().WithReadOnly(colliders).ForEach((Entity e, DynamicBuffer <PlayerInput> inputBuffer,
                                                                 ref Attack attack, ref Damage damage,
                                                                 ref Translation trans, ref PlayerData pdata, ref PredictedGhostComponent prediction) =>
        {
            if (!GhostPredictionSystemGroup.ShouldPredict(predictingTick, prediction))
            {
                return;
            }

            if (!(inputBuffer.GetDataAtTick(predictingTick, out PlayerInput input) && input.Tick == predictingTick))
            {
                // LogServer(isServer, $"Did NOT run server-side prediction because only available input had tick {input.Tick} while the predicting tick is {predictingTick}");
                return;
            }
Exemplo n.º 10
0
    protected override void OnUpdate()
    {
        var tick      = m_GhostPredictionSystemGroup.PredictingTick;
        var deltaTime = Time.DeltaTime;

        Entities.ForEach((DynamicBuffer <CubeInput> inputBuffer, ref Translation trans, in PredictedGhostComponent prediction) =>
        {
            if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction))
            {
                return;
            }
            CubeInput input;
            inputBuffer.GetDataAtTick(tick, out input);
            if (input.horizontal > 0)
            {
                trans.Value.x += deltaTime;
            }
            if (input.horizontal < 0)
            {
                trans.Value.x -= deltaTime;
            }
            if (input.vertical > 0)
            {
                trans.Value.z += deltaTime;
            }
            if (input.vertical < 0)
            {
                trans.Value.z -= deltaTime;
            }
        }).ScheduleParallel();
    }
 protected override void OnCreate()
 {
     m_GhostUpdateSystemGroup      = World.GetOrCreateSystem <GhostUpdateSystemGroup>();
     m_ClientSimulationSystemGroup = World.GetOrCreateSystem <ClientSimulationSystemGroup>();
     m_GhostPredictionSystemGroup  = World.GetOrCreateSystem <GhostPredictionSystemGroup>();
     m_interpolatedQuery           = GetEntityQuery(new EntityQueryDesc
     {
         All = new [] {
             ComponentType.ReadWrite <ExtraBlockSnapshotData>(),
             ComponentType.ReadOnly <GhostComponent>(),
             ComponentType.ReadWrite <Rotation>(),
             ComponentType.ReadWrite <Translation>(),
         },
         None = new [] { ComponentType.ReadWrite <PredictedGhostComponent>() }
     });
     m_predictedQuery = GetEntityQuery(new EntityQueryDesc
     {
         All = new [] {
             ComponentType.ReadOnly <ExtraBlockSnapshotData>(),
             ComponentType.ReadOnly <GhostComponent>(),
             ComponentType.ReadOnly <PredictedGhostComponent>(),
             ComponentType.ReadWrite <Rotation>(),
             ComponentType.ReadWrite <Translation>(),
         }
     });
     RequireForUpdate(GetEntityQuery(ComponentType.ReadWrite <ExtraBlockSnapshotData>(),
                                     ComponentType.ReadOnly <GhostComponent>()));
 }
Exemplo n.º 12
0
    protected override void OnUpdate()
    {
        var group     = World.GetExistingSystem <GhostPredictionSystemGroup>();
        var tick      = group.PredictingTick;
        var deltaTime = Time.DeltaTime;

        Entities.ForEach((DynamicBuffer <CubeInput> inputBuffer, ref Translation trans, ref PredictedGhostComponent prediction, ref Rotation rot) =>
        {
            if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction))
            {
                return;
            }
            CubeInput input;
            inputBuffer.GetDataAtTick(tick, out input);

            rot.Value = quaternion.AxisAngle(math.up(), input.rotation * math.PI / 180);

            if (input.horizontal > 0)
            {
                trans.Value.x += deltaTime;
            }
            if (input.horizontal < 0)
            {
                trans.Value.x -= deltaTime;
            }
            if (input.vertical > 0)
            {
                trans.Value.z += deltaTime;
            }
            if (input.vertical < 0)
            {
                trans.Value.z -= deltaTime;
            }
        });
    }
Exemplo n.º 13
0
    protected override void OnCreate()
    {
        m_GhostUpdateSystemGroup = World.GetOrCreateSystem <GhostUpdateSystemGroup>();
        m_ghostEntityMap         = m_GhostUpdateSystemGroup.GhostEntityMap;
#if UNITY_EDITOR || DEVELOPMENT_BUILD
        m_ghostMinMaxSnapshotTick = m_GhostUpdateSystemGroup.GhostSnapshotTickMinMax;
#endif
        m_ClientSimulationSystemGroup = World.GetOrCreateSystem <ClientSimulationSystemGroup>();
        m_GhostPredictionSystemGroup  = World.GetOrCreateSystem <GhostPredictionSystemGroup>();
        m_interpolatedQuery           = GetEntityQuery(new EntityQueryDesc
        {
            All = new [] {
                ComponentType.ReadWrite <LagCompensationTestPlayerSnapshotData>(),
                ComponentType.ReadOnly <GhostComponent>(),
                ComponentType.ReadWrite <LagCompensationTestPlayer>(),
                ComponentType.ReadWrite <Rotation>(),
                ComponentType.ReadWrite <Translation>(),
            },
            None = new [] { ComponentType.ReadWrite <PredictedGhostComponent>() }
        });
        m_predictedQuery = GetEntityQuery(new EntityQueryDesc
        {
            All = new [] {
                ComponentType.ReadOnly <LagCompensationTestPlayerSnapshotData>(),
                ComponentType.ReadOnly <GhostComponent>(),
                ComponentType.ReadOnly <PredictedGhostComponent>(),
                ComponentType.ReadWrite <LagCompensationTestPlayer>(),
                ComponentType.ReadWrite <Rotation>(),
                ComponentType.ReadWrite <Translation>(),
            }
        });
        RequireForUpdate(GetEntityQuery(ComponentType.ReadWrite <LagCompensationTestPlayerSnapshotData>(),
                                        ComponentType.ReadOnly <GhostComponent>()));
    }
Exemplo n.º 14
0
 public void Execute([ReadOnly] ref Velocity velocity, ref Translation position, [ReadOnly] ref PredictedGhostComponent prediction)
 {
     if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction))
     {
         return;
     }
     position.Value.xy += velocity.Value * deltaTime;
 }
Exemplo n.º 15
0
    protected override void OnCreate()
    {
        simulationDeltaTime = 1f / GetSingleton <ClientServerTickRate>().SimulationTickRate;

        ghostPredictionSystemGroup     = World.GetOrCreateSystem <GhostPredictionSystemGroup>();
        startCountdownServerSystem     = World.GetOrCreateSystem <StartCountdownServerSystem>();
        checkpointInitializationSystem = World.GetOrCreateSystem <CheckpointInitializationSystem>();
    }
Exemplo n.º 16
0
    protected override void OnUpdate()
    {
        var tick      = m_GhostPredictionSystemGroup.PredictingTick;
        var deltaTime = Time.DeltaTime;

        Entities.ForEach((DynamicBuffer <PlayerInput> inputBuffer, ref Translation trans, ref PhysicsVelocity pv, in PredictedGhostComponent prediction, in PlayerMovementSpeed pms) =>
        {
            if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction))
            {
                return;
            }
            PlayerInput input;
            inputBuffer.GetDataAtTick(tick, out input);
            var speed = pms.speed;

            /*if (input.horizontal > 0)
             *  trans.Value.x += speed * deltaTime;
             * if (input.horizontal < 0)
             *  trans.Value.x -= speed * deltaTime;
             * if (input.vertical > 0)
             *  trans.Value.z += speed * deltaTime;
             * if (input.vertical < 0)
             *  trans.Value.z -= speed * deltaTime;*/

            // cosi' non rimbalza ma lagga e ci mette un po' ad accelerare
            if (input.horizontal > 0)
            {
                pv.Linear.x += speed * deltaTime;
            }
            if (input.horizontal < 0)
            {
                pv.Linear.x -= speed * deltaTime;
            }
            if (input.vertical > 0)
            {
                pv.Linear.z += speed * deltaTime;
            }
            if (input.vertical < 0)
            {
                pv.Linear.z -= speed * deltaTime;
            }

            if (input.firstJump)
            {
                pv.Linear.y     = 8f;
                input.firstJump = false;
            }

            /*
             * un altro modo per far muovere l'oggetto è generando un impulso lineare (using Unity.Physics.Extensions):
             * Itero su tutte le entities che hanno i componenti PhysicsVelocity e PhysicsMass (+ PlayerMovementSpeed
             * e l'input del Player, nel nostro caso DynamicBuffer<PlayerInput>), quindi imposto la direzione
             * dell'impulso con:
             * float3 direction = new float3(horizontalInput, 0.0f, verticalInput);
             * e applico l'impulso lineare utilizzando il metodo seguente:
             * PhysicsComponentExtensions.ApplyLinearImpulse(ref velocity, physicsMass, direction * movement.Force
             */
        }).ScheduleParallel();
Exemplo n.º 17
0
        protected override void OnUpdate()
        {
            Dependency.Complete();

            var time = GetEntityQuery(ComponentType.ReadOnly <GlobalGameTime>()).GetSingleton <GlobalGameTime>().gameTime;
            var playerControlledStateFromEntity  = GetComponentDataFromEntity <PlayerControlled.State>(true);
            var characterPredictedDataFromEntity = GetComponentDataFromEntity <Character.PredictedData>(false);
            var characterStartPositionFromEntity = GetComponentDataFromEntity <CharacterControllerMoveQuery>(false);
            var characterVelocityFromEntity      = GetComponentDataFromEntity <CharacterControllerVelocity>(false);
            var predictedFromEntity = GetComponentDataFromEntity <PredictedGhostComponent>(false);
            var PredictingTick      = World.GetExistingSystem <GhostPredictionSystemGroup>().PredictingTick;

            Entities
            .ForEach((ref Ability.EnabledAbility activeAbility, ref Ability.AbilityStateActive stateActive, ref Settings settings, ref PredictedState predictedState) =>
            {
                if (!characterVelocityFromEntity.HasComponent(activeAbility.owner) &&
                    predictedFromEntity.Exists(activeAbility.owner) &&
                    !GhostPredictionSystemGroup.ShouldPredict(PredictingTick, predictedFromEntity[activeAbility.owner]))
                {
                    return;
                }


                var command            = playerControlledStateFromEntity[activeAbility.owner].command;
                var charPredictedState = characterPredictedDataFromEntity[activeAbility.owner];

                var startPosition           = characterStartPositionFromEntity[activeAbility.owner];
                startPosition.StartPosition = charPredictedState.position;
                characterStartPositionFromEntity[activeAbility.owner] = startPosition;

                var phaseDuration = time.DurationSinceTick(predictedState.locoStartTick);

                if (phaseDuration >= settings.dashDuration)
                {
                    stateActive.requestCooldown = true;
                    return;
                }
                //GameDebug.Log($"{predictedState.locoStartTick} :: {time.tick}");
                var velocity = predictedState.startVelocity;
                if (predictedState.locoStartTick + 1 == time.tick)
                {
                    var dashVel                  = settings.dashDistance / settings.dashDuration;
                    var moveYawRotation          = Quaternion.Euler(0, command.lookYaw + command.moveYaw, 0);
                    var moveVec                  = moveYawRotation * Vector3.forward;
                    velocity                     = moveVec * dashVel;
                    velocity.y                   = 0f;
                    predictedState.startVelocity = velocity;
                    //GameDebug.Log($"predictedState.startVelocity {predictedState.startVelocity}");
                }

                var oldVel      = characterVelocityFromEntity[activeAbility.owner];
                oldVel.Velocity = velocity;
                characterVelocityFromEntity[activeAbility.owner] = oldVel;
            }).Run();
        }
Exemplo n.º 18
0
        protected override void OnUpdate()
        {
            var barrier   = m_Barrier.CreateCommandBuffer().ToConcurrent();
            var group     = World.GetExistingSystem <GhostPredictionSystemGroup>();
            var tick      = group.PredictingTick;
            var deltaTime = Time.DeltaTime;


            Entities
            .WithBurst()
            .ForEach((Entity entity, int entityInQueryIndex, DynamicBuffer <PlayerInput> inputBuffer, ref PhysicsVelocity v, ref PredictedGhostComponent prediction, in Translation t, in PlayerTag player) =>
            {
                if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction))
                {
                    return;
                }

                Player.PlayerInput input;
                inputBuffer.GetDataAtTick(tick, out input);

                if (input.Left)
                {
                    v.Linear.x = player.speed;
                }
                if (input.Right)
                {
                    v.Linear.x = -player.speed;
                }

                if (input.Up)
                {
                    v.Linear.y = player.jumpForce;
                }

                //if (input.Down)
                // t.Value.y -= speed;

                if (input.Shoot)
                {
                    /*Debug.DrawLine(t.Value, (Vector3)t.Value + new Vector3(0, 1, 0), Color.red);
                     * Debug.DrawLine(t.Value, (Vector3)t.Value + new Vector3(0, -1, 0), Color.red);
                     * Debug.DrawLine(t.Value, (Vector3)t.Value + new Vector3(1, 0, 0), Color.red);
                     * Debug.DrawLine(t.Value, (Vector3)t.Value + new Vector3(-1, 0, 0), Color.red);*/

                    var stencilEntity = barrier.CreateEntity(entityInQueryIndex);
                    barrier.AddComponent(entityInQueryIndex, stencilEntity, new VoxelStencilInput
                    {
                        centerX  = t.Value.x,
                        centerY  = t.Value.y,
                        fillType = false,
                        radius   = 1f,
                        shape    = VoxelShape.Circle
                    });
                }
            }).ScheduleParallel();
    protected override void OnCreate()
    {
        //This will grab the BeginSimulationEntityCommandBuffer system to be used in OnUpdate
        m_BeginSimEcb = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>();

        //This will grab the BeginSimulationEntityCommandBuffer system to be used in OnUpdate
        m_PredictionGroup = World.GetOrCreateSystem <GhostPredictionSystemGroup>();

        //We check to ensure GameSettingsComponent exists to know if the SubScene has been streamed in
        //We need the SubScene for actions in our OnUpdate()
        RequireSingletonForUpdate <GameSettingsComponent>();
    }
Exemplo n.º 20
0
        protected override void OnUpdate()
        {
            var predictionGroup = World.GetExistingSystem <GhostPredictionSystemGroup>();
            var tick            = predictionGroup.PredictingTick;
            var deltaTime       = Time.DeltaTime;

            Entities.WithAll <BulletTagComponent>().ForEach((ref Translation position, in PredictedGhostComponent prediction, in Velocity velocity) =>
            {
                if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction))
                {
                    return;
                }
                position.Value.xy += velocity.Value * deltaTime;
            }).ScheduleParallel();
    protected override void OnUpdate()
    {
        var deltaTime   = m_PredictionGroup.Time.DeltaTime;
        var currentTick = m_PredictionGroup.PredictingTick;

        Entities
        .ForEach((ref Translation position, in VelocityComponent velocity, in PredictedGhostComponent prediction) =>
        {
            if (!GhostPredictionSystemGroup.ShouldPredict(currentTick, prediction))
            {
                return;
            }

            position.Value.xyz += velocity.Linear * deltaTime;
        }).ScheduleParallel();
    protected override void OnUpdate()
    {
        var group = World.GetExistingSystem <GhostPredictionSystemGroup>();
        var tick  = group.PredictingTick;

        Entities.ForEach((ref ServerPuckData puck, ref PhysicsVelocity vel, ref PredictedGhostComponent prediction) =>
        {
            if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction))
            {
                return;
            }

            LimitPuckVelocitySystem.SetVel(ref vel);
        });
    }
    protected override void OnCreate()
    {
        m_GhostUpdateSystemGroup = World.GetOrCreateSystem <GhostUpdateSystemGroup>();
        m_ghostEntityMap         = m_GhostUpdateSystemGroup.GhostEntityMap;
#if UNITY_EDITOR || DEVELOPMENT_BUILD
        m_ghostMinMaxSnapshotTick = m_GhostUpdateSystemGroup.GhostSnapshotTickMinMax;
#endif
        m_ClientSimulationSystemGroup = World.GetOrCreateSystem <ClientSimulationSystemGroup>();
        m_GhostPredictionSystemGroup  = World.GetOrCreateSystem <GhostPredictionSystemGroup>();
        m_interpolatedQuery           = GetEntityQuery(new EntityQueryDesc
        {
            All = new [] {
                ComponentType.ReadWrite <Char_TerraformerSnapshotData>(),
                ComponentType.ReadOnly <GhostComponent>(),
                ComponentType.ReadWrite <Character.InterpolatedData>(),
                ComponentType.ReadWrite <Character.ReplicatedData>(),
                ComponentType.ReadWrite <CharacterControllerGroundSupportData>(),
                ComponentType.ReadWrite <CharacterControllerMoveResult>(),
                ComponentType.ReadWrite <CharacterControllerVelocity>(),
                ComponentType.ReadWrite <HealthStateData>(),
                ComponentType.ReadWrite <Inventory.State>(),
                ComponentType.ReadWrite <Player.OwnerPlayerId>(),
                ComponentType.ReadWrite <PlayerControlled.State>(),
                ComponentType.ReadOnly <LinkedEntityGroup>(),
            },
            None = new [] { ComponentType.ReadWrite <PredictedGhostComponent>() }
        });
        m_predictedQuery = GetEntityQuery(new EntityQueryDesc
        {
            All = new [] {
                ComponentType.ReadOnly <Char_TerraformerSnapshotData>(),
                ComponentType.ReadOnly <GhostComponent>(),
                ComponentType.ReadOnly <PredictedGhostComponent>(),
                ComponentType.ReadWrite <Character.PredictedData>(),
                ComponentType.ReadWrite <Character.ReplicatedData>(),
                ComponentType.ReadWrite <CharacterControllerGroundSupportData>(),
                ComponentType.ReadWrite <CharacterControllerMoveResult>(),
                ComponentType.ReadWrite <CharacterControllerVelocity>(),
                ComponentType.ReadWrite <HealthStateData>(),
                ComponentType.ReadWrite <Inventory.State>(),
                ComponentType.ReadWrite <Player.OwnerPlayerId>(),
                ComponentType.ReadWrite <PlayerControlled.State>(),
                ComponentType.ReadOnly <LinkedEntityGroup>(),
            }
        });
        RequireForUpdate(GetEntityQuery(ComponentType.ReadWrite <Char_TerraformerSnapshotData>(),
                                        ComponentType.ReadOnly <GhostComponent>()));
    }
Exemplo n.º 24
0
    protected override void OnUpdate()
    {
        var group = World.GetExistingSystem <GhostPredictionSystemGroup>();
        var tick  = group.PredictingTick;

        Entities.ForEach((DynamicBuffer <CharacterSyncData> inputBuffer, ref MovableComponent movable, ref LookRotationComponent rotatable, ref PredictedGhostComponent prediction) =>
        {
            if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction))
            {
                return;
            }
            inputBuffer.GetDataAtTick(tick, out CharacterSyncData input);
            //这里只需要将数据进行更改
            movable.Direction = rotatable.Direction = new float3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
        });
    }
Exemplo n.º 25
0
    protected override void OnUpdate()
    {
        var group = World.GetExistingSystem <GhostPredictionSystemGroup>();
        var tick  = group.PredictingTick;

        var deltaTime     = Time.DeltaTime;
        var entityManager = EntityManager;

        Entities.ForEach((Entity ent, DynamicBuffer <PilotInput> inputBuffer, ref PredictedGhostComponent prediction, in CameraRigChild cameraRigChild) =>
        {
            if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction))
            {
                return;
            }
            inputBuffer.GetDataAtTick(tick, out PilotInput input);

            entityManager.SetComponentData(ent, new CameraRigChild {
                Value         = cameraRigChild.Value,
                headPose      = input.head.positon,
                headRot       = input.head.rotation,
                leftHandPose  = input.leftHand.positon,
                leftHandRot   = input.leftHand.rotation,
                rightHandPose = input.rightHand.positon,
                rightHandRot  = input.rightHand.rotation
            });
            var cameraRig = entityManager.GetComponentData <CameraRigData>(cameraRigChild.Value);
            entityManager.SetComponentData(cameraRig.head, new Translation {
                Value = cameraRigChild.headPose
            });
            entityManager.SetComponentData(cameraRig.head, new Rotation {
                Value = cameraRigChild.headRot
            });
            entityManager.SetComponentData(cameraRig.leftHand, new Translation {
                Value = cameraRigChild.leftHandPose
            });
            entityManager.SetComponentData(cameraRig.leftHand, new Rotation {
                Value = cameraRigChild.leftHandRot
            });
            entityManager.SetComponentData(cameraRig.rightHand, new Translation {
                Value = cameraRigChild.rightHandPose
            });
            entityManager.SetComponentData(cameraRig.rightHand, new Rotation {
                Value = cameraRigChild.rightHandRot
            });
        }).Run();
    }
Exemplo n.º 26
0
        protected override void OnUpdate()
        {
            var group = World.GetExistingSystem <GhostPredictionSystemGroup>();
            var tick  = group.PredictingTick;

            Entities
            .WithBurst()
            .ForEach((DynamicBuffer <Player.PlayerInput> inputBuffer, ref SpriteInformation sd, ref PredictedGhostComponent prediction) =>
            {
                if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction))
                {
                    return;
                }

                Player.PlayerInput input;
                inputBuffer.GetDataAtTick(tick, out input);

                if (input.Left && input.Right)
                {
                    sd.animation = 0;
                }
                else if (input.Left)
                {
                    sd.direction = SpriteInformation.Direction.LEFT;
                    sd.animation = 1;
                }
                else if (input.Right)
                {
                    sd.direction = SpriteInformation.Direction.RIGHT;
                    sd.animation = 1;
                }
                else
                {
                    sd.animation = 0;
                }

                if (input.Down && input.Up)
                {
                    sd.animation = 0;
                }
                else if (input.Down || input.Up)
                {
                    sd.animation = 1;
                }
            }).ScheduleParallel();
        }
Exemplo n.º 27
0
        protected override void OnUpdate()
        {
            if (!s_IsEnabled)
            {
                return;
            }
            var tick      = m_GhostPredictionSystemGroup.PredictingTick;
            var deltaTime = Time.DeltaTime;

            Entities.ForEach((ref Translation trans, in PredictedGhostComponent predictedGhost) => {
                if (!GhostPredictionSystemGroup.ShouldPredict(tick, predictedGhost))
                {
                    return;
                }
                // Make sure we advance by one unit per tick, makes it easier to debug the values
                trans.Value.x += deltaTime * 60.0f;
            }).ScheduleParallel();
        }
    protected override void OnUpdate()
    {
        var group = World.GetExistingSystem <GhostPredictionSystemGroup> ();
        var tick  = group.PredictingTick;

        var projectiles         = projectileQuery.ToEntityArray(Allocator.TempJob);
        var projectilePositions = projectileQuery.ToComponentDataArray <Translation> (Allocator.TempJob);
        var projectileId        = projectileQuery.ToComponentDataArray <ProjectileComponent> (Allocator.TempJob);

        Entities.ForEach((ref Translation trans, ref MovableCubeComponent cube, ref PredictedGhostComponent prediction) => {
            if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediction))
            {
                return;
            }

            Rectangle rect = new Rectangle {
                x = trans.Value.x - 0.5f, y = trans.Value.z - 0.5f, width = 1, height = 1
            };

            for (var j = 0; j < projectiles.Length; j++)
            {
                if (projectileId[j].playerId != cube.PlayerId)
                {
                    Circle circle = new Circle {
                        x = projectilePositions[j].Value.x, y = projectilePositions[j].Value.z, radius = 0.5f
                    };
                    if (CircleToRectangle(circle, rect))
                    {
                        // UI.Instance.updatePlayerScore (cube.PlayerId);
                        // Death
                        trans.Value = new float3(0, 0.5f, 0);
                        PostUpdateCommands.SetComponent(projectiles[j], new Translation {
                            Value = new float3(100, 0, 100)
                        });
                    }
                }
            }
        });

        projectiles.Dispose();
        projectilePositions.Dispose();
        projectileId.Dispose();
    }
        protected override void OnUpdate()
        {
            var tick = predictionGroup.PredictingTick;

            Entities
            .ForEach((Entity entity, ref Translation translation, in DynamicBuffer <TestInput> inputBuffer, in PredictedGhostComponent
                      prediciton) =>
            {
                if (!GhostPredictionSystemGroup.ShouldPredict(tick, prediciton))
                {
                    return;
                }

                if (!inputBuffer.GetDataAtTick(tick, out var input))
                {
                    return;
                }

                translation.Value.y += 1.0f * input.Value;
            }).Run();
    protected override void OnCreate()
    {
        m_GhostUpdateSystemGroup = World.GetOrCreateSystem <GhostUpdateSystemGroup>();
        m_ghostEntityMap         = m_GhostUpdateSystemGroup.GhostEntityMap;
#if UNITY_EDITOR || DEVELOPMENT_BUILD
        m_ghostMinMaxSnapshotTick = m_GhostUpdateSystemGroup.GhostSnapshotTickMinMax;
#endif
        m_ClientSimulationSystemGroup = World.GetOrCreateSystem <ClientSimulationSystemGroup>();
        m_GhostPredictionSystemGroup  = World.GetOrCreateSystem <GhostPredictionSystemGroup>();
        m_interpolatedQuery           = GetEntityQuery(new EntityQueryDesc
        {
            All = new [] {
                ComponentType.ReadWrite <__GHOST_NAME__SnapshotData>(),
                ComponentType.ReadOnly <GhostComponent>(),
                #region __GHOST_INTERPOLATED_COMPONENT_TYPE__
                ComponentType.ReadWrite <__GHOST_COMPONENT_TYPE__>(),
                #endregion
                #region __GHOST_INTERPOLATED_READ_ONLY_COMPONENT_TYPE__
                ComponentType.ReadOnly <__GHOST_COMPONENT_TYPE__>(),
                #endregion
            },
            None = new [] { ComponentType.ReadWrite <PredictedGhostComponent>() }
        });
        m_predictedQuery = GetEntityQuery(new EntityQueryDesc
        {
            All = new [] {
                ComponentType.ReadOnly <__GHOST_NAME__SnapshotData>(),
                ComponentType.ReadOnly <GhostComponent>(),
                ComponentType.ReadOnly <PredictedGhostComponent>(),
                #region __GHOST_PREDICTED_COMPONENT_TYPE__
                ComponentType.ReadWrite <__GHOST_COMPONENT_TYPE__>(),
                #endregion
                #region __GHOST_PREDICTED_READ_ONLY_COMPONENT_TYPE__
                ComponentType.ReadOnly <__GHOST_COMPONENT_TYPE__>(),
                #endregion
            }
        });
        RequireForUpdate(GetEntityQuery(ComponentType.ReadWrite <__GHOST_NAME__SnapshotData>(),
                                        ComponentType.ReadOnly <GhostComponent>()));
    }