Panda3D
cullBinManager.I
1 // Filename: cullBinManager.I
2 // Created by: drose (28Feb02)
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: CullBinManager::SortBins::Constructor
18 // Access: Public
19 // Description: This is a function object whose sole purpose is to
20 // put the _sorted_bins vector in the proper order for
21 // rendering the bins.
22 ////////////////////////////////////////////////////////////////////
23 INLINE CullBinManager::SortBins::
24 SortBins(CullBinManager *manager) :
25  _manager(manager)
26 {
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: CullBinManager::SortBins::operator ()
31 // Access: Public
32 // Description: The function call method of the function object.
33 // Returns true if the two bin indices are already in
34 // sorted order with a < b, or false otherwise.
35 ////////////////////////////////////////////////////////////////////
36 INLINE bool CullBinManager::SortBins::
37 operator () (int a, int b) const {
38  return _manager->_bin_definitions[a]._sort < _manager->_bin_definitions[b]._sort;
39 }
40 
41 
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: CullBinManager::get_num_bins
45 // Access: Published
46 // Description: Returns the number of bins in the world.
47 ////////////////////////////////////////////////////////////////////
48 INLINE int CullBinManager::
49 get_num_bins() const {
50  // We quietly sort the bins in order if they are not already sorted.
51  // This is a non-const operation, but we pretend it's const because
52  // it's intended to be a transparent update.
53  if (!_bins_are_sorted) {
54  ((CullBinManager *)this)->do_sort_bins();
55  }
56  return _sorted_bins.size();
57 }
58 
59 ////////////////////////////////////////////////////////////////////
60 // Function: CullBinManager::get_bin
61 // Access: Published
62 // Description: Returns the bin_index of the nth bin in the set,
63 // where n is a number between 0 and get_num_bins().
64 // This returns the list of bin_index numbers, in sorted
65 // order (that is, in the order in which the bins should
66 // be rendered).
67 ////////////////////////////////////////////////////////////////////
68 INLINE int CullBinManager::
69 get_bin(int n) const {
70  nassertr(n >= 0 && n < (int)_sorted_bins.size(), -1);
71  return _sorted_bins[n];
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: CullBinManager::get_bin_name
76 // Access: Published
77 // Description: Returns the name of the bin with the indicated
78 // bin_index (where bin_index was retrieved by get_bin()
79 // or find_bin()). The bin's name may not be changed
80 // during the life of the bin.
81 ////////////////////////////////////////////////////////////////////
82 INLINE string CullBinManager::
83 get_bin_name(int bin_index) const {
84  nassertr(bin_index >= 0 && bin_index < (int)_bin_definitions.size(), string());
85  nassertr(_bin_definitions[bin_index]._in_use, string());
86  return _bin_definitions[bin_index]._name;
87 }
88 
89 ////////////////////////////////////////////////////////////////////
90 // Function: CullBinManager::get_bin_type
91 // Access: Published
92 // Description: Returns the type of the bin with the indicated
93 // bin_index (where bin_index was retrieved by get_bin()
94 // or find_bin()).
95 ////////////////////////////////////////////////////////////////////
96 INLINE CullBinManager::BinType CullBinManager::
97 get_bin_type(int bin_index) const {
98  nassertr(bin_index >= 0 && bin_index < (int)_bin_definitions.size(), BT_invalid);
99  nassertr(_bin_definitions[bin_index]._in_use, BT_invalid);
100  return _bin_definitions[bin_index]._type;
101 }
102 
103 ////////////////////////////////////////////////////////////////////
104 // Function: CullBinManager::get_bin_type
105 // Access: Published
106 // Description: Returns the type of the bin with the indicated
107 // name.
108 ////////////////////////////////////////////////////////////////////
109 INLINE CullBinManager::BinType CullBinManager::
110 get_bin_type(const string &name) const {
111  int bin_index = find_bin(name);
112  nassertr(bin_index != -1, BT_invalid);
113  return get_bin_type(bin_index);
114 }
115 
116 ////////////////////////////////////////////////////////////////////
117 // Function: CullBinManager::set_bin_type
118 // Access: Published
119 // Description: Changes the type of the bin with the indicated
120 // bin_index (where bin_index was retrieved by get_bin()
121 // or find_bin()).
122 //
123 // The change might be effective immediately, or it
124 // might take place next frame, depending on the bin
125 // type.
126 ////////////////////////////////////////////////////////////////////
127 INLINE void CullBinManager::
128 set_bin_type(int bin_index, CullBinManager::BinType type) {
129  nassertv(bin_index >= 0 && bin_index < (int)_bin_definitions.size());
130  nassertv(_bin_definitions[bin_index]._in_use);
131  _bin_definitions[bin_index]._type = type;
132 }
133 
134 ////////////////////////////////////////////////////////////////////
135 // Function: CullBinManager::set_bin_type
136 // Access: Published
137 // Description: Changes the type of the bin with the indicated
138 // name.
139 //
140 // The change might be effective immediately, or it
141 // might take place next frame, depending on the bin
142 // type.
143 ////////////////////////////////////////////////////////////////////
144 INLINE void CullBinManager::
145 set_bin_type(const string &name, CullBinManager::BinType type) {
146  int bin_index = find_bin(name);
147  nassertv(bin_index != -1);
148  set_bin_type(bin_index, type);
149 }
150 
151 ////////////////////////////////////////////////////////////////////
152 // Function: CullBinManager::get_bin_sort
153 // Access: Published
154 // Description: Returns the sort order of the bin with the indicated
155 // bin_index (where bin_index was retrieved by get_bin()
156 // or find_bin()).
157 //
158 // The bins are rendered in increasing order by their
159 // sort order; this number may be changed from time to
160 // time to reorder the bins.
161 ////////////////////////////////////////////////////////////////////
162 INLINE int CullBinManager::
163 get_bin_sort(int bin_index) const {
164  nassertr(bin_index >= 0 && bin_index < (int)_bin_definitions.size(), 0);
165  nassertr(_bin_definitions[bin_index]._in_use, 0);
166  return _bin_definitions[bin_index]._sort;
167 }
168 
169 ////////////////////////////////////////////////////////////////////
170 // Function: CullBinManager::get_bin_sort
171 // Access: Published
172 // Description: Returns the sort order of the bin with the indicated
173 // name.
174 //
175 // The bins are rendered in increasing order by their
176 // sort order; this number may be changed from time to
177 // time to reorder the bins.
178 ////////////////////////////////////////////////////////////////////
179 INLINE int CullBinManager::
180 get_bin_sort(const string &name) const {
181  int bin_index = find_bin(name);
182  nassertr(bin_index != -1, 0);
183  return get_bin_sort(bin_index);
184 }
185 
186 ////////////////////////////////////////////////////////////////////
187 // Function: CullBinManager::set_bin_sort
188 // Access: Published
189 // Description: Changes the sort order of the bin with the indicated
190 // bin_index (where bin_index was retrieved by get_bin()
191 // or find_bin()).
192 //
193 // The bins are rendered in increasing order by their
194 // sort order; this number may be changed from time to
195 // time to reorder the bins.
196 ////////////////////////////////////////////////////////////////////
197 INLINE void CullBinManager::
198 set_bin_sort(int bin_index, int sort) {
199  nassertv(bin_index >= 0 && bin_index < (int)_bin_definitions.size());
200  nassertv(_bin_definitions[bin_index]._in_use);
201  _bin_definitions[bin_index]._sort = sort;
202  _bins_are_sorted = false;
203 }
204 
205 ////////////////////////////////////////////////////////////////////
206 // Function: CullBinManager::set_bin_sort
207 // Access: Published
208 // Description: Changes the sort order of the bin with the indicated
209 // name.
210 //
211 // The bins are rendered in increasing order by their
212 // sort order; this number may be changed from time to
213 // time to reorder the bins.
214 ////////////////////////////////////////////////////////////////////
215 INLINE void CullBinManager::
216 set_bin_sort(const string &name, int sort) {
217  int bin_index = find_bin(name);
218  nassertv(bin_index != -1);
219  set_bin_sort(bin_index, sort);
220 }
221 
222 ////////////////////////////////////////////////////////////////////
223 // Function: CullBinManager::get_bin_active
224 // Access: Published
225 // Description: Returns the active flag of the bin with the indicated
226 // bin_index (where bin_index was retrieved by get_bin()
227 // or find_bin()).
228 //
229 // When a bin is marked inactive, all geometry assigned
230 // to it is not rendered.
231 ////////////////////////////////////////////////////////////////////
232 INLINE bool CullBinManager::
233 get_bin_active(int bin_index) const {
234  nassertr(bin_index >= 0 && bin_index < (int)_bin_definitions.size(), false);
235  nassertr(_bin_definitions[bin_index]._in_use, false);
236  return _bin_definitions[bin_index]._active;
237 }
238 
239 ////////////////////////////////////////////////////////////////////
240 // Function: CullBinManager::get_bin_active
241 // Access: Published
242 // Description: Returns the active flag of the bin with the indicated
243 // name.
244 //
245 // When a bin is marked inactive, all geometry assigned
246 // to it is not rendered.
247 ////////////////////////////////////////////////////////////////////
248 INLINE bool CullBinManager::
249 get_bin_active(const string &name) const {
250  int bin_index = find_bin(name);
251  nassertr(bin_index != -1, false);
252  return get_bin_active(bin_index);
253 }
254 
255 ////////////////////////////////////////////////////////////////////
256 // Function: CullBinManager::set_bin_active
257 // Access: Published
258 // Description: Changes the active flag of the bin with the indicated
259 // bin_index (where bin_index was retrieved by get_bin()
260 // or find_bin()).
261 //
262 // When a bin is marked inactive, all geometry assigned
263 // to it is not rendered.
264 ////////////////////////////////////////////////////////////////////
265 INLINE void CullBinManager::
266 set_bin_active(int bin_index, bool active) {
267  nassertv(bin_index >= 0 && bin_index < (int)_bin_definitions.size());
268  nassertv(_bin_definitions[bin_index]._in_use);
269  _bin_definitions[bin_index]._active = active;
270 }
271 
272 ////////////////////////////////////////////////////////////////////
273 // Function: CullBinManager::set_bin_active
274 // Access: Published
275 // Description: Changes the active flag of the bin with the indicated
276 // name.
277 //
278 // When a bin is marked inactive, all geometry assigned
279 // to it is not rendered.
280 ////////////////////////////////////////////////////////////////////
281 INLINE void CullBinManager::
282 set_bin_active(const string &name, bool active) {
283  int bin_index = find_bin(name);
284  nassertv(bin_index != -1);
285  set_bin_active(bin_index, active);
286 }
287 
288 #ifndef NDEBUG
289 ////////////////////////////////////////////////////////////////////
290 // Function: CullBinManager::get_bin_flash_active
291 // Access: Published
292 // Description: Returns true if the bin with the given bin_index is
293 // configured to flash at a predetermined color (where
294 // bin_index was retrieved by get_bin() or find_bin()).
295 //
296 // This method is not available in release builds.
297 ////////////////////////////////////////////////////////////////////
298 INLINE bool CullBinManager::
299 get_bin_flash_active(int bin_index) const {
300  nassertr(bin_index >= 0 && bin_index < (int)_bin_definitions.size(), false);
301  return _bin_definitions[bin_index]._flash_active;
302 }
303 
304 ////////////////////////////////////////////////////////////////////
305 // Function: CullBinManager::get_bin_flash_color
306 // Access: Published
307 // Description: Returns the color that this bin has been configured
308 // to flash to, if configured.
309 //
310 // This method is not available in release builds.
311 ////////////////////////////////////////////////////////////////////
312 INLINE const LColor &CullBinManager::
313 get_bin_flash_color(int bin_index) const {
314  nassertr(bin_index >= 0 && bin_index < (int)_bin_definitions.size(), LColor::zero());
315  return _bin_definitions[bin_index]._flash_color;
316 }
317 
318 ////////////////////////////////////////////////////////////////////
319 // Function: CullBinManager::set_bin_flash_active
320 // Access: Published
321 // Description: When set to true, the given bin_index is configured
322 // to flash at a predetermined color (where
323 // bin_index was retrieved by get_bin() or find_bin()).
324 //
325 // This method is not available in release builds.
326 ////////////////////////////////////////////////////////////////////
327 INLINE void CullBinManager::
328 set_bin_flash_active(int bin_index, bool active) {
329  nassertv(bin_index >= 0 && bin_index < (int)_bin_definitions.size());
330  _bin_definitions[bin_index]._flash_active = active;
331 }
332 
333 ////////////////////////////////////////////////////////////////////
334 // Function: CullBinManager::set_bin_flash_color
335 // Access: Published
336 // Description: Changes the flash color for the given bin index.
337 
338 // This method is not available in release builds.
339 ////////////////////////////////////////////////////////////////////
340 INLINE void CullBinManager::
341 set_bin_flash_color(int bin_index, const LColor &color) {
342  nassertv(bin_index >= 0 && bin_index < (int)_bin_definitions.size());
343  _bin_definitions[bin_index]._flash_color = color;
344 }
345 #endif // NDEBUG
346 
347 ////////////////////////////////////////////////////////////////////
348 // Function: CullBinManager::get_global_ptr
349 // Access: Published, Static
350 // Description: Returns the pointer to the global CullBinManager
351 // object.
352 ////////////////////////////////////////////////////////////////////
355  if (_global_ptr == (CullBinManager *)NULL) {
356  _global_ptr = new CullBinManager;
357  }
358  return _global_ptr;
359 }
void set_bin_flash_active(int bin_index, bool active)
When set to true, the given bin_index is configured to flash at a predetermined color (where bin_inde...
void set_bin_type(int bin_index, BinType type)
Changes the type of the bin with the indicated bin_index (where bin_index was retrieved by get_bin() ...
void set_bin_active(int bin_index, bool active)
Changes the active flag of the bin with the indicated bin_index (where bin_index was retrieved by get...
const LColor & get_bin_flash_color(int bin_index) const
Returns the color that this bin has been configured to flash to, if configured.
int get_bin_sort(int bin_index) const
Returns the sort order of the bin with the indicated bin_index (where bin_index was retrieved by get_...
bool get_bin_flash_active(int bin_index) const
Returns true if the bin with the given bin_index is configured to flash at a predetermined color (whe...
int get_num_bins() const
Returns the number of bins in the world.
string get_bin_name(int bin_index) const
Returns the name of the bin with the indicated bin_index (where bin_index was retrieved by get_bin() ...
static CullBinManager * get_global_ptr()
Returns the pointer to the global CullBinManager object.
int find_bin(const string &name) const
Returns the bin_index associated with the bin of the given name, or -1 if no bin has that name...
bool get_bin_active(int bin_index) const
Returns the active flag of the bin with the indicated bin_index (where bin_index was retrieved by get...
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
This is a global object that maintains the collection of named CullBins in the world.
void set_bin_flash_color(int bin_index, const LColor &color)
Changes the flash color for the given bin index.
static const LVecBase4f & zero()
Returns a zero-length vector.
Definition: lvecBase4.h:493
void set_bin_sort(int bin_index, int sort)
Changes the sort order of the bin with the indicated bin_index (where bin_index was retrieved by get_...
int get_bin(int n) const
Returns the bin_index of the nth bin in the set, where n is a number between 0 and get_num_bins()...
BinType get_bin_type(int bin_index) const
Returns the type of the bin with the indicated bin_index (where bin_index was retrieved by get_bin() ...