Panda3D
sliderTable.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 sliderTable.h
10  * @author drose
11  * @date 2005-03-28
12  */
13 
14 #ifndef SLIDERTABLE_H
15 #define SLIDERTABLE_H
16 
17 #include "pandabase.h"
18 #include "vertexSlider.h"
20 #include "pointerTo.h"
21 #include "pmap.h"
22 #include "cycleData.h"
23 #include "cycleDataReader.h"
24 #include "cycleDataWriter.h"
25 #include "pipelineCycler.h"
26 #include "sparseArray.h"
27 
28 /**
29  * Stores the total set of VertexSliders that the vertices in a particular
30  * GeomVertexData object might depend on.
31  *
32  * This is similar to a TransformTable, but it stores VertexSliders instead of
33  * VertexTransforms, and it stores them by name instead of by index number.
34  * Also, it is only used when animating vertices on the CPU, since GPU's don't
35  * support morphs at this point in time.
36  */
37 class EXPCL_PANDA_GOBJ SliderTable : public TypedWritableReferenceCount {
38 PUBLISHED:
39  SliderTable();
40  SliderTable(const SliderTable &copy);
41  void operator = (const SliderTable &copy);
42  virtual ~SliderTable();
43 
44  INLINE bool is_registered() const;
45  INLINE static CPT(SliderTable) register_table(const SliderTable *table);
46 
47  INLINE size_t get_num_sliders() const;
48  INLINE const VertexSlider *get_slider(size_t n) const;
49  MAKE_SEQ(get_sliders, get_num_sliders, get_slider);
50  INLINE const SparseArray &get_slider_rows(size_t n) const;
51 
52  INLINE const SparseArray &find_sliders(const InternalName *name) const;
53  INLINE bool has_slider(const InternalName *name) const;
54  INLINE bool is_empty() const;
55  INLINE UpdateSeq get_modified(Thread *current_thread = Thread::get_current_thread()) const;
56  MAKE_PROPERTY(modified, get_modified);
57 
58  void set_slider(size_t n, const VertexSlider *slider);
59  void set_slider_rows(size_t n, const SparseArray &rows);
60  void remove_slider(size_t n);
61  size_t add_slider(const VertexSlider *slider, const SparseArray &rows);
62 
63  void write(std::ostream &out) const;
64 
65 private:
66  void do_register();
67  void do_unregister();
68  INLINE void update_modified(UpdateSeq modified, Thread *current_thread);
69 
70 private:
71  bool _is_registered;
72 
73  class SliderDef {
74  public:
75  CPT(VertexSlider) _slider;
76  SparseArray _rows;
77  };
78 
79  typedef pvector<SliderDef> Sliders;
80  Sliders _sliders;
81 
82  typedef pmap< CPT(InternalName), SparseArray > SlidersByName;
83  SlidersByName _sliders_by_name;
84 
85  static SparseArray _empty_array;
86 
87  // This is the data that must be cycled between pipeline stages.
88  class EXPCL_PANDA_GOBJ CData : public CycleData {
89  public:
90  INLINE CData();
91  INLINE CData(const CData &copy);
92  virtual CycleData *make_copy() const;
93  virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
94  virtual void fillin(DatagramIterator &scan, BamReader *manager);
95  virtual TypeHandle get_parent_type() const {
96  return SliderTable::get_class_type();
97  }
98 
99  UpdateSeq _modified;
100  };
101 
102  PipelineCycler<CData> _cycler;
103  typedef CycleDataReader<CData> CDReader;
104  typedef CycleDataWriter<CData> CDWriter;
105 
106 public:
107  static void register_with_read_factory();
108  virtual void write_datagram(BamWriter *manager, Datagram &dg);
109  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
110 
111 protected:
112  static TypedWritable *make_from_bam(const FactoryParams &params);
113  void fillin(DatagramIterator &scan, BamReader *manager);
114 
115 public:
116  static TypeHandle get_class_type() {
117  return _type_handle;
118  }
119  static void init_type() {
120  TypedWritableReferenceCount::init_type();
121  register_type(_type_handle, "SliderTable",
122  TypedWritableReferenceCount::get_class_type());
123  }
124  virtual TypeHandle get_type() const {
125  return get_class_type();
126  }
127  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
128 
129 private:
130  static TypeHandle _type_handle;
131 
132  friend class VertexSlider;
133 };
134 
135 INLINE std::ostream &operator << (std::ostream &out, const SliderTable &obj);
136 
137 #include "sliderTable.I"
138 
139 #endif
UpdateSeq
This is a sequence number that increments monotonically.
Definition: updateSeq.h:37
SliderTable
Stores the total set of VertexSliders that the vertices in a particular GeomVertexData object might d...
Definition: sliderTable.h:37
CycleData
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:50
pvector< SliderDef >
vertexSlider.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CycleData::get_parent_type
virtual TypeHandle get_parent_type() const
Returns the type of the container that owns the CycleData.
Definition: cycleData.cxx:76
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition: datagramIterator.h:27
pmap
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
register_type
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
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
BamWriter
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
InternalName
Encodes a string name in a hash table, mapping it to a pointer.
Definition: internalName.h:38
typedWritableReferenceCount.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
sliderTable.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
CycleData::write_datagram
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
Thread::get_current_thread
get_current_thread
Returns a pointer to the currently-executing Thread object.
Definition: thread.h:109
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
pmap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
CycleDataWriter
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
Definition: cycleDataWriter.h:34
cycleData.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
SparseArray
This class records a set of integers, where each integer is either present or not present in the set.
Definition: sparseArray.h:42
CycleDataReader
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
Definition: cycleDataReader.h:35
cycleDataReader.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CycleData::fillin
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
plist
This is our own Panda specialization on the default STL list.
Definition: plist.h:35
VertexSlider
This is an abstract base class that retains some slider value, which is a linear value that typically...
Definition: vertexSlider.h:37
sparseArray.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pipelineCycler.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypedWritableReferenceCount
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
Definition: typedWritableReferenceCount.h:31
cycleDataWriter.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Thread
A thread; that is, a lightweight process.
Definition: thread.h:46
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CycleData::complete_pointers
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
PipelineCycler< CData >