Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

direct/src/interval/cInterval.h

Go to the documentation of this file.
00001 // Filename: cInterval.h
00002 // Created by:  drose (27Aug02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef CINTERVAL_H
00020 #define CINTERVAL_H
00021 
00022 #include "directbase.h"
00023 #include "typedReferenceCount.h"
00024 #include "pvector.h"
00025 #include "config_interval.h"
00026 
00027 class CIntervalManager;
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //       Class : CInterval
00031 // Description : The base class for timeline components.  A CInterval
00032 //               represents a single action, event, or collection of
00033 //               nested intervals that will be performed at some
00034 //               specific time or over a period of time.
00035 //
00036 //               This is essentially similar to the Python "Interval"
00037 //               class, but it is implemented in C++ (hence the name).
00038 //               Intervals that may be implemented in C++ will inherit
00039 //               from this class; Intervals that must be implemented
00040 //               in Python will inherit from the similar Python class.
00041 ////////////////////////////////////////////////////////////////////
00042 class EXPCL_DIRECT CInterval : public TypedReferenceCount {
00043 public:
00044   CInterval(const string &name, double duration, bool open_ended);
00045 
00046 PUBLISHED:
00047   INLINE const string &get_name() const;
00048   INLINE double get_duration() const;
00049   INLINE bool get_open_ended() const;
00050 
00051   enum EventType {
00052     ET_initialize,
00053     ET_instant,
00054     ET_step,
00055     ET_finalize,
00056     ET_reverse_initialize,
00057     ET_reverse_instant,
00058     ET_reverse_finalize,
00059     ET_interrupt
00060   };
00061 
00062   enum State {
00063     S_initial,
00064     S_started,
00065     S_paused,
00066     S_final
00067   };
00068 
00069   INLINE State get_state() const;
00070   INLINE bool is_stopped() const;
00071 
00072   INLINE void set_done_event(const string &event);
00073   INLINE const string &get_done_event() const;
00074 
00075   void set_t(double t);
00076   INLINE double get_t() const;
00077 
00078   INLINE void set_auto_pause(bool auto_pause);
00079   INLINE bool get_auto_pause() const;
00080   INLINE void set_auto_finish(bool auto_finish);
00081   INLINE bool get_auto_finish() const;
00082 
00083   INLINE void set_wants_t_callback(bool wants_t_callback);
00084   INLINE bool get_wants_t_callback() const;
00085 
00086   INLINE void set_manager(CIntervalManager *manager);
00087   INLINE CIntervalManager *get_manager() const;
00088 
00089   void start(double start_t = 0.0, double end_t = -1.0, double play_rate = 1.0);
00090   void loop(double start_t = 0.0, double end_t = -1.0, double play_rate = 1.0);
00091   double pause();
00092   void resume();
00093   void resume(double start_t);
00094   void finish();
00095   bool is_playing() const;
00096 
00097   // These functions control the actual playback of the interval.
00098   // Don't call them directly; they're intended to be called from a
00099   // supervising object, e.g. the Python start() .. finish()
00100   // interface.
00101 
00102   // These cannot be declared private because they must be accessible
00103   // to Python, but the method names are prefixed with priv_ to remind
00104   // you that you probably don't want to be using them directly.
00105   void priv_do_event(double t, EventType event);
00106   virtual void priv_initialize(double t);
00107   virtual void priv_instant();
00108   virtual void priv_step(double t);
00109   virtual void priv_finalize();
00110   virtual void priv_reverse_initialize(double t);
00111   virtual void priv_reverse_instant();
00112   virtual void priv_reverse_finalize();
00113   virtual void priv_interrupt();
00114 
00115   virtual void output(ostream &out) const;
00116   virtual void write(ostream &out, int indent_level) const;
00117 
00118   void setup_play(double start_time, double end_time, double play_rate,
00119                   bool do_loop);
00120   void setup_resume();
00121   bool step_play();
00122 
00123 public:
00124   void mark_dirty();
00125   INLINE bool check_t_callback();
00126 
00127 protected:
00128   void interval_done();
00129 
00130   INLINE void recompute() const;
00131   virtual void do_recompute();
00132   INLINE void check_stopped(TypeHandle type, const char *method_name) const;
00133   INLINE void check_started(TypeHandle type, const char *method_name) const;
00134 
00135   State _state;
00136   double _curr_t;
00137   string _name;
00138   string _done_event;
00139   double _duration;
00140 
00141   bool _auto_pause;
00142   bool _auto_finish;
00143   bool _wants_t_callback;
00144   double _last_t_callback;
00145   CIntervalManager *_manager;
00146 
00147   // For setup_play() and step_play().
00148   double _clock_start;
00149   double _start_t;
00150   double _end_t;
00151   bool _end_t_at_end;
00152   bool _start_t_at_start;
00153   double _play_rate;
00154   bool _do_loop;
00155   int _loop_count;
00156   
00157 private:
00158   bool _open_ended;
00159   bool _dirty;
00160 
00161   // We keep a record of the "parent" intervals (that is, any
00162   // CMetaInterval objects that keep a pointer to this one) strictly
00163   // so we can mark all of our parents dirty when this interval gets
00164   // dirty.
00165   typedef pvector<CInterval *> Parents;
00166   Parents _parents;
00167   
00168 public:
00169   static TypeHandle get_class_type() {
00170     return _type_handle;
00171   }
00172   static void init_type() {
00173     TypedReferenceCount::init_type();
00174     register_type(_type_handle, "CInterval",
00175                   TypedReferenceCount::get_class_type());
00176   }
00177   virtual TypeHandle get_type() const {
00178     return get_class_type();
00179   }
00180   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00181 
00182 private:
00183   static TypeHandle _type_handle;
00184 
00185   friend class CMetaInterval;
00186 };
00187 
00188 INLINE ostream &operator << (ostream &out, const CInterval &ival);
00189 ostream &operator << (ostream &out, CInterval::State state);
00190 
00191 #include "cInterval.I"
00192 
00193 #endif
00194 
00195 
00196 

Generated on Fri May 2 01:37:39 2003 for Direct by doxygen1.3