Browse Source

Implement ParamNodePath; fix circular include issue in shaderInput.h

rdb 10 years ago
parent
commit
7a6aa7bfae

+ 3 - 0
panda/src/pgraph/Sources.pp

@@ -79,6 +79,7 @@
     occluderNode.I occluderNode.h \
     occluderNode.I occluderNode.h \
     pandaNode.I pandaNode.h \
     pandaNode.I pandaNode.h \
     pandaNodeChain.I pandaNodeChain.h \
     pandaNodeChain.I pandaNodeChain.h \
+    paramNodePath.I paramNodePath.h \
     planeNode.I planeNode.h \
     planeNode.I planeNode.h \
     polylightEffect.I polylightEffect.h \
     polylightEffect.I polylightEffect.h \
     polylightNode.I polylightNode.h \
     polylightNode.I polylightNode.h \
@@ -184,6 +185,7 @@
     occluderNode.cxx \
     occluderNode.cxx \
     pandaNode.cxx \
     pandaNode.cxx \
     pandaNodeChain.cxx \
     pandaNodeChain.cxx \
+    paramNodePath.cxx \
     planeNode.cxx \
     planeNode.cxx \
     polylightEffect.cxx \
     polylightEffect.cxx \
     polylightNode.cxx \
     polylightNode.cxx \
@@ -286,6 +288,7 @@
     pandaNode.I pandaNode.h \
     pandaNode.I pandaNode.h \
     pandaNode_ext.h pandaNode_ext.cxx \
     pandaNode_ext.h pandaNode_ext.cxx \
     pandaNodeChain.I pandaNodeChain.h \
     pandaNodeChain.I pandaNodeChain.h \
+    paramNodePath.I paramNodePath.h \
     planeNode.I planeNode.h \
     planeNode.I planeNode.h \
     polylightEffect.I polylightEffect.h \
     polylightEffect.I polylightEffect.h \
     polylightNode.I polylightNode.h \
     polylightNode.I polylightNode.h \

+ 2 - 0
panda/src/pgraph/config_pgraph.cxx

@@ -60,6 +60,7 @@
 #include "nodePath.h"
 #include "nodePath.h"
 #include "nodePathComponent.h"
 #include "nodePathComponent.h"
 #include "pandaNode.h"
 #include "pandaNode.h"
+#include "paramNodePath.h"
 #include "planeNode.h"
 #include "planeNode.h"
 #include "polylightEffect.h"
 #include "polylightEffect.h"
 #include "polylightNode.h"
 #include "polylightNode.h"
@@ -436,6 +437,7 @@ init_libpgraph() {
   NodePathComponent::init_type();
   NodePathComponent::init_type();
   PandaNode::init_type();
   PandaNode::init_type();
   PandaNodePipelineReader::init_type();
   PandaNodePipelineReader::init_type();
+  ParamNodePath::init_type();
   PlaneNode::init_type();
   PlaneNode::init_type();
   PolylightNode::init_type();
   PolylightNode::init_type();
   PolylightEffect::init_type();
   PolylightEffect::init_type();

+ 1 - 3
panda/src/pgraph/nodePath.h

@@ -38,6 +38,7 @@
 #include "pta_LVecBase3.h"
 #include "pta_LVecBase3.h"
 #include "pta_LVecBase2.h"
 #include "pta_LVecBase2.h"
 #include "stl_compares.h"
 #include "stl_compares.h"
+#include "shaderInput.h"
 
 
 class NodePathCollection;
 class NodePathCollection;
 class FindApproxPath;
 class FindApproxPath;
@@ -1008,9 +1009,6 @@ private:
 
 
 INLINE ostream &operator << (ostream &out, const NodePath &node_path);
 INLINE ostream &operator << (ostream &out, const NodePath &node_path);
 
 
-// We have to put this down here, to work around a circular include.
-#include "shaderInput.h"
-
 #include "nodePath.I"
 #include "nodePath.I"
 
 
 #endif
 #endif

+ 1 - 0
panda/src/pgraph/p3pgraph_composite3.cxx

@@ -21,6 +21,7 @@
 #include "occluderNode.cxx"
 #include "occluderNode.cxx"
 #include "pandaNode.cxx"
 #include "pandaNode.cxx"
 #include "pandaNodeChain.cxx"
 #include "pandaNodeChain.cxx"
+#include "paramNodePath.cxx"
 #include "planeNode.cxx"
 #include "planeNode.cxx"
 #include "polylightEffect.cxx"
 #include "polylightEffect.cxx"
 #include "polylightNode.cxx"
 #include "polylightNode.cxx"

+ 60 - 0
panda/src/pgraph/paramNodePath.I

@@ -0,0 +1,60 @@
+// Filename: paramNodePath.I
+// Created by:  rdb (25Feb15)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: ParamNodePath::Constructor
+//       Access: Published
+//  Description: Creates a new ParamNodePath storing the given
+//               node path object.
+////////////////////////////////////////////////////////////////////
+INLINE ParamNodePath::
+ParamNodePath(const NodePath &node_path) :
+  _node_path(node_path)
+{
+}
+
+#ifdef USE_MOVE_SEMANTICS
+////////////////////////////////////////////////////////////////////
+//     Function: ParamNodePath::Move Constructor
+//       Access: Published
+//  Description: Creates a new ParamNodePath storing the given
+//               node path object.
+////////////////////////////////////////////////////////////////////
+INLINE ParamNodePath::
+ParamNodePath(NodePath &&node_path) NOEXCEPT :
+  _node_path(move(node_path))
+{
+}
+#endif  // USE_MOVE_SEMANTICS
+
+////////////////////////////////////////////////////////////////////
+//     Function: ParamNodePath::get_value_type
+//       Access: Published, Virtual
+//  Description: Returns NodePath::get_class_type().
+////////////////////////////////////////////////////////////////////
+INLINE TypeHandle ParamNodePath::
+get_value_type() const {
+  return NodePath::get_class_type();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ParamNodePath::get_value
+//       Access: Published
+//  Description: Retrieves the NodePath stored in the parameter.
+////////////////////////////////////////////////////////////////////
+INLINE const NodePath &ParamNodePath::
+get_value() const {
+  return _node_path;
+}

+ 108 - 0
panda/src/pgraph/paramNodePath.cxx

@@ -0,0 +1,108 @@
+// Filename: paramNodePath.cxx
+// Created by:  rdb (25Feb15)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#include "paramNodePath.h"
+#include "dcast.h"
+#include "pandaNode.h"
+
+TypeHandle ParamNodePath::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: ParamNodePath::output
+//       Access: Published, Virtual
+//  Description:
+////////////////////////////////////////////////////////////////////
+void ParamNodePath::
+output(ostream &out) const {
+  out << "node path " << _node_path;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ParamNodePath::register_with_read_factory
+//       Access: Public, Static
+//  Description: Tells the BamReader how to create objects of type
+//               ParamValue.
+////////////////////////////////////////////////////////////////////
+void ParamNodePath::
+register_with_read_factory() {
+  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ParamNodePath::write_datagram
+//       Access: Public, Virtual
+//  Description: Writes the contents of this object to the datagram
+//               for shipping out to a Bam file.
+////////////////////////////////////////////////////////////////////
+void ParamNodePath::
+write_datagram(BamWriter *manager, Datagram &dg) {
+  ParamValueBase::write_datagram(manager, dg);
+
+  // We can't store a NodePath, so we store a pointer to the
+  // underlying node, and pray that there is an unambiguous path
+  // from the root to it.
+  if (_node_path.is_empty()) {
+    manager->write_pointer(dg, NULL);
+  } else {
+    manager->write_pointer(dg, _node_path.node());
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ParamNodePath::complete_pointers
+//       Access: Public, Virtual
+//  Description: Receives an array of pointers, one for each time
+//               manager->read_pointer() was called in fillin().
+//               Returns the number of pointers processed.
+////////////////////////////////////////////////////////////////////
+int ParamNodePath::
+complete_pointers(TypedWritable **p_list, BamReader *manager) {
+  int pi = ParamValueBase::complete_pointers(p_list, manager);
+  _node_path = NodePath(DCAST(PandaNode, p_list[pi++]));
+
+  return pi;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ParamNodePath::make_from_bam
+//       Access: Protected, Static
+//  Description: This function is called by the BamReader's factory
+//               when a new object of type ParamValue is encountered
+//               in the Bam file.  It should create the ParamValue
+//               and extract its information from the file.
+////////////////////////////////////////////////////////////////////
+TypedWritable *ParamNodePath::
+make_from_bam(const FactoryParams &params) {
+  ParamNodePath *param = new ParamNodePath;
+  DatagramIterator scan;
+  BamReader *manager;
+
+  parse_params(params, scan, manager);
+  param->fillin(scan, manager);
+
+  return param;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ParamNodePath::fillin
+//       Access: Protected
+//  Description: This internal function is called by make_from_bam to
+//               read in all of the relevant data from the BamFile for
+//               the new ParamValue.
+////////////////////////////////////////////////////////////////////
+void ParamNodePath::
+fillin(DatagramIterator &scan, BamReader *manager) {
+  ParamValueBase::fillin(scan, manager);
+  manager->read_pointer(scan);
+}

+ 75 - 0
panda/src/pgraph/paramNodePath.h

@@ -0,0 +1,75 @@
+// Filename: paramNodePath.h
+// Created by:  rdb (25Feb15)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef PARAMNODEPATH_H
+#define PARAMNODEPATH_H
+
+#include "pandabase.h"
+#include "paramValue.h"
+#include "nodePath.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : ParamNodePath
+// Description : A class object for storing a NodePath as a parameter.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDA_GOBJ ParamNodePath : public ParamValueBase {
+protected:
+  INLINE ParamNodePath() {};
+
+PUBLISHED:
+  INLINE ParamNodePath(const NodePath &node_path);
+
+#ifdef USE_MOVE_SEMANTICS
+  INLINE ParamNodePath(NodePath &&node_path) NOEXCEPT;
+#endif
+
+  INLINE virtual TypeHandle get_value_type() const;
+  INLINE const NodePath &get_value() const;
+
+  virtual void output(ostream &out) const;
+
+private:
+  NodePath _node_path;
+
+public:
+  static void register_with_read_factory();
+  virtual void write_datagram(BamWriter *manager, Datagram &dg);
+  virtual int complete_pointers(TypedWritable **plist,
+                                BamReader *manager);
+
+protected:
+  static TypedWritable *make_from_bam(const FactoryParams &params);
+  void fillin(DatagramIterator &scan, BamReader *manager);
+
+public:
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    ParamValueBase::init_type();
+    register_type(_type_handle, "ParamNodePath",
+                  ParamValueBase::get_class_type());
+  }
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "paramNodePath.I"
+
+#endif

+ 0 - 27
panda/src/pgraph/shaderInput.I

@@ -119,23 +119,6 @@ ShaderInput(CPT_InternalName name, ParamValueBase *param, int priority) :
 {
 {
 }
 }
 
 
-////////////////////////////////////////////////////////////////////
-//     Function: ShaderInput::Constructor
-//       Access: Published
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE ShaderInput::
-ShaderInput(CPT_InternalName name, const NodePath &np, int priority) :
-  _name(MOVE(name)),
-  _type(M_nodepath),
-  _priority(priority),
-  _stored_nodepath(np),
-  _bind_layer(0),
-  _bind_level(0),
-  _access(A_read)
-{
-}
-
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ShaderInput::Constructor
 //     Function: ShaderInput::Constructor
 //       Access: Published
 //       Access: Published
@@ -678,16 +661,6 @@ get_texture() const {
   return DCAST(Texture, _value);
   return DCAST(Texture, _value);
 }
 }
 
 
-////////////////////////////////////////////////////////////////////
-//     Function: ShaderInput::get_nodepath
-//       Access: Published
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE const NodePath &ShaderInput::
-get_nodepath() const {
-  return _stored_nodepath;
-}
-
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ShaderInput::get_vector
 //     Function: ShaderInput::get_vector
 //       Access: Published
 //       Access: Published

+ 30 - 2
panda/src/pgraph/shaderInput.cxx

@@ -13,6 +13,7 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 
 
 #include "shaderInput.h"
 #include "shaderInput.h"
+#include "paramNodePath.h"
 
 
 TypeHandle ShaderInput::_type_handle;
 TypeHandle ShaderInput::_type_handle;
 
 
@@ -32,13 +33,40 @@ get_blank() {
   return blank;
   return blank;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: ShaderInput::Constructor
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+ShaderInput::
+ShaderInput(CPT_InternalName name, const NodePath &np, int priority) :
+  _name(MOVE(name)),
+  _type(M_nodepath),
+  _priority(priority),
+  _value(new ParamNodePath(np)),
+  _bind_layer(0),
+  _bind_level(0),
+  _access(A_read)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ShaderInput::get_nodepath
+//       Access: Published
+//  Description: Warning: no error checking is done.  This *will*
+//               crash if get_value_type() is not M_nodepath.
+////////////////////////////////////////////////////////////////////
+const NodePath &ShaderInput::
+get_nodepath() const {
+  return DCAST(ParamNodePath, _value)->get_value();
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ShaderInput::register_with_read_factory
 //     Function: ShaderInput::register_with_read_factory
 //       Access: Public, Static
 //       Access: Public, Static
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void ShaderInput::
 void ShaderInput::
 register_with_read_factory() {
 register_with_read_factory() {
   // IMPLEMENT ME
   // IMPLEMENT ME
 }
 }
-

+ 4 - 4
panda/src/pgraph/shaderInput.h

@@ -19,7 +19,6 @@
 #include "pandabase.h"
 #include "pandabase.h"
 #include "typedWritableReferenceCount.h"
 #include "typedWritableReferenceCount.h"
 #include "pointerTo.h"
 #include "pointerTo.h"
-#include "nodePath.h"
 #include "internalName.h"
 #include "internalName.h"
 #include "paramValue.h"
 #include "paramValue.h"
 #include "pta_float.h"
 #include "pta_float.h"
@@ -53,7 +52,6 @@ PUBLISHED:
 
 
   static const ShaderInput *get_blank();
   static const ShaderInput *get_blank();
   INLINE ShaderInput(CPT_InternalName name, int priority=0);
   INLINE ShaderInput(CPT_InternalName name, int priority=0);
-  INLINE ShaderInput(CPT_InternalName name, const NodePath &np, int priority=0);
   INLINE ShaderInput(CPT_InternalName name, Texture *tex, int priority=0);
   INLINE ShaderInput(CPT_InternalName name, Texture *tex, int priority=0);
   INLINE ShaderInput(CPT_InternalName name, Texture *tex, const SamplerState &sampler, int priority=0);
   INLINE ShaderInput(CPT_InternalName name, Texture *tex, const SamplerState &sampler, int priority=0);
   INLINE ShaderInput(CPT_InternalName name, Texture *tex, bool read, bool write, int z=-1, int n=0, int priority=0);
   INLINE ShaderInput(CPT_InternalName name, Texture *tex, bool read, bool write, int z=-1, int n=0, int priority=0);
@@ -90,6 +88,8 @@ PUBLISHED:
   INLINE ShaderInput(CPT_InternalName name, const LVecBase3i &vec, int priority=0);
   INLINE ShaderInput(CPT_InternalName name, const LVecBase3i &vec, int priority=0);
   INLINE ShaderInput(CPT_InternalName name, const LVecBase2i &vec, int priority=0);
   INLINE ShaderInput(CPT_InternalName name, const LVecBase2i &vec, int priority=0);
 
 
+  ShaderInput(CPT_InternalName name, const NodePath &np, int priority=0);
+
   enum ShaderInputType {
   enum ShaderInputType {
     M_invalid = 0,
     M_invalid = 0,
     M_texture,
     M_texture,
@@ -105,11 +105,12 @@ PUBLISHED:
   INLINE int get_value_type() const;
   INLINE int get_value_type() const;
   INLINE int get_priority() const;
   INLINE int get_priority() const;
   INLINE Texture *get_texture() const;
   INLINE Texture *get_texture() const;
-  INLINE const NodePath &get_nodepath() const;
   INLINE const LVecBase4 &get_vector() const;
   INLINE const LVecBase4 &get_vector() const;
   INLINE const Shader::ShaderPtrData &get_ptr() const;
   INLINE const Shader::ShaderPtrData &get_ptr() const;
   INLINE const SamplerState &get_sampler() const;
   INLINE const SamplerState &get_sampler() const;
 
 
+  const NodePath &get_nodepath() const;
+
 public:
 public:
   INLINE ParamValueBase *get_param() const;
   INLINE ParamValueBase *get_param() const;
 
 
@@ -118,7 +119,6 @@ public:
 private:
 private:
   SamplerState _sampler;
   SamplerState _sampler;
   LVecBase4 _stored_vector;
   LVecBase4 _stored_vector;
-  NodePath _stored_nodepath;
   Shader::ShaderPtrData _stored_ptr;
   Shader::ShaderPtrData _stored_ptr;
   CPT_InternalName _name;
   CPT_InternalName _name;
   PT(TypedWritableReferenceCount) _value;
   PT(TypedWritableReferenceCount) _value;