Panda3D

sliderTable.I
Go to the documentation of this file.
1 /**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file sliderTable.I
10 * @author drose
11 * @date 2005-03-28
12 */
13
14 /**
15 * Returns true if this table has been registered. Once it has been
16 * registered, the set of sliders in a SliderTable may not be further
17 * modified; but it must be registered before it can be assigned to a Geom.
18 */
19 INLINE bool SliderTable::
20 is_registered() const {
21 return _is_registered;
22 }
23
24 /**
25 * Registers a SliderTable for use. This is similar to
26 * GeomVertexFormat::register_format(). Once registered, a SliderTable may no
27 * longer be modified (although the individual VertexSlider objects may modify
28 * their reported sliders).
29 *
30 * This must be called before a table may be used in a Geom. After this call,
31 * you should discard the original pointer you passed in (which may or may not
32 * now be invalid) and let its reference count decrement normally; you should
33 * use only the returned value from this point on.
34 */
35 INLINE CPT(SliderTable) SliderTable::
36 register_table(const SliderTable *table) {
37 // We don't actually bother adding the table object to a registry. This
38 // means there may be multiple copies of identical registered SliderTables.
39 // Big deal. We can always go back and make a registry later if we really
40 // need it.
41 if (table->is_registered()) {
42 return table;
43 }
44
45 ((SliderTable *)table)->do_register();
46 return table;
47 }
48
49 /**
50 * Returns the number of sliders in the table.
51 */
52 INLINE size_t SliderTable::
53 get_num_sliders() const {
54 return _sliders.size();
55 }
56
57 /**
58 * Returns the nth slider in the table.
59 */
60 INLINE const VertexSlider *SliderTable::
61 get_slider(size_t n) const {
62 nassertr(n < _sliders.size(), nullptr);
63 return _sliders[n]._slider;
64 }
65
66 /**
67 * Returns the set of rows (vertices) governed by the nth slider in the table.
68 */
69 INLINE const SparseArray &SliderTable::
70 get_slider_rows(size_t n) const {
71 nassertr(n < _sliders.size(), _empty_array);
72 return _sliders[n]._rows;
73 }
74
75 /**
76 * Returns a list of slider indices that represent the list of sliders with
77 * the indicated name, or an empty SparseArray if no slider in the table has
78 * that name.
79 */
80 INLINE const SparseArray &SliderTable::
81 find_sliders(const InternalName *name) const {
82 SlidersByName::const_iterator sni;
83 sni = _sliders_by_name.find(name);
84 if (sni != _sliders_by_name.end()) {
85 return (*sni).second;
86 }
87 return _empty_array;
88 }
89
90 /**
91 * Returns true if the table has at least one slider by the indicated name,
92 * false otherwise.
93 */
94 INLINE bool SliderTable::
95 has_slider(const InternalName *name) const {
96 return (!find_sliders(name).is_zero());
97 }
98
99 /**
100 * Returns true if the table has no sliders, false if it has at least one.
101 */
102 INLINE bool SliderTable::
103 is_empty() const {
104 return _sliders.empty();
105 }
106
107 /**
108 * Returns a sequence number that's guaranteed to change at least when any
109 * VertexSliders in the table change. (However, this is only true for a
110 * registered table. An unregistered table may or may not reflect an update
111 * here when a VertexSlider changes.)
112 */
113 INLINE UpdateSeq SliderTable::
114 get_modified(Thread *current_thread) const {
115 CDReader cdata(_cycler, current_thread);
116 return cdata->_modified;
117 }
118
119 /**
120 * Called internally whenever a nested VertexSlider reports that it has been
121 * modified.
122 */
123 INLINE void SliderTable::
124 update_modified(UpdateSeq modified, Thread *current_thread) {
125 CDWriter cdata(_cycler, true, current_thread);
126 cdata->_modified = modified;
127 }
128
129 /**
130 *
131 */
132 INLINE SliderTable::CData::
133 CData() {
134 }
135
136 /**
137 *
138 */
139 INLINE SliderTable::CData::
140 CData(const SliderTable::CData &copy) :
141 _modified(copy._modified)
142 {
143 }
InternalName
Encodes a string name in a hash table, mapping it to a pointer.
Definition: internalName.h:38
SliderTable
Stores the total set of VertexSliders that the vertices in a particular GeomVertexData object might d...
Definition: sliderTable.h:37
SliderTable::is_registered
bool is_registered() const
Returns true if this table has been registered.
Definition: sliderTable.I:20
SliderTable::has_slider
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:95
SliderTable::get_slider
get_slider
Returns the nth slider in the table.
Definition: sliderTable.h:49
SliderTable::find_sliders
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:81
SliderTable::is_empty
bool is_empty() const
Returns true if the table has no sliders, false if it has at least one.
Definition: sliderTable.I:103
SliderTable::get_num_sliders
get_num_sliders
Returns the number of sliders in the table.
Definition: sliderTable.h:49
SliderTable::get_modified
get_modified
Returns a sequence number that's guaranteed to change at least when any VertexSliders in the table ch...
Definition: sliderTable.h:56
SliderTable::get_slider_rows
const SparseArray & get_slider_rows(size_t n) const
Returns the set of rows (vertices) governed by the nth slider in the table.
Definition: sliderTable.I:70
SparseArray
This class records a set of integers, where each integer is either present or not present in the set.
Definition: sparseArray.h:43
Thread
A thread; that is, a lightweight process.
Definition: thread.h:46
UpdateSeq
This is a sequence number that increments monotonically.
Definition: updateSeq.h:37
VertexSlider
This is an abstract base class that retains some slider value, which is a linear value that typically...
Definition: vertexSlider.h:37
CPT
CPT(SliderTable) SliderTable
Registers a SliderTable for use.
Definition: sliderTable.I:35