Panda3D
callbackNode.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 callbackNode.h
10  * @author drose
11  * @date 2009-03-13
12  */
13 
14 #ifndef CALLBACKNODE_H
15 #define CALLBACKNODE_H
16 
17 #include "pandabase.h"
18 #include "pandaNode.h"
19 #include "callbackObject.h"
20 #include "pointerTo.h"
21 
22 /**
23  * A special node that can issue arbitrary callbacks to user code, either
24  * during the cull or draw traversals.
25  */
26 class EXPCL_PANDA_PGRAPHNODES CallbackNode : public PandaNode {
27 PUBLISHED:
28  explicit CallbackNode(const std::string &name);
29 
30  INLINE void set_cull_callback(CallbackObject *object);
31  INLINE void clear_cull_callback();
32  INLINE CallbackObject *get_cull_callback() const;
33  MAKE_PROPERTY(cull_callback, get_cull_callback, set_cull_callback);
34 
35  INLINE void set_draw_callback(CallbackObject *object);
36  INLINE void clear_draw_callback();
37  INLINE CallbackObject *get_draw_callback() const;
38  MAKE_PROPERTY(draw_callback, get_draw_callback, set_draw_callback);
39 
40 public:
41  CallbackNode(const CallbackNode &copy);
42 
43  virtual PandaNode *make_copy() const;
44  virtual bool safe_to_combine() const;
45 
46  virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
47  virtual bool is_renderable() const;
48  virtual void add_for_draw(CullTraverser *trav, CullTraverserData &data);
49 
50  virtual void output(std::ostream &out) const;
51 
52 private:
53  class EXPCL_PANDA_PGRAPHNODES CData : public CycleData {
54  public:
55  INLINE CData();
56  INLINE CData(const CData &copy);
57  virtual CycleData *make_copy() const;
58  virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
59  virtual void fillin(DatagramIterator &scan, BamReader *manager);
60  virtual TypeHandle get_parent_type() const {
61  return CallbackNode::get_class_type();
62  }
63 
64  PT(CallbackObject) _cull_callback;
65  PT(CallbackObject) _draw_callback;
66  };
67 
68  PipelineCycler<CData> _cycler;
69  typedef CycleDataReader<CData> CDReader;
70  typedef CycleDataWriter<CData> CDWriter;
71 
72 public:
73  static void register_with_read_factory();
74  virtual void write_datagram(BamWriter *manager, Datagram &dg);
75 
76 protected:
77  static TypedWritable *make_from_bam(const FactoryParams &params);
78  void fillin(DatagramIterator &scan, BamReader *manager);
79 
80 public:
81  static TypeHandle get_class_type() {
82  return _type_handle;
83  }
84  static void init_type() {
85  PandaNode::init_type();
86  register_type(_type_handle, "CallbackNode",
87  PandaNode::get_class_type());
88  }
89  virtual TypeHandle get_type() const {
90  return get_class_type();
91  }
92  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
93 
94 private:
95  static TypeHandle _type_handle;
96 };
97 
98 #include "callbackNode.I"
99 
100 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:47
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual TypeHandle get_parent_type() const
Returns the type of the container that owns the CycleData.
Definition: cycleData.cxx:76
This collects together the pieces of data that are accumulated for each node while walking the scene ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
A special node that can issue arbitrary callbacks to user code, either during the cull or draw traver...
Definition: callbackNode.h:26
virtual bool safe_to_combine() const
Returns true if it is generally safe to combine this particular kind of PandaNode with other kinds of...
Definition: pandaNode.cxx:234
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
virtual void write_datagram(BamWriter *, Datagram &) const
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: cycleData.cxx:32
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
virtual void add_for_draw(CullTraverser *trav, CullTraverserData &data)
Adds the node's contents to the CullResult we are building up during the cull traversal,...
Definition: pandaNode.cxx:478
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:487
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a generic object that can be assigned to a callback at various points in the rendering proces...
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
Definition: cycleData.cxx:58
A class to retrieve the individual data elements previously stored in a Datagram.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
Definition: pandaNode.cxx:468
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Definition: cullTraverser.h:45
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.