00001 // Filename: nodePathComponent.h 00002 // Created by: drose (25Feb02) 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 #ifndef NODEPATHCOMPONENT_H 00020 #define NODEPATHCOMPONENT_H 00021 00022 #include "pandabase.h" 00023 00024 #include "pandaNode.h" 00025 #include "pointerTo.h" 00026 #include "referenceCount.h" 00027 #include "cycleData.h" 00028 #include "cycleDataReader.h" 00029 #include "cycleDataWriter.h" 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Class : NodePathComponent 00033 // Description : This is one component of a NodePath. These are 00034 // stored on each PandaNode, as many as one for each of 00035 // the possible instances of the node (but they only 00036 // exist when they are requested, to minimize memory 00037 // waste). A NodePath represents a singly-linked list 00038 // of these from an arbitrary component in the graph to 00039 // the root. 00040 // 00041 // This whole NodePath system is used to disambiguate 00042 // instances in the scene graph, and the 00043 // NodePathComponents are stored in the nodes themselves 00044 // to allow the nodes to keep these up to date as the 00045 // scene graph is manipulated. 00046 //////////////////////////////////////////////////////////////////// 00047 class EXPCL_PANDA NodePathComponent : public ReferenceCount { 00048 private: 00049 INLINE NodePathComponent(PandaNode *node, NodePathComponent *next = NULL); 00050 INLINE NodePathComponent(const NodePathComponent ©); 00051 INLINE void operator = (const NodePathComponent ©); 00052 00053 public: 00054 INLINE ~NodePathComponent(); 00055 00056 INLINE PandaNode *get_node() const; 00057 int get_key() const; 00058 bool is_top_node() const; 00059 INLINE bool is_collapsed() const; 00060 00061 NodePathComponent *get_next() const; 00062 int get_length() const; 00063 INLINE NodePathComponent *get_collapsed() const; 00064 00065 bool fix_length(); 00066 NodePathComponent *uncollapse(); 00067 00068 void output(ostream &out) const; 00069 00070 private: 00071 void set_next(NodePathComponent *next); 00072 void set_top_node(); 00073 void collapse_with(NodePathComponent *next); 00074 00075 // We don't have to cycle the _node and _key elements, since these 00076 // are permanent properties of this object. (Well, the _key is 00077 // semi-permanent: it becomes permanent after it has been set the 00078 // first time.) 00079 PT(PandaNode) _node; 00080 int _key; 00081 00082 // This is the data that must be cycled between pipeline stages. 00083 class EXPCL_PANDA CData : public CycleData { 00084 public: 00085 INLINE CData(); 00086 CData(const CData ©); 00087 virtual CycleData *make_copy() const; 00088 00089 PT(NodePathComponent) _next; 00090 int _length; 00091 }; 00092 00093 PipelineCycler<CData> _cycler; 00094 typedef CycleDataReader<CData> CDReader; 00095 typedef CycleDataWriter<CData> CDWriter; 00096 00097 static int _next_key; 00098 00099 public: 00100 static TypeHandle get_class_type() { 00101 return _type_handle; 00102 } 00103 static void init_type() { 00104 ReferenceCount::init_type(); 00105 register_type(_type_handle, "NodePathComponent", 00106 ReferenceCount::get_class_type()); 00107 } 00108 00109 private: 00110 static TypeHandle _type_handle; 00111 friend class PandaNode; 00112 }; 00113 00114 INLINE ostream &operator << (ostream &out, const NodePathComponent &comp); 00115 00116 #include "nodePathComponent.I" 00117 00118 #endif