public BulletStateData GetNextFrameData(BulletInputData inputData, BulletStateData currentState)
    {
        velocity = new Vector3(inputData.MovementAxes.x, 0, inputData.MovementAxes.y) * movementSpeed * Time.fixedDeltaTime;

        Controller.Move(velocity);

        return(new BulletStateData(currentState.Id, currentState.PlayerId, inputData.InputTick, transform.localPosition));
    }
    internal void ResetTo(BulletStateData stateData)
    {
        Controller.enabled = false;

        transform.localPosition = stateData.Position;

        Controller.enabled = true;
    }
Ejemplo n.º 3
0
    public BulletStateData Go(BulletSpawnData spawnData)
    {
        //Debug.Log($"bullet {Id} Go");

        BulletState = new BulletStateData(Id, PlayerId, 0, spawnData.Position);
        bulletController.ResetTo(BulletState);

        Owner.AddBullet(this);

        return(BulletState);
    }
Ejemplo n.º 4
0
    public BulletStateData BulletUpdate()
    {
        inputsToProcess = inputBuffer.Get();
        foreach (var input in inputsToProcess)
        {
            InputTick   = input.InputTick;
            BulletState = bulletController.GetNextFrameData(input, BulletState);
        }

        transform.localPosition = BulletState.Position;

        return(BulletState);
    }
    internal void UpdateBulletState(BulletStateData stateData)
    {
        if (!isInitialized)
        {
            return;
        }
        if (!isLocal)
        {
            interpolation.PushStateData(stateData);
            return;
        }

        while (history.Count > 0 && history.Peek().InputTick < stateData.InputTick)
        {
            history.Dequeue();
        }

        if (history.Count == 0)
        {
            return;
        }

        if (history.Peek().InputTick != stateData.InputTick)
        {
            return;
        }

        var predictedState = history.Dequeue();

        if ((predictedState.StateData.Position - stateData.Position).sqrMagnitude < reconciliationTolerance)
        {
            return;
        }

        //Debug.Log($"start reconciliation for frame {predictedState.InputTick}");
        //Debug.Log($"predicted position: {predictedState.StateData.Position}\nserver position: {stateData.Position}");

        interpolation.CurrentStateData = stateData;

        var h = history.ToArray();

        foreach (var ri in h)
        {
            //Debug.Log($"applying input {ri.InputTick}: {ri.InputData.MovementAxes}");
            bulletController.ResetTo(interpolation.CurrentStateData);
            var sd = bulletController.GetNextFrameData(ri.InputData, interpolation.CurrentStateData);
            interpolation.PushStateData(sd);
            //Debug.Log($"moved from {interpolation.PreviousStateData.Position} to {interpolation.CurrentStateData.Position}");
        }
    }
Ejemplo n.º 6
0
    private void FixedUpdate()
    {
        if (!IsRunning)
        {
            return;
        }

        ServerTick++;

        foreach (var p in serverPlayers)
        {
            p.PlayerPreUpdate();
        }

        // player states updaten
        for (int i = 0; i < serverPlayers.Count; i++)
        {
            var p = serverPlayers[i];
            playerStates[i] = p.PlayerUpdate();
        }

        // bullet states updaten
        for (int i = 0; i < serverBullets.Count; i++)
        {
            var b = serverBullets[i];
            bulletStates[b.Id] = b.BulletUpdate();
        }

        // updates an alle clients schicken
        var playerStateUpdates = playerStates.ToArray();
        var despawnDataUpdates = playerDespawns.ToArray();

        var bulletStateUpdates = new BulletStateData[bulletStates.Count];

        bulletStates.Values.CopyTo(bulletStateUpdates, 0);

        var bulletDespawnUpdates = bulletDespawns.ToArray();

        foreach (var p in serverPlayers)
        {
            var updateData = new GameUpdateData(
                p.InputTick,
                playerStateUpdates, despawnDataUpdates,
                bulletStateUpdates, bulletDespawnUpdates
                );

            //Debug.Log($"sending update: {updateData.Frame}");

            using (var msg = Message.Create((ushort)MessageTag.GameUpdate, updateData)) {
                p.Client.SendMessage(msg, SendMode.Reliable);
            }
        }

        // bullets für den nächsten frame initialisieren
        while (requestedBullets.Count > 0)
        {
            var bullet = requestedBullets.Dequeue();
            SpawnBullet(bullet);
        }

        playerDespawns.Clear();

        bulletDespawns.Clear();
    }
Ejemplo n.º 7
0
 public BulletReconciliationInfo(uint inputTick, BulletStateData stateData, BulletInputData inputData)
 {
     InputTick = inputTick;
     StateData = stateData;
     InputData = inputData;
 }