public LogicLooperActionContext(LogicLooper looper, long currentFrame, TimeSpan elapsedTimeFromPreviousFrame, CancellationToken cancellationToken) { Looper = looper ?? throw new ArgumentNullException(nameof(looper)); CurrentFrame = currentFrame; ElapsedTimeFromPreviousFrame = elapsedTimeFromPreviousFrame; CancellationToken = cancellationToken; }
/// <inheritdoc /> public Task RegisterActionAsync(LogicLooperActionDelegate loopAction) { var action = new LogicLooper.LooperAction(LogicLooper.DelegateHelper.GetWrapper(), loopAction, default); lock (_actions) { _actions.Add(action); } return(action.Future.Task); }
/// <summary> /// Initialize the looper pool with specified configurations. /// </summary> /// <param name="targetFrameTime"></param> /// <param name="looperCount"></param> /// <param name="balancer"></param> public LogicLooperPool(TimeSpan targetFrameTime, int looperCount, ILogicLooperPoolBalancer balancer) { if (looperCount <= 0) { throw new ArgumentOutOfRangeException(nameof(looperCount), "LooperCount must be more than zero."); } _loopers = new LogicLooper[looperCount]; for (var i = 0; i < looperCount; i++) { _loopers[i] = new LogicLooper(targetFrameTime); } _balancer = balancer ?? throw new ArgumentNullException(nameof(balancer)); }
public async Task <Room> JoinAsync(Player player, string roomName) { _group = await this.Group.AddAsync(roomName);//ルームに参加&ルームを保持 player.CopyTo(_me); _room.Players.Add(_me);//自分の情報も保持 Logger.Debug("PlayerCount: " + _room.Players.Count); //参加したことをルームに参加している全メンバーに通知 this.Broadcast(_group).OnJoin(_me); if (_looper == null) { _looper = new LogicLooper(30); _looper.RegisterActionAsync((in LogicLooperActionContext ctx) => { if (_room != null) { this.Broadcast(_group).OnUpdateRoom(_room); } return(true); });