예제 #1
0
        private void updateHitObject([CanBeNull] HitObject hitObject, bool silent)
        {
            scheduledUpdate?.Cancel();

            if (hitObject != null)
            {
                pendingUpdates.Add(hitObject);
            }

            scheduledUpdate = Schedule(() =>
            {
                beatmapProcessor?.PreProcess();

                foreach (var obj in pendingUpdates)
                {
                    obj.ApplyDefaults(ControlPointInfo, BeatmapInfo.BaseDifficulty);
                }

                beatmapProcessor?.PostProcess();

                if (!silent)
                {
                    foreach (var obj in pendingUpdates)
                    {
                        HitObjectUpdated?.Invoke(obj);
                    }
                }

                pendingUpdates.Clear();
            });
        }
예제 #2
0
        public IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList <Mod> mods)
        {
            var rulesetInstance = ruleset.CreateInstance();

            IBeatmapConverter converter = CreateBeatmapConverter(Beatmap, rulesetInstance);

            // Check if the beatmap can be converted
            if (!converter.CanConvert)
            {
                throw new BeatmapInvalidForRulesetException($"{nameof(Beatmaps.Beatmap)} can not be converted for the ruleset (ruleset: {ruleset.InstantiationInfo}, converter: {converter}).");
            }

            // Apply conversion mods
            foreach (var mod in mods.OfType <IApplicableToBeatmapConverter>())
            {
                mod.ApplyToBeatmapConverter(converter);
            }

            // Convert
            IBeatmap converted = converter.Convert();

            // Apply difficulty mods
            if (mods.Any(m => m is IApplicableToDifficulty))
            {
                converted.BeatmapInfo = converted.BeatmapInfo.Clone();
                converted.BeatmapInfo.BaseDifficulty = converted.BeatmapInfo.BaseDifficulty.Clone();

                foreach (var mod in mods.OfType <IApplicableToDifficulty>())
                {
                    mod.ApplyToDifficulty(converted.BeatmapInfo.BaseDifficulty);
                }
            }

            IBeatmapProcessor processor = rulesetInstance.CreateBeatmapProcessor(converted);

            processor?.PreProcess();

            // Compute default values for hitobjects, including creating nested hitobjects in-case they're needed
            foreach (var obj in converted.HitObjects)
            {
                obj.ApplyDefaults(converted.ControlPointInfo, converted.BeatmapInfo.BaseDifficulty);
            }

            foreach (var mod in mods.OfType <IApplicableToHitObject>())
            {
                foreach (var obj in converted.HitObjects)
                {
                    mod.ApplyToHitObject(obj);
                }
            }

            processor?.PostProcess();

            foreach (var mod in mods.OfType <IApplicableToBeatmap>())
            {
                mod.ApplyToBeatmap(converted);
            }

            return(converted);
        }
예제 #3
0
 public override void UpdateHitObject(HitObject hitObject)
 {
     scheduledUpdate?.Cancel();
     scheduledUpdate = Schedule(() =>
     {
         beatmapProcessor?.PreProcess();
         hitObject?.ApplyDefaults(playableBeatmap.ControlPointInfo, playableBeatmap.BeatmapInfo.BaseDifficulty);
         beatmapProcessor?.PostProcess();
     });
 }
예제 #4
0
 /// <summary>
 /// Updates a <see cref="HitObject"/>, invoking <see cref="HitObject.ApplyDefaults"/> and re-processing the beatmap.
 /// </summary>
 /// <param name="hitObject">The <see cref="HitObject"/> to update.</param>
 public void UpdateHitObject(HitObject hitObject)
 {
     scheduledUpdate?.Cancel();
     scheduledUpdate = Scheduler.AddDelayed(() =>
     {
         beatmapProcessor?.PreProcess();
         hitObject?.ApplyDefaults(ControlPointInfo, BeatmapInfo.BaseDifficulty);
         beatmapProcessor?.PostProcess();
     }, 0);
 }
예제 #5
0
        public virtual IBeatmap GetPlayableBeatmap(IRulesetInfo ruleset, IReadOnlyList <Mod> mods, CancellationToken token)
        {
            var rulesetInstance = ruleset.CreateInstance();

            if (rulesetInstance == null)
            {
                throw new RulesetLoadException("Creating ruleset instance failed when attempting to create playable beatmap.");
            }

            IBeatmapConverter converter = CreateBeatmapConverter(Beatmap, rulesetInstance);

            // Check if the beatmap can be converted
            if (Beatmap.HitObjects.Count > 0 && !converter.CanConvert())
            {
                throw new BeatmapInvalidForRulesetException($"{nameof(Beatmaps.Beatmap)} can not be converted for the ruleset (ruleset: {ruleset.InstantiationInfo}, converter: {converter}).");
            }

            // Apply conversion mods
            foreach (var mod in mods.OfType <IApplicableToBeatmapConverter>())
            {
                token.ThrowIfCancellationRequested();
                mod.ApplyToBeatmapConverter(converter);
            }

            // Convert
            IBeatmap converted = converter.Convert(token);

            // Apply conversion mods to the result
            foreach (var mod in mods.OfType <IApplicableAfterBeatmapConversion>())
            {
                token.ThrowIfCancellationRequested();
                mod.ApplyToBeatmap(converted);
            }

            // Apply difficulty mods
            if (mods.Any(m => m is IApplicableToDifficulty))
            {
                foreach (var mod in mods.OfType <IApplicableToDifficulty>())
                {
                    token.ThrowIfCancellationRequested();
                    mod.ApplyToDifficulty(converted.Difficulty);
                }
            }

            IBeatmapProcessor processor = rulesetInstance.CreateBeatmapProcessor(converted);

            foreach (var mod in mods.OfType <IApplicableToBeatmapProcessor>())
            {
                mod.ApplyToBeatmapProcessor(processor);
            }

            processor?.PreProcess();

            // Compute default values for hitobjects, including creating nested hitobjects in-case they're needed
            foreach (var obj in converted.HitObjects)
            {
                token.ThrowIfCancellationRequested();
                obj.ApplyDefaults(converted.ControlPointInfo, converted.Difficulty, token);
            }

            foreach (var mod in mods.OfType <IApplicableToHitObject>())
            {
                foreach (var obj in converted.HitObjects)
                {
                    token.ThrowIfCancellationRequested();
                    mod.ApplyToHitObject(obj);
                }
            }

            processor?.PostProcess();

            foreach (var mod in mods.OfType <IApplicableToBeatmap>())
            {
                token.ThrowIfCancellationRequested();
                mod.ApplyToBeatmap(converted);
            }

            return(converted);
        }
예제 #6
0
        public IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList <Mod> mods = null, TimeSpan?timeout = null)
        {
            using (var cancellationSource = createCancellationTokenSource(timeout))
            {
                mods ??= Array.Empty <Mod>();

                var rulesetInstance = ruleset.CreateInstance();

                IBeatmapConverter converter = CreateBeatmapConverter(Beatmap, rulesetInstance);

                // Check if the beatmap can be converted
                if (Beatmap.HitObjects.Count > 0 && !converter.CanConvert())
                {
                    throw new BeatmapInvalidForRulesetException($"{nameof(Beatmaps.Beatmap)} can not be converted for the ruleset (ruleset: {ruleset.InstantiationInfo}, converter: {converter}).");
                }

                // Apply conversion mods
                foreach (var mod in mods.OfType <IApplicableToBeatmapConverter>())
                {
                    if (cancellationSource.IsCancellationRequested)
                    {
                        throw new BeatmapLoadTimeoutException(BeatmapInfo);
                    }

                    mod.ApplyToBeatmapConverter(converter);
                }

                // Convert
                IBeatmap converted = converter.Convert();

                // Apply difficulty mods
                if (mods.Any(m => m is IApplicableToDifficulty))
                {
                    converted.BeatmapInfo = converted.BeatmapInfo.Clone();
                    converted.BeatmapInfo.BaseDifficulty = converted.BeatmapInfo.BaseDifficulty.Clone();

                    foreach (var mod in mods.OfType <IApplicableToDifficulty>())
                    {
                        if (cancellationSource.IsCancellationRequested)
                        {
                            throw new BeatmapLoadTimeoutException(BeatmapInfo);
                        }

                        mod.ApplyToDifficulty(converted.BeatmapInfo.BaseDifficulty);
                    }
                }

                IBeatmapProcessor processor = rulesetInstance.CreateBeatmapProcessor(converted);

                processor?.PreProcess();

                // Compute default values for hitobjects, including creating nested hitobjects in-case they're needed
                foreach (var obj in converted.HitObjects)
                {
                    if (cancellationSource.IsCancellationRequested)
                    {
                        throw new BeatmapLoadTimeoutException(BeatmapInfo);
                    }

                    obj.ApplyDefaults(converted.ControlPointInfo, converted.BeatmapInfo.BaseDifficulty);
                }

                foreach (var mod in mods.OfType <IApplicableToHitObject>())
                {
                    foreach (var obj in converted.HitObjects)
                    {
                        if (cancellationSource.IsCancellationRequested)
                        {
                            throw new BeatmapLoadTimeoutException(BeatmapInfo);
                        }

                        mod.ApplyToHitObject(obj);
                    }
                }

                processor?.PostProcess();

                foreach (var mod in mods.OfType <IApplicableToBeatmap>())
                {
                    cancellationSource.Token.ThrowIfCancellationRequested();
                    mod.ApplyToBeatmap(converted);
                }

                return(converted);
            }
        }
예제 #7
0
 private void addHitObject(HitObject hitObject)
 {
     beatmapProcessor?.PreProcess();
     hitObject.ApplyDefaults(playableBeatmap.ControlPointInfo, playableBeatmap.BeatmapInfo.BaseDifficulty);
     beatmapProcessor?.PostProcess();
 }
예제 #8
0
 private void removeHitObject(HitObject hitObject)
 {
     beatmapProcessor?.PreProcess();
     beatmapProcessor?.PostProcess();
 }