Exemple #1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var playerJob = new PlayerInputJob();

            playerJob.left            = 0;
            playerJob.right           = 0;
            playerJob.thrust          = 0;
            playerJob.shoot           = 0;
            playerJob.commandBuffer   = m_Barrier.CreateCommandBuffer().ToConcurrent();
            playerJob.inputFromEntity = GetBufferFromEntity <ShipCommandData>();
            playerJob.inputTargetTick = m_GhostPredict.PredictingTick;

            if (World.GetExistingSystem <ClientPresentationSystemGroup>().Enabled)
            {
                if (Input.GetKey("left"))
                {
                    playerJob.left = 1;
                }
                if (Input.GetKey("right"))
                {
                    playerJob.right = 1;
                }
                if (Input.GetKey("up"))
                {
                    playerJob.thrust = 1;
                }
                //if (InputSamplerSystem.spacePresses > 0)
                if (Input.GetKey("space"))
                {
                    playerJob.shoot = 1;
                }
            }
            else
            {
                // Spawn and generate some random inputs
                var state = (int)Time.ElapsedTime % 3;
                if (state == 0)
                {
                    playerJob.left = 1;
                }
                else
                {
                    playerJob.thrust = 1;
                }
                ++frameCount;
                if (frameCount % 100 == 0)
                {
                    playerJob.shoot = 1;
                    frameCount      = 0;
                }
            }

            var handle = playerJob.ScheduleSingle(this, inputDeps);

            m_Barrier.AddJobHandleForProducer(handle);
            return(handle);
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var playerJob = new PlayerInputJob();

            playerJob.shipInput   = GetComponentDataFromEntity <PlayerInputComponentData>();
            playerJob.cmdBuffer   = GetBufferFromEntity <IncomingCommandDataStreamBufferComponent>();
            playerJob.currentTick = serverSimulationSystemGroup.ServerTick;
            return(playerJob.ScheduleSingle(this, inputDeps));
        }
Exemple #3
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var playerJob = new PlayerInputJob();

            playerJob.left            = 0;
            playerJob.right           = 0;
            playerJob.thrust          = 0;
            playerJob.shoot           = 0;
            playerJob.shipState       = GetComponentDataFromEntity <ShipStateComponentData>();
            playerJob.rpcQueue        = m_RpcQueue;
            playerJob.rpcBuffer       = GetBufferFromEntity <OutgoingRpcDataStreamBufferComponent>();
            playerJob.cmdBuffer       = GetBufferFromEntity <OutgoingCommandDataStreamBufferComponent>();
            playerJob.ackSnapshot     = GetComponentDataFromEntity <NetworkSnapshotAck>();
            playerJob.localTime       = NetworkTimeSystem.TimestampMS;
            playerJob.inputTargetTick = NetworkTimeSystem.predictTargetTick;

            if (World.GetExistingManager <ClientPresentationSystemGroup>().Enabled)
            {
                if (Input.GetKey("left"))
                {
                    playerJob.left = 1;
                }
                if (Input.GetKey("right"))
                {
                    playerJob.right = 1;
                }
                if (Input.GetKey("up"))
                {
                    playerJob.thrust = 1;
                }
                if (InputSamplerSystem.spacePresses > 0)
                {
                    //if (Input.GetKey("space"))
                    playerJob.shoot = 1;
                }
            }
            else
            {
                // Spawn and generate some random inputs
                var state = (int)Time.fixedTime % 3;
                if (state == 0)
                {
                    playerJob.left = 1;
                }
                else
                {
                    playerJob.thrust = 1;
                }
                if (Time.frameCount % 100 == 0)
                {
                    playerJob.shoot = 1;
                }
            }

            return(playerJob.ScheduleSingle(this, inputDeps));
        }
Exemple #4
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var playerJob = new PlayerInputJob();

        playerJob.shoot = 0;

        playerJob.commandBuffer   = m_Barrier.CreateCommandBuffer().ToConcurrent();
        playerJob.inputFromEntity = GetBufferFromEntity <TestCommandData>();
        playerJob.inputTargetTick = m_GhostPredict.PredictingTick;

        if (Input.GetKeyDown("g"))
        {
            Debug.Log("g pressed");
            playerJob.shoot = 1;
        }

        var handle = playerJob.ScheduleSingle(this, inputDeps);

        m_Barrier.AddJobHandleForProducer(handle);
        return(handle);
    }
Exemple #5
0
        } // PlayerInputJob

        /// <summary>
        /// Each frame, this input system will sample player input, save it to a PlayerInputJob
        /// data structure, and schedule it to be processed later by the BeginSimulationEntityCommandBufferSystem
        /// </summary>
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var playerJob = new PlayerInputJob();

            playerJob.left   = 0;
            playerJob.right  = 0;
            playerJob.thrust = 0;
            playerJob.shoot  = 0;

            // More boilerplately stuff I honestly haven't been able to wrap my head around.
            playerJob.commandBuffer   = m_Barrier.CreateCommandBuffer().ToConcurrent();
            playerJob.inputFromEntity = GetBufferFromEntity <ShipCommandData>();
            playerJob.inputTargetTick = m_GhostPredict.PredictingTick;

            // Sample keyboard inputs only if the presentation group is active,
            // aka only take input if we're rendering (not tabbed out or anything)
            if (World.GetExistingSystem <ClientPresentationSystemGroup>().Enabled)
            {
                if (Input.GetKey("left"))
                {
                    playerJob.left = 1;
                }
                if (Input.GetKey("right"))
                {
                    playerJob.right = 1;
                }
                if (Input.GetKey("up"))
                {
                    playerJob.thrust = 1;
                }
                //if (InputSamplerSystem.spacePresses > 0) // This is commented out in the sample project! See comments on the InputSamplerSystem.
                if (Input.GetKey("space"))
                {
                    playerJob.shoot = 1;
                }
            }

            // FOR THIS SAMPLE GAME (never would we do this in our own game), random inputs are
            // generated for clients that are tabbed out. This is again just for demonstration
            // purposes so there's more happening when you demo it.
            else
            {
                // Spawn and generate some random inputs
                var state = (int)Time.ElapsedTime % 3;
                if (state == 0)
                {
                    playerJob.left = 1;
                }
                else
                {
                    playerJob.thrust = 1;
                }
                ++frameCount;
                if (frameCount % 100 == 0)
                {
                    playerJob.shoot = 1;
                    frameCount      = 0;
                }
            }

            // ... input has been sampled!

            var handle = playerJob.ScheduleSingle(this, inputDeps);

            m_Barrier.AddJobHandleForProducer(handle);
            return(handle);
        }