Panda3D
callbackNode.h
1 // Filename: callbackNode.h
2 // Created by: drose (13Mar09)
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 CALLBACKNODE_H
16 #define CALLBACKNODE_H
17 
18 #include "pandabase.h"
19 #include "pandaNode.h"
20 #include "callbackObject.h"
21 #include "pointerTo.h"
22 
23 ////////////////////////////////////////////////////////////////////
24 // Class : CallbackNode
25 // Description : A special node that can issue arbitrary callbacks to
26 // user code, either during the cull or draw traversals.
27 ////////////////////////////////////////////////////////////////////
28 class EXPCL_PANDA_PGRAPHNODES CallbackNode : public PandaNode {
29 PUBLISHED:
30  CallbackNode(const string &name);
31 
32  INLINE void set_cull_callback(CallbackObject *object);
33  INLINE void clear_cull_callback();
34  INLINE CallbackObject *get_cull_callback() const;
35 
36  INLINE void set_draw_callback(CallbackObject *object);
37  INLINE void clear_draw_callback();
38  INLINE CallbackObject *get_draw_callback() const;
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(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;
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
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:50
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
virtual TypeHandle get_parent_type() const
Returns the type of the container that owns the CycleData.
Definition: cycleData.cxx:91
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
A special node that can issue arbitrary callbacks to user code, either during the cull or draw traver...
Definition: callbackNode.h:28
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:281
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:34
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
virtual void add_for_draw(CullTraverser *trav, CullTraverserData &data)
Adds the node&#39;s contents to the CullResult we are building up during the cull traversal, so that it will be drawn at render time.
Definition: pandaNode.cxx:591
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:604
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&#39;s make_from_bam() method to read in all...
Definition: cycleData.cxx:68
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:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
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:578
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48