Beispiel #1
0
        public void Play(Robot r, Action onComplete, int repeats, float speed)
        {
            //Console.WriteLine("here");
            Thread t = new Thread(() =>
            {
                repeats++;
                while (repeats > 0)
                {
                    long startT = Time.Millis();
                    long playT  = startT;
                    //Console.WriteLine(Keyframes.Count);
                    LinkedListNode <Keyframe> node = Keyframes.First;
                    while (node != null)
                    {
                        Keyframe k = node.Value;

                        lock (this)
                        {
                            if (!isPlaying)
                            {
                                break;
                            }
                        }

                        long currT = (long)((Time.Millis() - startT) * speed);

                        long nextT = k.GetTime();
                        if (currT < nextT)
                        {
                            long total   = nextT - playT;
                            long running = currT - playT;
                            k.Step((float)running / (float)total, r);
                            Thread.Sleep(16);
                            continue;
                        }
                        else
                        {
                            playT = currT;
                        }
                        //Console.WriteLine(k.ToString());
                        k.DoAction(r);
                        node = node.Next;
                    }

                    repeats--;
                }

                onComplete();
            });

            lock (this)
            {
                isPlaying = true;
            }
            t.Start();
        }