Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/egg/eggSAnimData.cxx

Go to the documentation of this file.
00001 // Filename: eggSAnimData.cxx
00002 // Created by:  drose (19Feb99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "eggSAnimData.h"
00020 #include "eggMiscFuncs.h"
00021 #include "eggParameters.h"
00022 
00023 #include <indent.h>
00024 
00025 #include <math.h>
00026 
00027 TypeHandle EggSAnimData::_type_handle;
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: EggSAnimData::optimize
00031 //       Access: Public
00032 //  Description: Optimizes the data by collapsing a long table of
00033 //               duplicate values into a single value.
00034 ////////////////////////////////////////////////////////////////////
00035 void EggSAnimData::
00036 optimize() {
00037   if (get_num_rows() > 1) {
00038     double value = get_value(0);
00039     for (int row = 1; row < get_num_rows(); row++) {
00040       if (fabs(get_value(row) - value) > egg_parameters->_table_threshold) {
00041         return;
00042       }
00043     }
00044 
00045     // Ok, all the rows had the same value.  Collapse them.
00046     _data.erase(_data.begin() + 1, _data.end());
00047   }
00048 }
00049 
00050 
00051 ////////////////////////////////////////////////////////////////////
00052 //     Function: EggSAnimData::write
00053 //       Access: Public, Virtual
00054 //  Description: Writes the data to the indicated output stream in Egg
00055 //               format.
00056 ////////////////////////////////////////////////////////////////////
00057 void EggSAnimData::
00058 write(ostream &out, int indent_level) const {
00059   if (get_num_rows() <= 1) {
00060     // We get a lot of these little tiny tables.  For brevity, we'll
00061     // write these all on one line, because we can.  This just makes
00062     // it easier for a human to scan the egg file.
00063 
00064     indent(out, indent_level) << "<S$Anim> ";
00065     if (has_name()) {
00066       enquote_string(out, get_name()) << " {";
00067     } else {
00068       out << "{";
00069     }
00070 
00071     if (has_fps()) {
00072       out << " <Scalar> fps { " << get_fps() << " }";
00073     }
00074 
00075     if (get_num_rows() == 1) {
00076       out << " <V> { " << get_value(0) << " }";
00077     } else {
00078       out << " <V> { }";
00079     }
00080 
00081     out << " }\n";
00082 
00083   } else {
00084     // If there are at least two values in the table, we'll write it
00085     // out over multiple lines.
00086 
00087     write_header(out, indent_level, "<S$Anim>");
00088 
00089     if (has_fps()) {
00090       indent(out, indent_level + 2)
00091         << "<Scalar> fps { " << get_fps() << " }\n";
00092     }
00093     indent(out, indent_level + 2) << "<V> {\n";
00094     write_long_list(out, indent_level + 4, _data.begin(), _data.end(),
00095         "", "", 72);
00096     indent(out, indent_level + 2) << "}\n";
00097     indent(out, indent_level) << "}\n";
00098   }
00099 }

Generated on Fri May 2 00:37:55 2003 for Panda by doxygen1.3