Beispiel #1
0
 protected bool Equals(ObjectReference other)
 {
     return(EqualityComparer <Object> .Default.Equals(Object, other.Object));
 }
Beispiel #2
0
 private void OnObjectDeactivated(ObjectReference obj)
 {
     ObjectDeactivated?.Invoke(obj);
 }
Beispiel #3
0
 private void OnObjectLeft(ObjectReference obj)
 {
     ObjectLeft?.Invoke(obj);
 }
Beispiel #4
0
 private void OnObjectEntered(ObjectReference obj)
 {
     ObjectEntered?.Invoke(obj);
 }
Beispiel #5
0
        /// <summary>
        /// Updates the list of visible objects
        /// </summary>
        protected void UpdateView()
        {
            if (beatmap == null)
            {
                return;
            }

            currentMeasure     = SelectMeasure(position);
            CurrentTimingPoint = currentMeasure?.TimingPoint;

            var measure     = currentMeasure;
            var timingPoint = measure.TimingPoint;

            endPosition = position + viewDuration;

            var addedObjects = new HashSet <ObjectReference>();
            var newMeasures  = new List <Measure>();

            // Iterate over objects in view
            bool endReached = false;

            while (!endReached)
            {
                if (measure.AbsolutePosition > endPosition)
                {
                    break;
                }

                // Add measure to the list of current measure
                if (!measuresInView.Contains(measure))
                {
                    OnMeasureEntered(measure);
                }
                newMeasures.Add(measure);

                foreach (var obj in measure.Objects)
                {
                    var objRef = new ObjectReference(obj, measure);
                    if (!objectsInView.Contains(objRef))
                    {
                        if (GetObjectGroupEndingPosition(objRef) < position || GetObjectGroupStartingPosition(objRef) > endPosition)
                        {
                            continue;
                        }

                        double objectPosition = obj.GetAbsolutePosition(measure);
                        if (objectPosition >= endPosition)
                        {
                            endReached = true;
                            break;
                        }

                        // Add this object to the view list
                        if (!objectsInView.Contains(objRef))
                        {
                            addedObjects.Add(objRef);
                        }
                    }
                }

                // Also add crossing objects
                foreach (var objRef in measure.CrossingObjects)
                {
                    if (!objectsInView.Contains(objRef))
                    {
                        if (GetObjectGroupEndingPosition(objRef) < position || GetObjectGroupStartingPosition(objRef) > endPosition)
                        {
                            continue;
                        }

                        // Add this object to the view list
                        if (!objectsInView.Contains(objRef))
                        {
                            addedObjects.Add(objRef);
                        }
                    }
                }

                if (endReached)
                {
                    break;
                }

                // Next measure
                if (measure.Next == null)
                {
                    while (true)
                    {
                        // Next timing point
                        if (timingPoint.Next == null)
                        {
                            endReached = true;
                            break;
                        }

                        timingPoint = timingPoint.Next;
                        if (timingPoint.Measures.Count > 0)
                        {
                            measure = timingPoint.Measures[0];
                            break;
                        }
                    }
                }
                else
                {
                    // Next measure
                    measure = measure.Next;
                }
            }

            MarkPassedObjects();
            objectsInView.AddRange(addedObjects);
            measuresInView = newMeasures;

            // Handle new active objects
            foreach (var obj in addedObjects)
            {
                OnObjectEntered(obj);

                var objStart = obj.AbsolutePosition;
                // Handle new active objects
                if (objStart < position)
                {
                    if (!activeObjects.Contains(obj))
                    {
                        objectsToActivate.Add(obj);
                    }
                }
            }

            if (objectsInView.Count == 0)
            {
                // Update ended state
                HasEnded = LastObject == null || position > LastObject.AbsolutePosition;
            }
            else
            {
                // Can't have ended
                HasEnded = false;
            }

            // Process pending activations
            foreach (var obj in objectsToActivate)
            {
                OnObjectActivated(obj);
                activeObjects.Add(obj);
            }
            foreach (var obj in objectsToDeactivate)
            {
                OnObjectDeactivated(obj);
                activeObjects.Remove(obj);
            }
            objectsToActivate.Clear();
            objectsToDeactivate.Clear();
        }
Beispiel #6
0
        /// <summary>
        /// Sets the beatmap to use for source data
        /// </summary>
        protected void SetBeatmap(Beatmap beatmap)
        {
            // Reset state when beatmap is changed
            if (this.beatmap != beatmap)
            {
                this.beatmap = beatmap;
                foreach (var obj in objectsInView)
                {
                    OnObjectLeft(obj);
                }
                foreach (var obj in activeObjects)
                {
                    OnObjectDeactivated(obj);
                }

                objectsInView.Clear();
                allMeasures.Clear();
                currentMeasure = null;
                HasEnded       = true;
                LastObject     = null;
                FirstObject    = null;

                // Stop here when beatmap is cleared
                if (this.beatmap == null)
                {
                    return;
                }

                beatmap.UpdateMap();
            }

            UpdateView();

            allMeasures.Clear();
            foreach (var timingPoint in this.beatmap.TimingPoints)
            {
                allMeasures.AddRange(timingPoint.Measures);
            }

            // Find first object
            FirstObject = null;
            foreach (var measure in allMeasures)
            {
                foreach (var obj in measure.Objects)
                {
                    // TODO: Ignore events
                    FirstObject = new ObjectReference(obj, measure);
                    break;
                }

                if (FirstObject != null)
                {
                    break;
                }
            }

            // Find last object
            LastObject = null;
            for (int m = allMeasures.Count - 1; m >= 0; m--)
            {
                var measure = allMeasures[m];
                for (int o = measure.Objects.Count - 1; o >= 0; o--)
                {
                    var obj = measure.Objects[o];

                    // TODO: Ignore events
                    LastObject = new ObjectReference(obj, measure);
                    break;
                }

                if (LastObject != null)
                {
                    break;
                }
            }
        }