Panda3D
|
00001 // Filename: eggSAnimData.cxx 00002 // Created by: drose (19Feb99) 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 #include "eggSAnimData.h" 00016 #include "eggMiscFuncs.h" 00017 #include "eggParameters.h" 00018 00019 #include "indent.h" 00020 00021 #include <math.h> 00022 00023 TypeHandle EggSAnimData::_type_handle; 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: EggSAnimData::optimize 00027 // Access: Public 00028 // Description: Optimizes the data by collapsing a long table of 00029 // duplicate values into a single value. 00030 //////////////////////////////////////////////////////////////////// 00031 void EggSAnimData:: 00032 optimize() { 00033 if (get_num_rows() > 1) { 00034 double value = get_value(0); 00035 for (int row = 1; row < get_num_rows(); row++) { 00036 if (fabs(get_value(row) - value) > egg_parameters->_table_threshold) { 00037 return; 00038 } 00039 } 00040 00041 // Ok, all the rows had the same value. Collapse them. 00042 00043 // We have to use the call to v() to work around an apparent compiler bug with Win64. 00044 _data.v().erase(_data.v().begin() + 1, _data.v().end()); 00045 } 00046 } 00047 00048 00049 //////////////////////////////////////////////////////////////////// 00050 // Function: EggSAnimData::write 00051 // Access: Public, Virtual 00052 // Description: Writes the data to the indicated output stream in Egg 00053 // format. 00054 //////////////////////////////////////////////////////////////////// 00055 void EggSAnimData:: 00056 write(ostream &out, int indent_level) const { 00057 if (get_num_rows() <= 1) { 00058 // We get a lot of these little tiny tables. For brevity, we'll 00059 // write these all on one line, because we can. This just makes 00060 // it easier for a human to scan the egg file. 00061 00062 indent(out, indent_level) << "<S$Anim> "; 00063 if (has_name()) { 00064 enquote_string(out, get_name()) << " {"; 00065 } else { 00066 out << "{"; 00067 } 00068 00069 if (has_fps()) { 00070 out << " <Scalar> fps { " << get_fps() << " }"; 00071 } 00072 00073 if (get_num_rows() == 1) { 00074 out << " <V> { " << get_value(0) << " }"; 00075 } else { 00076 out << " <V> { }"; 00077 } 00078 00079 out << " }\n"; 00080 00081 } else { 00082 // If there are at least two values in the table, we'll write it 00083 // out over multiple lines. 00084 00085 write_header(out, indent_level, "<S$Anim>"); 00086 00087 if (has_fps()) { 00088 indent(out, indent_level + 2) 00089 << "<Scalar> fps { " << get_fps() << " }\n"; 00090 } 00091 indent(out, indent_level + 2) << "<V> {\n"; 00092 write_long_list(out, indent_level + 4, _data.begin(), _data.end(), 00093 "", "", 72); 00094 indent(out, indent_level + 2) << "}\n"; 00095 indent(out, indent_level) << "}\n"; 00096 } 00097 }