From e3136204dfb2c4585206e56306b97366b26bc884 Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 9 Jun 2003 21:55:17 +0000 Subject: [PATCH] output anim tables in standard order --- panda/src/egg/eggXfmSAnim.cxx | 49 ++++++++++++++++++++++++++++++++--- panda/src/egg/eggXfmSAnim.h | 6 +++-- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/panda/src/egg/eggXfmSAnim.cxx b/panda/src/egg/eggXfmSAnim.cxx index 7ad6990a9f..10da746848 100644 --- a/panda/src/egg/eggXfmSAnim.cxx +++ b/panda/src/egg/eggXfmSAnim.cxx @@ -35,7 +35,12 @@ TypeHandle EggXfmSAnim::_type_handle; // incorrect behavior of decompose_matrix(). When we have a new // egg-optchar, we can safely remove the old decompose_matrix() and // restore the correct standard order (above). -string EggXfmSAnim::_standard_order = "sphrt"; +const string EggXfmSAnim::_standard_order = "sphrt"; + +// These are the table ID's of all tables we support, in the order we +// expect to write them to the egg file. +const string EggXfmSAnim::_table_ids = "ijkhprxyz"; +const int EggXfmSAnim::_num_table_ids = 9; //////////////////////////////////////////////////////////////////// @@ -171,7 +176,42 @@ write(ostream &out, int indent_level) const { << " order { " << get_order() << " }\n"; } - EggGroupNode::write(out, indent_level + 2); + // Rather than calling EggGroupNode::write() to write out the + // children, we do it directly here so we can control the order. We + // write out all the non-table children first, then write out the + // table children in our expected order. (Normally there are only + // table children.) + EggSAnimData *tables[_num_table_ids]; + memset(tables, 0, sizeof(EggSAnimData *) * _num_table_ids); + + const_iterator ci; + for (ci = begin(); ci != end(); ++ci) { + EggNode *child = (*ci); + if (child->is_of_type(EggSAnimData::get_class_type())) { + EggSAnimData *sanim = DCAST(EggSAnimData, *ci); + + // Each child SAnimData table should have a one-letter name. + nassertv(sanim->get_name().length() == 1); + char name = sanim->get_name()[0]; + size_t index = _table_ids.find(name); + nassertv(index != string::npos); + if (index != string::npos) { + nassertv(tables[index] == (EggSAnimData *)NULL); + tables[index] = sanim; + } + } else { + // Any non-table children are written directly. + child->write(out, indent_level + 2); + } + } + + // Now write out the table children in our normal order. + for (int i = 0; i < _num_table_ids; i++) { + if (tables[i] != (EggSAnimData *)NULL) { + tables[i]->write(out, indent_level + 2); + } + } + indent(out, indent_level) << "}\n"; } @@ -492,8 +532,9 @@ add_data(const LMatrix4d &mat) { if (empty()) { // If we have no children, create all nine tables now. - const char *table_ids = "ijkhprxyz"; - for (const char *p = table_ids; *p; p++) { + for (string::const_iterator p = _table_ids.begin(); + p != _table_ids.end(); + ++p) { EggSAnimData *sanim = new EggSAnimData(string(1, *p)); add_child(sanim); } diff --git a/panda/src/egg/eggXfmSAnim.h b/panda/src/egg/eggXfmSAnim.h index e16dc687e8..d3db8aa0d7 100644 --- a/panda/src/egg/eggXfmSAnim.h +++ b/panda/src/egg/eggXfmSAnim.h @@ -92,8 +92,10 @@ private: string _order; CoordinateSystem _coordsys; - static string _standard_order; - + static const string _standard_order; + static const string _table_ids; + static const int _num_table_ids; + public: static TypeHandle get_class_type() {