示例#1
0
        public void EvaluateMuscianGrid()
        {
            //--- Initialisation
            foreach (Channel channel in Context.Map.Channels)
            {
                channel.ListMusician = new List<Musician>();
                channel.ListSpeed = new List<TimeValue<float>>();
                channel.ListSpeed.Add(new TimeValue<float>(new TimeSpan(), 1f));
                channel.InitChannelEffect();

                if (channel.CellStart != null)
                {
                    Musician musician = channel.GetMusicianNotPlaying();
                    musician.IsPlaying = true;
                    musician.NextCell = channel.CellStart;
                }

                foreach (Musician musician in channel.ListMusician)
                {
                    musician.ElapsedTime = TimeSpan.Zero;
                    if (musician.Channel.ListSample.Count > 0)
                        musician.CurrentSample = musician.Channel.ListSample[0];
                    else
                        musician.CurrentSample = null;
                }
            }
            //---

            int musicianCalculationInProgress = 1;

            while (musicianCalculationInProgress > 0)
            {
                musicianCalculationInProgress = 0;

                foreach (Channel channel in Context.Map.Channels)
                {
                    List<Musician> newMusicians = new List<Musician>();

                    foreach (Musician musician in channel.ListMusician)
                    {
                        if (musician.ElapsedTime < Context.Map.PartitionDuration && musician.NextCell != null)
                        {
                            Cell cell = musician.NextCell;
                            float speedFactor = 1f;

                            if (cell != null && (cell.Channel == null || cell.Channel == channel) && cell.Clip != null)
                            {
                                bool ignoreCell = false;

                                //--- Repeater
                                if (cell.Clip.Repeater.HasValue)
                                {
                                    TimeValue<Cell> part = musician.Partition.LastOrDefault(p => p.Value.Clip != null && p.Value.Clip.Instrument != null && p.Value.Clip.Instrument is InstrumentStop);
                                    TimeSpan timePart = TimeSpan.Zero;

                                    if (part != null)
                                        timePart = part.Time;

                                    ignoreCell = musician.Partition.Count(p => p.Time > timePart && p.Value == cell) >= (cell.Clip.Repeater.Value + 1);

                                    if (ignoreCell)
                                    {
                                        int a = 0;
                                    }
                                }
                                //---

                                //--- Note duration
                                speedFactor = cell.Clip.Duration;

                                if (speedFactor == 1 / 8f)
                                {
                                    int a = 0;
                                }
                                //---

                                if (!ignoreCell)
                                {
                                    //--- Speed
                                    if (cell.Clip.Speed.HasValue)
                                    {
                                        float speed = channel.GetSpeedFromTime(musician.ElapsedTime);

                                        speed *= (0.22f * (float)(cell.Clip.Speed.Value)) + 1f;

                                        if (speed < 1f / 16f)
                                            speed = 1f / 16f;
                                        else if (speed > 4f)
                                            speed = 4f;

                                        channel.ListSpeed.Add(new TimeValue<float>(musician.ElapsedTime, speed));
                                    }
                                    //---

                                    //--- Instrument
                                    if (cell.Clip.Instrument is InstrumentStop)
                                    {
                                        musician.IsPlaying = false;
                                        musician.NextCell = null;
                                    }
                                    //---

                                    //--- Effet
                                    if (cell.Clip.Instrument is InstrumentEffect)
                                    {
                                        InstrumentEffect effect = cell.Clip.Instrument as InstrumentEffect;

                                        ChannelEffect channelEffect = cell.Channel.ListEffect.Find(ce => ce.Name == effect.ChannelEffect.Name);

                                        for (int i = 0; i < channelEffect.ListEffectProperty.Count; i++)
                                        {
                                            channelEffect.ListEffectProperty[i].Curve.Keys.Add(new CurveKey((float)musician.ElapsedTime.TotalMilliseconds, effect.ChannelEffect.ListEffectProperty[i].Value));
                                        }
                                    }
                                    //---

                                    //--- Direction
                                    bool divided = false;

                                    for (int i = 0; i < 6; i++)
                                    {
                                        if (cell.Clip.Directions[i])
                                        {
                                            if (divided)
                                            {
                                                Musician newMusician = new Musician(channel);

                                                newMusician.CurrentDirection = i;
                                                newMusician.CurrentCell = cell;
                                                newMusician.NextCell = cell.Neighbourghs[newMusician.CurrentDirection];
                                                newMusician.ElapsedTime = musician.ElapsedTime;

                                                newMusicians.Add(newMusician);
                                            }
                                            else
                                            {
                                                musician.CurrentDirection = i;

                                                divided = true;
                                            }
                                        }
                                    }
                                }
                            }

                            if (cell != null)
                            {
                                //--- Met à jour la partition du musicien
                                musician.Partition.Add(new TimeValue<Cell>(musician.ElapsedTime, cell));
                                musician.ElapsedTime = musician.ElapsedTime.Add(new TimeSpan(0, 0, 0, 0, (int)(Context.Map.TimeDuration * speedFactor / channel.GetSpeedFromTime(musician.ElapsedTime))));

                                if (musician.IsPlaying)
                                    musician.NextCell = cell.Neighbourghs[musician.CurrentDirection];
                                //---

                                musicianCalculationInProgress++;
                            }
                        }
                    }

                    //--- Suppression des doublons de musiciens
                    foreach (Musician musician in channel.ListMusician)
                    {
                        if (musician.IsPlaying && musician.NextCell != null)
                        {
                            List<Musician> doublonMusician = channel.ListMusician.FindAll(
                                m => m.IsPlaying &&
                                    m != musician &&
                                    m.Partition.Last() == musician.Partition.Last() &&
                                    m.NextCell != null &&
                                    m.NextCell.IndexPosition == musician.NextCell.IndexPosition
                                    );

                            foreach (Musician doublon in doublonMusician)
                            {
                                //--- Création d'une cellule fictive pour la suppression du doublon
                                Cell cell = doublon.Partition.Last().Value;
                                Cell cellDoublon = new Cell(Context.Map, cell.Coord.X, cell.Coord.Y, cell.Location.X, cell.Location.Y);

                                cellDoublon.InitClip();
                                cellDoublon.Clip.Instrument = new InstrumentStop();
                                //---

                                doublon.IsPlaying = false;
                                doublon.Partition.Add(new TimeValue<Cell>(doublon.Partition.Last().Time, cellDoublon));
                                doublon.NextCell = null;
                            }
                        }
                    }
                    //---

                    //--- Création des nouveaux musiciens
                    foreach (Musician newMusician in newMusicians)
                    {
                        Musician musician = channel.GetMusicianNotPlaying();

                        if (musician != null)
                        {
                            musician.Partition.Add(new TimeValue<Cell>(newMusician.ElapsedTime, newMusician.CurrentCell));
                            musician.ElapsedTime = newMusician.ElapsedTime.Add(new TimeSpan(0, 0, 0, 0, (int)(Context.Map.TimeDuration * 1f / channel.GetSpeedFromTime(musician.ElapsedTime))));
                            musician.CurrentCell = null;
                            musician.NextCell = newMusician.NextCell;
                            musician.CurrentDirection = newMusician.CurrentDirection;
                            musician.IsPlaying = true;
                            if (musician.Channel.ListSample.Count > 0)
                                musician.CurrentSample = musician.Channel.ListSample[0];
                            else
                                musician.CurrentSample = null;
                        }
                    }
                    //---
                }
            }

            GameEngine.GamePlay.UpdateMusiciansToTime(false);
        }
示例#2
0
        private void DrawMusician(Musician musician, GameTime gameTime)
        {
            //Matrix localWorld = Matrix.CreateTranslation(CameraTarget) * Matrix.CreateTranslation(musician.Position * HexaWidth);

            //meshMusician.Draw(localWorld, View, Projection);

            if (musician.CurrentCell == null || !musician.IsPlaying)
                return;

            Vector2 cellLocation = Tools.GetVector2(musician.Position) * texHexa2D.Width + midCellSize - midCellSize / 2;

            SpriteBatch.Draw(texMusician, cellLocation, musician.Channel.Color);
        }
示例#3
0
文件: Channel.cs 项目: HaKDMoDz/geff
        public Musician GetMusicianNotPlaying()
        {
            Musician musician = this.ListMusician.Find(m => !m.IsPlaying);

            if (musician == null && this.ListMusician.Count < 6)
            {
                musician = new Musician(this);
                ListMusician.Add(musician);
            }

            if (musician != null)
            {
                musician.IsPlaying = true;
                musician.NextCell = null;
            }

            return musician;
        }