Panda3D
 All Classes Functions Variables Enumerations
cIntervalManager.h
1 // Filename: cIntervalManager.h
2 // Created by: drose (10Sep02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef CINTERVALMANAGER_H
16 #define CINTERVALMANAGER_H
17 
18 #include "directbase.h"
19 #include "cInterval.h"
20 #include "pointerTo.h"
21 #include "pvector.h"
22 #include "pmap.h"
23 #include "vector_int.h"
24 #include "pmutex.h"
25 
26 class EventQueue;
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : CIntervalManager
30 // Description : This object holds a number of currently-playing
31 // intervals and is responsible for advancing them each
32 // frame as needed.
33 //
34 // There is normally only one IntervalManager object in
35 // the world, and it is the responsibility of the
36 // scripting language to call step() on this object once
37 // each frame, and to then process the events indicated by
38 // get_next_event().
39 //
40 // It is also possible to create multiple
41 // IntervalManager objects for special needs.
42 ////////////////////////////////////////////////////////////////////
43 class EXPCL_DIRECT CIntervalManager {
44 PUBLISHED:
47 
48  INLINE void set_event_queue(EventQueue *event_queue);
49  INLINE EventQueue *get_event_queue() const;
50 
51  int add_c_interval(CInterval *interval, bool external);
52  int find_c_interval(const string &name) const;
53 
54  CInterval *get_c_interval(int index) const;
55  void remove_c_interval(int index);
56 
57  int interrupt();
58  int get_num_intervals() const;
59  int get_max_index() const;
60 
61  void step();
62  int get_next_event();
63  int get_next_removal();
64 
65  void output(ostream &out) const;
66  void write(ostream &out) const;
67 
68  static CIntervalManager *get_global_ptr();
69 
70 private:
71  void finish_interval(CInterval *interval);
72  void remove_index(int index);
73 
74  enum Flags {
75  F_external = 0x0001,
76  F_meta_interval = 0x0002,
77  };
78  class IntervalDef {
79  public:
80  PT(CInterval) _interval;
81  int _flags;
82  int _next_slot;
83  };
85  Intervals _intervals;
87  NameIndex _name_index;
88  typedef vector_int Removed;
89  Removed _removed;
90  EventQueue *_event_queue;
91 
92  int _first_slot;
93  int _next_event_index;
94 
95  Mutex _lock;
96 
97  static CIntervalManager *_global_ptr;
98 };
99 
100 INLINE ostream &operator << (ostream &out, const CInterval &ival_mgr);
101 
102 #include "cIntervalManager.I"
103 
104 #endif
105 
106 
107 
The base class for timeline components.
Definition: cInterval.h:39
A standard mutex, or mutual exclusion lock.
Definition: pmutex.h:44
A queue of pending events.
Definition: eventQueue.h:32
This object holds a number of currently-playing intervals and is responsible for advancing them each ...