Panda3D
transformBlendTable.h
1 // Filename: transformBlendTable.h
2 // Created by: drose (24Mar05)
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 #ifndef TRANSFORMBLENDTABLE_H
16 #define TRANSFORMBLENDTABLE_H
17 
18 #include "pandabase.h"
19 #include "transformBlend.h"
20 #include "vertexTransform.h"
21 #include "copyOnWriteObject.h"
22 #include "pointerTo.h"
23 #include "pvector.h"
24 #include "pmap.h"
25 #include "indirectLess.h"
26 #include "cycleData.h"
27 #include "cycleDataLockedReader.h"
28 #include "cycleDataReader.h"
29 #include "cycleDataWriter.h"
30 #include "pipelineCycler.h"
31 #include "sparseArray.h"
32 
33 class FactoryParams;
34 
35 ////////////////////////////////////////////////////////////////////
36 // Class : TransformBlendTable
37 // Description : This structure collects together the different
38 // combinations of transforms and blend amounts used by
39 // a GeomVertexData, to facilitate computing dynamic
40 // vertices on the CPU at runtime. Each vertex has a
41 // pointer to exactly one of the entries in this table,
42 // and each entry defines a number of transform/blend
43 // combinations.
44 //
45 // This structure is used for a GeomVertexData set up to
46 // compute its dynamic vertices on the CPU. See
47 // TransformTable for one set up to compute its
48 // dynamic vertices on the graphics card.
49 ////////////////////////////////////////////////////////////////////
50 class EXPCL_PANDA_GOBJ TransformBlendTable : public CopyOnWriteObject {
51 protected:
52  virtual PT(CopyOnWriteObject) make_cow_copy();
53 
54 PUBLISHED:
57  void operator = (const TransformBlendTable &copy);
58  virtual ~TransformBlendTable();
59 
60  INLINE int get_num_blends() const;
61  INLINE const TransformBlend &get_blend(int n) const;
62  MAKE_SEQ(get_blends, get_num_blends, get_blend);
63  INLINE UpdateSeq get_modified(Thread *current_thread) const;
64 
65  void set_blend(int n, const TransformBlend &blend);
66  void remove_blend(int n);
67  int add_blend(const TransformBlend &blend);
68 
69  INLINE int get_num_transforms() const;
70  INLINE int get_max_simultaneous_transforms() const;
71 
72  INLINE void set_rows(const SparseArray &rows);
73  INLINE const SparseArray &get_rows() const;
74  INLINE SparseArray &modify_rows();
75 
76  void write(ostream &out, int indent_level) const;
77 
78 private:
79  class CData;
80 
81  void clear_index();
82  INLINE void consider_rebuild_index() const;
83  void rebuild_index();
84 
85  void recompute_modified(CData *cdata, Thread *current_thread);
86  void clear_modified(Thread *current_thread);
87 
88 private:
89  // We don't bother with registering the table, or protecting its
90  // data in a CycleData structure--the interface on GeomVertexData
91  // guarantees that the pointer will be copied if we modify the
92  // table.
94  Blends _blends;
95 
96  SparseArray _rows;
97 
98  // This map indexes directly into the above vector. That means any
99  // time we add or remove anything from the vector, we must
100  // completely rebuild the index (since the vector might reallocate,
101  // invalidating all the pointers 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
108  // CycleData structure, we do need to keep a local cache of the
109  // relevant modified 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;
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 ostream &operator << (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:49
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:50
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
virtual TypeHandle get_parent_type() const
Returns the type of the container that owns the CycleData.
Definition: cycleData.cxx:91
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This is our own Panda specialization on the default STL list.
Definition: plist.h:38
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:34
This is an abstract base class that holds a pointer to some transform, computed in some arbitrary way...
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:40
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:55
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
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&#39;s make_from_bam() method to read in all...
Definition: cycleData.cxx:68
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:51
This structure collects together the different combinations of transforms and blend amounts used by a...
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is a sequence number that increments monotonically.
Definition: updateSeq.h:43
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43