Panda3D
 All Classes Functions Variables Enumerations
sliderTable.h
00001 // Filename: sliderTable.h
00002 // Created by:  drose (28Mar05)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef SLIDERTABLE_H
00016 #define SLIDERTABLE_H
00017 
00018 #include "pandabase.h"
00019 #include "vertexSlider.h"
00020 #include "typedWritableReferenceCount.h"
00021 #include "pointerTo.h"
00022 #include "pmap.h"
00023 #include "cycleData.h"
00024 #include "cycleDataReader.h"
00025 #include "cycleDataWriter.h"
00026 #include "pipelineCycler.h"
00027 #include "sparseArray.h"
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //       Class : SliderTable
00031 // Description : Stores the total set of VertexSliders that the
00032 //               vertices in a particular GeomVertexData object might
00033 //               depend on.
00034 //
00035 //               This is similar to a TransformTable, but it stores
00036 //               VertexSliders instead of VertexTransforms, and it
00037 //               stores them by name instead of by index number.
00038 //               Also, it is only used when animating vertices on the
00039 //               CPU, since GPU's don't support morphs at this point
00040 //               in time.
00041 ////////////////////////////////////////////////////////////////////
00042 class EXPCL_PANDA_GOBJ SliderTable : public TypedWritableReferenceCount {
00043 PUBLISHED:
00044   SliderTable();
00045   SliderTable(const SliderTable &copy);
00046   void operator = (const SliderTable &copy);
00047   virtual ~SliderTable();
00048 
00049   INLINE bool is_registered() const;
00050   INLINE static CPT(SliderTable) register_table(const SliderTable *table);
00051 
00052   INLINE int get_num_sliders() const;
00053   INLINE const VertexSlider *get_slider(int n) const;
00054   MAKE_SEQ(get_sliders, get_num_sliders, get_slider);
00055   INLINE const SparseArray &get_slider_rows(int n) const;
00056 
00057   INLINE const SparseArray &find_sliders(const InternalName *name) const;
00058   INLINE bool has_slider(const InternalName *name) const;
00059   INLINE bool is_empty() const;
00060   INLINE UpdateSeq get_modified(Thread *current_thread) const;
00061 
00062   void set_slider(int n, const VertexSlider *slider);
00063   void set_slider_rows(int n, const SparseArray &rows);
00064   void remove_slider(int n);
00065   int add_slider(const VertexSlider *slider, const SparseArray &rows);
00066 
00067   void write(ostream &out) const;
00068 
00069 private:
00070   void do_register();
00071   void do_unregister();
00072   INLINE void update_modified(UpdateSeq modified, Thread *current_thread);
00073 
00074 private:
00075   bool _is_registered;
00076 
00077   class SliderDef {
00078   public:
00079     CPT(VertexSlider) _slider;
00080     SparseArray _rows;
00081   };
00082 
00083   typedef pvector<SliderDef> Sliders;
00084   Sliders _sliders;
00085 
00086   typedef pmap< CPT(InternalName), SparseArray > SlidersByName;
00087   SlidersByName _sliders_by_name;
00088 
00089   static SparseArray _empty_array;
00090 
00091   // This is the data that must be cycled between pipeline stages.
00092   class EXPCL_PANDA_GOBJ CData : public CycleData {
00093   public:
00094     INLINE CData();
00095     INLINE CData(const CData &copy);
00096     virtual CycleData *make_copy() const;
00097     virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
00098     virtual void fillin(DatagramIterator &scan, BamReader *manager);
00099     virtual TypeHandle get_parent_type() const {
00100       return SliderTable::get_class_type();
00101     }
00102 
00103     UpdateSeq _modified;
00104   };
00105 
00106   PipelineCycler<CData> _cycler;
00107   typedef CycleDataReader<CData> CDReader;
00108   typedef CycleDataWriter<CData> CDWriter;
00109 
00110 public:
00111   static void register_with_read_factory();
00112   virtual void write_datagram(BamWriter *manager, Datagram &dg);
00113   virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
00114 
00115 protected:
00116   static TypedWritable *make_from_bam(const FactoryParams &params);
00117   void fillin(DatagramIterator &scan, BamReader *manager);
00118 
00119 public:
00120   static TypeHandle get_class_type() {
00121     return _type_handle;
00122   }
00123   static void init_type() {
00124     TypedWritableReferenceCount::init_type();
00125     register_type(_type_handle, "SliderTable",
00126                   TypedWritableReferenceCount::get_class_type());
00127   }
00128   virtual TypeHandle get_type() const {
00129     return get_class_type();
00130   }
00131   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00132 
00133 private:
00134   static TypeHandle _type_handle;
00135 
00136   friend class VertexSlider;
00137 };
00138 
00139 INLINE ostream &operator << (ostream &out, const SliderTable &obj);
00140 
00141 #include "sliderTable.I"
00142 
00143 #endif
 All Classes Functions Variables Enumerations