コード例 #1
0
        private IEnumerable <TimedPresetEvent> GetTimedEvents()
        {
            foreach (MethodInfo i in this.GetType().GetMethods(BindingFlags.Instance |
                                                               BindingFlags.Public |
                                                               BindingFlags.NonPublic))
            {
                object[] attrs = i.GetCustomAttributes(typeof(TimedAttribute),
                                                       true);

                if (attrs.Length == 0)
                {
                    continue;
                }

                ParameterInfo[] ps = i.GetParameters();

                if (ps.Length != 1 || ps[0].ParameterType != typeof(IController))
                {
                    throw new InvalidOperationException("Method tagged as a timeline event does not have the correct signature: " +
                                                        i.DeclaringType.FullName + ":" + i.Name);
                }

                foreach (TimedAttribute timed in i.GetCustomAttributes(typeof(TimedAttribute), true))
                {
                    TimedPresetCallback callback = (TimedPresetCallback)
                                                   Delegate.CreateDelegate(typeof(TimedPresetCallback), this, i);

                    yield return(new TimedPresetEvent(timed.Time, callback, timed.EventType));
                }
            }
        }
コード例 #2
0
            /// <summary>
            /// Constructor.
            /// </summary>
            /// <param name="time">
            /// The time in fractional seconds that this event is to be inserted
            /// into the timeline.
            /// </param>
            /// <param name="callback">
            /// The callback associated with this event.
            /// </param>
            /// <param name="type">
            /// The type of this event.
            /// </param>
            public TimedPresetEvent(double time, TimedPresetCallback callback,
                                    TimedPresetEventType type)
            {
                if (time < 0)
                {
                    throw new ArgumentOutOfRangeException("time < 0");
                }

                if (callback == null)
                {
                    throw new ArgumentNullException("callback");
                }

                this.mTime     = time;
                this.mCallback = callback;
                this.mType     = type;
            }
コード例 #3
0
        private void SyncCurrent(IController controller)
        {
            if (this.mTimeline.Count <= this.mCurrentPosition)
            {
                // If the list isn't empty then something bad happened.
                if (this.mTimeline.Count != 0)
                {
                    throw new InvalidOperationException("Logic error -- this should not happen.");
                }

                return;
            }

            double position = controller.PlayerData.SongPosition;

            if (this.mCurrentPosition >= 0 && this.mTimeline[this.mCurrentPosition].Time > position)
            {
                this.mCurrentPosition = -1;
                this.mCurrentScene    = null;
            }

            while (this.mCurrentPosition + 1 < this.mTimeline.Count &&
                   this.mTimeline[this.mCurrentPosition + 1].Time <= position)
            {
                this.mCurrentPosition++;

                TimedPresetEvent ev = this.mTimeline[this.mCurrentPosition];

                switch (ev.Type)
                {
                case TimedPresetEventType.Scene:
                    this.mCurrentScene = ev.Callback;
                    break;

                case TimedPresetEventType.Event:
                    ev.Callback(controller);
                    break;
                }
            }
        }