private void ExecuteSong(NoteQuality hitNoteQuality, float beatTimeDiff, Song matchingSong) { NoteHit?.Invoke(hitNoteQuality, beatTimeDiff); if (_beatInputHandler == Constants.Noop) { // don't execute song if game has been finished with the last note return; } _streakScore += _currentQualities.Aggregate(0, (total, curQuality) => total + (int)curQuality); _streakPower = Mathf.Min(_streakScore / Constants.REQUIRED_STREAK_SCORE, Constants.MAX_STREAK_POWER); _currentSong = matchingSong; int curStreakPower = _streakPower; _currentSong.ExecuteCommand(hitNoteQuality, curStreakPower); _coroutineProvider.StartCoroutine(Coroutines.ExecuteAfterSeconds(HALF_NOTE_TIME, () => { ExecutionStarted?.Invoke(matchingSong, curStreakPower); DisableTouchHandler(); })); ExecutionStarting?.Invoke(_currentSong, curStreakPower); _currentCommandUpdate = _currentSong.ExecuteCommandUpdate; ResetBeatAfterSeconds(NOTE_TIME * 4); }
internal async Task StartSubscribe() { var reader = TaskQueueReader; SubscriberStarted?.Invoke(this); while (true) { T newPayload; try { newPayload = await reader.ReadAsync(TaskManagerCancellationToken.Token).ConfigureAwait(false); } catch (OperationCanceledException) { break; } catch (Exception e) { TaskPayloadFetchException?.Invoke(this, e); continue; } var cts = TaskManagerCancellationToken; CancellationTokenSource localCts = null; var timeout = ExecutionTimeout; if (timeout.HasValue) { localCts = new CancellationTokenSource(timeout.Value); cts = CancellationTokenSource.CreateLinkedTokenSource( TaskManagerCancellationToken.Token, localCts.Token); } try { ExecutionStarting?.Invoke(this); await Execution(newPayload, cts).ConfigureAwait(false); ExecutionFinished?.Invoke(this); } catch (OperationCanceledException ex) { if (localCts?.IsCancellationRequested ?? false) { ExecutionTimeoutEvent?.Invoke(this); } else { SubscriberCancelled?.Invoke(this, ex); break; } } catch (ObjectDisposedException ed) { SubscriberCancelled?.Invoke(this, ed); break; } catch (Exception e) { ExecutionException?.Invoke(this, e); } if (TaskManagerCancellationToken.IsCancellationRequested) { break; } } TaskSubscriberFinalized?.Invoke(this); }
internal async Task PullTaskAsync(CancellationToken token) { var alreadyLogout = false; TaskPullerStarted?.Invoke(this); while (true) { if (TaskManagerCancellationToken.IsCancellationRequested) { break; } if (!LinkedMetadata.IsExecutorEnabled) { break; } var cts = TaskManagerCancellationToken; CancellationTokenSource localCts = null; var timeout = ExecutionTimeout; if (timeout.HasValue) { localCts = new CancellationTokenSource(timeout.Value); cts = CancellationTokenSource.CreateLinkedTokenSource( TaskManagerCancellationToken.Token, localCts.Token); } try { ExecutionStarting?.Invoke(this); await Execution(cts).ConfigureAwait(false); ExecutionFinished?.Invoke(this); } catch (OperationCanceledException) { if (localCts?.IsCancellationRequested ?? false) { ExecutionTimeoutEvent?.Invoke(this); } else { ExecutionCancelled?.Invoke(this); break; } } catch (ObjectDisposedException) { break; } catch (Exception e) { ExecutionExceptionHandler?.Invoke(this, e); } if (TaskManagerCancellationToken.IsCancellationRequested) { break; } if (!LinkedMetadata.IsExecutorEnabled) { break; } if (LinkedMetadata.GlobalApproveNewExecutorCreationCriteriaInContext() && ShouldTryToCreateNewPuller()) { CreatingNewPuller?.Invoke(this); #pragma warning disable 4014 LinkedMetadata.CreateNewTaskExecutor(token); #pragma warning restore 4014 NewPullerCreated?.Invoke(this); } if (!ShouldTryTerminateCurrentPuller()) { continue; } //Try kill itself if (await LinkedMetadata.TryPerformLogoutAsync().ConfigureAwait(false)) { alreadyLogout = true; break; } } if (!alreadyLogout) { await LinkedMetadata.ForceLogoutAsync().ConfigureAwait(false); } TaskPullerFinalized?.Invoke(this); }