Panda3D
|
00001 // Filename: cIntervalManager.h 00002 // Created by: drose (10Sep02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef CINTERVALMANAGER_H 00016 #define CINTERVALMANAGER_H 00017 00018 #include "directbase.h" 00019 #include "cInterval.h" 00020 #include "pointerTo.h" 00021 #include "pvector.h" 00022 #include "pmap.h" 00023 #include "vector_int.h" 00024 #include "pmutex.h" 00025 00026 class EventQueue; 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Class : CIntervalManager 00030 // Description : This object holds a number of currently-playing 00031 // intervals and is responsible for advancing them each 00032 // frame as needed. 00033 // 00034 // There is normally only one IntervalManager object in 00035 // the world, and it is the responsibility of the 00036 // scripting language to call step() on this object once 00037 // each frame, and to then process the events indicated by 00038 // get_next_event(). 00039 // 00040 // It is also possible to create multiple 00041 // IntervalManager objects for special needs. 00042 //////////////////////////////////////////////////////////////////// 00043 class EXPCL_DIRECT CIntervalManager { 00044 PUBLISHED: 00045 CIntervalManager(); 00046 ~CIntervalManager(); 00047 00048 INLINE void set_event_queue(EventQueue *event_queue); 00049 INLINE EventQueue *get_event_queue() const; 00050 00051 int add_c_interval(CInterval *interval, bool external); 00052 int find_c_interval(const string &name) const; 00053 00054 CInterval *get_c_interval(int index) const; 00055 void remove_c_interval(int index); 00056 00057 int interrupt(); 00058 int get_num_intervals() const; 00059 int get_max_index() const; 00060 00061 void step(); 00062 int get_next_event(); 00063 int get_next_removal(); 00064 00065 void output(ostream &out) const; 00066 void write(ostream &out) const; 00067 00068 static CIntervalManager *get_global_ptr(); 00069 00070 private: 00071 void finish_interval(CInterval *interval); 00072 void remove_index(int index); 00073 00074 enum Flags { 00075 F_external = 0x0001, 00076 F_meta_interval = 0x0002, 00077 }; 00078 class IntervalDef { 00079 public: 00080 PT(CInterval) _interval; 00081 int _flags; 00082 int _next_slot; 00083 }; 00084 typedef pvector<IntervalDef> Intervals; 00085 Intervals _intervals; 00086 typedef pmap<string, int> NameIndex; 00087 NameIndex _name_index; 00088 typedef vector_int Removed; 00089 Removed _removed; 00090 EventQueue *_event_queue; 00091 00092 int _first_slot; 00093 int _next_event_index; 00094 00095 Mutex _lock; 00096 00097 static CIntervalManager *_global_ptr; 00098 }; 00099 00100 INLINE ostream &operator << (ostream &out, const CInterval &ival_mgr); 00101 00102 #include "cIntervalManager.I" 00103 00104 #endif 00105 00106 00107