Panda3D
 All Classes Functions Variables Enumerations
cullBinManager.I
00001 // Filename: cullBinManager.I
00002 // Created by:  drose (28Feb02)
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 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: CullBinManager::SortBins::Constructor
00018 //       Access: Public
00019 //  Description: This is a function object whose sole purpose is to
00020 //               put the _sorted_bins vector in the proper order for
00021 //               rendering the bins.
00022 ////////////////////////////////////////////////////////////////////
00023 INLINE CullBinManager::SortBins::
00024 SortBins(CullBinManager *manager) :
00025   _manager(manager)
00026 {
00027 }
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: CullBinManager::SortBins::operator ()
00031 //       Access: Public
00032 //  Description: The function call method of the function object.
00033 //               Returns true if the two bin indices are already in
00034 //               sorted order with a < b, or false otherwise.
00035 ////////////////////////////////////////////////////////////////////
00036 INLINE bool CullBinManager::SortBins::
00037 operator () (int a, int b) const {
00038   return _manager->_bin_definitions[a]._sort < _manager->_bin_definitions[b]._sort;
00039 }
00040 
00041 
00042 
00043 ////////////////////////////////////////////////////////////////////
00044 //     Function: CullBinManager::get_num_bins
00045 //       Access: Published
00046 //  Description: Returns the number of bins in the world.
00047 ////////////////////////////////////////////////////////////////////
00048 INLINE int CullBinManager::
00049 get_num_bins() const {
00050   // We quietly sort the bins in order if they are not already sorted.
00051   // This is a non-const operation, but we pretend it's const because
00052   // it's intended to be a transparent update.
00053   if (!_bins_are_sorted) {
00054     ((CullBinManager *)this)->do_sort_bins();
00055   }
00056   return _sorted_bins.size();
00057 }
00058 
00059 ////////////////////////////////////////////////////////////////////
00060 //     Function: CullBinManager::get_bin
00061 //       Access: Published
00062 //  Description: Returns the bin_index of the nth bin in the set,
00063 //               where n is a number between 0 and get_num_bins().
00064 //               This returns the list of bin_index numbers, in sorted
00065 //               order (that is, in the order in which the bins should
00066 //               be rendered).
00067 ////////////////////////////////////////////////////////////////////
00068 INLINE int CullBinManager::
00069 get_bin(int n) const {
00070   nassertr(n >= 0 && n < (int)_sorted_bins.size(), -1);
00071   return _sorted_bins[n];
00072 }
00073 
00074 ////////////////////////////////////////////////////////////////////
00075 //     Function: CullBinManager::get_bin_name
00076 //       Access: Published
00077 //  Description: Returns the name of the bin with the indicated
00078 //               bin_index (where bin_index was retrieved by get_bin()
00079 //               or find_bin()).  The bin's name may not be changed
00080 //               during the life of the bin.
00081 ////////////////////////////////////////////////////////////////////
00082 INLINE string CullBinManager::
00083 get_bin_name(int bin_index) const {
00084   nassertr(bin_index >= 0 && bin_index < (int)_bin_definitions.size(), string());
00085   nassertr(_bin_definitions[bin_index]._in_use, string());
00086   return _bin_definitions[bin_index]._name;
00087 }
00088 
00089 ////////////////////////////////////////////////////////////////////
00090 //     Function: CullBinManager::get_bin_type
00091 //       Access: Published
00092 //  Description: Returns the type of the bin with the indicated
00093 //               bin_index (where bin_index was retrieved by get_bin()
00094 //               or find_bin()).
00095 ////////////////////////////////////////////////////////////////////
00096 INLINE CullBinManager::BinType CullBinManager::
00097 get_bin_type(int bin_index) const {
00098   nassertr(bin_index >= 0 && bin_index < (int)_bin_definitions.size(), BT_invalid);
00099   nassertr(_bin_definitions[bin_index]._in_use, BT_invalid);
00100   return _bin_definitions[bin_index]._type;
00101 }
00102 
00103 ////////////////////////////////////////////////////////////////////
00104 //     Function: CullBinManager::get_bin_type
00105 //       Access: Published
00106 //  Description: Returns the type of the bin with the indicated
00107 //               name.
00108 ////////////////////////////////////////////////////////////////////
00109 INLINE CullBinManager::BinType CullBinManager::
00110 get_bin_type(const string &name) const {
00111   int bin_index = find_bin(name);
00112   nassertr(bin_index != -1, BT_invalid);
00113   return get_bin_type(bin_index);
00114 }
00115 
00116 ////////////////////////////////////////////////////////////////////
00117 //     Function: CullBinManager::set_bin_type
00118 //       Access: Published
00119 //  Description: Changes the type of the bin with the indicated
00120 //               bin_index (where bin_index was retrieved by get_bin()
00121 //               or find_bin()).
00122 //
00123 //               The change might be effective immediately, or it
00124 //               might take place next frame, depending on the bin
00125 //               type.
00126 ////////////////////////////////////////////////////////////////////
00127 INLINE void CullBinManager::
00128 set_bin_type(int bin_index, CullBinManager::BinType type) {
00129   nassertv(bin_index >= 0 && bin_index < (int)_bin_definitions.size());
00130   nassertv(_bin_definitions[bin_index]._in_use);
00131   _bin_definitions[bin_index]._type = type;
00132 }
00133 
00134 ////////////////////////////////////////////////////////////////////
00135 //     Function: CullBinManager::set_bin_type
00136 //       Access: Published
00137 //  Description: Changes the type of the bin with the indicated
00138 //               name.
00139 //
00140 //               The change might be effective immediately, or it
00141 //               might take place next frame, depending on the bin
00142 //               type.
00143 ////////////////////////////////////////////////////////////////////
00144 INLINE void CullBinManager::
00145 set_bin_type(const string &name, CullBinManager::BinType type) {
00146   int bin_index = find_bin(name);
00147   nassertv(bin_index != -1);
00148   set_bin_type(bin_index, type);
00149 }
00150 
00151 ////////////////////////////////////////////////////////////////////
00152 //     Function: CullBinManager::get_bin_sort
00153 //       Access: Published
00154 //  Description: Returns the sort order of the bin with the indicated
00155 //               bin_index (where bin_index was retrieved by get_bin()
00156 //               or find_bin()).
00157 //
00158 //               The bins are rendered in increasing order by their
00159 //               sort order; this number may be changed from time to
00160 //               time to reorder the bins.
00161 ////////////////////////////////////////////////////////////////////
00162 INLINE int CullBinManager::
00163 get_bin_sort(int bin_index) const {
00164   nassertr(bin_index >= 0 && bin_index < (int)_bin_definitions.size(), 0);
00165   nassertr(_bin_definitions[bin_index]._in_use, 0);
00166   return _bin_definitions[bin_index]._sort;
00167 }
00168 
00169 ////////////////////////////////////////////////////////////////////
00170 //     Function: CullBinManager::get_bin_sort
00171 //       Access: Published
00172 //  Description: Returns the sort order of the bin with the indicated
00173 //               name.
00174 //
00175 //               The bins are rendered in increasing order by their
00176 //               sort order; this number may be changed from time to
00177 //               time to reorder the bins.
00178 ////////////////////////////////////////////////////////////////////
00179 INLINE int CullBinManager::
00180 get_bin_sort(const string &name) const {
00181   int bin_index = find_bin(name);
00182   nassertr(bin_index != -1, 0);
00183   return get_bin_sort(bin_index);
00184 }
00185 
00186 ////////////////////////////////////////////////////////////////////
00187 //     Function: CullBinManager::set_bin_sort
00188 //       Access: Published
00189 //  Description: Changes the sort order of the bin with the indicated
00190 //               bin_index (where bin_index was retrieved by get_bin()
00191 //               or find_bin()).
00192 //
00193 //               The bins are rendered in increasing order by their
00194 //               sort order; this number may be changed from time to
00195 //               time to reorder the bins.
00196 ////////////////////////////////////////////////////////////////////
00197 INLINE void CullBinManager::
00198 set_bin_sort(int bin_index, int sort) {
00199   nassertv(bin_index >= 0 && bin_index < (int)_bin_definitions.size());
00200   nassertv(_bin_definitions[bin_index]._in_use);
00201   _bin_definitions[bin_index]._sort = sort;
00202   _bins_are_sorted = false;
00203 }
00204 
00205 ////////////////////////////////////////////////////////////////////
00206 //     Function: CullBinManager::set_bin_sort
00207 //       Access: Published
00208 //  Description: Changes the sort order of the bin with the indicated
00209 //               name.
00210 //
00211 //               The bins are rendered in increasing order by their
00212 //               sort order; this number may be changed from time to
00213 //               time to reorder the bins.
00214 ////////////////////////////////////////////////////////////////////
00215 INLINE void CullBinManager::
00216 set_bin_sort(const string &name, int sort) {
00217   int bin_index = find_bin(name);
00218   nassertv(bin_index != -1);
00219   set_bin_sort(bin_index, sort);
00220 }
00221 
00222 ////////////////////////////////////////////////////////////////////
00223 //     Function: CullBinManager::get_bin_active
00224 //       Access: Published
00225 //  Description: Returns the active flag of the bin with the indicated
00226 //               bin_index (where bin_index was retrieved by get_bin()
00227 //               or find_bin()).
00228 //
00229 //               When a bin is marked inactive, all geometry assigned
00230 //               to it is not rendered.
00231 ////////////////////////////////////////////////////////////////////
00232 INLINE bool CullBinManager::
00233 get_bin_active(int bin_index) const {
00234   nassertr(bin_index >= 0 && bin_index < (int)_bin_definitions.size(), false);
00235   nassertr(_bin_definitions[bin_index]._in_use, false);
00236   return _bin_definitions[bin_index]._active;
00237 }
00238 
00239 ////////////////////////////////////////////////////////////////////
00240 //     Function: CullBinManager::get_bin_active
00241 //       Access: Published
00242 //  Description: Returns the active flag of the bin with the indicated
00243 //               name.
00244 //
00245 //               When a bin is marked inactive, all geometry assigned
00246 //               to it is not rendered.
00247 ////////////////////////////////////////////////////////////////////
00248 INLINE bool CullBinManager::
00249 get_bin_active(const string &name) const {
00250   int bin_index = find_bin(name);
00251   nassertr(bin_index != -1, false);
00252   return get_bin_active(bin_index);
00253 }
00254 
00255 ////////////////////////////////////////////////////////////////////
00256 //     Function: CullBinManager::set_bin_active
00257 //       Access: Published
00258 //  Description: Changes the active flag of the bin with the indicated
00259 //               bin_index (where bin_index was retrieved by get_bin()
00260 //               or find_bin()).
00261 //
00262 //               When a bin is marked inactive, all geometry assigned
00263 //               to it is not rendered.
00264 ////////////////////////////////////////////////////////////////////
00265 INLINE void CullBinManager::
00266 set_bin_active(int bin_index, bool active) {
00267   nassertv(bin_index >= 0 && bin_index < (int)_bin_definitions.size());
00268   nassertv(_bin_definitions[bin_index]._in_use);
00269   _bin_definitions[bin_index]._active = active;
00270 }
00271 
00272 ////////////////////////////////////////////////////////////////////
00273 //     Function: CullBinManager::set_bin_active
00274 //       Access: Published
00275 //  Description: Changes the active flag of the bin with the indicated
00276 //               name.
00277 //
00278 //               When a bin is marked inactive, all geometry assigned
00279 //               to it is not rendered.
00280 ////////////////////////////////////////////////////////////////////
00281 INLINE void CullBinManager::
00282 set_bin_active(const string &name, bool active) {
00283   int bin_index = find_bin(name);
00284   nassertv(bin_index != -1);
00285   set_bin_active(bin_index, active);
00286 }
 All Classes Functions Variables Enumerations