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)); }
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]); } } } }
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(); }
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(); }
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)); }
public static IDisposable OnReverse(this INetworkTimeline timeline, Action <IUserInputResult[]> onNext) { Action <ReverseTimelineData> action = data => { onNext(data.UserInputResult); }; return(timeline.OnReverse(action)); }
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); }
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)); }
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; }
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); }
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; }
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(); } }
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(); } }
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); } } } }
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(); }
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]); } } } }
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); }
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)); }