Ejemplo n.º 1
0
    private int PushUntilLastStep(IEntity entity, Type[] inputTypes, INetworkTimeline timeline)
    {
        var networkIdentityComponent = entity.GetComponent <NetworkIdentityComponent>();
        var identity          = networkIdentityComponent.Identity;
        var timePointWithLerp = timePointWithLerpDict[identity][timeline];
        var tickId            = timePointWithLerp.TickId;

        if (tickId < networkIdentityComponent.TickIdWhenCreated)
        {
            tickId = networkIdentityComponent.TickIdWhenCreated;
        }
        if (!timePointWithLerp.IsPlaying)
        {
            while (LockstepUtility.HasTickId(tickId))
            {
                var userInputData = GetUserInputDataByInputTypes(tickId, identity.UserId, inputTypes);
                for (int i = 0; i < userInputData.Length; i++)
                {
                    timePointWithLerp.AddRealtimeData(new TimePointData(tickId, LockstepUtility.GetDeltaTime(tickId), userInputData[i]));
                }
                tickId++;
            }
        }
        timePointWithLerp.TickId = tickId;
        return(tickId);
    }
 public override void Initialize(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory, PrefabFactory prefabFactory)
 {
     base.Initialize(eventSystem, poolManager, groupFactory, prefabFactory);
     Network           = LockstepFactory.Create(priority: (int)LockstepSettings.Priority.Debug);
     NetwrokTimeline   = Network.CreateTimeline(typeof(EventInput));
     NetworkIdentities = this.Create(typeof(NetworkIdentityComponent), typeof(ViewComponent));
 }
Ejemplo n.º 3
0
    private void ApplyTimePoint(IEntity entity, INetworkTimeline timeline)
    {
        var networkIdentityComponent = entity.GetComponent <NetworkIdentityComponent>();
        var identity          = networkIdentityComponent.Identity;
        var timePointWithLerp = timePointWithLerpDict[identity][timeline];
        var timePoints        = timePointWithLerp.TimePoints;
        var from = timePointWithLerp.From;
        var to   = timePointWithLerp.To;

        for (int i = 0; i < timePoints.Count; i++)
        {
            if (networkIdentityComponent.TickIdWhenCreated < 0 || networkIdentityComponent.TickIdWhenCreated > timePoints[i].TickId)
            {
                continue;
            }
            var duration = timePoints[i].Duration;
            var result   = DoForward(timeline, entity, timePoints[i], from, to, duration, i / (float)timePoints.Count);
            if (result != null && timePoints[i].ForecastCount > 0)
            {
                for (int j = 0; j < result.Count; j++)
                {
                    timePointWithLerp.RollbackData.Add(result[j]);
                }
            }
        }
    }
Ejemplo n.º 4
0
    private void UpdateTimeline(IEntity entity, Type[] inputTypes, INetworkTimeline timeline)
    {
        var networkIdentityComponent = entity.GetComponent <NetworkIdentityComponent>();
        var identity = networkIdentityComponent.Identity;

        if (!timePointWithLerpDict.ContainsKey(identity))
        {
            timePointWithLerpDict.Add(identity, new Dictionary <INetworkTimeline, TimePointWithLerp>());
        }
        if (!timePointWithLerpDict[identity].ContainsKey(timeline))
        {
            timePointWithLerpDict[identity].Add(timeline, new TimePointWithLerp());
        }
        var timePointWithLerp = timePointWithLerpDict[identity][timeline];

        timePointWithLerp.Begin(Time.deltaTime, FixedDeltaTime);

        PushUntilLastStep(entity, inputTypes, timeline);

        Rollback(entity, timeline);

        Forecast(identity, inputTypes, timeline);

        ApplyTimePoint(entity, timeline);

        timePointWithLerp.End();
    }
Ejemplo n.º 5
0
 public override void Initialize(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory, PrefabFactory prefabFactory)
 {
     base.Initialize(eventSystem, poolManager, groupFactory, prefabFactory);
     BulletComponents = this.Create(typeof(BulletComponent), typeof(NetworkIdentityComponent), typeof(ViewComponent), typeof(CapsuleCollider));
     Network          = LockstepFactory.Create(BulletComponents, usePhysics: true);
     NetwrokTimeline  = Network.CreateTimeline(typeof(EventInput));
     InitializeMaterials();
 }
Ejemplo n.º 6
0
 public override void Initialize(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory, PrefabFactory prefabFactory)
 {
     base.Initialize(eventSystem, poolManager, groupFactory, prefabFactory);
     UserComponents          = this.Create(typeof(UserComponent), typeof(ViewComponent));
     NetworkPlayerComponents = this.Create(typeof(NetworkPlayerComponent), typeof(NetworkIdentityComponent));
     Network         = LockstepFactory.Create();
     NetwrokTimeline = Network.CreateTimeline(typeof(EventInput));
 }
Ejemplo n.º 7
0
    public static IDisposable OnReverse(this INetworkTimeline timeline, Action <IUserInputResult[]> onNext)
    {
        Action <ReverseTimelineData> action = data =>
        {
            onNext(data.UserInputResult);
        };

        return(timeline.OnReverse(action));
    }
Ejemplo n.º 8
0
 private List <IUserInputResult[]> DoForward(INetworkTimeline timeline, IEntity entity, TimePointData timePoint, float from, float to, Fix64 deltaTime, float t)
 {
     if (t >= from && t <= to)
     {
         timePoint.DeltaTime = deltaTime;
         return(timeline.Forward(new ForwardTimelineData(entity, timePoint)));
     }
     return(null);
 }
Ejemplo n.º 9
0
    public static IDisposable OnForward(this INetworkTimeline timeline, Func <IEntity, UserInputData[], Fix64, IUserInputResult[]> onNext)
    {
        Func <ForwardTimelineData, IUserInputResult[]> func = data =>
        {
            return(onNext(data.Entity, data.UserInputData[0], data.DeltaTime));
        };

        return(timeline.OnForward(func));
    }
Ejemplo n.º 10
0
    public override void Initialize(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory, PrefabFactory prefabFactory)
    {
        base.Initialize(eventSystem, poolManager, groupFactory, prefabFactory);

        PlayerControlComponents = this.Create(typeof(PlayerControlComponent), typeof(CharacterController), typeof(ViewComponent));
        Network         = LockstepFactory.Create(PlayerControlComponents);
        NetwrokTimeline = Network.CreateTimeline(typeof(AxisInput), typeof(KeyInput), typeof(MouseInput));
        mainCamera      = Camera.main;
    }
Ejemplo n.º 11
0
 public override void Initialize(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory, PrefabFactory prefabFactory)
 {
     base.Initialize(eventSystem, poolManager, groupFactory, prefabFactory);
     ShootComponents = this.Create(typeof(PlayerControlComponent), typeof(NetworkIdentityComponent), typeof(ShootComponent), typeof(Animator), typeof(ViewComponent));
     Network         = LockstepFactory.Create(ShootComponents);
     NetwrokTimeline = Network.CreateTimeline(typeof(MouseInput), typeof(KeyInput), typeof(EventInput));
     BulletDAO       = new BulletDAO(Bullet, NameStr);
     WeaponDAO       = new WeaponDAO(Weapon, NameStr);
 }
Ejemplo n.º 12
0
 public override void Initialize(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory, PrefabFactory prefabFactory)
 {
     base.Initialize(eventSystem, poolManager, groupFactory, prefabFactory);
     ThridPersonCameraComponents = this.Create(typeof(ThridPersonCameraComponent), typeof(CinemachineVirtualCamera), typeof(CinemachineCollider), typeof(ViewComponent));
     PlayerControlComponents     = this.Create(typeof(PlayerControlComponent), typeof(ShootComponent));
     CrosshairComponents         = this.Create(typeof(CrosshairComponent), typeof(ViewComponent));
     Network          = LockstepFactory.Create(PlayerControlComponents);
     NetwrokTimeline  = Network.CreateTimeline(typeof(EventInput));
     Cursor.lockState = CursorLockMode.Locked;
     Cursor.visible   = false;
 }
Ejemplo n.º 13
0
    private void Rollback(INetworkTimeline timeline)
    {
        var timePointWithLerp = defaultTimePointWithLerpDict[timeline];

        if (UseForecast && !timePointWithLerp.IsPlaying && timePointWithLerp.ForecastData.Count > 0 && timePointWithLerp.RealtimeData.Count > 0)
        {
            for (int i = timePointWithLerp.RollbackData.Count - 1; i >= 0; i--)
            {
                timeline.Reverse(new ReverseTimelineData(null, timePointWithLerp.RollbackData[i]));
            }
            timePointWithLerp.RollbackData.Clear();
        }
    }
Ejemplo n.º 14
0
    private void Rollback(IEntity entity, INetworkTimeline timeline)
    {
        var networkIdentityComponent = entity.GetComponent <NetworkIdentityComponent>();
        var identity          = networkIdentityComponent.Identity;
        var timePointWithLerp = timePointWithLerpDict[identity][timeline];

        if (UseForecast && !timePointWithLerp.IsPlaying && timePointWithLerp.ForecastData.Count > 0 && timePointWithLerp.RealtimeData.Count > 0)
        {
            for (int i = timePointWithLerp.RollbackData.Count - 1; i >= 0; i--)
            {
                timeline.Reverse(new ReverseTimelineData(entity, timePointWithLerp.RollbackData[i]));
            }
            timePointWithLerp.RollbackData.Clear();
        }
    }
Ejemplo n.º 15
0
    private void Forecast(Type[] inputTypes, INetworkTimeline timeline)
    {
        var timePointWithLerp = defaultTimePointWithLerpDict[timeline];

        if (UseForecast && !timePointWithLerp.IsPlaying)
        {
            var tickId = timePointWithLerp.TickId - 1;
            if (LockstepUtility.HasTickId(tickId))
            {
                var deltaTime     = LockstepUtility.GetDeltaTime(tickId);
                var userInputData = GetUserInputDataByInputTypes(tickId, inputTypes);
                for (int i = 0; i < userInputData.Length; i++)
                {
                    timePointWithLerp.Forecast(new TimePointData(tickId, deltaTime, userInputData[i]), MaxForecastSteps);
                }
            }
        }
    }
Ejemplo n.º 16
0
    private void UpdateTimeline(Type[] inputTypes, INetworkTimeline timeline)
    {
        if (!defaultTimePointWithLerpDict.ContainsKey(timeline))
        {
            defaultTimePointWithLerpDict.Add(timeline, new TimePointWithLerp());
        }
        var timePointWithLerp = defaultTimePointWithLerpDict[timeline];

        timePointWithLerp.Begin(Time.deltaTime, FixedDeltaTime);

        PushUntilLastStep(inputTypes, timeline);

        Rollback(timeline);

        Forecast(inputTypes, timeline);

        ApplyTimePoint(timeline);

        timePointWithLerp.End();
    }
Ejemplo n.º 17
0
    private void ApplyTimePoint(INetworkTimeline timeline)
    {
        var timePointWithLerp = defaultTimePointWithLerpDict[timeline];
        var timePoints        = timePointWithLerp.TimePoints;
        var from = timePointWithLerp.From;
        var to   = timePointWithLerp.To;

        for (int i = 0; i < timePoints.Count; i++)
        {
            var duration = timePoints[i].Duration;
            var result   = DoForward(timeline, null, timePoints[i], from, to, duration, i / (float)timePoints.Count);
            if (result != null && timePoints[i].ForecastCount > 0)
            {
                for (int j = 0; j < result.Count; j++)
                {
                    timePointWithLerp.RollbackData.Add(result[j]);
                }
            }
        }
    }
Ejemplo n.º 18
0
    private int PushUntilLastStep(Type[] inputTypes, INetworkTimeline timeline)
    {
        var timePointWithLerp = defaultTimePointWithLerpDict[timeline];
        var tickId            = timePointWithLerp.TickId;

        if (!timePointWithLerp.IsPlaying)
        {
            while (LockstepUtility.HasTickId(tickId))
            {
                var userInputData = GetUserInputDataByInputTypes(tickId, inputTypes);
                for (int i = 0; i < userInputData.Length; i++)
                {
                    timePointWithLerp.AddRealtimeData(new TimePointData(tickId, LockstepUtility.GetDeltaTime(tickId), userInputData[i]));
                }
                tickId++;
            }
        }
        timePointWithLerp.TickId = tickId;
        return(tickId);
    }
Ejemplo n.º 19
0
 public override void Initialize(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory, PrefabFactory prefabFactory)
 {
     base.Initialize(eventSystem, poolManager, groupFactory, prefabFactory);
     Network         = LockstepFactory.Create();
     NetwrokTimeline = Network.CreateTimeline(typeof(EventInput));
 }