00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef CINTERVAL_H
00016 #define CINTERVAL_H
00017
00018 #include "directbase.h"
00019 #include "typedReferenceCount.h"
00020 #include "pvector.h"
00021 #include "config_interval.h"
00022 #include "pStatCollector.h"
00023
00024 class CIntervalManager;
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 class EXPCL_DIRECT CInterval : public TypedReferenceCount {
00040 public:
00041 CInterval(const string &name, double duration, bool open_ended);
00042 virtual ~CInterval();
00043
00044 PUBLISHED:
00045 INLINE const string &get_name() const;
00046 INLINE double get_duration() const;
00047 INLINE bool get_open_ended() const;
00048
00049 enum EventType {
00050 ET_initialize,
00051 ET_instant,
00052 ET_step,
00053 ET_finalize,
00054 ET_reverse_initialize,
00055 ET_reverse_instant,
00056 ET_reverse_finalize,
00057 ET_interrupt
00058 };
00059
00060 enum State {
00061 S_initial,
00062 S_started,
00063 S_paused,
00064 S_final
00065 };
00066
00067 INLINE State get_state() const;
00068 INLINE bool is_stopped() const;
00069
00070 INLINE void set_done_event(const string &event);
00071 INLINE const string &get_done_event() const;
00072
00073 void set_t(double t);
00074 INLINE double get_t() const;
00075
00076 INLINE void set_auto_pause(bool auto_pause);
00077 INLINE bool get_auto_pause() const;
00078 INLINE void set_auto_finish(bool auto_finish);
00079 INLINE bool get_auto_finish() const;
00080
00081 INLINE void set_wants_t_callback(bool wants_t_callback);
00082 INLINE bool get_wants_t_callback() const;
00083
00084 INLINE void set_manager(CIntervalManager *manager);
00085 INLINE CIntervalManager *get_manager() const;
00086
00087 void start(double start_t = 0.0, double end_t = -1.0, double play_rate = 1.0);
00088 void loop(double start_t = 0.0, double end_t = -1.0, double play_rate = 1.0);
00089 double pause();
00090 void resume();
00091 void resume(double start_t);
00092 void resume_until(double end_t);
00093 void finish();
00094 void clear_to_initial();
00095 bool is_playing() const;
00096
00097 double get_play_rate() const;
00098 void set_play_rate(double play_rate);
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 void priv_do_event(double t, EventType event);
00109 virtual void priv_initialize(double t);
00110 virtual void priv_instant();
00111 virtual void priv_step(double t);
00112 virtual void priv_finalize();
00113 virtual void priv_reverse_initialize(double t);
00114 virtual void priv_reverse_instant();
00115 virtual void priv_reverse_finalize();
00116 virtual void priv_interrupt();
00117
00118 virtual void output(ostream &out) const;
00119 virtual void write(ostream &out, int indent_level) const;
00120
00121 void setup_play(double start_time, double end_time, double play_rate,
00122 bool do_loop);
00123 void setup_resume();
00124 void setup_resume_until(double end_t);
00125 bool step_play();
00126
00127 public:
00128 void mark_dirty();
00129 INLINE bool check_t_callback();
00130
00131 protected:
00132 void interval_done();
00133
00134 INLINE void recompute() const;
00135 virtual void do_recompute();
00136 INLINE void check_stopped(TypeHandle type, const char *method_name) const;
00137 INLINE void check_started(TypeHandle type, const char *method_name) const;
00138
00139 State _state;
00140 double _curr_t;
00141 string _name;
00142 string _pname;
00143 string _done_event;
00144 double _duration;
00145
00146 bool _auto_pause;
00147 bool _auto_finish;
00148 bool _wants_t_callback;
00149 double _last_t_callback;
00150 CIntervalManager *_manager;
00151
00152
00153 double _clock_start;
00154 double _start_t;
00155 double _end_t;
00156 bool _end_t_at_end;
00157 bool _start_t_at_start;
00158 double _play_rate;
00159 bool _do_loop;
00160 int _loop_count;
00161
00162 private:
00163 bool _open_ended;
00164 bool _dirty;
00165
00166
00167
00168
00169
00170 typedef pvector<CInterval *> Parents;
00171 Parents _parents;
00172
00173 static PStatCollector _root_pcollector;
00174 PStatCollector _ival_pcollector;
00175
00176 public:
00177 static TypeHandle get_class_type() {
00178 return _type_handle;
00179 }
00180 static void init_type() {
00181 TypedReferenceCount::init_type();
00182 register_type(_type_handle, "CInterval",
00183 TypedReferenceCount::get_class_type());
00184 }
00185 virtual TypeHandle get_type() const {
00186 return get_class_type();
00187 }
00188 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00189
00190 private:
00191 static TypeHandle _type_handle;
00192
00193 friend class CMetaInterval;
00194 };
00195
00196 INLINE ostream &operator << (ostream &out, const CInterval &ival);
00197 EXPCL_DIRECT ostream &operator << (ostream &out, CInterval::State state);
00198
00199 #include "cInterval.I"
00200
00201 #endif
00202
00203
00204