00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 INLINE TimedCycle::
00021 TimedCycle() :
00022 _cycle_time(30),
00023 _inv_cycle_time(1./30),
00024 _next_switch(-1),
00025 _current_child(0),
00026 _element_count(0)
00027 {
00028 _global_clock = ClockObject::get_global_clock();
00029 }
00030
00031
00032
00033
00034
00035
00036 INLINE TimedCycle::
00037 TimedCycle(PN_stdfloat cycle_time, int element_count) :
00038 _cycle_time(cycle_time),
00039 _current_child(0),
00040 _element_count(element_count)
00041 {
00042 nassertv(_cycle_time > 0);
00043 _global_clock = ClockObject::get_global_clock();
00044 _next_switch = _global_clock->get_frame_time() + _cycle_time;
00045 _inv_cycle_time = 1. / _cycle_time;
00046 }
00047
00048
00049
00050
00051
00052
00053 INLINE void TimedCycle::
00054 set_element_count(int element_count)
00055 {
00056 _element_count = element_count;
00057 }
00058
00059
00060
00061
00062
00063
00064 INLINE void TimedCycle::
00065 set_cycle_time(PN_stdfloat cycle_time)
00066 {
00067 nassertv(cycle_time > 0);
00068 if (_next_switch == -1)
00069 {
00070 _next_switch = _global_clock->get_frame_time() + cycle_time;
00071 }
00072 else
00073 {
00074 _next_switch = _next_switch - _cycle_time + cycle_time;
00075 }
00076 _cycle_time = cycle_time;
00077 _inv_cycle_time = 1. / _cycle_time;
00078 }
00079
00080
00081
00082
00083
00084
00085
00086 INLINE int TimedCycle::
00087 next_element()
00088 {
00089 double current_time = _global_clock->get_frame_time();
00090 unsigned int increment = (unsigned int) ((current_time - _next_switch)
00091 * _inv_cycle_time);
00092
00093 _next_switch += _cycle_time * increment;
00094 _current_child = (_current_child + increment) % _element_count;
00095
00096 return _current_child;
00097 }
00098