Panda3D
eggSAnimData.cxx
1 // Filename: eggSAnimData.cxx
2 // Created by: drose (19Feb99)
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 #include "eggSAnimData.h"
16 #include "eggMiscFuncs.h"
17 #include "eggParameters.h"
18 
19 #include "indent.h"
20 
21 #include <math.h>
22 
23 TypeHandle EggSAnimData::_type_handle;
24 
25 ////////////////////////////////////////////////////////////////////
26 // Function: EggSAnimData::optimize
27 // Access: Public
28 // Description: Optimizes the data by collapsing a long table of
29 // duplicate values into a single value.
30 ////////////////////////////////////////////////////////////////////
31 void EggSAnimData::
33  if (get_num_rows() > 1) {
34  double value = get_value(0);
35  for (int row = 1; row < get_num_rows(); row++) {
36  if (fabs(get_value(row) - value) > egg_parameters->_table_threshold) {
37  return;
38  }
39  }
40 
41  // Ok, all the rows had the same value. Collapse them.
42 
43  // We have to use the call to v() to work around an apparent compiler bug with Win64.
44  _data.v().erase(_data.v().begin() + 1, _data.v().end());
45  }
46 }
47 
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: EggSAnimData::write
51 // Access: Public, Virtual
52 // Description: Writes the data to the indicated output stream in Egg
53 // format.
54 ////////////////////////////////////////////////////////////////////
55 void EggSAnimData::
56 write(ostream &out, int indent_level) const {
57  if (get_num_rows() <= 1) {
58  // We get a lot of these little tiny tables. For brevity, we'll
59  // write these all on one line, because we can. This just makes
60  // it easier for a human to scan the egg file.
61 
62  indent(out, indent_level) << "<S$Anim> ";
63  if (has_name()) {
64  enquote_string(out, get_name()) << " {";
65  } else {
66  out << "{";
67  }
68 
69  if (has_fps()) {
70  out << " <Scalar> fps { " << get_fps() << " }";
71  }
72 
73  if (get_num_rows() == 1) {
74  out << " <V> { " << get_value(0) << " }";
75  } else {
76  out << " <V> { }";
77  }
78 
79  out << " }\n";
80 
81  } else {
82  // If there are at least two values in the table, we'll write it
83  // out over multiple lines.
84 
85  write_header(out, indent_level, "<S$Anim>");
86 
87  if (has_fps()) {
88  indent(out, indent_level + 2)
89  << "<Scalar> fps { " << get_fps() << " }\n";
90  }
91  indent(out, indent_level + 2) << "<V> {\n";
92  write_long_list(out, indent_level + 4, _data.begin(), _data.end(),
93  "", "", 72);
94  indent(out, indent_level + 2) << "}\n";
95  indent(out, indent_level) << "}\n";
96  }
97 }
void optimize()
Optimizes the data by collapsing a long table of duplicate values into a single value.
virtual void write(ostream &out, int indent_level) const
Writes the data to the indicated output stream in Egg format.
double get_value(int row) const
Returns the value at the indicated row.
Definition: eggSAnimData.I:68
double get_fps() const
This is only valid if has_fps() returns true.
Definition: eggAnimData.I:94
void write_header(ostream &out, int indent_level, const char *egg_keyword) const
Writes the first line of the egg object, e.g.
int get_num_rows() const
Returns the number of rows in the table.
Definition: eggSAnimData.I:56
bool has_name() const
Returns true if the Namable has a nonempty name set, false if the name is empty.
Definition: namable.I:75
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85