Panda3D
 All Classes Functions Variables Enumerations
nodePathComponent.h
1 // Filename: nodePathComponent.h
2 // Created by: drose (25Feb02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef NODEPATHCOMPONENT_H
16 #define NODEPATHCOMPONENT_H
17 
18 #include "pandabase.h"
19 
20 #include "pandaNode.h"
21 #include "pointerTo.h"
22 #include "referenceCount.h"
23 #include "cycleData.h"
24 #include "cycleDataReader.h"
25 #include "cycleDataWriter.h"
26 #include "cycleDataLockedStageReader.h"
27 #include "cycleDataStageReader.h"
28 #include "cycleDataStageWriter.h"
29 #include "lightMutex.h"
30 #include "deletedChain.h"
31 
32 ////////////////////////////////////////////////////////////////////
33 // Class : NodePathComponent
34 // Description : This is one component of a NodePath. These are
35 // stored on each PandaNode, as many as one for each of
36 // the possible instances of the node (but they only
37 // exist when they are requested, to minimize memory
38 // waste). A NodePath represents a singly-linked list
39 // of these from an arbitrary component in the graph to
40 // the root.
41 //
42 // This whole NodePath system is used to disambiguate
43 // instances in the scene graph, and the
44 // NodePathComponents are stored in the nodes themselves
45 // to allow the nodes to keep these up to date as the
46 // scene graph is manipulated.
47 ////////////////////////////////////////////////////////////////////
48 class EXPCL_PANDA_PGRAPH NodePathComponent : public ReferenceCount {
49 private:
51  int pipeline_stage, Thread *current_thread);
52  INLINE NodePathComponent(const NodePathComponent &copy);
53  INLINE void operator = (const NodePathComponent &copy);
54 
55 public:
56  INLINE ~NodePathComponent();
57  ALLOC_DELETED_CHAIN(NodePathComponent);
58 
59  INLINE PandaNode *get_node() const;
60  INLINE bool has_key() const;
61  int get_key() const;
62  bool is_top_node(int pipeline_stage, Thread *current_thread) const;
63 
64  NodePathComponent *get_next(int pipeline_stage, Thread *current_thread) const;
65  int get_length(int pipeline_stage, Thread *current_thread) const;
66 
67  bool fix_length(int pipeline_stage, Thread *current_thread);
68 
69  void output(ostream &out) const;
70 
71 private:
72  void set_next(NodePathComponent *next, int pipeline_stage, Thread *current_thread);
73  void set_top_node(int pipeline_stage, Thread *current_thread);
74 
75  // We don't have to cycle the _node and _key elements, since these
76  // are permanent properties of this object. (Well, the _key is
77  // semi-permanent: it becomes permanent after it has been set the
78  // first time.)
79  PT(PandaNode) _node;
80  int _key;
81 
82  // This is the data that must be cycled between pipeline stages.
83  class EXPCL_PANDA_PGRAPH CData : public CycleData {
84  public:
85  INLINE CData();
86  CData(const CData &copy);
87  ALLOC_DELETED_CHAIN(CData);
88  virtual CycleData *make_copy() const;
89  virtual TypeHandle get_parent_type() const {
90  return NodePathComponent::get_class_type();
91  }
92 
93  PT(NodePathComponent) _next;
94  int _length;
95 
96  public:
97  static TypeHandle get_class_type() {
98  return _type_handle;
99  }
100  static void init_type() {
101  register_type(_type_handle, "NodePathComponent::CData");
102  }
103 
104  private:
105  static TypeHandle _type_handle;
106  };
107 
108  PipelineCycler<CData> _cycler;
114 
115  static int _next_key;
116  static LightMutex _key_lock;
117 
118 public:
119  static TypeHandle get_class_type() {
120  return _type_handle;
121  }
122  static void init_type() {
123  ReferenceCount::init_type();
124  register_type(_type_handle, "NodePathComponent",
125  ReferenceCount::get_class_type());
126  CData::init_type();
127  }
128 
129 private:
130  static TypeHandle _type_handle;
131  friend class PandaNode;
132 };
133 
134 INLINE ostream &operator << (ostream &out, const NodePathComponent &comp);
135 
136 #include "nodePathComponent.I"
137 
138 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This class is similar to CycleDataWriter, except it allows writing to a particular stage of the pipel...
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:50
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
This class is similar to CycleDataLockedReader, except it allows reading from a particular stage of t...
This class is similar to CycleDataReader, except it allows reading from a particular stage of the pip...
A base class for all things that want to be reference-counted.
A thread; that is, a lightweight process.
Definition: thread.h:51
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:45
This is one component of a NodePath.