public PlayArea() : base() { Gen = new RandomNumberGenerator(); Runners = new List <BaseRunner>(); Course = new List <Segment>(); CourseSegments = new List <PackedScene>(); IsReset = false; GenStatus = CourseGenerationStatus.Free; RunnerDeletionManager = new SemaphoreSlim(1, 1); CourseGeneratorManager = new SemaphoreSlim(1, 1); }
/// <summary> /// Detects when a runner is nearing the end of the course. /// Adds a new segment to the course and moves the RunnerDetector. /// </summary> /// <param name="body">Trigger node</param> public void OnRunnerDetectorBodyEntered(Node body) { Task.Run(() => { CourseGeneratorManager.Wait(); if (GenStatus != CourseGenerationStatus.Free) { CourseGeneratorManager.Release(); return; } GenStatus = CourseGenerationStatus.Busy; CourseGeneratorManager.Release(); CallDeferred(nameof(GenerateCourse), 1); //GenerateCourse(); var pos = Course[Course.Count - 2].Position; RunnerDetector.Position = pos; System.Threading.Thread.Sleep(1000); GenStatus = CourseGenerationStatus.Free; }); }