Panda3D
sliderTable.h
1 // Filename: sliderTable.h
2 // Created by: drose (28Mar05)
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 SLIDERTABLE_H
16 #define SLIDERTABLE_H
17 
18 #include "pandabase.h"
19 #include "vertexSlider.h"
20 #include "typedWritableReferenceCount.h"
21 #include "pointerTo.h"
22 #include "pmap.h"
23 #include "cycleData.h"
24 #include "cycleDataReader.h"
25 #include "cycleDataWriter.h"
26 #include "pipelineCycler.h"
27 #include "sparseArray.h"
28 
29 ////////////////////////////////////////////////////////////////////
30 // Class : SliderTable
31 // Description : Stores the total set of VertexSliders that the
32 // vertices in a particular GeomVertexData object might
33 // depend on.
34 //
35 // This is similar to a TransformTable, but it stores
36 // VertexSliders instead of VertexTransforms, and it
37 // stores them by name instead of by index number.
38 // Also, it is only used when animating vertices on the
39 // CPU, since GPU's don't support morphs at this point
40 // in time.
41 ////////////////////////////////////////////////////////////////////
42 class EXPCL_PANDA_GOBJ SliderTable : public TypedWritableReferenceCount {
43 PUBLISHED:
44  SliderTable();
45  SliderTable(const SliderTable &copy);
46  void operator = (const SliderTable &copy);
47  virtual ~SliderTable();
48 
49  INLINE bool is_registered() const;
50  INLINE static CPT(SliderTable) register_table(const SliderTable *table);
51 
52  INLINE int get_num_sliders() const;
53  INLINE const VertexSlider *get_slider(int n) const;
54  MAKE_SEQ(get_sliders, get_num_sliders, get_slider);
55  INLINE const SparseArray &get_slider_rows(int n) const;
56 
57  INLINE const SparseArray &find_sliders(const InternalName *name) const;
58  INLINE bool has_slider(const InternalName *name) const;
59  INLINE bool is_empty() const;
60  INLINE UpdateSeq get_modified(Thread *current_thread) const;
61 
62  void set_slider(int n, const VertexSlider *slider);
63  void set_slider_rows(int n, const SparseArray &rows);
64  void remove_slider(int n);
65  int add_slider(const VertexSlider *slider, const SparseArray &rows);
66 
67  void write(ostream &out) const;
68 
69 private:
70  void do_register();
71  void do_unregister();
72  INLINE void update_modified(UpdateSeq modified, Thread *current_thread);
73 
74 private:
75  bool _is_registered;
76 
77  class SliderDef {
78  public:
79  CPT(VertexSlider) _slider;
80  SparseArray _rows;
81  };
82 
84  Sliders _sliders;
85 
87  SlidersByName _sliders_by_name;
88 
89  static SparseArray _empty_array;
90 
91  // This is the data that must be cycled between pipeline stages.
92  class EXPCL_PANDA_GOBJ CData : public CycleData {
93  public:
94  INLINE CData();
95  INLINE CData(const CData &copy);
96  virtual CycleData *make_copy() const;
97  virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
98  virtual void fillin(DatagramIterator &scan, BamReader *manager);
99  virtual TypeHandle get_parent_type() const {
100  return SliderTable::get_class_type();
101  }
102 
103  UpdateSeq _modified;
104  };
105 
106  PipelineCycler<CData> _cycler;
109 
110 public:
111  static void register_with_read_factory();
112  virtual void write_datagram(BamWriter *manager, Datagram &dg);
113  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
114 
115 protected:
116  static TypedWritable *make_from_bam(const FactoryParams &params);
117  void fillin(DatagramIterator &scan, BamReader *manager);
118 
119 public:
120  static TypeHandle get_class_type() {
121  return _type_handle;
122  }
123  static void init_type() {
124  TypedWritableReferenceCount::init_type();
125  register_type(_type_handle, "SliderTable",
126  TypedWritableReferenceCount::get_class_type());
127  }
128  virtual TypeHandle get_type() const {
129  return get_class_type();
130  }
131  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
132 
133 private:
134  static TypeHandle _type_handle;
135 
136  friend class VertexSlider;
137 };
138 
139 INLINE ostream &operator << (ostream &out, const SliderTable &obj);
140 
141 #include "sliderTable.I"
142 
143 #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 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
This is an abstract base class that retains some slider value, which is a linear value that typically...
Definition: vertexSlider.h:41
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 ...
Stores the total set of VertexSliders that the vertices in a particular GeomVertexData object might d...
Definition: sliderTable.h:42
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
A thread; that is, a lightweight process.
Definition: thread.h:51
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