Panda3D

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