Panda3D
animPreloadTable.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 animPreloadTable.h
10  * @author drose
11  * @date 2008-08-05
12  */
13 
14 #ifndef ANIMPRELOADTABLE_H
15 #define ANIMPRELOADTABLE_H
16 
17 #include "pandabase.h"
19 #include "ordered_vector.h"
20 #include "copyOnWriteObject.h"
21 
22 class BamWriter;
23 class BamReader;
24 class Datagram;
25 class DatagramIterator;
26 class FactoryParams;
27 
28 /**
29  * This table records data about a list of animations for a particular model,
30  * such as number of frames and frame rate. It's used for implementating
31  * asynchronous binding.
32  *
33  * This table is normally built by an offline tool, such as egg-optchar.
34  */
35 class EXPCL_PANDA_CHAN AnimPreloadTable : public CopyOnWriteObject {
36 public:
37  class AnimRecord {
38  public:
39  INLINE AnimRecord();
40  INLINE bool operator < (const AnimRecord &other) const;
41 
42  std::string _basename;
43  PN_stdfloat _base_frame_rate;
44  int _num_frames;
45  };
46 
47 protected:
48  virtual PT(CopyOnWriteObject) make_cow_copy();
49 
50 PUBLISHED:
52  virtual ~AnimPreloadTable();
53 
54  int get_num_anims() const;
55  int find_anim(const std::string &basename) const;
56 
57  INLINE std::string get_basename(int n) const;
58  INLINE PN_stdfloat get_base_frame_rate(int n) const;
59  INLINE int get_num_frames(int n) const;
60 
61  void clear_anims();
62  void remove_anim(int n);
63  void add_anim(const std::string &basename, PN_stdfloat base_frame_rate, int num_frames);
64  void add_anims_from(const AnimPreloadTable *other);
65 
66  virtual void output(std::ostream &out) const;
67  virtual void write(std::ostream &out, int indent_level) const;
68 
69 private:
70  INLINE void consider_sort() const;
71 
72 public:
73  static void register_with_read_factory();
74  virtual void write_datagram(BamWriter *manager, Datagram &dg);
75  static TypedWritable *make_from_bam(const FactoryParams &params);
76 
77 protected:
78  void fillin(DatagramIterator &scan, BamReader *manager);
79 
80 private:
81  typedef ov_set<AnimRecord> Anims;
82  Anims _anims;
83  bool _needs_sort;
84 
85 public:
86  virtual TypeHandle get_type() const {
87  return get_class_type();
88  }
89  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
90 
91  static TypeHandle get_class_type() {
92  return _type_handle;
93  }
94  static void init_type() {
95  CopyOnWriteObject::init_type();
96  register_type(_type_handle, "AnimPreloadTable",
97  CopyOnWriteObject::get_class_type());
98  }
99 
100 private:
101  static TypeHandle _type_handle;
102 };
103 
104 inline std::ostream &operator << (std::ostream &out, const AnimPreloadTable &anim) {
105  anim.output(out);
106  return out;
107 }
108 
109 #include "animPreloadTable.I"
110 
111 #endif
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
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
animPreloadTable.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
typedWritableReferenceCount.h
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
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
copyOnWriteObject.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
TypedWritable::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: typedWritable.cxx:54
CopyOnWriteObject
This base class provides basic reference counting, but also can be used with a CopyOnWritePointer to ...
Definition: copyOnWriteObject.h:41
ordered_vector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
AnimPreloadTable
This table records data about a list of animations for a particular model, such as number of frames a...
Definition: animPreloadTable.h:35
TypedWritable::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: typedWritable.cxx:103
ov_set< AnimRecord >
AnimPreloadTable::AnimRecord
Definition: animPreloadTable.h:37