public override void Update() { this.TimeNow = (uint)(TimeHelper.ClientNowMilliSeconds() - this.StartTime); this.Recv(); this.TimerOut(); foreach (long id in updateChannels) { KChannel kChannel = this.GetKChannel(id); if (kChannel == null) { continue; } if (kChannel.Id == 0) { continue; } kChannel.Update(); } this.updateChannels.Clear(); while (this.removedChannels.Count > 0) { long id = this.removedChannels.Dequeue(); KChannel channel; if (!this.localConnChannels.TryGetValue(id, out channel)) { continue; } this.localConnChannels.Remove(id); channel.Dispose(); } }
public void TeamLeaderRun() { if (RoomEntity != null && RoomEntity.State == RoomState.Start) { RoomRunLoadingOutTimeMs = TimeHelper.ClientNowMilliSeconds() + RoomRunLoadingMaxTimeMs; RoomEntity.SwitchState(RoomState.Run); } }
public void Update() { EvaluateDeltaTime(); if (this.timeId.Count == 0) { return; } long timeNow = TimeHelper.ClientNowMilliSeconds(); if (timeNow < this.minTime) { return; } foreach (KeyValuePair <long, List <long> > kv in this.timeId.GetDictionary()) { long k = kv.Key; if (k > timeNow) { minTime = k; break; } this.timeOutTime.Enqueue(k); } while (this.timeOutTime.Count > 0) { long time = this.timeOutTime.Dequeue(); foreach (long timerId in this.timeId[time]) { this.timeOutTimerIds.Enqueue(timerId); } this.timeId.Remove(time); } while (this.timeOutTimerIds.Count > 0) { long timerId = this.timeOutTimerIds.Dequeue(); Timer timer; if (!this.timers.TryGetValue(timerId, out timer)) { continue; } this.timers.Remove(timerId); timer.tcs.SetResult(); } }
/// <summary> /// 等待指定(毫秒) /// </summary> /// <param name="time"></param> /// <returns></returns> public ETTask WaitForMilliSecondAsync(long time) { ETTaskCompletionSource tcs = new ETTaskCompletionSource(); Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = TimeHelper.ClientNowMilliSeconds() + time, tcs = tcs }; this.timers[timer.Id] = timer; this.timeId.Add(timer.Time, timer.Id); if (timer.Time < this.minTime) { this.minTime = timer.Time; } return(tcs.Task); }
public ETTask WaitAsync(long time, CancellationToken cancellationToken) { ETTaskCompletionSource tcs = new ETTaskCompletionSource(); Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = TimeHelper.ClientNowMilliSeconds() + time, tcs = tcs }; this.timers[timer.Id] = timer; this.timeId.Add(timer.Time, timer.Id); if (timer.Time < this.minTime) { this.minTime = timer.Time; } cancellationToken.Register(() => { this.Remove(timer.Id); }); return(tcs.Task); }
public KService() { this.StartTime = TimeHelper.ClientNowMilliSeconds(); this.TimeNow = (uint)(TimeHelper.ClientNowMilliSeconds() - this.StartTime); this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); //this.socket.Blocking = false; this.socket.Bind(new IPEndPoint(IPAddress.Any, 0)); #if SERVER if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { const uint IOC_IN = 0x80000000; const uint IOC_VENDOR = 0x18000000; uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12; this.socket.IOControl((int)SIO_UDP_CONNRESET, new[] { Convert.ToByte(false) }, null); } #endif Instance = this; }
public override void Update() { this.TimeNow = (uint)(TimeHelper.ClientNowMilliSeconds() - this.StartTime); this.Recv(); foreach (var kv in this.localConnChannels) { kv.Value.Update(); } while (this.removedChannels.Count > 0) { long id = this.removedChannels.Dequeue(); KChannel channel; if (!this.localConnChannels.TryGetValue(id, out channel)) { continue; } this.localConnChannels.Remove(id); channel.Dispose(); } }