Panda3D

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