private async Task ServerLoop() { var keepAliveTicks = 0; short itersPerSecond = 0; var stopWatch = Stopwatch.StartNew(); // for TPS measuring while (!this.cts.IsCancellationRequested) { await Task.Delay(50); await this.Events.InvokeServerTickAsync(); keepAliveTicks++; if (keepAliveTicks > 50) { var keepaliveid = DateTime.Now.Millisecond; foreach (var client in this.clients.Where(x => x.State == ClientState.Play)) { _ = Task.Run(async() => await client.ProcessKeepAliveAsync(keepaliveid)); } keepAliveTicks = 0; } foreach (var(uuid, player) in this.OnlinePlayers) { if (this.Config.Baah.HasValue) { var soundPosition = new SoundPosition(player.Location.X, player.Location.Y, player.Location.Z); await player.SendSoundAsync(461, soundPosition, SoundCategory.Master, 1.0f, 1.0f); } if (this.chatMessages.TryPeek(out QueueChat msg)) { await player.SendMessageAsync(msg.Message, msg.Position); } } this.chatMessages.TryDequeue(out var _); foreach (var client in clients) { if (!client.tcp.Connected) { this.clients.TryRemove(client); } } itersPerSecond++; // if Stopwatch elapsed time more than 1000 ms, reset counter, restart stopwatch, and set TPS property if (stopWatch.ElapsedMilliseconds >= 1000L) { TPS = itersPerSecond; itersPerSecond = 0; stopWatch.Restart(); } } }
public async Task <ArticulationTestExam> GenerateExam(SoundPosition soundPosition, string languageCode) { // Delete previous exams await DeleteAllExams(); // Get position name from enum string soundPositionName = Enum.GetName(typeof(SoundPosition), soundPosition); // Get tests by sound position var tests = await _repositoryTest.GetAsync(predicate : x => x.SoundPosition == soundPositionName && x.LanguageCode == languageCode, orderBy : x => x.Sound); // Create new exam var exam = new ArticulationTestExam(soundPositionName); // Create exam answers for each test int indexNumber = 0; exam.Answers = tests.Select(test => { indexNumber += 1; return(new ArticulationTestExamAnswer(indexNumber, test)); }).ToList(); // Save exam await _repositoryTestExam.InsertWithChildrenAsync(exam, true); return(exam); }
public SoundEffect(Sounds soundId, SoundPosition position, SoundCategory category = SoundCategory.Master, float pitch = 1.0f, float volume = 1f) { this.SoundId = soundId; this.Position = position; this.Category = category; this.Pitch = pitch; this.Volume = volume; }
public SoundEffect(Sounds soundId, SoundPosition position, SoundCategory category = SoundCategory.Master, float pitch = 1f, float volume = 1f) { SoundId = soundId; Position = position; Category = category; Pitch = pitch; Volume = volume; }
private async Task ServerLoop() { var keepAliveTicks = 0; short itersPerSecond = 0; var stopWatch = Stopwatch.StartNew(); // for TPS measuring while (!this.cts.IsCancellationRequested) { await Task.Delay(50, cts.Token); await this.Events.InvokeServerTickAsync(); keepAliveTicks++; if (keepAliveTicks > 50) { var keepaliveid = DateTime.Now.Millisecond; foreach (var client in this.clients.Where(x => x.State == ClientState.Play)) { client.ProcessKeepAlive(keepaliveid); } keepAliveTicks = 0; } if (Config.Baah.HasValue) { foreach (var(uuid, player) in this.OnlinePlayers) { var soundPosition = new SoundPosition(player.Position.X, player.Position.Y, player.Position.Z); await player.SendSoundAsync(Sounds.EntitySheepAmbient, soundPosition, SoundCategory.Master, 1.0f, 1.0f); } } while (chatMessages.TryDequeue(out QueueChat msg)) { foreach (var(uuid, player) in this.OnlinePlayers) { await player.SendMessageAsync(msg.Message, msg.Type); } } // if Stopwatch elapsed time more than 1000 ms, reset counter, restart stopwatch, and set TPS property itersPerSecond++; if (stopWatch.ElapsedMilliseconds >= 1000L) { TPS = itersPerSecond; itersPerSecond = 0; stopWatch.Restart(); } _ = Task.Run(() => World.ManageChunks()); } }
public NamedSoundEffect(string name, SoundPosition position, SoundCategory category, float volume, float pitch) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Name cannot be null or empty.", nameof(name)); } Name = name; Position = position; Category = category; Volume = volume; Pitch = pitch; }
public NamedSoundEffect(string name, SoundPosition location, SoundCategory category, float pitch, float volume) : base(0x18) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("message", nameof(name)); } this.Name = name; this.Category = category; this.Location = location; this.Volume = volume; this.Pitch = pitch; }
public NamedSoundEffect(string name, SoundPosition location, SoundCategory category, float pitch, float volume) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("message", nameof(name)); } Name = name; Category = category; Position = location; Volume = volume; Pitch = pitch; }
private async Task ServerLoop() { var keepaliveticks = 0; while (!this.cts.IsCancellationRequested) { await Task.Delay(50); await this.Events.InvokeServerTickAsync(); keepaliveticks++; if (keepaliveticks > 50) { var keepaliveid = DateTime.Now.Millisecond; foreach (var clnt in this.clients.Where(x => x.State == ClientState.Play)) { _ = Task.Run(async() => await clnt.ProcessKeepAlive(keepaliveid)); } keepaliveticks = 0; } foreach (var(uuid, player) in this.OnlinePlayers) { if (this.Config.Baah.HasValue) { var pos = new SoundPosition(player.Location.X, player.Location.Y, player.Location.Z); await player.SendSoundAsync(461, pos, SoundCategory.Master, 1.0f, 1.0f); } if (this.chatmessages.TryPeek(out QueueChat msg)) { await player.SendMessageAsync(msg.Message, msg.Position); } } this.chatmessages.TryDequeue(out var _); foreach (var client in clients) { if (!client.tcp.Connected) { this.clients.TryRemove(client); } } } }
private async Task OpenArticulationTestPopup() { // Open dialog box string soundLocation = await DialogService.SelectActionAsync( Resources.AppResources.SelectSoundPosition, Resources.AppResources.SelectSoundPosition, Resources.AppResources.Cancel, ResourceHelper.TranslateArray(Enum.GetNames(typeof(SoundPosition)))); if (soundLocation != Resources.AppResources.Cancel) { DialogService.ShowLoading(Resources.AppResources.Loading); // Convert selected action to resource key var soundLocationResourceKey = ResourceHelper.GetResourceNameByValue(soundLocation); // Convert string key value to enum SoundPosition soundPosition = (SoundPosition)Enum.Parse(typeof(SoundPosition), soundLocationResourceKey); // Navigate to articulation test await NavigationService.NavigateToAsync <ArticulationTestViewModel>(soundPosition); DialogService.HideLoading(); } }
public Task SendNamedSoundAsync(string name, SoundPosition position, SoundCategory category = SoundCategory.Master, float pitch = 1f, float volume = 1f) => client.QueuePacketAsync(new NamedSoundEffect(name, position, category, pitch, volume));
public Task SendSoundAsync(Sounds soundId, SoundPosition position, SoundCategory category = SoundCategory.Master, float pitch = 1f, float volume = 1f) => client.QueuePacketAsync(new SoundEffect(soundId, position, category, pitch, volume));
public void WriteSoundPosition(SoundPosition value) { WriteInt(value.X); WriteInt(value.Y); WriteInt(value.Z); }