00001 // Filename: sliderTable.I 00002 // Created by: drose (28Mar05) 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: SliderTable::is_registered 00018 // Access: Published 00019 // Description: Returns true if this table has been registered. 00020 // Once it has been registered, the set of sliders in 00021 // a SliderTable may not be further modified; but 00022 // it must be registered before it can be assigned to a 00023 // Geom. 00024 //////////////////////////////////////////////////////////////////// 00025 INLINE bool SliderTable:: 00026 is_registered() const { 00027 return _is_registered; 00028 } 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: SliderTable::register_table 00032 // Access: Published, Static 00033 // Description: Registers a SliderTable for use. This is 00034 // similar to GeomVertexFormat::register_format(). Once 00035 // registered, a SliderTable may no longer be 00036 // modified (although the individual VertexSlider 00037 // objects may modify their reported sliders). 00038 // 00039 // This must be called before a table may be used in a 00040 // Geom. After this call, you should discard the 00041 // original pointer you passed in (which may or may not 00042 // now be invalid) and let its reference count decrement 00043 // normally; you should use only the returned value from 00044 // this point on. 00045 //////////////////////////////////////////////////////////////////// 00046 INLINE CPT(SliderTable) SliderTable:: 00047 register_table(const SliderTable *table) { 00048 // We don't actually bother adding the table object to a registry. 00049 // This means there may be multiple copies of identical registered 00050 // SliderTables. Big deal. We can always go back and make a 00051 // registry later if we really need it. 00052 if (table->is_registered()) { 00053 return table; 00054 } 00055 00056 ((SliderTable *)table)->do_register(); 00057 return table; 00058 } 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function: SliderTable::get_num_sliders 00062 // Access: Published 00063 // Description: Returns the number of sliders in the table. 00064 //////////////////////////////////////////////////////////////////// 00065 INLINE int SliderTable:: 00066 get_num_sliders() const { 00067 return _sliders.size(); 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: SliderTable::get_slider 00072 // Access: Published 00073 // Description: Returns the nth slider in the table. 00074 //////////////////////////////////////////////////////////////////// 00075 INLINE const VertexSlider *SliderTable:: 00076 get_slider(int n) const { 00077 nassertr(n >= 0 && n < (int)_sliders.size(), NULL); 00078 return _sliders[n]._slider; 00079 } 00080 00081 //////////////////////////////////////////////////////////////////// 00082 // Function: SliderTable::get_slider_rows 00083 // Access: Published 00084 // Description: Returns the set of rows (vertices) governed by the 00085 // nth slider in the table. 00086 //////////////////////////////////////////////////////////////////// 00087 INLINE const SparseArray &SliderTable:: 00088 get_slider_rows(int n) const { 00089 nassertr(n >= 0 && n < (int)_sliders.size(), _empty_array); 00090 return _sliders[n]._rows; 00091 } 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function: SliderTable::find_sliders 00095 // Access: Published 00096 // Description: Returns a list of slider indices that represent the 00097 // list of sliders with the indicated name, or an empty 00098 // SparseArray if no slider in the table has that name. 00099 //////////////////////////////////////////////////////////////////// 00100 INLINE const SparseArray &SliderTable:: 00101 find_sliders(const InternalName *name) const { 00102 SlidersByName::const_iterator sni; 00103 sni = _sliders_by_name.find(name); 00104 if (sni != _sliders_by_name.end()) { 00105 return (*sni).second; 00106 } 00107 return _empty_array; 00108 } 00109 00110 //////////////////////////////////////////////////////////////////// 00111 // Function: SliderTable::has_slider 00112 // Access: Published 00113 // Description: Returns true if the table has at least one slider by 00114 // the indicated name, false otherwise. 00115 //////////////////////////////////////////////////////////////////// 00116 INLINE bool SliderTable:: 00117 has_slider(const InternalName *name) const { 00118 return (!find_sliders(name).is_zero()); 00119 } 00120 00121 //////////////////////////////////////////////////////////////////// 00122 // Function: SliderTable::is_empty 00123 // Access: Published 00124 // Description: Returns true if the table has no sliders, false if it 00125 // has at least one. 00126 //////////////////////////////////////////////////////////////////// 00127 INLINE bool SliderTable:: 00128 is_empty() const { 00129 return _sliders.empty(); 00130 } 00131 00132 //////////////////////////////////////////////////////////////////// 00133 // Function: SliderTable::get_modified 00134 // Access: Published 00135 // Description: Returns a sequence number that's guaranteed to change 00136 // at least when any VertexSliders in the table 00137 // change. (However, this is only true for a registered 00138 // table. An unregistered table may or may not 00139 // reflect an update here when a VertexSlider 00140 // changes.) 00141 //////////////////////////////////////////////////////////////////// 00142 INLINE UpdateSeq SliderTable:: 00143 get_modified(Thread *current_thread) const { 00144 CDReader cdata(_cycler, current_thread); 00145 return cdata->_modified; 00146 } 00147 00148 //////////////////////////////////////////////////////////////////// 00149 // Function: SliderTable::update_modified 00150 // Access: Private 00151 // Description: Called internally whenever a nested VertexSlider 00152 // reports that it has been modified. 00153 //////////////////////////////////////////////////////////////////// 00154 INLINE void SliderTable:: 00155 update_modified(UpdateSeq modified, Thread *current_thread) { 00156 CDWriter cdata(_cycler, true, current_thread); 00157 cdata->_modified = modified; 00158 } 00159 00160 //////////////////////////////////////////////////////////////////// 00161 // Function: SliderTable::CData::Constructor 00162 // Access: Public 00163 // Description: 00164 //////////////////////////////////////////////////////////////////// 00165 INLINE SliderTable::CData:: 00166 CData() { 00167 } 00168 00169 //////////////////////////////////////////////////////////////////// 00170 // Function: SliderTable::CData::Copy Constructor 00171 // Access: Public 00172 // Description: 00173 //////////////////////////////////////////////////////////////////// 00174 INLINE SliderTable::CData:: 00175 CData(const SliderTable::CData ©) : 00176 _modified(copy._modified) 00177 { 00178 }