- Main Page
- Packages
- Classes
- Files

- File List
- File Members

# D:/guillaume/guillara/3D/DXGfx/Backup/DXGfxLib/TimeLine.cs

Go to the documentation of this file.

    00001 //BSD License
    00002 //DXGfx® - http://www.eteractions.com
    00003 //Copyright (c) 2005
    00004 //by Guillaume Randon
    00005 //Permission is hereby granted, free of charge, to any person obtaining a copy of this software
    00006 //and associated documentation files (the "Software"), to deal in the Software without restriction,
    00007 //including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
    00008 //and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
    00009 //subject to the following conditions:
    00010 //The above copyright notice and this permission notice shall be included in all copies or substantial
    00011 //portions of the Software.
    00012 //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
    00013 //INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
    00014 //AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
    00015 //DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00016 //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    00017 using System;
    00018 using System.Collections.Generic;
    00019 using System.Text;
    00020
    00021 namespace DXGfxLib
    00022 {
    00027     public class TimeLine
    00028     {
    00032         public List<Event> events = null;
    00033
    00037         private double startTime = 0;
    00038
    00042         private double lastEvaluation = 0;
    00043
    00048         int lastEventFiredIndex = 0;
    00049
    00053         private SceneObject parent = null;
    00054
    00058         private Scene scene = null;
    00059
    00063         public TimeLine()
    00064         {
    00065             events = new List<Event>();
    00066         }
    00067
    00071         public void Clear()
    00072         {
    00073             events.Clear();
    00074         }
    00075
    00080         public void SetParent(SceneObject parent)
    00081         {
    00082             this.parent = parent;
    00083         }
    00084
    00089         public void SetScene(Scene scene)
    00090         {
    00091             this.scene = scene;
    00092         }
    00093
    00098         public virtual void Evaluate(double appTime, float elapsedTime)
    00099         {
    00100             if (startTime == 0)
    00101             {
    00102                 startTime = appTime;
    00103                 events.Sort();
    00104             }
    00105
    00106             for (int i = lastEventFiredIndex; i < events.Count; i++)
    00107             {
    00108                 if (events[i].timeOffset < (appTime - startTime))
    00109                 {
    00110                     if (parent != null)
    00111                     {
    00112                         parent.AddEvent(events[i]);
    00113                     }
    00114                     else if (scene != null)
    00115                     {
    00116                         scene.AddEvent(events[i]);
    00117                     }
    00118                     else
    00119                     {
    00120                         throw new Exception("No parent and no scene this is wrong !! Event can not be fired!");
    00121                     }
    00122                 }
    00123                 else
    00124                 {
    00125                     break;
    00126                 }
    00127             }
    00128
    00129             lastEvaluation = appTime;
    00130         }
    00131
    00135         public void Reset()
    00136         {
    00137             foreach (Event evt in events)
    00138             {
    00139                 evt.Reset();
    00140             }
    00141             startTime = 0;
    00142             lastEvaluation = 0;
    00143             lastEventFiredIndex = 0;
    00144         }
    00145     }
    00146 }