00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
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
00098
00099
00100
00101
00102
00103
00104
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
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
00162
00163
00164
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