Panda3D
sliderTable.I
1 // Filename: sliderTable.I
2 // Created by: drose (28Mar05)
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: SliderTable::is_registered
18 // Access: Published
19 // Description: Returns true if this table has been registered.
20 // Once it has been registered, the set of sliders in
21 // a SliderTable may not be further modified; but
22 // it must be registered before it can be assigned to a
23 // Geom.
24 ////////////////////////////////////////////////////////////////////
25 INLINE bool SliderTable::
26 is_registered() const {
27  return _is_registered;
28 }
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: SliderTable::register_table
32 // Access: Published, Static
33 // Description: Registers a SliderTable for use. This is
34 // similar to GeomVertexFormat::register_format(). Once
35 // registered, a SliderTable may no longer be
36 // modified (although the individual VertexSlider
37 // objects may modify their reported sliders).
38 //
39 // This must be called before a table may be used in a
40 // Geom. After this call, you should discard the
41 // original pointer you passed in (which may or may not
42 // now be invalid) and let its reference count decrement
43 // normally; you should use only the returned value from
44 // this point on.
45 ////////////////////////////////////////////////////////////////////
46 INLINE CPT(SliderTable) SliderTable::
47 register_table(const SliderTable *table) {
48  // We don't actually bother adding the table object to a registry.
49  // This means there may be multiple copies of identical registered
50  // SliderTables. Big deal. We can always go back and make a
51  // registry later if we really need it.
52  if (table->is_registered()) {
53  return table;
54  }
55 
56  ((SliderTable *)table)->do_register();
57  return table;
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: SliderTable::get_num_sliders
62 // Access: Published
63 // Description: Returns the number of sliders in the table.
64 ////////////////////////////////////////////////////////////////////
65 INLINE int SliderTable::
66 get_num_sliders() const {
67  return _sliders.size();
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: SliderTable::get_slider
72 // Access: Published
73 // Description: Returns the nth slider in the table.
74 ////////////////////////////////////////////////////////////////////
75 INLINE const VertexSlider *SliderTable::
76 get_slider(int n) const {
77  nassertr(n >= 0 && n < (int)_sliders.size(), NULL);
78  return _sliders[n]._slider;
79 }
80 
81 ////////////////////////////////////////////////////////////////////
82 // Function: SliderTable::get_slider_rows
83 // Access: Published
84 // Description: Returns the set of rows (vertices) governed by the
85 // nth slider in the table.
86 ////////////////////////////////////////////////////////////////////
87 INLINE const SparseArray &SliderTable::
88 get_slider_rows(int n) const {
89  nassertr(n >= 0 && n < (int)_sliders.size(), _empty_array);
90  return _sliders[n]._rows;
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function: SliderTable::find_sliders
95 // Access: Published
96 // Description: Returns a list of slider indices that represent the
97 // list of sliders with the indicated name, or an empty
98 // SparseArray if no slider in the table has that name.
99 ////////////////////////////////////////////////////////////////////
100 INLINE const SparseArray &SliderTable::
101 find_sliders(const InternalName *name) const {
102  SlidersByName::const_iterator sni;
103  sni = _sliders_by_name.find(name);
104  if (sni != _sliders_by_name.end()) {
105  return (*sni).second;
106  }
107  return _empty_array;
108 }
109 
110 ////////////////////////////////////////////////////////////////////
111 // Function: SliderTable::has_slider
112 // Access: Published
113 // Description: Returns true if the table has at least one slider by
114 // the indicated name, false otherwise.
115 ////////////////////////////////////////////////////////////////////
116 INLINE bool SliderTable::
117 has_slider(const InternalName *name) const {
118  return (!find_sliders(name).is_zero());
119 }
120 
121 ////////////////////////////////////////////////////////////////////
122 // Function: SliderTable::is_empty
123 // Access: Published
124 // Description: Returns true if the table has no sliders, false if it
125 // has at least one.
126 ////////////////////////////////////////////////////////////////////
127 INLINE bool SliderTable::
128 is_empty() const {
129  return _sliders.empty();
130 }
131 
132 ////////////////////////////////////////////////////////////////////
133 // Function: SliderTable::get_modified
134 // Access: Published
135 // Description: Returns a sequence number that's guaranteed to change
136 // at least when any VertexSliders in the table
137 // change. (However, this is only true for a registered
138 // table. An unregistered table may or may not
139 // reflect an update here when a VertexSlider
140 // changes.)
141 ////////////////////////////////////////////////////////////////////
143 get_modified(Thread *current_thread) const {
144  CDReader cdata(_cycler, current_thread);
145  return cdata->_modified;
146 }
147 
148 ////////////////////////////////////////////////////////////////////
149 // Function: SliderTable::update_modified
150 // Access: Private
151 // Description: Called internally whenever a nested VertexSlider
152 // reports that it has been modified.
153 ////////////////////////////////////////////////////////////////////
154 INLINE void SliderTable::
155 update_modified(UpdateSeq modified, Thread *current_thread) {
156  CDWriter cdata(_cycler, true, current_thread);
157  cdata->_modified = modified;
158 }
159 
160 ////////////////////////////////////////////////////////////////////
161 // Function: SliderTable::CData::Constructor
162 // Access: Public
163 // Description:
164 ////////////////////////////////////////////////////////////////////
165 INLINE SliderTable::CData::
166 CData() {
167 }
168 
169 ////////////////////////////////////////////////////////////////////
170 // Function: SliderTable::CData::Copy Constructor
171 // Access: Public
172 // Description:
173 ////////////////////////////////////////////////////////////////////
174 INLINE SliderTable::CData::
175 CData(const SliderTable::CData &copy) :
176  _modified(copy._modified)
177 {
178 }
This class records a set of integers, where each integer is either present or not present in the set...
Definition: sparseArray.h:49
const SparseArray & get_slider_rows(int n) const
Returns the set of rows (vertices) governed by the nth slider in the table.
Definition: sliderTable.I:88
UpdateSeq get_modified(Thread *current_thread) const
Returns a sequence number that&#39;s guaranteed to change at least when any VertexSliders in the table ch...
Definition: sliderTable.I:143
This is an abstract base class that retains some slider value, which is a linear value that typically...
Definition: vertexSlider.h:41
bool has_slider(const InternalName *name) const
Returns true if the table has at least one slider by the indicated name, false otherwise.
Definition: sliderTable.I:117
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
Stores the total set of VertexSliders that the vertices in a particular GeomVertexData object might d...
Definition: sliderTable.h:42
const SparseArray & find_sliders(const InternalName *name) const
Returns a list of slider indices that represent the list of sliders with the indicated name...
Definition: sliderTable.I:101
const VertexSlider * get_slider(int n) const
Returns the nth slider in the table.
Definition: sliderTable.I:76
int get_num_sliders() const
Returns the number of sliders in the table.
Definition: sliderTable.I:66
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
bool is_empty() const
Returns true if the table has no sliders, false if it has at least one.
Definition: sliderTable.I:128
bool is_registered() const
Returns true if this table has been registered.
Definition: sliderTable.I:26
A thread; that is, a lightweight process.
Definition: thread.h:51
This is a sequence number that increments monotonically.
Definition: updateSeq.h:43