Panda3D
|
00001 // Filename: callbackNode.h 00002 // Created by: drose (13Mar09) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef CALLBACKNODE_H 00016 #define CALLBACKNODE_H 00017 00018 #include "pandabase.h" 00019 #include "pandaNode.h" 00020 #include "callbackObject.h" 00021 #include "pointerTo.h" 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Class : CallbackNode 00025 // Description : A special node that can issue arbitrary callbacks to 00026 // user code, either during the cull or draw traversals. 00027 //////////////////////////////////////////////////////////////////// 00028 class EXPCL_PANDA_PGRAPHNODES CallbackNode : public PandaNode { 00029 PUBLISHED: 00030 CallbackNode(const string &name); 00031 00032 INLINE void set_cull_callback(CallbackObject *object); 00033 INLINE void clear_cull_callback(); 00034 INLINE CallbackObject *get_cull_callback() const; 00035 00036 INLINE void set_draw_callback(CallbackObject *object); 00037 INLINE void clear_draw_callback(); 00038 INLINE CallbackObject *get_draw_callback() const; 00039 00040 public: 00041 CallbackNode(const CallbackNode ©); 00042 00043 virtual PandaNode *make_copy() const; 00044 virtual bool safe_to_combine() const; 00045 00046 virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data); 00047 virtual bool is_renderable() const; 00048 virtual void add_for_draw(CullTraverser *trav, CullTraverserData &data); 00049 00050 virtual void output(ostream &out) const; 00051 00052 private: 00053 class EXPCL_PANDA_PGRAPHNODES CData : public CycleData { 00054 public: 00055 INLINE CData(); 00056 INLINE CData(const CData ©); 00057 virtual CycleData *make_copy() const; 00058 virtual void write_datagram(BamWriter *manager, Datagram &dg) const; 00059 virtual void fillin(DatagramIterator &scan, BamReader *manager); 00060 virtual TypeHandle get_parent_type() const { 00061 return CallbackNode::get_class_type(); 00062 } 00063 00064 PT(CallbackObject) _cull_callback; 00065 PT(CallbackObject) _draw_callback; 00066 }; 00067 00068 PipelineCycler<CData> _cycler; 00069 typedef CycleDataReader<CData> CDReader; 00070 typedef CycleDataWriter<CData> CDWriter; 00071 00072 public: 00073 static void register_with_read_factory(); 00074 virtual void write_datagram(BamWriter *manager, Datagram &dg); 00075 00076 protected: 00077 static TypedWritable *make_from_bam(const FactoryParams ¶ms); 00078 void fillin(DatagramIterator &scan, BamReader *manager); 00079 00080 public: 00081 static TypeHandle get_class_type() { 00082 return _type_handle; 00083 } 00084 static void init_type() { 00085 PandaNode::init_type(); 00086 register_type(_type_handle, "CallbackNode", 00087 PandaNode::get_class_type()); 00088 } 00089 virtual TypeHandle get_type() const { 00090 return get_class_type(); 00091 } 00092 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00093 00094 private: 00095 static TypeHandle _type_handle; 00096 }; 00097 00098 #include "callbackNode.I" 00099 00100 #endif