Browse Source

add sort_filename

David Rose 20 years ago
parent
commit
d122e0084b

+ 8 - 0
panda/src/egg/eggFilenameNode.h

@@ -46,6 +46,14 @@ PUBLISHED:
   INLINE const Filename &get_fullpath() const;
   INLINE void set_fullpath(const Filename &fullpath);
 
+public:
+  class IndirectOrderByBasename {
+  public:
+    bool operator () (const EggFilenameNode *a, const EggFilenameNode *b) const {
+      return a->get_filename().get_basename() < b->get_filename().get_basename();
+    }
+  };
+
 private:
   Filename _filename;
   Filename _fullpath;

+ 14 - 0
panda/src/egg/eggTextureCollection.cxx

@@ -421,6 +421,20 @@ sort_by_tref() {
        NamableOrderByName());
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: EggTextureCollection::sort_by_basename
+//       Access: Public
+//  Description: Sorts all the textures into alphabetical order by
+//               the basename part (including extension) of the
+//               filename.  Subsequent operations using begin()/end()
+//               will traverse in this sorted order.
+////////////////////////////////////////////////////////////////////
+void EggTextureCollection::
+sort_by_basename() {
+  sort(_ordered_textures.begin(), _ordered_textures.end(),
+       EggFilenameNode::IndirectOrderByBasename());
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: EggTextureCollection::add_texture
 //       Access: Public

+ 1 - 0
panda/src/egg/eggTextureCollection.h

@@ -83,6 +83,7 @@ PUBLISHED:
 
   void uniquify_trefs();
   void sort_by_tref();
+  void sort_by_basename();
 
 public:
   // Can be used to traverse all the textures in the collection, in