コード例 #1
0
        /// <summary>
        /// When this classes thread is started the below loop continues to run
        /// until either the user presses pause/stop or the frame is completed.
        /// 
        /// We use our own buffered graphics object to draw onto the viewpanel as
        /// we had trouble getting double buffered graphics working properly 
        /// otherwise (therefore giving flickery animation).
        /// </summary>
        private void playLoop()
        {
            try
              {
            foreach (PlayFrame frame in mFrameList)
            {
              // Generate the play data from the frame. This is done internally
              // to the frame so that if we want to change the implementation
              // and store the data in the frame we can.
              mPlayData = frame.GenerateViewingData();

              ParentForm.BeginInvoke((MethodInvoker) delegate()
            {
              ParentForm.SetupViewTrackbar(mPlayData.PlayData.Count);
            });

              DateTime currentTime;
              int cycleIndex = 0;
              mCycleIndex = 0;
              while (cycleIndex < mPlayData.PlayData.Count)
              {
            List<ItemPlayData> singleCycleData = mPlayData.PlayData[cycleIndex];

            ThreadState = PlayThreadState.Playing;

            ParentForm.BeginInvoke((MethodInvoker) delegate()
              {
                ParentForm.UpdateViewTrackbar(cycleIndex);
              });
            currentTime = DateTime.Now;
            mCyclePlayData = singleCycleData;

            // Invoked on the gui thread. Required otherwise we get cross thread
            // exceptions.
            ViewPanel.BeginInvoke((MethodInvoker) delegate()
              {
                ViewPanel.Refresh();
              });

            // We are attempting to draw at 60 cycles per second to the graphics
            // object. If this is achieved then we need to wait a few
            // milliseconds after each draw to keep the graphics from being
            // jerky.
            //
            // If the drawing is too slow we just draw again immediately.
            // Although if this is the case then the visual will be awful.
            TimeSpan timeDiff = DateTime.Now - currentTime;
            if (timeDiff.TotalMilliseconds < MAX_FRAME_TIME)
            {
              Thread.Sleep((int)(MAX_FRAME_TIME - timeDiff.TotalMilliseconds));
            }

            // Pause requests come from the main thread.
            if (ThreadState == PlayThreadState.PauseRequested)
            {
              ThreadState = PlayThreadState.Paused;

              while (ThreadState == PlayThreadState.Paused)
              {
                Thread.Sleep(100);
              }
            }

            if (ThreadState == PlayThreadState.StopRequested)
            {
              break;
            }

            cycleIndex = mCycleIndex;
            if (PlaySpeed == 1.0f)
            {
              mCycleIndex += 4;
            }
            else if (PlaySpeed == 0.5f)
            {
              mCycleIndex += 2;
            }
            else if (PlaySpeed == 0.25f)
            {
              mCycleIndex++;
            }
              }
            }
              }
              catch (ThreadAbortException e)
              {
            // If the main class is disposed then this exception will be thrown.
            Console.WriteLine(e.Message);
              }
              finally
              {
            mCycleIndex = 0;
            ThreadState = PlayThreadState.Stopped;
            ParentForm.BeginInvoke((MethodInvoker)delegate()
              {
            ParentForm.EndPlayingThread();
              });
              }
        }
コード例 #2
0
 public DesignToViewConverter(PlayFrame frame,
                          DiscMovement discMovement, 
                          Dictionary<Player, List<LinearMovement>> playerMovement,
                          List<Trigger> triggers)
 {
     mDiscFrameMovement = discMovement;
       mPlayerMovement = playerMovement;
       mTriggers = triggers;
       mFrame = frame;
       mFramePlayData = new FramePlayData();
       mFramePlayData.PlayData = new List<List<ItemPlayData>>();
       mFramePlayData.PauseTexts = new Dictionary<int, String>();
       mProcessedPlayers = new List<Player>();
       mPlayerDelays = new Dictionary<Player,int>();
 }