nodePathComponent.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #ifndef NODEPATHCOMPONENT_H
  15. #define NODEPATHCOMPONENT_H
  16. #include "pandabase.h"
  17. #include "pandaNode.h"
  18. #include "pointerTo.h"
  19. #include "referenceCount.h"
  20. #include "cycleData.h"
  21. #include "cycleDataReader.h"
  22. #include "cycleDataWriter.h"
  23. #include "cycleDataLockedStageReader.h"
  24. #include "cycleDataStageReader.h"
  25. #include "cycleDataStageWriter.h"
  26. #include "lightMutex.h"
  27. #include "deletedChain.h"
  28. ////////////////////////////////////////////////////////////////////
  29. // Class : NodePathComponent
  30. // Description : This is one component of a NodePath. These are
  31. // stored on each PandaNode, as many as one for each of
  32. // the possible instances of the node (but they only
  33. // exist when they are requested, to minimize memory
  34. // waste). A NodePath represents a singly-linked list
  35. // of these from an arbitrary component in the graph to
  36. // the root.
  37. //
  38. // This whole NodePath system is used to disambiguate
  39. // instances in the scene graph, and the
  40. // NodePathComponents are stored in the nodes themselves
  41. // to allow the nodes to keep these up to date as the
  42. // scene graph is manipulated.
  43. ////////////////////////////////////////////////////////////////////
  44. class EXPCL_PANDA_PGRAPH NodePathComponent : public ReferenceCount {
  45. private:
  46. NodePathComponent(PandaNode *node, NodePathComponent *next,
  47. int pipeline_stage, Thread *current_thread);
  48. INLINE NodePathComponent(const NodePathComponent &copy);
  49. INLINE void operator = (const NodePathComponent &copy);
  50. public:
  51. INLINE ~NodePathComponent();
  52. ALLOC_DELETED_CHAIN(NodePathComponent);
  53. INLINE PandaNode *get_node() const;
  54. INLINE bool has_key() const;
  55. int get_key() const;
  56. bool is_top_node(int pipeline_stage, Thread *current_thread) const;
  57. NodePathComponent *get_next(int pipeline_stage, Thread *current_thread) const;
  58. int get_length(int pipeline_stage, Thread *current_thread) const;
  59. bool fix_length(int pipeline_stage, Thread *current_thread);
  60. void output(ostream &out) const;
  61. private:
  62. void set_next(NodePathComponent *next, int pipeline_stage, Thread *current_thread);
  63. void set_top_node(int pipeline_stage, Thread *current_thread);
  64. // We don't have to cycle the _node and _key elements, since these
  65. // are permanent properties of this object. (Well, the _key is
  66. // semi-permanent: it becomes permanent after it has been set the
  67. // first time.)
  68. PT(PandaNode) _node;
  69. int _key;
  70. // This is the data that must be cycled between pipeline stages.
  71. class EXPCL_PANDA_PGRAPH CData : public CycleData {
  72. public:
  73. INLINE CData();
  74. CData(const CData &copy);
  75. ALLOC_DELETED_CHAIN(CData);
  76. virtual CycleData *make_copy() const;
  77. virtual TypeHandle get_parent_type() const {
  78. return NodePathComponent::get_class_type();
  79. }
  80. PT(NodePathComponent) _next;
  81. int _length;
  82. public:
  83. static TypeHandle get_class_type() {
  84. return _type_handle;
  85. }
  86. static void init_type() {
  87. register_type(_type_handle, "NodePathComponent::CData");
  88. }
  89. private:
  90. static TypeHandle _type_handle;
  91. };
  92. PipelineCycler<CData> _cycler;
  93. typedef CycleDataReader<CData> CDReader;
  94. typedef CycleDataWriter<CData> CDWriter;
  95. typedef CycleDataLockedStageReader<CData> CDLockedStageReader;
  96. typedef CycleDataStageReader<CData> CDStageReader;
  97. typedef CycleDataStageWriter<CData> CDStageWriter;
  98. static int _next_key;
  99. static LightMutex _key_lock;
  100. public:
  101. static TypeHandle get_class_type() {
  102. return _type_handle;
  103. }
  104. static void init_type() {
  105. ReferenceCount::init_type();
  106. register_type(_type_handle, "NodePathComponent",
  107. ReferenceCount::get_class_type());
  108. CData::init_type();
  109. }
  110. private:
  111. static TypeHandle _type_handle;
  112. friend class PandaNode;
  113. };
  114. INLINE ostream &operator << (ostream &out, const NodePathComponent &comp);
  115. #include "nodePathComponent.I"
  116. #endif