15 #ifndef TRANSFORMSTATE_H 16 #define TRANSFORMSTATE_H 18 #include "pandabase.h" 20 #include "nodeCachedReferenceCount.h" 21 #include "pointerTo.h" 24 #include "updateSeq.h" 25 #include "pStatCollector.h" 26 #include "geomEnums.h" 27 #include "lightReMutex.h" 28 #include "lightReMutexHolder.h" 29 #include "lightMutex.h" 30 #include "lightMutexHolder.h" 31 #include "config_pgraph.h" 32 #include "deletedChain.h" 33 #include "simpleHashMap.h" 34 #include "cacheStats.h" 35 #include "extension.h" 67 TransformState(
const TransformState ©);
68 void operator = (
const TransformState ©);
71 virtual ~TransformState();
72 ALLOC_DELETED_CHAIN(TransformState);
75 INLINE
bool operator != (
const TransformState &other)
const;
76 INLINE
int compare_to(
const TransformState &other)
const;
77 int compare_to(
const TransformState &other,
bool uniquify_matrix)
const;
78 bool operator == (
const TransformState &other)
const;
79 INLINE
size_t get_hash()
const;
81 static CPT(TransformState) make_identity();
82 static CPT(TransformState) make_invalid();
83 INLINE
static CPT(TransformState) make_pos(
const LVecBase3 &pos);
84 INLINE
static CPT(TransformState) make_hpr(
const LVecBase3 &hpr);
85 INLINE
static CPT(TransformState) make_quat(
const LQuaternion &quat);
86 INLINE
static CPT(TransformState) make_pos_hpr(
const LVecBase3 &pos,
88 INLINE
static CPT(TransformState) make_scale(PN_stdfloat scale);
89 INLINE
static CPT(TransformState) make_scale(
const LVecBase3 &scale);
90 INLINE
static CPT(TransformState) make_shear(
const LVecBase3 &shear);
91 INLINE
static CPT(TransformState) make_pos_hpr_scale(
const LVecBase3 &pos,
94 INLINE
static CPT(TransformState) make_pos_quat_scale(
const LVecBase3 &pos,
97 static CPT(TransformState) make_pos_hpr_scale_shear(
const LVecBase3 &pos,
101 static CPT(TransformState) make_pos_quat_scale_shear(
const LVecBase3 &pos,
105 static CPT(TransformState) make_mat(
const LMatrix4 &mat);
108 INLINE
static CPT(TransformState) make_pos2d(
const LVecBase2 &pos);
109 INLINE
static CPT(TransformState) make_rotate2d(PN_stdfloat rotate);
110 INLINE
static CPT(TransformState) make_pos_rotate2d(
const LVecBase2 &pos,
112 INLINE
static CPT(TransformState) make_scale2d(PN_stdfloat scale);
113 INLINE
static CPT(TransformState) make_scale2d(
const LVecBase2 &scale);
114 INLINE
static CPT(TransformState) make_shear2d(PN_stdfloat shear);
115 INLINE
static CPT(TransformState) make_pos_rotate_scale2d(
const LVecBase2 &pos,
118 static CPT(TransformState) make_pos_rotate_scale_shear2d(
const LVecBase2 &pos,
122 static CPT(TransformState) make_mat3(
const LMatrix3 &mat);
125 INLINE
bool is_identity()
const;
126 INLINE
bool is_invalid()
const;
127 INLINE
bool is_singular()
const;
128 INLINE
bool is_2d()
const;
130 INLINE
bool has_components()
const;
131 INLINE
bool components_given()
const;
132 INLINE
bool hpr_given()
const;
133 INLINE
bool quat_given()
const;
134 INLINE
bool has_pos()
const;
135 INLINE
bool has_hpr()
const;
136 INLINE
bool has_quat()
const;
137 INLINE
bool has_scale()
const;
138 INLINE
bool has_identity_scale()
const;
139 INLINE
bool has_uniform_scale()
const;
140 INLINE
bool has_shear()
const;
141 INLINE
bool has_nonzero_shear()
const;
142 INLINE
bool has_mat()
const;
144 INLINE
const LPoint3 &get_pos()
const;
148 INLINE
const LVecBase3 &get_scale()
const;
149 INLINE PN_stdfloat get_uniform_scale()
const;
150 INLINE
const LVecBase3 &get_shear()
const;
151 INLINE
const LMatrix4 &get_mat()
const;
154 INLINE PN_stdfloat get_rotate2d()
const;
156 INLINE PN_stdfloat get_shear2d()
const;
159 CPT(TransformState) set_pos(
const LVecBase3 &pos)
const;
160 CPT(TransformState) set_hpr(
const LVecBase3 &hpr)
const;
161 CPT(TransformState) set_quat(
const LQuaternion &quat)
const;
162 CPT(TransformState) set_scale(
const LVecBase3 &scale)
const;
163 CPT(TransformState) set_shear(
const LVecBase3 &shear)
const;
165 CPT(TransformState) set_pos2d(
const LVecBase2 &pos)
const;
166 CPT(TransformState) set_rotate2d(PN_stdfloat rotate)
const;
167 CPT(TransformState) set_scale2d(
const LVecBase2 &scale)
const;
168 CPT(TransformState) set_shear2d(PN_stdfloat shear)
const;
170 CPT(TransformState) compose(
const TransformState *other)
const;
171 CPT(TransformState) invert_compose(
const TransformState *other)
const;
173 INLINE CPT(TransformState) get_inverse()
const;
174 INLINE CPT(TransformState) get_unique()
const;
176 INLINE
int get_geom_rendering(
int geom_rendering)
const;
178 virtual bool unref()
const;
185 INLINE
int get_composition_cache_num_entries()
const;
186 INLINE
int get_invert_composition_cache_num_entries()
const;
188 INLINE
int get_composition_cache_size()
const;
189 INLINE
const TransformState *get_composition_cache_source(
int n)
const;
190 INLINE
const TransformState *get_composition_cache_result(
int n)
const;
191 INLINE
int get_invert_composition_cache_size()
const;
192 INLINE
const TransformState *get_invert_composition_cache_source(
int n)
const;
193 INLINE
const TransformState *get_invert_composition_cache_result(
int n)
const;
194 bool validate_composition_cache()
const;
195 EXTENSION(PyObject *get_composition_cache()
const);
196 EXTENSION(PyObject *get_invert_composition_cache()
const);
198 void output(ostream &out)
const;
199 void write(ostream &out,
int indent_level)
const;
200 void write_composition_cache(ostream &out,
int indent_level)
const;
202 static int get_num_states();
203 static int get_num_unused_states();
204 static int clear_cache();
205 static int garbage_collect();
206 static void list_cycles(ostream &out);
207 static void list_states(ostream &out);
208 static bool validate_states();
209 EXTENSION(
static PyObject *get_states());
210 EXTENSION(
static PyObject *get_unused_states());
214 static void init_states();
216 INLINE
static void flush_level();
219 INLINE
bool do_cache_unref()
const;
220 INLINE
bool do_node_unref()
const;
222 class CompositionCycleDescEntry {
224 INLINE CompositionCycleDescEntry(
const TransformState *obj,
225 const TransformState *result,
228 const TransformState *_obj;
229 const TransformState *_result;
234 static CPT(TransformState) return_new(TransformState *state);
235 static CPT(TransformState) return_unique(TransformState *state);
237 CPT(TransformState) do_compose(
const TransformState *other)
const;
238 CPT(TransformState) store_compose(
const TransformState *other,
const TransformState *result);
239 CPT(TransformState) do_invert_compose(
const TransformState *other)
const;
240 CPT(TransformState) store_invert_compose(
const TransformState *other,
const TransformState *result);
241 void detect_and_break_cycles();
242 static bool r_detect_cycles(
const TransformState *start_state,
243 const TransformState *current_state,
245 CompositionCycleDesc *cycle_desc);
246 static bool r_detect_reverse_cycles(
const TransformState *start_state,
247 const TransformState *current_state,
249 CompositionCycleDesc *cycle_desc);
252 void remove_cache_pointers();
262 static States *_states;
263 static CPT(TransformState) _identity_state;
264 static CPT(TransformState) _invalid_state;
283 INLINE Composition();
284 INLINE Composition(
const Composition ©);
288 const TransformState *_result;
292 CompositionCache _composition_cache;
293 CompositionCache _invert_composition_cache;
301 static int _garbage_index;
303 static bool _uniquify_matrix;
320 INLINE
void check_hash()
const;
321 INLINE
void check_singular()
const;
322 INLINE
void check_components()
const;
323 INLINE
void check_hpr()
const;
324 INLINE
void check_quat()
const;
325 INLINE
void check_norm_quat()
const;
326 INLINE
void check_mat()
const;
327 INLINE
void calc_hash();
329 void calc_singular();
330 INLINE
void calc_components();
331 void do_calc_components();
332 INLINE
void calc_hpr();
335 void calc_norm_quat();
336 INLINE
void calc_mat();
339 INLINE
void check_uniform_scale();
340 INLINE
void check_uniform_scale2d();
342 INLINE
void set_destructing();
343 INLINE
bool is_destructing()
const;
345 INLINE
void consider_update_pstats(
int old_referenced_bits)
const;
346 static void update_pstats(
int old_referenced_bits,
int new_referenced_bits);
349 F_is_identity = 0x00000001,
350 F_is_singular = 0x00000002,
351 F_singular_known = 0x00000004,
352 F_components_given = 0x00000008,
353 F_components_known = 0x00000010,
354 F_has_components = 0x00000020,
355 F_mat_known = 0x00000040,
356 F_is_invalid = 0x00000080,
357 F_quat_given = 0x00000100,
358 F_quat_known = 0x00000200,
359 F_hpr_given = 0x00000400,
360 F_hpr_known = 0x00000800,
361 F_uniform_scale = 0x00001000,
362 F_identity_scale = 0x00002000,
363 F_has_nonzero_shear = 0x00004000,
364 F_is_destructing = 0x00008000,
365 F_is_2d = 0x00010000,
366 F_hash_known = 0x00020000,
367 F_norm_quat_known = 0x00040000,
384 static void register_with_read_factory();
396 static void init_type() {
397 NodeCachedReferenceCount::init_type();
398 register_type(_type_handle,
"TransformState",
399 NodeCachedReferenceCount::get_class_type());
402 return get_class_type();
404 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
412 INLINE ostream &operator << (ostream &out,
const TransformState &state) {
417 #include "transformState.I" This is the base class for all three-component vectors and points.
This class further specializes CachedTypedWritableReferenceCount to also add a node_ref_count, for the purposes of counting the number of times the object is referenced by a "node", presumably a PandaNode.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Base class for objects that can be written to and read from Bam files.
A lightweight reentrant mutex.
void node_ref() const
Explicitly increments the reference count.
This template class implements an unordered map of keys to data, implemented as a hashtable...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
This is our own Panda specialization on the default STL vector.
A lightweight class that represents a single element that may be timed and/or counted via stats...
bool cache_unref() const
Explicitly decrements the cache reference count and the normal reference count simultaneously.
This describes the structure of a single array within a Geom data.
This is a 4-by-4 transform matrix.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void cache_ref() const
Explicitly increments the cache reference count and the normal reference count simultaneously.
This is the base class for all two-component vectors and points.
bool node_unref() const
Explicitly decrements the node reference count and the normal reference count simultaneously.
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
The default class template does not define any methods.
An STL function object class, this is intended to be used on any ordered collection of class objects ...
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
This is used to track the utilization of the TransformState and RenderState caches, for low-level performance tuning information.
This is the base quaternion class.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
This is a 3-by-3 transform matrix.
This is a sequence number that increments monotonically.
This is a standard, non-reentrant mutex, similar to the Mutex class.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
virtual bool unref() const
Explicitly decrements the reference count.