public void TestActiveObjects() { Beatmap beatmap; using (var file = OpenTestMap("C18H27NO3")) { // Load only metadata BeatmapKsh kshBeatmap = new BeatmapKsh(file); beatmap = new Beatmap(kshBeatmap); } BeatmapPlayback playback = new BeatmapPlayback(); playback.Beatmap = beatmap; playback.ViewDuration = 0.2; playback.Position = 3.0; Assert.AreEqual(2, playback.ActiveObjects.Count); playback.Position = 13.285; Assert.AreEqual(1, playback.ActiveObjects.Count); Assert.IsAssignableFrom(typeof(Laser), playback.ActiveObjects[0].Object); // Same test but with larger view duration playback.ViewDuration = 1.0; Assert.AreEqual(1, playback.ActiveObjects.Count); Assert.IsAssignableFrom(typeof(Laser), playback.ActiveObjects[0].Object); playback.Position = 25.285; Assert.AreEqual(3, playback.ActiveObjects.Count); var hold = playback.ActiveObjects.First(x => x.Object is Hold); Assert.IsNotNull(hold); // Test events int holdCount = 3; BeatmapPlayback.ObjectEventHandler handler = reference => { holdCount--; }; playback.ObjectDeactivated += handler; playback.Position = 0.0; playback.ObjectDeactivated -= handler; Assert.AreEqual(0, holdCount); handler = reference => { holdCount++; }; playback.ObjectActivated += handler; playback.Position = 35.571; Assert.AreEqual(2, holdCount); // Some more seeks to be sure playback.Position = 25.285; Assert.AreEqual(3, playback.ActiveObjects.Count); playback.Position = 35.571; Assert.AreEqual(2, playback.ActiveObjects.Count); }
public void TestLaserVisiblity() { Beatmap beatmap = new Beatmap(); TimingPoint tp; beatmap.TimingPoints.Add(tp = new TimingPoint { BPM = 240.0f, }); var measure0 = tp.AddMeasure(); var measure1 = tp.AddMeasure(); var measure2 = tp.AddMeasure(); var laserRoot = new LaserRoot { HorizontalPosition = 0.0f, Index = 0, Position = new TimeDivision(0, 4) }; laserRoot.Root = new ObjectReference(laserRoot, measure0); var laserEnd = new Laser { HorizontalPosition = 1.0f, Previous = laserRoot.Root, Position = new TimeDivision(0, 4) }; laserEnd.Root = laserRoot.Root; laserRoot.Next = new ObjectReference(laserEnd, measure2); measure0.Objects.Add(laserRoot); measure2.Objects.Add(laserEnd); BeatmapPlayback playback = new BeatmapPlayback(); playback.ViewDuration = 0.5f; playback.Position = 1.0f; playback.Beatmap = beatmap; var lr = new ObjectReference(laserRoot, measure0); Assert.Contains(lr, measure1.CrossingObjects); Assert.AreEqual(1, playback.MeasuresInView.Count); Assert.AreEqual(measure1, playback.MeasuresInView[0]); Assert.IsTrue(playback.ObjectsInView.Contains(lr)); }
public void Dispose() { if (playback != null) { playback.ObjectActivated -= PlaybackOnObjectActivated; playback.ObjectDeactivated -= PlaybackOnObjectDeactivated; playback = null; } // Dispose effects laserEffectBinding?.Dispose(); foreach (var holdEffect in holdEffectBindings.Values) { holdEffect.Dispose(); } }
/// <summary> /// Hook up the effect controller to playback events /// </summary> /// <param name="playback"></param> public void Initializer(BeatmapPlayback playback, AudioTrack track, SampleManager sampleManager) { Debug.Assert(this.playback == null); // Only do this once, or dispose first this.sampleManager = sampleManager; this.playback = playback; this.track = track; playback.ObjectActivated += PlaybackOnObjectActivated; playback.ObjectDeactivated += PlaybackOnObjectDeactivated; beatmap = playback.Beatmap; laserSlamSample = sampleManager.Get("laser_slam0.wav"); // TODO: Pass in to this function as PlaybackContext context = new PlaybackContext { Playback = playback, Track = track, }; }
public void TestBeatmapPlayback() { Beatmap beatmap; using (var file = OpenTestMap("C18H27NO3")) { // Load only metadata BeatmapKsh kshBeatmap = new BeatmapKsh(file); beatmap = new Beatmap(kshBeatmap); } var t0 = beatmap.TimingPoints[0]; BeatmapPlayback playback = new BeatmapPlayback(); playback.Beatmap = beatmap; playback.ViewDuration = t0.MeasureDuration * 2; // Store objects HashSet <ObjectReference> objectSet = new HashSet <ObjectReference>(playback.ObjectsInView); Assert.AreEqual(8, objectSet.Count); // 8 Laser points playback.ObjectLeft += reference => objectSet.Remove(reference); // Advance a few measures playback.Position = t0.GetMeasureOffset(10); // Check if objects went out of view Assert.IsEmpty(objectSet); // Check addition playback.ObjectEntered += reference => objectSet.Add(reference); playback.Position = 0.0; Assert.AreEqual(8, objectSet.Count); // 8 Laser points again }
public ControllerWindow(AudioTrack track, BeatmapPlayback playback) { beatmapPlayback = playback; audioTrack = track; Size = new Vector2(300, 400); Children = new Drawable[] { new Box { Colour = new Color4(30, 30, 30, 240), RelativeSizeAxes = Axes.Both, Depth = 0 }, new FlowContainer { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, Direction = FlowDirection.VerticalOnly, Children = new Drawable[] { titleBar = new Box //title decoration { Colour = Color4.DarkBlue, RelativeSizeAxes = Axes.X, Size = new Vector2(1, 20), }, new Container //toolbar { RelativeSizeAxes = Axes.X, Size = new Vector2(1, 40), Children = new Drawable[] { new Box { Colour = new Color4(20, 20, 20, 255), RelativeSizeAxes = Axes.Both, }, new FlowContainer { RelativeSizeAxes = Axes.Both, Spacing = new Vector2(1), Children = new Drawable[] { new Button { Colour = Color4.DarkGray, Size = new Vector2(100, 1), RelativeSizeAxes = Axes.Y, Text = @"Pause", Action = TogglePause }, new Button { Colour = Color4.DarkGray, Size = new Vector2(100, 1), RelativeSizeAxes = Axes.Y, Text = @"Restart", Action = Restart }, }, }, }, }, }, }, new Container { RelativeSizeAxes = Axes.Both, Padding = new MarginPadding { Top = 65 }, Children = new[] { container = new FlowContainer { RelativeSizeAxes = Axes.Both, Direction = FlowDirection.VerticalOnly, } } }, }; // Add slider options container.Add(CreateSliderBinding("Position", 0, track.Length, x => audioTrack.Seek(x), () => audioTrack.CurrentTime)); container.Add(CreateSliderBinding("View Duration", 0.1, 4.0, x => beatmapPlayback.ViewDuration = x, () => beatmapPlayback.ViewDuration)); }
public void TestCompareForwardBackward() { Beatmap beatmap; using (var file = OpenTestMap("C18H27NO3")) { // Load only metadata BeatmapKsh kshBeatmap = new BeatmapKsh(file); beatmap = new Beatmap(kshBeatmap); } BeatmapPlayback playback = new BeatmapPlayback(); playback.Beatmap = beatmap; playback.ViewDuration = 0.2; List <int> results = new List <int>(); int passedObjects = 0; int activatedObjects = 0; playback.ObjectEntered += reference => { passedObjects++; }; playback.ObjectActivated += reference => { activatedObjects++; }; // Test multiple view sizes for (int i = 0; i < 2; i++) { // Simulate game loop double timeStep = 1.0 / 240.0; if (i == 0) { playback.Position = 0.0; passedObjects = 0; activatedObjects = 0; while (!playback.HasEnded) { playback.Position += timeStep; } } else { playback.Position = playback.LastObject.AbsolutePosition + 2.0; passedObjects = 0; activatedObjects = 0; while (playback.Position >= 0.0) { playback.Position -= timeStep; } } results.Add(passedObjects); results.Add(activatedObjects); } // Check reverse and forward results Assert.AreEqual(results[0], results[2]); Assert.AreEqual(results[1], results[3]); }
public void TestReverseMapIteration() { Beatmap beatmap; using (var file = OpenTestMap("C18H27NO3")) { // Load only metadata BeatmapKsh kshBeatmap = new BeatmapKsh(file); beatmap = new Beatmap(kshBeatmap); } BeatmapPlayback playback = new BeatmapPlayback(); playback.Beatmap = beatmap; // Test multiple view sizes for (int i = 0; i < 5; i++) { playback.ViewDuration = 0.1 + 0.1 * i; playback.Position = playback.LastObject.AbsolutePosition + 2.0; // Store objects HashSet <ObjectReference> objectSet = new HashSet <ObjectReference>(playback.ObjectsInView); int passedObjects = 0; HashSet <ObjectReference> activeObjects = new HashSet <ObjectReference>(); int activeObjectCounter = 0; playback.ObjectEntered += reference => { Assert.That(objectSet, Has.No.Member(reference)); objectSet.Add(reference); passedObjects++; }; playback.ObjectLeft += reference => { Assert.That(objectSet, Has.Member(reference)); objectSet.Remove(reference); }; playback.ObjectActivated += reference => { activeObjectCounter++; activeObjects.Add(reference); }; playback.ObjectDeactivated += reference => { activeObjectCounter--; activeObjects.Remove(reference); }; // Simulate game loop double timeStep = 1.0 / 240.0; int step = 0; while (playback.Position > 0.0) { playback.Position -= timeStep; step++; } Assert.IsEmpty(objectSet); Assert.IsEmpty(activeObjects); Assert.AreEqual(0, activeObjectCounter); } }