Panda3D
|
00001 // Filename: attribNodeRegistry.h 00002 // Created by: drose (07Jul07) 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 #ifndef ATTRIBNODEREGISTRY_H 00016 #define ATTRIBNODEREGISTRY_H 00017 00018 #include "pandabase.h" 00019 #include "nodePath.h" 00020 #include "ordered_vector.h" 00021 #include "lightMutex.h" 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Class : AttribNodeRegistry 00025 // Description : This global object records NodePaths that are 00026 // referenced by scene graph attribs, such as 00027 // ClipPlaneAttribs and LightAttribs. 00028 // 00029 // Its primary purpose is to unify attribs that are 00030 // loaded in from bam files. Attrib nodes are 00031 // identified by name and type; when a bam file that 00032 // contains references to some attrib nodes is loaded, 00033 // those nodes are first looked up here in the 00034 // AttribNodeRegistry. If there is a match (by name and 00035 // node type), the identified node is used instead of 00036 // the node referenced within the bam file itself. 00037 //////////////////////////////////////////////////////////////////// 00038 class EXPCL_PANDA_PGRAPH AttribNodeRegistry { 00039 protected: 00040 AttribNodeRegistry(); 00041 00042 PUBLISHED: 00043 void add_node(const NodePath &attrib_node); 00044 bool remove_node(const NodePath &attrib_node); 00045 NodePath lookup_node(const NodePath &orig_node) const; 00046 00047 int get_num_nodes() const; 00048 NodePath get_node(int n) const; 00049 MAKE_SEQ(get_nodes, get_num_nodes, get_node); 00050 TypeHandle get_node_type(int n) const; 00051 string get_node_name(int n) const; 00052 00053 int find_node(const NodePath &attrib_node) const; 00054 int find_node(TypeHandle type, const string &name) const; 00055 void remove_node(int n); 00056 void clear(); 00057 00058 void output(ostream &out) const; 00059 void write(ostream &out) const; 00060 00061 INLINE static AttribNodeRegistry *get_global_ptr(); 00062 00063 private: 00064 static void make_global_ptr(); 00065 00066 class Entry { 00067 public: 00068 INLINE Entry(const NodePath &node); 00069 INLINE Entry(TypeHandle type, const string &name); 00070 INLINE bool operator < (const Entry &other) const; 00071 00072 TypeHandle _type; 00073 string _name; 00074 NodePath _node; 00075 }; 00076 00077 typedef ov_set<Entry> Entries; 00078 Entries _entries; 00079 00080 LightMutex _lock; 00081 00082 static AttribNodeRegistry * TVOLATILE _global_ptr; 00083 }; 00084 00085 #include "attribNodeRegistry.I" 00086 00087 #endif 00088