Panda3D
transformBlendTable.h
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 transformBlendTable.h
10  * @author drose
11  * @date 2005-03-24
12  */
13 
14 #ifndef TRANSFORMBLENDTABLE_H
15 #define TRANSFORMBLENDTABLE_H
16 
17 #include "pandabase.h"
18 #include "transformBlend.h"
19 #include "vertexTransform.h"
20 #include "copyOnWriteObject.h"
21 #include "pointerTo.h"
22 #include "pvector.h"
23 #include "pmap.h"
24 #include "indirectLess.h"
25 #include "cycleData.h"
26 #include "cycleDataLockedReader.h"
27 #include "cycleDataReader.h"
28 #include "cycleDataWriter.h"
29 #include "pipelineCycler.h"
30 #include "sparseArray.h"
31 
32 class FactoryParams;
33 
34 /**
35  * This structure collects together the different combinations of transforms
36  * and blend amounts used by a GeomVertexData, to facilitate computing dynamic
37  * vertices on the CPU at runtime. Each vertex has a pointer to exactly one
38  * of the entries in this table, and each entry defines a number of
39  * transform/blend combinations.
40  *
41  * This structure is used for a GeomVertexData set up to compute its dynamic
42  * vertices on the CPU. See TransformTable for one set up to compute its
43  * dynamic vertices on the graphics card.
44  */
45 class EXPCL_PANDA_GOBJ TransformBlendTable : public CopyOnWriteObject {
46 protected:
47  virtual PT(CopyOnWriteObject) make_cow_copy();
48 
49 PUBLISHED:
52  void operator = (const TransformBlendTable &copy);
53  virtual ~TransformBlendTable();
54 
55  INLINE size_t get_num_blends() const;
56  INLINE const TransformBlend &get_blend(size_t n) const;
57  MAKE_SEQ(get_blends, get_num_blends, get_blend);
58  INLINE UpdateSeq get_modified(Thread *current_thread = Thread::get_current_thread()) const;
59 
60  void set_blend(size_t n, const TransformBlend &blend);
61  void remove_blend(size_t n);
62  size_t add_blend(const TransformBlend &blend);
63 
64  INLINE int get_num_transforms() const;
65  INLINE int get_max_simultaneous_transforms() const;
66 
67  INLINE void set_rows(const SparseArray &rows);
68  INLINE const SparseArray &get_rows() const;
69  INLINE SparseArray &modify_rows();
70 
71  void write(std::ostream &out, int indent_level) const;
72 
73  MAKE_SEQ_PROPERTY(blends, get_num_blends, get_blend, set_blend, remove_blend);
74  MAKE_PROPERTY(modified, get_modified);
75  MAKE_PROPERTY(num_transforms, get_num_transforms);
76  MAKE_PROPERTY(max_simultaneous_transforms, get_max_simultaneous_transforms);
77  MAKE_PROPERTY(rows, get_rows, set_rows);
78 
79 private:
80  class CData;
81 
82  void clear_index();
83  INLINE void consider_rebuild_index() const;
84  void rebuild_index();
85 
86  void recompute_modified(CData *cdata, Thread *current_thread);
87  void clear_modified(Thread *current_thread);
88 
89 private:
90  // We don't bother with registering the table, or protecting its data in a
91  // CycleData structure--the interface on GeomVertexData guarantees that the
92  // pointer will be copied if we modify the table.
94  Blends _blends;
95 
96  SparseArray _rows;
97 
98  // This map indexes directly into the above vector. That means any time we
99  // add or remove anything from the vector, we must completely rebuild the
100  // index (since the vector might reallocate, invalidating all the pointers
101  // into it).
103  BlendIndex _blend_index;
104  int _num_transforms;
105  int _max_simultaneous_transforms;
106 
107  // Even though we don't store the actual blend table data in a CycleData
108  // structure, we do need to keep a local cache of the relevant modified
109  // stamps there, so it can be updated per-thread.
110  class EXPCL_PANDA_GOBJ CData : public CycleData {
111  public:
112  INLINE CData();
113  INLINE CData(const CData &copy);
114  virtual CycleData *make_copy() const;
115  virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
116  virtual void fillin(DatagramIterator &scan, BamReader *manager);
117  virtual TypeHandle get_parent_type() const {
118  return TransformBlendTable::get_class_type();
119  }
120 
121  UpdateSeq _modified;
122  UpdateSeq _global_modified;
123  };
124 
125  PipelineCycler<CData> _cycler;
126  typedef CycleDataLockedReader<CData> CDLockedReader;
127  typedef CycleDataReader<CData> CDReader;
128  typedef CycleDataWriter<CData> CDWriter;
129 
130 public:
131  static void register_with_read_factory();
132  virtual void write_datagram(BamWriter *manager, Datagram &dg);
133  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
134 
135 protected:
136  static TypedWritable *make_from_bam(const FactoryParams &params);
137  void fillin(DatagramIterator &scan, BamReader *manager);
138 
139 public:
140  static TypeHandle get_class_type() {
141  return _type_handle;
142  }
143  static void init_type() {
144  CopyOnWriteObject::init_type();
145  register_type(_type_handle, "TransformBlendTable",
146  CopyOnWriteObject::get_class_type());
147  }
148  virtual TypeHandle get_type() const {
149  return get_class_type();
150  }
151  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
152 
153 private:
154  static TypeHandle _type_handle;
155 
156  friend class VertexTransform;
157 };
158 
159 INLINE std::ostream &operator << (std::ostream &out, const TransformBlendTable &obj);
160 
161 #include "transformBlendTable.I"
162 
163 #endif
This class records a set of integers, where each integer is either present or not present in the set.
Definition: sparseArray.h:42
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:47
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual TypeHandle get_parent_type() const
Returns the type of the container that owns the CycleData.
Definition: cycleData.cxx:76
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
This is our own Panda specialization on the default STL list.
Definition: plist.h:35
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
virtual void write_datagram(BamWriter *, Datagram &) const
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: cycleData.cxx:32
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is an abstract base class that holds a pointer to some transform, computed in some arbitrary way...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This template class calls PipelineCycler::read() in the constructor and PipelineCycler::release_read(...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
Definition: cycleData.cxx:48
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This defines a single entry in a TransformBlendTable.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
Definition: cycleData.cxx:58
This base class provides basic reference counting, but also can be used with a CopyOnWritePointer to ...
A thread; that is, a lightweight process.
Definition: thread.h:46
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This structure collects together the different combinations of transforms and blend amounts used by a...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A class to retrieve the individual data elements previously stored in a Datagram.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
This is a sequence number that increments monotonically.
Definition: updateSeq.h:37
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.