Panda3D
 All Classes Functions Variables Enumerations
animPreloadTable.h
1 // Filename: animPreloadTable.h
2 // Created by: drose (05Aug08)
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 ANIMPRELOADTABLE_H
16 #define ANIMPRELOADTABLE_H
17 
18 #include "pandabase.h"
19 #include "typedWritableReferenceCount.h"
20 #include "ordered_vector.h"
21 #include "copyOnWriteObject.h"
22 
23 class BamWriter;
24 class BamReader;
25 class Datagram;
26 class DatagramIterator;
27 class FactoryParams;
28 
29 ////////////////////////////////////////////////////////////////////
30 // Class : AnimPreloadTable
31 // Description : This table records data about a list of animations
32 // for a particular model, such as number of frames and
33 // frame rate. It's used for implementating
34 // asynchronous binding.
35 //
36 // This table is normally built by an offline tool, such
37 // as egg-optchar.
38 ////////////////////////////////////////////////////////////////////
39 class EXPCL_PANDA_CHAN AnimPreloadTable : public CopyOnWriteObject {
40 public:
41  class AnimRecord {
42  public:
43  INLINE AnimRecord();
44  INLINE bool operator < (const AnimRecord &other) const;
45 
46  string _basename;
47  PN_stdfloat _base_frame_rate;
48  int _num_frames;
49  };
50 
51 protected:
52  virtual PT(CopyOnWriteObject) make_cow_copy();
53 
54 PUBLISHED:
56  virtual ~AnimPreloadTable();
57 
58  int get_num_anims() const;
59  int find_anim(const string &basename) const;
60 
61  INLINE string get_basename(int n) const;
62  INLINE PN_stdfloat get_base_frame_rate(int n) const;
63  INLINE int get_num_frames(int n) const;
64 
65  void clear_anims();
66  void remove_anim(int n);
67  void add_anim(const string &basename, PN_stdfloat base_frame_rate, int num_frames);
68  void add_anims_from(const AnimPreloadTable *other);
69 
70  virtual void output(ostream &out) const;
71  virtual void write(ostream &out, int indent_level) const;
72 
73 private:
74  INLINE void consider_sort() const;
75 
76 public:
77  static void register_with_read_factory();
78  virtual void write_datagram(BamWriter *manager, Datagram &dg);
79  static TypedWritable *make_from_bam(const FactoryParams &params);
80 
81 protected:
82  void fillin(DatagramIterator &scan, BamReader *manager);
83 
84 private:
85  typedef ov_set<AnimRecord> Anims;
86  Anims _anims;
87  bool _needs_sort;
88 
89 public:
90  virtual TypeHandle get_type() const {
91  return get_class_type();
92  }
93  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
94 
95  static TypeHandle get_class_type() {
96  return _type_handle;
97  }
98  static void init_type() {
99  CopyOnWriteObject::init_type();
100  register_type(_type_handle, "AnimPreloadTable",
101  CopyOnWriteObject::get_class_type());
102  }
103 
104 private:
105  static TypeHandle _type_handle;
106 };
107 
108 inline ostream &operator << (ostream &out, const AnimPreloadTable &anim) {
109  anim.output(out);
110  return out;
111 }
112 
113 #include "animPreloadTable.I"
114 
115 #endif
116 
117 
This table records data about a list of animations for a particular model, such as number of frames a...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
A specialization of ordered_vector that emulates a standard STL set: one copy of each element is allo...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
This base class provides basic reference counting, but also can be used with a CopyOnWritePointer to ...
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
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43