Panda3D
 All Classes Functions Variables Enumerations
nodePathComponent.h
00001 // Filename: nodePathComponent.h
00002 // Created by:  drose (25Feb02)
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 NODEPATHCOMPONENT_H
00016 #define NODEPATHCOMPONENT_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "pandaNode.h"
00021 #include "pointerTo.h"
00022 #include "referenceCount.h"
00023 #include "cycleData.h"
00024 #include "cycleDataReader.h"
00025 #include "cycleDataWriter.h"
00026 #include "cycleDataLockedStageReader.h"
00027 #include "cycleDataStageReader.h"
00028 #include "cycleDataStageWriter.h"
00029 #include "lightMutex.h"
00030 #include "deletedChain.h"
00031 
00032 ////////////////////////////////////////////////////////////////////
00033 //       Class : NodePathComponent
00034 // Description : This is one component of a NodePath.  These are
00035 //               stored on each PandaNode, as many as one for each of
00036 //               the possible instances of the node (but they only
00037 //               exist when they are requested, to minimize memory
00038 //               waste).  A NodePath represents a singly-linked list
00039 //               of these from an arbitrary component in the graph to
00040 //               the root.
00041 //
00042 //               This whole NodePath system is used to disambiguate
00043 //               instances in the scene graph, and the
00044 //               NodePathComponents are stored in the nodes themselves
00045 //               to allow the nodes to keep these up to date as the
00046 //               scene graph is manipulated.
00047 ////////////////////////////////////////////////////////////////////
00048 class EXPCL_PANDA_PGRAPH NodePathComponent : public ReferenceCount {
00049 private:
00050   NodePathComponent(PandaNode *node, NodePathComponent *next,
00051                     int pipeline_stage, Thread *current_thread);
00052   INLINE NodePathComponent(const NodePathComponent &copy);
00053   INLINE void operator = (const NodePathComponent &copy);
00054 
00055 public:
00056   INLINE ~NodePathComponent();
00057   ALLOC_DELETED_CHAIN(NodePathComponent);
00058   
00059   INLINE PandaNode *get_node() const;
00060   INLINE bool has_key() const;
00061   int get_key() const;
00062   bool is_top_node(int pipeline_stage, Thread *current_thread) const;
00063   
00064   NodePathComponent *get_next(int pipeline_stage, Thread *current_thread) const;
00065   int get_length(int pipeline_stage, Thread *current_thread) const;
00066 
00067   bool fix_length(int pipeline_stage, Thread *current_thread);
00068 
00069   void output(ostream &out) const;
00070   
00071 private:
00072   void set_next(NodePathComponent *next, int pipeline_stage, Thread *current_thread);
00073   void set_top_node(int pipeline_stage, Thread *current_thread);
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_PGRAPH CData : public CycleData {
00084   public:
00085     INLINE CData();
00086     CData(const CData &copy);
00087     ALLOC_DELETED_CHAIN(CData);
00088     virtual CycleData *make_copy() const;
00089     virtual TypeHandle get_parent_type() const {
00090       return NodePathComponent::get_class_type();
00091     }
00092 
00093     PT(NodePathComponent) _next;
00094     int _length;
00095     
00096   public:
00097     static TypeHandle get_class_type() {
00098       return _type_handle;
00099     }
00100     static void init_type() {
00101       register_type(_type_handle, "NodePathComponent::CData");
00102     }
00103     
00104   private:
00105     static TypeHandle _type_handle;
00106   };
00107 
00108   PipelineCycler<CData> _cycler;
00109   typedef CycleDataReader<CData> CDReader;
00110   typedef CycleDataWriter<CData> CDWriter;
00111   typedef CycleDataLockedStageReader<CData> CDLockedStageReader;
00112   typedef CycleDataStageReader<CData> CDStageReader;
00113   typedef CycleDataStageWriter<CData> CDStageWriter;
00114 
00115   static int _next_key;
00116   static LightMutex _key_lock;
00117 
00118 public:
00119   static TypeHandle get_class_type() {
00120     return _type_handle;
00121   }
00122   static void init_type() {
00123     ReferenceCount::init_type();
00124     register_type(_type_handle, "NodePathComponent",
00125                   ReferenceCount::get_class_type());
00126     CData::init_type();
00127   }
00128   
00129 private:
00130   static TypeHandle _type_handle;
00131   friend class PandaNode;
00132 };
00133 
00134 INLINE ostream &operator << (ostream &out, const NodePathComponent &comp);
00135 
00136 #include "nodePathComponent.I"
00137 
00138 #endif
 All Classes Functions Variables Enumerations